PageRenderTime 60ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/char/sx.c

https://bitbucket.org/evzijst/gittest
C | 2621 lines | 1653 code | 458 blank | 510 comment | 320 complexity | e1bc835ba89ca697969d28141e400705 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /* sx.c -- driver for the Specialix SX series cards.
  2. *
  3. * This driver will also support the older SI, and XIO cards.
  4. *
  5. *
  6. * (C) 1998 - 2004 R.E.Wolff@BitWizard.nl
  7. *
  8. * Simon Allen (simonallen@cix.compulink.co.uk) wrote a previous
  9. * version of this driver. Some fragments may have been copied. (none
  10. * yet :-)
  11. *
  12. * Specialix pays for the development and support of this driver.
  13. * Please DO contact support@specialix.co.uk if you require
  14. * support. But please read the documentation (sx.txt) first.
  15. *
  16. *
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License as
  20. * published by the Free Software Foundation; either version 2 of
  21. * the License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be
  24. * useful, but WITHOUT ANY WARRANTY; without even the implied
  25. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  26. * PURPOSE. See the GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public
  29. * License along with this program; if not, write to the Free
  30. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  31. * USA.
  32. *
  33. * Revision history:
  34. * $Log: sx.c,v $
  35. * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
  36. * - Fixed module and port counting
  37. * - Fixed signal handling
  38. * - Fixed an Ooops
  39. *
  40. * Revision 1.32 2000/03/07 09:00:00 wolff,pvdl
  41. * - Fixed some sx_dprintk typos
  42. * - added detection for an invalid board/module configuration
  43. *
  44. * Revision 1.31 2000/03/06 12:00:00 wolff,pvdl
  45. * - Added support for EISA
  46. *
  47. * Revision 1.30 2000/01/21 17:43:06 wolff
  48. * - Added support for SX+
  49. *
  50. * Revision 1.26 1999/08/05 15:22:14 wolff
  51. * - Port to 2.3.x
  52. * - Reformatted to Linus' liking.
  53. *
  54. * Revision 1.25 1999/07/30 14:24:08 wolff
  55. * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0).
  56. *
  57. * Revision 1.24 1999/07/28 09:41:52 wolff
  58. * - I noticed the remark about use-count straying in sx.txt. I checked
  59. * sx_open, and found a few places where that could happen. I hope it's
  60. * fixed now.
  61. *
  62. * Revision 1.23 1999/07/28 08:56:06 wolff
  63. * - Fixed crash when sx_firmware run twice.
  64. * - Added sx_slowpoll as a module parameter (I guess nobody really wanted
  65. * to change it from the default... )
  66. * - Fixed a stupid editing problem I introduced in 1.22.
  67. * - Fixed dropping characters on a termios change.
  68. *
  69. * Revision 1.22 1999/07/26 21:01:43 wolff
  70. * Russell Brown noticed that I had overlooked 4 out of six modem control
  71. * signals in sx_getsignals. Ooops.
  72. *
  73. * Revision 1.21 1999/07/23 09:11:33 wolff
  74. * I forgot to free dynamically allocated memory when the driver is unloaded.
  75. *
  76. * Revision 1.20 1999/07/20 06:25:26 wolff
  77. * The "closing wait" wasn't honoured. Thanks to James Griffiths for
  78. * reporting this.
  79. *
  80. * Revision 1.19 1999/07/11 08:59:59 wolff
  81. * Fixed an oops in close, when an open was pending. Changed the memtest
  82. * a bit. Should also test the board in word-mode, however my card fails the
  83. * memtest then. I still have to figure out what is wrong...
  84. *
  85. * Revision 1.18 1999/06/10 09:38:42 wolff
  86. * Changed the format of the firmware revision from %04x to %x.%02x .
  87. *
  88. * Revision 1.17 1999/06/04 09:44:35 wolff
  89. * fixed problem: reference to pci stuff when config_pci was off...
  90. * Thanks to Jorge Novo for noticing this.
  91. *
  92. * Revision 1.16 1999/06/02 08:30:15 wolff
  93. * added/removed the workaround for the DCD bug in the Firmware.
  94. * A bit more debugging code to locate that...
  95. *
  96. * Revision 1.15 1999/06/01 11:35:30 wolff
  97. * when DCD is left low (floating?), on TA's the firmware first tells us
  98. * that DCD is high, but after a short while suddenly comes to the
  99. * conclusion that it is low. All this would be fine, if it weren't that
  100. * Unix requires us to send a "hangup" signal in that case. This usually
  101. * all happens BEFORE the program has had a chance to ioctl the device
  102. * into clocal mode..
  103. *
  104. * Revision 1.14 1999/05/25 11:18:59 wolff
  105. * Added PCI-fix.
  106. * Added checks for return code of sx_sendcommand.
  107. * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...)
  108. *
  109. * Revision 1.13 1999/04/29 15:18:01 wolff
  110. * Fixed an "oops" that showed on SuSE 6.0 systems.
  111. * Activate DTR again after stty 0.
  112. *
  113. * Revision 1.12 1999/04/29 07:49:52 wolff
  114. * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming
  115. * the connection would be dropped anyway. That is not always the case,
  116. * and confuses people).
  117. * Told the card to always monitor the modem signals.
  118. * Added support for dynamic gs_debug adjustments.
  119. * Now tells the rest of the system the number of ports.
  120. *
  121. * Revision 1.11 1999/04/24 11:11:30 wolff
  122. * Fixed two stupid typos in the memory test.
  123. *
  124. * Revision 1.10 1999/04/24 10:53:39 wolff
  125. * Added some of Christian's suggestions.
  126. * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the
  127. * card to send the signal to the process.....)
  128. *
  129. * Revision 1.9 1999/04/23 07:26:38 wolff
  130. * Included Christian Lademann's 2.0 compile-warning fixes and interrupt
  131. * assignment redesign.
  132. * Cleanup of some other stuff.
  133. *
  134. * Revision 1.8 1999/04/16 13:05:30 wolff
  135. * fixed a DCD change unnoticed bug.
  136. *
  137. * Revision 1.7 1999/04/14 22:19:51 wolff
  138. * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!)
  139. *
  140. * Revision 1.6 1999/04/13 18:40:20 wolff
  141. * changed misc-minor to 161, as assigned by HPA.
  142. *
  143. * Revision 1.5 1999/04/13 15:12:25 wolff
  144. * Fixed use-count leak when "hangup" occurred.
  145. * Added workaround for a stupid-PCIBIOS bug.
  146. *
  147. *
  148. * Revision 1.4 1999/04/01 22:47:40 wolff
  149. * Fixed < 1M linux-2.0 problem.
  150. * (vremap isn't compatible with ioremap in that case)
  151. *
  152. * Revision 1.3 1999/03/31 13:45:45 wolff
  153. * Firmware loading is now done through a separate IOCTL.
  154. *
  155. * Revision 1.2 1999/03/28 12:22:29 wolff
  156. * rcs cleanup
  157. *
  158. * Revision 1.1 1999/03/28 12:10:34 wolff
  159. * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS).
  160. *
  161. * Revision 0.12 1999/03/28 09:20:10 wolff
  162. * Fixed problem in 0.11, continueing cleanup.
  163. *
  164. * Revision 0.11 1999/03/28 08:46:44 wolff
  165. * cleanup. Not good.
  166. *
  167. * Revision 0.10 1999/03/28 08:09:43 wolff
  168. * Fixed loosing characters on close.
  169. *
  170. * Revision 0.9 1999/03/21 22:52:01 wolff
  171. * Ported back to 2.2.... (minor things)
  172. *
  173. * Revision 0.8 1999/03/21 22:40:33 wolff
  174. * Port to 2.0
  175. *
  176. * Revision 0.7 1999/03/21 19:06:34 wolff
  177. * Fixed hangup processing.
  178. *
  179. * Revision 0.6 1999/02/05 08:45:14 wolff
  180. * fixed real_raw problems. Inclusion into kernel imminent.
  181. *
  182. * Revision 0.5 1998/12/21 23:51:06 wolff
  183. * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it
  184. * shouldn't have. THATs why I want to have transmit interrupts even when
  185. * the buffer is empty.
  186. *
  187. * Revision 0.4 1998/12/17 09:34:46 wolff
  188. * PPP works. ioctl works. Basically works!
  189. *
  190. * Revision 0.3 1998/12/15 13:05:18 wolff
  191. * It works! Wow! Gotta start implementing IOCTL and stuff....
  192. *
  193. * Revision 0.2 1998/12/01 08:33:53 wolff
  194. * moved over to 2.1.130
  195. *
  196. * Revision 0.1 1998/11/03 21:23:51 wolff
  197. * Initial revision. Detects SX card.
  198. *
  199. * */
  200. #define RCS_ID "$Id: sx.c,v 1.33 2000/03/08 10:01:02 wolff, pvdl Exp $"
  201. #define RCS_REV "$Revision: 1.33 $"
  202. #include <linux/module.h>
  203. #include <linux/config.h>
  204. #include <linux/kdev_t.h>
  205. #include <linux/kernel.h>
  206. #include <linux/sched.h>
  207. #include <linux/ioport.h>
  208. #include <linux/interrupt.h>
  209. #include <linux/errno.h>
  210. #include <linux/tty.h>
  211. #include <linux/tty_flip.h>
  212. #include <linux/mm.h>
  213. #include <linux/serial.h>
  214. #include <linux/fcntl.h>
  215. #include <linux/major.h>
  216. #include <linux/delay.h>
  217. #include <linux/pci.h>
  218. #include <linux/slab.h>
  219. #include <linux/init.h>
  220. #include <linux/miscdevice.h>
  221. #include <linux/bitops.h>
  222. #include <asm/io.h>
  223. #include <asm/uaccess.h>
  224. /* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */
  225. #define BYTE u8
  226. #define WORD u16
  227. /* .... but the 3.0.4 version uses _u8 and _u16. */
  228. #define _u8 u8
  229. #define _u16 u16
  230. #include "sxboards.h"
  231. #include "sxwindow.h"
  232. #include <linux/generic_serial.h>
  233. #include "sx.h"
  234. /* I don't think that this driver can handle more than 256 ports on
  235. one machine. You'll have to increase the number of boards in sx.h
  236. if you want more than 4 boards. */
  237. #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
  238. #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
  239. #endif
  240. #ifdef CONFIG_PCI
  241. static struct pci_device_id sx_pci_tbl[] = {
  242. { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, PCI_ANY_ID, PCI_ANY_ID },
  243. { 0 }
  244. };
  245. MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
  246. #endif /* CONFIG_PCI */
  247. /* Configurable options:
  248. (Don't be too sure that it'll work if you toggle them) */
  249. /* Am I paranoid or not ? ;-) */
  250. #undef SX_PARANOIA_CHECK
  251. /* 20 -> 2000 per second. The card should rate-limit interrupts at 100
  252. Hz, but it is user configurable. I don't recommend going above 1000
  253. Hz. The interrupt ratelimit might trigger if the interrupt is
  254. shared with a very active other device. */
  255. #define IRQ_RATE_LIMIT 20
  256. /* Sharing interrupts is possible now. If the other device wants more
  257. than 2000 interrupts per second, we'd gracefully decline further
  258. interrupts. That's not what we want. On the other hand, if the
  259. other device interrupts 2000 times a second, don't use the SX
  260. interrupt. Use polling. */
  261. #undef IRQ_RATE_LIMIT
  262. #if 0
  263. /* Not implemented */
  264. /*
  265. * The following defines are mostly for testing purposes. But if you need
  266. * some nice reporting in your syslog, you can define them also.
  267. */
  268. #define SX_REPORT_FIFO
  269. #define SX_REPORT_OVERRUN
  270. #endif
  271. /* Function prototypes */
  272. static void sx_disable_tx_interrupts (void * ptr);
  273. static void sx_enable_tx_interrupts (void * ptr);
  274. static void sx_disable_rx_interrupts (void * ptr);
  275. static void sx_enable_rx_interrupts (void * ptr);
  276. static int sx_get_CD (void * ptr);
  277. static void sx_shutdown_port (void * ptr);
  278. static int sx_set_real_termios (void *ptr);
  279. static void sx_close (void *ptr);
  280. static int sx_chars_in_buffer (void * ptr);
  281. static int sx_init_board (struct sx_board *board);
  282. static int sx_init_portstructs (int nboards, int nports);
  283. static int sx_fw_ioctl (struct inode *inode, struct file *filp,
  284. unsigned int cmd, unsigned long arg);
  285. static int sx_init_drivers(void);
  286. static struct tty_driver *sx_driver;
  287. static struct sx_board boards[SX_NBOARDS];
  288. static struct sx_port *sx_ports;
  289. static int sx_initialized;
  290. static int sx_nports;
  291. static int sx_debug;
  292. /* You can have the driver poll your card.
  293. - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
  294. This is used when the card cannot use an interrupt for some reason.
  295. - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If
  296. the driver misses an interrupt (report this if it DOES happen to you!)
  297. everything will continue to work....
  298. */
  299. static int sx_poll = 1;
  300. static int sx_slowpoll;
  301. /* The card limits the number of interrupts per second.
  302. At 115k2 "100" should be sufficient.
  303. If you're using higher baudrates, you can increase this...
  304. */
  305. static int sx_maxints = 100;
  306. /* These are the only open spaces in my computer. Yours may have more
  307. or less.... -- REW
  308. duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
  309. */
  310. static int sx_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
  311. 0xc8000, 0xd8000, 0xe8000};
  312. static int si_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000,
  313. 0xc8000, 0xd8000, 0xe8000, 0xa0000};
  314. static int si1_probe_addrs[]= { 0xd0000};
  315. #define NR_SX_ADDRS (sizeof(sx_probe_addrs)/sizeof (int))
  316. #define NR_SI_ADDRS (sizeof(si_probe_addrs)/sizeof (int))
  317. #define NR_SI1_ADDRS (sizeof(si1_probe_addrs)/sizeof (int))
  318. /* Set the mask to all-ones. This alas, only supports 32 interrupts.
  319. Some architectures may need more. */
  320. static int sx_irqmask = -1;
  321. module_param_array(sx_probe_addrs, int, NULL, 0);
  322. module_param_array(si_probe_addrs, int, NULL, 0);
  323. module_param(sx_poll, int, 0);
  324. module_param(sx_slowpoll, int, 0);
  325. module_param(sx_maxints, int, 0);
  326. module_param(sx_debug, int, 0);
  327. module_param(sx_irqmask, int, 0);
  328. MODULE_LICENSE("GPL");
  329. static struct real_driver sx_real_driver = {
  330. sx_disable_tx_interrupts,
  331. sx_enable_tx_interrupts,
  332. sx_disable_rx_interrupts,
  333. sx_enable_rx_interrupts,
  334. sx_get_CD,
  335. sx_shutdown_port,
  336. sx_set_real_termios,
  337. sx_chars_in_buffer,
  338. sx_close,
  339. };
  340. /*
  341. This driver can spew a whole lot of debugging output at you. If you
  342. need maximum performance, you should disable the DEBUG define. To
  343. aid in debugging in the field, I'm leaving the compile-time debug
  344. features enabled, and disable them "runtime". That allows me to
  345. instruct people with problems to enable debugging without requiring
  346. them to recompile...
  347. */
  348. #define DEBUG
  349. #ifdef DEBUG
  350. #define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
  351. #else
  352. #define sx_dprintk(f, str...) /* nothing */
  353. #endif
  354. #define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__)
  355. #define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit %s\n", __FUNCTION__)
  356. #define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
  357. __FUNCTION__, port->line)
  358. /*
  359. * Firmware loader driver specific routines
  360. *
  361. */
  362. static struct file_operations sx_fw_fops = {
  363. .owner = THIS_MODULE,
  364. .ioctl = sx_fw_ioctl,
  365. };
  366. static struct miscdevice sx_fw_device = {
  367. SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
  368. };
  369. #ifdef SX_PARANOIA_CHECK
  370. /* This doesn't work. Who's paranoid around here? Not me! */
  371. static inline int sx_paranoia_check(struct sx_port const * port,
  372. char *name, const char *routine)
  373. {
  374. static const char *badmagic =
  375. KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
  376. static const char *badinfo =
  377. KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
  378. if (!port) {
  379. printk(badinfo, name, routine);
  380. return 1;
  381. }
  382. if (port->magic != SX_MAGIC) {
  383. printk(badmagic, name, routine);
  384. return 1;
  385. }
  386. return 0;
  387. }
  388. #else
  389. #define sx_paranoia_check(a,b,c) 0
  390. #endif
  391. /* The timeouts. First try 30 times as fast as possible. Then give
  392. the card some time to breathe between accesses. (Otherwise the
  393. processor on the card might not be able to access its OWN bus... */
  394. #define TIMEOUT_1 30
  395. #define TIMEOUT_2 1000000
  396. #ifdef DEBUG
  397. static void my_hd_io(void __iomem *p, int len)
  398. {
  399. int i, j, ch;
  400. unsigned char __iomem *addr = p;
  401. for (i=0;i<len;i+=16) {
  402. printk ("%p ", addr+i);
  403. for (j=0;j<16;j++) {
  404. printk ("%02x %s", readb(addr+j+i), (j==7)?" ":"");
  405. }
  406. for (j=0;j<16;j++) {
  407. ch = readb(addr+j+i);
  408. printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
  409. }
  410. printk ("\n");
  411. }
  412. }
  413. static void my_hd(void *p, int len)
  414. {
  415. int i, j, ch;
  416. unsigned char *addr = p;
  417. for (i=0;i<len;i+=16) {
  418. printk ("%p ", addr+i);
  419. for (j=0;j<16;j++) {
  420. printk ("%02x %s", addr[j+i], (j==7)?" ":"");
  421. }
  422. for (j=0;j<16;j++) {
  423. ch = addr[j+i];
  424. printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch));
  425. }
  426. printk ("\n");
  427. }
  428. }
  429. #endif
  430. /* This needs redoing for Alpha -- REW -- Done. */
  431. static inline void write_sx_byte (struct sx_board *board, int offset, u8 byte)
  432. {
  433. writeb (byte, board->base+offset);
  434. }
  435. static inline u8 read_sx_byte (struct sx_board *board, int offset)
  436. {
  437. return readb (board->base+offset);
  438. }
  439. static inline void write_sx_word (struct sx_board *board, int offset, u16 word)
  440. {
  441. writew (word, board->base+offset);
  442. }
  443. static inline u16 read_sx_word (struct sx_board *board, int offset)
  444. {
  445. return readw (board->base + offset);
  446. }
  447. static int sx_busy_wait_eq (struct sx_board *board,
  448. int offset, int mask, int correctval)
  449. {
  450. int i;
  451. func_enter ();
  452. for (i=0; i < TIMEOUT_1 ;i++)
  453. if ((read_sx_byte (board, offset) & mask) == correctval) {
  454. func_exit ();
  455. return 1;
  456. }
  457. for (i=0; i < TIMEOUT_2 ;i++) {
  458. if ((read_sx_byte (board, offset) & mask) == correctval) {
  459. func_exit ();
  460. return 1;
  461. }
  462. udelay (1);
  463. }
  464. func_exit ();
  465. return 0;
  466. }
  467. static int sx_busy_wait_neq (struct sx_board *board,
  468. int offset, int mask, int badval)
  469. {
  470. int i;
  471. func_enter ();
  472. for (i=0; i < TIMEOUT_1 ;i++)
  473. if ((read_sx_byte (board, offset) & mask) != badval) {
  474. func_exit ();
  475. return 1;
  476. }
  477. for (i=0; i < TIMEOUT_2 ;i++) {
  478. if ((read_sx_byte (board, offset) & mask) != badval) {
  479. func_exit ();
  480. return 1;
  481. }
  482. udelay (1);
  483. }
  484. func_exit ();
  485. return 0;
  486. }
  487. /* 5.6.4 of 6210028 r2.3 */
  488. static int sx_reset (struct sx_board *board)
  489. {
  490. func_enter ();
  491. if (IS_SX_BOARD (board)) {
  492. write_sx_byte (board, SX_CONFIG, 0);
  493. write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */
  494. if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) {
  495. printk (KERN_INFO "sx: Card doesn't respond to reset....\n");
  496. return 0;
  497. }
  498. } else if (IS_EISA_BOARD(board)) {
  499. outb(board->irq<<4, board->eisa_base+0xc02);
  500. } else if (IS_SI1_BOARD(board)) {
  501. write_sx_byte (board, SI1_ISA_RESET, 0); // value does not matter
  502. } else {
  503. /* Gory details of the SI/ISA board */
  504. write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
  505. write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
  506. write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
  507. write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
  508. write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
  509. write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
  510. }
  511. func_exit ();
  512. return 1;
  513. }
  514. /* This doesn't work on machines where "NULL" isn't 0 */
  515. /* If you have one of those, someone will need to write
  516. the equivalent of this, which will amount to about 3 lines. I don't
  517. want to complicate this right now. -- REW
  518. (See, I do write comments every now and then :-) */
  519. #define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
  520. #define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
  521. #define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
  522. #define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
  523. #define sx_write_channel_byte(port, elem, val) \
  524. write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
  525. #define sx_read_channel_byte(port, elem) \
  526. read_sx_byte (port->board, CHAN_OFFSET (port, elem))
  527. #define sx_write_channel_word(port, elem, val) \
  528. write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
  529. #define sx_read_channel_word(port, elem) \
  530. read_sx_word (port->board, CHAN_OFFSET (port, elem))
  531. #define sx_write_module_byte(board, addr, elem, val) \
  532. write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
  533. #define sx_read_module_byte(board, addr, elem) \
  534. read_sx_byte (board, MODU_OFFSET (board, addr, elem))
  535. #define sx_write_module_word(board, addr, elem, val) \
  536. write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
  537. #define sx_read_module_word(board, addr, elem) \
  538. read_sx_word (board, MODU_OFFSET (board, addr, elem))
  539. #define sx_write_board_byte(board, elem, val) \
  540. write_sx_byte (board, BRD_OFFSET (board, elem), val)
  541. #define sx_read_board_byte(board, elem) \
  542. read_sx_byte (board, BRD_OFFSET (board, elem))
  543. #define sx_write_board_word(board, elem, val) \
  544. write_sx_word (board, BRD_OFFSET (board, elem), val)
  545. #define sx_read_board_word(board, elem) \
  546. read_sx_word (board, BRD_OFFSET (board, elem))
  547. static int sx_start_board (struct sx_board *board)
  548. {
  549. if (IS_SX_BOARD (board)) {
  550. write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN);
  551. } else if (IS_EISA_BOARD(board)) {
  552. write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
  553. outb((board->irq<<4)|4, board->eisa_base+0xc02);
  554. } else if (IS_SI1_BOARD(board)) {
  555. write_sx_byte (board, SI1_ISA_RESET_CLEAR, 0);
  556. write_sx_byte (board, SI1_ISA_INTCL, 0);
  557. } else {
  558. /* Don't bug me about the clear_set.
  559. I haven't the foggiest idea what it's about -- REW */
  560. write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
  561. write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
  562. }
  563. return 1;
  564. }
  565. #define SX_IRQ_REG_VAL(board) \
  566. ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0)
  567. /* Note. The SX register is write-only. Therefore, we have to enable the
  568. bus too. This is a no-op, if you don't mess with this driver... */
  569. static int sx_start_interrupts (struct sx_board *board)
  570. {
  571. /* Don't call this with board->irq == 0 */
  572. if (IS_SX_BOARD(board)) {
  573. write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) |
  574. SX_CONF_BUSEN |
  575. SX_CONF_HOSTIRQ);
  576. } else if (IS_EISA_BOARD(board)) {
  577. inb(board->eisa_base+0xc03);
  578. } else if (IS_SI1_BOARD(board)) {
  579. write_sx_byte (board, SI1_ISA_INTCL,0);
  580. write_sx_byte (board, SI1_ISA_INTCL_CLEAR,0);
  581. } else {
  582. switch (board->irq) {
  583. case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break;
  584. case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break;
  585. case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break;
  586. default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n",
  587. board->irq);
  588. return 0;
  589. }
  590. write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
  591. }
  592. return 1;
  593. }
  594. static int sx_send_command (struct sx_port *port,
  595. int command, int mask, int newstat)
  596. {
  597. func_enter2 ();
  598. write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command);
  599. func_exit ();
  600. return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat);
  601. }
  602. static char *mod_type_s (int module_type)
  603. {
  604. switch (module_type) {
  605. case TA4: return "TA4";
  606. case TA8: return "TA8";
  607. case TA4_ASIC: return "TA4_ASIC";
  608. case TA8_ASIC: return "TA8_ASIC";
  609. case MTA_CD1400:return "MTA_CD1400";
  610. case SXDC: return "SXDC";
  611. default:return "Unknown/invalid";
  612. }
  613. }
  614. static char *pan_type_s (int pan_type)
  615. {
  616. switch (pan_type) {
  617. case MOD_RS232DB25: return "MOD_RS232DB25";
  618. case MOD_RS232RJ45: return "MOD_RS232RJ45";
  619. case MOD_RS422DB25: return "MOD_RS422DB25";
  620. case MOD_PARALLEL: return "MOD_PARALLEL";
  621. case MOD_2_RS232DB25: return "MOD_2_RS232DB25";
  622. case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45";
  623. case MOD_2_RS422DB25: return "MOD_2_RS422DB25";
  624. case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE";
  625. case MOD_2_PARALLEL: return "MOD_2_PARALLEL";
  626. case MOD_BLANK: return "empty";
  627. default:return "invalid";
  628. }
  629. }
  630. static int mod_compat_type (int module_type)
  631. {
  632. return module_type >> 4;
  633. }
  634. static void sx_reconfigure_port(struct sx_port *port)
  635. {
  636. if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) {
  637. if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
  638. printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n");
  639. }
  640. } else {
  641. sx_dprintk (SX_DEBUG_TERMIOS,
  642. "sx: Not sending reconfigure: port isn't open (%02x).\n",
  643. sx_read_channel_byte (port, hi_hstat));
  644. }
  645. }
  646. static void sx_setsignals (struct sx_port *port, int dtr, int rts)
  647. {
  648. int t;
  649. func_enter2 ();
  650. t = sx_read_channel_byte (port, hi_op);
  651. if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR);
  652. if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS);
  653. sx_write_channel_byte (port, hi_op, t);
  654. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
  655. func_exit ();
  656. }
  657. static int sx_getsignals (struct sx_port *port)
  658. {
  659. int i_stat,o_stat;
  660. o_stat = sx_read_channel_byte (port, hi_op);
  661. i_stat = sx_read_channel_byte (port, hi_ip);
  662. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n",
  663. (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
  664. port->c_dcd, sx_get_CD (port),
  665. sx_read_channel_byte (port, hi_ip),
  666. sx_read_channel_byte (port, hi_state));
  667. return (((o_stat & OP_DTR)?TIOCM_DTR:0) |
  668. ((o_stat & OP_RTS)?TIOCM_RTS:0) |
  669. ((i_stat & IP_CTS)?TIOCM_CTS:0) |
  670. ((i_stat & IP_DCD)?TIOCM_CAR:0) |
  671. ((i_stat & IP_DSR)?TIOCM_DSR:0) |
  672. ((i_stat & IP_RI)?TIOCM_RNG:0)
  673. );
  674. }
  675. static void sx_set_baud (struct sx_port *port)
  676. {
  677. int t;
  678. if (port->board->ta_type == MOD_SXDC) {
  679. switch (port->gs.baud) {
  680. /* Save some typing work... */
  681. #define e(x) case x:t= BAUD_ ## x ; break
  682. e(50);e(75);e(110);e(150);e(200);e(300);e(600);
  683. e(1200);e(1800);e(2000);e(2400);e(4800);e(7200);
  684. e(9600);e(14400);e(19200);e(28800);e(38400);
  685. e(56000);e(57600);e(64000);e(76800);e(115200);
  686. e(128000);e(150000);e(230400);e(256000);e(460800);
  687. e(921600);
  688. case 134 :t = BAUD_134_5; break;
  689. case 0 :t = -1;
  690. break;
  691. default:
  692. /* Can I return "invalid"? */
  693. t = BAUD_9600;
  694. printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud);
  695. break;
  696. }
  697. #undef e
  698. if (t > 0) {
  699. /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
  700. sx_setsignals (port, 1, -1);
  701. /* XXX This is not TA & MTA compatible */
  702. sx_write_channel_byte (port, hi_csr, 0xff);
  703. sx_write_channel_byte (port, hi_txbaud, t);
  704. sx_write_channel_byte (port, hi_rxbaud, t);
  705. } else {
  706. sx_setsignals (port, 0, -1);
  707. }
  708. } else {
  709. switch (port->gs.baud) {
  710. #define e(x) case x:t= CSR_ ## x ; break
  711. e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800);
  712. e(1800);e(9600);
  713. e(19200);e(57600);e(38400);
  714. /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
  715. case 110:
  716. if (port->board->ta_type == MOD_TA) {
  717. t = CSR_110;
  718. break;
  719. } else {
  720. t = CSR_9600;
  721. printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
  722. break;
  723. }
  724. case 115200:
  725. if (port->board->ta_type == MOD_TA) {
  726. t = CSR_9600;
  727. printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
  728. break;
  729. } else {
  730. t = CSR_110;
  731. break;
  732. }
  733. case 0 :t = -1;
  734. break;
  735. default:
  736. t = CSR_9600;
  737. printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud);
  738. break;
  739. }
  740. #undef e
  741. if (t >= 0) {
  742. sx_setsignals (port, 1, -1);
  743. sx_write_channel_byte (port, hi_csr, t * 0x11);
  744. } else {
  745. sx_setsignals (port, 0, -1);
  746. }
  747. }
  748. }
  749. /* Simon Allen's version of this routine was 225 lines long. 85 is a lot
  750. better. -- REW */
  751. static int sx_set_real_termios (void *ptr)
  752. {
  753. struct sx_port *port = ptr;
  754. func_enter2();
  755. if (!port->gs.tty)
  756. return 0;
  757. /* What is this doing here? -- REW
  758. Ha! figured it out. It is to allow you to get DTR active again
  759. if you've dropped it with stty 0. Moved to set_baud, where it
  760. belongs (next to the drop dtr if baud == 0) -- REW */
  761. /* sx_setsignals (port, 1, -1); */
  762. sx_set_baud (port);
  763. #define CFLAG port->gs.tty->termios->c_cflag
  764. sx_write_channel_byte (port, hi_mr1,
  765. (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) |
  766. (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) |
  767. (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) |
  768. (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) |
  769. (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) |
  770. (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) |
  771. (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) );
  772. sx_write_channel_byte (port, hi_mr2,
  773. (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) |
  774. (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP));
  775. switch (CFLAG & CSIZE) {
  776. case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break;
  777. case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break;
  778. case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break;
  779. case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break;
  780. default:
  781. printk (KERN_INFO "sx: Invalid wordsize: %d\n", CFLAG & CSIZE);
  782. break;
  783. }
  784. sx_write_channel_byte (port, hi_prtcl,
  785. (I_IXON (port->gs.tty)?SP_TXEN:0) |
  786. (I_IXOFF (port->gs.tty)?SP_RXEN:0) |
  787. (I_IXANY (port->gs.tty)?SP_TANY:0) |
  788. SP_DCEN);
  789. sx_write_channel_byte (port, hi_break,
  790. (I_IGNBRK(port->gs.tty)?BR_IGN:0 |
  791. I_BRKINT(port->gs.tty)?BR_INT:0));
  792. sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty));
  793. sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty));
  794. sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty));
  795. sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty));
  796. sx_reconfigure_port(port);
  797. /* Tell line discipline whether we will do input cooking */
  798. if(I_OTHER(port->gs.tty)) {
  799. clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
  800. } else {
  801. set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
  802. }
  803. sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
  804. port->gs.tty->termios->c_iflag,
  805. I_OTHER(port->gs.tty));
  806. /* Tell line discipline whether we will do output cooking.
  807. * If OPOST is set and no other output flags are set then we can do output
  808. * processing. Even if only *one* other flag in the O_OTHER group is set
  809. * we do cooking in software.
  810. */
  811. if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
  812. set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
  813. } else {
  814. clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
  815. }
  816. sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
  817. port->gs.tty->termios->c_oflag,
  818. O_OTHER(port->gs.tty));
  819. /* port->c_dcd = sx_get_CD (port); */
  820. func_exit ();
  821. return 0;
  822. }
  823. /* ********************************************************************** *
  824. * the interrupt related routines *
  825. * ********************************************************************** */
  826. /* Note:
  827. Other drivers use the macro "MIN" to calculate how much to copy.
  828. This has the disadvantage that it will evaluate parts twice. That's
  829. expensive when it's IO (and the compiler cannot optimize those away!).
  830. Moreover, I'm not sure that you're race-free.
  831. I assign a value, and then only allow the value to decrease. This
  832. is always safe. This makes the code a few lines longer, and you
  833. know I'm dead against that, but I think it is required in this
  834. case. */
  835. static void sx_transmit_chars (struct sx_port *port)
  836. {
  837. int c;
  838. int tx_ip;
  839. int txroom;
  840. func_enter2 ();
  841. sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
  842. port, port->gs.xmit_cnt);
  843. if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) {
  844. return;
  845. }
  846. while (1) {
  847. c = port->gs.xmit_cnt;
  848. sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c);
  849. tx_ip = sx_read_channel_byte (port, hi_txipos);
  850. /* Took me 5 minutes to deduce this formula.
  851. Luckily it is literally in the manual in section 6.5.4.3.5 */
  852. txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff;
  853. /* Don't copy more bytes than there is room for in the buffer */
  854. if (c > txroom)
  855. c = txroom;
  856. sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom );
  857. /* Don't copy past the end of the hardware transmit buffer */
  858. if (c > 0x100 - tx_ip)
  859. c = 0x100 - tx_ip;
  860. sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip );
  861. /* Don't copy pas the end of the source buffer */
  862. if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
  863. c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
  864. sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%ld) \n",
  865. c, SERIAL_XMIT_SIZE- port->gs.xmit_tail);
  866. /* If for one reason or another, we can't copy more data, we're done! */
  867. if (c == 0) break;
  868. memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip,
  869. port->gs.xmit_buf + port->gs.xmit_tail, c);
  870. /* Update the pointer in the card */
  871. sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff);
  872. /* Update the kernel buffer end */
  873. port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
  874. /* This one last. (this is essential)
  875. It would allow others to start putting more data into the buffer! */
  876. port->gs.xmit_cnt -= c;
  877. }
  878. if (port->gs.xmit_cnt == 0) {
  879. sx_disable_tx_interrupts (port);
  880. }
  881. if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
  882. tty_wakeup(port->gs.tty);
  883. sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
  884. port->gs.wakeup_chars);
  885. }
  886. clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks);
  887. func_exit ();
  888. }
  889. /* Note the symmetry between receiving chars and transmitting them!
  890. Note: The kernel should have implemented both a receive buffer and
  891. a transmit buffer. */
  892. /* Inlined: Called only once. Remove the inline when you add another call */
  893. static inline void sx_receive_chars (struct sx_port *port)
  894. {
  895. int c;
  896. int rx_op;
  897. struct tty_struct *tty;
  898. int copied=0;
  899. func_enter2 ();
  900. tty = port->gs.tty;
  901. while (1) {
  902. rx_op = sx_read_channel_byte (port, hi_rxopos);
  903. c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff;
  904. sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
  905. /* Don't copy more bytes than there is room for in the buffer */
  906. if (tty->flip.count + c > TTY_FLIPBUF_SIZE)
  907. c = TTY_FLIPBUF_SIZE - tty->flip.count;
  908. sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
  909. /* Don't copy past the end of the hardware receive buffer */
  910. if (rx_op + c > 0x100) c = 0x100 - rx_op;
  911. sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c);
  912. /* If for one reason or another, we can't copy more data, we're done! */
  913. if (c == 0) break;
  914. sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c,
  915. read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op),
  916. CHAN_OFFSET(port, hi_rxbuf));
  917. memcpy_fromio (tty->flip.char_buf_ptr,
  918. port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c);
  919. memset(tty->flip.flag_buf_ptr, TTY_NORMAL, c);
  920. /* Update the kernel buffer end */
  921. tty->flip.count += c;
  922. tty->flip.char_buf_ptr += c;
  923. tty->flip.flag_buf_ptr += c;
  924. /* This one last. ( Not essential.)
  925. It allows the card to start putting more data into the buffer!
  926. Update the pointer in the card */
  927. sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff);
  928. copied += c;
  929. }
  930. if (copied) {
  931. struct timeval tv;
  932. do_gettimeofday (&tv);
  933. sx_dprintk (SX_DEBUG_RECEIVE,
  934. "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n",
  935. port->line, copied,
  936. (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw);
  937. /* Tell the rest of the system the news. Great news. New characters! */
  938. tty_flip_buffer_push (tty);
  939. /* tty_schedule_flip (tty); */
  940. }
  941. func_exit ();
  942. }
  943. /* Inlined: it is called only once. Remove the inline if you add another
  944. call */
  945. static inline void sx_check_modem_signals (struct sx_port *port)
  946. {
  947. int hi_state;
  948. int c_dcd;
  949. hi_state = sx_read_channel_byte (port, hi_state);
  950. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
  951. port->c_dcd, sx_get_CD (port));
  952. if (hi_state & ST_BREAK) {
  953. hi_state &= ~ST_BREAK;
  954. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n");
  955. sx_write_channel_byte (port, hi_state, hi_state);
  956. gs_got_break (&port->gs);
  957. }
  958. if (hi_state & ST_DCD) {
  959. hi_state &= ~ST_DCD;
  960. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
  961. sx_write_channel_byte (port, hi_state, hi_state);
  962. c_dcd = sx_get_CD (port);
  963. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
  964. if (c_dcd != port->c_dcd) {
  965. port->c_dcd = c_dcd;
  966. if (sx_get_CD (port)) {
  967. /* DCD went UP */
  968. if ((sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) &&
  969. !(port->gs.tty->termios->c_cflag & CLOCAL) ) {
  970. /* Are we blocking in open?*/
  971. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n");
  972. wake_up_interruptible(&port->gs.open_wait);
  973. } else {
  974. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n");
  975. }
  976. } else {
  977. /* DCD went down! */
  978. if (!(port->gs.tty->termios->c_cflag & CLOCAL) ) {
  979. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n");
  980. tty_hangup (port->gs.tty);
  981. } else {
  982. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n");
  983. }
  984. }
  985. } else {
  986. sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n");
  987. }
  988. }
  989. }
  990. /* This is what an interrupt routine should look like.
  991. * Small, elegant, clear.
  992. */
  993. static irqreturn_t sx_interrupt (int irq, void *ptr, struct pt_regs *regs)
  994. {
  995. struct sx_board *board = ptr;
  996. struct sx_port *port;
  997. int i;
  998. func_enter ();
  999. sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq);
  1000. /* AAargh! The order in which to do these things is essential and
  1001. not trivial.
  1002. - Rate limit goes before "recursive". Otherwise a series of
  1003. recursive calls will hang the machine in the interrupt routine.
  1004. - hardware twiddling goes before "recursive". Otherwise when we
  1005. poll the card, and a recursive interrupt happens, we won't
  1006. ack the card, so it might keep on interrupting us. (especially
  1007. level sensitive interrupt systems like PCI).
  1008. - Rate limit goes before hardware twiddling. Otherwise we won't
  1009. catch a card that has gone bonkers.
  1010. - The "initialized" test goes after the hardware twiddling. Otherwise
  1011. the card will stick us in the interrupt routine again.
  1012. - The initialized test goes before recursive.
  1013. */
  1014. #ifdef IRQ_RATE_LIMIT
  1015. /* Aaargh! I'm ashamed. This costs more lines-of-code than the
  1016. actual interrupt routine!. (Well, used to when I wrote that comment) */
  1017. {
  1018. static int lastjif;
  1019. static int nintr=0;
  1020. if (lastjif == jiffies) {
  1021. if (++nintr > IRQ_RATE_LIMIT) {
  1022. free_irq (board->irq, board);
  1023. printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n",
  1024. board->irq);
  1025. }
  1026. } else {
  1027. lastjif = jiffies;
  1028. nintr = 0;
  1029. }
  1030. }
  1031. #endif
  1032. if (board->irq == irq) {
  1033. /* Tell the card we've noticed the interrupt. */
  1034. sx_write_board_word (board, cc_int_pending, 0);
  1035. if (IS_SX_BOARD (board)) {
  1036. write_sx_byte (board, SX_RESET_IRQ, 1);
  1037. } else if (IS_EISA_BOARD(board)) {
  1038. inb(board->eisa_base+0xc03);
  1039. write_sx_word(board, 8, 0);
  1040. } else {
  1041. write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
  1042. write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
  1043. }
  1044. }
  1045. if (!sx_initialized)
  1046. return IRQ_HANDLED;
  1047. if (!(board->flags & SX_BOARD_INITIALIZED))
  1048. return IRQ_HANDLED;
  1049. if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) {
  1050. printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
  1051. return IRQ_HANDLED;
  1052. }
  1053. for (i=0;i<board->nports;i++) {
  1054. port = &board->ports[i];
  1055. if (port->gs.flags & GS_ACTIVE) {
  1056. if (sx_read_channel_byte (port, hi_state)) {
  1057. sx_dprintk (SX_DEBUG_INTERRUPTS,
  1058. "Port %d: modem signal change?... \n", i);
  1059. sx_check_modem_signals (port);
  1060. }
  1061. if (port->gs.xmit_cnt) {
  1062. sx_transmit_chars (port);
  1063. }
  1064. if (!(port->gs.flags & SX_RX_THROTTLE)) {
  1065. sx_receive_chars (port);
  1066. }
  1067. }
  1068. }
  1069. clear_bit (SX_BOARD_INTR_LOCK, &board->locks);
  1070. sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq);
  1071. func_exit ();
  1072. return IRQ_HANDLED;
  1073. }
  1074. static void sx_pollfunc (unsigned long data)
  1075. {
  1076. struct sx_board *board = (struct sx_board *) data;
  1077. func_enter ();
  1078. sx_interrupt (0, board, NULL);
  1079. init_timer(&board->timer);
  1080. board->timer.expires = jiffies + sx_poll;
  1081. add_timer (&board->timer);
  1082. func_exit ();
  1083. }
  1084. /* ********************************************************************** *
  1085. * Here are the routines that actually *
  1086. * interface with the generic_serial driver *
  1087. * ********************************************************************** */
  1088. /* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
  1089. /* Hmm. Ok I figured it out. You don't. */
  1090. static void sx_disable_tx_interrupts (void * ptr)
  1091. {
  1092. struct sx_port *port = ptr;
  1093. func_enter2();
  1094. port->gs.flags &= ~GS_TX_INTEN;
  1095. func_exit();
  1096. }
  1097. static void sx_enable_tx_interrupts (void * ptr)
  1098. {
  1099. struct sx_port *port = ptr;
  1100. int data_in_buffer;
  1101. func_enter2();
  1102. /* First transmit the characters that we're supposed to */
  1103. sx_transmit_chars (port);
  1104. /* The sx card will never interrupt us if we don't fill the buffer
  1105. past 25%. So we keep considering interrupts off if that's the case. */
  1106. data_in_buffer = (sx_read_channel_byte (port, hi_txipos) -
  1107. sx_read_channel_byte (port, hi_txopos)) & 0xff;
  1108. /* XXX Must be "HIGH_WATER" for SI card according to doc. */
  1109. if (data_in_buffer < LOW_WATER)
  1110. port->gs.flags &= ~GS_TX_INTEN;
  1111. func_exit();
  1112. }
  1113. static void sx_disable_rx_interrupts (void * ptr)
  1114. {
  1115. /* struct sx_port *port = ptr; */
  1116. func_enter();
  1117. func_exit();
  1118. }
  1119. static void sx_enable_rx_interrupts (void * ptr)
  1120. {
  1121. /* struct sx_port *port = ptr; */
  1122. func_enter();
  1123. func_exit();
  1124. }
  1125. /* Jeez. Isn't this simple? */
  1126. static int sx_get_CD (void * ptr)
  1127. {
  1128. struct sx_port *port = ptr;
  1129. func_enter2();
  1130. func_exit();
  1131. return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0);
  1132. }
  1133. /* Jeez. Isn't this simple? */
  1134. static int sx_chars_in_buffer (void * ptr)
  1135. {
  1136. struct sx_port *port = ptr;
  1137. func_enter2();
  1138. func_exit();
  1139. return ((sx_read_channel_byte (port, hi_txipos) -
  1140. sx_read_channel_byte (port, hi_txopos)) & 0xff);
  1141. }
  1142. static void sx_shutdown_port (void * ptr)
  1143. {
  1144. struct sx_port *port = ptr;
  1145. func_enter();
  1146. port->gs.flags &= ~ GS_ACTIVE;
  1147. if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) {
  1148. sx_setsignals (port, 0, 0);
  1149. sx_reconfigure_port(port);
  1150. }
  1151. func_exit();
  1152. }
  1153. /* ********************************************************************** *
  1154. * Here are the routines that actually *
  1155. * interface with the rest of the system *
  1156. * ********************************************************************** */
  1157. static int sx_open (struct tty_struct * tty, struct file * filp)
  1158. {
  1159. struct sx_port *port;
  1160. int retval, line;
  1161. unsigned long flags;
  1162. func_enter();
  1163. if (!sx_initialized) {
  1164. return -EIO;
  1165. }
  1166. line = tty->index;
  1167. sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n",
  1168. current->pid, line, tty, current->signal->tty, sx_nports);
  1169. if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
  1170. return -ENODEV;
  1171. port = & sx_ports[line];
  1172. port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
  1173. 1 -> 0 transition. */
  1174. sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
  1175. spin_lock_irqsave(&port->gs.driver_lock, flags);
  1176. tty->driver_data = port;
  1177. port->gs.tty = tty;
  1178. port->gs.count++;
  1179. spin_unlock_irqrestore(&port->gs.driver_lock, flags);
  1180. sx_dprintk (SX_DEBUG_OPEN, "starting port\n");
  1181. /*
  1182. * Start up serial port
  1183. */
  1184. retval = gs_init_port(&port->gs);
  1185. sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n");
  1186. if (retval) {
  1187. port->gs.count--;
  1188. return retval;
  1189. }
  1190. port->gs.flags |= GS_ACTIVE;
  1191. if (port->gs.count <= 1)
  1192. sx_setsignals (port, 1,1);
  1193. #if 0
  1194. if (sx_debug & SX_DEBUG_OPEN)
  1195. my_hd (port, sizeof (*port));
  1196. #else
  1197. if (sx_debug & SX_DEBUG_OPEN)
  1198. my_hd_io (port->board->base + port->ch_base, sizeof (*port));
  1199. #endif
  1200. if (port->gs.count <= 1) {
  1201. if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
  1202. printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n");
  1203. spin_lock_irqsave(&port->gs.driver_lock, flags);
  1204. port->gs.count--;
  1205. spin_unlock_irqrestore(&port->gs.driver_lock, flags);
  1206. return -EIO;
  1207. }
  1208. }
  1209. retval = gs_block_til_ready(port, filp);
  1210. sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
  1211. retval, port->gs.count);
  1212. if (retval) {
  1213. /*
  1214. * Don't lower gs.count here because sx_close() will be called later
  1215. */
  1216. return retval;
  1217. }
  1218. /* tty->low_latency = 1; */
  1219. port->c_dcd = sx_get_CD (port);
  1220. sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
  1221. func_exit();
  1222. return 0;
  1223. }
  1224. static void sx_close (void *ptr)
  1225. {
  1226. struct sx_port *port = ptr;
  1227. /* Give the port 5 seconds to close down. */
  1228. int to = 5 * HZ;
  1229. func_enter ();
  1230. sx_setsignals (port, 0, 0);
  1231. sx_reconfigure_port(port);
  1232. sx_send_command (port, HS_CLOSE, 0, 0);
  1233. while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED))
  1234. if (msleep_interruptible(10))
  1235. break;
  1236. if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) {
  1237. if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) {
  1238. printk (KERN_ERR
  1239. "sx: sent the force_close command, but card didn't react\n");
  1240. } else
  1241. sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n");
  1242. }
  1243. sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
  1244. 5 * HZ - to - 1, port->gs.count);
  1245. if(port->gs.count) {
  1246. sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", port->gs.count);
  1247. //printk ("%s SETTING port count to zero: %p count: %d\n", __FUNCTION__, port, port->gs.count);
  1248. //port->gs.count = 0;
  1249. }
  1250. func_exit ();
  1251. }
  1252. /* This is relatively thorough. But then again it is only 20 lines. */
  1253. #define MARCHUP for (i=min;i<max;i++)
  1254. #define MARCHDOWN for (i=max-1;i>=min;i--)
  1255. #define W0 write_sx_byte (board, i, 0x55)
  1256. #define W1 write_sx_byte (board, i, 0xaa)
  1257. #define R0 if (read_sx_byte (board, i) != 0x55) return 1
  1258. #define R1 if (read_sx_byte (board, i) != 0xaa) return 1
  1259. /* This memtest takes a human-noticable time. You normally only do it
  1260. once a boot, so I guess that it is worth it. */
  1261. static int do_memtest (struct sx_board *board, int min, int max)
  1262. {
  1263. int i;
  1264. /* This is a marchb. Theoretically, marchb catches much more than
  1265. simpler tests. In practise, the longer test just catches more
  1266. intermittent errors. -- REW
  1267. (For the theory behind memory testing see:
  1268. Testing Semiconductor Memories by A.J. van de Goor.) */
  1269. MARCHUP {W0;}
  1270. MARCHUP {R0;W1;R1;W0;R0;W1;}
  1271. MARCHUP {R1;W0;W1;}
  1272. MARCHDOWN {R1;W0;W1;W0;}
  1273. MARCHDOWN {R0;W1;W0;}
  1274. return 0;
  1275. }
  1276. #undef MARCHUP
  1277. #undef MARCHDOWN
  1278. #undef W0
  1279. #undef W1
  1280. #undef R0
  1281. #undef R1
  1282. #define MARCHUP for (i=min;i<max;i+=2)
  1283. #define MARCHDOWN for (i=max-1;i>=min;i-=2)
  1284. #define W0 write_sx_word (board, i, 0x55aa)
  1285. #define W1 write_sx_word (board, i, 0xaa55)
  1286. #define R0 if (read_sx_word (board, i) != 0x55aa) return 1
  1287. #define R1 if (read_sx_word (board, i) != 0xaa55) return 1
  1288. #if 0
  1289. /* This memtest takes a human-noticable time. You normally only do it
  1290. once a boot, so I guess that it is worth it. */
  1291. static int do_memtest_w (struct sx_board *board, int min, int max)
  1292. {
  1293. int i;
  1294. MARCHUP {W0;}
  1295. MARCHUP {R0;W1;R1;W0;R0;W1;}
  1296. MARCHUP {R1;W0;W1;}
  1297. MARCHDOWN {R1;W0;W1;W0;}
  1298. MARCHDOWN {R0;W1;W0;}
  1299. return 0;
  1300. }
  1301. #endif
  1302. static int sx_fw_ioctl (struct inode *inode, struct file *filp,
  1303. unsigned int cmd, unsigned long arg)
  1304. {
  1305. int rc = 0;
  1306. int __user *descr = (int __user *)arg;
  1307. int i;
  1308. static struct sx_board *board = NULL;
  1309. int nbytes, offset;
  1310. unsigned long data;
  1311. char *tmp;
  1312. func_enter();
  1313. #if 0
  1314. /* Removed superuser check: Sysops can use the permissions on the device
  1315. file to restrict access. Recommendation: Root only. (root.root 600) */
  1316. if (!capable(CAP_SYS_ADMIN)) {
  1317. return -EPERM;
  1318. }
  1319. #endif
  1320. sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
  1321. if (!board) board = &boards[0];
  1322. if (board->flags & SX_BOARD_PRESENT) {
  1323. sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
  1324. board->flags);
  1325. } else {
  1326. sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
  1327. board->flags);
  1328. for (i=0;i< SX_NBOARDS;i++)
  1329. sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
  1330. sx_dprintk (SX_DEBUG_FIRMWARE, "\n");
  1331. return -EIO;
  1332. }
  1333. switch (cmd) {
  1334. case SXIO_SET_BOARD:
  1335. sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
  1336. if (arg >= SX_NBOARDS) return -EIO;
  1337. sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n");
  1338. if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO;
  1339. sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n");
  1340. board = &boards[arg];
  1341. break;
  1342. case SXIO_GET_TYPE:
  1343. rc = -ENOENT; /* If we manage to miss one, return error. */
  1344. if (IS_SX_BOARD (board)) rc = SX_TYPE_SX;
  1345. if (IS_CF_BOARD (board)) rc = SX_TYPE_CF;
  1346. if (IS_SI_BOARD (board)) rc = SX_TYPE_SI;
  1347. if (IS_SI1_BOARD (board)) rc = SX_TYPE_SI;
  1348. if (IS_EISA_BOARD (board)) rc = SX_TYPE_SI;
  1349. sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
  1350. break;
  1351. case SXIO_DO_RAMTEST:
  1352. if (sx_initialized) /* Already initialized: better not ramtest the board. */
  1353. return -EPERM;
  1354. if (IS_SX_BOARD (board)) {
  1355. rc = do_memtest (board, 0, 0x7000);
  1356. if (!rc) rc = do_memtest (board, 0, 0x7000);
  1357. /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/
  1358. } else {
  1359. rc = do_memtest (board, 0, 0x7ff8);
  1360. /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
  1361. }
  1362. sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc);
  1363. break;
  1364. case SXIO_DOWNLOAD:
  1365. if (sx_initialized) /* Already initialized */
  1366. return -EEXIST;
  1367. if (!sx_reset (board))
  1368. return -EIO;
  1369. sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
  1370. tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER);
  1371. if (!tmp) return -ENOMEM;
  1372. get_user (nbytes, descr++);
  1373. get_user (offset, descr++);
  1374. get_user (data, descr++);
  1375. while (nbytes && data) {
  1376. for (i=0;i<nbytes;i += SX_CHUNK_SIZE) {
  1377. if (copy_from_user(tmp, (char __user *)data+i,
  1378. (i + SX_CHUNK_SIZE >
  1379. nbytes) ? nbytes - i :
  1380. SX_CHUNK_SIZE)) {
  1381. kfree (tmp);
  1382. return -EFAULT;
  1383. }
  1384. memcpy_toio(board->base2 + offset + i, tmp,
  1385. (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
  1386. }
  1387. get_user (nbytes, descr++);
  1388. get_user (offset, descr++);
  1389. get_user (data, descr++);
  1390. }
  1391. kfree (tmp);
  1392. sx_nports += sx_init_board (board);
  1393. rc = sx_nports;
  1394. break;
  1395. case SXIO_INIT:
  1396. if (sx_initialized) /* Already initialized */
  1397. return -EEXIST;
  1398. /* This is not allowed until all boards are initialized... */
  1399. for (i=0;i<SX_NBOARDS;i++) {
  1400. if ( (boards[i].flags & SX_BOARD_PRESENT) &&
  1401. !(boards[i].flags & SX_BOARD_INITIALIZED))
  1402. return -EIO;
  1403. }
  1404. for (i=0;i<SX_NBOARDS;i++)
  1405. if (!(boards[i].flags & SX_BOARD_PRESENT)) break;
  1406. sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
  1407. "%d channels, first board: %d ports\n",
  1408. i, sx_nports, boards[0].nports);
  1409. rc = sx_init_portstructs (i, sx_nports);
  1410. sx_init_drivers ();
  1411. if (rc >= 0)
  1412. sx_initialized++;
  1413. break;
  1414. case SXIO_SETDEBUG:
  1415. sx_debug = arg;
  1416. break;
  1417. case SXIO_GETDEBUG:
  1418. rc = sx_debug;
  1419. break;
  1420. case SXIO_GETGSDEBUG:
  1421. case SXIO_SETGSDEBUG:
  1422. rc = -EINVAL;
  1423. break;
  1424. case SXIO_GETNPORTS:
  1425. rc = sx_nports;
  1426. break;
  1427. default:
  1428. printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd);
  1429. break;
  1430. }
  1431. func_exit ();
  1432. return rc;
  1433. }
  1434. static void sx_break (struct tty_struct * tty, int flag)
  1435. {
  1436. struct sx_port *port = tty->driver_data;
  1437. int rv;
  1438. func_enter ();
  1439. if (flag)
  1440. rv = sx_send_command (port, HS_START, -1, HS_IDLE_BREAK);
  1441. else
  1442. rv = sx_send_command (port, HS_STOP, -1, HS_IDLE_OPEN);
  1443. if (rv != 1) printk (KERN_ERR "sx: couldn't send break (%x).\n",
  1444. read_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat)));
  1445. func_exit ();
  1446. }
  1447. static int sx_tiocmget(struct tty_struct *tty, struct file *file)
  1448. {
  1449. struct sx_port *port = tty->driver_data;
  1450. return sx_getsignals(port);
  1451. }
  1452. static int sx_tiocmset(struct tty_struct *tty, struct file *file,
  1453. unsigned int set, unsigned int clear)
  1454. {
  1455. struct sx_port *port = tty->driver_data;
  1456. int rts = -1, dtr = -1;
  1457. if (set & TIOCM_RTS)
  1458. rts = 1;
  1459. if (set & TIOCM_DTR)
  1460. dtr = 1;
  1461. if (clear & TIOCM_RTS)
  1462. rts = 0;
  1463. if (clear & TIOCM_DTR)
  1464. dtr = 0;
  1465. sx_setsignals(port, dtr, rts);
  1466. sx_reconfigure_port(port);
  1467. return 0;
  1468. }
  1469. static int sx_ioctl (struct tty_struct * tty, struct file * filp,
  1470. unsigned int cmd, unsigned long arg)
  1471. {
  1472. int rc;
  1473. struct sx_port *port = tty->driver_data;
  1474. void __user *argp = (void __user *)arg;
  1475. int ival;
  1476. /* func_enter2(); */
  1477. rc = 0;
  1478. switch (cmd) {
  1479. case TIOCGSOFTCAR:
  1480. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1481. (unsigned __user *) argp);
  1482. break;
  1483. case TIOCSSOFTCAR:
  1484. if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
  1485. tty->termios->c_cflag =
  1486. (tty->termios->c_cflag & ~CLOCAL) |
  1487. (ival ? CLOCAL : 0);
  1488. }
  1489. break;
  1490. case TIOCGSERIAL:
  1491. rc = gs_getserial(&port->gs, argp);
  1492. break;
  1493. case TIOCSSERIAL:
  1494. rc = gs_setserial(&port->gs, argp);
  1495. break;
  1496. default:
  1497. rc = -ENOIOCTLCMD;
  1498. break;
  1499. }
  1500. /* func_exit(); */
  1501. return rc;
  1502. }
  1503. /* The throttle/unthrottle scheme for the Specialix card is different
  1504. * from other drivers and deserves some explanation.
  1505. * The Specialix hardware takes care of XON/XOFF
  1506. * and CTS/RTS flow control itself. This means that all we have to
  1507. * do when signalled by the upper tty layer to throttle/unthrottle is
  1508. * to make a note of it here. When we come to read characters from the
  1509. * rx buffers on the card (sx_receive_chars()) we look to see if the
  1510. * upper layer can accept more (as noted here in sx_rx_throt[]).
  1511. * If it can't we simply don't remove chars from the cards buffer.
  1512. * When the tty layer can accept chars, we again note that here and when
  1513. * sx_receive_chars() is called it will remove them from the cards buffer.
  1514. * The card will notice that a ports buffer has drained below some low
  1515. * water mark and will unflow control the line itself, using whatever
  1516. * flow control scheme is in use for that port. -- Simon Allen
  1517. */
  1518. static void sx_throttle (struct tty_struct * tty)
  1519. {
  1520. struct sx_port *port = (struct sx_port *)tty->driver_data;
  1521. func_enter2();
  1522. /* If the port is using any type of input flow
  1523. * control then throttle the port.
  1524. */
  1525. if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) {
  1526. port->gs.flags |= SX_RX_THROTTLE;
  1527. }
  1528. func_exit();
  1529. }
  1530. static void sx_unthrottle (struct tty_struct * tty)
  1531. {
  1532. struct sx_port *port = (struct sx_port *)tty->driver_data;
  1533. func_enter2();
  1534. /* Always unthrottle even if flow control is not enabled on
  1535. * this port in case we disabled flow control while the port
  1536. * was throttled
  1537. */
  1538. port->gs.flags &= ~SX_RX_THROTTLE;
  1539. func_exit();
  1540. return;
  1541. }
  1542. /* ********************************************************************** *
  1543. * Here are the initialization routines. *
  1544. * ********************************************************************** */
  1545. static int sx_init_board (struct sx_board *board)
  1546. {
  1547. int addr;
  1548. int chans;
  1549. int type;
  1550. func_enter();
  1551. /* This is preceded by downloading the download code. */
  1552. board->flags |= SX_BOARD_INITIALIZED;
  1553. if (read_sx_byte (board, 0))
  1554. /* CF boards may need this. */
  1555. write_sx_byte(board,0, 0);
  1556. /* This resets the processor again, to make sure it didn't do any
  1557. foolish things while we were downloading the image */
  1558. if (!sx_reset (board))
  1559. return 0;
  1560. sx_start_board (board);
  1561. udelay (10);
  1562. if (!sx_busy_wait_neq (board, 0, 0xff, 0)) {
  1563. printk (KERN_ERR "sx: Ooops. Board won't initialize.\n");
  1564. return 0;
  1565. }
  1566. /* Ok. So now the processor on the card is running. It gathered
  1567. some info for us... */
  1568. sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n");
  1569. if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base, 0x10);
  1570. sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n");
  1571. if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base + 0x80, 0x30);
  1572. sx_dprintk (SX_DEBUG_INIT,
  1573. "init_status: %x, %dk memory, firmware V%x.%02x,\n",
  1574. read_sx_byte (board, 0), read_sx_byte(board, 1),
  1575. read_sx_byte (board, 5), read_sx_byte(board, 4));
  1576. if (read_sx_byte (board, 0) == 0xff) {
  1577. printk (KERN_INFO "sx: No modules found. Sorry.\n");
  1578. board->nports = 0;
  1579. return 0;
  1580. }
  1581. chans = 0;
  1582. if (IS_SX_BOARD(board)) {
  1583. sx_write_board_word (board, cc_int_count, sx_maxints);
  1584. } else {
  1585. if (sx_maxints)
  1586. sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints);
  1587. }
  1588. /* grab the first module type... */
  1589. /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
  1590. board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip));
  1591. /* XXX byteorder */
  1592. for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
  1593. type = sx_read_module_byte (board, addr, mc_chip);
  1594. sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n",
  1595. addr, read_sx_byte (board, addr + 2));
  1596. chans += sx_read_module_byte (board, addr, mc_type);
  1597. sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n",
  1598. mod_type_s (type),
  1599. pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf),
  1600. pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4));
  1601. sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n",
  1602. sx_read_module_byte (board, addr, mc_rev1),
  1603. sx_read_module_byte (board, addr, mc_rev2),
  1604. sx_read_module_byte (board, addr, mc_mtaasic_rev));
  1605. /* The following combinations are illegal: It should theoretically
  1606. work, but timing problems make the bus HANG. */
  1607. if (mod_compat_type (type) != board->ta_type) {
  1608. printk (KERN_ERR "sx: This is an invalid configuration.\n"
  1609. "Don't mix TA/MTA/SXDC on the same hostadapter.\n");
  1610. chans=0;
  1611. break;
  1612. }
  1613. if ((IS_EISA_BOARD(board) ||
  1614. IS_SI_BOARD(board)) && (mod_compat_type(type) == 4)) {
  1615. printk (KERN_ERR "sx: This is an invalid configuration.\n"
  1616. "Don't use SXDCs on an SI/XIO adapter.\n");
  1617. chans=0;
  1618. break;
  1619. }
  1620. #if 0 /* Problem fixed: firmware 3.05 */
  1621. if (IS_SX_BOARD(board) && (type == TA8)) {
  1622. /* There are some issues with the firmware and the DCD/RTS
  1623. lines. It might work if you tie them together or something.
  1624. It might also work if you get a newer sx_firmware. Therefore
  1625. this is just a warning. */
  1626. printk (KERN_WARNING "sx: The SX host doesn't work too well "
  1627. "with the TA8 adapters.\nSpecialix is working on it.\n");
  1628. }
  1629. #endif
  1630. }
  1631. if (chans) {
  1632. /* board->flags |= SX_BOARD_PRESENT; */
  1633. if(board->irq > 0) {
  1634. /* fixed irq, probably PCI */
  1635. if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
  1636. if(request_irq(board->irq, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board)) {
  1637. printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq);
  1638. board->irq = 0;
  1639. }
  1640. } else
  1641. board->irq = 0;
  1642. } else if(board->irq < 0 && sx_irqmask) {
  1643. /* auto-allocate irq */
  1644. int irqnr;
  1645. int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
  1646. for(irqnr = 15; irqnr > 0; irqnr--)
  1647. if(irqmask & (1 << irqnr))
  1648. if(! request_irq(irqnr, sx_interrupt, SA_SHIRQ | SA_INTERRUPT, "sx", board))
  1649. break;
  1650. if(! irqnr)
  1651. printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
  1652. board->irq = irqnr;
  1653. } else
  1654. board->irq = 0;
  1655. if (board->irq) {
  1656. /* Found a valid interrupt, start up interrupts! */
  1657. sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq);
  1658. sx_start_interrupts (board);
  1659. board->poll = sx_slowpoll;
  1660. board->flags |= SX_IRQ_ALLOCATED;
  1661. } else {
  1662. /* no irq: setup board for polled operation */
  1663. board->poll = sx_poll;
  1664. sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll);
  1665. }
  1666. /* The timer should be initialized anyway: That way we can safely
  1667. del_timer it when the module is unloaded. */
  1668. init_timer (&board->timer);
  1669. if (board->poll) {
  1670. board->timer.data = (unsigned long) board;
  1671. board->timer.function = sx_pollfunc;
  1672. board->timer.expires = jiffies + board->poll;
  1673. add_timer (&board->timer);
  1674. }
  1675. } else {
  1676. board->irq = 0;
  1677. }
  1678. board->nports = chans;
  1679. sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports);
  1680. func_exit();
  1681. return chans;
  1682. }
  1683. static void printheader(void)
  1684. {
  1685. static int header_printed;
  1686. if (!header_printed) {
  1687. printk (KERN_INFO "Specialix SX driver "
  1688. "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n");
  1689. printk (KERN_INFO "sx: version %s\n", RCS_ID);
  1690. header_printed = 1;
  1691. }
  1692. }
  1693. static int probe_sx (struct sx_board *board)
  1694. {
  1695. struct vpd_prom vpdp;
  1696. char *p;
  1697. int i;
  1698. func_enter();
  1699. if (!IS_CF_BOARD (board)) {
  1700. sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
  1701. board->base + SX_VPD_ROM);
  1702. if (sx_debug & SX_DEBUG_PROBE)
  1703. my_hd_io(board->base + SX_VPD_ROM, 0x40);
  1704. p = (char *) &vpdp;
  1705. for (i=0;i< sizeof (struct vpd_prom);i++)
  1706. *p++ = read_sx_byte (board, SX_VPD_ROM + i*2);
  1707. if (sx_debug & SX_DEBUG_PROBE)
  1708. my_hd (&vpdp, 0x20);
  1709. sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n");
  1710. if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
  1711. sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n",
  1712. vpdp.identifier);
  1713. return 0;
  1714. }
  1715. }
  1716. printheader ();
  1717. if (!IS_CF_BOARD (board)) {
  1718. printk (KERN_DEBUG "sx: Found an SX board at %lx\n", board->hw_base);
  1719. printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
  1720. vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
  1721. printk ( "Manufactured: %d/%d\n",
  1722. 1970 + vpdp.myear, vpdp.mweek);
  1723. if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) &&
  1724. (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
  1725. /* This might be a bit harsh. This was the primary reason the
  1726. SX/ISA card didn't work at first... */
  1727. printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n");
  1728. return (0);
  1729. }
  1730. if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) {
  1731. if (((unsigned long)board->hw_base) & 0x8000) {
  1732. printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %lx.\n", board->hw_base);
  1733. printk (KERN_WARNING "sx: Read sx.txt for more info.\n");
  1734. }
  1735. }
  1736. }
  1737. board->nports = -1;
  1738. /* This resets the processor, and keeps it off the bus. */
  1739. if (!sx_reset (board))
  1740. return 0;
  1741. sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
  1742. board->flags |= SX_BOARD_PRESENT;
  1743. func_exit();
  1744. return 1;
  1745. }
  1746. /* Specialix probes for this card at 32k increments from 640k to 16M.
  1747. I consider machines with less than 16M unlikely nowadays, so I'm
  1748. not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
  1749. card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
  1750. 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
  1751. static int probe_si (struct sx_board *board)
  1752. {
  1753. int i;
  1754. func_enter();
  1755. sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at %p.\n", board->hw_base,
  1756. board->base + SI2_ISA_ID_BASE);
  1757. if (sx_debug & SX_DEBUG_PROBE)
  1758. my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8);
  1759. if (!IS_EISA_BOARD(board)) {
  1760. if( IS_SI1_BOARD(board) )
  1761. {
  1762. for (i=0;i<8;i++) {
  1763. write_sx_byte (board, SI2_ISA_ID_BASE+7-i,i);
  1764. }
  1765. }
  1766. for (i=0;i<8;i++) {
  1767. if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) {
  1768. func_exit ();
  1769. return 0;
  1770. }
  1771. }
  1772. }
  1773. /* Now we're pretty much convinced that there is an SI board here,
  1774. but to prevent trouble, we'd better double check that we don't
  1775. have an SI1 board when we're probing for an SI2 board.... */
  1776. write_sx_byte (board, SI2_ISA_ID_BASE,0x10);
  1777. if ( IS_SI1_BOARD(board)) {
  1778. /* This should be an SI1 board, which has this
  1779. location writable... */
  1780. if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10)
  1781. func_exit ();
  1782. return 0;
  1783. } else {
  1784. /* This should be an SI2 board, which has the bottom
  1785. 3 bits non-writable... */
  1786. if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10)
  1787. func_exit ();
  1788. return 0;
  1789. }
  1790. /* Now we're pretty much convinced that there is an SI board here,
  1791. but to prevent trouble, we'd better double check that we don't
  1792. have an SI1 board when we're probing for an SI2 board.... */
  1793. write_sx_byte (board, SI2_ISA_ID_BASE,0x10);
  1794. if ( IS_SI1_BOARD(board)) {
  1795. /* This should be an SI1 board, which has this
  1796. location writable... */
  1797. if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10)
  1798. func_exit();
  1799. return 0;
  1800. } else {
  1801. /* This should be an SI2 board, which has the bottom
  1802. 3 bits non-writable... */
  1803. if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10)
  1804. func_exit ();
  1805. return 0;
  1806. }
  1807. printheader ();
  1808. printk (KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
  1809. /* Compared to the SX boards, it is a complete guess as to what
  1810. this card is up to... */
  1811. board->nports = -1;
  1812. /* This resets the processor, and keeps it off the bus. */
  1813. if (!sx_reset (board))
  1814. return 0;
  1815. sx_dprintk (SX_DEBUG_INIT, "reset the board...\n");
  1816. board->flags |= SX_BOARD_PRESENT;
  1817. func_exit();
  1818. return 1;
  1819. }
  1820. static struct tty_operations sx_ops = {
  1821. .break_ctl = sx_break,
  1822. .open = sx_open,
  1823. .close = gs_close,
  1824. .write = gs_write,
  1825. .put_char = gs_put_char,
  1826. .flush_chars = gs_flush_chars,
  1827. .write_room = gs_write_room,
  1828. .chars_in_buffer = gs_chars_in_buffer,
  1829. .flush_buffer = gs_flush_buffer,
  1830. .ioctl = sx_ioctl,
  1831. .throttle = sx_throttle,
  1832. .unthrottle = sx_unthrottle,
  1833. .set_termios = gs_set_termios,
  1834. .stop = gs_stop,
  1835. .start = gs_start,
  1836. .hangup = gs_hangup,
  1837. .tiocmget = sx_tiocmget,
  1838. .tiocmset = sx_tiocmset,
  1839. };
  1840. static int sx_init_drivers(void)
  1841. {
  1842. int error;
  1843. func_enter();
  1844. sx_driver = alloc_tty_driver(sx_nports);
  1845. if (!sx_driver)
  1846. return 1;
  1847. sx_driver->owner = THIS_MODULE;
  1848. sx_driver->driver_name = "specialix_sx";
  1849. sx_driver->name = "ttyX";
  1850. sx_driver->major = SX_NORMAL_MAJOR;
  1851. sx_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1852. sx_driver->subtype = SERIAL_TYPE_NORMAL;
  1853. sx_driver->init_termios = tty_std_termios;
  1854. sx_driver->init_termios.c_cflag =
  1855. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  1856. sx_driver->flags = TTY_DRIVER_REAL_RAW;
  1857. tty_set_operations(sx_driver, &sx_ops);
  1858. if ((error = tty_register_driver(sx_driver))) {
  1859. put_tty_driver(sx_driver);
  1860. printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
  1861. error);
  1862. return 1;
  1863. }
  1864. func_exit();
  1865. return 0;
  1866. }
  1867. static void * ckmalloc (int size)
  1868. {
  1869. void *p;
  1870. p = kmalloc(size, GFP_KERNEL);
  1871. if (p)
  1872. memset(p, 0, size);
  1873. return p;
  1874. }
  1875. static int sx_init_portstructs (int nboards, int nports)
  1876. {
  1877. struct sx_board *board;
  1878. struct sx_port *port;
  1879. int i, j;
  1880. int addr, chans;
  1881. int portno;
  1882. func_enter();
  1883. /* Many drivers statically allocate the maximum number of ports
  1884. There is no reason not to allocate them dynamically. Is there? -- REW */
  1885. sx_ports = ckmalloc(nports * sizeof (struct sx_port));
  1886. if (!sx_ports)
  1887. return -ENOMEM;
  1888. port = sx_ports;
  1889. for (i = 0; i < nboards; i++) {
  1890. board = &boards[i];
  1891. board->ports = port;
  1892. for (j=0; j < boards[i].nports;j++) {
  1893. sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j);
  1894. port->gs.magic = SX_MAGIC;
  1895. port->gs.close_delay = HZ/2;
  1896. port->gs.closing_wait = 30 * HZ;
  1897. port->board = board;
  1898. port->gs.rd = &sx_real_driver;
  1899. #ifdef NEW_WRITE_LOCKING
  1900. port->gs.port_write_sem = MUTEX;
  1901. #endif
  1902. port->gs.driver_lock = SPIN_LOCK_UNLOCKED;
  1903. /*
  1904. * Initializing wait queue
  1905. */
  1906. init_waitqueue_head(&port->gs.open_wait);
  1907. init_waitqueue_head(&port->gs.close_wait);
  1908. port++;
  1909. }
  1910. }
  1911. port = sx_ports;
  1912. portno = 0;
  1913. for (i = 0; i < nboards; i++) {
  1914. board = &boards[i];
  1915. board->port_base = portno;
  1916. /* Possibly the configuration was rejected. */
  1917. sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports);
  1918. if (board->nports <= 0) continue;
  1919. /* XXX byteorder ?? */
  1920. for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) {
  1921. chans = sx_read_module_byte (board, addr, mc_type);
  1922. sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans);
  1923. sx_dprintk (SX_DEBUG_PROBE, "Port at");
  1924. for (j=0;j<chans;j++) {
  1925. /* The "sx-way" is the way it SHOULD be done. That way in the
  1926. future, the firmware may for example pack the structures a bit
  1927. more efficient. Neil tells me it isn't going to happen anytime
  1928. soon though. */
  1929. if (IS_SX_BOARD(board))
  1930. port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer);
  1931. else
  1932. port->ch_base = addr + 0x100 + 0x300*j;
  1933. sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base);
  1934. port->line = portno++;
  1935. port++;
  1936. }
  1937. sx_dprintk (SX_DEBUG_PROBE, "\n");
  1938. }
  1939. /* This has to be done earlier. */
  1940. /* board->flags |= SX_BOARD_INITIALIZED; */
  1941. }
  1942. func_exit();
  1943. return 0;
  1944. }
  1945. static void __exit sx_release_drivers(void)
  1946. {
  1947. func_enter();
  1948. tty_unregister_driver(sx_driver);
  1949. put_tty_driver(sx_driver);
  1950. func_exit();
  1951. }
  1952. #ifdef CONFIG_PCI
  1953. /********************************************************
  1954. * Setting bit 17 in the CNTRL register of the PLX 9050 *
  1955. * chip forces a retry on writes while a read is pending.*
  1956. * This is to prevent the card locking up on Intel Xeon *
  1957. * multiprocessor systems with the NX chipset. -- NV *
  1958. ********************************************************/
  1959. /* Newer cards are produced with this bit set from the configuration
  1960. EEprom. As the bit is read/write for the CPU, we can fix it here,
  1961. if we detect that it isn't set correctly. -- REW */
  1962. static void fix_sx_pci (struct pci_dev *pdev, struct sx_board *board)
  1963. {
  1964. unsigned int hwbase;
  1965. void __iomem *rebase;
  1966. unsigned int t;
  1967. #define CNTRL_REG_OFFSET 0x50
  1968. #define CNTRL_REG_GOODVALUE 0x18260000
  1969. pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
  1970. hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
  1971. rebase = ioremap(hwbase, 0x80);
  1972. t = readl (rebase + CNTRL_REG_OFFSET);
  1973. if (t != CNTRL_REG_GOODVALUE) {
  1974. printk (KERN_DEBUG "sx: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
  1975. writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
  1976. }
  1977. iounmap(rebase);
  1978. }
  1979. #endif
  1980. static int __init sx_init(void)
  1981. {
  1982. int i;
  1983. int found = 0;
  1984. int eisa_slot;
  1985. struct sx_board *board;
  1986. #ifdef CONFIG_PCI
  1987. struct pci_dev *pdev = NULL;
  1988. unsigned int tint;
  1989. unsigned short tshort;
  1990. #endif
  1991. func_enter();
  1992. sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug);
  1993. if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) {
  1994. printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. "
  1995. "Assuming -1.\n");
  1996. printk ("(%p)\n", &sx_debug);
  1997. sx_debug=-1;
  1998. }
  1999. if (misc_register(&sx_fw_device) < 0) {
  2000. printk(KERN_ERR "SX: Unable to register firmware loader driver.\n");
  2001. return -EIO;
  2002. }
  2003. #ifdef CONFIG_PCI
  2004. while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
  2005. PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
  2006. pdev))) {
  2007. if (pci_enable_device(pdev))
  2008. continue;
  2009. /* Specialix has a whole bunch of cards with
  2010. 0x2000 as the device ID. They say its because
  2011. the standard requires it. Stupid standard. */
  2012. /* It seems that reading a word doesn't work reliably on 2.0.
  2013. Also, reading a non-aligned dword doesn't work. So we read the
  2014. whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
  2015. ourselves */
  2016. /* I don't know why the define doesn't work, constant 0x2c does --REW */
  2017. pci_read_config_dword (pdev, 0x2c, &tint);
  2018. tshort = (tint >> 16) & 0xffff;
  2019. sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
  2020. /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
  2021. if ((tshort != 0x0200) && (tshort != 0x0300)) {
  2022. sx_dprintk (SX_DEBUG_PROBE, "But it's not an SX card (%d)...\n",
  2023. tshort);
  2024. continue;
  2025. }
  2026. board = &boards[found];
  2027. board->flags &= ~SX_BOARD_TYPE;
  2028. board->flags |= (tshort == 0x200)?SX_PCI_BOARD:
  2029. SX_CFPCI_BOARD;
  2030. /* CF boards use base address 3.... */
  2031. if (IS_CF_BOARD (board))
  2032. board->hw_base = pci_resource_start (pdev, 3);
  2033. else
  2034. board->hw_base = pci_resource_start (pdev, 2);
  2035. board->base2 =
  2036. board->base = ioremap(board->hw_base, WINDOW_LEN (board));
  2037. if (!board->base) {
  2038. printk(KERN_ERR "ioremap failed\n");
  2039. /* XXX handle error */
  2040. }
  2041. /* Most of the stuff on the CF board is offset by
  2042. 0x18000 .... */
  2043. if (IS_CF_BOARD (board)) board->base += 0x18000;
  2044. board->irq = pdev->irq;
  2045. sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x/%p(%d) %x.\n",
  2046. tint, boards[found].base, board->irq, board->flags);
  2047. if (probe_sx (board)) {
  2048. found++;
  2049. fix_sx_pci (pdev, board);
  2050. } else
  2051. iounmap(board->base2);
  2052. }
  2053. #endif
  2054. for (i=0;i<NR_SX_ADDRS;i++) {
  2055. board = &boards[found];
  2056. board->hw_base = sx_probe_addrs[i];
  2057. board->base2 =
  2058. board->base = ioremap(board->hw_base, SX_WINDOW_LEN);
  2059. board->flags &= ~SX_BOARD_TYPE;
  2060. board->flags |= SX_ISA_BOARD;
  2061. board->irq = sx_irqmask?-1:0;
  2062. if (probe_sx (board)) {
  2063. found++;
  2064. } else {
  2065. iounmap(board->base);
  2066. }
  2067. }
  2068. for (i=0;i<NR_SI_ADDRS;i++) {
  2069. board = &boards[found];
  2070. board->hw_base = si_probe_addrs[i];
  2071. board->base2 =
  2072. board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
  2073. board->flags &= ~SX_BOARD_TYPE;
  2074. board->flags |= SI_ISA_BOARD;
  2075. board->irq = sx_irqmask ?-1:0;
  2076. if (probe_si (board)) {
  2077. found++;
  2078. } else {
  2079. iounmap (board->base);
  2080. }
  2081. }
  2082. for (i=0;i<NR_SI1_ADDRS;i++) {
  2083. board = &boards[found];
  2084. board->hw_base = si1_probe_addrs[i];
  2085. board->base2 =
  2086. board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN);
  2087. board->flags &= ~SX_BOARD_TYPE;
  2088. board->flags |= SI1_ISA_BOARD;
  2089. board->irq = sx_irqmask ?-1:0;
  2090. if (probe_si (board)) {
  2091. found++;
  2092. } else {
  2093. iounmap (board->base);
  2094. }
  2095. }
  2096. sx_dprintk(SX_DEBUG_PROBE, "Probing for EISA cards\n");
  2097. for(eisa_slot=0x1000; eisa_slot<0x10000; eisa_slot+=0x1000)
  2098. {
  2099. if((inb(eisa_slot+0xc80)==0x4d) &&
  2100. (inb(eisa_slot+0xc81)==0x98))
  2101. {
  2102. sx_dprintk(SX_DEBUG_PROBE, "%s : Signature found in EISA slot %d, Product %d Rev %d\n",
  2103. "XIO", (eisa_slot>>12), inb(eisa_slot+0xc82), inb(eisa_slot+0xc83));
  2104. board = &boards[found];
  2105. board->eisa_base = eisa_slot;
  2106. board->flags &= ~SX_BOARD_TYPE;
  2107. board->flags |= SI_EISA_BOARD;
  2108. board->hw_base = (((inb(0xc01+eisa_slot) << 8) + inb(0xc00+eisa_slot)) << 16);
  2109. board->base2 =
  2110. board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
  2111. sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
  2112. sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
  2113. board->irq = inb(board->eisa_base+0xc02)>>4;
  2114. sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
  2115. probe_si(board);
  2116. found++;
  2117. }
  2118. }
  2119. if (found) {
  2120. printk (KERN_INFO "sx: total of %d boards detected.\n", found);
  2121. } else {
  2122. misc_deregister(&sx_fw_device);
  2123. }
  2124. func_exit();
  2125. return found?0:-EIO;
  2126. }
  2127. static void __exit sx_exit (void)
  2128. {
  2129. int i;
  2130. struct sx_board *board;
  2131. func_enter();
  2132. for (i = 0; i < SX_NBOARDS; i++) {
  2133. board = &boards[i];
  2134. if (board->flags & SX_BOARD_INITIALIZED) {
  2135. sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %p\n", board->base);
  2136. /* The board should stop messing with us.
  2137. (actually I mean the interrupt) */
  2138. sx_reset (board);
  2139. if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
  2140. free_irq (board->irq, board);
  2141. /* It is safe/allowed to del_timer a non-active timer */
  2142. del_timer (& board->timer);
  2143. iounmap(board->base);
  2144. }
  2145. }
  2146. if (misc_deregister(&sx_fw_device) < 0) {
  2147. printk (KERN_INFO "sx: couldn't deregister firmware loader devic\n");
  2148. }
  2149. sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized);
  2150. if (sx_initialized)
  2151. sx_release_drivers ();
  2152. kfree (sx_ports);
  2153. func_exit();
  2154. }
  2155. module_init(sx_init);
  2156. module_exit(sx_exit);