synclinkmp.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:147k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * $Id: synclinkmp.c,v 3.17 2002/04/22 16:05:39 paulkf Exp $
  3.  *
  4.  * Device driver for Microgate SyncLink Multiport
  5.  * high speed multiprotocol serial adapter.
  6.  *
  7.  * written by Paul Fulghum for Microgate Corporation
  8.  * paulkf@microgate.com
  9.  *
  10.  * Microgate and SyncLink are trademarks of Microgate Corporation
  11.  *
  12.  * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
  13.  * This code is released under the GNU General Public License (GPL)
  14.  *
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18.  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19.  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  */
  27. #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
  28. #if defined(__i386__)
  29. #  define BREAKPOINT() asm("   int $3");
  30. #else
  31. #  define BREAKPOINT() { }
  32. #endif
  33. #define MAX_DEVICES 12
  34. #include <linux/config.h>
  35. #include <linux/module.h>
  36. #include <linux/version.h>
  37. #include <linux/errno.h>
  38. #include <linux/signal.h>
  39. #include <linux/sched.h>
  40. #include <linux/timer.h>
  41. #include <linux/interrupt.h>
  42. #include <linux/pci.h>
  43. #include <linux/tty.h>
  44. #include <linux/tty_flip.h>
  45. #include <linux/serial.h>
  46. #include <linux/major.h>
  47. #include <linux/string.h>
  48. #include <linux/fcntl.h>
  49. #include <linux/ptrace.h>
  50. #include <linux/ioport.h>
  51. #include <linux/mm.h>
  52. #include <linux/slab.h>
  53. #include <linux/netdevice.h>
  54. #include <linux/vmalloc.h>
  55. #include <linux/init.h>
  56. #include <asm/serial.h>
  57. #include <linux/delay.h>
  58. #include <linux/ioctl.h>
  59. #include <asm/system.h>
  60. #include <asm/io.h>
  61. #include <asm/irq.h>
  62. #include <asm/dma.h>
  63. #include <asm/bitops.h>
  64. #include <asm/types.h>
  65. #include <linux/termios.h>
  66. #include <linux/tqueue.h>
  67. #ifdef CONFIG_SYNCLINK_SYNCPPP_MODULE
  68. #define CONFIG_SYNCLINK_SYNCPPP 1
  69. #endif
  70. #ifdef CONFIG_SYNCLINK_SYNCPPP
  71. #include <net/syncppp.h>
  72. #endif
  73. #include <asm/segment.h>
  74. #define GET_USER(error,value,addr) error = get_user(value,addr)
  75. #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
  76. #define PUT_USER(error,value,addr) error = put_user(value,addr)
  77. #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
  78. #include <asm/uaccess.h>
  79. #include "linux/synclink.h"
  80. static MGSL_PARAMS default_params = {
  81. MGSL_MODE_HDLC, /* unsigned long mode */
  82. 0, /* unsigned char loopback; */
  83. HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
  84. HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
  85. 0, /* unsigned long clock_speed; */
  86. 0xff, /* unsigned char addr_filter; */
  87. HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
  88. HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
  89. HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
  90. 9600, /* unsigned long data_rate; */
  91. 8, /* unsigned char data_bits; */
  92. 1, /* unsigned char stop_bits; */
  93. ASYNC_PARITY_NONE /* unsigned char parity; */
  94. };
  95. /* size in bytes of DMA data buffers */
  96. #define SCABUFSIZE  1024
  97. #define SCA_MEM_SIZE 0x40000
  98. #define SCA_BASE_SIZE   512
  99. #define SCA_REG_SIZE    16
  100. #define SCA_MAX_PORTS   4
  101. #define SCAMAXDESC  128
  102. #define BUFFERLISTSIZE 4096
  103. /* SCA-I style DMA buffer descriptor */
  104. typedef struct _SCADESC
  105. {
  106. u16 next; /* lower l6 bits of next descriptor addr */
  107. u16 buf_ptr; /* lower 16 bits of buffer addr */
  108. u8 buf_base; /* upper 8 bits of buffer addr */
  109. u8 pad1;
  110. u16 length; /* length of buffer */
  111. u8 status; /* status of buffer */
  112. u8 pad2;
  113. } SCADESC, *PSCADESC;
  114. typedef struct _SCADESC_EX
  115. {
  116. /* device driver bookkeeping section */
  117. char  *virt_addr;     /* virtual address of data buffer */
  118. u16 phys_entry; /* lower 16-bits of physical address of this descriptor */
  119. } SCADESC_EX, *PSCADESC_EX;
  120. /* The queue of BH actions to be performed */
  121. #define BH_RECEIVE  1
  122. #define BH_TRANSMIT 2
  123. #define BH_STATUS   4
  124. #define IO_PIN_SHUTDOWN_LIMIT 100
  125. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  126. struct _input_signal_events {
  127. int ri_up;
  128. int ri_down;
  129. int dsr_up;
  130. int dsr_down;
  131. int dcd_up;
  132. int dcd_down;
  133. int cts_up;
  134. int cts_down;
  135. };
  136. /*
  137.  * Device instance data structure
  138.  */
  139. typedef struct _synclinkmp_info {
  140. void *if_ptr; /* General purpose pointer (used by SPPP) */
  141. int magic;
  142. int flags;
  143. int count; /* count of opens */
  144. int line;
  145. unsigned short close_delay;
  146. unsigned short closing_wait; /* time to wait before closing */
  147. struct mgsl_icount icount;
  148. struct termios normal_termios;
  149. struct termios callout_termios;
  150. struct tty_struct  *tty;
  151. int timeout;
  152. int x_char; /* xon/xoff character */
  153. int blocked_open; /* # of blocked opens */
  154. long session; /* Session of opening process */
  155. long pgrp; /* pgrp of opening process */
  156. u16 read_status_mask1;  /* break detection (SR1 indications) */
  157. u16 read_status_mask2;  /* parity/framing/overun (SR2 indications) */
  158. unsigned char  ignore_status_mask1;  /* break detection (SR1 indications) */
  159. unsigned char ignore_status_mask2;  /* parity/framing/overun (SR2 indications) */
  160. unsigned char  *tx_buf;
  161. int tx_put;
  162. int tx_get;
  163. int tx_count;
  164. wait_queue_head_t open_wait;
  165. wait_queue_head_t close_wait;
  166. wait_queue_head_t status_event_wait_q;
  167. wait_queue_head_t event_wait_q;
  168. struct timer_list tx_timer; /* HDLC transmit timeout timer */
  169. struct _synclinkmp_info *next_device; /* device list link */
  170. struct timer_list status_timer; /* input signal status check timer */
  171. spinlock_t lock; /* spinlock for synchronizing with ISR */
  172. struct tq_struct task;   /* task structure for scheduling bh */
  173. u32 max_frame_size; /* as set by device config */
  174. u32 pending_bh;
  175. int bh_running; /* Protection from multiple */
  176. int isr_overflow;
  177. int bh_requested;
  178. int dcd_chkcount; /* check counts to prevent */
  179. int cts_chkcount; /* too many IRQs if a signal */
  180. int dsr_chkcount; /* is floating */
  181. int ri_chkcount;
  182. char *buffer_list; /* virtual address of Rx & Tx buffer lists */
  183. unsigned long buffer_list_phys;
  184. unsigned int rx_buf_count; /* count of total allocated Rx buffers */
  185. SCADESC *rx_buf_list;    /* list of receive buffer entries */
  186. SCADESC_EX rx_buf_list_ex[SCAMAXDESC]; /* list of receive buffer entries */
  187. unsigned int current_rx_buf;
  188. unsigned int tx_buf_count; /* count of total allocated Tx buffers */
  189. SCADESC *tx_buf_list; /* list of transmit buffer entries */
  190. SCADESC_EX tx_buf_list_ex[SCAMAXDESC]; /* list of transmit buffer entries */
  191. unsigned int last_tx_buf;
  192. unsigned char *tmp_rx_buf;
  193. unsigned int tmp_rx_buf_count;
  194. int rx_enabled;
  195. int rx_overflow;
  196. int tx_enabled;
  197. int tx_active;
  198. u32 idle_mode;
  199. unsigned char ie0_value;
  200. unsigned char ie1_value;
  201. unsigned char ie2_value;
  202. unsigned char ctrlreg_value;
  203. unsigned char old_signals;
  204. char device_name[25]; /* device instance name */
  205. int port_count;
  206. int adapter_num;
  207. int port_num;
  208. struct _synclinkmp_info *port_array[SCA_MAX_PORTS];
  209. unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
  210. unsigned int irq_level; /* interrupt level */
  211. unsigned long irq_flags;
  212. int irq_requested; /* nonzero if IRQ requested */
  213. MGSL_PARAMS params; /* communications parameters */
  214. unsigned char serial_signals; /* current serial signal states */
  215. int irq_occurred; /* for diagnostics use */
  216. unsigned int init_error; /* Initialization startup error */
  217. u32 last_mem_alloc;
  218. unsigned char* memory_base; /* shared memory address (PCI only) */
  219. u32 phys_memory_base;
  220.      int shared_mem_requested;
  221. unsigned char* sca_base; /* HD64570 SCA Memory address */
  222. u32 phys_sca_base;
  223. u32 sca_offset;
  224. int sca_base_requested;
  225. unsigned char* lcr_base; /* local config registers (PCI only) */
  226. u32 phys_lcr_base;
  227. u32 lcr_offset;
  228. int lcr_mem_requested;
  229. unsigned char* statctrl_base; /* status/control register memory */
  230. u32 phys_statctrl_base;
  231. u32 statctrl_offset;
  232. int sca_statctrl_requested;
  233. u32 misc_ctrl_value;
  234. char flag_buf[MAX_ASYNC_BUFFER_SIZE];
  235. char char_buf[MAX_ASYNC_BUFFER_SIZE];
  236. BOOLEAN drop_rts_on_tx_done;
  237. struct _input_signal_events input_signal_events;
  238. /* SPPP/Cisco HDLC device parts */
  239. int netcount;
  240. int dosyncppp;
  241. spinlock_t netlock;
  242. #ifdef CONFIG_SYNCLINK_SYNCPPP
  243. struct ppp_device pppdev;
  244. char netname[10];
  245. struct net_device *netdev;
  246. struct net_device_stats netstats;
  247. struct net_device netdevice;
  248. #endif
  249. } SLMP_INFO;
  250. #define MGSL_MAGIC 0x5401
  251. /*
  252.  * define serial signal status change macros
  253.  */
  254. #define MISCSTATUS_DCD_LATCHED (SerialSignal_DCD<<8) /* indicates change in DCD */
  255. #define MISCSTATUS_RI_LATCHED (SerialSignal_RI<<8) /* indicates change in RI */
  256. #define MISCSTATUS_CTS_LATCHED (SerialSignal_CTS<<8) /* indicates change in CTS */
  257. #define MISCSTATUS_DSR_LATCHED (SerialSignal_DSR<<8) /* change in DSR */
  258. /* Common Register macros */
  259. #define LPR 0x00
  260. #define PABR0 0x02
  261. #define PABR1 0x03
  262. #define WCRL 0x04
  263. #define WCRM 0x05
  264. #define WCRH 0x06
  265. #define DPCR 0x08
  266. #define DMER 0x09
  267. #define ISR0 0x10
  268. #define ISR1 0x11
  269. #define ISR2 0x12
  270. #define IER0 0x14
  271. #define IER1 0x15
  272. #define IER2 0x16
  273. #define ITCR 0x18
  274. #define INTVR  0x1a
  275. #define IMVR 0x1c
  276. /* MSCI Register macros */
  277. #define TRB 0x20
  278. #define TRBL 0x20
  279. #define TRBH 0x21
  280. #define SR0 0x22
  281. #define SR1 0x23
  282. #define SR2 0x24
  283. #define SR3 0x25
  284. #define FST 0x26
  285. #define IE0 0x28
  286. #define IE1 0x29
  287. #define IE2 0x2a
  288. #define FIE 0x2b
  289. #define CMD 0x2c
  290. #define MD0 0x2e
  291. #define MD1 0x2f
  292. #define MD2 0x30
  293. #define CTL 0x31
  294. #define SA0 0x32
  295. #define SA1 0x33
  296. #define IDL 0x34
  297. #define TMC 0x35
  298. #define RXS 0x36
  299. #define TXS 0x37
  300. #define TRC0 0x38
  301. #define TRC1 0x39
  302. #define RRC 0x3a
  303. #define CST0 0x3c
  304. #define CST1 0x3d
  305. /* Timer Register Macros */
  306. #define TCNT 0x60
  307. #define TCNTL 0x60
  308. #define TCNTH 0x61
  309. #define TCONR 0x62
  310. #define TCONRL 0x62
  311. #define TCONRH 0x63
  312. #define TMCS 0x64
  313. #define TEPR 0x65
  314. /* DMA Controller Register macros */
  315. #define DAR 0x80
  316. #define DARL 0x80
  317. #define DARH 0x81
  318. #define DARB 0x82
  319. #define BAR 0x80
  320. #define BARL 0x80
  321. #define BARH 0x81
  322. #define BARB 0x82
  323. #define SAR 0x84
  324. #define SARL 0x84
  325. #define SARH 0x85
  326. #define SARB 0x86
  327. #define CPB 0x86
  328. #define CDA 0x88
  329. #define CDAL 0x88
  330. #define CDAH 0x89
  331. #define EDA 0x8a
  332. #define EDAL 0x8a
  333. #define EDAH 0x8b
  334. #define BFL 0x8c
  335. #define BFLL 0x8c
  336. #define BFLH 0x8d
  337. #define BCR 0x8e
  338. #define BCRL 0x8e
  339. #define BCRH 0x8f
  340. #define DSR 0x90
  341. #define DMR 0x91
  342. #define FCT 0x93
  343. #define DIR 0x94
  344. #define DCMD 0x95
  345. /* combine with timer or DMA register address */
  346. #define TIMER0 0x00
  347. #define TIMER1 0x08
  348. #define TIMER2 0x10
  349. #define TIMER3 0x18
  350. #define RXDMA  0x00
  351. #define TXDMA  0x20
  352. /* SCA Command Codes */
  353. #define NOOP 0x00
  354. #define TXRESET 0x01
  355. #define TXENABLE 0x02
  356. #define TXDISABLE 0x03
  357. #define TXCRCINIT 0x04
  358. #define TXCRCEXCL 0x05
  359. #define TXEOM 0x06
  360. #define TXABORT 0x07
  361. #define MPON 0x08
  362. #define TXBUFCLR 0x09
  363. #define RXRESET 0x11
  364. #define RXENABLE 0x12
  365. #define RXDISABLE 0x13
  366. #define RXCRCINIT 0x14
  367. #define RXREJECT 0x15
  368. #define SEARCHMP 0x16
  369. #define RXCRCEXCL 0x17
  370. #define RXCRCCALC 0x18
  371. #define CHRESET 0x21
  372. #define HUNT 0x31
  373. /* DMA command codes */
  374. #define SWABORT 0x01
  375. #define FEICLEAR 0x02
  376. /* IE0 */
  377. #define TXINTE  BIT7
  378. #define RXINTE  BIT6
  379. #define TXRDYE  BIT1
  380. #define RXRDYE  BIT0
  381. /* IE1 & SR1 */
  382. #define UDRN    BIT7
  383. #define IDLE    BIT6
  384. #define SYNCD   BIT4
  385. #define FLGD    BIT4
  386. #define CCTS    BIT3
  387. #define CDCD    BIT2
  388. #define BRKD    BIT1
  389. #define ABTD    BIT1
  390. #define GAPD    BIT1
  391. #define BRKE    BIT0
  392. #define IDLD BIT0
  393. /* IE2 & SR2 */
  394. #define EOM BIT7
  395. #define PMP BIT6
  396. #define SHRT BIT6
  397. #define PE BIT5
  398. #define ABT BIT5
  399. #define FRME BIT4
  400. #define RBIT BIT4
  401. #define OVRN BIT3
  402. #define CRCE BIT2
  403. #define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
  404. /*
  405.  * Global linked list of SyncLink devices
  406.  */
  407. static SLMP_INFO *synclinkmp_device_list = NULL;
  408. static int synclinkmp_adapter_count = -1;
  409. static int synclinkmp_device_count = 0;
  410. /*
  411.  * Set this param to non-zero to load eax with the
  412.  * .text section address and breakpoint on module load.
  413.  * This is useful for use with gdb and add-symbol-file command.
  414.  */
  415. static int break_on_load=0;
  416. /*
  417.  * Driver major number, defaults to zero to get auto
  418.  * assigned major number. May be forced as module parameter.
  419.  */
  420. static int ttymajor=0;
  421. static int cuamajor=0;
  422. /*
  423.  * Array of user specified options for ISA adapters.
  424.  */
  425. static int debug_level = 0;
  426. static int maxframe[MAX_DEVICES] = {0,};
  427. static int dosyncppp[MAX_DEVICES] = {0,};
  428. MODULE_PARM(break_on_load,"i");
  429. MODULE_PARM(ttymajor,"i");
  430. MODULE_PARM(cuamajor,"i");
  431. MODULE_PARM(debug_level,"i");
  432. MODULE_PARM(maxframe,"1-" __MODULE_STRING(MAX_DEVICES) "i");
  433. MODULE_PARM(dosyncppp,"1-" __MODULE_STRING(MAX_DEVICES) "i");
  434. static char *driver_name = "SyncLink MultiPort driver";
  435. static char *driver_version = "$Revision: 3.17 $";
  436. static int __devinit synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
  437. static void __devexit synclinkmp_remove_one(struct pci_dev *dev);
  438. static struct pci_device_id synclinkmp_pci_tbl[] __devinitdata = {
  439. { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_SCA, PCI_ANY_ID, PCI_ANY_ID, },
  440. { 0, }, /* terminate list */
  441. };
  442. MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
  443. static struct pci_driver synclinkmp_pci_driver = {
  444. name: "synclinkmp",
  445. id_table: synclinkmp_pci_tbl,
  446. probe: synclinkmp_init_one,
  447. remove: __devexit_p(synclinkmp_remove_one),
  448. };
  449. static struct tty_driver serial_driver, callout_driver;
  450. static int serial_refcount;
  451. /* number of characters left in xmit buffer before we ask for more */
  452. #define WAKEUP_CHARS 256
  453. static struct tty_struct *serial_table[MAX_DEVICES];
  454. static struct termios *serial_termios[MAX_DEVICES];
  455. static struct termios *serial_termios_locked[MAX_DEVICES];
  456. #ifndef MIN
  457. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  458. #endif
  459. /* tty callbacks */
  460. static int  open(struct tty_struct *tty, struct file * filp);
  461. static void close(struct tty_struct *tty, struct file * filp);
  462. static void hangup(struct tty_struct *tty);
  463. static void set_termios(struct tty_struct *tty, struct termios *old_termios);
  464. static int  write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
  465. static void put_char(struct tty_struct *tty, unsigned char ch);
  466. static void send_xchar(struct tty_struct *tty, char ch);
  467. static void wait_until_sent(struct tty_struct *tty, int timeout);
  468. static int  write_room(struct tty_struct *tty);
  469. static void flush_chars(struct tty_struct *tty);
  470. static void flush_buffer(struct tty_struct *tty);
  471. static void tx_hold(struct tty_struct *tty);
  472. static void tx_release(struct tty_struct *tty);
  473. static int  ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  474. static int  read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
  475. static int  chars_in_buffer(struct tty_struct *tty);
  476. static void throttle(struct tty_struct * tty);
  477. static void unthrottle(struct tty_struct * tty);
  478. static void set_break(struct tty_struct *tty, int break_state);
  479. /* sppp support and callbacks */
  480. #ifdef CONFIG_SYNCLINK_SYNCPPP
  481. static void sppp_init(SLMP_INFO *info);
  482. static void sppp_delete(SLMP_INFO *info);
  483. static void sppp_rx_done(SLMP_INFO *info, char *buf, int size);
  484. static void sppp_tx_done(SLMP_INFO *info);
  485. static int  sppp_cb_open(struct net_device *d);
  486. static int  sppp_cb_close(struct net_device *d);
  487. static int  sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
  488. static int  sppp_cb_tx(struct sk_buff *skb, struct net_device *dev);
  489. static void sppp_cb_tx_timeout(struct net_device *dev);
  490. static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev);
  491. #endif
  492. /* ioctl handlers */
  493. static int  get_stats(SLMP_INFO *info, struct mgsl_icount *user_icount);
  494. static int  get_params(SLMP_INFO *info, MGSL_PARAMS *params);
  495. static int  set_params(SLMP_INFO *info, MGSL_PARAMS *params);
  496. static int  get_txidle(SLMP_INFO *info, int*idle_mode);
  497. static int  set_txidle(SLMP_INFO *info, int idle_mode);
  498. static int  tx_enable(SLMP_INFO *info, int enable);
  499. static int  tx_abort(SLMP_INFO *info);
  500. static int  rx_enable(SLMP_INFO *info, int enable);
  501. static int  map_status(int signals);
  502. static int  modem_input_wait(SLMP_INFO *info,int arg);
  503. static int  wait_mgsl_event(SLMP_INFO *info, int *mask_ptr);
  504. static int  get_modem_info(SLMP_INFO *info, unsigned int *value);
  505. static int  set_modem_info(SLMP_INFO *info, unsigned int cmd,unsigned int *value);
  506. static void set_break(struct tty_struct *tty, int break_state);
  507. static void add_device(SLMP_INFO *info);
  508. static void device_init(int adapter_num, struct pci_dev *pdev);
  509. static int  claim_resources(SLMP_INFO *info);
  510. static void release_resources(SLMP_INFO *info);
  511. static int  startup(SLMP_INFO *info);
  512. static int  block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
  513. static void shutdown(SLMP_INFO *info);
  514. static void program_hw(SLMP_INFO *info);
  515. static void change_params(SLMP_INFO *info);
  516. static int  init_adapter(SLMP_INFO *info);
  517. static int  register_test(SLMP_INFO *info);
  518. static int  irq_test(SLMP_INFO *info);
  519. static int  loopback_test(SLMP_INFO *info);
  520. static int  adapter_test(SLMP_INFO *info);
  521. static int  memory_test(SLMP_INFO *info);
  522. static void reset_adapter(SLMP_INFO *info);
  523. static void reset_port(SLMP_INFO *info);
  524. static void async_mode(SLMP_INFO *info);
  525. static void hdlc_mode(SLMP_INFO *info);
  526. static void rx_stop(SLMP_INFO *info);
  527. static void rx_start(SLMP_INFO *info);
  528. static void rx_reset_buffers(SLMP_INFO *info);
  529. static void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last);
  530. static int  rx_get_frame(SLMP_INFO *info);
  531. static void tx_start(SLMP_INFO *info);
  532. static void tx_stop(SLMP_INFO *info);
  533. static void tx_load_fifo(SLMP_INFO *info);
  534. static void tx_set_idle(SLMP_INFO *info);
  535. static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count);
  536. static void get_signals(SLMP_INFO *info);
  537. static void set_signals(SLMP_INFO *info);
  538. static void enable_loopback(SLMP_INFO *info, int enable);
  539. static void set_rate(SLMP_INFO *info, u32 data_rate);
  540. static int  bh_action(SLMP_INFO *info);
  541. static void bh_handler(void* Context);
  542. static void bh_receive(SLMP_INFO *info);
  543. static void bh_transmit(SLMP_INFO *info);
  544. static void bh_status(SLMP_INFO *info);
  545. static void isr_timer(SLMP_INFO *info);
  546. static void isr_rxint(SLMP_INFO *info);
  547. static void isr_rxrdy(SLMP_INFO *info);
  548. static void isr_txint(SLMP_INFO *info);
  549. static void isr_txrdy(SLMP_INFO *info);
  550. static void isr_rxdmaok(SLMP_INFO *info);
  551. static void isr_rxdmaerror(SLMP_INFO *info);
  552. static void isr_txdmaok(SLMP_INFO *info);
  553. static void isr_txdmaerror(SLMP_INFO *info);
  554. static void isr_io_pin(SLMP_INFO *info, u16 status);
  555. static void synclinkmp_interrupt(int irq, void *dev_id, struct pt_regs * regs);
  556. static int  alloc_dma_bufs(SLMP_INFO *info);
  557. static void free_dma_bufs(SLMP_INFO *info);
  558. static int  alloc_buf_list(SLMP_INFO *info);
  559. static int  alloc_frame_bufs(SLMP_INFO *info, SCADESC *list, SCADESC_EX *list_ex,int count);
  560. static int  alloc_tmp_rx_buf(SLMP_INFO *info);
  561. static void free_tmp_rx_buf(SLMP_INFO *info);
  562. static void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count);
  563. static void trace_block(SLMP_INFO *info, const char* data, int count, int xmit);
  564. static void tx_timeout(unsigned long context);
  565. static void status_timeout(unsigned long context);
  566. static unsigned char read_reg(SLMP_INFO *info, unsigned char addr);
  567. static void write_reg(SLMP_INFO *info, unsigned char addr, unsigned char val);
  568. static u16 read_reg16(SLMP_INFO *info, unsigned char addr);
  569. static void write_reg16(SLMP_INFO *info, unsigned char addr, u16 val);
  570. static unsigned char read_status_reg(SLMP_INFO * info);
  571. static void write_control_reg(SLMP_INFO * info);
  572. static unsigned char rx_active_fifo_level = 16; // rx request FIFO activation level in bytes
  573. static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation level in bytes
  574. static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
  575. static u32 misc_ctrl_value = 0x007e4040;
  576. static u32 lcr1_brdr_value = 0x0080002d;
  577. static u32 read_ahead_count = 8;
  578. /* DPCR, DMA Priority Control
  579.  *
  580.  * 07..05  Not used, must be 0
  581.  * 04      BRC, bus release condition: 0=all transfers complete
  582.  *              1=release after 1 xfer on all channels
  583.  * 03      CCC, channel change condition: 0=every cycle
  584.  *              1=after each channel completes all xfers
  585.  * 02..00  PR<2..0>, priority 100=round robin
  586.  *
  587.  * 00000100 = 0x00
  588.  */
  589. static unsigned char dma_priority = 0x04;
  590. // Number of bytes that can be written to shared RAM
  591. // in a single write operation
  592. static u32 sca_pci_load_interval = 64;
  593. /*
  594.  * 1st function defined in .text section. Calling this function in
  595.  * init_module() followed by a breakpoint allows a remote debugger
  596.  * (gdb) to get the .text address for the add-symbol-file command.
  597.  * This allows remote debugging of dynamically loadable modules.
  598.  */
  599. static void* synclinkmp_get_text_ptr(void);
  600. static void* synclinkmp_get_text_ptr() {return synclinkmp_get_text_ptr;}
  601. static inline int sanity_check(SLMP_INFO *info,
  602.        kdev_t device, const char *routine)
  603. {
  604. #ifdef SANITY_CHECK
  605. static const char *badmagic =
  606. "Warning: bad magic number for synclinkmp_struct (%s) in %sn";
  607. static const char *badinfo =
  608. "Warning: null synclinkmp_struct for (%s) in %sn";
  609. if (!info) {
  610. printk(badinfo, kdevname(device), routine);
  611. return 1;
  612. }
  613. if (info->magic != MGSL_MAGIC) {
  614. printk(badmagic, kdevname(device), routine);
  615. return 1;
  616. }
  617. #endif
  618. return 0;
  619. }
  620. /* tty callbacks */
  621. /* Called when a port is opened.  Init and enable port.
  622.  */
  623. static int open(struct tty_struct *tty, struct file *filp)
  624. {
  625. SLMP_INFO *info;
  626. int retval, line;
  627. unsigned long flags;
  628. line = MINOR(tty->device) - tty->driver.minor_start;
  629. if ((line < 0) || (line >= synclinkmp_device_count)) {
  630. printk("%s(%d): open with illegal line #%d.n",
  631. __FILE__,__LINE__,line);
  632. return -ENODEV;
  633. }
  634. info = synclinkmp_device_list;
  635. while(info && info->line != line)
  636. info = info->next_device;
  637. if ( !info ){
  638. printk("%s(%d):%s Can't find specified device on open (line=%d)n",
  639. __FILE__,__LINE__,info->device_name,line);
  640. return -ENODEV;
  641. }
  642. if ( info->init_error ) {
  643. printk("%s(%d):%s device is not allocated, init error=%dn",
  644. __FILE__,__LINE__,info->device_name,info->init_error);
  645. return -ENODEV;
  646. }
  647. tty->driver_data = info;
  648. info->tty = tty;
  649. if (sanity_check(info, tty->device, "open"))
  650. return -ENODEV;
  651. if (debug_level >= DEBUG_LEVEL_INFO)
  652. printk("%s(%d):%s open(), old ref count = %dn",
  653.  __FILE__,__LINE__,tty->driver.name, info->count);
  654. MOD_INC_USE_COUNT;
  655. /* If port is closing, signal caller to try again */
  656. if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
  657. if (info->flags & ASYNC_CLOSING)
  658. interruptible_sleep_on(&info->close_wait);
  659. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  660. -EAGAIN : -ERESTARTSYS);
  661. goto cleanup;
  662. }
  663. info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  664. spin_lock_irqsave(&info->netlock, flags);
  665. if (info->netcount) {
  666. retval = -EBUSY;
  667. spin_unlock_irqrestore(&info->netlock, flags);
  668. goto cleanup;
  669. }
  670. info->count++;
  671. spin_unlock_irqrestore(&info->netlock, flags);
  672. if (info->count == 1) {
  673. /* 1st open on this device, init hardware */
  674. retval = startup(info);
  675. if (retval < 0)
  676. goto cleanup;
  677. }
  678. retval = block_til_ready(tty, filp, info);
  679. if (retval) {
  680. if (debug_level >= DEBUG_LEVEL_INFO)
  681. printk("%s(%d):%s block_til_ready() returned %dn",
  682.  __FILE__,__LINE__, info->device_name, retval);
  683. goto cleanup;
  684. }
  685. if ((info->count == 1) &&
  686.     info->flags & ASYNC_SPLIT_TERMIOS) {
  687. if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
  688. *tty->termios = info->normal_termios;
  689. else
  690. *tty->termios = info->callout_termios;
  691. change_params(info);
  692. }
  693. info->session = current->session;
  694. info->pgrp    = current->pgrp;
  695. if (debug_level >= DEBUG_LEVEL_INFO)
  696. printk("%s(%d):%s open() successn",
  697.  __FILE__,__LINE__, info->device_name);
  698. retval = 0;
  699. cleanup:
  700. if (retval) {
  701. if(MOD_IN_USE)
  702. MOD_DEC_USE_COUNT;
  703. if(info->count)
  704. info->count--;
  705. }
  706. return retval;
  707. }
  708. /* Called when port is closed. Wait for remaining data to be
  709.  * sent. Disable port and free resources.
  710.  */
  711. static void close(struct tty_struct *tty, struct file *filp)
  712. {
  713. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  714. if (!info || sanity_check(info, tty->device, "close"))
  715. return;
  716. if (debug_level >= DEBUG_LEVEL_INFO)
  717. printk("%s(%d):%s close() entry, count=%dn",
  718.  __FILE__,__LINE__, info->device_name, info->count);
  719. if (!info->count || tty_hung_up_p(filp))
  720. goto cleanup;
  721. if ((tty->count == 1) && (info->count != 1)) {
  722. /*
  723.  * tty->count is 1 and the tty structure will be freed.
  724.  * info->count should be one in this case.
  725.  * if it's not, correct it so that the port is shutdown.
  726.  */
  727. printk("%s(%d):%s close: bad refcount; tty->count is 1, "
  728.        "info->count is %dn",
  729.  __FILE__,__LINE__, info->device_name, info->count);
  730. info->count = 1;
  731. }
  732. info->count--;
  733. /* if at least one open remaining, leave hardware active */
  734. if (info->count)
  735. goto cleanup;
  736. info->flags |= ASYNC_CLOSING;
  737. /* Save the termios structure, since this port may have
  738.  * separate termios for callout and dialin.
  739.  */
  740. if (info->flags & ASYNC_NORMAL_ACTIVE)
  741. info->normal_termios = *tty->termios;
  742. if (info->flags & ASYNC_CALLOUT_ACTIVE)
  743. info->callout_termios = *tty->termios;
  744. /* set tty->closing to notify line discipline to
  745.  * only process XON/XOFF characters. Only the N_TTY
  746.  * discipline appears to use this (ppp does not).
  747.  */
  748. tty->closing = 1;
  749. /* wait for transmit data to clear all layers */
  750. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
  751. if (debug_level >= DEBUG_LEVEL_INFO)
  752. printk("%s(%d):%s close() calling tty_wait_until_sentn",
  753.  __FILE__,__LINE__, info->device_name );
  754. tty_wait_until_sent(tty, info->closing_wait);
  755. }
  756.   if (info->flags & ASYNC_INITIALIZED)
  757.   wait_until_sent(tty, info->timeout);
  758. if (tty->driver.flush_buffer)
  759. tty->driver.flush_buffer(tty);
  760. if (tty->ldisc.flush_buffer)
  761. tty->ldisc.flush_buffer(tty);
  762. shutdown(info);
  763. tty->closing = 0;
  764. info->tty = 0;
  765. if (info->blocked_open) {
  766. if (info->close_delay) {
  767. set_current_state(TASK_INTERRUPTIBLE);
  768. schedule_timeout(info->close_delay);
  769. }
  770. wake_up_interruptible(&info->open_wait);
  771. }
  772. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
  773.  ASYNC_CLOSING);
  774. wake_up_interruptible(&info->close_wait);
  775. cleanup:
  776. if (debug_level >= DEBUG_LEVEL_INFO)
  777. printk("%s(%d):%s close() exit, count=%dn", __FILE__,__LINE__,
  778. tty->driver.name, info->count);
  779. if(MOD_IN_USE)
  780. MOD_DEC_USE_COUNT;
  781. }
  782. /* Called by tty_hangup() when a hangup is signaled.
  783.  * This is the same as closing all open descriptors for the port.
  784.  */
  785. static void hangup(struct tty_struct *tty)
  786. {
  787. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  788. if (debug_level >= DEBUG_LEVEL_INFO)
  789. printk("%s(%d):%s hangup()n",
  790.  __FILE__,__LINE__, info->device_name );
  791. if (sanity_check(info, tty->device, "hangup"))
  792. return;
  793. flush_buffer(tty);
  794. shutdown(info);
  795. info->count = 0;
  796. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
  797. info->tty = 0;
  798. wake_up_interruptible(&info->open_wait);
  799. }
  800. /* Set new termios settings
  801.  */
  802. static void set_termios(struct tty_struct *tty, struct termios *old_termios)
  803. {
  804. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  805. unsigned long flags;
  806. if (debug_level >= DEBUG_LEVEL_INFO)
  807. printk("%s(%d):%s set_termios()n", __FILE__,__LINE__,
  808. tty->driver.name );
  809. /* just return if nothing has changed */
  810. if ((tty->termios->c_cflag == old_termios->c_cflag)
  811.     && (RELEVANT_IFLAG(tty->termios->c_iflag)
  812. == RELEVANT_IFLAG(old_termios->c_iflag)))
  813.   return;
  814. change_params(info);
  815. /* Handle transition to B0 status */
  816. if (old_termios->c_cflag & CBAUD &&
  817.     !(tty->termios->c_cflag & CBAUD)) {
  818. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  819. spin_lock_irqsave(&info->lock,flags);
  820.   set_signals(info);
  821. spin_unlock_irqrestore(&info->lock,flags);
  822. }
  823. /* Handle transition away from B0 status */
  824. if (!(old_termios->c_cflag & CBAUD) &&
  825.     tty->termios->c_cflag & CBAUD) {
  826. info->serial_signals |= SerialSignal_DTR;
  827.   if (!(tty->termios->c_cflag & CRTSCTS) ||
  828.       !test_bit(TTY_THROTTLED, &tty->flags)) {
  829. info->serial_signals |= SerialSignal_RTS;
  830.   }
  831. spin_lock_irqsave(&info->lock,flags);
  832.   set_signals(info);
  833. spin_unlock_irqrestore(&info->lock,flags);
  834. }
  835. /* Handle turning off CRTSCTS */
  836. if (old_termios->c_cflag & CRTSCTS &&
  837.     !(tty->termios->c_cflag & CRTSCTS)) {
  838. tty->hw_stopped = 0;
  839. tx_release(tty);
  840. }
  841. }
  842. /* Send a block of data
  843.  *
  844.  * Arguments:
  845.  *
  846.  *  tty pointer to tty information structure
  847.  *  from_user flag: 1 = from user process
  848.  *  buf pointer to buffer containing send data
  849.  *  count size of send data in bytes
  850.  *
  851.  * Return Value: number of characters written
  852.  */
  853. static int write(struct tty_struct *tty, int from_user,
  854.  const unsigned char *buf, int count)
  855. {
  856. int c, ret = 0, err;
  857. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  858. unsigned long flags;
  859. if (debug_level >= DEBUG_LEVEL_INFO)
  860. printk("%s(%d):%s write() count=%dn",
  861.        __FILE__,__LINE__,info->device_name,count);
  862. if (sanity_check(info, tty->device, "write"))
  863. goto cleanup;
  864. if (!tty || !info->tx_buf)
  865. goto cleanup;
  866. if (info->params.mode == MGSL_MODE_HDLC) {
  867. if (count > info->max_frame_size) {
  868. ret = -EIO;
  869. goto cleanup;
  870. }
  871. if (info->tx_active)
  872. goto cleanup;
  873. if (info->tx_count) {
  874. /* send accumulated data from send_char() calls */
  875. /* as frame and wait before accepting more data. */
  876. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  877. goto start;
  878. }
  879. if (!from_user) {
  880. ret = info->tx_count = count;
  881. tx_load_dma_buffer(info, buf, count);
  882. goto start;
  883. }
  884. }
  885. for (;;) {
  886. c = MIN(count,
  887. MIN(info->max_frame_size - info->tx_count - 1,
  888.     info->max_frame_size - info->tx_put));
  889. if (c <= 0)
  890. break;
  891. if (from_user) {
  892. COPY_FROM_USER(err, info->tx_buf + info->tx_put, buf, c);
  893. if (err) {
  894. if (!ret)
  895. ret = -EFAULT;
  896. break;
  897. }
  898. } else
  899. memcpy(info->tx_buf + info->tx_put, buf, c);
  900. spin_lock_irqsave(&info->lock,flags);
  901. info->tx_put += c;
  902. if (info->tx_put >= info->max_frame_size)
  903. info->tx_put -= info->max_frame_size;
  904. info->tx_count += c;
  905. spin_unlock_irqrestore(&info->lock,flags);
  906. buf += c;
  907. count -= c;
  908. ret += c;
  909. }
  910. if (info->params.mode == MGSL_MODE_HDLC) {
  911. if (count) {
  912. ret = info->tx_count = 0;
  913. goto cleanup;
  914. }
  915. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  916. }
  917. start:
  918.   if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
  919. spin_lock_irqsave(&info->lock,flags);
  920. if (!info->tx_active)
  921.   tx_start(info);
  922. spin_unlock_irqrestore(&info->lock,flags);
  923.   }
  924. cleanup:
  925. if (debug_level >= DEBUG_LEVEL_INFO)
  926. printk( "%s(%d):%s write() returning=%dn",
  927. __FILE__,__LINE__,info->device_name,ret);
  928. return ret;
  929. }
  930. /* Add a character to the transmit buffer.
  931.  */
  932. static void put_char(struct tty_struct *tty, unsigned char ch)
  933. {
  934. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  935. unsigned long flags;
  936. if ( debug_level >= DEBUG_LEVEL_INFO ) {
  937. printk( "%s(%d):%s put_char(%d)n",
  938. __FILE__,__LINE__,info->device_name,ch);
  939. }
  940. if (sanity_check(info, tty->device, "put_char"))
  941. return;
  942. if (!tty || !info->tx_buf)
  943. return;
  944. spin_lock_irqsave(&info->lock,flags);
  945. if ( (info->params.mode != MGSL_MODE_HDLC) ||
  946.      !info->tx_active ) {
  947. if (info->tx_count < info->max_frame_size - 1) {
  948. info->tx_buf[info->tx_put++] = ch;
  949. if (info->tx_put >= info->max_frame_size)
  950. info->tx_put -= info->max_frame_size;
  951. info->tx_count++;
  952. }
  953. }
  954. spin_unlock_irqrestore(&info->lock,flags);
  955. }
  956. /* Send a high-priority XON/XOFF character
  957.  */
  958. static void send_xchar(struct tty_struct *tty, char ch)
  959. {
  960. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  961. unsigned long flags;
  962. if (debug_level >= DEBUG_LEVEL_INFO)
  963. printk("%s(%d):%s send_xchar(%d)n",
  964.  __FILE__,__LINE__, info->device_name, ch );
  965. if (sanity_check(info, tty->device, "send_xchar"))
  966. return;
  967. info->x_char = ch;
  968. if (ch) {
  969. /* Make sure transmit interrupts are on */
  970. spin_lock_irqsave(&info->lock,flags);
  971. if (!info->tx_enabled)
  972.   tx_start(info);
  973. spin_unlock_irqrestore(&info->lock,flags);
  974. }
  975. }
  976. /* Wait until the transmitter is empty.
  977.  */
  978. static void wait_until_sent(struct tty_struct *tty, int timeout)
  979. {
  980. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  981. unsigned long orig_jiffies, char_time;
  982. if (!info )
  983. return;
  984. if (debug_level >= DEBUG_LEVEL_INFO)
  985. printk("%s(%d):%s wait_until_sent() entryn",
  986.  __FILE__,__LINE__, info->device_name );
  987. if (sanity_check(info, tty->device, "wait_until_sent"))
  988. return;
  989. if (!(info->flags & ASYNC_INITIALIZED))
  990. goto exit;
  991. orig_jiffies = jiffies;
  992. /* Set check interval to 1/5 of estimated time to
  993.  * send a character, and make it at least 1. The check
  994.  * interval should also be less than the timeout.
  995.  * Note: use tight timings here to satisfy the NIST-PCTS.
  996.  */
  997. if ( info->params.data_rate ) {
  998.         char_time = info->timeout/(32 * 5);
  999. if (!char_time)
  1000. char_time++;
  1001. } else
  1002. char_time = 1;
  1003. if (timeout)
  1004. char_time = MIN(char_time, timeout);
  1005. if ( info->params.mode == MGSL_MODE_HDLC ) {
  1006. while (info->tx_active) {
  1007. set_current_state(TASK_INTERRUPTIBLE);
  1008. schedule_timeout(char_time);
  1009. if (signal_pending(current))
  1010. break;
  1011. if (timeout && ((orig_jiffies + timeout) < jiffies))
  1012. break;
  1013. }
  1014. } else {
  1015. //TODO: determine if there is something similar to USC16C32
  1016. //  TXSTATUS_ALL_SENT status
  1017. while ( info->tx_active && info->tx_enabled) {
  1018. set_current_state(TASK_INTERRUPTIBLE);
  1019. schedule_timeout(char_time);
  1020. if (signal_pending(current))
  1021. break;
  1022. if (timeout && ((orig_jiffies + timeout) < jiffies))
  1023. break;
  1024. }
  1025. }
  1026. exit:
  1027. if (debug_level >= DEBUG_LEVEL_INFO)
  1028. printk("%s(%d):%s wait_until_sent() exitn",
  1029.  __FILE__,__LINE__, info->device_name );
  1030. }
  1031. /* Return the count of free bytes in transmit buffer
  1032.  */
  1033. static int write_room(struct tty_struct *tty)
  1034. {
  1035. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1036. int ret;
  1037. if (sanity_check(info, tty->device, "write_room"))
  1038. return 0;
  1039. if (info->params.mode == MGSL_MODE_HDLC) {
  1040. ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
  1041. } else {
  1042. ret = info->max_frame_size - info->tx_count - 1;
  1043. if (ret < 0)
  1044. ret = 0;
  1045. }
  1046. if (debug_level >= DEBUG_LEVEL_INFO)
  1047. printk("%s(%d):%s write_room()=%dn",
  1048.        __FILE__, __LINE__, info->device_name, ret);
  1049. return ret;
  1050. }
  1051. /* enable transmitter and send remaining buffered characters
  1052.  */
  1053. static void flush_chars(struct tty_struct *tty)
  1054. {
  1055. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1056. unsigned long flags;
  1057. if ( debug_level >= DEBUG_LEVEL_INFO )
  1058. printk( "%s(%d):%s flush_chars() entry tx_count=%dn",
  1059. __FILE__,__LINE__,info->device_name,info->tx_count);
  1060. if (sanity_check(info, tty->device, "flush_chars"))
  1061. return;
  1062. if (info->tx_count <= 0 || tty->stopped || tty->hw_stopped ||
  1063.     !info->tx_buf)
  1064. return;
  1065. if ( debug_level >= DEBUG_LEVEL_INFO )
  1066. printk( "%s(%d):%s flush_chars() entry, starting transmittern",
  1067. __FILE__,__LINE__,info->device_name );
  1068. spin_lock_irqsave(&info->lock,flags);
  1069. if (!info->tx_active) {
  1070. if ( (info->params.mode == MGSL_MODE_HDLC) &&
  1071. info->tx_count ) {
  1072. /* operating in synchronous (frame oriented) mode */
  1073. /* copy data from circular tx_buf to */
  1074. /* transmit DMA buffer. */
  1075. tx_load_dma_buffer(info,
  1076.  info->tx_buf,info->tx_count);
  1077. }
  1078.   tx_start(info);
  1079. }
  1080. spin_unlock_irqrestore(&info->lock,flags);
  1081. }
  1082. /* Discard all data in the send buffer
  1083.  */
  1084. static void flush_buffer(struct tty_struct *tty)
  1085. {
  1086. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1087. unsigned long flags;
  1088. if (debug_level >= DEBUG_LEVEL_INFO)
  1089. printk("%s(%d):%s flush_buffer() entryn",
  1090.  __FILE__,__LINE__, info->device_name );
  1091. if (sanity_check(info, tty->device, "flush_buffer"))
  1092. return;
  1093. spin_lock_irqsave(&info->lock,flags);
  1094. info->tx_count = info->tx_put = info->tx_get = 0;
  1095. del_timer(&info->tx_timer);
  1096. spin_unlock_irqrestore(&info->lock,flags);
  1097. wake_up_interruptible(&tty->write_wait);
  1098. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  1099.     tty->ldisc.write_wakeup)
  1100. (tty->ldisc.write_wakeup)(tty);
  1101. }
  1102. /* throttle (stop) transmitter
  1103.  */
  1104. static void tx_hold(struct tty_struct *tty)
  1105. {
  1106. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1107. unsigned long flags;
  1108. if (sanity_check(info, tty->device, "tx_hold"))
  1109. return;
  1110. if ( debug_level >= DEBUG_LEVEL_INFO )
  1111. printk("%s(%d):%s tx_hold()n",
  1112. __FILE__,__LINE__,info->device_name);
  1113. spin_lock_irqsave(&info->lock,flags);
  1114. if (info->tx_enabled)
  1115.   tx_stop(info);
  1116. spin_unlock_irqrestore(&info->lock,flags);
  1117. }
  1118. /* release (start) transmitter
  1119.  */
  1120. static void tx_release(struct tty_struct *tty)
  1121. {
  1122. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1123. unsigned long flags;
  1124. if (sanity_check(info, tty->device, "tx_release"))
  1125. return;
  1126. if ( debug_level >= DEBUG_LEVEL_INFO )
  1127. printk("%s(%d):%s tx_release()n",
  1128. __FILE__,__LINE__,info->device_name);
  1129. spin_lock_irqsave(&info->lock,flags);
  1130. if (!info->tx_enabled)
  1131.   tx_start(info);
  1132. spin_unlock_irqrestore(&info->lock,flags);
  1133. }
  1134. /* Service an IOCTL request
  1135.  *
  1136.  * Arguments:
  1137.  *
  1138.  *  tty pointer to tty instance data
  1139.  *  file pointer to associated file object for device
  1140.  *  cmd IOCTL command code
  1141.  *  arg command argument/context
  1142.  *
  1143.  * Return Value: 0 if success, otherwise error code
  1144.  */
  1145. static int ioctl(struct tty_struct *tty, struct file *file,
  1146.  unsigned int cmd, unsigned long arg)
  1147. {
  1148. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1149. int error;
  1150. struct mgsl_icount cnow; /* kernel counter temps */
  1151. struct serial_icounter_struct *p_cuser; /* user space */
  1152. unsigned long flags;
  1153. if (debug_level >= DEBUG_LEVEL_INFO)
  1154. printk("%s(%d):%s ioctl() cmd=%08Xn", __FILE__,__LINE__,
  1155. info->device_name, cmd );
  1156. if (sanity_check(info, tty->device, "ioctl"))
  1157. return -ENODEV;
  1158. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1159.     (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1160. if (tty->flags & (1 << TTY_IO_ERROR))
  1161.     return -EIO;
  1162. }
  1163. switch (cmd) {
  1164. case TIOCMGET:
  1165. return get_modem_info(info, (unsigned int *) arg);
  1166. case TIOCMBIS:
  1167. case TIOCMBIC:
  1168. case TIOCMSET:
  1169. return set_modem_info(info, cmd, (unsigned int *) arg);
  1170. case MGSL_IOCGPARAMS:
  1171. return get_params(info,(MGSL_PARAMS *)arg);
  1172. case MGSL_IOCSPARAMS:
  1173. return set_params(info,(MGSL_PARAMS *)arg);
  1174. case MGSL_IOCGTXIDLE:
  1175. return get_txidle(info,(int*)arg);
  1176. case MGSL_IOCSTXIDLE:
  1177. return set_txidle(info,(int)arg);
  1178. case MGSL_IOCTXENABLE:
  1179. return tx_enable(info,(int)arg);
  1180. case MGSL_IOCRXENABLE:
  1181. return rx_enable(info,(int)arg);
  1182. case MGSL_IOCTXABORT:
  1183. return tx_abort(info);
  1184. case MGSL_IOCGSTATS:
  1185. return get_stats(info,(struct mgsl_icount*)arg);
  1186. case MGSL_IOCWAITEVENT:
  1187. return wait_mgsl_event(info,(int*)arg);
  1188. case MGSL_IOCLOOPTXDONE:
  1189. return 0; // TODO: Not supported, need to document
  1190. case MGSL_IOCCLRMODCOUNT:
  1191. while(MOD_IN_USE)
  1192. MOD_DEC_USE_COUNT;
  1193. return 0;
  1194. /* Wait for modem input (DCD,RI,DSR,CTS) change
  1195.  * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
  1196.  */
  1197. case TIOCMIWAIT:
  1198. return modem_input_wait(info,(int)arg);
  1199. /*
  1200.  * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1201.  * Return: write counters to the user passed counter struct
  1202.  * NB: both 1->0 and 0->1 transitions are counted except for
  1203.  *     RI where only 0->1 is counted.
  1204.  */
  1205. case TIOCGICOUNT:
  1206. spin_lock_irqsave(&info->lock,flags);
  1207. cnow = info->icount;
  1208. spin_unlock_irqrestore(&info->lock,flags);
  1209. p_cuser = (struct serial_icounter_struct *) arg;
  1210. PUT_USER(error,cnow.cts, &p_cuser->cts);
  1211. if (error) return error;
  1212. PUT_USER(error,cnow.dsr, &p_cuser->dsr);
  1213. if (error) return error;
  1214. PUT_USER(error,cnow.rng, &p_cuser->rng);
  1215. if (error) return error;
  1216. PUT_USER(error,cnow.dcd, &p_cuser->dcd);
  1217. if (error) return error;
  1218. PUT_USER(error,cnow.rx, &p_cuser->rx);
  1219. if (error) return error;
  1220. PUT_USER(error,cnow.tx, &p_cuser->tx);
  1221. if (error) return error;
  1222. PUT_USER(error,cnow.frame, &p_cuser->frame);
  1223. if (error) return error;
  1224. PUT_USER(error,cnow.overrun, &p_cuser->overrun);
  1225. if (error) return error;
  1226. PUT_USER(error,cnow.parity, &p_cuser->parity);
  1227. if (error) return error;
  1228. PUT_USER(error,cnow.brk, &p_cuser->brk);
  1229. if (error) return error;
  1230. PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
  1231. if (error) return error;
  1232. return 0;
  1233. default:
  1234. return -ENOIOCTLCMD;
  1235. }
  1236. return 0;
  1237. }
  1238. /*
  1239.  * /proc fs routines....
  1240.  */
  1241. static inline int line_info(char *buf, SLMP_INFO *info)
  1242. {
  1243. char stat_buf[30];
  1244. int ret;
  1245. unsigned long flags;
  1246. ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08Xn"
  1247.        "tIRQ=%d MaxFrameSize=%un",
  1248. info->device_name,
  1249. info->phys_sca_base,
  1250. info->phys_memory_base,
  1251. info->phys_statctrl_base,
  1252. info->phys_lcr_base,
  1253. info->irq_level,
  1254. info->max_frame_size );
  1255. /* output current serial signal states */
  1256. spin_lock_irqsave(&info->lock,flags);
  1257.   get_signals(info);
  1258. spin_unlock_irqrestore(&info->lock,flags);
  1259. stat_buf[0] = 0;
  1260. stat_buf[1] = 0;
  1261. if (info->serial_signals & SerialSignal_RTS)
  1262. strcat(stat_buf, "|RTS");
  1263. if (info->serial_signals & SerialSignal_CTS)
  1264. strcat(stat_buf, "|CTS");
  1265. if (info->serial_signals & SerialSignal_DTR)
  1266. strcat(stat_buf, "|DTR");
  1267. if (info->serial_signals & SerialSignal_DSR)
  1268. strcat(stat_buf, "|DSR");
  1269. if (info->serial_signals & SerialSignal_DCD)
  1270. strcat(stat_buf, "|CD");
  1271. if (info->serial_signals & SerialSignal_RI)
  1272. strcat(stat_buf, "|RI");
  1273. if (info->params.mode == MGSL_MODE_HDLC) {
  1274. ret += sprintf(buf+ret, "tHDLC txok:%d rxok:%d",
  1275.       info->icount.txok, info->icount.rxok);
  1276. if (info->icount.txunder)
  1277. ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
  1278. if (info->icount.txabort)
  1279. ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
  1280. if (info->icount.rxshort)
  1281. ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
  1282. if (info->icount.rxlong)
  1283. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
  1284. if (info->icount.rxover)
  1285. ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
  1286. if (info->icount.rxcrc)
  1287. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxcrc);
  1288. } else {
  1289. ret += sprintf(buf+ret, "tASYNC tx:%d rx:%d",
  1290.       info->icount.tx, info->icount.rx);
  1291. if (info->icount.frame)
  1292. ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
  1293. if (info->icount.parity)
  1294. ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
  1295. if (info->icount.brk)
  1296. ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
  1297. if (info->icount.overrun)
  1298. ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
  1299. }
  1300. /* Append serial signal status to end */
  1301. ret += sprintf(buf+ret, " %sn", stat_buf+1);
  1302. ret += sprintf(buf+ret, "ttxactive=%d bh_req=%d bh_run=%d pending_bh=%xn",
  1303.  info->tx_active,info->bh_requested,info->bh_running,
  1304.  info->pending_bh);
  1305. return ret;
  1306. }
  1307. /* Called to print information about devices
  1308.  */
  1309. int read_proc(char *page, char **start, off_t off, int count,
  1310.       int *eof, void *data)
  1311. {
  1312. int len = 0, l;
  1313. off_t begin = 0;
  1314. SLMP_INFO *info;
  1315. len += sprintf(page, "synclinkmp driver:%sn", driver_version);
  1316. info = synclinkmp_device_list;
  1317. while( info ) {
  1318. l = line_info(page + len, info);
  1319. len += l;
  1320. if (len+begin > off+count)
  1321. goto done;
  1322. if (len+begin < off) {
  1323. begin += len;
  1324. len = 0;
  1325. }
  1326. info = info->next_device;
  1327. }
  1328. *eof = 1;
  1329. done:
  1330. if (off >= len+begin)
  1331. return 0;
  1332. *start = page + (off-begin);
  1333. return ((count < begin+len-off) ? count : begin+len-off);
  1334. }
  1335. /* Return the count of bytes in transmit buffer
  1336.  */
  1337. static int chars_in_buffer(struct tty_struct *tty)
  1338. {
  1339. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1340. if (sanity_check(info, tty->device, "chars_in_buffer"))
  1341. return 0;
  1342. if (debug_level >= DEBUG_LEVEL_INFO)
  1343. printk("%s(%d):%s chars_in_buffer()=%dn",
  1344.        __FILE__, __LINE__, info->device_name, info->tx_count);
  1345. return info->tx_count;
  1346. }
  1347. /* Signal remote device to throttle send data (our receive data)
  1348.  */
  1349. static void throttle(struct tty_struct * tty)
  1350. {
  1351. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1352. unsigned long flags;
  1353. if (debug_level >= DEBUG_LEVEL_INFO)
  1354. printk("%s(%d):%s throttle() entryn",
  1355.  __FILE__,__LINE__, info->device_name );
  1356. if (sanity_check(info, tty->device, "throttle"))
  1357. return;
  1358. if (I_IXOFF(tty))
  1359. send_xchar(tty, STOP_CHAR(tty));
  1360.   if (tty->termios->c_cflag & CRTSCTS) {
  1361. spin_lock_irqsave(&info->lock,flags);
  1362. info->serial_signals &= ~SerialSignal_RTS;
  1363.   set_signals(info);
  1364. spin_unlock_irqrestore(&info->lock,flags);
  1365. }
  1366. }
  1367. /* Signal remote device to stop throttling send data (our receive data)
  1368.  */
  1369. static void unthrottle(struct tty_struct * tty)
  1370. {
  1371. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1372. unsigned long flags;
  1373. if (debug_level >= DEBUG_LEVEL_INFO)
  1374. printk("%s(%d):%s unthrottle() entryn",
  1375.  __FILE__,__LINE__, info->device_name );
  1376. if (sanity_check(info, tty->device, "unthrottle"))
  1377. return;
  1378. if (I_IXOFF(tty)) {
  1379. if (info->x_char)
  1380. info->x_char = 0;
  1381. else
  1382. send_xchar(tty, START_CHAR(tty));
  1383. }
  1384.   if (tty->termios->c_cflag & CRTSCTS) {
  1385. spin_lock_irqsave(&info->lock,flags);
  1386. info->serial_signals |= SerialSignal_RTS;
  1387.   set_signals(info);
  1388. spin_unlock_irqrestore(&info->lock,flags);
  1389. }
  1390. }
  1391. /* set or clear transmit break condition
  1392.  * break_state -1=set break condition, 0=clear
  1393.  */
  1394. static void set_break(struct tty_struct *tty, int break_state)
  1395. {
  1396. unsigned char RegValue;
  1397. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  1398. unsigned long flags;
  1399. if (debug_level >= DEBUG_LEVEL_INFO)
  1400. printk("%s(%d):%s set_break(%d)n",
  1401.  __FILE__,__LINE__, info->device_name, break_state);
  1402. if (sanity_check(info, tty->device, "set_break"))
  1403. return;
  1404. spin_lock_irqsave(&info->lock,flags);
  1405. RegValue = read_reg(info, CTL);
  1406.   if (break_state == -1)
  1407. RegValue |= BIT3;
  1408. else
  1409. RegValue &= ~BIT3;
  1410. write_reg(info, CTL, RegValue);
  1411. spin_unlock_irqrestore(&info->lock,flags);
  1412. }
  1413. #ifdef CONFIG_SYNCLINK_SYNCPPP
  1414. /* syncppp support and callbacks */
  1415. static void sppp_init(SLMP_INFO *info)
  1416. {
  1417. struct net_device *d;
  1418. sprintf(info->netname,"mgslm%dp%d",info->adapter_num,info->port_num);
  1419. info->if_ptr = &info->pppdev;
  1420. info->netdev = info->pppdev.dev = &info->netdevice;
  1421. sppp_attach(&info->pppdev);
  1422. d = info->netdev;
  1423. strcpy(d->name,info->netname);
  1424. d->base_addr = 0;
  1425. d->irq = info->irq_level;
  1426. d->dma = 0;
  1427. d->priv = info;
  1428. d->init = NULL;
  1429. d->open = sppp_cb_open;
  1430. d->stop = sppp_cb_close;
  1431. d->hard_start_xmit = sppp_cb_tx;
  1432. d->do_ioctl = sppp_cb_ioctl;
  1433. d->get_stats = sppp_cb_net_stats;
  1434. d->tx_timeout = sppp_cb_tx_timeout;
  1435. d->watchdog_timeo = 10*HZ;
  1436. #if LINUX_VERSION_CODE < VERSION(2,4,4) 
  1437. dev_init_buffers(d);
  1438. #endif
  1439. if (register_netdev(d) == -1) {
  1440. printk(KERN_WARNING "%s: register_netdev failed.n", d->name);
  1441. sppp_detach(info->netdev);
  1442. return;
  1443. }
  1444. if (debug_level >= DEBUG_LEVEL_INFO)
  1445. printk("sppp_init(%s)n",info->netname);
  1446. }
  1447. static void sppp_delete(SLMP_INFO *info)
  1448. {
  1449. if (debug_level >= DEBUG_LEVEL_INFO)
  1450. printk("sppp_delete(%s)n",info->netname);
  1451. sppp_detach(info->netdev);
  1452. unregister_netdev(info->netdev);
  1453. }
  1454. static int sppp_cb_open(struct net_device *d)
  1455. {
  1456. SLMP_INFO *info = d->priv;
  1457. int err, flags;
  1458. if (debug_level >= DEBUG_LEVEL_INFO)
  1459. printk("sppp_cb_open(%s)n",info->netname);
  1460. spin_lock_irqsave(&info->netlock, flags);
  1461. if (info->count != 0 || info->netcount != 0) {
  1462. printk(KERN_WARNING "%s: sppp_cb_open returning busyn", info->netname);
  1463. spin_unlock_irqrestore(&info->netlock, flags);
  1464. return -EBUSY;
  1465. }
  1466. info->netcount=1;
  1467. MOD_INC_USE_COUNT;
  1468. spin_unlock_irqrestore(&info->netlock, flags);
  1469. /* claim resources and init adapter */
  1470. if ((err = startup(info)) != 0)
  1471. goto open_fail;
  1472. /* allow syncppp module to do open processing */
  1473. if ((err = sppp_open(d)) != 0) {
  1474. shutdown(info);
  1475. goto open_fail;
  1476. }
  1477. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  1478. program_hw(info);
  1479. d->trans_start = jiffies;
  1480. netif_start_queue(d);
  1481. return 0;
  1482. open_fail:
  1483. spin_lock_irqsave(&info->netlock, flags);
  1484. info->netcount=0;
  1485. MOD_DEC_USE_COUNT;
  1486. spin_unlock_irqrestore(&info->netlock, flags);
  1487. return err;
  1488. }
  1489. static void sppp_cb_tx_timeout(struct net_device *dev)
  1490. {
  1491. SLMP_INFO *info = dev->priv;
  1492. int flags;
  1493. if (debug_level >= DEBUG_LEVEL_INFO)
  1494. printk("sppp_tx_timeout(%s)n",info->netname);
  1495. info->netstats.tx_errors++;
  1496. info->netstats.tx_aborted_errors++;
  1497. spin_lock_irqsave(&info->lock,flags);
  1498. tx_stop(info);
  1499. spin_unlock_irqrestore(&info->lock,flags);
  1500. netif_wake_queue(dev);
  1501. }
  1502. static int sppp_cb_tx(struct sk_buff *skb, struct net_device *dev)
  1503. {
  1504. SLMP_INFO *info = dev->priv;
  1505. unsigned long flags;
  1506. if (debug_level >= DEBUG_LEVEL_INFO)
  1507. printk("sppp_tx(%s)n",info->netname);
  1508. netif_stop_queue(dev);
  1509. info->tx_count = skb->len;
  1510. tx_load_dma_buffer(info, skb->data, skb->len);
  1511. info->netstats.tx_packets++;
  1512. info->netstats.tx_bytes += skb->len;
  1513. dev_kfree_skb(skb);
  1514. dev->trans_start = jiffies;
  1515. spin_lock_irqsave(&info->lock,flags);
  1516. if (!info->tx_active)
  1517.   tx_start(info);
  1518. spin_unlock_irqrestore(&info->lock,flags);
  1519. return 0;
  1520. }
  1521. static int sppp_cb_close(struct net_device *d)
  1522. {
  1523. SLMP_INFO *info = d->priv;
  1524. unsigned long flags;
  1525. if (debug_level >= DEBUG_LEVEL_INFO)
  1526. printk("sppp_cb_close(%s)n",info->netname);
  1527. /* shutdown adapter and release resources */
  1528. shutdown(info);
  1529. /* allow syncppp to do close processing */
  1530. sppp_close(d);
  1531. netif_stop_queue(d);
  1532. spin_lock_irqsave(&info->netlock, flags);
  1533. info->netcount=0;
  1534. MOD_DEC_USE_COUNT;
  1535. spin_unlock_irqrestore(&info->netlock, flags);
  1536. return 0;
  1537. }
  1538. static void sppp_rx_done(SLMP_INFO *info, char *buf, int size)
  1539. {
  1540. struct sk_buff *skb = dev_alloc_skb(size);
  1541. if (debug_level >= DEBUG_LEVEL_INFO)
  1542. printk("sppp_rx_done(%s)n",info->netname);
  1543. if (skb == NULL) {
  1544. printk(KERN_NOTICE "%s: cant alloc skb, dropping packetn",
  1545. info->netname);
  1546. info->netstats.rx_dropped++;
  1547. return;
  1548. }
  1549. memcpy(skb_put(skb, size),buf,size);
  1550. skb->protocol = htons(ETH_P_WAN_PPP);
  1551. skb->dev = info->netdev;
  1552. skb->mac.raw = skb->data;
  1553. info->netstats.rx_packets++;
  1554. info->netstats.rx_bytes += size;
  1555. netif_rx(skb);
  1556. info->netdev->trans_start = jiffies;
  1557. }
  1558. static void sppp_tx_done(SLMP_INFO *info)
  1559. {
  1560. if (netif_queue_stopped(info->netdev))
  1561.     netif_wake_queue(info->netdev);
  1562. }
  1563. static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev)
  1564. {
  1565. SLMP_INFO *info = dev->priv;
  1566. if (debug_level >= DEBUG_LEVEL_INFO)
  1567. printk("net_stats(%s)n",info->netname);
  1568. return &info->netstats;
  1569. }
  1570. static int sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1571. {
  1572. SLMP_INFO *info = (SLMP_INFO *)dev->priv;
  1573. if (debug_level >= DEBUG_LEVEL_INFO)
  1574. printk("%s(%d):ioctl %s cmd=%08Xn", __FILE__,__LINE__,
  1575. info->netname, cmd );
  1576. return sppp_do_ioctl(dev, ifr, cmd);
  1577. }
  1578. #endif /* ifdef CONFIG_SYNCLINK_SYNCPPP */
  1579. /* Return next bottom half action to perform.
  1580.  * Return Value: BH action code or 0 if nothing to do.
  1581.  */
  1582. int bh_action(SLMP_INFO *info)
  1583. {
  1584. unsigned long flags;
  1585. int rc = 0;
  1586. spin_lock_irqsave(&info->lock,flags);
  1587. if (info->pending_bh & BH_RECEIVE) {
  1588. info->pending_bh &= ~BH_RECEIVE;
  1589. rc = BH_RECEIVE;
  1590. } else if (info->pending_bh & BH_TRANSMIT) {
  1591. info->pending_bh &= ~BH_TRANSMIT;
  1592. rc = BH_TRANSMIT;
  1593. } else if (info->pending_bh & BH_STATUS) {
  1594. info->pending_bh &= ~BH_STATUS;
  1595. rc = BH_STATUS;
  1596. }
  1597. if (!rc) {
  1598. /* Mark BH routine as complete */
  1599. info->bh_running   = 0;
  1600. info->bh_requested = 0;
  1601. }
  1602. spin_unlock_irqrestore(&info->lock,flags);
  1603. return rc;
  1604. }
  1605. /* Perform bottom half processing of work items queued by ISR.
  1606.  */
  1607. void bh_handler(void* Context)
  1608. {
  1609. SLMP_INFO *info = (SLMP_INFO*)Context;
  1610. int action;
  1611. if (!info)
  1612. return;
  1613. if ( debug_level >= DEBUG_LEVEL_BH )
  1614. printk( "%s(%d):%s bh_handler() entryn",
  1615. __FILE__,__LINE__,info->device_name);
  1616. info->bh_running = 1;
  1617. while((action = bh_action(info)) != 0) {
  1618. /* Process work item */
  1619. if ( debug_level >= DEBUG_LEVEL_BH )
  1620. printk( "%s(%d):%s bh_handler() work item action=%dn",
  1621. __FILE__,__LINE__,info->device_name, action);
  1622. switch (action) {
  1623. case BH_RECEIVE:
  1624. bh_receive(info);
  1625. break;
  1626. case BH_TRANSMIT:
  1627. bh_transmit(info);
  1628. break;
  1629. case BH_STATUS:
  1630. bh_status(info);
  1631. break;
  1632. default:
  1633. /* unknown work item ID */
  1634. printk("%s(%d):%s Unknown work item ID=%08X!n",
  1635. __FILE__,__LINE__,info->device_name,action);
  1636. break;
  1637. }
  1638. }
  1639. if ( debug_level >= DEBUG_LEVEL_BH )
  1640. printk( "%s(%d):%s bh_handler() exitn",
  1641. __FILE__,__LINE__,info->device_name);
  1642. }
  1643. void bh_receive(SLMP_INFO *info)
  1644. {
  1645. if ( debug_level >= DEBUG_LEVEL_BH )
  1646. printk( "%s(%d):%s bh_receive()n",
  1647. __FILE__,__LINE__,info->device_name);
  1648. while( rx_get_frame(info) );
  1649. }
  1650. void bh_transmit(SLMP_INFO *info)
  1651. {
  1652. struct tty_struct *tty = info->tty;
  1653. if ( debug_level >= DEBUG_LEVEL_BH )
  1654. printk( "%s(%d):%s bh_transmit() entryn",
  1655. __FILE__,__LINE__,info->device_name);
  1656. if (tty) {
  1657. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  1658.     tty->ldisc.write_wakeup) {
  1659. if ( debug_level >= DEBUG_LEVEL_BH )
  1660. printk( "%s(%d):%s calling ldisc.write_wakeupn",
  1661. __FILE__,__LINE__,info->device_name);
  1662. (tty->ldisc.write_wakeup)(tty);
  1663. }
  1664. wake_up_interruptible(&tty->write_wait);
  1665. }
  1666. }
  1667. void bh_status(SLMP_INFO *info)
  1668. {
  1669. if ( debug_level >= DEBUG_LEVEL_BH )
  1670. printk( "%s(%d):%s bh_status() entryn",
  1671. __FILE__,__LINE__,info->device_name);
  1672. info->ri_chkcount = 0;
  1673. info->dsr_chkcount = 0;
  1674. info->dcd_chkcount = 0;
  1675. info->cts_chkcount = 0;
  1676. }
  1677. void isr_timer(SLMP_INFO * info)
  1678. {
  1679. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  1680. /* IER2<7..4> = timer<3..0> interrupt enables (0=disabled) */
  1681. write_reg(info, IER2, 0);
  1682. /* TMCS, Timer Control/Status Register
  1683.  *
  1684.  * 07      CMF, Compare match flag (read only) 1=match
  1685.  * 06      ECMI, CMF Interrupt Enable: 0=disabled
  1686.  * 05      Reserved, must be 0
  1687.  * 04      TME, Timer Enable
  1688.  * 03..00  Reserved, must be 0
  1689.  *
  1690.  * 0000 0000
  1691.  */
  1692. write_reg(info, (unsigned char)(timer + TMCS), 0);
  1693. info->irq_occurred = TRUE;
  1694. if ( debug_level >= DEBUG_LEVEL_ISR )
  1695. printk("%s(%d):%s isr_timer()n",
  1696. __FILE__,__LINE__,info->device_name);
  1697. }
  1698. void isr_rxint(SLMP_INFO * info)
  1699. {
  1700.   struct tty_struct *tty = info->tty;
  1701.   struct mgsl_icount *icount = &info->icount;
  1702. unsigned char status = read_reg(info, SR1);
  1703. unsigned char status2 = read_reg(info, SR2);
  1704. /* clear status bits */
  1705. if ( status & (FLGD + IDLD + CDCD + BRKD) )
  1706. write_reg(info, SR1, 
  1707. (unsigned char)(status & (FLGD + IDLD + CDCD + BRKD)));
  1708. if ( status2 & OVRN )
  1709. write_reg(info, SR2, (unsigned char)(status2 & OVRN));
  1710. if ( debug_level >= DEBUG_LEVEL_ISR )
  1711. printk("%s(%d):%s isr_rxint status=%02X %02xn",
  1712. __FILE__,__LINE__,info->device_name,status,status2);
  1713. if (info->params.mode == MGSL_MODE_ASYNC) {
  1714. if (status & BRKD) {
  1715. icount->brk++;
  1716. /* process break detection if tty control
  1717.  * is not set to ignore it
  1718.  */
  1719. if ( tty ) {
  1720. if (!(status & info->ignore_status_mask1)) {
  1721. if (info->read_status_mask1 & BRKD) {
  1722. *tty->flip.flag_buf_ptr = TTY_BREAK;
  1723. if (info->flags & ASYNC_SAK)
  1724. do_SAK(tty);
  1725. }
  1726. }
  1727. }
  1728. }
  1729. }
  1730. else {
  1731. if (status & (FLGD|IDLD)) {
  1732. if (status & FLGD)
  1733. info->icount.exithunt++;
  1734. else if (status & IDLD)
  1735. info->icount.rxidle++;
  1736. wake_up_interruptible(&info->event_wait_q);
  1737. }
  1738. }
  1739. if (status & CDCD) {
  1740. /* simulate a common modem status change interrupt
  1741.  * for our handler
  1742.  */
  1743. get_signals( info );
  1744. isr_io_pin(info,
  1745. MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD));
  1746. }
  1747. }
  1748. /*
  1749.  * handle async rx data interrupts
  1750.  */
  1751. void isr_rxrdy(SLMP_INFO * info)
  1752. {
  1753. u16 status;
  1754. unsigned char DataByte;
  1755.   struct tty_struct *tty = info->tty;
  1756.   struct mgsl_icount *icount = &info->icount;
  1757. if ( debug_level >= DEBUG_LEVEL_ISR )
  1758. printk("%s(%d):%s isr_rxrdyn",
  1759. __FILE__,__LINE__,info->device_name);
  1760. while((status = read_reg(info,CST0)) & BIT0)
  1761. {
  1762. DataByte = read_reg(info,TRB);
  1763. if ( tty ) {
  1764. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  1765. continue;
  1766. *tty->flip.char_buf_ptr = DataByte;
  1767. *tty->flip.flag_buf_ptr = 0;
  1768. }
  1769. icount->rx++;
  1770. if ( status & (PE + FRME + OVRN) ) {
  1771. printk("%s(%d):%s rxerr=%04Xn",
  1772. __FILE__,__LINE__,info->device_name,status);
  1773. /* update error statistics */
  1774. if (status & PE)
  1775. icount->parity++;
  1776. else if (status & FRME)
  1777. icount->frame++;
  1778. else if (status & OVRN)
  1779. icount->overrun++;
  1780. /* discard char if tty control flags say so */
  1781. if (status & info->ignore_status_mask2)
  1782. continue;
  1783. status &= info->read_status_mask2;
  1784. if ( tty ) {
  1785. if (status & PE)
  1786. *tty->flip.flag_buf_ptr = TTY_PARITY;
  1787. else if (status & FRME)
  1788. *tty->flip.flag_buf_ptr = TTY_FRAME;
  1789. if (status & OVRN) {
  1790. /* Overrun is special, since it's
  1791.  * reported immediately, and doesn't
  1792.  * affect the current character
  1793.  */
  1794. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  1795. tty->flip.count++;
  1796. tty->flip.flag_buf_ptr++;
  1797. tty->flip.char_buf_ptr++;
  1798. *tty->flip.flag_buf_ptr = TTY_OVERRUN;
  1799. }
  1800. }
  1801. }
  1802. } /* end of if (error) */
  1803. if ( tty ) {
  1804. tty->flip.flag_buf_ptr++;
  1805. tty->flip.char_buf_ptr++;
  1806. tty->flip.count++;
  1807. }
  1808. }
  1809. if ( debug_level >= DEBUG_LEVEL_ISR ) {
  1810. printk("%s(%d):%s isr_rxrdy() flip count=%dn",
  1811. __FILE__,__LINE__,info->device_name,
  1812. tty ? tty->flip.count : 0);
  1813. printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%dn",
  1814. __FILE__,__LINE__,info->device_name,
  1815. icount->rx,icount->brk,icount->parity,
  1816. icount->frame,icount->overrun);
  1817. }
  1818. if ( tty && tty->flip.count )
  1819. tty_flip_buffer_push(tty);
  1820. }
  1821. void isr_txeom(SLMP_INFO * info, unsigned char status)
  1822. {
  1823. if ( debug_level >= DEBUG_LEVEL_ISR )
  1824. printk("%s(%d):%s isr_txeom status=%02xn",
  1825. __FILE__,__LINE__,info->device_name,status);
  1826. /* disable and clear MSCI interrupts */
  1827. info->ie1_value &= ~(IDLE + UDRN);
  1828. write_reg(info, IE1, info->ie1_value);
  1829. write_reg(info, SR1, (unsigned char)(UDRN + IDLE));
  1830. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  1831. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  1832. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  1833. if ( info->tx_active ) {
  1834. if (info->params.mode != MGSL_MODE_ASYNC) {
  1835. if (status & UDRN)
  1836. info->icount.txunder++;
  1837. else if (status & IDLE)
  1838. info->icount.txok++;
  1839. }
  1840. info->tx_active = 0;
  1841. info->tx_count = info->tx_put = info->tx_get = 0;
  1842. del_timer(&info->tx_timer);
  1843. if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done ) {
  1844. info->serial_signals &= ~SerialSignal_RTS;
  1845. info->drop_rts_on_tx_done = 0;
  1846. set_signals(info);
  1847. }
  1848. #ifdef CONFIG_SYNCLINK_SYNCPPP
  1849. if (info->netcount)
  1850. sppp_tx_done(info);
  1851. else
  1852. #endif
  1853. {
  1854. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  1855. tx_stop(info);
  1856. return;
  1857. }
  1858. info->pending_bh |= BH_TRANSMIT;
  1859. }
  1860. }
  1861. }
  1862. /*
  1863.  * handle tx status interrupts
  1864.  */
  1865. void isr_txint(SLMP_INFO * info)
  1866. {
  1867. unsigned char status = read_reg(info, SR1);
  1868. /* clear status bits */
  1869. write_reg(info, SR1, (unsigned char)(status & (UDRN + IDLE + CCTS)));
  1870. if ( debug_level >= DEBUG_LEVEL_ISR )
  1871. printk("%s(%d):%s isr_txint status=%02xn",
  1872. __FILE__,__LINE__,info->device_name,status);
  1873. if (status & (UDRN + IDLE))
  1874. isr_txeom(info, status);
  1875. if (status & CCTS) {
  1876. /* simulate a common modem status change interrupt
  1877.  * for our handler
  1878.  */
  1879. get_signals( info );
  1880. isr_io_pin(info,
  1881. MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS));
  1882. }
  1883. }
  1884. /*
  1885.  * handle async tx data interrupts
  1886.  */
  1887. void isr_txrdy(SLMP_INFO * info)
  1888. {
  1889. if ( debug_level >= DEBUG_LEVEL_ISR )
  1890. printk("%s(%d):%s isr_txrdy() tx_count=%dn",
  1891. __FILE__,__LINE__,info->device_name,info->tx_count);
  1892. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  1893. tx_stop(info);
  1894. return;
  1895. }
  1896. if ( info->tx_count )
  1897. tx_load_fifo( info );
  1898. else {
  1899. info->tx_active = 0;
  1900. info->ie0_value &= ~TXRDYE;
  1901. write_reg(info, IE0, info->ie0_value);
  1902. }
  1903. if (info->tx_count < WAKEUP_CHARS)
  1904. info->pending_bh |= BH_TRANSMIT;
  1905. }
  1906. void isr_rxdmaok(SLMP_INFO * info)
  1907. {
  1908. /* BIT7 = EOT (end of transfer)
  1909.  * BIT6 = EOM (end of message/frame)
  1910.  */
  1911. unsigned char status = read_reg(info,RXDMA + DSR) & 0xc0;
  1912. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  1913. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  1914. if ( debug_level >= DEBUG_LEVEL_ISR )
  1915. printk("%s(%d):%s isr_rxdmaok(), status=%02xn",
  1916. __FILE__,__LINE__,info->device_name,status);
  1917. info->pending_bh |= BH_RECEIVE;
  1918. }
  1919. void isr_rxdmaerror(SLMP_INFO * info)
  1920. {
  1921. /* BIT5 = BOF (buffer overflow)
  1922.  * BIT4 = COF (counter overflow)
  1923.  */
  1924. unsigned char status = read_reg(info,RXDMA + DSR) & 0x30;
  1925. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  1926. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  1927. if ( debug_level >= DEBUG_LEVEL_ISR )
  1928. printk("%s(%d):%s isr_rxdmaerror(), status=%02xn",
  1929. __FILE__,__LINE__,info->device_name,status);
  1930. info->rx_overflow = TRUE;
  1931. info->pending_bh |= BH_RECEIVE;
  1932. }
  1933. void isr_txdmaok(SLMP_INFO * info)
  1934. {
  1935. /* BIT7 = EOT (end of transfer, used for async mode)
  1936.  * BIT6 = EOM (end of message/frame, used for sync mode)
  1937.  *
  1938.  * We don't look at DMA status because only EOT is enabled
  1939.  * and we always clear and disable all tx DMA IRQs.
  1940.  */
  1941. // unsigned char dma_status = read_reg(info,TXDMA + DSR) & 0xc0;
  1942. unsigned char status_reg1 = read_reg(info, SR1);
  1943. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  1944. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  1945. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  1946. if ( debug_level >= DEBUG_LEVEL_ISR )
  1947. printk("%s(%d):%s isr_txdmaok(), status=%02xn",
  1948. __FILE__,__LINE__,info->device_name,status_reg1);
  1949. /* If transmitter already idle, do end of frame processing,
  1950.  * otherwise enable interrupt for tx IDLE.
  1951.  */
  1952. if (status_reg1 & IDLE)
  1953. isr_txeom(info, IDLE);
  1954. else {
  1955. /* disable and clear underrun IRQ, enable IDLE interrupt */
  1956. info->ie1_value |= IDLE;
  1957. info->ie1_value &= ~UDRN;
  1958. write_reg(info, IE1, info->ie1_value);
  1959. write_reg(info, SR1, UDRN);
  1960. }
  1961. }
  1962. void isr_txdmaerror(SLMP_INFO * info)
  1963. {
  1964. /* BIT5 = BOF (buffer overflow)
  1965.  * BIT4 = COF (counter overflow)
  1966.  */
  1967. unsigned char status = read_reg(info,TXDMA + DSR) & 0x30;
  1968. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  1969. write_reg(info, TXDMA + DSR, (unsigned char)(status | 1));
  1970. if ( debug_level >= DEBUG_LEVEL_ISR )
  1971. printk("%s(%d):%s isr_txdmaerror(), status=%02xn",
  1972. __FILE__,__LINE__,info->device_name,status);
  1973. }
  1974. /* handle input serial signal changes
  1975.  */
  1976. void isr_io_pin( SLMP_INFO *info, u16 status )
  1977. {
  1978.   struct mgsl_icount *icount;
  1979. if ( debug_level >= DEBUG_LEVEL_ISR )
  1980. printk("%s(%d):isr_io_pin status=%04Xn",
  1981. __FILE__,__LINE__,status);
  1982. if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
  1983.               MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
  1984. icount = &info->icount;
  1985. /* update input line counters */
  1986. if (status & MISCSTATUS_RI_LATCHED) {
  1987. icount->rng++;
  1988. if ( status & SerialSignal_RI )
  1989. info->input_signal_events.ri_up++;
  1990. else
  1991. info->input_signal_events.ri_down++;
  1992. }
  1993. if (status & MISCSTATUS_DSR_LATCHED) {
  1994. icount->dsr++;
  1995. if ( status & SerialSignal_DSR )
  1996. info->input_signal_events.dsr_up++;
  1997. else
  1998. info->input_signal_events.dsr_down++;
  1999. }
  2000. if (status & MISCSTATUS_DCD_LATCHED) {
  2001. if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2002. info->ie1_value &= ~CDCD;
  2003. write_reg(info, IE1, info->ie1_value);
  2004. }
  2005. icount->dcd++;
  2006. if (status & SerialSignal_DCD) {
  2007. info->input_signal_events.dcd_up++;
  2008. #ifdef CONFIG_SYNCLINK_SYNCPPP
  2009. if (info->netcount)
  2010. sppp_reopen(info->netdev);
  2011. #endif
  2012. } else
  2013. info->input_signal_events.dcd_down++;
  2014. }
  2015. if (status & MISCSTATUS_CTS_LATCHED)
  2016. {
  2017. if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2018. info->ie1_value &= ~CCTS;
  2019. write_reg(info, IE1, info->ie1_value);
  2020. }
  2021. icount->cts++;
  2022. if ( status & SerialSignal_CTS )
  2023. info->input_signal_events.cts_up++;
  2024. else
  2025. info->input_signal_events.cts_down++;
  2026. }
  2027. wake_up_interruptible(&info->status_event_wait_q);
  2028. wake_up_interruptible(&info->event_wait_q);
  2029. if ( (info->flags & ASYNC_CHECK_CD) &&
  2030.      (status & MISCSTATUS_DCD_LATCHED) ) {
  2031. if ( debug_level >= DEBUG_LEVEL_ISR )
  2032. printk("%s CD now %s...", info->device_name,
  2033.        (status & SerialSignal_DCD) ? "on" : "off");
  2034. if (status & SerialSignal_DCD)
  2035. wake_up_interruptible(&info->open_wait);
  2036. else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
  2037.    (info->flags & ASYNC_CALLOUT_NOHUP))) {
  2038. if ( debug_level >= DEBUG_LEVEL_ISR )
  2039. printk("doing serial hangup...");
  2040. if (info->tty)
  2041. tty_hangup(info->tty);
  2042. }
  2043. }
  2044. if ( (info->flags & ASYNC_CTS_FLOW) &&
  2045.      (status & MISCSTATUS_CTS_LATCHED) ) {
  2046. if ( info->tty ) {
  2047. if (info->tty->hw_stopped) {
  2048. if (status & SerialSignal_CTS) {
  2049. if ( debug_level >= DEBUG_LEVEL_ISR )
  2050. printk("CTS tx start...");
  2051.   info->tty->hw_stopped = 0;
  2052. tx_start(info);
  2053. info->pending_bh |= BH_TRANSMIT;
  2054. return;
  2055. }
  2056. } else {
  2057. if (!(status & SerialSignal_CTS)) {
  2058. if ( debug_level >= DEBUG_LEVEL_ISR )
  2059. printk("CTS tx stop...");
  2060.   info->tty->hw_stopped = 1;
  2061. tx_stop(info);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. }
  2067. info->pending_bh |= BH_STATUS;
  2068. }
  2069. /* Interrupt service routine entry point.
  2070.  *
  2071.  * Arguments:
  2072.  *  irq interrupt number that caused interrupt
  2073.  *  dev_id device ID supplied during interrupt registration
  2074.  *  regs interrupted processor context
  2075.  */
  2076. static void synclinkmp_interrupt(int irq, void *dev_id, struct pt_regs * regs)
  2077. {
  2078. SLMP_INFO * info;
  2079. unsigned char status, status0, status1=0;
  2080. unsigned char dmastatus, dmastatus0, dmastatus1=0;
  2081. unsigned char timerstatus0, timerstatus1=0;
  2082. unsigned char shift;
  2083. unsigned int i;
  2084. unsigned short tmp;
  2085. if ( debug_level >= DEBUG_LEVEL_ISR )
  2086. printk("%s(%d): synclinkmp_interrupt(%d)entry.n",
  2087. __FILE__,__LINE__,irq);
  2088. info = (SLMP_INFO *)dev_id;
  2089. if (!info)
  2090. return;
  2091. spin_lock(&info->lock);
  2092. for(;;) {
  2093. /* get status for SCA0 (ports 0-1) */
  2094. tmp = read_reg16(info, ISR0); /* get ISR0 and ISR1 in one read */
  2095. status0 = (unsigned char)tmp;
  2096. dmastatus0 = (unsigned char)(tmp>>8);
  2097. timerstatus0 = read_reg(info, ISR2);
  2098. if ( debug_level >= DEBUG_LEVEL_ISR )
  2099. printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02xn",
  2100. __FILE__,__LINE__,info->device_name,
  2101. status0,dmastatus0,timerstatus0);
  2102. if (info->port_count == 4) {
  2103. /* get status for SCA1 (ports 2-3) */
  2104. tmp = read_reg16(info->port_array[2], ISR0);
  2105. status1 = (unsigned char)tmp;
  2106. dmastatus1 = (unsigned char)(tmp>>8);
  2107. timerstatus1 = read_reg(info->port_array[2], ISR2);
  2108. if ( debug_level >= DEBUG_LEVEL_ISR )
  2109. printk("%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02xn",
  2110. __FILE__,__LINE__,info->device_name,
  2111. status1,dmastatus1,timerstatus1);
  2112. }
  2113. if (!status0 && !dmastatus0 && !timerstatus0 &&
  2114.  !status1 && !dmastatus1 && !timerstatus1)
  2115. break;
  2116. for(i=0; i < info->port_count ; i++) {
  2117. if (info->port_array[i] == NULL)
  2118. continue;
  2119. if (i < 2) {
  2120. status = status0;
  2121. dmastatus = dmastatus0;
  2122. } else {
  2123. status = status1;
  2124. dmastatus = dmastatus1;
  2125. }
  2126. shift = i & 1 ? 4 :0;
  2127. if (status & BIT0 << shift)
  2128. isr_rxrdy(info->port_array[i]);
  2129. if (status & BIT1 << shift)
  2130. isr_txrdy(info->port_array[i]);
  2131. if (status & BIT2 << shift)
  2132. isr_rxint(info->port_array[i]);
  2133. if (status & BIT3 << shift)
  2134. isr_txint(info->port_array[i]);
  2135. if (dmastatus & BIT0 << shift)
  2136. isr_rxdmaerror(info->port_array[i]);
  2137. if (dmastatus & BIT1 << shift)
  2138. isr_rxdmaok(info->port_array[i]);
  2139. if (dmastatus & BIT2 << shift)
  2140. isr_txdmaerror(info->port_array[i]);
  2141. if (dmastatus & BIT3 << shift)
  2142. isr_txdmaok(info->port_array[i]);
  2143. }
  2144. if (timerstatus0 & (BIT5 | BIT4))
  2145. isr_timer(info->port_array[0]);
  2146. if (timerstatus0 & (BIT7 | BIT6))
  2147. isr_timer(info->port_array[1]);
  2148. if (timerstatus1 & (BIT5 | BIT4))
  2149. isr_timer(info->port_array[2]);
  2150. if (timerstatus1 & (BIT7 | BIT6))
  2151. isr_timer(info->port_array[3]);
  2152. }
  2153. for(i=0; i < info->port_count ; i++) {
  2154. SLMP_INFO * port = info->port_array[i];
  2155. /* Request bottom half processing if there's something
  2156.  * for it to do and the bh is not already running.
  2157.  *
  2158.  * Note: startup adapter diags require interrupts.
  2159.  * do not request bottom half processing if the
  2160.  * device is not open in a normal mode.
  2161.  */
  2162. if ( port && (port->count || port->netcount) &&
  2163.      port->pending_bh && !port->bh_running &&
  2164.      !port->bh_requested ) {
  2165. if ( debug_level >= DEBUG_LEVEL_ISR )
  2166. printk("%s(%d):%s queueing bh task.n",
  2167. __FILE__,__LINE__,port->device_name);
  2168. queue_task(&port->task, &tq_immediate);
  2169. mark_bh(IMMEDIATE_BH);
  2170. port->bh_requested = 1;
  2171. }
  2172. }
  2173. spin_unlock(&info->lock);
  2174. if ( debug_level >= DEBUG_LEVEL_ISR )
  2175. printk("%s(%d):synclinkmp_interrupt(%d)exit.n",
  2176. __FILE__,__LINE__,irq);
  2177. }
  2178. /* Initialize and start device.
  2179.  */
  2180. static int startup(SLMP_INFO * info)
  2181. {
  2182. if ( debug_level >= DEBUG_LEVEL_INFO )
  2183. printk("%s(%d):%s tx_releaseup()n",__FILE__,__LINE__,info->device_name);
  2184. if (info->flags & ASYNC_INITIALIZED)
  2185. return 0;
  2186. if (!info->tx_buf) {
  2187. info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
  2188. if (!info->tx_buf) {
  2189. printk(KERN_ERR"%s(%d):%s can't allocate transmit buffern",
  2190. __FILE__,__LINE__,info->device_name);
  2191. return -ENOMEM;
  2192. }
  2193. }
  2194. info->pending_bh = 0;
  2195. init_timer(&info->tx_timer);
  2196. info->tx_timer.data = (unsigned long)info;
  2197. info->tx_timer.function = tx_timeout;
  2198. /* program hardware for current parameters */
  2199. reset_port(info);
  2200. change_params(info);
  2201. init_timer(&info->status_timer);
  2202. info->status_timer.data = (unsigned long)info;
  2203. info->status_timer.function = status_timeout;
  2204. info->status_timer.expires = jiffies + jiffies_from_ms(10);
  2205. add_timer(&info->status_timer);
  2206. if (info->tty)
  2207. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  2208. info->flags |= ASYNC_INITIALIZED;
  2209. return 0;
  2210. }
  2211. /* Called by close() and hangup() to shutdown hardware
  2212.  */
  2213. static void shutdown(SLMP_INFO * info)
  2214. {
  2215. unsigned long flags;
  2216. if (!(info->flags & ASYNC_INITIALIZED))
  2217. return;
  2218. if (debug_level >= DEBUG_LEVEL_INFO)
  2219. printk("%s(%d):%s synclinkmp_shutdown()n",
  2220.  __FILE__,__LINE__, info->device_name );
  2221. /* clear status wait queue because status changes */
  2222. /* can't happen after shutting down the hardware */
  2223. wake_up_interruptible(&info->status_event_wait_q);
  2224. wake_up_interruptible(&info->event_wait_q);
  2225. del_timer(&info->tx_timer);
  2226. del_timer(&info->status_timer);
  2227. if (info->tx_buf) {
  2228. free_page((unsigned long) info->tx_buf);
  2229. info->tx_buf = 0;
  2230. }
  2231. spin_lock_irqsave(&info->lock,flags);
  2232. reset_port(info);
  2233.   if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
  2234.   info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  2235. set_signals(info);
  2236. }
  2237. spin_unlock_irqrestore(&info->lock,flags);
  2238. if (info->tty)
  2239. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2240. info->flags &= ~ASYNC_INITIALIZED;
  2241. }
  2242. static void program_hw(SLMP_INFO *info)
  2243. {
  2244. unsigned long flags;
  2245. spin_lock_irqsave(&info->lock,flags);
  2246. rx_stop(info);
  2247. tx_stop(info);
  2248. info->tx_count = info->tx_put = info->tx_get = 0;
  2249. if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
  2250. hdlc_mode(info);
  2251. else
  2252. async_mode(info);
  2253. set_signals(info);
  2254. info->dcd_chkcount = 0;
  2255. info->cts_chkcount = 0;
  2256. info->ri_chkcount = 0;
  2257. info->dsr_chkcount = 0;
  2258. info->ie1_value |= (CDCD|CCTS);
  2259. write_reg(info, IE1, info->ie1_value);
  2260. get_signals(info);
  2261. if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
  2262. rx_start(info);
  2263. spin_unlock_irqrestore(&info->lock,flags);
  2264. }
  2265. /* Reconfigure adapter based on new parameters
  2266.  */
  2267. static void change_params(SLMP_INFO *info)
  2268. {
  2269. unsigned cflag;
  2270. int bits_per_char;
  2271. if (!info->tty || !info->tty->termios)
  2272. return;
  2273. if (debug_level >= DEBUG_LEVEL_INFO)
  2274. printk("%s(%d):%s change_params()n",
  2275.  __FILE__,__LINE__, info->device_name );
  2276. cflag = info->tty->termios->c_cflag;
  2277. /* if B0 rate (hangup) specified then negate DTR and RTS */
  2278. /* otherwise assert DTR and RTS */
  2279.   if (cflag & CBAUD)
  2280. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2281. else
  2282. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  2283. /* byte size and parity */
  2284. switch (cflag & CSIZE) {
  2285.       case CS5: info->params.data_bits = 5; break;
  2286.       case CS6: info->params.data_bits = 6; break;
  2287.       case CS7: info->params.data_bits = 7; break;
  2288.       case CS8: info->params.data_bits = 8; break;
  2289.       /* Never happens, but GCC is too dumb to figure it out */
  2290.       default:  info->params.data_bits = 7; break;
  2291.       }
  2292. if (cflag & CSTOPB)
  2293. info->params.stop_bits = 2;
  2294. else
  2295. info->params.stop_bits = 1;
  2296. info->params.parity = ASYNC_PARITY_NONE;
  2297. if (cflag & PARENB) {
  2298. if (cflag & PARODD)
  2299. info->params.parity = ASYNC_PARITY_ODD;
  2300. else
  2301. info->params.parity = ASYNC_PARITY_EVEN;
  2302. #ifdef CMSPAR
  2303. if (cflag & CMSPAR)
  2304. info->params.parity = ASYNC_PARITY_SPACE;
  2305. #endif
  2306. }
  2307. /* calculate number of jiffies to transmit a full
  2308.  * FIFO (32 bytes) at specified data rate
  2309.  */
  2310. bits_per_char = info->params.data_bits +
  2311. info->params.stop_bits + 1;
  2312. /* if port data rate is set to 460800 or less then
  2313.  * allow tty settings to override, otherwise keep the
  2314.  * current data rate.
  2315.  */
  2316. if (info->params.data_rate <= 460800) {
  2317. info->params.data_rate = tty_get_baud_rate(info->tty);
  2318. }
  2319. if ( info->params.data_rate ) {
  2320. info->timeout = (32*HZ*bits_per_char) /
  2321. info->params.data_rate;
  2322. }
  2323. info->timeout += HZ/50; /* Add .02 seconds of slop */
  2324. if (cflag & CRTSCTS)
  2325. info->flags |= ASYNC_CTS_FLOW;
  2326. else
  2327. info->flags &= ~ASYNC_CTS_FLOW;
  2328. if (cflag & CLOCAL)
  2329. info->flags &= ~ASYNC_CHECK_CD;
  2330. else
  2331. info->flags |= ASYNC_CHECK_CD;
  2332. /* process tty input control flags */
  2333. info->read_status_mask2 = OVRN;
  2334. if (I_INPCK(info->tty))
  2335. info->read_status_mask2 |= PE | FRME;
  2336.   if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  2337.   info->read_status_mask1 |= BRKD;
  2338. if (I_IGNPAR(info->tty))
  2339. info->ignore_status_mask2 |= PE | FRME;
  2340. if (I_IGNBRK(info->tty)) {
  2341. info->ignore_status_mask1 |= BRKD;
  2342. /* If ignoring parity and break indicators, ignore
  2343.  * overruns too.  (For real raw support).
  2344.  */
  2345. if (I_IGNPAR(info->tty))