PageRenderTime 68ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  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 for that.
  1295. */
  1296. memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
  1297. /* -----------------------------------------------------------------
  1298. The below assignment will set bc to point at the BEGINING of
  1299. the cards channel structures. For 1 card there will be between
  1300. 8 and 64 of these structures.
  1301. -------------------------------------------------------------------- */
  1302. bc = (volatile struct board_chan *)((ulong)memaddr + CHANSTRUCT);
  1303. /* -------------------------------------------------------------------
  1304. The below assignment will set gd to point at the BEGINING of
  1305. global memory address 0xc00. The first data in that global
  1306. memory actually starts at address 0xc1a. The command in
  1307. pointer begins at 0xd10.
  1308. ---------------------------------------------------------------------- */
  1309. gd = (volatile struct global_data *)((ulong)memaddr + GLOBAL);
  1310. /* --------------------------------------------------------------------
  1311. XEPORTS (address 0xc22) points at the number of channels the
  1312. card supports. (For 64XE, XI, XEM, and XR use 0xc02)
  1313. ----------------------------------------------------------------------- */
  1314. if (((bd->type == PCXEVE) | (bd->type == PCXE)) &&
  1315. (*(ushort *)((ulong)memaddr + XEPORTS) < 3))
  1316. shrinkmem = 1;
  1317. if (bd->type < PCIXEM)
  1318. if (!request_region((int)bd->port, 4, board_desc[bd->type]))
  1319. return;
  1320. memwinon(bd, 0);
  1321. /* --------------------------------------------------------------------
  1322. Remember ch is the main drivers channels structure, while bc is
  1323. the cards channel structure.
  1324. ------------------------------------------------------------------------ */
  1325. /* For every port on the card do ..... */
  1326. for (i = 0; i < bd->numports; i++, ch++, bc++)
  1327. { /* Begin for each port */
  1328. ch->brdchan = bc;
  1329. ch->mailbox = gd;
  1330. INIT_WORK(&ch->tqueue, do_softint, ch);
  1331. ch->board = &boards[crd];
  1332. switch (bd->type)
  1333. { /* Begin switch bd->type */
  1334. /* ----------------------------------------------------------------
  1335. Since some of the boards use different bitmaps for their
  1336. control signals we cannot hard code these values and retain
  1337. portability. We virtualize this data here.
  1338. ------------------------------------------------------------------- */
  1339. case EISAXEM:
  1340. case PCXEM:
  1341. case PCIXEM:
  1342. case PCIXRJ:
  1343. case PCIXR:
  1344. ch->m_rts = 0x02 ;
  1345. ch->m_dcd = 0x80 ;
  1346. ch->m_dsr = 0x20 ;
  1347. ch->m_cts = 0x10 ;
  1348. ch->m_ri = 0x40 ;
  1349. ch->m_dtr = 0x01 ;
  1350. break;
  1351. case PCXE:
  1352. case PCXEVE:
  1353. case PCXI:
  1354. case PC64XE:
  1355. ch->m_rts = 0x02 ;
  1356. ch->m_dcd = 0x08 ;
  1357. ch->m_dsr = 0x10 ;
  1358. ch->m_cts = 0x20 ;
  1359. ch->m_ri = 0x40 ;
  1360. ch->m_dtr = 0x80 ;
  1361. break;
  1362. } /* End switch bd->type */
  1363. if (boards[crd].altpin)
  1364. {
  1365. ch->dsr = ch->m_dcd;
  1366. ch->dcd = ch->m_dsr;
  1367. ch->digiext.digi_flags |= DIGI_ALTPIN;
  1368. }
  1369. else
  1370. {
  1371. ch->dcd = ch->m_dcd;
  1372. ch->dsr = ch->m_dsr;
  1373. }
  1374. ch->boardnum = crd;
  1375. ch->channelnum = i;
  1376. ch->magic = EPCA_MAGIC;
  1377. ch->tty = NULL;
  1378. if (shrinkmem)
  1379. {
  1380. fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
  1381. shrinkmem = 0;
  1382. }
  1383. switch (bd->type)
  1384. { /* Begin switch bd->type */
  1385. case PCIXEM:
  1386. case PCIXRJ:
  1387. case PCIXR:
  1388. /* Cover all the 2MEG cards */
  1389. ch->txptr = memaddr + (((bc->tseg) << 4) & 0x1fffff);
  1390. ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x1fffff);
  1391. ch->txwin = FEPWIN | ((bc->tseg) >> 11);
  1392. ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
  1393. break;
  1394. case PCXEM:
  1395. case EISAXEM:
  1396. /* Cover all the 32K windowed cards */
  1397. /* Mask equal to window size - 1 */
  1398. ch->txptr = memaddr + (((bc->tseg) << 4) & 0x7fff);
  1399. ch->rxptr = memaddr + (((bc->rseg) << 4) & 0x7fff);
  1400. ch->txwin = FEPWIN | ((bc->tseg) >> 11);
  1401. ch->rxwin = FEPWIN | ((bc->rseg) >> 11);
  1402. break;
  1403. case PCXEVE:
  1404. case PCXE:
  1405. ch->txptr = memaddr + (((bc->tseg - bd->memory_seg) << 4) & 0x1fff);
  1406. ch->txwin = FEPWIN | ((bc->tseg - bd->memory_seg) >> 9);
  1407. ch->rxptr = memaddr + (((bc->rseg - bd->memory_seg) << 4) & 0x1fff);
  1408. ch->rxwin = FEPWIN | ((bc->rseg - bd->memory_seg) >>9 );
  1409. break;
  1410. case PCXI:
  1411. case PC64XE:
  1412. ch->txptr = memaddr + ((bc->tseg - bd->memory_seg) << 4);
  1413. ch->rxptr = memaddr + ((bc->rseg - bd->memory_seg) << 4);
  1414. ch->txwin = ch->rxwin = 0;
  1415. break;
  1416. } /* End switch bd->type */
  1417. ch->txbufhead = 0;
  1418. ch->txbufsize = bc->tmax + 1;
  1419. ch->rxbufhead = 0;
  1420. ch->rxbufsize = bc->rmax + 1;
  1421. lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
  1422. /* Set transmitter low water mark */
  1423. fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
  1424. /* Set receiver low water mark */
  1425. fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
  1426. /* Set receiver high water mark */
  1427. fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
  1428. bc->edelay = 100;
  1429. bc->idata = 1;
  1430. ch->startc = bc->startc;
  1431. ch->stopc = bc->stopc;
  1432. ch->startca = bc->startca;
  1433. ch->stopca = bc->stopca;
  1434. ch->fepcflag = 0;
  1435. ch->fepiflag = 0;
  1436. ch->fepoflag = 0;
  1437. ch->fepstartc = 0;
  1438. ch->fepstopc = 0;
  1439. ch->fepstartca = 0;
  1440. ch->fepstopca = 0;
  1441. ch->close_delay = 50;
  1442. ch->count = 0;
  1443. ch->blocked_open = 0;
  1444. init_waitqueue_head(&ch->open_wait);
  1445. init_waitqueue_head(&ch->close_wait);
  1446. ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
  1447. if (!(ch->tmp_buf))
  1448. {
  1449. printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
  1450. release_region((int)bd->port, 4);
  1451. while(i-- > 0)
  1452. kfree((ch--)->tmp_buf);
  1453. return;
  1454. }
  1455. else
  1456. memset((void *)ch->tmp_buf,0,ch->txbufsize);
  1457. } /* End for each port */
  1458. printk(KERN_INFO
  1459. "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
  1460. VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
  1461. sprintf(mesg,
  1462. "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
  1463. VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
  1464. console_print(mesg);
  1465. memwinoff(bd, 0);
  1466. } /* End post_fep_init */
  1467. /* --------------------- Begin epcapoll ------------------------ */
  1468. static void epcapoll(unsigned long ignored)
  1469. { /* Begin epcapoll */
  1470. unsigned long flags;
  1471. int crd;
  1472. volatile unsigned int head, tail;
  1473. struct channel *ch;
  1474. struct board_info *bd;
  1475. /* -------------------------------------------------------------------
  1476. This routine is called upon every timer interrupt. Even though
  1477. the Digi series cards are capable of generating interrupts this
  1478. method of non-looping polling is more efficient. This routine
  1479. checks for card generated events (Such as receive data, are transmit
  1480. buffer empty) and acts on those events.
  1481. ----------------------------------------------------------------------- */
  1482. save_flags(flags);
  1483. cli();
  1484. for (crd = 0; crd < num_cards; crd++)
  1485. { /* Begin for each card */
  1486. bd = &boards[crd];
  1487. ch = card_ptr[crd];
  1488. if ((bd->status == DISABLED) || digi_poller_inhibited)
  1489. continue; /* Begin loop next interation */
  1490. /* -----------------------------------------------------------
  1491. assertmemoff is not needed here; indeed it is an empty subroutine.
  1492. It is being kept because future boards may need this as well as
  1493. some legacy boards.
  1494. ---------------------------------------------------------------- */
  1495. assertmemoff(ch);
  1496. globalwinon(ch);
  1497. /* ---------------------------------------------------------------
  1498. In this case head and tail actually refer to the event queue not
  1499. the transmit or receive queue.
  1500. ------------------------------------------------------------------- */
  1501. head = ch->mailbox->ein;
  1502. tail = ch->mailbox->eout;
  1503. /* If head isn't equal to tail we have an event */
  1504. if (head != tail)
  1505. doevent(crd);
  1506. memoff(ch);
  1507. } /* End for each card */
  1508. mod_timer(&epca_timer, jiffies + (HZ / 25));
  1509. restore_flags(flags);
  1510. } /* End epcapoll */
  1511. /* --------------------- Begin doevent ------------------------ */
  1512. static void doevent(int crd)
  1513. { /* Begin doevent */
  1514. volatile unchar *eventbuf;
  1515. struct channel *ch, *chan0;
  1516. static struct tty_struct *tty;
  1517. volatile struct board_info *bd;
  1518. volatile struct board_chan *bc;
  1519. register volatile unsigned int tail, head;
  1520. register int event, channel;
  1521. register int mstat, lstat;
  1522. /* -------------------------------------------------------------------
  1523. This subroutine is called by epcapoll when an event is detected
  1524. in the event queue. This routine responds to those events.
  1525. --------------------------------------------------------------------- */
  1526. bd = &boards[crd];
  1527. chan0 = card_ptr[crd];
  1528. epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
  1529. assertgwinon(chan0);
  1530. while ((tail = chan0->mailbox->eout) != (head = chan0->mailbox->ein))
  1531. { /* Begin while something in event queue */
  1532. assertgwinon(chan0);
  1533. eventbuf = (volatile unchar *)bus_to_virt((ulong)(bd->re_map_membase + tail + ISTART));
  1534. /* Get the channel the event occurred on */
  1535. channel = eventbuf[0];
  1536. /* Get the actual event code that occurred */
  1537. event = eventbuf[1];
  1538. /* ----------------------------------------------------------------
  1539. The two assignments below get the current modem status (mstat)
  1540. and the previous modem status (lstat). These are useful becuase
  1541. an event could signal a change in modem signals itself.
  1542. ------------------------------------------------------------------- */
  1543. mstat = eventbuf[2];
  1544. lstat = eventbuf[3];
  1545. ch = chan0 + channel;
  1546. if ((unsigned)channel >= bd->numports || !ch)
  1547. {
  1548. if (channel >= bd->numports)
  1549. ch = chan0;
  1550. bc = ch->brdchan;
  1551. goto next;
  1552. }
  1553. if ((bc = ch->brdchan) == NULL)
  1554. goto next;
  1555. if (event & DATA_IND)
  1556. { /* Begin DATA_IND */
  1557. receive_data(ch);
  1558. assertgwinon(ch);
  1559. } /* End DATA_IND */
  1560. /* else *//* Fix for DCD transition missed bug */
  1561. if (event & MODEMCHG_IND)
  1562. { /* Begin MODEMCHG_IND */
  1563. /* A modem signal change has been indicated */
  1564. ch->imodem = mstat;
  1565. if (ch->asyncflags & ASYNC_CHECK_CD)
  1566. {
  1567. if (mstat & ch->dcd) /* We are now receiving dcd */
  1568. wake_up_interruptible(&ch->open_wait);
  1569. else
  1570. pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
  1571. }
  1572. } /* End MODEMCHG_IND */
  1573. tty = ch->tty;
  1574. if (tty)
  1575. { /* Begin if valid tty */
  1576. if (event & BREAK_IND)
  1577. { /* Begin if BREAK_IND */
  1578. /* A break has been indicated */
  1579. tty->flip.count++;
  1580. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  1581. *tty->flip.char_buf_ptr++ = 0;
  1582. tty_schedule_flip(tty);
  1583. } /* End if BREAK_IND */
  1584. else
  1585. if (event & LOWTX_IND)
  1586. { /* Begin LOWTX_IND */
  1587. if (ch->statusflags & LOWWAIT)
  1588. { /* Begin if LOWWAIT */
  1589. ch->statusflags &= ~LOWWAIT;
  1590. tty_wakeup(tty);
  1591. wake_up_interruptible(&tty->write_wait);
  1592. } /* End if LOWWAIT */
  1593. } /* End LOWTX_IND */
  1594. else
  1595. if (event & EMPTYTX_IND)
  1596. { /* Begin EMPTYTX_IND */
  1597. /* This event is generated by setup_empty_event */
  1598. ch->statusflags &= ~TXBUSY;
  1599. if (ch->statusflags & EMPTYWAIT)
  1600. { /* Begin if EMPTYWAIT */
  1601. ch->statusflags &= ~EMPTYWAIT;
  1602. tty_wakeup(tty);
  1603. wake_up_interruptible(&tty->write_wait);
  1604. } /* End if EMPTYWAIT */
  1605. } /* End EMPTYTX_IND */
  1606. } /* End if valid tty */
  1607. next:
  1608. globalwinon(ch);
  1609. if (!bc)
  1610. printk(KERN_ERR "<Error> - bc == NULL in doevent!\n");
  1611. else
  1612. bc->idata = 1;
  1613. chan0->mailbox->eout = (tail + 4) & (IMAX - ISTART - 4);
  1614. globalwinon(chan0);
  1615. } /* End while something in event queue */
  1616. } /* End doevent */
  1617. /* --------------------- Begin fepcmd ------------------------ */
  1618. static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
  1619. int byte2, int ncmds, int bytecmd)
  1620. { /* Begin fepcmd */
  1621. unchar *memaddr;
  1622. unsigned int head, cmdTail, cmdStart, cmdMax;
  1623. long count;
  1624. int n;
  1625. /* This is the routine in which commands may be passed to the card. */
  1626. if (ch->board->status == DISABLED)
  1627. {
  1628. return;
  1629. }
  1630. assertgwinon(ch);
  1631. /* Remember head (As well as max) is just an offset not a base addr */
  1632. head = ch->mailbox->cin;
  1633. /* cmdStart is a base address */
  1634. cmdStart = ch->mailbox->cstart;
  1635. /* ------------------------------------------------------------------
  1636. We do the addition below because we do not want a max pointer
  1637. relative to cmdStart. We want a max pointer that points at the
  1638. physical end of the command queue.
  1639. -------------------------------------------------------------------- */
  1640. cmdMax = (cmdStart + 4 + (ch->mailbox->cmax));
  1641. memaddr = ch->board->re_map_membase;
  1642. /*
  1643. The below command is necessary because newer kernels (2.1.x and
  1644. up) do not have a 1:1 virtual to physical mapping. The below
  1645. call adjust for that.
  1646. */
  1647. memaddr = (unsigned char *)bus_to_virt((unsigned long)memaddr);
  1648. if (head >= (cmdMax - cmdStart) || (head & 03))
  1649. {
  1650. printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__,
  1651. cmd, head);
  1652. printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__,
  1653. cmdMax, cmdStart);
  1654. return;
  1655. }
  1656. if (bytecmd)
  1657. {
  1658. *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
  1659. *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
  1660. /* Below word_or_byte is bits to set */
  1661. *(volatile unchar *)(memaddr + head + cmdStart + 2) = (unchar)word_or_byte;
  1662. /* Below byte2 is bits to reset */
  1663. *(volatile unchar *)(memaddr + head + cmdStart + 3) = (unchar)byte2;
  1664. }
  1665. else
  1666. {
  1667. *(volatile unchar *)(memaddr + head + cmdStart + 0) = (unchar)cmd;
  1668. *(volatile unchar *)(memaddr + head + cmdStart + 1) = (unchar)ch->channelnum;
  1669. *(volatile ushort*)(memaddr + head + cmdStart + 2) = (ushort)word_or_byte;
  1670. }
  1671. head = (head + 4) & (cmdMax - cmdStart - 4);
  1672. ch->mailbox->cin = head;
  1673. count = FEPTIMEOUT;
  1674. for (;;)
  1675. { /* Begin forever loop */
  1676. count--;
  1677. if (count == 0)
  1678. {
  1679. printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
  1680. return;
  1681. }
  1682. head = ch->mailbox->cin;
  1683. cmdTail = ch->mailbox->cout;
  1684. n = (head - cmdTail) & (cmdMax - cmdStart - 4);
  1685. /* ----------------------------------------------------------
  1686. Basically this will break when the FEP acknowledges the
  1687. command by incrementing cmdTail (Making it equal to head).
  1688. ------------------------------------------------------------- */
  1689. if (n <= ncmds * (sizeof(short) * 4))
  1690. break; /* Well nearly forever :-) */
  1691. } /* End forever loop */
  1692. } /* End fepcmd */
  1693. /* ---------------------------------------------------------------------
  1694. Digi products use fields in their channels structures that are very
  1695. similar to the c_cflag and c_iflag fields typically found in UNIX
  1696. termios structures. The below three routines allow mappings
  1697. between these hardware "flags" and their respective Linux flags.
  1698. ------------------------------------------------------------------------- */
  1699. /* --------------------- Begin termios2digi_h -------------------- */
  1700. static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
  1701. { /* Begin termios2digi_h */
  1702. unsigned res = 0;
  1703. if (cflag & CRTSCTS)
  1704. {
  1705. ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
  1706. res |= ((ch->m_cts) | (ch->m_rts));
  1707. }
  1708. if (ch->digiext.digi_flags & RTSPACE)
  1709. res |= ch->m_rts;
  1710. if (ch->digiext.digi_flags & DTRPACE)
  1711. res |= ch->m_dtr;
  1712. if (ch->digiext.digi_flags & CTSPACE)
  1713. res |= ch->m_cts;
  1714. if (ch->digiext.digi_flags & DSRPACE)
  1715. res |= ch->dsr;
  1716. if (ch->digiext.digi_flags & DCDPACE)
  1717. res |= ch->dcd;
  1718. if (res & (ch->m_rts))
  1719. ch->digiext.digi_flags |= RTSPACE;
  1720. if (res & (ch->m_cts))
  1721. ch->digiext.digi_flags |= CTSPACE;
  1722. return res;
  1723. } /* End termios2digi_h */
  1724. /* --------------------- Begin termios2digi_i -------------------- */
  1725. static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
  1726. { /* Begin termios2digi_i */
  1727. unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
  1728. INPCK | ISTRIP|IXON|IXANY|IXOFF);
  1729. if (ch->digiext.digi_flags & DIGI_AIXON)
  1730. res |= IAIXON;
  1731. return res;
  1732. } /* End termios2digi_i */
  1733. /* --------------------- Begin termios2digi_c -------------------- */
  1734. static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
  1735. { /* Begin termios2digi_c */
  1736. unsigned res = 0;
  1737. #ifdef SPEED_HACK
  1738. /* CL: HACK to force 115200 at 38400 and 57600 at 19200 Baud */
  1739. if ((cflag & CBAUD)== B38400) cflag=cflag - B38400 + B115200;
  1740. if ((cflag & CBAUD)== B19200) cflag=cflag - B19200 + B57600;
  1741. #endif /* SPEED_HACK */
  1742. if (cflag & CBAUDEX)
  1743. { /* Begin detected CBAUDEX */
  1744. ch->digiext.digi_flags |= DIGI_FAST;
  1745. /* -------------------------------------------------------------
  1746. HUPCL bit is used by FEP to indicate fast baud
  1747. table is to be used.
  1748. ----------------------------------------------------------------- */
  1749. res |= FEP_HUPCL;
  1750. } /* End detected CBAUDEX */
  1751. else ch->digiext.digi_flags &= ~DIGI_FAST;
  1752. /* -------------------------------------------------------------------
  1753. CBAUD has bit position 0x1000 set these days to indicate Linux
  1754. baud rate remap. Digi hardware can't handle the bit assignment.
  1755. (We use a different bit assignment for high speed.). Clear this
  1756. bit out.
  1757. ---------------------------------------------------------------------- */
  1758. res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
  1759. /* -------------------------------------------------------------
  1760. This gets a little confusing. The Digi cards have their own
  1761. representation of c_cflags controling baud rate. For the most
  1762. part this is identical to the Linux implementation. However;
  1763. Digi supports one rate (76800) that Linux doesn't. This means
  1764. that the c_cflag entry that would normally mean 76800 for Digi
  1765. actually means 115200 under Linux. Without the below mapping,
  1766. a stty 115200 would only drive the board at 76800. Since
  1767. the rate 230400 is also found after 76800, the same problem afflicts
  1768. us when we choose a rate of 230400. Without the below modificiation
  1769. stty 230400 would actually give us 115200.
  1770. There are two additional differences. The Linux value for CLOCAL
  1771. (0x800; 0004000) has no meaning to the Digi hardware. Also in
  1772. later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
  1773. 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
  1774. should be checked for a screened out prior to termios2digi_c
  1775. returning. Since CLOCAL isn't used by the board this can be
  1776. ignored as long as the returned value is used only by Digi hardware.
  1777. ----------------------------------------------------------------- */
  1778. if (cflag & CBAUDEX)
  1779. {
  1780. /* -------------------------------------------------------------
  1781. The below code is trying to guarantee that only baud rates
  1782. 115200 and 230400 are remapped. We use exclusive or because
  1783. the various baud rates share common bit positions and therefore
  1784. can't be tested for easily.
  1785. ----------------------------------------------------------------- */
  1786. if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
  1787. (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
  1788. {
  1789. res += 1;
  1790. }
  1791. }
  1792. return res;
  1793. } /* End termios2digi_c */
  1794. /* --------------------- Begin epcaparam ----------------------- */
  1795. static void epcaparam(struct tty_struct *tty, struct channel *ch)
  1796. { /* Begin epcaparam */
  1797. unsigned int cmdHead;
  1798. struct termios *ts;
  1799. volatile struct board_chan *bc;
  1800. unsigned mval, hflow, cflag, iflag;
  1801. bc = ch->brdchan;
  1802. epcaassert(bc !=0, "bc out of range");
  1803. assertgwinon(ch);
  1804. ts = tty->termios;
  1805. if ((ts->c_cflag & CBAUD) == 0)
  1806. { /* Begin CBAUD detected */
  1807. cmdHead = bc->rin;
  1808. bc->rout = cmdHead;
  1809. cmdHead = bc->tin;
  1810. /* Changing baud in mid-stream transmission can be wonderful */
  1811. /* ---------------------------------------------------------------
  1812. Flush current transmit buffer by setting cmdTail pointer (tout)
  1813. to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
  1814. ----------------------------------------------------------------- */
  1815. fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
  1816. mval = 0;
  1817. } /* End CBAUD detected */
  1818. else
  1819. { /* Begin CBAUD not detected */
  1820. /* -------------------------------------------------------------------
  1821. c_cflags have changed but that change had nothing to do with BAUD.
  1822. Propagate the change to the card.
  1823. ---------------------------------------------------------------------- */
  1824. cflag = termios2digi_c(ch, ts->c_cflag);
  1825. if (cflag != ch->fepcflag)
  1826. {
  1827. ch->fepcflag = cflag;
  1828. /* Set baud rate, char size, stop bits, parity */
  1829. fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
  1830. }
  1831. /* ----------------------------------------------------------------
  1832. If the user has not forced CLOCAL and if the device is not a
  1833. CALLOUT device (Which is always CLOCAL) we set flags such that
  1834. the driver will wait on carrier detect.
  1835. ------------------------------------------------------------------- */
  1836. if (ts->c_cflag & CLOCAL)
  1837. { /* Begin it is a cud device or a ttyD device with CLOCAL on */
  1838. ch->asyncflags &= ~ASYNC_CHECK_CD;
  1839. } /* End it is a cud device or a ttyD device with CLOCAL on */
  1840. else
  1841. { /* Begin it is a ttyD device */
  1842. ch->asyncflags |= ASYNC_CHECK_CD;
  1843. } /* End it is a ttyD device */
  1844. mval = ch->m_dtr | ch->m_rts;
  1845. } /* End CBAUD not detected */
  1846. iflag = termios2digi_i(ch, ts->c_iflag);
  1847. /* Check input mode flags */
  1848. if (iflag != ch->fepiflag)
  1849. {
  1850. ch->fepiflag = iflag;
  1851. /* ---------------------------------------------------------------
  1852. Command sets channels iflag structure on the board. Such things
  1853. as input soft flow control, handling of parity errors, and
  1854. break handling are all set here.
  1855. ------------------------------------------------------------------- */
  1856. /* break handling, parity handling, input stripping, flow control chars */
  1857. fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
  1858. }
  1859. /* ---------------------------------------------------------------
  1860. Set the board mint value for this channel. This will cause hardware
  1861. events to be generated each time the DCD signal (Described in mint)
  1862. changes.
  1863. ------------------------------------------------------------------- */
  1864. bc->mint = ch->dcd;
  1865. if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
  1866. if (ch->digiext.digi_flags & DIGI_FORCEDCD)
  1867. bc->mint = 0;
  1868. ch->imodem = bc->mstat;
  1869. hflow = termios2digi_h(ch, ts->c_cflag);
  1870. if (hflow != ch->hflow)
  1871. {
  1872. ch->hflow = hflow;
  1873. /* --------------------------------------------------------------
  1874. Hard flow control has been selected but the board is not
  1875. using it. Activate hard flow control now.
  1876. ----------------------------------------------------------------- */
  1877. fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
  1878. }
  1879. mval ^= ch->modemfake & (mval ^ ch->modem);
  1880. if (ch->omodem ^ mval)
  1881. {
  1882. ch->omodem = mval;
  1883. /* --------------------------------------------------------------
  1884. The below command sets the DTR and RTS mstat structure. If
  1885. hard flow control is NOT active these changes will drive the
  1886. output of the actual DTR and RTS lines. If hard flow control
  1887. is active, the changes will be saved in the mstat structure and
  1888. only asserted when hard flow control is turned off.
  1889. ----------------------------------------------------------------- */
  1890. /* First reset DTR & RTS; then set them */
  1891. fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
  1892. fepcmd(ch, SETMODEM, mval, 0, 0, 1);
  1893. }
  1894. if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc)
  1895. {
  1896. ch->fepstartc = ch->startc;
  1897. ch->fepstopc = ch->stopc;
  1898. /* ------------------------------------------------------------
  1899. The XON / XOFF characters have changed; propagate these
  1900. changes to the card.
  1901. --------------------------------------------------------------- */
  1902. fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
  1903. }
  1904. if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca)
  1905. {
  1906. ch->fepstartca = ch->startca;
  1907. ch->fepstopca = ch->stopca;
  1908. /* ---------------------------------------------------------------
  1909. Similar to the above, this time the auxilarly XON / XOFF
  1910. characters have changed; propagate these changes to the card.
  1911. ------------------------------------------------------------------ */
  1912. fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
  1913. }
  1914. } /* End epcaparam */
  1915. /* --------------------- Begin receive_data ----------------------- */
  1916. static void receive_data(struct channel *ch)
  1917. { /* Begin receive_data */
  1918. unchar *rptr;
  1919. struct termios *ts = NULL;
  1920. struct tty_struct *tty;
  1921. volatile struct board_chan *bc;
  1922. register int dataToRead, wrapgap, bytesAvailable;
  1923. register unsigned int tail, head;
  1924. unsigned int wrapmask;
  1925. int rc;
  1926. /* ---------------------------------------------------------------
  1927. This routine is called by doint when a receive data event
  1928. has taken place.
  1929. ------------------------------------------------------------------- */
  1930. globalwinon(ch);
  1931. if (ch->statusflags & RXSTOPPED)
  1932. return;
  1933. tty = ch->tty;
  1934. if (tty)
  1935. ts = tty->termios;
  1936. bc = ch->brdchan;
  1937. if (!bc)
  1938. {
  1939. printk(KERN_ERR "<Error> - bc is NULL in receive_data!\n");
  1940. return;
  1941. }
  1942. wrapmask = ch->rxbufsize - 1;
  1943. /* ---------------------------------------------------------------------
  1944. Get the head and tail pointers to the receiver queue. Wrap the
  1945. head pointer if it has reached the end of the buffer.
  1946. ------------------------------------------------------------------------ */
  1947. head = bc->rin;
  1948. head &= wrapmask;
  1949. tail = bc->rout & wrapmask;
  1950. bytesAvailable = (head - tail) & wrapmask;
  1951. if (bytesAvailable == 0)
  1952. return;
  1953. /* ------------------------------------------------------------------
  1954. If CREAD bit is off or device not open, set TX tail to head
  1955. --------------------------------------------------------------------- */
  1956. if (!tty || !ts || !(ts->c_cflag & CREAD))
  1957. {
  1958. bc->rout = head;
  1959. return;
  1960. }
  1961. if (tty->flip.count == TTY_FLIPBUF_SIZE)
  1962. return;
  1963. if (bc->orun)
  1964. {
  1965. bc->orun = 0;
  1966. printk(KERN_WARNING "overrun! DigiBoard device %s\n",tty->name);
  1967. }
  1968. rxwinon(ch);
  1969. rptr = tty->flip.char_buf_ptr;
  1970. rc = tty->flip.count;
  1971. while (bytesAvailable > 0)
  1972. { /* Begin while there is data on the card */
  1973. wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
  1974. /* ---------------------------------------------------------------
  1975. Even if head has wrapped around only report the amount of
  1976. data to be equal to the size - tail. Remember memcpy can't
  1977. automaticly wrap around the receive buffer.
  1978. ----------------------------------------------------------------- */
  1979. dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
  1980. /* --------------------------------------------------------------
  1981. Make sure we don't overflow the buffer
  1982. ----------------------------------------------------------------- */
  1983. if ((rc + dataToRead) > TTY_FLIPBUF_SIZE)
  1984. dataToRead = TTY_FLIPBUF_SIZE - rc;
  1985. if (dataToRead == 0)
  1986. break;
  1987. /* ---------------------------------------------------------------
  1988. Move data read from our card into the line disciplines buffer
  1989. for translation if necessary.
  1990. ------------------------------------------------------------------ */
  1991. if ((memcpy(rptr, ch->rxptr + tail, dataToRead)) != rptr)
  1992. printk(KERN_ERR "<Error> - receive_data : memcpy failed\n");
  1993. rc += dataToRead;
  1994. rptr += dataToRead;
  1995. tail = (tail + dataToRead) & wrapmask;
  1996. bytesAvailable -= dataToRead;
  1997. } /* End while there is data on the card */
  1998. tty->flip.count = rc;
  1999. tty->flip.char_buf_ptr = rptr;
  2000. globalwinon(ch);
  2001. bc->rout = tail;
  2002. /* Must be called with global data */
  2003. tty_schedule_flip(ch->tty);
  2004. return;
  2005. } /* End receive_data */
  2006. static int info_ioctl(struct tty_struct *tty, struct file * file,
  2007. unsigned int cmd, unsigned long arg)
  2008. {
  2009. switch (cmd)
  2010. { /* Begin switch cmd */
  2011. case DIGI_GETINFO:
  2012. { /* Begin case DIGI_GETINFO */
  2013. struct digi_info di ;
  2014. int brd;
  2015. getUser(brd, (unsigned int __user *)arg);
  2016. if ((brd < 0) || (brd >= num_cards) || (num_cards == 0))
  2017. return (-ENODEV);
  2018. memset(&di, 0, sizeof(di));
  2019. di.board = brd ;
  2020. di.status = boards[brd].status;
  2021. di.type = boards[brd].type ;
  2022. di.numports = boards[brd].numports ;
  2023. di.port = boards[brd].port ;
  2024. di.membase = boards[brd].membase ;
  2025. if (copy_to_user((void __user *)arg, &di, sizeof (di)))
  2026. return -EFAULT;
  2027. break;
  2028. } /* End case DIGI_GETINFO */
  2029. case DIGI_POLLER:
  2030. { /* Begin case DIGI_POLLER */
  2031. int brd = arg & 0xff000000 >> 16 ;
  2032. unsigned char state = arg & 0xff ;
  2033. if ((brd < 0) || (brd >= num_cards))
  2034. {
  2035. printk(KERN_ERR "<Error> - DIGI POLLER : brd not valid!\n");
  2036. return (-ENODEV);
  2037. }
  2038. digi_poller_inhibited = state ;
  2039. break ;
  2040. } /* End case DIGI_POLLER */
  2041. case DIGI_INIT:
  2042. { /* Begin case DIGI_INIT */
  2043. /* ------------------------------------------------------------
  2044. This call is made by the apps to complete the initilization
  2045. of the board(s). This routine is responsible for setting
  2046. the card to its initial state and setting the drivers control
  2047. fields to the sutianle settings for the card in question.
  2048. ---------------------------------------------------------------- */
  2049. int crd ;
  2050. for (crd = 0; crd < num_cards; crd++)
  2051. post_fep_init (crd);
  2052. break ;
  2053. } /* End case DIGI_INIT */
  2054. default:
  2055. return -ENOIOCTLCMD;
  2056. } /* End switch cmd */
  2057. return (0) ;
  2058. }
  2059. /* --------------------- Begin pc_ioctl ----------------------- */
  2060. static int pc_tiocmget(struct tty_struct *tty, struct file *file)
  2061. {
  2062. struct channel *ch = (struct channel *) tty->driver_data;
  2063. volatile struct board_chan *bc;
  2064. unsigned int mstat, mflag = 0;
  2065. unsigned long flags;
  2066. if (ch)
  2067. bc = ch->brdchan;
  2068. else
  2069. {
  2070. printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmget!\n");
  2071. return(-EINVAL);
  2072. }
  2073. save_flags(flags);
  2074. cli();
  2075. globalwinon(ch);
  2076. mstat = bc->mstat;
  2077. memoff(ch);
  2078. restore_flags(flags);
  2079. if (mstat & ch->m_dtr)
  2080. mflag |= TIOCM_DTR;
  2081. if (mstat & ch->m_rts)
  2082. mflag |= TIOCM_RTS;
  2083. if (mstat & ch->m_cts)
  2084. mflag |= TIOCM_CTS;
  2085. if (mstat & ch->dsr)
  2086. mflag |= TIOCM_DSR;
  2087. if (mstat & ch->m_ri)
  2088. mflag |= TIOCM_RI;
  2089. if (mstat & ch->dcd)
  2090. mflag |= TIOCM_CD;
  2091. return mflag;
  2092. }
  2093. static int pc_tiocmset(struct tty_struct *tty, struct file *file,
  2094. unsigned int set, unsigned int clear)
  2095. {
  2096. struct channel *ch = (struct channel *) tty->driver_data;
  2097. unsigned long flags;
  2098. if (!ch) {
  2099. printk(KERN_ERR "<Error> - ch is NULL in pc_tiocmset!\n");
  2100. return(-EINVAL);
  2101. }
  2102. save_flags(flags);
  2103. cli();
  2104. /*
  2105. * I think this modemfake stuff is broken. It doesn't
  2106. * correctly reflect the behaviour desired by the TIOCM*
  2107. * ioctls. Therefore this is probably broken.
  2108. */
  2109. if (set & TIOCM_RTS) {
  2110. ch->modemfake |= ch->m_rts;
  2111. ch->modem |= ch->m_rts;
  2112. }
  2113. if (set & TIOCM_DTR) {
  2114. ch->modemfake |= ch->m_dtr;
  2115. ch->modem |= ch->m_dtr;
  2116. }
  2117. if (clear & TIOCM_RTS) {
  2118. ch->modemfake |= ch->m_rts;
  2119. ch->modem &= ~ch->m_rts;
  2120. }
  2121. if (clear & TIOCM_DTR) {
  2122. ch->modemfake |= ch->m_dtr;
  2123. ch->modem &= ~ch->m_dtr;
  2124. }
  2125. globalwinon(ch);
  2126. /* --------------------------------------------------------------
  2127. The below routine generally sets up parity, baud, flow control
  2128. issues, etc.... It effect both control flags and input flags.
  2129. ------------------------------------------------------------------ */
  2130. epcaparam(tty,ch);
  2131. memoff(ch);
  2132. restore_flags(flags);
  2133. return 0;
  2134. }
  2135. static int pc_ioctl(struct tty_struct *tty, struct file * file,
  2136. unsigned int cmd, unsigned long arg)
  2137. { /* Begin pc_ioctl */
  2138. digiflow_t dflow;
  2139. int retval;
  2140. unsigned long flags;
  2141. unsigned int mflag, mstat;
  2142. unsigned char startc, stopc;
  2143. volatile struct board_chan *bc;
  2144. struct channel *ch = (struct channel *) tty->driver_data;
  2145. void __user *argp = (void __user *)arg;
  2146. if (ch)
  2147. bc = ch->brdchan;
  2148. else
  2149. {
  2150. printk(KERN_ERR "<Error> - ch is NULL in pc_ioctl!\n");
  2151. return(-EINVAL);
  2152. }
  2153. save_flags(flags);
  2154. /* -------------------------------------------------------------------
  2155. For POSIX compliance we need to add more ioctls. See tty_ioctl.c
  2156. in /usr/src/linux/drivers/char for a good example. In particular
  2157. think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
  2158. ---------------------------------------------------------------------- */
  2159. switch (cmd)
  2160. { /* Begin switch cmd */
  2161. case TCGETS:
  2162. if (copy_to_user(argp,
  2163. tty->termios, sizeof(struct termios)))
  2164. return -EFAULT;
  2165. return(0);
  2166. case TCGETA:
  2167. return get_termio(tty, argp);
  2168. case TCSBRK: /* SVID version: non-zero arg --> no break */
  2169. retval = tty_check_change(tty);
  2170. if (retval)
  2171. return retval;
  2172. /* Setup an event to indicate when the transmit buffer empties */
  2173. setup_empty_event(tty,ch);
  2174. tty_wait_until_sent(tty, 0);
  2175. if (!arg)
  2176. digi_send_break(ch, HZ/4); /* 1/4 second */
  2177. return 0;
  2178. case TCSBRKP: /* support for POSIX tcsendbreak() */
  2179. retval = tty_check_change(tty);
  2180. if (retval)
  2181. return retval;
  2182. /* Setup an event to indicate when the transmit buffer empties */
  2183. setup_empty_event(tty,ch);
  2184. tty_wait_until_sent(tty, 0);
  2185. digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
  2186. return 0;
  2187. case TIOCGSOFTCAR:
  2188. if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
  2189. return -EFAULT;
  2190. return 0;
  2191. case TIOCSSOFTCAR:
  2192. {
  2193. unsigned int value;
  2194. if (get_user(value, (unsigned __user *)argp))
  2195. return -EFAULT;
  2196. tty->termios->c_cflag =
  2197. ((tty->termios->c_cflag & ~CLOCAL) |
  2198. (value ? CLOCAL : 0));
  2199. return 0;
  2200. }
  2201. case TIOCMODG:
  2202. mflag = pc_tiocmget(tty, file);
  2203. if (put_user(mflag, (unsigned long __user *)argp))
  2204. return -EFAULT;
  2205. break;
  2206. case TIOCMODS:
  2207. if (get_user(mstat, (unsigned __user *)argp))
  2208. return -EFAULT;
  2209. return pc_tiocmset(tty, file, mstat, ~mstat);
  2210. case TIOCSDTR:
  2211. ch->omodem |= ch->m_dtr;
  2212. cli();
  2213. globalwinon(ch);
  2214. fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
  2215. memoff(ch);
  2216. restore_flags(flags);
  2217. break;
  2218. case TIOCCDTR:
  2219. ch->omodem &= ~ch->m_dtr;
  2220. cli();
  2221. globalwinon(ch);
  2222. fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
  2223. memoff(ch);
  2224. restore_flags(flags);
  2225. break;
  2226. case DIGI_GETA:
  2227. if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
  2228. return -EFAULT;
  2229. break;
  2230. case DIGI_SETAW:
  2231. case DIGI_SETAF:
  2232. if ((cmd) == (DIGI_SETAW))
  2233. {
  2234. /* Setup an event to indicate when the transmit buffer empties */
  2235. setup_empty_event(tty,ch);
  2236. tty_wait_until_sent(tty, 0);
  2237. }
  2238. else
  2239. {
  2240. /* ldisc lock already held in ioctl */
  2241. if (tty->ldisc.flush_buffer)
  2242. tty->ldisc.flush_buffer(tty);
  2243. }
  2244. /* Fall Thru */
  2245. case DIGI_SETA:
  2246. if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
  2247. return -EFAULT;
  2248. if (ch->digiext.digi_flags & DIGI_ALTPIN)
  2249. {
  2250. ch->dcd = ch->m_dsr;
  2251. ch->dsr = ch->m_dcd;
  2252. }
  2253. else
  2254. {
  2255. ch->dcd = ch->m_dcd;
  2256. ch->dsr = ch->m_dsr;
  2257. }
  2258. cli();
  2259. globalwinon(ch);
  2260. /* -----------------------------------------------------------------
  2261. The below routine generally sets up parity, baud, flow control
  2262. issues, etc.... It effect both control flags and input flags.
  2263. ------------------------------------------------------------------- */
  2264. epcaparam(tty,ch);
  2265. memoff(ch);
  2266. restore_flags(flags);
  2267. break;
  2268. case DIGI_GETFLOW:
  2269. case DIGI_GETAFLOW:
  2270. cli();
  2271. globalwinon(ch);
  2272. if ((cmd) == (DIGI_GETFLOW))
  2273. {
  2274. dflow.startc = bc->startc;
  2275. dflow.stopc = bc->stopc;
  2276. }
  2277. else
  2278. {
  2279. dflow.startc = bc->startca;
  2280. dflow.stopc = bc->stopca;
  2281. }
  2282. memoff(ch);
  2283. restore_flags(flags);
  2284. if (copy_to_user(argp, &dflow, sizeof(dflow)))
  2285. return -EFAULT;
  2286. break;
  2287. case DIGI_SETAFLOW:
  2288. case DIGI_SETFLOW:
  2289. if ((cmd) == (DIGI_SETFLOW))
  2290. {
  2291. startc = ch->startc;
  2292. stopc = ch->stopc;
  2293. }
  2294. else
  2295. {
  2296. startc = ch->startca;
  2297. stopc = ch->stopca;
  2298. }
  2299. if (copy_from_user(&dflow, argp, sizeof(dflow)))
  2300. return -EFAULT;
  2301. if (dflow.startc != startc || dflow.stopc != stopc)
  2302. { /* Begin if setflow toggled */
  2303. cli();
  2304. globalwinon(ch);
  2305. if ((cmd) == (DIGI_SETFLOW))
  2306. {
  2307. ch->fepstartc = ch->startc = dflow.startc;
  2308. ch->fepstopc = ch->stopc = dflow.stopc;
  2309. fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
  2310. }
  2311. else
  2312. {
  2313. ch->fepstartca = ch->startca = dflow.startc;
  2314. ch->fepstopca = ch->stopca = dflow.stopc;
  2315. fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
  2316. }
  2317. if (ch->statusflags & TXSTOPPED)
  2318. pc_start(tty);
  2319. memoff(ch);
  2320. restore_flags(flags);
  2321. } /* End if setflow toggled */
  2322. break;
  2323. default:
  2324. return -ENOIOCTLCMD;
  2325. } /* End switch cmd */
  2326. return 0;
  2327. } /* End pc_ioctl */
  2328. /* --------------------- Begin pc_set_termios ----------------------- */
  2329. static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
  2330. { /* Begin pc_set_termios */
  2331. struct channel *ch;
  2332. unsigned long flags;
  2333. /* ---------------------------------------------------------
  2334. verifyChannel returns the channel from the tty struct
  2335. if it is valid. This serves as a sanity check.
  2336. ------------------------------------------------------------- */
  2337. if ((ch = verifyChannel(tty)) != NULL)
  2338. { /* Begin if channel valid */
  2339. save_flags(flags);
  2340. cli();
  2341. globalwinon(ch);
  2342. epcaparam(tty, ch);
  2343. memoff(ch);
  2344. if ((old_termios->c_cflag & CRTSCTS) &&
  2345. ((tty->termios->c_cflag & CRTSCTS) == 0))
  2346. tty->hw_stopped = 0;
  2347. if (!(old_termios->c_cflag & CLOCAL) &&
  2348. (tty->termios->c_cflag & CLOCAL))
  2349. wake_up_interruptible(&ch->open_wait);
  2350. restore_flags(flags);
  2351. } /* End if channel valid */
  2352. } /* End pc_set_termios */
  2353. /* --------------------- Begin do_softint ----------------------- */
  2354. static void do_softint(void *private_)
  2355. { /* Begin do_softint */
  2356. struct channel *ch = (struct channel *) private_;
  2357. /* Called in response to a modem change event */
  2358. if (ch && ch->magic == EPCA_MAGIC)
  2359. { /* Begin EPCA_MAGIC */
  2360. struct tty_struct *tty = ch->tty;
  2361. if (tty && tty->driver_data)
  2362. {
  2363. if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event))
  2364. { /* Begin if clear_bit */
  2365. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  2366. wake_up_interruptible(&ch->open_wait);
  2367. ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
  2368. } /* End if clear_bit */
  2369. }
  2370. } /* End EPCA_MAGIC */
  2371. } /* End do_softint */
  2372. /* ------------------------------------------------------------
  2373. pc_stop and pc_start provide software flow control to the
  2374. routine and the pc_ioctl routine.
  2375. ---------------------------------------------------------------- */
  2376. /* --------------------- Begin pc_stop ----------------------- */
  2377. static void pc_stop(struct tty_struct *tty)
  2378. { /* Begin pc_stop */
  2379. struct channel *ch;
  2380. unsigned long flags;
  2381. /* ---------------------------------------------------------
  2382. verifyChannel returns the channel from the tty struct
  2383. if it is valid. This serves as a sanity check.
  2384. ------------------------------------------------------------- */
  2385. if ((ch = verifyChannel(tty)) != NULL)
  2386. { /* Begin if valid channel */
  2387. save_flags(flags);
  2388. cli();
  2389. if ((ch->statusflags & TXSTOPPED) == 0)
  2390. { /* Begin if transmit stop requested */
  2391. globalwinon(ch);
  2392. /* STOP transmitting now !! */
  2393. fepcmd(ch, PAUSETX, 0, 0, 0, 0);
  2394. ch->statusflags |= TXSTOPPED;
  2395. memoff(ch);
  2396. } /* End if transmit stop requested */
  2397. restore_flags(flags);
  2398. } /* End if valid channel */
  2399. } /* End pc_stop */
  2400. /* --------------------- Begin pc_start ----------------------- */
  2401. static void pc_start(struct tty_struct *tty)
  2402. { /* Begin pc_start */
  2403. struct channel *ch;
  2404. /* ---------------------------------------------------------
  2405. verifyChannel returns the channel from the tty struct
  2406. if it is valid. This serves as a sanity check.
  2407. ------------------------------------------------------------- */
  2408. if ((ch = verifyChannel(tty)) != NULL)
  2409. { /* Begin if channel valid */
  2410. unsigned long flags;
  2411. save_flags(flags);
  2412. cli();
  2413. /* Just in case output was resumed because of a change in Digi-flow */
  2414. if (ch->statusflags & TXSTOPPED)
  2415. { /* Begin transmit resume requested */
  2416. volatile struct board_chan *bc;
  2417. globalwinon(ch);
  2418. bc = ch->brdchan;
  2419. if (ch->statusflags & LOWWAIT)
  2420. bc->ilow = 1;
  2421. /* Okay, you can start transmitting again... */
  2422. fepcmd(ch, RESUMETX, 0, 0, 0, 0);
  2423. ch->statusflags &= ~TXSTOPPED;
  2424. memoff(ch);
  2425. } /* End transmit resume requested */
  2426. restore_flags(flags);
  2427. } /* End if channel valid */
  2428. } /* End pc_start */
  2429. /* ------------------------------------------------------------------
  2430. The below routines pc_throttle and pc_unthrottle are used
  2431. to slow (And resume) the receipt of data into the kernels
  2432. receive buffers. The exact occurrence of this depends on the
  2433. size of the kernels receive buffer and what the 'watermarks'
  2434. are set to for that buffer. See the n_ttys.c file for more
  2435. details.
  2436. ______________________________________________________________________ */
  2437. /* --------------------- Begin throttle ----------------------- */
  2438. static void pc_throttle(struct tty_struct * tty)
  2439. { /* Begin pc_throttle */
  2440. struct channel *ch;
  2441. unsigned long flags;
  2442. /* ---------------------------------------------------------
  2443. verifyChannel returns the channel from the tty struct
  2444. if it is valid. This serves as a sanity check.
  2445. ------------------------------------------------------------- */
  2446. if ((ch = verifyChannel(tty)) != NULL)
  2447. { /* Begin if channel valid */
  2448. save_flags(flags);
  2449. cli();
  2450. if ((ch->statusflags & RXSTOPPED) == 0)
  2451. {
  2452. globalwinon(ch);
  2453. fepcmd(ch, PAUSERX, 0, 0, 0, 0);
  2454. ch->statusflags |= RXSTOPPED;
  2455. memoff(ch);
  2456. }
  2457. restore_flags(flags);
  2458. } /* End if channel valid */
  2459. } /* End pc_throttle */
  2460. /* --------------------- Begin unthrottle ----------------------- */
  2461. static void pc_unthrottle(struct tty_struct *tty)
  2462. { /* Begin pc_unthrottle */
  2463. struct channel *ch;
  2464. unsigned long flags;
  2465. volatile struct board_chan *bc;
  2466. /* ---------------------------------------------------------
  2467. verifyChannel returns the channel from the tty struct
  2468. if it is valid. This serves as a sanity check.
  2469. ------------------------------------------------------------- */
  2470. if ((ch = verifyChannel(tty)) != NULL)
  2471. { /* Begin if channel valid */
  2472. /* Just in case output was resumed because of a change in Digi-flow */
  2473. save_flags(flags);
  2474. cli();
  2475. if (ch->statusflags & RXSTOPPED)
  2476. {
  2477. globalwinon(ch);
  2478. bc = ch->brdchan;
  2479. fepcmd(ch, RESUMERX, 0, 0, 0, 0);
  2480. ch->statusflags &= ~RXSTOPPED;
  2481. memoff(ch);
  2482. }
  2483. restore_flags(flags);
  2484. } /* End if channel valid */
  2485. } /* End pc_unthrottle */
  2486. /* --------------------- Begin digi_send_break ----------------------- */
  2487. void digi_send_break(struct channel *ch, int msec)
  2488. { /* Begin digi_send_break */
  2489. unsigned long flags;
  2490. save_flags(flags);
  2491. cli();
  2492. globalwinon(ch);
  2493. /* --------------------------------------------------------------------
  2494. Maybe I should send an infinite break here, schedule() for
  2495. msec amount of time, and then stop the break. This way,
  2496. the user can't screw up the FEP by causing digi_send_break()
  2497. to be called (i.e. via an ioctl()) more than once in msec amount
  2498. of time. Try this for now...
  2499. ------------------------------------------------------------------------ */
  2500. fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
  2501. memoff(ch);
  2502. restore_flags(flags);
  2503. } /* End digi_send_break */
  2504. /* --------------------- Begin setup_empty_event ----------------------- */
  2505. static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
  2506. { /* Begin setup_empty_event */
  2507. volatile struct board_chan *bc = ch->brdchan;
  2508. unsigned long int flags;
  2509. save_flags(flags);
  2510. cli();
  2511. globalwinon(ch);
  2512. ch->statusflags |= EMPTYWAIT;
  2513. /* ------------------------------------------------------------------
  2514. When set the iempty flag request a event to be generated when the
  2515. transmit buffer is empty (If there is no BREAK in progress).
  2516. --------------------------------------------------------------------- */
  2517. bc->iempty = 1;
  2518. memoff(ch);
  2519. restore_flags(flags);
  2520. } /* End setup_empty_event */
  2521. /* --------------------- Begin get_termio ----------------------- */
  2522. static int get_termio(struct tty_struct * tty, struct termio __user * termio)
  2523. { /* Begin get_termio */
  2524. return kernel_termios_to_user_termio(termio, tty->termios);
  2525. } /* End get_termio */
  2526. /* ---------------------- Begin epca_setup -------------------------- */
  2527. void epca_setup(char *str, int *ints)
  2528. { /* Begin epca_setup */
  2529. struct board_info board;
  2530. int index, loop, last;
  2531. char *temp, *t2;
  2532. unsigned len;
  2533. /* ----------------------------------------------------------------------
  2534. If this routine looks a little strange it is because it is only called
  2535. if a LILO append command is given to boot the kernel with parameters.
  2536. In this way, we can provide the user a method of changing his board
  2537. configuration without rebuilding the kernel.
  2538. ----------------------------------------------------------------------- */
  2539. if (!liloconfig)
  2540. liloconfig = 1;
  2541. memset(&board, 0, sizeof(board));
  2542. /* Assume the data is int first, later we can change it */
  2543. /* I think that array position 0 of ints holds the number of args */
  2544. for (last = 0, index = 1; index <= ints[0]; index++)
  2545. switch(index)
  2546. { /* Begin parse switch */
  2547. case 1:
  2548. board.status = ints[index];
  2549. /* ---------------------------------------------------------
  2550. We check for 2 (As opposed to 1; because 2 is a flag
  2551. instructing the driver to ignore epcaconfig.) For this
  2552. reason we check for 2.
  2553. ------------------------------------------------------------ */
  2554. if (board.status == 2)
  2555. { /* Begin ignore epcaconfig as well as lilo cmd line */
  2556. nbdevs = 0;
  2557. num_cards = 0;
  2558. return;
  2559. } /* End ignore epcaconfig as well as lilo cmd line */
  2560. if (board.status > 2)
  2561. {
  2562. printk(KERN_ERR "<Error> - epca_setup: Invalid board status 0x%x\n", board.status);
  2563. invalid_lilo_config = 1;
  2564. setup_error_code |= INVALID_BOARD_STATUS;
  2565. return;
  2566. }
  2567. last = index;
  2568. break;
  2569. case 2:
  2570. board.type = ints[index];
  2571. if (board.type >= PCIXEM)
  2572. {
  2573. printk(KERN_ERR "<Error> - epca_setup: Invalid board type 0x%x\n", board.type);
  2574. invalid_lilo_config = 1;
  2575. setup_error_code |= INVALID_BOARD_TYPE;
  2576. return;
  2577. }
  2578. last = index;
  2579. break;
  2580. case 3:
  2581. board.altpin = ints[index];
  2582. if (board.altpin > 1)
  2583. {
  2584. printk(KERN_ERR "<Error> - epca_setup: Invalid board altpin 0x%x\n", board.altpin);
  2585. invalid_lilo_config = 1;
  2586. setup_error_code |= INVALID_ALTPIN;
  2587. return;
  2588. }
  2589. last = index;
  2590. break;
  2591. case 4:
  2592. board.numports = ints[index];
  2593. if ((board.numports < 2) || (board.numports > 256))
  2594. {
  2595. printk(KERN_ERR "<Error> - epca_setup: Invalid board numports 0x%x\n", board.numports);
  2596. invalid_lilo_config = 1;
  2597. setup_error_code |= INVALID_NUM_PORTS;
  2598. return;
  2599. }
  2600. nbdevs += board.numports;
  2601. last = index;
  2602. break;
  2603. case 5:
  2604. board.port = (unsigned char *)ints[index];
  2605. if (ints[index] <= 0)
  2606. {
  2607. printk(KERN_ERR "<Error> - epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
  2608. invalid_lilo_config = 1;
  2609. setup_error_code |= INVALID_PORT_BASE;
  2610. return;
  2611. }
  2612. last = index;
  2613. break;
  2614. case 6:
  2615. board.membase = (unsigned char *)ints[index];
  2616. if (ints[index] <= 0)
  2617. {
  2618. printk(KERN_ERR "<Error> - epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
  2619. invalid_lilo_config = 1;
  2620. setup_error_code |= INVALID_MEM_BASE;
  2621. return;
  2622. }
  2623. last = index;
  2624. break;
  2625. default:
  2626. printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
  2627. return;
  2628. } /* End parse switch */
  2629. while (str && *str)
  2630. { /* Begin while there is a string arg */
  2631. /* find the next comma or terminator */
  2632. temp = str;
  2633. /* While string is not null, and a comma hasn't been found */
  2634. while (*temp && (*temp != ','))
  2635. temp++;
  2636. if (!*temp)
  2637. temp = NULL;
  2638. else
  2639. *temp++ = 0;
  2640. /* Set index to the number of args + 1 */
  2641. index = last + 1;
  2642. switch(index)
  2643. {
  2644. case 1:
  2645. len = strlen(str);
  2646. if (strncmp("Disable", str, len) == 0)
  2647. board.status = 0;
  2648. else
  2649. if (strncmp("Enable", str, len) == 0)
  2650. board.status = 1;
  2651. else
  2652. {
  2653. printk(KERN_ERR "<Error> - epca_setup: Invalid status %s\n", str);
  2654. invalid_lilo_config = 1;
  2655. setup_error_code |= INVALID_BOARD_STATUS;
  2656. return;
  2657. }
  2658. last = index;
  2659. break;
  2660. case 2:
  2661. for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
  2662. if (strcmp(board_desc[loop], str) == 0)
  2663. break;
  2664. /* ---------------------------------------------------------------
  2665. If the index incremented above refers to a legitamate board
  2666. type set it here.
  2667. ------------------------------------------------------------------*/
  2668. if (index < EPCA_NUM_TYPES)
  2669. board.type = loop;
  2670. else
  2671. {
  2672. printk(KERN_ERR "<Error> - epca_setup: Invalid board type: %s\n", str);
  2673. invalid_lilo_config = 1;
  2674. setup_error_code |= INVALID_BOARD_TYPE;
  2675. return;
  2676. }
  2677. last = index;
  2678. break;
  2679. case 3:
  2680. len = strlen(str);
  2681. if (strncmp("Disable", str, len) == 0)
  2682. board.altpin = 0;
  2683. else
  2684. if (strncmp("Enable", str, len) == 0)
  2685. board.altpin = 1;
  2686. else
  2687. {
  2688. printk(KERN_ERR "<Error> - epca_setup: Invalid altpin %s\n", str);
  2689. invalid_lilo_config = 1;
  2690. setup_error_code |= INVALID_ALTPIN;
  2691. return;
  2692. }
  2693. last = index;
  2694. break;
  2695. case 4:
  2696. t2 = str;
  2697. while (isdigit(*t2))
  2698. t2++;
  2699. if (*t2)
  2700. {
  2701. printk(KERN_ERR "<Error> - epca_setup: Invalid port count %s\n", str);
  2702. invalid_lilo_config = 1;
  2703. setup_error_code |= INVALID_NUM_PORTS;
  2704. return;
  2705. }
  2706. /* ------------------------------------------------------------
  2707. There is not a man page for simple_strtoul but the code can be
  2708. found in vsprintf.c. The first argument is the string to
  2709. translate (To an unsigned long obviously), the second argument
  2710. can be the address of any character variable or a NULL. If a
  2711. variable is given, the end pointer of the string will be stored
  2712. in that variable; if a NULL is given the end pointer will
  2713. not be returned. The last argument is the base to use. If
  2714. a 0 is indicated, the routine will attempt to determine the
  2715. proper base by looking at the values prefix (A '0' for octal,
  2716. a 'x' for hex, etc ... If a value is given it will use that
  2717. value as the base.
  2718. ---------------------------------------------------------------- */
  2719. board.numports = simple_strtoul(str, NULL, 0);
  2720. nbdevs += board.numports;
  2721. last = index;
  2722. break;
  2723. case 5:
  2724. t2 = str;
  2725. while (isxdigit(*t2))
  2726. t2++;
  2727. if (*t2)
  2728. {
  2729. printk(KERN_ERR "<Error> - epca_setup: Invalid i/o address %s\n", str);
  2730. invalid_lilo_config = 1;
  2731. setup_error_code |= INVALID_PORT_BASE;
  2732. return;
  2733. }
  2734. board.port = (unsigned char *)simple_strtoul(str, NULL, 16);
  2735. last = index;
  2736. break;
  2737. case 6:
  2738. t2 = str;
  2739. while (isxdigit(*t2))
  2740. t2++;
  2741. if (*t2)
  2742. {
  2743. printk(KERN_ERR "<Error> - epca_setup: Invalid memory base %s\n",str);
  2744. invalid_lilo_config = 1;
  2745. setup_error_code |= INVALID_MEM_BASE;
  2746. return;
  2747. }
  2748. board.membase = (unsigned char *)simple_strtoul(str, NULL, 16);
  2749. last = index;
  2750. break;
  2751. default:
  2752. printk(KERN_ERR "PC/Xx: Too many string parms\n");
  2753. return;
  2754. }
  2755. str = temp;
  2756. } /* End while there is a string arg */
  2757. if (last < 6)
  2758. {
  2759. printk(KERN_ERR "PC/Xx: Insufficient parms specified\n");
  2760. return;
  2761. }
  2762. /* I should REALLY validate the stuff here */
  2763. /* Copies our local copy of board into boards */
  2764. memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
  2765. /* Does this get called once per lilo arg are what ? */
  2766. printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
  2767. num_cards, board_desc[board.type],
  2768. board.numports, (int)board.port, (unsigned int) board.membase);
  2769. num_cards++;
  2770. } /* End epca_setup */
  2771. #ifdef ENABLE_PCI
  2772. /* ------------------------ Begin init_PCI --------------------------- */
  2773. enum epic_board_types {
  2774. brd_xr = 0,
  2775. brd_xem,
  2776. brd_cx,
  2777. brd_xrj,
  2778. };
  2779. /* indexed directly by epic_board_types enum */
  2780. static struct {
  2781. unsigned char board_type;
  2782. unsigned bar_idx; /* PCI base address region */
  2783. } epca_info_tbl[] = {
  2784. { PCIXR, 0, },
  2785. { PCIXEM, 0, },
  2786. { PCICX, 0, },
  2787. { PCIXRJ, 2, },
  2788. };
  2789. static int __devinit epca_init_one (struct pci_dev *pdev,
  2790. const struct pci_device_id *ent)
  2791. {
  2792. static int board_num = -1;
  2793. int board_idx, info_idx = ent->driver_data;
  2794. unsigned long addr;
  2795. if (pci_enable_device(pdev))
  2796. return -EIO;
  2797. board_num++;
  2798. board_idx = board_num + num_cards;
  2799. if (board_idx >= MAXBOARDS)
  2800. goto err_out;
  2801. addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
  2802. if (!addr) {
  2803. printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
  2804. epca_info_tbl[info_idx].bar_idx);
  2805. goto err_out;
  2806. }
  2807. boards[board_idx].status = ENABLED;
  2808. boards[board_idx].type = epca_info_tbl[info_idx].board_type;
  2809. boards[board_idx].numports = 0x0;
  2810. boards[board_idx].port =
  2811. (unsigned char *)((char *) addr + PCI_IO_OFFSET);
  2812. boards[board_idx].membase =
  2813. (unsigned char *)((char *) addr);
  2814. if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
  2815. printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
  2816. 0x200000, addr + PCI_IO_OFFSET);
  2817. goto err_out;
  2818. }
  2819. boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
  2820. if (!boards[board_idx].re_map_port) {
  2821. printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
  2822. 0x200000, addr + PCI_IO_OFFSET);
  2823. goto err_out_free_pciio;
  2824. }
  2825. if (!request_mem_region (addr, 0x200000, "epca")) {
  2826. printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
  2827. 0x200000, addr);
  2828. goto err_out_free_iounmap;
  2829. }
  2830. boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
  2831. if (!boards[board_idx].re_map_membase) {
  2832. printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
  2833. 0x200000, addr + PCI_IO_OFFSET);
  2834. goto err_out_free_memregion;
  2835. }
  2836. /* --------------------------------------------------------------
  2837. I don't know what the below does, but the hardware guys say
  2838. its required on everything except PLX (In this case XRJ).
  2839. ---------------------------------------------------------------- */
  2840. if (info_idx != brd_xrj) {
  2841. pci_write_config_byte(pdev, 0x40, 0);
  2842. pci_write_config_byte(pdev, 0x46, 0);
  2843. }
  2844. return 0;
  2845. err_out_free_memregion:
  2846. release_mem_region (addr, 0x200000);
  2847. err_out_free_iounmap:
  2848. iounmap (boards[board_idx].re_map_port);
  2849. err_out_free_pciio:
  2850. release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
  2851. err_out:
  2852. return -ENODEV;
  2853. }
  2854. static struct pci_device_id epca_pci_tbl[] = {
  2855. { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
  2856. { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
  2857. { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
  2858. { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
  2859. { 0, }
  2860. };
  2861. MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
  2862. int __init init_PCI (void)
  2863. { /* Begin init_PCI */
  2864. memset (&epca_driver, 0, sizeof (epca_driver));
  2865. epca_driver.name = "epca";
  2866. epca_driver.id_table = epca_pci_tbl;
  2867. epca_driver.probe = epca_init_one;
  2868. return pci_register_driver(&epca_driver);
  2869. } /* End init_PCI */
  2870. #endif /* ENABLE_PCI */
  2871. MODULE_LICENSE("GPL");