Lines Matching full:info
41 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (b… argument
42 /*#define DBGTBUF(info) dump_tbufs(info)*/
43 /*#define DBGRBUF(info) dump_rbufs(info)*/
166 static void hdlcdev_tx_done(struct slgt_info *info);
167 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size);
168 static int hdlcdev_init(struct slgt_info *info);
169 static void hdlcdev_exit(struct slgt_info *info);
426 #define slgt_irq_on(info, mask) \ argument
427 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
428 #define slgt_irq_off(info, mask) \ argument
429 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
431 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
432 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
433 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
434 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
435 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
436 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
438 static void msc_set_vcr(struct slgt_info *info);
440 static int startup(struct slgt_info *info);
441 static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
442 static void shutdown(struct slgt_info *info);
443 static void program_hw(struct slgt_info *info);
444 static void change_params(struct slgt_info *info);
446 static int register_test(struct slgt_info *info);
447 static int irq_test(struct slgt_info *info);
448 static int loopback_test(struct slgt_info *info);
449 static int adapter_test(struct slgt_info *info);
451 static void reset_adapter(struct slgt_info *info);
452 static void reset_port(struct slgt_info *info);
453 static void async_mode(struct slgt_info *info);
454 static void sync_mode(struct slgt_info *info);
456 static void rx_stop(struct slgt_info *info);
457 static void rx_start(struct slgt_info *info);
458 static void reset_rbufs(struct slgt_info *info);
459 static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
460 static void rdma_reset(struct slgt_info *info);
461 static bool rx_get_frame(struct slgt_info *info);
462 static bool rx_get_buf(struct slgt_info *info);
464 static void tx_start(struct slgt_info *info);
465 static void tx_stop(struct slgt_info *info);
466 static void tx_set_idle(struct slgt_info *info);
467 static unsigned int free_tbuf_count(struct slgt_info *info);
468 static unsigned int tbuf_bytes(struct slgt_info *info);
469 static void reset_tbufs(struct slgt_info *info);
470 static void tdma_reset(struct slgt_info *info);
471 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
473 static void get_signals(struct slgt_info *info);
474 static void set_signals(struct slgt_info *info);
475 static void enable_loopback(struct slgt_info *info);
476 static void set_rate(struct slgt_info *info, u32 data_rate);
478 static int bh_action(struct slgt_info *info);
480 static void bh_transmit(struct slgt_info *info);
481 static void isr_serial(struct slgt_info *info);
482 static void isr_rdma(struct slgt_info *info);
483 static void isr_txeom(struct slgt_info *info, unsigned short status);
484 static void isr_tdma(struct slgt_info *info);
486 static int alloc_dma_bufs(struct slgt_info *info);
487 static void free_dma_bufs(struct slgt_info *info);
488 static int alloc_desc(struct slgt_info *info);
489 static void free_desc(struct slgt_info *info);
490 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count);
491 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count);
493 static int alloc_tmp_rbuf(struct slgt_info *info);
494 static void free_tmp_rbuf(struct slgt_info *info);
502 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
503 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
504 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
505 static int get_txidle(struct slgt_info *info, int __user *idle_mode);
506 static int set_txidle(struct slgt_info *info, int idle_mode);
507 static int tx_enable(struct slgt_info *info, int enable);
508 static int tx_abort(struct slgt_info *info);
509 static int rx_enable(struct slgt_info *info, int enable);
510 static int modem_input_wait(struct slgt_info *info,int arg);
511 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
516 static int get_interface(struct slgt_info *info, int __user *if_mode);
517 static int set_interface(struct slgt_info *info, int if_mode);
518 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
519 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
520 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
521 static int get_xsync(struct slgt_info *info, int __user *if_mode);
522 static int set_xsync(struct slgt_info *info, int if_mode);
523 static int get_xctrl(struct slgt_info *info, int __user *if_mode);
524 static int set_xctrl(struct slgt_info *info, int if_mode);
529 static void add_device(struct slgt_info *info);
531 static int claim_resources(struct slgt_info *info);
532 static void release_resources(struct slgt_info *info);
551 static void trace_block(struct slgt_info *info, const char *data, int count, const char *label) in trace_block() argument
555 printk("%s %s data:\n",info->device_name, label); in trace_block()
574 #define DBGDATA(info, buf, size, label) argument
578 static void dump_tbufs(struct slgt_info *info) in dump_tbufs() argument
581 printk("tbuf_current=%d\n", info->tbuf_current); in dump_tbufs()
582 for (i=0 ; i < info->tbuf_count ; i++) { in dump_tbufs()
584 i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status)); in dump_tbufs()
588 #define DBGTBUF(info) argument
592 static void dump_rbufs(struct slgt_info *info) in dump_rbufs() argument
595 printk("rbuf_current=%d\n", info->rbuf_current); in dump_rbufs()
596 for (i=0 ; i < info->rbuf_count ; i++) { in dump_rbufs()
598 i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status)); in dump_rbufs()
602 #define DBGRBUF(info) argument
605 static inline int sanity_check(struct slgt_info *info, char *devname, const char *name) in sanity_check() argument
608 if (!info) { in sanity_check()
612 if (info->magic != MGSL_MAGIC) { in sanity_check()
617 if (!info) in sanity_check()
649 struct slgt_info *info; in open() local
659 info = slgt_device_list; in open()
660 while(info && info->line != line) in open()
661 info = info->next_device; in open()
662 if (sanity_check(info, tty->name, "open")) in open()
664 if (info->init_error) { in open()
665 DBGERR(("%s init error=%d\n", info->device_name, info->init_error)); in open()
669 tty->driver_data = info; in open()
670 info->port.tty = tty; in open()
672 DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count)); in open()
674 mutex_lock(&info->port.mutex); in open()
675 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; in open()
677 spin_lock_irqsave(&info->netlock, flags); in open()
678 if (info->netcount) { in open()
680 spin_unlock_irqrestore(&info->netlock, flags); in open()
681 mutex_unlock(&info->port.mutex); in open()
684 info->port.count++; in open()
685 spin_unlock_irqrestore(&info->netlock, flags); in open()
687 if (info->port.count == 1) { in open()
689 retval = startup(info); in open()
691 mutex_unlock(&info->port.mutex); in open()
695 mutex_unlock(&info->port.mutex); in open()
696 retval = block_til_ready(tty, filp, info); in open()
698 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); in open()
707 info->port.tty = NULL; /* tty layer will release tty struct */ in open()
708 if(info->port.count) in open()
709 info->port.count--; in open()
712 DBGINFO(("%s open rc=%d\n", info->device_name, retval)); in open()
718 struct slgt_info *info = tty->driver_data; in close() local
720 if (sanity_check(info, tty->name, "close")) in close()
722 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); in close()
724 if (tty_port_close_start(&info->port, tty, filp) == 0) in close()
727 mutex_lock(&info->port.mutex); in close()
728 if (tty_port_initialized(&info->port)) in close()
729 wait_until_sent(tty, info->timeout); in close()
733 shutdown(info); in close()
734 mutex_unlock(&info->port.mutex); in close()
736 tty_port_close_end(&info->port, tty); in close()
737 info->port.tty = NULL; in close()
739 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); in close()
744 struct slgt_info *info = tty->driver_data; in hangup() local
747 if (sanity_check(info, tty->name, "hangup")) in hangup()
749 DBGINFO(("%s hangup\n", info->device_name)); in hangup()
753 mutex_lock(&info->port.mutex); in hangup()
754 shutdown(info); in hangup()
756 spin_lock_irqsave(&info->port.lock, flags); in hangup()
757 info->port.count = 0; in hangup()
758 info->port.tty = NULL; in hangup()
759 spin_unlock_irqrestore(&info->port.lock, flags); in hangup()
760 tty_port_set_active(&info->port, 0); in hangup()
761 mutex_unlock(&info->port.mutex); in hangup()
763 wake_up_interruptible(&info->port.open_wait); in hangup()
768 struct slgt_info *info = tty->driver_data; in set_termios() local
773 change_params(info); in set_termios()
777 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in set_termios()
778 spin_lock_irqsave(&info->lock,flags); in set_termios()
779 set_signals(info); in set_termios()
780 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
785 info->signals |= SerialSignal_DTR; in set_termios()
787 info->signals |= SerialSignal_RTS; in set_termios()
788 spin_lock_irqsave(&info->lock,flags); in set_termios()
789 set_signals(info); in set_termios()
790 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
800 static void update_tx_timer(struct slgt_info *info) in update_tx_timer() argument
806 if (info->params.mode == MGSL_MODE_HDLC) { in update_tx_timer()
807 int timeout = (tbuf_bytes(info) * 7) + 1000; in update_tx_timer()
808 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout)); in update_tx_timer()
816 struct slgt_info *info = tty->driver_data; in write() local
819 if (sanity_check(info, tty->name, "write")) in write()
822 DBGINFO(("%s write count=%d\n", info->device_name, count)); in write()
824 if (!info->tx_buf || (count > info->max_frame_size)) in write()
830 spin_lock_irqsave(&info->lock, flags); in write()
832 if (info->tx_count) { in write()
834 if (!tx_load(info, info->tx_buf, info->tx_count)) in write()
836 info->tx_count = 0; in write()
839 if (tx_load(info, buf, count)) in write()
843 spin_unlock_irqrestore(&info->lock, flags); in write()
844 DBGINFO(("%s write rc=%d\n", info->device_name, ret)); in write()
850 struct slgt_info *info = tty->driver_data; in put_char() local
854 if (sanity_check(info, tty->name, "put_char")) in put_char()
856 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); in put_char()
857 if (!info->tx_buf) in put_char()
859 spin_lock_irqsave(&info->lock,flags); in put_char()
860 if (info->tx_count < info->max_frame_size) { in put_char()
861 info->tx_buf[info->tx_count++] = ch; in put_char()
864 spin_unlock_irqrestore(&info->lock,flags); in put_char()
870 struct slgt_info *info = tty->driver_data; in send_xchar() local
873 if (sanity_check(info, tty->name, "send_xchar")) in send_xchar()
875 DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch)); in send_xchar()
876 info->x_char = ch; in send_xchar()
878 spin_lock_irqsave(&info->lock,flags); in send_xchar()
879 if (!info->tx_enabled) in send_xchar()
880 tx_start(info); in send_xchar()
881 spin_unlock_irqrestore(&info->lock,flags); in send_xchar()
887 struct slgt_info *info = tty->driver_data; in wait_until_sent() local
890 if (!info ) in wait_until_sent()
892 if (sanity_check(info, tty->name, "wait_until_sent")) in wait_until_sent()
894 DBGINFO(("%s wait_until_sent entry\n", info->device_name)); in wait_until_sent()
895 if (!tty_port_initialized(&info->port)) in wait_until_sent()
906 if (info->params.data_rate) { in wait_until_sent()
907 char_time = info->timeout/(32 * 5); in wait_until_sent()
916 while (info->tx_active) { in wait_until_sent()
924 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); in wait_until_sent()
929 struct slgt_info *info = tty->driver_data; in write_room() local
932 if (sanity_check(info, tty->name, "write_room")) in write_room()
934 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; in write_room()
935 DBGINFO(("%s write_room=%d\n", info->device_name, ret)); in write_room()
941 struct slgt_info *info = tty->driver_data; in flush_chars() local
944 if (sanity_check(info, tty->name, "flush_chars")) in flush_chars()
946 DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count)); in flush_chars()
948 if (info->tx_count <= 0 || tty->stopped || in flush_chars()
949 tty->hw_stopped || !info->tx_buf) in flush_chars()
952 DBGINFO(("%s flush_chars start transmit\n", info->device_name)); in flush_chars()
954 spin_lock_irqsave(&info->lock,flags); in flush_chars()
955 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in flush_chars()
956 info->tx_count = 0; in flush_chars()
957 spin_unlock_irqrestore(&info->lock,flags); in flush_chars()
962 struct slgt_info *info = tty->driver_data; in flush_buffer() local
965 if (sanity_check(info, tty->name, "flush_buffer")) in flush_buffer()
967 DBGINFO(("%s flush_buffer\n", info->device_name)); in flush_buffer()
969 spin_lock_irqsave(&info->lock, flags); in flush_buffer()
970 info->tx_count = 0; in flush_buffer()
971 spin_unlock_irqrestore(&info->lock, flags); in flush_buffer()
981 struct slgt_info *info = tty->driver_data; in tx_hold() local
984 if (sanity_check(info, tty->name, "tx_hold")) in tx_hold()
986 DBGINFO(("%s tx_hold\n", info->device_name)); in tx_hold()
987 spin_lock_irqsave(&info->lock,flags); in tx_hold()
988 if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC) in tx_hold()
989 tx_stop(info); in tx_hold()
990 spin_unlock_irqrestore(&info->lock,flags); in tx_hold()
998 struct slgt_info *info = tty->driver_data; in tx_release() local
1001 if (sanity_check(info, tty->name, "tx_release")) in tx_release()
1003 DBGINFO(("%s tx_release\n", info->device_name)); in tx_release()
1004 spin_lock_irqsave(&info->lock, flags); in tx_release()
1005 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in tx_release()
1006 info->tx_count = 0; in tx_release()
1007 spin_unlock_irqrestore(&info->lock, flags); in tx_release()
1024 struct slgt_info *info = tty->driver_data; in ioctl() local
1028 if (sanity_check(info, tty->name, "ioctl")) in ioctl()
1030 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); in ioctl()
1039 return wait_mgsl_event(info, argp); in ioctl()
1041 return modem_input_wait(info,(int)arg); in ioctl()
1043 return set_gpio(info, argp); in ioctl()
1045 return get_gpio(info, argp); in ioctl()
1047 return wait_gpio(info, argp); in ioctl()
1049 return get_xsync(info, argp); in ioctl()
1051 return set_xsync(info, (int)arg); in ioctl()
1053 return get_xctrl(info, argp); in ioctl()
1055 return set_xctrl(info, (int)arg); in ioctl()
1057 mutex_lock(&info->port.mutex); in ioctl()
1060 ret = get_params(info, argp); in ioctl()
1063 ret = set_params(info, argp); in ioctl()
1066 ret = get_txidle(info, argp); in ioctl()
1069 ret = set_txidle(info, (int)arg); in ioctl()
1072 ret = tx_enable(info, (int)arg); in ioctl()
1075 ret = rx_enable(info, (int)arg); in ioctl()
1078 ret = tx_abort(info); in ioctl()
1081 ret = get_stats(info, argp); in ioctl()
1084 ret = get_interface(info, argp); in ioctl()
1087 ret = set_interface(info,(int)arg); in ioctl()
1092 mutex_unlock(&info->port.mutex); in ioctl()
1100 struct slgt_info *info = tty->driver_data; in get_icount() local
1104 spin_lock_irqsave(&info->lock,flags); in get_icount()
1105 cnow = info->icount; in get_icount()
1106 spin_unlock_irqrestore(&info->lock,flags); in get_icount()
1127 static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params) in get_params32() argument
1131 DBGINFO(("%s get_params32\n", info->device_name)); in get_params32()
1133 tmp_params.mode = (compat_ulong_t)info->params.mode; in get_params32()
1134 tmp_params.loopback = info->params.loopback; in get_params32()
1135 tmp_params.flags = info->params.flags; in get_params32()
1136 tmp_params.encoding = info->params.encoding; in get_params32()
1137 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed; in get_params32()
1138 tmp_params.addr_filter = info->params.addr_filter; in get_params32()
1139 tmp_params.crc_type = info->params.crc_type; in get_params32()
1140 tmp_params.preamble_length = info->params.preamble_length; in get_params32()
1141 tmp_params.preamble = info->params.preamble; in get_params32()
1142 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate; in get_params32()
1143 tmp_params.data_bits = info->params.data_bits; in get_params32()
1144 tmp_params.stop_bits = info->params.stop_bits; in get_params32()
1145 tmp_params.parity = info->params.parity; in get_params32()
1151 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params) in set_params32() argument
1155 DBGINFO(("%s set_params32\n", info->device_name)); in set_params32()
1159 spin_lock(&info->lock); in set_params32()
1161 info->base_clock = tmp_params.clock_speed; in set_params32()
1163 info->params.mode = tmp_params.mode; in set_params32()
1164 info->params.loopback = tmp_params.loopback; in set_params32()
1165 info->params.flags = tmp_params.flags; in set_params32()
1166 info->params.encoding = tmp_params.encoding; in set_params32()
1167 info->params.clock_speed = tmp_params.clock_speed; in set_params32()
1168 info->params.addr_filter = tmp_params.addr_filter; in set_params32()
1169 info->params.crc_type = tmp_params.crc_type; in set_params32()
1170 info->params.preamble_length = tmp_params.preamble_length; in set_params32()
1171 info->params.preamble = tmp_params.preamble; in set_params32()
1172 info->params.data_rate = tmp_params.data_rate; in set_params32()
1173 info->params.data_bits = tmp_params.data_bits; in set_params32()
1174 info->params.stop_bits = tmp_params.stop_bits; in set_params32()
1175 info->params.parity = tmp_params.parity; in set_params32()
1177 spin_unlock(&info->lock); in set_params32()
1179 program_hw(info); in set_params32()
1187 struct slgt_info *info = tty->driver_data; in slgt_compat_ioctl() local
1190 if (sanity_check(info, tty->name, "compat_ioctl")) in slgt_compat_ioctl()
1192 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd)); in slgt_compat_ioctl()
1196 rc = set_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1200 rc = get_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1219 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc)); in slgt_compat_ioctl()
1229 static inline void line_info(struct seq_file *m, struct slgt_info *info) in line_info() argument
1235 info->device_name, info->phys_reg_addr, in line_info()
1236 info->irq_level, info->max_frame_size); in line_info()
1239 spin_lock_irqsave(&info->lock,flags); in line_info()
1240 get_signals(info); in line_info()
1241 spin_unlock_irqrestore(&info->lock,flags); in line_info()
1245 if (info->signals & SerialSignal_RTS) in line_info()
1247 if (info->signals & SerialSignal_CTS) in line_info()
1249 if (info->signals & SerialSignal_DTR) in line_info()
1251 if (info->signals & SerialSignal_DSR) in line_info()
1253 if (info->signals & SerialSignal_DCD) in line_info()
1255 if (info->signals & SerialSignal_RI) in line_info()
1258 if (info->params.mode != MGSL_MODE_ASYNC) { in line_info()
1260 info->icount.txok, info->icount.rxok); in line_info()
1261 if (info->icount.txunder) in line_info()
1262 seq_printf(m, " txunder:%d", info->icount.txunder); in line_info()
1263 if (info->icount.txabort) in line_info()
1264 seq_printf(m, " txabort:%d", info->icount.txabort); in line_info()
1265 if (info->icount.rxshort) in line_info()
1266 seq_printf(m, " rxshort:%d", info->icount.rxshort); in line_info()
1267 if (info->icount.rxlong) in line_info()
1268 seq_printf(m, " rxlong:%d", info->icount.rxlong); in line_info()
1269 if (info->icount.rxover) in line_info()
1270 seq_printf(m, " rxover:%d", info->icount.rxover); in line_info()
1271 if (info->icount.rxcrc) in line_info()
1272 seq_printf(m, " rxcrc:%d", info->icount.rxcrc); in line_info()
1275 info->icount.tx, info->icount.rx); in line_info()
1276 if (info->icount.frame) in line_info()
1277 seq_printf(m, " fe:%d", info->icount.frame); in line_info()
1278 if (info->icount.parity) in line_info()
1279 seq_printf(m, " pe:%d", info->icount.parity); in line_info()
1280 if (info->icount.brk) in line_info()
1281 seq_printf(m, " brk:%d", info->icount.brk); in line_info()
1282 if (info->icount.overrun) in line_info()
1283 seq_printf(m, " oe:%d", info->icount.overrun); in line_info()
1290 info->tx_active,info->bh_requested,info->bh_running, in line_info()
1291 info->pending_bh); in line_info()
1298 struct slgt_info *info; in synclink_gt_proc_show() local
1302 info = slgt_device_list; in synclink_gt_proc_show()
1303 while( info ) { in synclink_gt_proc_show()
1304 line_info(m, info); in synclink_gt_proc_show()
1305 info = info->next_device; in synclink_gt_proc_show()
1315 struct slgt_info *info = tty->driver_data; in chars_in_buffer() local
1317 if (sanity_check(info, tty->name, "chars_in_buffer")) in chars_in_buffer()
1319 count = tbuf_bytes(info); in chars_in_buffer()
1320 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count)); in chars_in_buffer()
1329 struct slgt_info *info = tty->driver_data; in throttle() local
1332 if (sanity_check(info, tty->name, "throttle")) in throttle()
1334 DBGINFO(("%s throttle\n", info->device_name)); in throttle()
1338 spin_lock_irqsave(&info->lock,flags); in throttle()
1339 info->signals &= ~SerialSignal_RTS; in throttle()
1340 set_signals(info); in throttle()
1341 spin_unlock_irqrestore(&info->lock,flags); in throttle()
1350 struct slgt_info *info = tty->driver_data; in unthrottle() local
1353 if (sanity_check(info, tty->name, "unthrottle")) in unthrottle()
1355 DBGINFO(("%s unthrottle\n", info->device_name)); in unthrottle()
1357 if (info->x_char) in unthrottle()
1358 info->x_char = 0; in unthrottle()
1363 spin_lock_irqsave(&info->lock,flags); in unthrottle()
1364 info->signals |= SerialSignal_RTS; in unthrottle()
1365 set_signals(info); in unthrottle()
1366 spin_unlock_irqrestore(&info->lock,flags); in unthrottle()
1376 struct slgt_info *info = tty->driver_data; in set_break() local
1380 if (sanity_check(info, tty->name, "set_break")) in set_break()
1382 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); in set_break()
1384 spin_lock_irqsave(&info->lock,flags); in set_break()
1385 value = rd_reg16(info, TCR); in set_break()
1390 wr_reg16(info, TCR, value); in set_break()
1391 spin_unlock_irqrestore(&info->lock,flags); in set_break()
1410 struct slgt_info *info = dev_to_port(dev); in hdlcdev_attach() local
1415 if (info->port.count) in hdlcdev_attach()
1418 DBGINFO(("%s hdlcdev_attach\n", info->device_name)); in hdlcdev_attach()
1438 info->params.encoding = new_encoding; in hdlcdev_attach()
1439 info->params.crc_type = new_crctype; in hdlcdev_attach()
1442 if (info->netcount) in hdlcdev_attach()
1443 program_hw(info); in hdlcdev_attach()
1457 struct slgt_info *info = dev_to_port(dev); in hdlcdev_xmit() local
1475 spin_lock_irqsave(&info->lock, flags); in hdlcdev_xmit()
1476 tx_load(info, skb->data, skb->len); in hdlcdev_xmit()
1477 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_xmit()
1495 struct slgt_info *info = dev_to_port(dev); in hdlcdev_open() local
1510 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1511 if (info->port.count != 0 || info->netcount != 0) { in hdlcdev_open()
1513 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1516 info->netcount=1; in hdlcdev_open()
1517 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1520 if ((rc = startup(info)) != 0) { in hdlcdev_open()
1521 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1522 info->netcount=0; in hdlcdev_open()
1523 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1528 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in hdlcdev_open()
1529 program_hw(info); in hdlcdev_open()
1536 spin_lock_irqsave(&info->lock, flags); in hdlcdev_open()
1537 get_signals(info); in hdlcdev_open()
1538 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_open()
1539 if (info->signals & SerialSignal_DCD) in hdlcdev_open()
1556 struct slgt_info *info = dev_to_port(dev); in hdlcdev_close() local
1564 shutdown(info); in hdlcdev_close()
1568 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_close()
1569 info->netcount=0; in hdlcdev_close()
1570 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_close()
1590 struct slgt_info *info = dev_to_port(dev); in hdlcdev_ioctl() local
1596 if (info->port.count) in hdlcdev_ioctl()
1613 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1626 new_line.clock_rate = info->params.clock_speed; in hdlcdev_ioctl()
1627 new_line.loopback = info->params.loopback ? 1:0; in hdlcdev_ioctl()
1646 case CLOCK_DEFAULT: flags = info->params.flags & in hdlcdev_ioctl()
1657 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1661 info->params.flags |= flags; in hdlcdev_ioctl()
1663 info->params.loopback = new_line.loopback; in hdlcdev_ioctl()
1666 info->params.clock_speed = new_line.clock_rate; in hdlcdev_ioctl()
1668 info->params.clock_speed = 0; in hdlcdev_ioctl()
1671 if (info->netcount) in hdlcdev_ioctl()
1672 program_hw(info); in hdlcdev_ioctl()
1687 struct slgt_info *info = dev_to_port(dev); in hdlcdev_tx_timeout() local
1695 spin_lock_irqsave(&info->lock,flags); in hdlcdev_tx_timeout()
1696 tx_stop(info); in hdlcdev_tx_timeout()
1697 spin_unlock_irqrestore(&info->lock,flags); in hdlcdev_tx_timeout()
1706 * info pointer to device instance information
1708 static void hdlcdev_tx_done(struct slgt_info *info) in hdlcdev_tx_done() argument
1710 if (netif_queue_stopped(info->netdev)) in hdlcdev_tx_done()
1711 netif_wake_queue(info->netdev); in hdlcdev_tx_done()
1718 * info pointer to device instance information
1722 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size) in hdlcdev_rx() argument
1725 struct net_device *dev = info->netdev; in hdlcdev_rx()
1757 * info pointer to device instance information
1761 static int hdlcdev_init(struct slgt_info *info) in hdlcdev_init() argument
1769 dev = alloc_hdlcdev(info); in hdlcdev_init()
1771 printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name); in hdlcdev_init()
1776 dev->mem_start = info->phys_reg_addr; in hdlcdev_init()
1777 dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1; in hdlcdev_init()
1778 dev->irq = info->irq_level; in hdlcdev_init()
1798 info->netdev = dev; in hdlcdev_init()
1806 * info pointer to device instance information
1808 static void hdlcdev_exit(struct slgt_info *info) in hdlcdev_exit() argument
1810 unregister_hdlc_device(info->netdev); in hdlcdev_exit()
1811 free_netdev(info->netdev); in hdlcdev_exit()
1812 info->netdev = NULL; in hdlcdev_exit()
1820 static void rx_async(struct slgt_info *info) in rx_async() argument
1822 struct mgsl_icount *icount = &info->icount; in rx_async()
1826 struct slgt_desc *bufs = info->rbufs; in rx_async()
1832 start = end = info->rbuf_current; in rx_async()
1835 count = desc_count(bufs[end]) - info->rbuf_index; in rx_async()
1836 p = bufs[end].buf + info->rbuf_index; in rx_async()
1838 DBGISR(("%s rx_async count=%d\n", info->device_name, count)); in rx_async()
1839 DBGDATA(info, p, count, "rx"); in rx_async()
1854 if (status & info->ignore_status_mask) in rx_async()
1861 tty_insert_flip_char(&info->port, ch, stat); in rx_async()
1867 info->rbuf_index += i; in rx_async()
1868 mod_timer(&info->rx_timer, jiffies + 1); in rx_async()
1872 info->rbuf_index = 0; in rx_async()
1873 free_rbufs(info, end, end); in rx_async()
1875 if (++end == info->rbuf_count) in rx_async()
1884 tty_flip_buffer_push(&info->port); in rx_async()
1890 static int bh_action(struct slgt_info *info) in bh_action() argument
1895 spin_lock_irqsave(&info->lock,flags); in bh_action()
1897 if (info->pending_bh & BH_RECEIVE) { in bh_action()
1898 info->pending_bh &= ~BH_RECEIVE; in bh_action()
1900 } else if (info->pending_bh & BH_TRANSMIT) { in bh_action()
1901 info->pending_bh &= ~BH_TRANSMIT; in bh_action()
1903 } else if (info->pending_bh & BH_STATUS) { in bh_action()
1904 info->pending_bh &= ~BH_STATUS; in bh_action()
1908 info->bh_running = false; in bh_action()
1909 info->bh_requested = false; in bh_action()
1913 spin_unlock_irqrestore(&info->lock,flags); in bh_action()
1923 struct slgt_info *info = container_of(work, struct slgt_info, task); in bh_handler() local
1926 info->bh_running = true; in bh_handler()
1928 while((action = bh_action(info))) { in bh_handler()
1931 DBGBH(("%s bh receive\n", info->device_name)); in bh_handler()
1932 switch(info->params.mode) { in bh_handler()
1934 rx_async(info); in bh_handler()
1937 while(rx_get_frame(info)); in bh_handler()
1943 while(rx_get_buf(info)); in bh_handler()
1947 if (info->rx_restart) in bh_handler()
1948 rx_start(info); in bh_handler()
1951 bh_transmit(info); in bh_handler()
1954 DBGBH(("%s bh status\n", info->device_name)); in bh_handler()
1955 info->ri_chkcount = 0; in bh_handler()
1956 info->dsr_chkcount = 0; in bh_handler()
1957 info->dcd_chkcount = 0; in bh_handler()
1958 info->cts_chkcount = 0; in bh_handler()
1961 DBGBH(("%s unknown action\n", info->device_name)); in bh_handler()
1965 DBGBH(("%s bh_handler exit\n", info->device_name)); in bh_handler()
1968 static void bh_transmit(struct slgt_info *info) in bh_transmit() argument
1970 struct tty_struct *tty = info->port.tty; in bh_transmit()
1972 DBGBH(("%s bh_transmit\n", info->device_name)); in bh_transmit()
1977 static void dsr_change(struct slgt_info *info, unsigned short status) in dsr_change() argument
1980 info->signals |= SerialSignal_DSR; in dsr_change()
1981 info->input_signal_events.dsr_up++; in dsr_change()
1983 info->signals &= ~SerialSignal_DSR; in dsr_change()
1984 info->input_signal_events.dsr_down++; in dsr_change()
1986 DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); in dsr_change()
1987 if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dsr_change()
1988 slgt_irq_off(info, IRQ_DSR); in dsr_change()
1991 info->icount.dsr++; in dsr_change()
1992 wake_up_interruptible(&info->status_event_wait_q); in dsr_change()
1993 wake_up_interruptible(&info->event_wait_q); in dsr_change()
1994 info->pending_bh |= BH_STATUS; in dsr_change()
1997 static void cts_change(struct slgt_info *info, unsigned short status) in cts_change() argument
2000 info->signals |= SerialSignal_CTS; in cts_change()
2001 info->input_signal_events.cts_up++; in cts_change()
2003 info->signals &= ~SerialSignal_CTS; in cts_change()
2004 info->input_signal_events.cts_down++; in cts_change()
2006 DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); in cts_change()
2007 if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in cts_change()
2008 slgt_irq_off(info, IRQ_CTS); in cts_change()
2011 info->icount.cts++; in cts_change()
2012 wake_up_interruptible(&info->status_event_wait_q); in cts_change()
2013 wake_up_interruptible(&info->event_wait_q); in cts_change()
2014 info->pending_bh |= BH_STATUS; in cts_change()
2016 if (tty_port_cts_enabled(&info->port)) { in cts_change()
2017 if (info->port.tty) { in cts_change()
2018 if (info->port.tty->hw_stopped) { in cts_change()
2019 if (info->signals & SerialSignal_CTS) { in cts_change()
2020 info->port.tty->hw_stopped = 0; in cts_change()
2021 info->pending_bh |= BH_TRANSMIT; in cts_change()
2025 if (!(info->signals & SerialSignal_CTS)) in cts_change()
2026 info->port.tty->hw_stopped = 1; in cts_change()
2032 static void dcd_change(struct slgt_info *info, unsigned short status) in dcd_change() argument
2035 info->signals |= SerialSignal_DCD; in dcd_change()
2036 info->input_signal_events.dcd_up++; in dcd_change()
2038 info->signals &= ~SerialSignal_DCD; in dcd_change()
2039 info->input_signal_events.dcd_down++; in dcd_change()
2041 DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); in dcd_change()
2042 if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dcd_change()
2043 slgt_irq_off(info, IRQ_DCD); in dcd_change()
2046 info->icount.dcd++; in dcd_change()
2048 if (info->netcount) { in dcd_change()
2049 if (info->signals & SerialSignal_DCD) in dcd_change()
2050 netif_carrier_on(info->netdev); in dcd_change()
2052 netif_carrier_off(info->netdev); in dcd_change()
2055 wake_up_interruptible(&info->status_event_wait_q); in dcd_change()
2056 wake_up_interruptible(&info->event_wait_q); in dcd_change()
2057 info->pending_bh |= BH_STATUS; in dcd_change()
2059 if (tty_port_check_carrier(&info->port)) { in dcd_change()
2060 if (info->signals & SerialSignal_DCD) in dcd_change()
2061 wake_up_interruptible(&info->port.open_wait); in dcd_change()
2063 if (info->port.tty) in dcd_change()
2064 tty_hangup(info->port.tty); in dcd_change()
2069 static void ri_change(struct slgt_info *info, unsigned short status) in ri_change() argument
2072 info->signals |= SerialSignal_RI; in ri_change()
2073 info->input_signal_events.ri_up++; in ri_change()
2075 info->signals &= ~SerialSignal_RI; in ri_change()
2076 info->input_signal_events.ri_down++; in ri_change()
2078 DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); in ri_change()
2079 if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in ri_change()
2080 slgt_irq_off(info, IRQ_RI); in ri_change()
2083 info->icount.rng++; in ri_change()
2084 wake_up_interruptible(&info->status_event_wait_q); in ri_change()
2085 wake_up_interruptible(&info->event_wait_q); in ri_change()
2086 info->pending_bh |= BH_STATUS; in ri_change()
2089 static void isr_rxdata(struct slgt_info *info) in isr_rxdata() argument
2091 unsigned int count = info->rbuf_fill_count; in isr_rxdata()
2092 unsigned int i = info->rbuf_fill_index; in isr_rxdata()
2095 while (rd_reg16(info, SSR) & IRQ_RXDATA) { in isr_rxdata()
2096 reg = rd_reg16(info, RDR); in isr_rxdata()
2097 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); in isr_rxdata()
2098 if (desc_complete(info->rbufs[i])) { in isr_rxdata()
2100 rx_stop(info); in isr_rxdata()
2101 info->rx_restart = 1; in isr_rxdata()
2104 info->rbufs[i].buf[count++] = (unsigned char)reg; in isr_rxdata()
2106 if (info->params.mode == MGSL_MODE_ASYNC) in isr_rxdata()
2107 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); in isr_rxdata()
2108 if (count == info->rbuf_fill_level || (reg & BIT10)) { in isr_rxdata()
2110 set_desc_count(info->rbufs[i], count); in isr_rxdata()
2111 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); in isr_rxdata()
2112 info->rbuf_fill_count = count = 0; in isr_rxdata()
2113 if (++i == info->rbuf_count) in isr_rxdata()
2115 info->pending_bh |= BH_RECEIVE; in isr_rxdata()
2119 info->rbuf_fill_index = i; in isr_rxdata()
2120 info->rbuf_fill_count = count; in isr_rxdata()
2123 static void isr_serial(struct slgt_info *info) in isr_serial() argument
2125 unsigned short status = rd_reg16(info, SSR); in isr_serial()
2127 DBGISR(("%s isr_serial status=%04X\n", info->device_name, status)); in isr_serial()
2129 wr_reg16(info, SSR, status); /* clear pending */ in isr_serial()
2131 info->irq_occurred = true; in isr_serial()
2133 if (info->params.mode == MGSL_MODE_ASYNC) { in isr_serial()
2135 if (info->tx_active) in isr_serial()
2136 isr_txeom(info, status); in isr_serial()
2138 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2139 isr_rxdata(info); in isr_serial()
2141 info->icount.brk++; in isr_serial()
2143 if (info->port.tty) { in isr_serial()
2144 if (!(status & info->ignore_status_mask)) { in isr_serial()
2145 if (info->read_status_mask & MASK_BREAK) { in isr_serial()
2146 tty_insert_flip_char(&info->port, 0, TTY_BREAK); in isr_serial()
2147 if (info->port.flags & ASYNC_SAK) in isr_serial()
2148 do_SAK(info->port.tty); in isr_serial()
2155 isr_txeom(info, status); in isr_serial()
2156 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2157 isr_rxdata(info); in isr_serial()
2160 info->icount.rxidle++; in isr_serial()
2162 info->icount.exithunt++; in isr_serial()
2163 wake_up_interruptible(&info->event_wait_q); in isr_serial()
2167 rx_start(info); in isr_serial()
2171 dsr_change(info, status); in isr_serial()
2173 cts_change(info, status); in isr_serial()
2175 dcd_change(info, status); in isr_serial()
2177 ri_change(info, status); in isr_serial()
2180 static void isr_rdma(struct slgt_info *info) in isr_rdma() argument
2182 unsigned int status = rd_reg32(info, RDCSR); in isr_rdma()
2184 DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status)); in isr_rdma()
2197 wr_reg32(info, RDCSR, status); /* clear pending */ in isr_rdma()
2200 DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); in isr_rdma()
2201 info->rx_restart = true; in isr_rdma()
2203 info->pending_bh |= BH_RECEIVE; in isr_rdma()
2206 static void isr_tdma(struct slgt_info *info) in isr_tdma() argument
2208 unsigned int status = rd_reg32(info, TDCSR); in isr_tdma()
2210 DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status)); in isr_tdma()
2222 wr_reg32(info, TDCSR, status); /* clear pending */ in isr_tdma()
2227 info->pending_bh |= BH_TRANSMIT; in isr_tdma()
2234 * if there are unsent buffers then info->tbuf_start
2237 static bool unsent_tbufs(struct slgt_info *info) in unsent_tbufs() argument
2239 unsigned int i = info->tbuf_current; in unsent_tbufs()
2251 i = info->tbuf_count - 1; in unsent_tbufs()
2252 if (!desc_count(info->tbufs[i])) in unsent_tbufs()
2254 info->tbuf_start = i; in unsent_tbufs()
2256 } while (i != info->tbuf_current); in unsent_tbufs()
2261 static void isr_txeom(struct slgt_info *info, unsigned short status) in isr_txeom() argument
2263 DBGISR(("%s txeom status=%04x\n", info->device_name, status)); in isr_txeom()
2265 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in isr_txeom()
2266 tdma_reset(info); in isr_txeom()
2268 unsigned short val = rd_reg16(info, TCR); in isr_txeom()
2269 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in isr_txeom()
2270 wr_reg16(info, TCR, val); /* clear reset bit */ in isr_txeom()
2273 if (info->tx_active) { in isr_txeom()
2274 if (info->params.mode != MGSL_MODE_ASYNC) { in isr_txeom()
2276 info->icount.txunder++; in isr_txeom()
2278 info->icount.txok++; in isr_txeom()
2281 if (unsent_tbufs(info)) { in isr_txeom()
2282 tx_start(info); in isr_txeom()
2283 update_tx_timer(info); in isr_txeom()
2286 info->tx_active = false; in isr_txeom()
2288 del_timer(&info->tx_timer); in isr_txeom()
2290 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { in isr_txeom()
2291 info->signals &= ~SerialSignal_RTS; in isr_txeom()
2292 info->drop_rts_on_tx_done = false; in isr_txeom()
2293 set_signals(info); in isr_txeom()
2297 if (info->netcount) in isr_txeom()
2298 hdlcdev_tx_done(info); in isr_txeom()
2302 if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) { in isr_txeom()
2303 tx_stop(info); in isr_txeom()
2306 info->pending_bh |= BH_TRANSMIT; in isr_txeom()
2311 static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state) in isr_gpio() argument
2316 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) { in isr_gpio()
2323 info->gpio_wait_q = w->next; in isr_gpio()
2336 struct slgt_info *info = dev_id; in slgt_interrupt() local
2340 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); in slgt_interrupt()
2342 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { in slgt_interrupt()
2343 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); in slgt_interrupt()
2344 info->irq_occurred = true; in slgt_interrupt()
2345 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2346 if (info->port_array[i] == NULL) in slgt_interrupt()
2348 spin_lock(&info->port_array[i]->lock); in slgt_interrupt()
2350 isr_serial(info->port_array[i]); in slgt_interrupt()
2352 isr_rdma(info->port_array[i]); in slgt_interrupt()
2354 isr_tdma(info->port_array[i]); in slgt_interrupt()
2355 spin_unlock(&info->port_array[i]->lock); in slgt_interrupt()
2359 if (info->gpio_present) { in slgt_interrupt()
2362 spin_lock(&info->lock); in slgt_interrupt()
2363 while ((changed = rd_reg32(info, IOSR)) != 0) { in slgt_interrupt()
2364 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); in slgt_interrupt()
2366 state = rd_reg32(info, IOVR); in slgt_interrupt()
2368 wr_reg32(info, IOSR, changed); in slgt_interrupt()
2369 for (i=0 ; i < info->port_count ; i++) { in slgt_interrupt()
2370 if (info->port_array[i] != NULL) in slgt_interrupt()
2371 isr_gpio(info->port_array[i], changed, state); in slgt_interrupt()
2374 spin_unlock(&info->lock); in slgt_interrupt()
2377 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2378 struct slgt_info *port = info->port_array[i]; in slgt_interrupt()
2392 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); in slgt_interrupt()
2396 static int startup(struct slgt_info *info) in startup() argument
2398 DBGINFO(("%s startup\n", info->device_name)); in startup()
2400 if (tty_port_initialized(&info->port)) in startup()
2403 if (!info->tx_buf) { in startup()
2404 info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); in startup()
2405 if (!info->tx_buf) { in startup()
2406 DBGERR(("%s can't allocate tx buffer\n", info->device_name)); in startup()
2411 info->pending_bh = 0; in startup()
2413 memset(&info->icount, 0, sizeof(info->icount)); in startup()
2416 change_params(info); in startup()
2418 if (info->port.tty) in startup()
2419 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); in startup()
2421 tty_port_set_initialized(&info->port, 1); in startup()
2429 static void shutdown(struct slgt_info *info) in shutdown() argument
2433 if (!tty_port_initialized(&info->port)) in shutdown()
2436 DBGINFO(("%s shutdown\n", info->device_name)); in shutdown()
2440 wake_up_interruptible(&info->status_event_wait_q); in shutdown()
2441 wake_up_interruptible(&info->event_wait_q); in shutdown()
2443 del_timer_sync(&info->tx_timer); in shutdown()
2444 del_timer_sync(&info->rx_timer); in shutdown()
2446 kfree(info->tx_buf); in shutdown()
2447 info->tx_buf = NULL; in shutdown()
2449 spin_lock_irqsave(&info->lock,flags); in shutdown()
2451 tx_stop(info); in shutdown()
2452 rx_stop(info); in shutdown()
2454 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in shutdown()
2456 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { in shutdown()
2457 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in shutdown()
2458 set_signals(info); in shutdown()
2461 flush_cond_wait(&info->gpio_wait_q); in shutdown()
2463 spin_unlock_irqrestore(&info->lock,flags); in shutdown()
2465 if (info->port.tty) in shutdown()
2466 set_bit(TTY_IO_ERROR, &info->port.tty->flags); in shutdown()
2468 tty_port_set_initialized(&info->port, 0); in shutdown()
2471 static void program_hw(struct slgt_info *info) in program_hw() argument
2475 spin_lock_irqsave(&info->lock,flags); in program_hw()
2477 rx_stop(info); in program_hw()
2478 tx_stop(info); in program_hw()
2480 if (info->params.mode != MGSL_MODE_ASYNC || in program_hw()
2481 info->netcount) in program_hw()
2482 sync_mode(info); in program_hw()
2484 async_mode(info); in program_hw()
2486 set_signals(info); in program_hw()
2488 info->dcd_chkcount = 0; in program_hw()
2489 info->cts_chkcount = 0; in program_hw()
2490 info->ri_chkcount = 0; in program_hw()
2491 info->dsr_chkcount = 0; in program_hw()
2493 slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI); in program_hw()
2494 get_signals(info); in program_hw()
2496 if (info->netcount || in program_hw()
2497 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) in program_hw()
2498 rx_start(info); in program_hw()
2500 spin_unlock_irqrestore(&info->lock,flags); in program_hw()
2506 static void change_params(struct slgt_info *info) in change_params() argument
2511 if (!info->port.tty) in change_params()
2513 DBGINFO(("%s change_params\n", info->device_name)); in change_params()
2515 cflag = info->port.tty->termios.c_cflag; in change_params()
2520 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in change_params()
2522 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in change_params()
2527 case CS5: info->params.data_bits = 5; break; in change_params()
2528 case CS6: info->params.data_bits = 6; break; in change_params()
2529 case CS7: info->params.data_bits = 7; break; in change_params()
2530 case CS8: info->params.data_bits = 8; break; in change_params()
2531 default: info->params.data_bits = 7; break; in change_params()
2534 info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1; in change_params()
2537 info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN; in change_params()
2539 info->params.parity = ASYNC_PARITY_NONE; in change_params()
2544 bits_per_char = info->params.data_bits + in change_params()
2545 info->params.stop_bits + 1; in change_params()
2547 info->params.data_rate = tty_get_baud_rate(info->port.tty); in change_params()
2549 if (info->params.data_rate) { in change_params()
2550 info->timeout = (32*HZ*bits_per_char) / in change_params()
2551 info->params.data_rate; in change_params()
2553 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_params()
2555 tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); in change_params()
2556 tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); in change_params()
2560 info->read_status_mask = IRQ_RXOVER; in change_params()
2561 if (I_INPCK(info->port.tty)) in change_params()
2562 info->read_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2563 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) in change_params()
2564 info->read_status_mask |= MASK_BREAK; in change_params()
2565 if (I_IGNPAR(info->port.tty)) in change_params()
2566 info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2567 if (I_IGNBRK(info->port.tty)) { in change_params()
2568 info->ignore_status_mask |= MASK_BREAK; in change_params()
2572 if (I_IGNPAR(info->port.tty)) in change_params()
2573 info->ignore_status_mask |= MASK_OVERRUN; in change_params()
2576 program_hw(info); in change_params()
2579 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount) in get_stats() argument
2581 DBGINFO(("%s get_stats\n", info->device_name)); in get_stats()
2583 memset(&info->icount, 0, sizeof(info->icount)); in get_stats()
2585 if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount))) in get_stats()
2591 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params) in get_params() argument
2593 DBGINFO(("%s get_params\n", info->device_name)); in get_params()
2594 if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS))) in get_params()
2599 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params) in set_params() argument
2604 DBGINFO(("%s set_params\n", info->device_name)); in set_params()
2608 spin_lock_irqsave(&info->lock, flags); in set_params()
2610 info->base_clock = tmp_params.clock_speed; in set_params()
2612 memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS)); in set_params()
2613 spin_unlock_irqrestore(&info->lock, flags); in set_params()
2615 program_hw(info); in set_params()
2620 static int get_txidle(struct slgt_info *info, int __user *idle_mode) in get_txidle() argument
2622 DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode)); in get_txidle()
2623 if (put_user(info->idle_mode, idle_mode)) in get_txidle()
2628 static int set_txidle(struct slgt_info *info, int idle_mode) in set_txidle() argument
2631 DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode)); in set_txidle()
2632 spin_lock_irqsave(&info->lock,flags); in set_txidle()
2633 info->idle_mode = idle_mode; in set_txidle()
2634 if (info->params.mode != MGSL_MODE_ASYNC) in set_txidle()
2635 tx_set_idle(info); in set_txidle()
2636 spin_unlock_irqrestore(&info->lock,flags); in set_txidle()
2640 static int tx_enable(struct slgt_info *info, int enable) in tx_enable() argument
2643 DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable)); in tx_enable()
2644 spin_lock_irqsave(&info->lock,flags); in tx_enable()
2646 if (!info->tx_enabled) in tx_enable()
2647 tx_start(info); in tx_enable()
2649 if (info->tx_enabled) in tx_enable()
2650 tx_stop(info); in tx_enable()
2652 spin_unlock_irqrestore(&info->lock,flags); in tx_enable()
2659 static int tx_abort(struct slgt_info *info) in tx_abort() argument
2662 DBGINFO(("%s tx_abort\n", info->device_name)); in tx_abort()
2663 spin_lock_irqsave(&info->lock,flags); in tx_abort()
2664 tdma_reset(info); in tx_abort()
2665 spin_unlock_irqrestore(&info->lock,flags); in tx_abort()
2669 static int rx_enable(struct slgt_info *info, int enable) in rx_enable() argument
2673 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable)); in rx_enable()
2674 spin_lock_irqsave(&info->lock,flags); in rx_enable()
2683 spin_unlock_irqrestore(&info->lock, flags); in rx_enable()
2686 info->rbuf_fill_level = rbuf_fill_level; in rx_enable()
2688 info->rx_pio = 1; /* PIO mode */ in rx_enable()
2690 info->rx_pio = 0; /* DMA mode */ in rx_enable()
2691 rx_stop(info); /* restart receiver to use new fill level */ in rx_enable()
2702 if (!info->rx_enabled) in rx_enable()
2703 rx_start(info); in rx_enable()
2706 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3); in rx_enable()
2709 if (info->rx_enabled) in rx_enable()
2710 rx_stop(info); in rx_enable()
2712 spin_unlock_irqrestore(&info->lock,flags); in rx_enable()
2719 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr) in wait_mgsl_event() argument
2733 DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask)); in wait_mgsl_event()
2735 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2738 get_signals(info); in wait_mgsl_event()
2739 s = info->signals; in wait_mgsl_event()
2747 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2752 cprev = info->icount; in wait_mgsl_event()
2753 oldsigs = info->input_signal_events; in wait_mgsl_event()
2757 unsigned short val = rd_reg16(info, SCR); in wait_mgsl_event()
2759 wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE)); in wait_mgsl_event()
2763 add_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2765 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2775 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2776 cnow = info->icount; in wait_mgsl_event()
2777 newsigs = info->input_signal_events; in wait_mgsl_event()
2779 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2814 remove_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2819 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2820 if (!waitqueue_active(&info->event_wait_q)) { in wait_mgsl_event()
2822 wr_reg16(info, SCR, in wait_mgsl_event()
2823 (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE)); in wait_mgsl_event()
2825 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2833 static int get_interface(struct slgt_info *info, int __user *if_mode) in get_interface() argument
2835 DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode)); in get_interface()
2836 if (put_user(info->if_mode, if_mode)) in get_interface()
2841 static int set_interface(struct slgt_info *info, int if_mode) in set_interface() argument
2846 DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode)); in set_interface()
2847 spin_lock_irqsave(&info->lock,flags); in set_interface()
2848 info->if_mode = if_mode; in set_interface()
2850 msc_set_vcr(info); in set_interface()
2853 val = rd_reg16(info, TCR); in set_interface()
2854 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in set_interface()
2858 wr_reg16(info, TCR, val); in set_interface()
2860 spin_unlock_irqrestore(&info->lock,flags); in set_interface()
2864 static int get_xsync(struct slgt_info *info, int __user *xsync) in get_xsync() argument
2866 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync)); in get_xsync()
2867 if (put_user(info->xsync, xsync)) in get_xsync()
2878 static int set_xsync(struct slgt_info *info, int xsync) in set_xsync() argument
2882 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync)); in set_xsync()
2883 spin_lock_irqsave(&info->lock, flags); in set_xsync()
2884 info->xsync = xsync; in set_xsync()
2885 wr_reg32(info, XSR, xsync); in set_xsync()
2886 spin_unlock_irqrestore(&info->lock, flags); in set_xsync()
2890 static int get_xctrl(struct slgt_info *info, int __user *xctrl) in get_xctrl() argument
2892 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl)); in get_xctrl()
2893 if (put_user(info->xctrl, xctrl)) in get_xctrl()
2915 static int set_xctrl(struct slgt_info *info, int xctrl) in set_xctrl() argument
2919 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl)); in set_xctrl()
2920 spin_lock_irqsave(&info->lock, flags); in set_xctrl()
2921 info->xctrl = xctrl; in set_xctrl()
2922 wr_reg32(info, XCR, xctrl); in set_xctrl()
2923 spin_unlock_irqrestore(&info->lock, flags); in set_xctrl()
2936 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in set_gpio() argument
2942 if (!info->gpio_present) in set_gpio()
2947 info->device_name, gpio.state, gpio.smask, in set_gpio()
2950 spin_lock_irqsave(&info->port_array[0]->lock, flags); in set_gpio()
2952 data = rd_reg32(info, IODR); in set_gpio()
2955 wr_reg32(info, IODR, data); in set_gpio()
2958 data = rd_reg32(info, IOVR); in set_gpio()
2961 wr_reg32(info, IOVR, data); in set_gpio()
2963 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in set_gpio()
2971 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in get_gpio() argument
2974 if (!info->gpio_present) in get_gpio()
2976 gpio.state = rd_reg32(info, IOVR); in get_gpio()
2978 gpio.dir = rd_reg32(info, IODR); in get_gpio()
2983 info->device_name, gpio.state, gpio.dir)); in get_gpio()
3045 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in wait_gpio() argument
3053 if (!info->gpio_present) in wait_gpio()
3058 info->device_name, gpio.state, gpio.smask)); in wait_gpio()
3060 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0) in wait_gpio()
3064 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3066 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); in wait_gpio()
3068 state = rd_reg32(info, IOVR); in wait_gpio()
3075 add_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3076 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3082 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3083 remove_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3087 if (info->gpio_wait_q == NULL) in wait_gpio()
3088 wr_reg32(info, IOER, 0); in wait_gpio()
3089 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3096 static int modem_input_wait(struct slgt_info *info,int arg) in modem_input_wait() argument
3104 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3105 cprev = info->icount; in modem_input_wait()
3106 add_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3108 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3118 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3119 cnow = info->icount; in modem_input_wait()
3121 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3141 remove_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3151 struct slgt_info *info = tty->driver_data; in tiocmget() local
3155 spin_lock_irqsave(&info->lock,flags); in tiocmget()
3156 get_signals(info); in tiocmget()
3157 spin_unlock_irqrestore(&info->lock,flags); in tiocmget()
3159 result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) + in tiocmget()
3160 ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) + in tiocmget()
3161 ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) + in tiocmget()
3162 ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) + in tiocmget()
3163 ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) + in tiocmget()
3164 ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0); in tiocmget()
3166 DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result)); in tiocmget()
3180 struct slgt_info *info = tty->driver_data; in tiocmset() local
3183 DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear)); in tiocmset()
3186 info->signals |= SerialSignal_RTS; in tiocmset()
3188 info->signals |= SerialSignal_DTR; in tiocmset()
3190 info->signals &= ~SerialSignal_RTS; in tiocmset()
3192 info->signals &= ~SerialSignal_DTR; in tiocmset()
3194 spin_lock_irqsave(&info->lock,flags); in tiocmset()
3195 set_signals(info); in tiocmset()
3196 spin_unlock_irqrestore(&info->lock,flags); in tiocmset()
3203 struct slgt_info *info = container_of(port, struct slgt_info, port); in carrier_raised() local
3205 spin_lock_irqsave(&info->lock,flags); in carrier_raised()
3206 get_signals(info); in carrier_raised()
3207 spin_unlock_irqrestore(&info->lock,flags); in carrier_raised()
3208 return (info->signals & SerialSignal_DCD) ? 1 : 0; in carrier_raised()
3214 struct slgt_info *info = container_of(port, struct slgt_info, port); in dtr_rts() local
3216 spin_lock_irqsave(&info->lock,flags); in dtr_rts()
3218 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in dtr_rts()
3220 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in dtr_rts()
3221 set_signals(info); in dtr_rts()
3222 spin_unlock_irqrestore(&info->lock,flags); in dtr_rts()
3230 struct slgt_info *info) in block_til_ready() argument
3237 struct tty_port *port = &info->port; in block_til_ready()
3260 spin_lock_irqsave(&info->lock, flags); in block_til_ready()
3262 spin_unlock_irqrestore(&info->lock, flags); in block_til_ready()
3312 static int alloc_tmp_rbuf(struct slgt_info *info) in alloc_tmp_rbuf() argument
3314 info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3315 if (info->tmp_rbuf == NULL) in alloc_tmp_rbuf()
3318 info->flag_buf = kzalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3319 if (!info->flag_buf) { in alloc_tmp_rbuf()
3320 kfree(info->tmp_rbuf); in alloc_tmp_rbuf()
3321 info->tmp_rbuf = NULL; in alloc_tmp_rbuf()
3327 static void free_tmp_rbuf(struct slgt_info *info) in free_tmp_rbuf() argument
3329 kfree(info->tmp_rbuf); in free_tmp_rbuf()
3330 info->tmp_rbuf = NULL; in free_tmp_rbuf()
3331 kfree(info->flag_buf); in free_tmp_rbuf()
3332 info->flag_buf = NULL; in free_tmp_rbuf()
3338 static int alloc_desc(struct slgt_info *info) in alloc_desc() argument
3344 info->bufs = pci_zalloc_consistent(info->pdev, DESC_LIST_SIZE, in alloc_desc()
3345 &info->bufs_dma_addr); in alloc_desc()
3346 if (info->bufs == NULL) in alloc_desc()
3349 info->rbufs = (struct slgt_desc*)info->bufs; in alloc_desc()
3350 info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count; in alloc_desc()
3352 pbufs = (unsigned int)info->bufs_dma_addr; in alloc_desc()
3358 for (i=0; i < info->rbuf_count; i++) { in alloc_desc()
3360 info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc)); in alloc_desc()
3363 if (i == info->rbuf_count - 1) in alloc_desc()
3364 info->rbufs[i].next = cpu_to_le32(pbufs); in alloc_desc()
3366 info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc))); in alloc_desc()
3367 set_desc_count(info->rbufs[i], DMABUFSIZE); in alloc_desc()
3370 for (i=0; i < info->tbuf_count; i++) { in alloc_desc()
3372 info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc)); in alloc_desc()
3375 if (i == info->tbuf_count - 1) in alloc_desc()
3376 info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc)); in alloc_desc()
3378 …info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc))); in alloc_desc()
3384 static void free_desc(struct slgt_info *info) in free_desc() argument
3386 if (info->bufs != NULL) { in free_desc()
3387 pci_free_consistent(info->pdev, DESC_LIST_SIZE, info->bufs, info->bufs_dma_addr); in free_desc()
3388 info->bufs = NULL; in free_desc()
3389 info->rbufs = NULL; in free_desc()
3390 info->tbufs = NULL; in free_desc()
3394 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in alloc_bufs() argument
3398 if ((bufs[i].buf = pci_alloc_consistent(info->pdev, DMABUFSIZE, &bufs[i].buf_dma_addr)) == NULL) in alloc_bufs()
3405 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in free_bufs() argument
3411 pci_free_consistent(info->pdev, DMABUFSIZE, bufs[i].buf, bufs[i].buf_dma_addr); in free_bufs()
3416 static int alloc_dma_bufs(struct slgt_info *info) in alloc_dma_bufs() argument
3418 info->rbuf_count = 32; in alloc_dma_bufs()
3419 info->tbuf_count = 32; in alloc_dma_bufs()
3421 if (alloc_desc(info) < 0 || in alloc_dma_bufs()
3422 alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 || in alloc_dma_bufs()
3423 alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 || in alloc_dma_bufs()
3424 alloc_tmp_rbuf(info) < 0) { in alloc_dma_bufs()
3425 DBGERR(("%s DMA buffer alloc fail\n", info->device_name)); in alloc_dma_bufs()
3428 reset_rbufs(info); in alloc_dma_bufs()
3432 static void free_dma_bufs(struct slgt_info *info) in free_dma_bufs() argument
3434 if (info->bufs) { in free_dma_bufs()
3435 free_bufs(info, info->rbufs, info->rbuf_count); in free_dma_bufs()
3436 free_bufs(info, info->tbufs, info->tbuf_count); in free_dma_bufs()
3437 free_desc(info); in free_dma_bufs()
3439 free_tmp_rbuf(info); in free_dma_bufs()
3442 static int claim_resources(struct slgt_info *info) in claim_resources() argument
3444 if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) { in claim_resources()
3446 info->device_name, info->phys_reg_addr)); in claim_resources()
3447 info->init_error = DiagStatus_AddressConflict; in claim_resources()
3451 info->reg_addr_requested = true; in claim_resources()
3453 info->reg_addr = ioremap_nocache(info->phys_reg_addr, SLGT_REG_SIZE); in claim_resources()
3454 if (!info->reg_addr) { in claim_resources()
3456 info->device_name, info->phys_reg_addr)); in claim_resources()
3457 info->init_error = DiagStatus_CantAssignPciResources; in claim_resources()
3463 release_resources(info); in claim_resources()
3467 static void release_resources(struct slgt_info *info) in release_resources() argument
3469 if (info->irq_requested) { in release_resources()
3470 free_irq(info->irq_level, info); in release_resources()
3471 info->irq_requested = false; in release_resources()
3474 if (info->reg_addr_requested) { in release_resources()
3475 release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); in release_resources()
3476 info->reg_addr_requested = false; in release_resources()
3479 if (info->reg_addr) { in release_resources()
3480 iounmap(info->reg_addr); in release_resources()
3481 info->reg_addr = NULL; in release_resources()
3488 static void add_device(struct slgt_info *info) in add_device() argument
3492 info->next_device = NULL; in add_device()
3493 info->line = slgt_device_count; in add_device()
3494 sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line); in add_device()
3496 if (info->line < MAX_DEVICES) { in add_device()
3497 if (maxframe[info->line]) in add_device()
3498 info->max_frame_size = maxframe[info->line]; in add_device()
3504 slgt_device_list = info; in add_device()
3509 current_dev->next_device = info; in add_device()
3512 if (info->max_frame_size < 4096) in add_device()
3513 info->max_frame_size = 4096; in add_device()
3514 else if (info->max_frame_size > 65535) in add_device()
3515 info->max_frame_size = 65535; in add_device()
3517 switch(info->pdev->device) { in add_device()
3529 info->params.mode = MGSL_MODE_ASYNC; in add_device()
3535 devstr, info->device_name, info->phys_reg_addr, in add_device()
3536 info->irq_level, info->max_frame_size); in add_device()
3539 hdlcdev_init(info); in add_device()
3553 struct slgt_info *info; in alloc_dev() local
3555 info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL); in alloc_dev()
3557 if (!info) { in alloc_dev()
3561 tty_port_init(&info->port); in alloc_dev()
3562 info->port.ops = &slgt_port_ops; in alloc_dev()
3563 info->magic = MGSL_MAGIC; in alloc_dev()
3564 INIT_WORK(&info->task, bh_handler); in alloc_dev()
3565 info->max_frame_size = 4096; in alloc_dev()
3566 info->base_clock = 14745600; in alloc_dev()
3567 info->rbuf_fill_level = DMABUFSIZE; in alloc_dev()
3568 info->port.close_delay = 5*HZ/10; in alloc_dev()
3569 info->port.closing_wait = 30*HZ; in alloc_dev()
3570 init_waitqueue_head(&info->status_event_wait_q); in alloc_dev()
3571 init_waitqueue_head(&info->event_wait_q); in alloc_dev()
3572 spin_lock_init(&info->netlock); in alloc_dev()
3573 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); in alloc_dev()
3574 info->idle_mode = HDLC_TXIDLE_FLAGS; in alloc_dev()
3575 info->adapter_num = adapter_num; in alloc_dev()
3576 info->port_num = port_num; in alloc_dev()
3578 timer_setup(&info->tx_timer, tx_timeout, 0); in alloc_dev()
3579 timer_setup(&info->rx_timer, rx_timeout, 0); in alloc_dev()
3581 /* Copy configuration info to device instance data */ in alloc_dev()
3582 info->pdev = pdev; in alloc_dev()
3583 info->irq_level = pdev->irq; in alloc_dev()
3584 info->phys_reg_addr = pci_resource_start(pdev,0); in alloc_dev()
3586 info->bus_type = MGSL_BUS_TYPE_PCI; in alloc_dev()
3587 info->irq_flags = IRQF_SHARED; in alloc_dev()
3589 info->init_error = -1; /* assume error, set to 0 on successful init */ in alloc_dev()
3592 return info; in alloc_dev()
3657 struct slgt_info *info = port_array[i]; in device_init() local
3658 tty_port_register_device(&info->port, serial_driver, info->line, in device_init()
3659 &info->pdev->dev); in device_init()
3708 struct slgt_info *info; in slgt_cleanup() local
3714 for (info=slgt_device_list ; info != NULL ; info=info->next_device) in slgt_cleanup()
3715 tty_unregister_device(serial_driver, info->line); in slgt_cleanup()
3723 info = slgt_device_list; in slgt_cleanup()
3724 while(info) { in slgt_cleanup()
3725 reset_port(info); in slgt_cleanup()
3726 info = info->next_device; in slgt_cleanup()
3730 info = slgt_device_list; in slgt_cleanup()
3731 while(info) { in slgt_cleanup()
3733 hdlcdev_exit(info); in slgt_cleanup()
3735 free_dma_bufs(info); in slgt_cleanup()
3736 free_tmp_rbuf(info); in slgt_cleanup()
3737 if (info->port_num == 0) in slgt_cleanup()
3738 release_resources(info); in slgt_cleanup()
3739 tmp = info; in slgt_cleanup()
3740 info = info->next_device; in slgt_cleanup()
3819 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3821 reg_addr += (info->port_num) * 32; \
3823 reg_addr += (info->port_num) * 16;
3825 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) in rd_reg8() argument
3831 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value) in wr_reg8() argument
3837 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr) in rd_reg16() argument
3843 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value) in wr_reg16() argument
3849 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr) in rd_reg32() argument
3855 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value) in wr_reg32() argument
3861 static void rdma_reset(struct slgt_info *info) in rdma_reset() argument
3866 wr_reg32(info, RDCSR, BIT1); in rdma_reset()
3870 if (!(rd_reg32(info, RDCSR) & BIT0)) in rdma_reset()
3874 static void tdma_reset(struct slgt_info *info) in tdma_reset() argument
3879 wr_reg32(info, TDCSR, BIT1); in tdma_reset()
3883 if (!(rd_reg32(info, TDCSR) & BIT0)) in tdma_reset()
3892 static void enable_loopback(struct slgt_info *info) in enable_loopback() argument
3895 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); in enable_loopback()
3897 if (info->params.mode != MGSL_MODE_ASYNC) { in enable_loopback()
3906 wr_reg8(info, CCR, 0x49); in enable_loopback()
3909 if (info->params.clock_speed) in enable_loopback()
3910 set_rate(info, info->params.clock_speed); in enable_loopback()
3912 set_rate(info, 3686400); in enable_loopback()
3919 static void set_rate(struct slgt_info *info, u32 rate) in set_rate() argument
3922 unsigned int osc = info->base_clock; in set_rate()
3934 wr_reg16(info, BDR, (unsigned short)div); in set_rate()
3938 static void rx_stop(struct slgt_info *info) in rx_stop() argument
3943 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_stop()
3944 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_stop()
3945 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_stop()
3947 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE); in rx_stop()
3950 wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER); in rx_stop()
3952 rdma_reset(info); in rx_stop()
3954 info->rx_enabled = false; in rx_stop()
3955 info->rx_restart = false; in rx_stop()
3958 static void rx_start(struct slgt_info *info) in rx_start() argument
3962 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA); in rx_start()
3965 wr_reg16(info, SSR, IRQ_RXOVER); in rx_start()
3968 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_start()
3969 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_start()
3970 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_start()
3972 rdma_reset(info); in rx_start()
3973 reset_rbufs(info); in rx_start()
3975 if (info->rx_pio) { in rx_start()
3977 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); in rx_start()
3978 slgt_irq_on(info, IRQ_RXDATA); in rx_start()
3979 if (info->params.mode == MGSL_MODE_ASYNC) { in rx_start()
3981 wr_reg32(info, RDCSR, BIT6); in rx_start()
3985 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); in rx_start()
3987 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); in rx_start()
3989 if (info->params.mode != MGSL_MODE_ASYNC) { in rx_start()
3991 wr_reg32(info, RDCSR, (BIT2 + BIT0)); in rx_start()
3994 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); in rx_start()
3998 slgt_irq_on(info, IRQ_RXOVER); in rx_start()
4001 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); in rx_start()
4003 info->rx_restart = false; in rx_start()
4004 info->rx_enabled = true; in rx_start()
4007 static void tx_start(struct slgt_info *info) in tx_start() argument
4009 if (!info->tx_enabled) { in tx_start()
4010 wr_reg16(info, TCR, in tx_start()
4011 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); in tx_start()
4012 info->tx_enabled = true; in tx_start()
4015 if (desc_count(info->tbufs[info->tbuf_start])) { in tx_start()
4016 info->drop_rts_on_tx_done = false; in tx_start()
4018 if (info->params.mode != MGSL_MODE_ASYNC) { in tx_start()
4019 if (info->params.flags & HDLC_FLAG_AUTO_RTS) { in tx_start()
4020 get_signals(info); in tx_start()
4021 if (!(info->signals & SerialSignal_RTS)) { in tx_start()
4022 info->signals |= SerialSignal_RTS; in tx_start()
4023 set_signals(info); in tx_start()
4024 info->drop_rts_on_tx_done = true; in tx_start()
4028 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
4029 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); in tx_start()
4031 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_start()
4033 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
4034 slgt_irq_on(info, IRQ_TXIDLE); in tx_start()
4036 wr_reg16(info, SSR, IRQ_TXIDLE); in tx_start()
4039 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); in tx_start()
4040 wr_reg32(info, TDCSR, BIT2 + BIT0); in tx_start()
4041 info->tx_active = true; in tx_start()
4045 static void tx_stop(struct slgt_info *info) in tx_stop() argument
4049 del_timer(&info->tx_timer); in tx_stop()
4051 tdma_reset(info); in tx_stop()
4054 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ in tx_stop()
4055 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in tx_stop()
4057 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in tx_stop()
4060 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_stop()
4062 reset_tbufs(info); in tx_stop()
4064 info->tx_enabled = false; in tx_stop()
4065 info->tx_active = false; in tx_stop()
4068 static void reset_port(struct slgt_info *info) in reset_port() argument
4070 if (!info->reg_addr) in reset_port()
4073 tx_stop(info); in reset_port()
4074 rx_stop(info); in reset_port()
4076 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in reset_port()
4077 set_signals(info); in reset_port()
4079 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in reset_port()
4082 static void reset_adapter(struct slgt_info *info) in reset_adapter() argument
4085 for (i=0; i < info->port_count; ++i) { in reset_adapter()
4086 if (info->port_array[i]) in reset_adapter()
4087 reset_port(info->port_array[i]); in reset_adapter()
4091 static void async_mode(struct slgt_info *info) in async_mode() argument
4095 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in async_mode()
4096 tx_stop(info); in async_mode()
4097 rx_stop(info); in async_mode()
4119 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in async_mode()
4122 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4124 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4128 switch (info->params.data_bits) in async_mode()
4135 if (info->params.stop_bits != 1) in async_mode()
4138 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in async_mode()
4141 wr_reg16(info, TCR, val); in async_mode()
4162 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4164 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4168 switch (info->params.data_bits) in async_mode()
4175 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in async_mode()
4178 wr_reg16(info, RCR, val); in async_mode()
4189 wr_reg8(info, CCR, 0x69); in async_mode()
4191 msc_set_vcr(info); in async_mode()
4214 if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate && in async_mode()
4215 ((info->base_clock < (info->params.data_rate * 16)) || in async_mode()
4216 (info->base_clock % (info->params.data_rate * 16)))) { in async_mode()
4219 set_rate(info, info->params.data_rate * 8); in async_mode()
4222 set_rate(info, info->params.data_rate * 16); in async_mode()
4224 wr_reg16(info, SCR, val); in async_mode()
4226 slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER); in async_mode()
4228 if (info->params.loopback) in async_mode()
4229 enable_loopback(info); in async_mode()
4232 static void sync_mode(struct slgt_info *info) in sync_mode() argument
4236 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in sync_mode()
4237 tx_stop(info); in sync_mode()
4238 rx_stop(info); in sync_mode()
4262 switch(info->params.mode) { in sync_mode()
4270 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in sync_mode()
4273 switch(info->params.encoding) in sync_mode()
4284 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4290 if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE) in sync_mode()
4293 switch (info->params.preamble_length) in sync_mode()
4300 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in sync_mode()
4303 wr_reg16(info, TCR, val); in sync_mode()
4307 switch (info->params.preamble) in sync_mode()
4316 wr_reg8(info, TPR, (unsigned char)val); in sync_mode()
4337 switch(info->params.mode) { in sync_mode()
4346 switch(info->params.encoding) in sync_mode()
4357 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4363 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in sync_mode()
4366 wr_reg16(info, RCR, val); in sync_mode()
4377 if (info->params.flags & HDLC_FLAG_TXC_BRG) in sync_mode()
4382 if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4387 else if (info->params.flags & HDLC_FLAG_TXC_DPLL) in sync_mode()
4389 else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN) in sync_mode()
4392 if (info->params.flags & HDLC_FLAG_RXC_BRG) in sync_mode()
4394 else if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4396 else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN) in sync_mode()
4399 if (info->params.clock_speed) in sync_mode()
4402 wr_reg8(info, CCR, (unsigned char)val); in sync_mode()
4404 if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL)) in sync_mode()
4407 switch(info->params.encoding) in sync_mode()
4417 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val)); in sync_mode()
4420 set_rate(info, info->params.clock_speed * 16); in sync_mode()
4423 set_rate(info, info->params.clock_speed); in sync_mode()
4425 tx_set_idle(info); in sync_mode()
4427 msc_set_vcr(info); in sync_mode()
4448 wr_reg16(info, SCR, BIT15 + BIT14 + BIT0); in sync_mode()
4450 if (info->params.loopback) in sync_mode()
4451 enable_loopback(info); in sync_mode()
4457 static void tx_set_idle(struct slgt_info *info) in tx_set_idle() argument
4465 tcr = rd_reg16(info, TCR); in tx_set_idle()
4466 if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) { in tx_set_idle()
4470 wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff)); in tx_set_idle()
4475 wr_reg16(info, TCR, tcr); in tx_set_idle()
4477 if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) { in tx_set_idle()
4479 val = (unsigned char)(info->idle_mode & 0xff); in tx_set_idle()
4482 switch(info->idle_mode) in tx_set_idle()
4493 wr_reg8(info, TIR, val); in tx_set_idle()
4499 static void get_signals(struct slgt_info *info) in get_signals() argument
4501 unsigned short status = rd_reg16(info, SSR); in get_signals()
4504 info->signals &= SerialSignal_RTS | SerialSignal_DTR; in get_signals()
4507 info->signals |= SerialSignal_DSR; in get_signals()
4509 info->signals |= SerialSignal_CTS; in get_signals()
4511 info->signals |= SerialSignal_DCD; in get_signals()
4513 info->signals |= SerialSignal_RI; in get_signals()
4519 static void msc_set_vcr(struct slgt_info *info) in msc_set_vcr() argument
4532 switch(info->if_mode & MGSL_INTERFACE_MASK) in msc_set_vcr()
4545 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST) in msc_set_vcr()
4547 if (info->signals & SerialSignal_DTR) in msc_set_vcr()
4549 if (info->signals & SerialSignal_RTS) in msc_set_vcr()
4551 if (info->if_mode & MGSL_INTERFACE_LL) in msc_set_vcr()
4553 if (info->if_mode & MGSL_INTERFACE_RL) in msc_set_vcr()
4555 wr_reg8(info, VCR, val); in msc_set_vcr()
4561 static void set_signals(struct slgt_info *info) in set_signals() argument
4563 unsigned char val = rd_reg8(info, VCR); in set_signals()
4564 if (info->signals & SerialSignal_DTR) in set_signals()
4568 if (info->signals & SerialSignal_RTS) in set_signals()
4572 wr_reg8(info, VCR, val); in set_signals()
4578 static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last) in free_rbufs() argument
4584 info->rbufs[i].status = 0; in free_rbufs()
4585 set_desc_count(info->rbufs[i], info->rbuf_fill_level); in free_rbufs()
4588 if (++i == info->rbuf_count) in free_rbufs()
4591 info->rbuf_current = i; in free_rbufs()
4597 static void reset_rbufs(struct slgt_info *info) in reset_rbufs() argument
4599 free_rbufs(info, 0, info->rbuf_count - 1); in reset_rbufs()
4600 info->rbuf_fill_index = 0; in reset_rbufs()
4601 info->rbuf_fill_count = 0; in reset_rbufs()
4609 static bool rx_get_frame(struct slgt_info *info) in rx_get_frame() argument
4615 struct tty_struct *tty = info->port.tty; in rx_get_frame()
4619 switch (info->params.crc_type & HDLC_CRC_MASK) { in rx_get_frame()
4628 start = end = info->rbuf_current; in rx_get_frame()
4631 if (!desc_complete(info->rbufs[end])) in rx_get_frame()
4634 if (framesize == 0 && info->params.addr_filter != 0xff) in rx_get_frame()
4635 addr_field = info->rbufs[end].buf[0]; in rx_get_frame()
4637 framesize += desc_count(info->rbufs[end]); in rx_get_frame()
4639 if (desc_eof(info->rbufs[end])) in rx_get_frame()
4642 if (++end == info->rbuf_count) in rx_get_frame()
4645 if (end == info->rbuf_current) { in rx_get_frame()
4646 if (info->rx_enabled){ in rx_get_frame()
4647 spin_lock_irqsave(&info->lock,flags); in rx_get_frame()
4648 rx_start(info); in rx_get_frame()
4649 spin_unlock_irqrestore(&info->lock,flags); in rx_get_frame()
4664 status = desc_status(info->rbufs[end]); in rx_get_frame()
4667 if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE) in rx_get_frame()
4671 (addr_field != 0xff && addr_field != info->params.addr_filter)) { in rx_get_frame()
4672 free_rbufs(info, start, end); in rx_get_frame()
4677 info->icount.rxshort++; in rx_get_frame()
4680 info->icount.rxcrc++; in rx_get_frame()
4681 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) in rx_get_frame()
4687 info->netdev->stats.rx_errors++; in rx_get_frame()
4688 info->netdev->stats.rx_frame_errors++; in rx_get_frame()
4693 info->device_name, status, framesize)); in rx_get_frame()
4694 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx"); in rx_get_frame()
4697 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { in rx_get_frame()
4702 if (framesize > info->max_frame_size + crc_size) in rx_get_frame()
4703 info->icount.rxlong++; in rx_get_frame()
4708 unsigned char *p = info->tmp_rbuf; in rx_get_frame()
4709 info->tmp_rbuf_count = framesize; in rx_get_frame()
4711 info->icount.rxok++; in rx_get_frame()
4714 int partial_count = min_t(int, copy_count, info->rbuf_fill_level); in rx_get_frame()
4715 memcpy(p, info->rbufs[i].buf, partial_count); in rx_get_frame()
4718 if (++i == info->rbuf_count) in rx_get_frame()
4722 if (info->params.crc_type & HDLC_CRC_RETURN_EX) { in rx_get_frame()
4728 if (info->netcount) in rx_get_frame()
4729 hdlcdev_rx(info,info->tmp_rbuf, framesize); in rx_get_frame()
4732 ldisc_receive_buf(tty, info->tmp_rbuf, info->flag_buf, framesize); in rx_get_frame()
4735 free_rbufs(info, start, end); in rx_get_frame()
4746 static bool rx_get_buf(struct slgt_info *info) in rx_get_buf() argument
4748 unsigned int i = info->rbuf_current; in rx_get_buf()
4751 if (!desc_complete(info->rbufs[i])) in rx_get_buf()
4753 count = desc_count(info->rbufs[i]); in rx_get_buf()
4754 switch(info->params.mode) { in rx_get_buf()
4759 if (desc_residue(info->rbufs[i])) in rx_get_buf()
4763 DBGDATA(info, info->rbufs[i].buf, count, "rx"); in rx_get_buf()
4766 ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, in rx_get_buf()
4767 info->flag_buf, count); in rx_get_buf()
4768 free_rbufs(info, i, i); in rx_get_buf()
4772 static void reset_tbufs(struct slgt_info *info) in reset_tbufs() argument
4775 info->tbuf_current = 0; in reset_tbufs()
4776 for (i=0 ; i < info->tbuf_count ; i++) { in reset_tbufs()
4777 info->tbufs[i].status = 0; in reset_tbufs()
4778 info->tbufs[i].count = 0; in reset_tbufs()
4785 static unsigned int free_tbuf_count(struct slgt_info *info) in free_tbuf_count() argument
4788 unsigned int i = info->tbuf_current; in free_tbuf_count()
4792 if (desc_count(info->tbufs[i])) in free_tbuf_count()
4795 if (++i == info->tbuf_count) in free_tbuf_count()
4797 } while (i != info->tbuf_current); in free_tbuf_count()
4800 if (count && (rd_reg32(info, TDCSR) & BIT0)) in free_tbuf_count()
4810 static unsigned int tbuf_bytes(struct slgt_info *info) in tbuf_bytes() argument
4813 unsigned int i = info->tbuf_current; in tbuf_bytes()
4830 count = desc_count(info->tbufs[i]); in tbuf_bytes()
4834 active_buf_count = info->tbufs[i].buf_count; in tbuf_bytes()
4835 if (++i == info->tbuf_count) in tbuf_bytes()
4837 } while (i != info->tbuf_current); in tbuf_bytes()
4840 reg_value = rd_reg32(info, TDCSR); in tbuf_bytes()
4850 if (info->tx_active) in tbuf_bytes()
4860 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) in tx_load() argument
4867 if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) in tx_load()
4870 DBGDATA(info, buf, size, "tx"); in tx_load()
4883 info->tbuf_start = i = info->tbuf_current; in tx_load()
4886 d = &info->tbufs[i]; in tx_load()
4898 if ((!size && info->params.mode == MGSL_MODE_HDLC) || in tx_load()
4899 info->params.mode == MGSL_MODE_RAW) in tx_load()
4905 if (i != info->tbuf_start) in tx_load()
4909 if (++i == info->tbuf_count) in tx_load()
4913 info->tbuf_current = i; in tx_load()
4916 d = &info->tbufs[info->tbuf_start]; in tx_load()
4920 if (!info->tx_active) in tx_load()
4921 tx_start(info); in tx_load()
4922 update_tx_timer(info); in tx_load()
4927 static int register_test(struct slgt_info *info) in register_test() argument
4936 wr_reg16(info, TIR, patterns[i]); in register_test()
4937 wr_reg16(info, BDR, patterns[(i+1)%count]); in register_test()
4938 if ((rd_reg16(info, TIR) != patterns[i]) || in register_test()
4939 (rd_reg16(info, BDR) != patterns[(i+1)%count])) { in register_test()
4944 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0; in register_test()
4945 info->init_error = rc ? 0 : DiagStatus_AddressFailure; in register_test()
4949 static int irq_test(struct slgt_info *info) in irq_test() argument
4953 struct tty_struct *oldtty = info->port.tty; in irq_test()
4954 u32 speed = info->params.data_rate; in irq_test()
4956 info->params.data_rate = 921600; in irq_test()
4957 info->port.tty = NULL; in irq_test()
4959 spin_lock_irqsave(&info->lock, flags); in irq_test()
4960 async_mode(info); in irq_test()
4961 slgt_irq_on(info, IRQ_TXIDLE); in irq_test()
4964 wr_reg16(info, TCR, in irq_test()
4965 (unsigned short)(rd_reg16(info, TCR) | BIT1)); in irq_test()
4968 wr_reg16(info, TDR, 0); in irq_test()
4971 info->init_error = DiagStatus_IrqFailure; in irq_test()
4972 info->irq_occurred = false; in irq_test()
4974 spin_unlock_irqrestore(&info->lock, flags); in irq_test()
4977 while(timeout-- && !info->irq_occurred) in irq_test()
4980 spin_lock_irqsave(&info->lock,flags); in irq_test()
4981 reset_port(info); in irq_test()
4982 spin_unlock_irqrestore(&info->lock,flags); in irq_test()
4984 info->params.data_rate = speed; in irq_test()
4985 info->port.tty = oldtty; in irq_test()
4987 info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure; in irq_test()
4988 return info->irq_occurred ? 0 : -ENODEV; in irq_test()
4991 static int loopback_test_rx(struct slgt_info *info) in loopback_test_rx() argument
4996 if (desc_complete(info->rbufs[0])) { in loopback_test_rx()
4997 count = desc_count(info->rbufs[0]); in loopback_test_rx()
4998 src = info->rbufs[0].buf; in loopback_test_rx()
4999 dest = info->tmp_rbuf; in loopback_test_rx()
5006 info->tmp_rbuf_count++; in loopback_test_rx()
5009 DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx"); in loopback_test_rx()
5015 static int loopback_test(struct slgt_info *info) in loopback_test() argument
5025 struct tty_struct *oldtty = info->port.tty; in loopback_test()
5028 memcpy(¶ms, &info->params, sizeof(params)); in loopback_test()
5030 info->params.mode = MGSL_MODE_ASYNC; in loopback_test()
5031 info->params.data_rate = 921600; in loopback_test()
5032 info->params.loopback = 1; in loopback_test()
5033 info->port.tty = NULL; in loopback_test()
5039 info->tmp_rbuf_count = 0; in loopback_test()
5040 memset(info->tmp_rbuf, 0, TESTFRAMESIZE); in loopback_test()
5043 spin_lock_irqsave(&info->lock,flags); in loopback_test()
5044 async_mode(info); in loopback_test()
5045 rx_start(info); in loopback_test()
5046 tx_load(info, buf, count); in loopback_test()
5047 spin_unlock_irqrestore(&info->lock, flags); in loopback_test()
5052 if (loopback_test_rx(info)) { in loopback_test()
5059 if (!rc && (info->tmp_rbuf_count != count || in loopback_test()
5060 memcmp(buf, info->tmp_rbuf, count))) { in loopback_test()
5064 spin_lock_irqsave(&info->lock,flags); in loopback_test()
5065 reset_adapter(info); in loopback_test()
5066 spin_unlock_irqrestore(&info->lock,flags); in loopback_test()
5068 memcpy(&info->params, ¶ms, sizeof(info->params)); in loopback_test()
5069 info->port.tty = oldtty; in loopback_test()
5071 info->init_error = rc ? DiagStatus_DmaFailure : 0; in loopback_test()
5075 static int adapter_test(struct slgt_info *info) in adapter_test() argument
5077 DBGINFO(("testing %s\n", info->device_name)); in adapter_test()
5078 if (register_test(info) < 0) { in adapter_test()
5080 info->device_name, info->phys_reg_addr); in adapter_test()
5081 } else if (irq_test(info) < 0) { in adapter_test()
5083 info->device_name, info->irq_level); in adapter_test()
5084 } else if (loopback_test(info) < 0) { in adapter_test()
5085 printk("loopback test failure %s\n", info->device_name); in adapter_test()
5087 return info->init_error; in adapter_test()
5095 struct slgt_info *info = from_timer(info, t, tx_timer); in tx_timeout() local
5098 DBGINFO(("%s tx_timeout\n", info->device_name)); in tx_timeout()
5099 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) { in tx_timeout()
5100 info->icount.txtimeout++; in tx_timeout()
5102 spin_lock_irqsave(&info->lock,flags); in tx_timeout()
5103 tx_stop(info); in tx_timeout()
5104 spin_unlock_irqrestore(&info->lock,flags); in tx_timeout()
5107 if (info->netcount) in tx_timeout()
5108 hdlcdev_tx_done(info); in tx_timeout()
5111 bh_transmit(info); in tx_timeout()
5119 struct slgt_info *info = from_timer(info, t, rx_timer); in rx_timeout() local
5122 DBGINFO(("%s rx_timeout\n", info->device_name)); in rx_timeout()
5123 spin_lock_irqsave(&info->lock, flags); in rx_timeout()
5124 info->pending_bh |= BH_RECEIVE; in rx_timeout()
5125 spin_unlock_irqrestore(&info->lock, flags); in rx_timeout()
5126 bh_handler(&info->task); in rx_timeout()