/drivers/char/epca.c

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

Large files are truncated click here to view the full file

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