PageRenderTime 88ms CodeModel.GetById 17ms app.highlight 56ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/char/epca.c

https://bitbucket.org/evzijst/gittest
C | 3789 lines | 2187 code | 907 blank | 695 comment | 345 complexity | c77d8deab6ed1b0737609a564245fc5a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2
   3 
   4	Copyright (C) 1996  Digi International.
   5 
   6	For technical support please email digiLinux@dgii.com or
   7	call Digi tech support at (612) 912-3456
   8
   9	Much of this design and code came from epca.c which was 
  10	copyright (C) 1994, 1995 Troy De Jongh, and subsquently 
  11	modified by David Nugent, Christoph Lameter, Mike McLagan. 
  12 
  13 	This program is free software; you can redistribute it and/or modify
  14 	it under the terms of the GNU General Public License as published by
  15 	the Free Software Foundation; either version 2 of the License, or
  16 	(at your option) any later version.
  17
  18 	This program is distributed in the hope that it will be useful,
  19 	but WITHOUT ANY WARRANTY; without even the implied warranty of
  20 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21 	GNU General Public License for more details.
  22
  23 	You should have received a copy of the GNU General Public License
  24 	along with this program; if not, write to the Free Software
  25 	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26
  27--------------------------------------------------------------------------- */
  28/* See README.epca for change history --DAT*/
  29
  30
  31#include <linux/config.h>
  32#include <linux/module.h>
  33#include <linux/kernel.h>
  34#include <linux/types.h>
  35#include <linux/init.h>
  36#include <linux/serial.h>
  37#include <linux/delay.h>
  38#include <linux/ctype.h>
  39#include <linux/tty.h>
  40#include <linux/tty_flip.h>
  41#include <linux/slab.h>
  42#include <linux/ioport.h>
  43#include <linux/interrupt.h>
  44#include <asm/uaccess.h>
  45#include <asm/io.h>
  46
  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>
  56#include "digiPCI.h"
  57#endif /* ENABLE_PCI */
  58
  59#include "digi1.h"
  60#include "digiFep1.h"
  61#include "epca.h"
  62#include "epcaconfig.h"
  63
  64#if BITS_PER_LONG != 32
  65#  error FIXME: this driver only works on 32-bit platforms
  66#endif
  67
  68/* ---------------------- Begin defines ------------------------ */
  69
  70#define VERSION            "1.3.0.1-LK"
  71
  72/* This major needs to be submitted to Linux to join the majors list */
  73
  74#define DIGIINFOMAJOR       35  /* For Digi specific ioctl */ 
  75
  76
  77#define MAXCARDS 7
  78#define epcaassert(x, msg)  if (!(x)) epca_error(__LINE__, msg)
  79
  80#define PFX "epca: "
  81
  82/* ----------------- Begin global definitions ------------------- */
  83
  84static char mesg[100];
  85static int nbdevs, num_cards, liloconfig;
  86static int digi_poller_inhibited = 1 ;
  87
  88static int setup_error_code;
  89static int invalid_lilo_config;
  90
  91/* -----------------------------------------------------------------------
  92	MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 
  93	7 below.
  94--------------------------------------------------------------------------*/
  95static struct board_info boards[MAXBOARDS];
  96
  97
  98/* ------------- Begin structures used for driver registeration ---------- */
  99
 100static struct tty_driver *pc_driver;
 101static struct tty_driver *pc_info;
 102
 103/* ------------------ Begin Digi specific structures -------------------- */
 104
 105/* ------------------------------------------------------------------------
 106	digi_channels represents an array of structures that keep track of
 107	each channel of the Digi product.  Information such as transmit and
 108	receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
 109	are stored here.  This structure is NOT used to overlay the cards 
 110	physical channel structure.
 111-------------------------------------------------------------------------- */
 112  
 113static struct channel digi_channels[MAX_ALLOC];
 114
 115/* ------------------------------------------------------------------------
 116	card_ptr is an array used to hold the address of the
 117	first channel structure of each card.  This array will hold
 118	the addresses of various channels located in digi_channels.
 119-------------------------------------------------------------------------- */
 120static struct channel *card_ptr[MAXCARDS];
 121
 122static struct timer_list epca_timer;
 123
 124/* ---------------------- Begin function prototypes --------------------- */
 125
 126/* ----------------------------------------------------------------------
 127	Begin generic memory functions.  These functions will be alias
 128	(point at) more specific functions dependent on the board being
 129	configured.
 130----------------------------------------------------------------------- */
 131	
 132static inline void memwinon(struct board_info *b, unsigned int win);
 133static inline void memwinoff(struct board_info *b, unsigned int win);
 134static inline void globalwinon(struct channel *ch);
 135static inline void rxwinon(struct channel *ch);
 136static inline void txwinon(struct channel *ch);
 137static inline void memoff(struct channel *ch);
 138static inline void assertgwinon(struct channel *ch);
 139static inline void assertmemoff(struct channel *ch);
 140
 141/* ---- Begin more 'specific' memory functions for cx_like products --- */
 142
 143static inline void pcxem_memwinon(struct board_info *b, unsigned int win);
 144static inline void pcxem_memwinoff(struct board_info *b, unsigned int win);
 145static inline void pcxem_globalwinon(struct channel *ch);
 146static inline void pcxem_rxwinon(struct channel *ch);
 147static inline void pcxem_txwinon(struct channel *ch);
 148static inline void pcxem_memoff(struct channel *ch);
 149
 150/* ------ Begin more 'specific' memory functions for the pcxe ------- */
 151
 152static inline void pcxe_memwinon(struct board_info *b, unsigned int win);
 153static inline void pcxe_memwinoff(struct board_info *b, unsigned int win);
 154static inline void pcxe_globalwinon(struct channel *ch);
 155static inline void pcxe_rxwinon(struct channel *ch);
 156static inline void pcxe_txwinon(struct channel *ch);
 157static inline void pcxe_memoff(struct channel *ch);
 158
 159/* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
 160/* Note : pc64xe and pcxi share the same windowing routines */
 161
 162static inline void pcxi_memwinon(struct board_info *b, unsigned int win);
 163static inline void pcxi_memwinoff(struct board_info *b, unsigned int win);
 164static inline void pcxi_globalwinon(struct channel *ch);
 165static inline void pcxi_rxwinon(struct channel *ch);
 166static inline void pcxi_txwinon(struct channel *ch);
 167static inline void pcxi_memoff(struct channel *ch);
 168
 169/* - Begin 'specific' do nothing memory functions needed for some cards - */
 170
 171static inline void dummy_memwinon(struct board_info *b, unsigned int win);
 172static inline void dummy_memwinoff(struct board_info *b, unsigned int win);
 173static inline void dummy_globalwinon(struct channel *ch);
 174static inline void dummy_rxwinon(struct channel *ch);
 175static inline void dummy_txwinon(struct channel *ch);
 176static inline void dummy_memoff(struct channel *ch);
 177static inline void dummy_assertgwinon(struct channel *ch);
 178static inline void dummy_assertmemoff(struct channel *ch);
 179
 180/* ------------------- Begin declare functions ----------------------- */
 181
 182static inline struct channel *verifyChannel(register struct tty_struct *);
 183static inline void pc_sched_event(struct channel *, int);
 184static void epca_error(int, char *);
 185static void pc_close(struct tty_struct *, struct file *);
 186static void shutdown(struct channel *);
 187static void pc_hangup(struct tty_struct *);
 188static void pc_put_char(struct tty_struct *, unsigned char);
 189static int pc_write_room(struct tty_struct *);
 190static int pc_chars_in_buffer(struct tty_struct *);
 191static void pc_flush_buffer(struct tty_struct *);
 192static void pc_flush_chars(struct tty_struct *);
 193static int block_til_ready(struct tty_struct *, struct file *,
 194                           struct channel *);
 195static int pc_open(struct tty_struct *, struct file *);
 196static void post_fep_init(unsigned int crd);
 197static void epcapoll(unsigned long);
 198static void doevent(int);
 199static void fepcmd(struct channel *, int, int, int, int, int);
 200static unsigned termios2digi_h(struct channel *ch, unsigned);
 201static unsigned termios2digi_i(struct channel *ch, unsigned);
 202static unsigned termios2digi_c(struct channel *ch, unsigned);
 203static void epcaparam(struct tty_struct *, struct channel *);
 204static void receive_data(struct channel *);
 205static int pc_ioctl(struct tty_struct *, struct file *,
 206                    unsigned int, unsigned long);
 207static int info_ioctl(struct tty_struct *, struct file *,
 208                    unsigned int, unsigned long);
 209static void pc_set_termios(struct tty_struct *, struct termios *);
 210static void do_softint(void *);
 211static void pc_stop(struct tty_struct *);
 212static void pc_start(struct tty_struct *);
 213static void pc_throttle(struct tty_struct * tty);
 214static void pc_unthrottle(struct tty_struct *tty);
 215static void digi_send_break(struct channel *ch, int msec);
 216static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
 217void epca_setup(char *, int *);
 218void console_print(const char *);
 219
 220static int get_termio(struct tty_struct *, struct termio __user *);
 221static int pc_write(struct tty_struct *, const unsigned char *, int);
 222int pc_init(void);
 223
 224#ifdef ENABLE_PCI
 225static int init_PCI(void);
 226#endif /* ENABLE_PCI */
 227
 228
 229/* ------------------------------------------------------------------
 230	Table of functions for each board to handle memory.  Mantaining 
 231	parallelism is a *very* good idea here.  The idea is for the 
 232	runtime code to blindly call these functions, not knowing/caring    
 233	about the underlying hardware.  This stuff should contain no
 234	conditionals; if more functionality is needed a different entry
 235	should be established.  These calls are the interface calls and 
 236	are the only functions that should be accessed.  Anyone caught
 237	making direct calls deserves what they get.
 238-------------------------------------------------------------------- */
 239
 240static inline void memwinon(struct board_info *b, unsigned int win)
 241{
 242	(b->memwinon)(b, win);
 243}
 244
 245static inline void memwinoff(struct board_info *b, unsigned int win)
 246{
 247	(b->memwinoff)(b, win);
 248}
 249
 250static inline void globalwinon(struct channel *ch)
 251{
 252	(ch->board->globalwinon)(ch);
 253}
 254
 255static inline void rxwinon(struct channel *ch)
 256{
 257	(ch->board->rxwinon)(ch);
 258}
 259
 260static inline void txwinon(struct channel *ch)
 261{
 262	(ch->board->txwinon)(ch);
 263}
 264
 265static inline void memoff(struct channel *ch)
 266{
 267	(ch->board->memoff)(ch);
 268}
 269static inline void assertgwinon(struct channel *ch)
 270{
 271	(ch->board->assertgwinon)(ch);
 272}
 273
 274static inline void assertmemoff(struct channel *ch)
 275{
 276	(ch->board->assertmemoff)(ch);
 277}
 278
 279/* ---------------------------------------------------------
 280	PCXEM windowing is the same as that used in the PCXR 
 281	and CX series cards.
 282------------------------------------------------------------ */
 283
 284static inline void pcxem_memwinon(struct board_info *b, unsigned int win)
 285{
 286        outb_p(FEPWIN|win, (int)b->port + 1);
 287}
 288
 289static inline void pcxem_memwinoff(struct board_info *b, unsigned int win)
 290{
 291	outb_p(0, (int)b->port + 1);
 292}
 293
 294static inline void pcxem_globalwinon(struct channel *ch)
 295{
 296	outb_p( FEPWIN, (int)ch->board->port + 1);
 297}
 298
 299static inline void pcxem_rxwinon(struct channel *ch)
 300{
 301	outb_p(ch->rxwin, (int)ch->board->port + 1);
 302}
 303
 304static inline void pcxem_txwinon(struct channel *ch)
 305{
 306	outb_p(ch->txwin, (int)ch->board->port + 1);
 307}
 308
 309static inline void pcxem_memoff(struct channel *ch)
 310{
 311	outb_p(0, (int)ch->board->port + 1);
 312}
 313
 314/* ----------------- Begin pcxe memory window stuff ------------------ */
 315
 316static inline void pcxe_memwinon(struct board_info *b, unsigned int win)
 317{
 318               outb_p(FEPWIN | win, (int)b->port + 1);
 319}
 320
 321static inline void pcxe_memwinoff(struct board_info *b, unsigned int win)
 322{
 323	outb_p(inb((int)b->port) & ~FEPMEM,
 324	           (int)b->port + 1);
 325	outb_p(0, (int)b->port + 1);
 326}
 327
 328static inline void pcxe_globalwinon(struct channel *ch)
 329{
 330	outb_p( FEPWIN, (int)ch->board->port + 1);
 331}
 332
 333static inline void pcxe_rxwinon(struct channel *ch)
 334{
 335		outb_p(ch->rxwin, (int)ch->board->port + 1);
 336}
 337
 338static inline void pcxe_txwinon(struct channel *ch)
 339{
 340		outb_p(ch->txwin, (int)ch->board->port + 1);
 341}
 342
 343static inline void pcxe_memoff(struct channel *ch)
 344{
 345	outb_p(0, (int)ch->board->port);
 346	outb_p(0, (int)ch->board->port + 1);
 347}
 348
 349/* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
 350
 351static inline void pcxi_memwinon(struct board_info *b, unsigned int win)
 352{
 353               outb_p(inb((int)b->port) | FEPMEM, (int)b->port);
 354}
 355
 356static inline void pcxi_memwinoff(struct board_info *b, unsigned int win)
 357{
 358	outb_p(inb((int)b->port) & ~FEPMEM, (int)b->port);
 359}
 360
 361static inline void pcxi_globalwinon(struct channel *ch)
 362{
 363	outb_p(FEPMEM, (int)ch->board->port);
 364}
 365
 366static inline void pcxi_rxwinon(struct channel *ch)
 367{
 368		outb_p(FEPMEM, (int)ch->board->port);
 369}
 370
 371static inline void pcxi_txwinon(struct channel *ch)
 372{
 373		outb_p(FEPMEM, (int)ch->board->port);
 374}
 375
 376static inline void pcxi_memoff(struct channel *ch)
 377{
 378	outb_p(0, (int)ch->board->port);
 379}
 380
 381static inline void pcxi_assertgwinon(struct channel *ch)
 382{
 383	epcaassert(inb((int)ch->board->port) & FEPMEM, "Global memory off");
 384}
 385
 386static inline void pcxi_assertmemoff(struct channel *ch)
 387{
 388	epcaassert(!(inb((int)ch->board->port) & FEPMEM), "Memory on");
 389}
 390
 391
 392/* ----------------------------------------------------------------------
 393	Not all of the cards need specific memory windowing routines.  Some
 394	cards (Such as PCI) needs no windowing routines at all.  We provide
 395	these do nothing routines so that the same code base can be used.
 396	The driver will ALWAYS call a windowing routine if it thinks it needs
 397	to; regardless of the card.  However, dependent on the card the routine
 398	may or may not do anything.
 399---------------------------------------------------------------------------*/
 400
 401static inline void dummy_memwinon(struct board_info *b, unsigned int win)
 402{
 403}
 404
 405static inline void dummy_memwinoff(struct board_info *b, unsigned int win)
 406{
 407}
 408
 409static inline void dummy_globalwinon(struct channel *ch)
 410{
 411}
 412
 413static inline void dummy_rxwinon(struct channel *ch)
 414{
 415}
 416
 417static inline void dummy_txwinon(struct channel *ch)
 418{
 419}
 420
 421static inline void dummy_memoff(struct channel *ch)
 422{
 423}
 424
 425static inline void dummy_assertgwinon(struct channel *ch)
 426{
 427}
 428
 429static inline void dummy_assertmemoff(struct channel *ch)
 430{
 431}
 432
 433/* ----------------- Begin verifyChannel function ----------------------- */
 434static inline struct channel *verifyChannel(register struct tty_struct *tty)
 435{ /* Begin verifyChannel */
 436
 437	/* --------------------------------------------------------------------
 438		This routine basically provides a sanity check.  It insures that
 439		the channel returned is within the proper range of addresses as
 440		well as properly initialized.  If some bogus info gets passed in
 441		through tty->driver_data this should catch it.
 442	--------------------------------------------------------------------- */
 443
 444	if (tty) 
 445	{ /* Begin if tty */
 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)
 452				return ch;
 453		}
 454
 455	} /* End if tty */
 456
 457	/* Else return a NULL for invalid */
 458	return NULL;
 459
 460} /* End verifyChannel */
 461
 462/* ------------------ Begin pc_sched_event ------------------------- */
 463
 464static inline void pc_sched_event(struct channel *ch, int event)
 465{ /* Begin pc_sched_event */
 466
 467
 468	/* ----------------------------------------------------------------------
 469		We call this to schedule interrupt processing on some event.  The 
 470		kernel sees our request and calls the related routine in OUR driver.
 471	-------------------------------------------------------------------------*/
 472
 473	ch->event |= 1 << event;
 474	schedule_work(&ch->tqueue);
 475
 476
 477} /* End pc_sched_event */
 478
 479/* ------------------ Begin epca_error ------------------------- */
 480
 481static void epca_error(int line, char *msg)
 482{ /* Begin epca_error */
 483
 484	printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
 485	return;
 486
 487} /* End epca_error */
 488
 489/* ------------------ Begin pc_close ------------------------- */
 490static void pc_close(struct tty_struct * tty, struct file * filp)
 491{ /* Begin pc_close */
 492
 493	struct channel *ch;
 494	unsigned long flags;
 495
 496	/* ---------------------------------------------------------
 497		verifyChannel returns the channel from the tty struct
 498		if it is valid.  This serves as a sanity check.
 499	------------------------------------------------------------- */
 500
 501	if ((ch = verifyChannel(tty)) != NULL) 
 502	{ /* Begin if ch != NULL */
 503
 504		save_flags(flags);
 505		cli();
 506
 507		if (tty_hung_up_p(filp)) 
 508		{
 509			restore_flags(flags);
 510			return;
 511		}
 512
 513		/* Check to see if the channel is open more than once */
 514		if (ch->count-- > 1) 
 515		{ /* Begin channel is open more than once */
 516
 517			/* -------------------------------------------------------------
 518				Return without doing anything.  Someone might still be using
 519				the channel.
 520			---------------------------------------------------------------- */
 521
 522			restore_flags(flags);
 523			return;
 524		} /* End channel is open more than once */
 525
 526		/* Port open only once go ahead with shutdown & reset */
 527
 528		if (ch->count < 0) 
 529		{
 530			ch->count = 0;
 531		}
 532
 533		/* ---------------------------------------------------------------
 534			Let the rest of the driver know the channel is being closed.
 535			This becomes important if an open is attempted before close 
 536			is finished.
 537		------------------------------------------------------------------ */
 538
 539		ch->asyncflags |= ASYNC_CLOSING;
 540	
 541		tty->closing = 1;
 542
 543		if (ch->asyncflags & ASYNC_INITIALIZED) 
 544		{
 545			/* Setup an event to indicate when the transmit buffer empties */
 546			setup_empty_event(tty, ch);		
 547			tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
 548		}
 549	
 550		if (tty->driver->flush_buffer)
 551			tty->driver->flush_buffer(tty);
 552
 553		tty_ldisc_flush(tty);
 554		shutdown(ch);
 555		tty->closing = 0;
 556		ch->event = 0;
 557		ch->tty = NULL;
 558
 559		if (ch->blocked_open) 
 560		{ /* Begin if blocked_open */
 561
 562			if (ch->close_delay) 
 563			{
 564				msleep_interruptible(jiffies_to_msecs(ch->close_delay));
 565			}
 566
 567			wake_up_interruptible(&ch->open_wait);
 568
 569		} /* End if blocked_open */
 570
 571		ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED | 
 572		                      ASYNC_CLOSING);
 573		wake_up_interruptible(&ch->close_wait);
 574
 575
 576		restore_flags(flags);
 577
 578	} /* End if ch != NULL */
 579
 580} /* End pc_close */ 
 581
 582/* ------------------ Begin shutdown  ------------------------- */
 583
 584static void shutdown(struct channel *ch)
 585{ /* Begin shutdown */
 586
 587	unsigned long flags;
 588	struct tty_struct *tty;
 589	volatile struct board_chan *bc;
 590
 591	if (!(ch->asyncflags & ASYNC_INITIALIZED)) 
 592		return;
 593
 594	save_flags(flags);
 595	cli();
 596	globalwinon(ch);
 597
 598	bc = ch->brdchan;
 599
 600	/* ------------------------------------------------------------------
 601		In order for an event to be generated on the receipt of data the
 602		idata flag must be set. Since we are shutting down, this is not 
 603		necessary clear this flag.
 604	--------------------------------------------------------------------- */ 
 605
 606	if (bc)
 607		bc->idata = 0;
 608
 609	tty = ch->tty;
 610
 611	/* ----------------------------------------------------------------
 612	   If we're a modem control device and HUPCL is on, drop RTS & DTR.
 613 	------------------------------------------------------------------ */
 614
 615	if (tty->termios->c_cflag & HUPCL) 
 616	{
 617		ch->omodem &= ~(ch->m_rts | ch->m_dtr);
 618		fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
 619	}
 620
 621	memoff(ch);
 622
 623	/* ------------------------------------------------------------------
 624		The channel has officialy been closed.  The next time it is opened
 625		it will have to reinitialized.  Set a flag to indicate this.
 626	---------------------------------------------------------------------- */
 627
 628	/* Prevent future Digi programmed interrupts from coming active */
 629
 630	ch->asyncflags &= ~ASYNC_INITIALIZED;
 631	restore_flags(flags);
 632
 633} /* End shutdown */
 634
 635/* ------------------ Begin pc_hangup  ------------------------- */
 636
 637static void pc_hangup(struct tty_struct *tty)
 638{ /* Begin pc_hangup */
 639
 640	struct channel *ch;
 641	
 642	/* ---------------------------------------------------------
 643		verifyChannel returns the channel from the tty struct
 644		if it is valid.  This serves as a sanity check.
 645	------------------------------------------------------------- */
 646
 647	if ((ch = verifyChannel(tty)) != NULL) 
 648	{ /* Begin if ch != NULL */
 649
 650		unsigned long flags;
 651
 652		save_flags(flags);
 653		cli();
 654		if (tty->driver->flush_buffer)
 655			tty->driver->flush_buffer(tty);
 656		tty_ldisc_flush(tty);
 657		shutdown(ch);
 658
 659		ch->tty   = NULL;
 660		ch->event = 0;
 661		ch->count = 0;
 662		restore_flags(flags);
 663		ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
 664		wake_up_interruptible(&ch->open_wait);
 665
 666	} /* End if ch != NULL */
 667
 668} /* End pc_hangup */
 669
 670/* ------------------ Begin pc_write  ------------------------- */
 671
 672static int pc_write(struct tty_struct * tty,
 673                    const unsigned char *buf, int bytesAvailable)
 674{ /* Begin pc_write */
 675
 676	register unsigned int head, tail;
 677	register int dataLen;
 678	register int size;
 679	register int amountCopied;
 680
 681
 682	struct channel *ch;
 683	unsigned long flags;
 684	int remain;
 685	volatile struct board_chan *bc;
 686
 687
 688	/* ----------------------------------------------------------------
 689		pc_write is primarily called directly by the kernel routine
 690		tty_write (Though it can also be called by put_char) found in
 691		tty_io.c.  pc_write is passed a line discipline buffer where 
 692		the data to be written out is stored.  The line discipline 
 693		implementation itself is done at the kernel level and is not 
 694		brought into the driver.  
 695	------------------------------------------------------------------- */
 696
 697	/* ---------------------------------------------------------
 698		verifyChannel returns the channel from the tty struct
 699		if it is valid.  This serves as a sanity check.
 700	------------------------------------------------------------- */
 701
 702	if ((ch = verifyChannel(tty)) == NULL)
 703		return 0;
 704
 705	/* Make a pointer to the channel data structure found on the board. */
 706
 707	bc   = ch->brdchan;
 708	size = ch->txbufsize;
 709
 710	amountCopied = 0;
 711	save_flags(flags);
 712	cli();
 713
 714	globalwinon(ch);
 715
 716	head = bc->tin & (size - 1);
 717	tail = bc->tout;
 718
 719	if (tail != bc->tout)
 720		tail = bc->tout;
 721	tail &= (size - 1);
 722
 723	/*	If head >= tail, head has not wrapped around. */ 
 724	if (head >= tail) 
 725	{ /* Begin head has not wrapped */
 726
 727		/* ---------------------------------------------------------------
 728			remain (much like dataLen above) represents the total amount of
 729			space available on the card for data.  Here dataLen represents
 730			the space existing between the head pointer and the end of 
 731			buffer.  This is important because a memcpy cannot be told to
 732			automatically wrap around when it hits the buffer end.
 733		------------------------------------------------------------------ */ 
 734
 735		dataLen = size - head;
 736		remain = size - (head - tail) - 1;
 737
 738	} /* End head has not wrapped */
 739	else 
 740	{ /* Begin head has wrapped around */
 741
 742		remain = tail - head - 1;
 743		dataLen = remain;
 744
 745	} /* End head has wrapped around */
 746
 747	/* -------------------------------------------------------------------
 748			Check the space on the card.  If we have more data than 
 749			space; reduce the amount of data to fit the space.
 750	---------------------------------------------------------------------- */
 751
 752	bytesAvailable = min(remain, bytesAvailable);
 753
 754	txwinon(ch);
 755	while (bytesAvailable > 0) 
 756	{ /* Begin while there is data to copy onto card */
 757
 758		/* -----------------------------------------------------------------
 759			If head is not wrapped, the below will make sure the first 
 760			data copy fills to the end of card buffer.
 761		------------------------------------------------------------------- */
 762
 763		dataLen = min(bytesAvailable, dataLen);
 764		memcpy(ch->txptr + head, buf, dataLen);
 765		buf += dataLen;
 766		head += dataLen;
 767		amountCopied += dataLen;
 768		bytesAvailable -= dataLen;
 769
 770		if (head >= size) 
 771		{
 772			head = 0;
 773			dataLen = tail;
 774		}
 775
 776	} /* End while there is data to copy onto card */
 777
 778	ch->statusflags |= TXBUSY;
 779	globalwinon(ch);
 780	bc->tin = head;
 781
 782	if ((ch->statusflags & LOWWAIT) == 0) 
 783	{
 784		ch->statusflags |= LOWWAIT;
 785		bc->ilow = 1;
 786	}
 787	memoff(ch);
 788	restore_flags(flags);
 789
 790	return(amountCopied);
 791
 792} /* End pc_write */
 793
 794/* ------------------ Begin pc_put_char  ------------------------- */
 795
 796static void pc_put_char(struct tty_struct *tty, unsigned char c)
 797{ /* Begin pc_put_char */
 798
 799   
 800	pc_write(tty, &c, 1);
 801	return;
 802
 803} /* End pc_put_char */
 804
 805/* ------------------ Begin pc_write_room  ------------------------- */
 806
 807static int pc_write_room(struct tty_struct *tty)
 808{ /* Begin pc_write_room */
 809
 810	int remain;
 811	struct channel *ch;
 812	unsigned long flags;
 813	unsigned int head, tail;
 814	volatile struct board_chan *bc;
 815
 816	remain = 0;
 817
 818	/* ---------------------------------------------------------
 819		verifyChannel returns the channel from the tty struct
 820		if it is valid.  This serves as a sanity check.
 821	------------------------------------------------------------- */
 822
 823	if ((ch = verifyChannel(tty)) != NULL) 
 824	{
 825		save_flags(flags);
 826		cli();
 827		globalwinon(ch);
 828
 829		bc   = ch->brdchan;
 830		head = bc->tin & (ch->txbufsize - 1);
 831		tail = bc->tout;
 832
 833		if (tail != bc->tout)
 834			tail = bc->tout;
 835		/* Wrap tail if necessary */
 836		tail &= (ch->txbufsize - 1);
 837
 838		if ((remain = tail - head - 1) < 0 )
 839			remain += ch->txbufsize;
 840
 841		if (remain && (ch->statusflags & LOWWAIT) == 0) 
 842		{
 843			ch->statusflags |= LOWWAIT;
 844			bc->ilow = 1;
 845		}
 846		memoff(ch);
 847		restore_flags(flags);
 848	}
 849
 850	/* Return how much room is left on card */
 851	return remain;
 852
 853} /* End pc_write_room */
 854
 855/* ------------------ Begin pc_chars_in_buffer  ---------------------- */
 856
 857static int pc_chars_in_buffer(struct tty_struct *tty)
 858{ /* Begin pc_chars_in_buffer */
 859
 860	int chars;
 861	unsigned int ctail, head, tail;
 862	int remain;
 863	unsigned long flags;
 864	struct channel *ch;
 865	volatile struct board_chan *bc;
 866
 867
 868	/* ---------------------------------------------------------
 869		verifyChannel returns the channel from the tty struct
 870		if it is valid.  This serves as a sanity check.
 871	------------------------------------------------------------- */
 872
 873	if ((ch = verifyChannel(tty)) == NULL)
 874		return(0);
 875
 876	save_flags(flags);
 877	cli();
 878	globalwinon(ch);
 879
 880	bc = ch->brdchan;
 881	tail = bc->tout;
 882	head = bc->tin;
 883	ctail = ch->mailbox->cout;
 884
 885	if (tail == head && ch->mailbox->cin == ctail && bc->tbusy == 0)
 886		chars = 0;
 887	else 
 888	{ /* Begin if some space on the card has been used */
 889
 890		head = bc->tin & (ch->txbufsize - 1);
 891		tail &= (ch->txbufsize - 1);
 892
 893		/*  --------------------------------------------------------------
 894			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.
 896			Not the amount of bytes empty.
 897		------------------------------------------------------------------- */
 898
 899		if ((remain = tail - head - 1) < 0 )
 900			remain += ch->txbufsize;
 901
 902		chars = (int)(ch->txbufsize - remain);
 903
 904		/* -------------------------------------------------------------  
 905			Make it possible to wakeup anything waiting for output
 906			in tty_ioctl.c, etc.
 907
 908			If not already set.  Setup an event to indicate when the
 909			transmit buffer empties 
 910		----------------------------------------------------------------- */
 911
 912		if (!(ch->statusflags & EMPTYWAIT))
 913			setup_empty_event(tty,ch);
 914
 915	} /* End if some space on the card has been used */
 916
 917	memoff(ch);
 918	restore_flags(flags);
 919
 920	/* Return number of characters residing on card. */
 921	return(chars);
 922
 923} /* End pc_chars_in_buffer */
 924
 925/* ------------------ Begin pc_flush_buffer  ---------------------- */
 926
 927static void pc_flush_buffer(struct tty_struct *tty)
 928{ /* Begin pc_flush_buffer */
 929
 930	unsigned int tail;
 931	unsigned long flags;
 932	struct channel *ch;
 933	volatile struct board_chan *bc;
 934
 935
 936	/* ---------------------------------------------------------
 937		verifyChannel returns the channel from the tty struct
 938		if it is valid.  This serves as a sanity check.
 939	------------------------------------------------------------- */
 940
 941	if ((ch = verifyChannel(tty)) == NULL)
 942		return;
 943
 944	save_flags(flags);
 945	cli();
 946
 947	globalwinon(ch);
 948
 949	bc   = ch->brdchan;
 950	tail = bc->tout;
 951
 952	/* Have FEP move tout pointer; effectively flushing transmit buffer */
 953
 954	fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
 955
 956	memoff(ch);
 957	restore_flags(flags);
 958
 959	wake_up_interruptible(&tty->write_wait);
 960	tty_wakeup(tty);
 961
 962} /* End pc_flush_buffer */
 963
 964/* ------------------ Begin pc_flush_chars  ---------------------- */
 965
 966static void pc_flush_chars(struct tty_struct *tty)
 967{ /* Begin pc_flush_chars */
 968
 969	struct channel * ch;
 970
 971	/* ---------------------------------------------------------
 972		verifyChannel returns the channel from the tty struct
 973		if it is valid.  This serves as a sanity check.
 974	------------------------------------------------------------- */
 975
 976	if ((ch = verifyChannel(tty)) != NULL) 
 977	{
 978		unsigned long flags;
 979
 980		save_flags(flags);
 981		cli();
 982
 983		/* ----------------------------------------------------------------
 984			If not already set and the transmitter is busy setup an event
 985			to indicate when the transmit empties.
 986		------------------------------------------------------------------- */
 987
 988		if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
 989			setup_empty_event(tty,ch);
 990
 991		restore_flags(flags);
 992	}
 993
 994} /* End pc_flush_chars */
 995
 996/* ------------------ Begin block_til_ready  ---------------------- */
 997
 998static int block_til_ready(struct tty_struct *tty, 
 999                           struct file *filp, struct channel *ch)
1000{ /* Begin block_til_ready */
1001
1002	DECLARE_WAITQUEUE(wait,current);
1003	int	retval, do_clocal = 0;
1004	unsigned long flags;
1005
1006
1007	if (tty_hung_up_p(filp))
1008	{
1009		if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1010			retval = -EAGAIN;
1011		else
1012			retval = -ERESTARTSYS;	
1013		return(retval);
1014	}
1015
1016	/* ----------------------------------------------------------------- 
1017		If the device is in the middle of being closed, then block
1018		until it's done, and then try again.
1019	-------------------------------------------------------------------- */
1020	if (ch->asyncflags & ASYNC_CLOSING) 
1021	{
1022		interruptible_sleep_on(&ch->close_wait);
1023
1024		if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1025			return -EAGAIN;
1026		else
1027			return -ERESTARTSYS;
1028	}
1029
1030	if (filp->f_flags & O_NONBLOCK) 
1031	{
1032		/* ----------------------------------------------------------------- 
1033	  	 If non-blocking mode is set, then make the check up front
1034	  	 and then exit.
1035		-------------------------------------------------------------------- */
1036
1037		ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1038
1039		return 0;
1040	}
1041
1042
1043	if (tty->termios->c_cflag & CLOCAL)
1044		do_clocal = 1;
1045	
1046   /* Block waiting for the carrier detect and the line to become free */
1047	
1048	retval = 0;
1049	add_wait_queue(&ch->open_wait, &wait);
1050	save_flags(flags);
1051	cli();
1052
1053
1054	/* We dec count so that pc_close will know when to free things */
1055	if (!tty_hung_up_p(filp))
1056		ch->count--;
1057
1058	restore_flags(flags);
1059
1060	ch->blocked_open++;
1061
1062	while(1) 
1063	{ /* Begin forever while  */
1064
1065		set_current_state(TASK_INTERRUPTIBLE);
1066
1067		if (tty_hung_up_p(filp) ||
1068		    !(ch->asyncflags & ASYNC_INITIALIZED)) 
1069		{
1070			if (ch->asyncflags & ASYNC_HUP_NOTIFY)
1071				retval = -EAGAIN;
1072			else
1073				retval = -ERESTARTSYS;	
1074			break;
1075		}
1076
1077		if (!(ch->asyncflags & ASYNC_CLOSING) && 
1078			  (do_clocal || (ch->imodem & ch->dcd)))
1079			break;
1080
1081		if (signal_pending(current)) 
1082		{
1083			retval = -ERESTARTSYS;
1084			break;
1085		}
1086
1087		/* ---------------------------------------------------------------
1088			Allow someone else to be scheduled.  We will occasionally go
1089			through this loop until one of the above conditions change.
1090			The below schedule call will allow other processes to enter and
1091			prevent this loop from hogging the cpu.
1092		------------------------------------------------------------------ */
1093		schedule();
1094
1095	} /* End forever while  */
1096
1097	current->state = TASK_RUNNING;
1098	remove_wait_queue(&ch->open_wait, &wait);
1099	cli();
1100	if (!tty_hung_up_p(filp))
1101		ch->count++;
1102	restore_flags(flags);
1103
1104	ch->blocked_open--;
1105
1106	if (retval)
1107		return retval;
1108
1109	ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
1110
1111	return 0;
1112
1113} /* End block_til_ready */	
1114
1115/* ------------------ Begin pc_open  ---------------------- */
1116
1117static int pc_open(struct tty_struct *tty, struct file * filp)
1118{ /* Begin pc_open */
1119
1120	struct channel *ch;
1121	unsigned long flags;
1122	int line, retval, boardnum;
1123	volatile struct board_chan *bc;
1124	volatile unsigned int head;
1125
1126	line = tty->index;
1127	if (line < 0 || line >= nbdevs) 
1128	{
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
1135	ch = &digi_channels[line];
1136	boardnum = ch->boardnum;
1137
1138	/* Check status of board configured in system.  */
1139
1140	/* -----------------------------------------------------------------
1141		I check to see if the epca_setup routine detected an user error.  
1142		It might be better to put this in pc_init, but for the moment it
1143		goes here.
1144	---------------------------------------------------------------------- */
1145
1146	if (invalid_lilo_config)
1147	{
1148		if (setup_error_code & INVALID_BOARD_TYPE)
1149			printk(KERN_ERR "<Error> - pc_open: Invalid board type specified in LILO command\n");
1150
1151		if (setup_error_code & INVALID_NUM_PORTS)
1152			printk(KERN_ERR "<Error> - pc_open: Invalid number of ports specified in LILO command\n");
1153
1154		if (setup_error_code & INVALID_MEM_BASE)
1155			printk(KERN_ERR "<Error> - pc_open: Invalid board memory address specified in LILO command\n");
1156
1157		if (setup_error_code & INVALID_PORT_BASE)
1158			printk(KERN_ERR "<Error> - pc_open: Invalid board port address specified in LILO command\n");
1159
1160		if (setup_error_code & INVALID_BOARD_STATUS)
1161			printk(KERN_ERR "<Error> - pc_open: Invalid board status specified in LILO command\n");
1162
1163		if (setup_error_code & INVALID_ALTPIN)
1164			printk(KERN_ERR "<Error> - pc_open: Invalid board altpin specified in LILO command\n");
1165
1166		tty->driver_data = NULL;   /* Mark this device as 'down' */
1167		return(-ENODEV);
1168	}
1169
1170	if ((boardnum >= num_cards) || (boards[boardnum].status == DISABLED)) 
1171	{
1172		tty->driver_data = NULL;   /* Mark this device as 'down' */
1173		return(-ENODEV);
1174	}
1175	
1176	if (( bc = ch->brdchan) == 0) 
1177	{
1178		tty->driver_data = NULL;
1179		return(-ENODEV);
1180	}
1181
1182	/* ------------------------------------------------------------------
1183		Every time a channel is opened, increment a counter.  This is 
1184		necessary because we do not wish to flush and shutdown the channel
1185		until the last app holding the channel open, closes it.	 	
1186	--------------------------------------------------------------------- */
1187
1188	ch->count++;
1189
1190	/* ----------------------------------------------------------------
1191		Set a kernel structures pointer to our local channel 
1192		structure.  This way we can get to it when passed only
1193		a tty struct.
1194	------------------------------------------------------------------ */
1195
1196	tty->driver_data = ch;
1197	
1198	/* ----------------------------------------------------------------
1199		If this is the first time the channel has been opened, initialize
1200		the tty->termios struct otherwise let pc_close handle it.
1201	-------------------------------------------------------------------- */
1202
1203	save_flags(flags);
1204	cli();
1205
1206	globalwinon(ch);
1207	ch->statusflags = 0;
1208
1209	/* Save boards current modem status */
1210	ch->imodem = bc->mstat;
1211
1212	/* ----------------------------------------------------------------
1213	   Set receive head and tail ptrs to each other.  This indicates
1214	   no data available to read.
1215	----------------------------------------------------------------- */
1216	head = bc->rin;
1217	bc->rout = head;
1218
1219	/* Set the channels associated tty structure */
1220	ch->tty = tty;
1221
1222	/* -----------------------------------------------------------------
1223		The below routine generally sets up parity, baud, flow control 
1224		issues, etc.... It effect both control flags and input flags.
1225	-------------------------------------------------------------------- */
1226	epcaparam(tty,ch);
1227
1228	ch->asyncflags |= ASYNC_INITIALIZED;
1229	memoff(ch);
1230
1231	restore_flags(flags);
1232
1233	retval = block_til_ready(tty, filp, ch);
1234	if (retval)
1235	{
1236		return retval;
1237	}
1238
1239	/* -------------------------------------------------------------
1240		Set this again in case a hangup set it to zero while this 
1241		open() was waiting for the line...
1242	--------------------------------------------------------------- */
1243	ch->tty = tty;
1244
1245	save_flags(flags);
1246	cli();
1247	globalwinon(ch);
1248
1249	/* Enable Digi Data events */
1250	bc->idata = 1;
1251
1252	memoff(ch);
1253	restore_flags(flags);
1254
1255	return 0;
1256
1257} /* End pc_open */
1258
1259#ifdef MODULE
1260static int __init epca_module_init(void)
1261{ /* Begin init_module */
1262
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}
1274
1275module_init(epca_module_init);
1276#endif
1277
1278#ifdef ENABLE_PCI
1279static struct pci_driver epca_driver;
1280#endif
1281
1282#ifdef MODULE
1283/* -------------------- Begin cleanup_module  ---------------------- */
1284
1285static void __exit epca_module_exit(void)
1286{
1287
1288	int               count, crd;
1289	struct board_info *bd;
1290	struct channel    *ch;
1291	unsigned long     flags;
1292
1293	del_timer_sync(&epca_timer);
1294
1295	save_flags(flags);
1296	cli();
1297
1298	if ((tty_unregister_driver(pc_driver)) ||  
1299	    (tty_unregister_driver(pc_info)))
1300	{
1301		printk(KERN_WARNING "<Error> - DIGI : cleanup_module failed to un-register tty driver\n");
1302		restore_flags(flags);
1303		return;
1304	}
1305	put_tty_driver(pc_driver);
1306	put_tty_driver(pc_info);
1307
1308	for (crd = 0; crd < num_cards; crd++) 
1309	{ /* Begin for each card */
1310
1311		bd = &boards[crd];
1312
1313		if (!bd)
1314		{ /* Begin sanity check */
1315			printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1316			return;
1317		} /* End sanity check */
1318
1319		ch = card_ptr[crd]; 
1320
1321		for (count = 0; count < bd->numports; count++, ch++) 
1322		{ /* Begin for each port */
1323
1324			if (ch) 
1325			{
1326				if (ch->tty)
1327					tty_hangup(ch->tty);
1328				kfree(ch->tmp_buf);
1329			}
1330
1331		} /* End for each port */
1332	} /* End for each card */
1333
1334#ifdef ENABLE_PCI
1335	pci_unregister_driver (&epca_driver);
1336#endif
1337
1338	restore_flags(flags);
1339
1340}
1341module_exit(epca_module_exit);
1342#endif /* MODULE */
1343
1344static struct tty_operations pc_ops = {
1345	.open = pc_open,
1346	.close = pc_close,
1347	.write = pc_write,
1348	.write_room = pc_write_room,
1349	.flush_buffer = pc_flush_buffer,
1350	.chars_in_buffer = pc_chars_in_buffer,
1351	.flush_chars = pc_flush_chars,
1352	.put_char = pc_put_char,
1353	.ioctl = pc_ioctl,
1354	.set_termios = pc_set_termios,
1355	.stop = pc_stop,
1356	.start = pc_start,
1357	.throttle = pc_throttle,
1358	.unthrottle = pc_unthrottle,
1359	.hangup = pc_hangup,
1360};
1361
1362static int info_open(struct tty_struct *tty, struct file * filp)
1363{
1364	return 0;
1365}
1366
1367static struct tty_operations info_ops = {
1368	.open = info_open,
1369	.ioctl = info_ioctl,
1370};
1371
1372/* ------------------ Begin pc_init  ---------------------- */
1373
1374int __init pc_init(void)
1375{ /* 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;
1394	struct board_info *bd;
1395	unsigned char board_id = 0;
1396
1397#ifdef ENABLE_PCI
1398	int pci_boards_found, pci_count;
1399
1400	pci_count = 0;
1401#endif /* ENABLE_PCI */
1402
1403	pc_driver = alloc_tty_driver(MAX_ALLOC);
1404	if (!pc_driver)
1405		return -ENOMEM;
1406
1407	pc_info = alloc_tty_driver(MAX_ALLOC);
1408	if (!pc_info) {
1409		put_tty_driver(pc_driver);
1410		return -ENOMEM;
1411	}
1412
1413	/* -----------------------------------------------------------------------
1414		If epca_setup has not been ran by LILO set num_cards to defaults; copy
1415		board structure defined by digiConfig into drivers board structure.
1416		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.
1418	-------------------------------------------------------------------------- */
1419	if (!liloconfig)
1420	{ /* Begin driver has been configured via. epcaconfig */
1421
1422		nbdevs = NBDEVS;
1423		num_cards = NUMCARDS;
1424		memcpy((void *)&boards, (void *)&static_boards,
1425		       (sizeof(struct board_info) * NUMCARDS));
1426	} /* End driver has been configured via. epcaconfig */
1427
1428	/* -----------------------------------------------------------------
1429		Note : If lilo was used to configure the driver and the 
1430		ignore epcaconfig option was choosen (digiepca=2) then 
1431		nbdevs and num_cards will equal 0 at this point.  This is
1432		okay; PCI cards will still be picked up if detected.
1433	--------------------------------------------------------------------- */
1434
1435	/*  -----------------------------------------------------------
1436		Set up interrupt, we will worry about memory allocation in
1437		post_fep_init. 
1438	--------------------------------------------------------------- */
1439
1440
1441	printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
1442
1443#ifdef ENABLE_PCI
1444
1445	/* ------------------------------------------------------------------
1446		NOTE : This code assumes that the number of ports found in 
1447		       the boards array is correct.  This could be wrong if
1448		       the card in question is PCI (And therefore has no ports 
1449		       entry in the boards structure.)  The rest of the 
1450		       information will be valid for PCI because the beginning
1451		       of pc_init scans for PCI and determines i/o and base
1452		       memory addresses.  I am not sure if it is possible to 
1453		       read the number of ports supported by the card prior to
1454		       it being booted (Since that is the state it is in when 
1455		       pc_init is run).  Because it is not possible to query the
1456		       number of supported ports until after the card has booted;
1457		       we are required to calculate the card_ptrs as the card is	 
1458		       is initialized (Inside post_fep_init).  The negative thing
1459		       about this approach is that digiDload's call to GET_INFO
1460		       will have a bad port value.  (Since this is called prior
1461		       to post_fep_init.)
1462
1463	--------------------------------------------------------------------- */
1464  
1465	pci_boards_found = 0;
1466	if(num_cards < MAXBOARDS)
1467		pci_boards_found += init_PCI();
1468	num_cards += pci_boards_found;
1469
1470#endif /* ENABLE_PCI */
1471
1472	pc_driver->owner = THIS_MODULE;
1473	pc_driver->name = "ttyD"; 
1474	pc_driver->devfs_name = "tts/D";
1475	pc_driver->major = DIGI_MAJOR; 
1476	pc_driver->minor_start = 0;
1477	pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1478	pc_driver->subtype = SERIAL_TYPE_NORMAL;
1479	pc_driver->init_termios = tty_std_termios;
1480	pc_driver->init_termios.c_iflag = 0;
1481	pc_driver->init_termios.c_oflag = 0;
1482	pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1483	pc_driver->init_termios.c_lflag = 0;
1484	pc_driver->flags = TTY_DRIVER_REAL_RAW;
1485	tty_set_operations(pc_driver, &pc_ops);
1486
1487	pc_info->owner = THIS_MODULE;
1488	pc_info->name = "digi_ctl";
1489	pc_info->major = DIGIINFOMAJOR;
1490	pc_info->minor_start = 0;
1491	pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1492	pc_info->subtype = SERIAL_TYPE_INFO;
1493	pc_info->init_termios = tty_std_termios;
1494	pc_info->init_termios.c_iflag = 0;
1495	pc_info->init_termios.c_oflag = 0;
1496	pc_info->init_termios.c_lflag = 0;
1497	pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1498	pc_info->flags = TTY_DRIVER_REAL_RAW;
1499	tty_set_operations(pc_info, &info_ops);
1500
1501
1502	save_flags(flags);
1503	cli();
1504
1505	for (crd = 0; crd < num_cards; crd++) 
1506	{ /* Begin for each card */
1507
1508		/*  ------------------------------------------------------------------
1509			This is where the appropriate memory handlers for the hardware is
1510			set.  Everything at runtime blindly jumps through these vectors.
1511		---------------------------------------------------------------------- */
1512
1513		/* defined in epcaconfig.h */
1514		bd = &boards[crd];
1515
1516		switch (bd->type)
1517		{ /* Begin switch on bd->type {board type} */
1518			case PCXEM:
1519			case EISAXEM:
1520				bd->memwinon     = pcxem_memwinon ;
1521				bd->memwinoff    = pcxem_memwinoff ;
1522				bd->globalwinon  = pcxem_globalwinon ;
1523				bd->txwinon      = pcxem_txwinon ;
1524				bd->rxwinon      = pcxem_rxwinon ;
1525				bd->memoff       = pcxem_memoff ;
1526				bd->assertgwinon = dummy_assertgwinon;
1527				bd->assertmemoff = dummy_assertmemoff;
1528				break;
1529
1530			case PCIXEM:
1531			case PCIXRJ:
1532			case PCIXR:
1533				bd->memwinon     = dummy_memwinon;
1534				bd->memwinoff    = dummy_memwinoff;
1535				bd->globalwinon  = dummy_globalwinon;
1536				bd->txwinon      = dummy_txwinon;
1537				bd->rxwinon      = dummy_rxwinon;
1538				bd->memoff       = dummy_memoff;
1539				bd->assertgwinon = dummy_assertgwinon;
1540				bd->assertmemoff = dummy_assertmemoff;
1541				break;
1542
1543			case PCXE:
1544			case PCXEVE:
1545
1546				bd->memwinon     = pcxe_memwinon;
1547				bd->memwinoff    = pcxe_memwinoff;
1548				bd->globalwinon  = pcxe_globalwinon;
1549				bd->txwinon      = pcxe_txwinon;
1550				bd->rxwinon      = pcxe_rxwinon;
1551				bd->memoff       = pcxe_memoff;
1552				bd->assertgwinon = dummy_assertgwinon;
1553				bd->assertmemoff = dummy_assertmemoff;
1554				break;
1555
1556			case PCXI:
1557			case PC64XE:
1558
1559				bd->memwinon     = pcxi_memwinon;
1560				bd->memwinoff    = pcxi_memwinoff;
1561				bd->globalwinon  = pcxi_globalwinon;
1562				bd->txwinon      = pcxi_txwinon;
1563				bd->rxwinon      = pcxi_rxwinon;
1564				bd->memoff       = pcxi_memoff;
1565				bd->assertgwinon = pcxi_assertgwinon;
1566				bd->assertmemoff = pcxi_assertmemoff;
1567				break;
1568
1569			default:
1570				break;
1571
1572		} /* End switch on bd->type */
1573
1574		/* ---------------------------------------------------------------
1575			Some cards need a memory segment to be defined for use in 
1576			transmit and receive windowing operations.  These boards
1577			are listed in the below switch.  In the case of the XI the
1578			amount of memory on the board is variable so the memory_seg
1579			is also variable.  This code determines what they segment 
1580			should be.
1581		----------------------------------------------------------------- */
1582
1583		switch (bd->type)
1584		{ /* Begin switch on bd->type {board type} */
1585
1586			case PCXE:
1587			case PCXEVE:
1588			case PC64XE:
1589				bd->memory_seg = 0xf000;
1590			break;
1591
1592			case PCXI:
1593				board_id = inb((int)bd->port);
1594				if ((board_id & 0x1) == 0x1) 
1595				{ /* Begin it's an XI card */ 
1596
1597					/* Is it a 64K board */
1598					if ((board_id & 0x30) == 0) 
1599						bd->memory_seg = 0xf000;
1600
1601					/* Is it a 128K board */
1602					if ((board_id & 0x30) == 0x10) 
1603						bd->memory_seg = 0xe000;
1604
1605					/* Is is a 256K board */	
1606					if ((board_id & 0x30) == 0x20) 
1607						bd->memory_seg = 0xc000;
1608
1609					/* Is it a 512K board */
1610					if ((board_id & 0x30) == 0x30) 
1611						bd->memory_seg = 0x8000;
1612
1613				} /* End it is an XI card */
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;
1619
1620		} /* End switch on bd->type */
1621
1622	} /* End for each card */
1623
1624	if (tty_register_driver(pc_driver))
1625		panic("Couldn't register Digi PC/ driver");
1626
1627	if (tty_register_driver(pc_info))
1628		panic("Couldn't register Digi PC/ info ");
1629
1630	/* -------------------------------------------------------------------
1631	   Start up the poller to check for events on all enabled boards
1632	---------------------------------------------------------------------- */
1633
1634	init_timer(&epca_timer);
1635	epca_timer.function = epcapoll;
1636	mod_timer(&epca_timer, jiffies + HZ/25);
1637
1638	restore_flags(flags);
1639
1640	return 0;
1641
1642} /* End pc_init */
1643
1644/* ------------------ Begin post_fep_init  ---------------------- */
1645
1646static void post_fep_init(unsigned int crd)
1647{ /* Begin post_fep_init */
1648
1649	int i;
1650	unchar *memaddr;
1651	volatile struct global_data *gd;
1652	struct board_info *bd;
1653	volatile struct board_chan *bc;
1654	struct channel *ch; 
1655	int shrinkmem = 0, lowwater ; 
1656 
1657	/*  -------------------------------------------------------------
1658		This call is made by the user via. the ioctl call DIGI_INIT.
1659		It is responsible for setting up all the card specific stuff.
1660	---------------------------------------------------------------- */
1661	bd = &boards[crd];
1662
1663	/* -----------------------------------------------------------------
1664		If this is a PCI board, get the port info.  Remember PCI cards
1665		do not have entries into the epcaconfig.h file, so we can't get 
1666		the number of ports from it.  Unfortunetly, this means that anyone
1667		doing a DIGI_GETINFO before the board has booted will get an invalid
1668		number of ports returned (It should return 0).  Calls to DIGI_GETINFO
1669		after DIGI_INIT has been called will return the proper values. 
1670	------------------------------------------------------------------- */
1671
1672	if (bd->type >= PCIXEM) /* If the board in question is PCI */
1673	{ /* Begin get PCI number of ports */
1674
1675		/* --------------------------------------------------------------------
1676			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
1678			the same memory offset for the channel data.  This will have to be
1679			changed if we ever develop a PCI/XE card.  NOTE : The FEP manual
1680			states that the port offset is 0xC22 as opposed to 0xC02.  This is
1681			only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
1682			On the PCI cards the number of ports is determined by reading a 
1683			ID PROM located in the box attached to the card.  The card can then
1684			determine the index the id to determine the number of ports available.
1685			(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)).  
1687		------------------------------------------------------------------------ */ 
1688
1689		bd->numports = (unsigned short)*(unsigned char *)bus_to_virt((unsigned long)
1690                                                       (bd->re_map_membase + XEMPORTS));
1691
1692		
1693		epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
1694		nbdevs += (bd->numports);
1695
1696	} /* End get PCI number of ports */
1697
1698	if (crd != 0)
1699		card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1700	else
1701		card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
1702
1703	ch = card_ptr[crd];
1704
1705
1706	epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1707
1708	memaddr = (unchar *)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…

Large files files are truncated, but you can click here to view the full file