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)*/
400 #define slgt_irq_on(info, mask) \ argument
401 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
402 #define slgt_irq_off(info, mask) \ argument
403 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
405 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
406 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
407 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
408 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
409 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
410 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
412 static void msc_set_vcr(struct slgt_info *info);
414 static int startup(struct slgt_info *info);
415 static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
416 static void shutdown(struct slgt_info *info);
417 static void program_hw(struct slgt_info *info);
418 static void change_params(struct slgt_info *info);
420 static int adapter_test(struct slgt_info *info);
422 static void reset_port(struct slgt_info *info);
423 static void async_mode(struct slgt_info *info);
424 static void sync_mode(struct slgt_info *info);
426 static void rx_stop(struct slgt_info *info);
427 static void rx_start(struct slgt_info *info);
428 static void reset_rbufs(struct slgt_info *info);
429 static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
430 static bool rx_get_frame(struct slgt_info *info);
431 static bool rx_get_buf(struct slgt_info *info);
433 static void tx_start(struct slgt_info *info);
434 static void tx_stop(struct slgt_info *info);
435 static void tx_set_idle(struct slgt_info *info);
436 static unsigned int tbuf_bytes(struct slgt_info *info);
437 static void reset_tbufs(struct slgt_info *info);
438 static void tdma_reset(struct slgt_info *info);
439 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
441 static void get_gtsignals(struct slgt_info *info);
442 static void set_gtsignals(struct slgt_info *info);
443 static void set_rate(struct slgt_info *info, u32 data_rate);
445 static void bh_transmit(struct slgt_info *info);
446 static void isr_txeom(struct slgt_info *info, unsigned short status);
454 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
455 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
456 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
457 static int get_txidle(struct slgt_info *info, int __user *idle_mode);
458 static int set_txidle(struct slgt_info *info, int idle_mode);
459 static int tx_enable(struct slgt_info *info, int enable);
460 static int tx_abort(struct slgt_info *info);
461 static int rx_enable(struct slgt_info *info, int enable);
462 static int modem_input_wait(struct slgt_info *info,int arg);
463 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
464 static int get_interface(struct slgt_info *info, int __user *if_mode);
465 static int set_interface(struct slgt_info *info, int if_mode);
466 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
467 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
468 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
469 static int get_xsync(struct slgt_info *info, int __user *if_mode);
470 static int set_xsync(struct slgt_info *info, int if_mode);
471 static int get_xctrl(struct slgt_info *info, int __user *if_mode);
472 static int set_xctrl(struct slgt_info *info, int if_mode);
477 static void release_resources(struct slgt_info *info);
496 static void trace_block(struct slgt_info *info, const char *data, int count, const char *label) in trace_block() argument
500 printk("%s %s data:\n",info->device_name, label); in trace_block()
519 #define DBGDATA(info, buf, size, label) argument
523 static void dump_tbufs(struct slgt_info *info) in dump_tbufs() argument
526 printk("tbuf_current=%d\n", info->tbuf_current); in dump_tbufs()
527 for (i=0 ; i < info->tbuf_count ; i++) { in dump_tbufs()
529 i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status)); in dump_tbufs()
533 #define DBGTBUF(info) argument
537 static void dump_rbufs(struct slgt_info *info) in dump_rbufs() argument
540 printk("rbuf_current=%d\n", info->rbuf_current); in dump_rbufs()
541 for (i=0 ; i < info->rbuf_count ; i++) { in dump_rbufs()
543 i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status)); in dump_rbufs()
547 #define DBGRBUF(info) argument
550 static inline int sanity_check(struct slgt_info *info, char *devname, const char *name) in sanity_check() argument
553 if (!info) { in sanity_check()
557 if (info->magic != MGSL_MAGIC) { in sanity_check()
562 if (!info) in sanity_check()
594 struct slgt_info *info; in open() local
604 info = slgt_device_list; in open()
605 while(info && info->line != line) in open()
606 info = info->next_device; in open()
607 if (sanity_check(info, tty->name, "open")) in open()
609 if (info->init_error) { in open()
610 DBGERR(("%s init error=%d\n", info->device_name, info->init_error)); in open()
614 tty->driver_data = info; in open()
615 info->port.tty = tty; in open()
617 DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count)); in open()
619 mutex_lock(&info->port.mutex); in open()
621 spin_lock_irqsave(&info->netlock, flags); in open()
622 if (info->netcount) { in open()
624 spin_unlock_irqrestore(&info->netlock, flags); in open()
625 mutex_unlock(&info->port.mutex); in open()
628 info->port.count++; in open()
629 spin_unlock_irqrestore(&info->netlock, flags); in open()
631 if (info->port.count == 1) { in open()
633 retval = startup(info); in open()
635 mutex_unlock(&info->port.mutex); in open()
639 mutex_unlock(&info->port.mutex); in open()
640 retval = block_til_ready(tty, filp, info); in open()
642 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); in open()
651 info->port.tty = NULL; /* tty layer will release tty struct */ in open()
652 if(info->port.count) in open()
653 info->port.count--; in open()
656 DBGINFO(("%s open rc=%d\n", info->device_name, retval)); in open()
662 struct slgt_info *info = tty->driver_data; in close() local
664 if (sanity_check(info, tty->name, "close")) in close()
666 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); in close()
668 if (tty_port_close_start(&info->port, tty, filp) == 0) in close()
671 mutex_lock(&info->port.mutex); in close()
672 if (tty_port_initialized(&info->port)) in close()
673 wait_until_sent(tty, info->timeout); in close()
677 shutdown(info); in close()
678 mutex_unlock(&info->port.mutex); in close()
680 tty_port_close_end(&info->port, tty); in close()
681 info->port.tty = NULL; in close()
683 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); in close()
688 struct slgt_info *info = tty->driver_data; in hangup() local
691 if (sanity_check(info, tty->name, "hangup")) in hangup()
693 DBGINFO(("%s hangup\n", info->device_name)); in hangup()
697 mutex_lock(&info->port.mutex); in hangup()
698 shutdown(info); in hangup()
700 spin_lock_irqsave(&info->port.lock, flags); in hangup()
701 info->port.count = 0; in hangup()
702 info->port.tty = NULL; in hangup()
703 spin_unlock_irqrestore(&info->port.lock, flags); in hangup()
704 tty_port_set_active(&info->port, 0); in hangup()
705 mutex_unlock(&info->port.mutex); in hangup()
707 wake_up_interruptible(&info->port.open_wait); in hangup()
712 struct slgt_info *info = tty->driver_data; in set_termios() local
717 change_params(info); in set_termios()
721 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in set_termios()
722 spin_lock_irqsave(&info->lock,flags); in set_termios()
723 set_gtsignals(info); in set_termios()
724 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
729 info->signals |= SerialSignal_DTR; in set_termios()
731 info->signals |= SerialSignal_RTS; in set_termios()
732 spin_lock_irqsave(&info->lock,flags); in set_termios()
733 set_gtsignals(info); in set_termios()
734 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
744 static void update_tx_timer(struct slgt_info *info) in update_tx_timer() argument
750 if (info->params.mode == MGSL_MODE_HDLC) { in update_tx_timer()
751 int timeout = (tbuf_bytes(info) * 7) + 1000; in update_tx_timer()
752 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout)); in update_tx_timer()
760 struct slgt_info *info = tty->driver_data; in write() local
763 if (sanity_check(info, tty->name, "write")) in write()
766 DBGINFO(("%s write count=%d\n", info->device_name, count)); in write()
768 if (!info->tx_buf || (count > info->max_frame_size)) in write()
774 spin_lock_irqsave(&info->lock, flags); in write()
776 if (info->tx_count) { in write()
778 if (!tx_load(info, info->tx_buf, info->tx_count)) in write()
780 info->tx_count = 0; in write()
783 if (tx_load(info, buf, count)) in write()
787 spin_unlock_irqrestore(&info->lock, flags); in write()
788 DBGINFO(("%s write rc=%d\n", info->device_name, ret)); in write()
794 struct slgt_info *info = tty->driver_data; in put_char() local
798 if (sanity_check(info, tty->name, "put_char")) in put_char()
800 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); in put_char()
801 if (!info->tx_buf) in put_char()
803 spin_lock_irqsave(&info->lock,flags); in put_char()
804 if (info->tx_count < info->max_frame_size) { in put_char()
805 info->tx_buf[info->tx_count++] = ch; in put_char()
808 spin_unlock_irqrestore(&info->lock,flags); in put_char()
814 struct slgt_info *info = tty->driver_data; in send_xchar() local
817 if (sanity_check(info, tty->name, "send_xchar")) in send_xchar()
819 DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch)); in send_xchar()
820 info->x_char = ch; in send_xchar()
822 spin_lock_irqsave(&info->lock,flags); in send_xchar()
823 if (!info->tx_enabled) in send_xchar()
824 tx_start(info); in send_xchar()
825 spin_unlock_irqrestore(&info->lock,flags); in send_xchar()
831 struct slgt_info *info = tty->driver_data; in wait_until_sent() local
834 if (!info ) in wait_until_sent()
836 if (sanity_check(info, tty->name, "wait_until_sent")) in wait_until_sent()
838 DBGINFO(("%s wait_until_sent entry\n", info->device_name)); in wait_until_sent()
839 if (!tty_port_initialized(&info->port)) in wait_until_sent()
850 if (info->params.data_rate) { in wait_until_sent()
851 char_time = info->timeout/(32 * 5); in wait_until_sent()
860 while (info->tx_active) { in wait_until_sent()
868 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); in wait_until_sent()
873 struct slgt_info *info = tty->driver_data; in write_room() local
876 if (sanity_check(info, tty->name, "write_room")) in write_room()
878 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; in write_room()
879 DBGINFO(("%s write_room=%u\n", info->device_name, ret)); in write_room()
885 struct slgt_info *info = tty->driver_data; in flush_chars() local
888 if (sanity_check(info, tty->name, "flush_chars")) in flush_chars()
890 DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count)); in flush_chars()
892 if (info->tx_count <= 0 || tty->flow.stopped || in flush_chars()
893 tty->hw_stopped || !info->tx_buf) in flush_chars()
896 DBGINFO(("%s flush_chars start transmit\n", info->device_name)); in flush_chars()
898 spin_lock_irqsave(&info->lock,flags); in flush_chars()
899 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in flush_chars()
900 info->tx_count = 0; in flush_chars()
901 spin_unlock_irqrestore(&info->lock,flags); in flush_chars()
906 struct slgt_info *info = tty->driver_data; in flush_buffer() local
909 if (sanity_check(info, tty->name, "flush_buffer")) in flush_buffer()
911 DBGINFO(("%s flush_buffer\n", info->device_name)); in flush_buffer()
913 spin_lock_irqsave(&info->lock, flags); in flush_buffer()
914 info->tx_count = 0; in flush_buffer()
915 spin_unlock_irqrestore(&info->lock, flags); in flush_buffer()
925 struct slgt_info *info = tty->driver_data; in tx_hold() local
928 if (sanity_check(info, tty->name, "tx_hold")) in tx_hold()
930 DBGINFO(("%s tx_hold\n", info->device_name)); in tx_hold()
931 spin_lock_irqsave(&info->lock,flags); in tx_hold()
932 if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC) in tx_hold()
933 tx_stop(info); in tx_hold()
934 spin_unlock_irqrestore(&info->lock,flags); in tx_hold()
942 struct slgt_info *info = tty->driver_data; in tx_release() local
945 if (sanity_check(info, tty->name, "tx_release")) in tx_release()
947 DBGINFO(("%s tx_release\n", info->device_name)); in tx_release()
948 spin_lock_irqsave(&info->lock, flags); in tx_release()
949 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in tx_release()
950 info->tx_count = 0; in tx_release()
951 spin_unlock_irqrestore(&info->lock, flags); in tx_release()
968 struct slgt_info *info = tty->driver_data; in ioctl() local
972 if (sanity_check(info, tty->name, "ioctl")) in ioctl()
974 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); in ioctl()
983 return wait_mgsl_event(info, argp); in ioctl()
985 return modem_input_wait(info,(int)arg); in ioctl()
987 return set_gpio(info, argp); in ioctl()
989 return get_gpio(info, argp); in ioctl()
991 return wait_gpio(info, argp); in ioctl()
993 return get_xsync(info, argp); in ioctl()
995 return set_xsync(info, (int)arg); in ioctl()
997 return get_xctrl(info, argp); in ioctl()
999 return set_xctrl(info, (int)arg); in ioctl()
1001 mutex_lock(&info->port.mutex); in ioctl()
1004 ret = get_params(info, argp); in ioctl()
1007 ret = set_params(info, argp); in ioctl()
1010 ret = get_txidle(info, argp); in ioctl()
1013 ret = set_txidle(info, (int)arg); in ioctl()
1016 ret = tx_enable(info, (int)arg); in ioctl()
1019 ret = rx_enable(info, (int)arg); in ioctl()
1022 ret = tx_abort(info); in ioctl()
1025 ret = get_stats(info, argp); in ioctl()
1028 ret = get_interface(info, argp); in ioctl()
1031 ret = set_interface(info,(int)arg); in ioctl()
1036 mutex_unlock(&info->port.mutex); in ioctl()
1044 struct slgt_info *info = tty->driver_data; in get_icount() local
1048 spin_lock_irqsave(&info->lock,flags); in get_icount()
1049 cnow = info->icount; in get_icount()
1050 spin_unlock_irqrestore(&info->lock,flags); in get_icount()
1071 static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params) in get_params32() argument
1075 DBGINFO(("%s get_params32\n", info->device_name)); in get_params32()
1077 tmp_params.mode = (compat_ulong_t)info->params.mode; in get_params32()
1078 tmp_params.loopback = info->params.loopback; in get_params32()
1079 tmp_params.flags = info->params.flags; in get_params32()
1080 tmp_params.encoding = info->params.encoding; in get_params32()
1081 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed; in get_params32()
1082 tmp_params.addr_filter = info->params.addr_filter; in get_params32()
1083 tmp_params.crc_type = info->params.crc_type; in get_params32()
1084 tmp_params.preamble_length = info->params.preamble_length; in get_params32()
1085 tmp_params.preamble = info->params.preamble; in get_params32()
1086 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate; in get_params32()
1087 tmp_params.data_bits = info->params.data_bits; in get_params32()
1088 tmp_params.stop_bits = info->params.stop_bits; in get_params32()
1089 tmp_params.parity = info->params.parity; in get_params32()
1095 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params) in set_params32() argument
1099 DBGINFO(("%s set_params32\n", info->device_name)); in set_params32()
1103 spin_lock(&info->lock); in set_params32()
1105 info->base_clock = tmp_params.clock_speed; in set_params32()
1107 info->params.mode = tmp_params.mode; in set_params32()
1108 info->params.loopback = tmp_params.loopback; in set_params32()
1109 info->params.flags = tmp_params.flags; in set_params32()
1110 info->params.encoding = tmp_params.encoding; in set_params32()
1111 info->params.clock_speed = tmp_params.clock_speed; in set_params32()
1112 info->params.addr_filter = tmp_params.addr_filter; in set_params32()
1113 info->params.crc_type = tmp_params.crc_type; in set_params32()
1114 info->params.preamble_length = tmp_params.preamble_length; in set_params32()
1115 info->params.preamble = tmp_params.preamble; in set_params32()
1116 info->params.data_rate = tmp_params.data_rate; in set_params32()
1117 info->params.data_bits = tmp_params.data_bits; in set_params32()
1118 info->params.stop_bits = tmp_params.stop_bits; in set_params32()
1119 info->params.parity = tmp_params.parity; in set_params32()
1121 spin_unlock(&info->lock); in set_params32()
1123 program_hw(info); in set_params32()
1131 struct slgt_info *info = tty->driver_data; in slgt_compat_ioctl() local
1134 if (sanity_check(info, tty->name, "compat_ioctl")) in slgt_compat_ioctl()
1136 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd)); in slgt_compat_ioctl()
1140 rc = set_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1144 rc = get_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1163 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc)); in slgt_compat_ioctl()
1173 static inline void line_info(struct seq_file *m, struct slgt_info *info) in line_info() argument
1179 info->device_name, info->phys_reg_addr, in line_info()
1180 info->irq_level, info->max_frame_size); in line_info()
1183 spin_lock_irqsave(&info->lock,flags); in line_info()
1184 get_gtsignals(info); in line_info()
1185 spin_unlock_irqrestore(&info->lock,flags); in line_info()
1189 if (info->signals & SerialSignal_RTS) in line_info()
1191 if (info->signals & SerialSignal_CTS) in line_info()
1193 if (info->signals & SerialSignal_DTR) in line_info()
1195 if (info->signals & SerialSignal_DSR) in line_info()
1197 if (info->signals & SerialSignal_DCD) in line_info()
1199 if (info->signals & SerialSignal_RI) in line_info()
1202 if (info->params.mode != MGSL_MODE_ASYNC) { in line_info()
1204 info->icount.txok, info->icount.rxok); in line_info()
1205 if (info->icount.txunder) in line_info()
1206 seq_printf(m, " txunder:%d", info->icount.txunder); in line_info()
1207 if (info->icount.txabort) in line_info()
1208 seq_printf(m, " txabort:%d", info->icount.txabort); in line_info()
1209 if (info->icount.rxshort) in line_info()
1210 seq_printf(m, " rxshort:%d", info->icount.rxshort); in line_info()
1211 if (info->icount.rxlong) in line_info()
1212 seq_printf(m, " rxlong:%d", info->icount.rxlong); in line_info()
1213 if (info->icount.rxover) in line_info()
1214 seq_printf(m, " rxover:%d", info->icount.rxover); in line_info()
1215 if (info->icount.rxcrc) in line_info()
1216 seq_printf(m, " rxcrc:%d", info->icount.rxcrc); in line_info()
1219 info->icount.tx, info->icount.rx); in line_info()
1220 if (info->icount.frame) in line_info()
1221 seq_printf(m, " fe:%d", info->icount.frame); in line_info()
1222 if (info->icount.parity) in line_info()
1223 seq_printf(m, " pe:%d", info->icount.parity); in line_info()
1224 if (info->icount.brk) in line_info()
1225 seq_printf(m, " brk:%d", info->icount.brk); in line_info()
1226 if (info->icount.overrun) in line_info()
1227 seq_printf(m, " oe:%d", info->icount.overrun); in line_info()
1234 info->tx_active,info->bh_requested,info->bh_running, in line_info()
1235 info->pending_bh); in line_info()
1242 struct slgt_info *info; in synclink_gt_proc_show() local
1246 info = slgt_device_list; in synclink_gt_proc_show()
1247 while( info ) { in synclink_gt_proc_show()
1248 line_info(m, info); in synclink_gt_proc_show()
1249 info = info->next_device; in synclink_gt_proc_show()
1259 struct slgt_info *info = tty->driver_data; in chars_in_buffer() local
1261 if (sanity_check(info, tty->name, "chars_in_buffer")) in chars_in_buffer()
1263 count = tbuf_bytes(info); in chars_in_buffer()
1264 DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count)); in chars_in_buffer()
1273 struct slgt_info *info = tty->driver_data; in throttle() local
1276 if (sanity_check(info, tty->name, "throttle")) in throttle()
1278 DBGINFO(("%s throttle\n", info->device_name)); in throttle()
1282 spin_lock_irqsave(&info->lock,flags); in throttle()
1283 info->signals &= ~SerialSignal_RTS; in throttle()
1284 set_gtsignals(info); in throttle()
1285 spin_unlock_irqrestore(&info->lock,flags); in throttle()
1294 struct slgt_info *info = tty->driver_data; in unthrottle() local
1297 if (sanity_check(info, tty->name, "unthrottle")) in unthrottle()
1299 DBGINFO(("%s unthrottle\n", info->device_name)); in unthrottle()
1301 if (info->x_char) in unthrottle()
1302 info->x_char = 0; in unthrottle()
1307 spin_lock_irqsave(&info->lock,flags); in unthrottle()
1308 info->signals |= SerialSignal_RTS; in unthrottle()
1309 set_gtsignals(info); in unthrottle()
1310 spin_unlock_irqrestore(&info->lock,flags); in unthrottle()
1320 struct slgt_info *info = tty->driver_data; in set_break() local
1324 if (sanity_check(info, tty->name, "set_break")) in set_break()
1326 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); in set_break()
1328 spin_lock_irqsave(&info->lock,flags); in set_break()
1329 value = rd_reg16(info, TCR); in set_break()
1334 wr_reg16(info, TCR, value); in set_break()
1335 spin_unlock_irqrestore(&info->lock,flags); in set_break()
1354 struct slgt_info *info = dev_to_port(dev); in hdlcdev_attach() local
1359 if (info->port.count) in hdlcdev_attach()
1362 DBGINFO(("%s hdlcdev_attach\n", info->device_name)); in hdlcdev_attach()
1382 info->params.encoding = new_encoding; in hdlcdev_attach()
1383 info->params.crc_type = new_crctype; in hdlcdev_attach()
1386 if (info->netcount) in hdlcdev_attach()
1387 program_hw(info); in hdlcdev_attach()
1400 struct slgt_info *info = dev_to_port(dev); in hdlcdev_xmit() local
1418 spin_lock_irqsave(&info->lock, flags); in hdlcdev_xmit()
1419 tx_load(info, skb->data, skb->len); in hdlcdev_xmit()
1420 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_xmit()
1438 struct slgt_info *info = dev_to_port(dev); in hdlcdev_open() local
1453 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1454 if (info->port.count != 0 || info->netcount != 0) { in hdlcdev_open()
1456 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1459 info->netcount=1; in hdlcdev_open()
1460 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1463 if ((rc = startup(info)) != 0) { in hdlcdev_open()
1464 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1465 info->netcount=0; in hdlcdev_open()
1466 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1471 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in hdlcdev_open()
1472 program_hw(info); in hdlcdev_open()
1479 spin_lock_irqsave(&info->lock, flags); in hdlcdev_open()
1480 get_gtsignals(info); in hdlcdev_open()
1481 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_open()
1482 if (info->signals & SerialSignal_DCD) in hdlcdev_open()
1499 struct slgt_info *info = dev_to_port(dev); in hdlcdev_close() local
1507 shutdown(info); in hdlcdev_close()
1511 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_close()
1512 info->netcount=0; in hdlcdev_close()
1513 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_close()
1532 struct slgt_info *info = dev_to_port(dev); in hdlcdev_ioctl() local
1538 if (info->port.count) in hdlcdev_ioctl()
1552 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1565 new_line.clock_rate = info->params.clock_speed; in hdlcdev_ioctl()
1566 new_line.loopback = info->params.loopback ? 1:0; in hdlcdev_ioctl()
1585 case CLOCK_DEFAULT: flags = info->params.flags & in hdlcdev_ioctl()
1596 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1600 info->params.flags |= flags; in hdlcdev_ioctl()
1602 info->params.loopback = new_line.loopback; in hdlcdev_ioctl()
1605 info->params.clock_speed = new_line.clock_rate; in hdlcdev_ioctl()
1607 info->params.clock_speed = 0; in hdlcdev_ioctl()
1610 if (info->netcount) in hdlcdev_ioctl()
1611 program_hw(info); in hdlcdev_ioctl()
1626 struct slgt_info *info = dev_to_port(dev); in hdlcdev_tx_timeout() local
1634 spin_lock_irqsave(&info->lock,flags); in hdlcdev_tx_timeout()
1635 tx_stop(info); in hdlcdev_tx_timeout()
1636 spin_unlock_irqrestore(&info->lock,flags); in hdlcdev_tx_timeout()
1643 * @info: pointer to device instance information
1647 static void hdlcdev_tx_done(struct slgt_info *info) in hdlcdev_tx_done() argument
1649 if (netif_queue_stopped(info->netdev)) in hdlcdev_tx_done()
1650 netif_wake_queue(info->netdev); in hdlcdev_tx_done()
1655 * @info: pointer to device instance information
1661 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size) in hdlcdev_rx() argument
1664 struct net_device *dev = info->netdev; in hdlcdev_rx()
1694 * @info: pointer to device instance information
1700 static int hdlcdev_init(struct slgt_info *info) in hdlcdev_init() argument
1708 dev = alloc_hdlcdev(info); in hdlcdev_init()
1710 printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name); in hdlcdev_init()
1715 dev->mem_start = info->phys_reg_addr; in hdlcdev_init()
1716 dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1; in hdlcdev_init()
1717 dev->irq = info->irq_level; in hdlcdev_init()
1737 info->netdev = dev; in hdlcdev_init()
1743 * @info: pointer to device instance information
1747 static void hdlcdev_exit(struct slgt_info *info) in hdlcdev_exit() argument
1749 unregister_hdlc_device(info->netdev); in hdlcdev_exit()
1750 free_netdev(info->netdev); in hdlcdev_exit()
1751 info->netdev = NULL; in hdlcdev_exit()
1759 static void rx_async(struct slgt_info *info) in rx_async() argument
1761 struct mgsl_icount *icount = &info->icount; in rx_async()
1765 struct slgt_desc *bufs = info->rbufs; in rx_async()
1771 start = end = info->rbuf_current; in rx_async()
1774 count = desc_count(bufs[end]) - info->rbuf_index; in rx_async()
1775 p = bufs[end].buf + info->rbuf_index; in rx_async()
1777 DBGISR(("%s rx_async count=%d\n", info->device_name, count)); in rx_async()
1778 DBGDATA(info, p, count, "rx"); in rx_async()
1793 if (status & info->ignore_status_mask) in rx_async()
1800 tty_insert_flip_char(&info->port, ch, stat); in rx_async()
1806 info->rbuf_index += i; in rx_async()
1807 mod_timer(&info->rx_timer, jiffies + 1); in rx_async()
1811 info->rbuf_index = 0; in rx_async()
1812 free_rbufs(info, end, end); in rx_async()
1814 if (++end == info->rbuf_count) in rx_async()
1823 tty_flip_buffer_push(&info->port); in rx_async()
1829 static int bh_action(struct slgt_info *info) in bh_action() argument
1834 spin_lock_irqsave(&info->lock,flags); in bh_action()
1836 if (info->pending_bh & BH_RECEIVE) { in bh_action()
1837 info->pending_bh &= ~BH_RECEIVE; in bh_action()
1839 } else if (info->pending_bh & BH_TRANSMIT) { in bh_action()
1840 info->pending_bh &= ~BH_TRANSMIT; in bh_action()
1842 } else if (info->pending_bh & BH_STATUS) { in bh_action()
1843 info->pending_bh &= ~BH_STATUS; in bh_action()
1847 info->bh_running = false; in bh_action()
1848 info->bh_requested = false; in bh_action()
1852 spin_unlock_irqrestore(&info->lock,flags); in bh_action()
1862 struct slgt_info *info = container_of(work, struct slgt_info, task); in bh_handler() local
1865 info->bh_running = true; in bh_handler()
1867 while((action = bh_action(info))) { in bh_handler()
1870 DBGBH(("%s bh receive\n", info->device_name)); in bh_handler()
1871 switch(info->params.mode) { in bh_handler()
1873 rx_async(info); in bh_handler()
1876 while(rx_get_frame(info)); in bh_handler()
1882 while(rx_get_buf(info)); in bh_handler()
1886 if (info->rx_restart) in bh_handler()
1887 rx_start(info); in bh_handler()
1890 bh_transmit(info); in bh_handler()
1893 DBGBH(("%s bh status\n", info->device_name)); in bh_handler()
1894 info->ri_chkcount = 0; in bh_handler()
1895 info->dsr_chkcount = 0; in bh_handler()
1896 info->dcd_chkcount = 0; in bh_handler()
1897 info->cts_chkcount = 0; in bh_handler()
1900 DBGBH(("%s unknown action\n", info->device_name)); in bh_handler()
1904 DBGBH(("%s bh_handler exit\n", info->device_name)); in bh_handler()
1907 static void bh_transmit(struct slgt_info *info) in bh_transmit() argument
1909 struct tty_struct *tty = info->port.tty; in bh_transmit()
1911 DBGBH(("%s bh_transmit\n", info->device_name)); in bh_transmit()
1916 static void dsr_change(struct slgt_info *info, unsigned short status) in dsr_change() argument
1919 info->signals |= SerialSignal_DSR; in dsr_change()
1920 info->input_signal_events.dsr_up++; in dsr_change()
1922 info->signals &= ~SerialSignal_DSR; in dsr_change()
1923 info->input_signal_events.dsr_down++; in dsr_change()
1925 DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); in dsr_change()
1926 if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dsr_change()
1927 slgt_irq_off(info, IRQ_DSR); in dsr_change()
1930 info->icount.dsr++; in dsr_change()
1931 wake_up_interruptible(&info->status_event_wait_q); in dsr_change()
1932 wake_up_interruptible(&info->event_wait_q); in dsr_change()
1933 info->pending_bh |= BH_STATUS; in dsr_change()
1936 static void cts_change(struct slgt_info *info, unsigned short status) in cts_change() argument
1939 info->signals |= SerialSignal_CTS; in cts_change()
1940 info->input_signal_events.cts_up++; in cts_change()
1942 info->signals &= ~SerialSignal_CTS; in cts_change()
1943 info->input_signal_events.cts_down++; in cts_change()
1945 DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); in cts_change()
1946 if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in cts_change()
1947 slgt_irq_off(info, IRQ_CTS); in cts_change()
1950 info->icount.cts++; in cts_change()
1951 wake_up_interruptible(&info->status_event_wait_q); in cts_change()
1952 wake_up_interruptible(&info->event_wait_q); in cts_change()
1953 info->pending_bh |= BH_STATUS; in cts_change()
1955 if (tty_port_cts_enabled(&info->port)) { in cts_change()
1956 if (info->port.tty) { in cts_change()
1957 if (info->port.tty->hw_stopped) { in cts_change()
1958 if (info->signals & SerialSignal_CTS) { in cts_change()
1959 info->port.tty->hw_stopped = 0; in cts_change()
1960 info->pending_bh |= BH_TRANSMIT; in cts_change()
1964 if (!(info->signals & SerialSignal_CTS)) in cts_change()
1965 info->port.tty->hw_stopped = 1; in cts_change()
1971 static void dcd_change(struct slgt_info *info, unsigned short status) in dcd_change() argument
1974 info->signals |= SerialSignal_DCD; in dcd_change()
1975 info->input_signal_events.dcd_up++; in dcd_change()
1977 info->signals &= ~SerialSignal_DCD; in dcd_change()
1978 info->input_signal_events.dcd_down++; in dcd_change()
1980 DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); in dcd_change()
1981 if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dcd_change()
1982 slgt_irq_off(info, IRQ_DCD); in dcd_change()
1985 info->icount.dcd++; in dcd_change()
1987 if (info->netcount) { in dcd_change()
1988 if (info->signals & SerialSignal_DCD) in dcd_change()
1989 netif_carrier_on(info->netdev); in dcd_change()
1991 netif_carrier_off(info->netdev); in dcd_change()
1994 wake_up_interruptible(&info->status_event_wait_q); in dcd_change()
1995 wake_up_interruptible(&info->event_wait_q); in dcd_change()
1996 info->pending_bh |= BH_STATUS; in dcd_change()
1998 if (tty_port_check_carrier(&info->port)) { in dcd_change()
1999 if (info->signals & SerialSignal_DCD) in dcd_change()
2000 wake_up_interruptible(&info->port.open_wait); in dcd_change()
2002 if (info->port.tty) in dcd_change()
2003 tty_hangup(info->port.tty); in dcd_change()
2008 static void ri_change(struct slgt_info *info, unsigned short status) in ri_change() argument
2011 info->signals |= SerialSignal_RI; in ri_change()
2012 info->input_signal_events.ri_up++; in ri_change()
2014 info->signals &= ~SerialSignal_RI; in ri_change()
2015 info->input_signal_events.ri_down++; in ri_change()
2017 DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); in ri_change()
2018 if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in ri_change()
2019 slgt_irq_off(info, IRQ_RI); in ri_change()
2022 info->icount.rng++; in ri_change()
2023 wake_up_interruptible(&info->status_event_wait_q); in ri_change()
2024 wake_up_interruptible(&info->event_wait_q); in ri_change()
2025 info->pending_bh |= BH_STATUS; in ri_change()
2028 static void isr_rxdata(struct slgt_info *info) in isr_rxdata() argument
2030 unsigned int count = info->rbuf_fill_count; in isr_rxdata()
2031 unsigned int i = info->rbuf_fill_index; in isr_rxdata()
2034 while (rd_reg16(info, SSR) & IRQ_RXDATA) { in isr_rxdata()
2035 reg = rd_reg16(info, RDR); in isr_rxdata()
2036 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); in isr_rxdata()
2037 if (desc_complete(info->rbufs[i])) { in isr_rxdata()
2039 rx_stop(info); in isr_rxdata()
2040 info->rx_restart = true; in isr_rxdata()
2043 info->rbufs[i].buf[count++] = (unsigned char)reg; in isr_rxdata()
2045 if (info->params.mode == MGSL_MODE_ASYNC) in isr_rxdata()
2046 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); in isr_rxdata()
2047 if (count == info->rbuf_fill_level || (reg & BIT10)) { in isr_rxdata()
2049 set_desc_count(info->rbufs[i], count); in isr_rxdata()
2050 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); in isr_rxdata()
2051 info->rbuf_fill_count = count = 0; in isr_rxdata()
2052 if (++i == info->rbuf_count) in isr_rxdata()
2054 info->pending_bh |= BH_RECEIVE; in isr_rxdata()
2058 info->rbuf_fill_index = i; in isr_rxdata()
2059 info->rbuf_fill_count = count; in isr_rxdata()
2062 static void isr_serial(struct slgt_info *info) in isr_serial() argument
2064 unsigned short status = rd_reg16(info, SSR); in isr_serial()
2066 DBGISR(("%s isr_serial status=%04X\n", info->device_name, status)); in isr_serial()
2068 wr_reg16(info, SSR, status); /* clear pending */ in isr_serial()
2070 info->irq_occurred = true; in isr_serial()
2072 if (info->params.mode == MGSL_MODE_ASYNC) { in isr_serial()
2074 if (info->tx_active) in isr_serial()
2075 isr_txeom(info, status); in isr_serial()
2077 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2078 isr_rxdata(info); in isr_serial()
2080 info->icount.brk++; in isr_serial()
2082 if (info->port.tty) { in isr_serial()
2083 if (!(status & info->ignore_status_mask)) { in isr_serial()
2084 if (info->read_status_mask & MASK_BREAK) { in isr_serial()
2085 tty_insert_flip_char(&info->port, 0, TTY_BREAK); in isr_serial()
2086 if (info->port.flags & ASYNC_SAK) in isr_serial()
2087 do_SAK(info->port.tty); in isr_serial()
2094 isr_txeom(info, status); in isr_serial()
2095 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2096 isr_rxdata(info); in isr_serial()
2099 info->icount.rxidle++; in isr_serial()
2101 info->icount.exithunt++; in isr_serial()
2102 wake_up_interruptible(&info->event_wait_q); in isr_serial()
2106 rx_start(info); in isr_serial()
2110 dsr_change(info, status); in isr_serial()
2112 cts_change(info, status); in isr_serial()
2114 dcd_change(info, status); in isr_serial()
2116 ri_change(info, status); in isr_serial()
2119 static void isr_rdma(struct slgt_info *info) in isr_rdma() argument
2121 unsigned int status = rd_reg32(info, RDCSR); in isr_rdma()
2123 DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status)); in isr_rdma()
2136 wr_reg32(info, RDCSR, status); /* clear pending */ in isr_rdma()
2139 DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); in isr_rdma()
2140 info->rx_restart = true; in isr_rdma()
2142 info->pending_bh |= BH_RECEIVE; in isr_rdma()
2145 static void isr_tdma(struct slgt_info *info) in isr_tdma() argument
2147 unsigned int status = rd_reg32(info, TDCSR); in isr_tdma()
2149 DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status)); in isr_tdma()
2161 wr_reg32(info, TDCSR, status); /* clear pending */ in isr_tdma()
2166 info->pending_bh |= BH_TRANSMIT; in isr_tdma()
2173 * if there are unsent buffers then info->tbuf_start
2176 static bool unsent_tbufs(struct slgt_info *info) in unsent_tbufs() argument
2178 unsigned int i = info->tbuf_current; in unsent_tbufs()
2190 i = info->tbuf_count - 1; in unsent_tbufs()
2191 if (!desc_count(info->tbufs[i])) in unsent_tbufs()
2193 info->tbuf_start = i; in unsent_tbufs()
2195 } while (i != info->tbuf_current); in unsent_tbufs()
2200 static void isr_txeom(struct slgt_info *info, unsigned short status) in isr_txeom() argument
2202 DBGISR(("%s txeom status=%04x\n", info->device_name, status)); in isr_txeom()
2204 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in isr_txeom()
2205 tdma_reset(info); in isr_txeom()
2207 unsigned short val = rd_reg16(info, TCR); in isr_txeom()
2208 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in isr_txeom()
2209 wr_reg16(info, TCR, val); /* clear reset bit */ in isr_txeom()
2212 if (info->tx_active) { in isr_txeom()
2213 if (info->params.mode != MGSL_MODE_ASYNC) { in isr_txeom()
2215 info->icount.txunder++; in isr_txeom()
2217 info->icount.txok++; in isr_txeom()
2220 if (unsent_tbufs(info)) { in isr_txeom()
2221 tx_start(info); in isr_txeom()
2222 update_tx_timer(info); in isr_txeom()
2225 info->tx_active = false; in isr_txeom()
2227 del_timer(&info->tx_timer); in isr_txeom()
2229 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { in isr_txeom()
2230 info->signals &= ~SerialSignal_RTS; in isr_txeom()
2231 info->drop_rts_on_tx_done = false; in isr_txeom()
2232 set_gtsignals(info); in isr_txeom()
2236 if (info->netcount) in isr_txeom()
2237 hdlcdev_tx_done(info); in isr_txeom()
2241 if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) { in isr_txeom()
2242 tx_stop(info); in isr_txeom()
2245 info->pending_bh |= BH_TRANSMIT; in isr_txeom()
2250 static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state) in isr_gpio() argument
2255 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) { in isr_gpio()
2262 info->gpio_wait_q = w->next; in isr_gpio()
2275 struct slgt_info *info = dev_id; in slgt_interrupt() local
2279 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); in slgt_interrupt()
2281 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { in slgt_interrupt()
2282 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); in slgt_interrupt()
2283 info->irq_occurred = true; in slgt_interrupt()
2284 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2285 if (info->port_array[i] == NULL) in slgt_interrupt()
2287 spin_lock(&info->port_array[i]->lock); in slgt_interrupt()
2289 isr_serial(info->port_array[i]); in slgt_interrupt()
2291 isr_rdma(info->port_array[i]); in slgt_interrupt()
2293 isr_tdma(info->port_array[i]); in slgt_interrupt()
2294 spin_unlock(&info->port_array[i]->lock); in slgt_interrupt()
2298 if (info->gpio_present) { in slgt_interrupt()
2301 spin_lock(&info->lock); in slgt_interrupt()
2302 while ((changed = rd_reg32(info, IOSR)) != 0) { in slgt_interrupt()
2303 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); in slgt_interrupt()
2305 state = rd_reg32(info, IOVR); in slgt_interrupt()
2307 wr_reg32(info, IOSR, changed); in slgt_interrupt()
2308 for (i=0 ; i < info->port_count ; i++) { in slgt_interrupt()
2309 if (info->port_array[i] != NULL) in slgt_interrupt()
2310 isr_gpio(info->port_array[i], changed, state); in slgt_interrupt()
2313 spin_unlock(&info->lock); in slgt_interrupt()
2316 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2317 struct slgt_info *port = info->port_array[i]; in slgt_interrupt()
2331 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); in slgt_interrupt()
2335 static int startup(struct slgt_info *info) in startup() argument
2337 DBGINFO(("%s startup\n", info->device_name)); in startup()
2339 if (tty_port_initialized(&info->port)) in startup()
2342 if (!info->tx_buf) { in startup()
2343 info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); in startup()
2344 if (!info->tx_buf) { in startup()
2345 DBGERR(("%s can't allocate tx buffer\n", info->device_name)); in startup()
2350 info->pending_bh = 0; in startup()
2352 memset(&info->icount, 0, sizeof(info->icount)); in startup()
2355 change_params(info); in startup()
2357 if (info->port.tty) in startup()
2358 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); in startup()
2360 tty_port_set_initialized(&info->port, 1); in startup()
2368 static void shutdown(struct slgt_info *info) in shutdown() argument
2372 if (!tty_port_initialized(&info->port)) in shutdown()
2375 DBGINFO(("%s shutdown\n", info->device_name)); in shutdown()
2379 wake_up_interruptible(&info->status_event_wait_q); in shutdown()
2380 wake_up_interruptible(&info->event_wait_q); in shutdown()
2382 del_timer_sync(&info->tx_timer); in shutdown()
2383 del_timer_sync(&info->rx_timer); in shutdown()
2385 kfree(info->tx_buf); in shutdown()
2386 info->tx_buf = NULL; in shutdown()
2388 spin_lock_irqsave(&info->lock,flags); in shutdown()
2390 tx_stop(info); in shutdown()
2391 rx_stop(info); in shutdown()
2393 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in shutdown()
2395 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { in shutdown()
2396 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in shutdown()
2397 set_gtsignals(info); in shutdown()
2400 flush_cond_wait(&info->gpio_wait_q); in shutdown()
2402 spin_unlock_irqrestore(&info->lock,flags); in shutdown()
2404 if (info->port.tty) in shutdown()
2405 set_bit(TTY_IO_ERROR, &info->port.tty->flags); in shutdown()
2407 tty_port_set_initialized(&info->port, 0); in shutdown()
2410 static void program_hw(struct slgt_info *info) in program_hw() argument
2414 spin_lock_irqsave(&info->lock,flags); in program_hw()
2416 rx_stop(info); in program_hw()
2417 tx_stop(info); in program_hw()
2419 if (info->params.mode != MGSL_MODE_ASYNC || in program_hw()
2420 info->netcount) in program_hw()
2421 sync_mode(info); in program_hw()
2423 async_mode(info); in program_hw()
2425 set_gtsignals(info); in program_hw()
2427 info->dcd_chkcount = 0; in program_hw()
2428 info->cts_chkcount = 0; in program_hw()
2429 info->ri_chkcount = 0; in program_hw()
2430 info->dsr_chkcount = 0; in program_hw()
2432 slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI); in program_hw()
2433 get_gtsignals(info); in program_hw()
2435 if (info->netcount || in program_hw()
2436 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) in program_hw()
2437 rx_start(info); in program_hw()
2439 spin_unlock_irqrestore(&info->lock,flags); in program_hw()
2445 static void change_params(struct slgt_info *info) in change_params() argument
2450 if (!info->port.tty) in change_params()
2452 DBGINFO(("%s change_params\n", info->device_name)); in change_params()
2454 cflag = info->port.tty->termios.c_cflag; in change_params()
2459 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in change_params()
2461 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in change_params()
2465 info->params.data_bits = tty_get_char_size(cflag); in change_params()
2466 info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1; in change_params()
2469 info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN; in change_params()
2471 info->params.parity = ASYNC_PARITY_NONE; in change_params()
2476 bits_per_char = info->params.data_bits + in change_params()
2477 info->params.stop_bits + 1; in change_params()
2479 info->params.data_rate = tty_get_baud_rate(info->port.tty); in change_params()
2481 if (info->params.data_rate) { in change_params()
2482 info->timeout = (32*HZ*bits_per_char) / in change_params()
2483 info->params.data_rate; in change_params()
2485 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_params()
2487 tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); in change_params()
2488 tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); in change_params()
2492 info->read_status_mask = IRQ_RXOVER; in change_params()
2493 if (I_INPCK(info->port.tty)) in change_params()
2494 info->read_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2495 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) in change_params()
2496 info->read_status_mask |= MASK_BREAK; in change_params()
2497 if (I_IGNPAR(info->port.tty)) in change_params()
2498 info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2499 if (I_IGNBRK(info->port.tty)) { in change_params()
2500 info->ignore_status_mask |= MASK_BREAK; in change_params()
2504 if (I_IGNPAR(info->port.tty)) in change_params()
2505 info->ignore_status_mask |= MASK_OVERRUN; in change_params()
2508 program_hw(info); in change_params()
2511 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount) in get_stats() argument
2513 DBGINFO(("%s get_stats\n", info->device_name)); in get_stats()
2515 memset(&info->icount, 0, sizeof(info->icount)); in get_stats()
2517 if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount))) in get_stats()
2523 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params) in get_params() argument
2525 DBGINFO(("%s get_params\n", info->device_name)); in get_params()
2526 if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS))) in get_params()
2531 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params) in set_params() argument
2536 DBGINFO(("%s set_params\n", info->device_name)); in set_params()
2540 spin_lock_irqsave(&info->lock, flags); in set_params()
2542 info->base_clock = tmp_params.clock_speed; in set_params()
2544 memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS)); in set_params()
2545 spin_unlock_irqrestore(&info->lock, flags); in set_params()
2547 program_hw(info); in set_params()
2552 static int get_txidle(struct slgt_info *info, int __user *idle_mode) in get_txidle() argument
2554 DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode)); in get_txidle()
2555 if (put_user(info->idle_mode, idle_mode)) in get_txidle()
2560 static int set_txidle(struct slgt_info *info, int idle_mode) in set_txidle() argument
2563 DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode)); in set_txidle()
2564 spin_lock_irqsave(&info->lock,flags); in set_txidle()
2565 info->idle_mode = idle_mode; in set_txidle()
2566 if (info->params.mode != MGSL_MODE_ASYNC) in set_txidle()
2567 tx_set_idle(info); in set_txidle()
2568 spin_unlock_irqrestore(&info->lock,flags); in set_txidle()
2572 static int tx_enable(struct slgt_info *info, int enable) in tx_enable() argument
2575 DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable)); in tx_enable()
2576 spin_lock_irqsave(&info->lock,flags); in tx_enable()
2578 if (!info->tx_enabled) in tx_enable()
2579 tx_start(info); in tx_enable()
2581 if (info->tx_enabled) in tx_enable()
2582 tx_stop(info); in tx_enable()
2584 spin_unlock_irqrestore(&info->lock,flags); in tx_enable()
2591 static int tx_abort(struct slgt_info *info) in tx_abort() argument
2594 DBGINFO(("%s tx_abort\n", info->device_name)); in tx_abort()
2595 spin_lock_irqsave(&info->lock,flags); in tx_abort()
2596 tdma_reset(info); in tx_abort()
2597 spin_unlock_irqrestore(&info->lock,flags); in tx_abort()
2601 static int rx_enable(struct slgt_info *info, int enable) in rx_enable() argument
2605 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable)); in rx_enable()
2606 spin_lock_irqsave(&info->lock,flags); in rx_enable()
2615 spin_unlock_irqrestore(&info->lock, flags); in rx_enable()
2618 info->rbuf_fill_level = rbuf_fill_level; in rx_enable()
2620 info->rx_pio = 1; /* PIO mode */ in rx_enable()
2622 info->rx_pio = 0; /* DMA mode */ in rx_enable()
2623 rx_stop(info); /* restart receiver to use new fill level */ in rx_enable()
2634 if (!info->rx_enabled) in rx_enable()
2635 rx_start(info); in rx_enable()
2638 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3); in rx_enable()
2641 if (info->rx_enabled) in rx_enable()
2642 rx_stop(info); in rx_enable()
2644 spin_unlock_irqrestore(&info->lock,flags); in rx_enable()
2651 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr) in wait_mgsl_event() argument
2665 DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask)); in wait_mgsl_event()
2667 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2670 get_gtsignals(info); in wait_mgsl_event()
2671 s = info->signals; in wait_mgsl_event()
2679 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2684 cprev = info->icount; in wait_mgsl_event()
2685 oldsigs = info->input_signal_events; in wait_mgsl_event()
2689 unsigned short val = rd_reg16(info, SCR); in wait_mgsl_event()
2691 wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE)); in wait_mgsl_event()
2695 add_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2697 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2707 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2708 cnow = info->icount; in wait_mgsl_event()
2709 newsigs = info->input_signal_events; in wait_mgsl_event()
2711 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2746 remove_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2751 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2752 if (!waitqueue_active(&info->event_wait_q)) { in wait_mgsl_event()
2754 wr_reg16(info, SCR, in wait_mgsl_event()
2755 (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE)); in wait_mgsl_event()
2757 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2765 static int get_interface(struct slgt_info *info, int __user *if_mode) in get_interface() argument
2767 DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode)); in get_interface()
2768 if (put_user(info->if_mode, if_mode)) in get_interface()
2773 static int set_interface(struct slgt_info *info, int if_mode) in set_interface() argument
2778 DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode)); in set_interface()
2779 spin_lock_irqsave(&info->lock,flags); in set_interface()
2780 info->if_mode = if_mode; in set_interface()
2782 msc_set_vcr(info); in set_interface()
2785 val = rd_reg16(info, TCR); in set_interface()
2786 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in set_interface()
2790 wr_reg16(info, TCR, val); in set_interface()
2792 spin_unlock_irqrestore(&info->lock,flags); in set_interface()
2796 static int get_xsync(struct slgt_info *info, int __user *xsync) in get_xsync() argument
2798 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync)); in get_xsync()
2799 if (put_user(info->xsync, xsync)) in get_xsync()
2810 static int set_xsync(struct slgt_info *info, int xsync) in set_xsync() argument
2814 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync)); in set_xsync()
2815 spin_lock_irqsave(&info->lock, flags); in set_xsync()
2816 info->xsync = xsync; in set_xsync()
2817 wr_reg32(info, XSR, xsync); in set_xsync()
2818 spin_unlock_irqrestore(&info->lock, flags); in set_xsync()
2822 static int get_xctrl(struct slgt_info *info, int __user *xctrl) in get_xctrl() argument
2824 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl)); in get_xctrl()
2825 if (put_user(info->xctrl, xctrl)) in get_xctrl()
2847 static int set_xctrl(struct slgt_info *info, int xctrl) in set_xctrl() argument
2851 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl)); in set_xctrl()
2852 spin_lock_irqsave(&info->lock, flags); in set_xctrl()
2853 info->xctrl = xctrl; in set_xctrl()
2854 wr_reg32(info, XCR, xctrl); in set_xctrl()
2855 spin_unlock_irqrestore(&info->lock, flags); in set_xctrl()
2868 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in set_gpio() argument
2874 if (!info->gpio_present) in set_gpio()
2879 info->device_name, gpio.state, gpio.smask, in set_gpio()
2882 spin_lock_irqsave(&info->port_array[0]->lock, flags); in set_gpio()
2884 data = rd_reg32(info, IODR); in set_gpio()
2887 wr_reg32(info, IODR, data); in set_gpio()
2890 data = rd_reg32(info, IOVR); in set_gpio()
2893 wr_reg32(info, IOVR, data); in set_gpio()
2895 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in set_gpio()
2903 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in get_gpio() argument
2906 if (!info->gpio_present) in get_gpio()
2908 gpio.state = rd_reg32(info, IOVR); in get_gpio()
2910 gpio.dir = rd_reg32(info, IODR); in get_gpio()
2915 info->device_name, gpio.state, gpio.dir)); in get_gpio()
2977 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in wait_gpio() argument
2985 if (!info->gpio_present) in wait_gpio()
2990 info->device_name, gpio.state, gpio.smask)); in wait_gpio()
2992 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0) in wait_gpio()
2996 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
2998 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); in wait_gpio()
3000 state = rd_reg32(info, IOVR); in wait_gpio()
3007 add_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3008 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3014 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3015 remove_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3019 if (info->gpio_wait_q == NULL) in wait_gpio()
3020 wr_reg32(info, IOER, 0); in wait_gpio()
3021 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3028 static int modem_input_wait(struct slgt_info *info,int arg) in modem_input_wait() argument
3036 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3037 cprev = info->icount; in modem_input_wait()
3038 add_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3040 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3050 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3051 cnow = info->icount; in modem_input_wait()
3053 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3073 remove_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3083 struct slgt_info *info = tty->driver_data; in tiocmget() local
3087 spin_lock_irqsave(&info->lock,flags); in tiocmget()
3088 get_gtsignals(info); in tiocmget()
3089 spin_unlock_irqrestore(&info->lock,flags); in tiocmget()
3091 result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) + in tiocmget()
3092 ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) + in tiocmget()
3093 ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) + in tiocmget()
3094 ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) + in tiocmget()
3095 ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) + in tiocmget()
3096 ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0); in tiocmget()
3098 DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result)); in tiocmget()
3112 struct slgt_info *info = tty->driver_data; in tiocmset() local
3115 DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear)); in tiocmset()
3118 info->signals |= SerialSignal_RTS; in tiocmset()
3120 info->signals |= SerialSignal_DTR; in tiocmset()
3122 info->signals &= ~SerialSignal_RTS; in tiocmset()
3124 info->signals &= ~SerialSignal_DTR; in tiocmset()
3126 spin_lock_irqsave(&info->lock,flags); in tiocmset()
3127 set_gtsignals(info); in tiocmset()
3128 spin_unlock_irqrestore(&info->lock,flags); in tiocmset()
3135 struct slgt_info *info = container_of(port, struct slgt_info, port); in carrier_raised() local
3137 spin_lock_irqsave(&info->lock,flags); in carrier_raised()
3138 get_gtsignals(info); in carrier_raised()
3139 spin_unlock_irqrestore(&info->lock,flags); in carrier_raised()
3140 return (info->signals & SerialSignal_DCD) ? 1 : 0; in carrier_raised()
3146 struct slgt_info *info = container_of(port, struct slgt_info, port); in dtr_rts() local
3148 spin_lock_irqsave(&info->lock,flags); in dtr_rts()
3150 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in dtr_rts()
3152 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in dtr_rts()
3153 set_gtsignals(info); in dtr_rts()
3154 spin_unlock_irqrestore(&info->lock,flags); in dtr_rts()
3162 struct slgt_info *info) in block_til_ready() argument
3169 struct tty_port *port = &info->port; in block_til_ready()
3192 spin_lock_irqsave(&info->lock, flags); in block_til_ready()
3194 spin_unlock_irqrestore(&info->lock, flags); in block_til_ready()
3244 static int alloc_tmp_rbuf(struct slgt_info *info) in alloc_tmp_rbuf() argument
3246 info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3247 if (info->tmp_rbuf == NULL) in alloc_tmp_rbuf()
3250 info->flag_buf = kzalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3251 if (!info->flag_buf) { in alloc_tmp_rbuf()
3252 kfree(info->tmp_rbuf); in alloc_tmp_rbuf()
3253 info->tmp_rbuf = NULL; in alloc_tmp_rbuf()
3259 static void free_tmp_rbuf(struct slgt_info *info) in free_tmp_rbuf() argument
3261 kfree(info->tmp_rbuf); in free_tmp_rbuf()
3262 info->tmp_rbuf = NULL; in free_tmp_rbuf()
3263 kfree(info->flag_buf); in free_tmp_rbuf()
3264 info->flag_buf = NULL; in free_tmp_rbuf()
3270 static int alloc_desc(struct slgt_info *info) in alloc_desc() argument
3276 info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE, in alloc_desc()
3277 &info->bufs_dma_addr, GFP_KERNEL); in alloc_desc()
3278 if (info->bufs == NULL) in alloc_desc()
3281 info->rbufs = (struct slgt_desc*)info->bufs; in alloc_desc()
3282 info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count; in alloc_desc()
3284 pbufs = (unsigned int)info->bufs_dma_addr; in alloc_desc()
3290 for (i=0; i < info->rbuf_count; i++) { in alloc_desc()
3292 info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc)); in alloc_desc()
3295 if (i == info->rbuf_count - 1) in alloc_desc()
3296 info->rbufs[i].next = cpu_to_le32(pbufs); in alloc_desc()
3298 info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc))); in alloc_desc()
3299 set_desc_count(info->rbufs[i], DMABUFSIZE); in alloc_desc()
3302 for (i=0; i < info->tbuf_count; i++) { in alloc_desc()
3304 info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc)); in alloc_desc()
3307 if (i == info->tbuf_count - 1) in alloc_desc()
3308 info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc)); in alloc_desc()
3310info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc))); in alloc_desc()
3316 static void free_desc(struct slgt_info *info) in free_desc() argument
3318 if (info->bufs != NULL) { in free_desc()
3319 dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE, in free_desc()
3320 info->bufs, info->bufs_dma_addr); in free_desc()
3321 info->bufs = NULL; in free_desc()
3322 info->rbufs = NULL; in free_desc()
3323 info->tbufs = NULL; in free_desc()
3327 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in alloc_bufs() argument
3331 bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE, in alloc_bufs()
3340 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in free_bufs() argument
3346 dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf, in free_bufs()
3352 static int alloc_dma_bufs(struct slgt_info *info) in alloc_dma_bufs() argument
3354 info->rbuf_count = 32; in alloc_dma_bufs()
3355 info->tbuf_count = 32; in alloc_dma_bufs()
3357 if (alloc_desc(info) < 0 || in alloc_dma_bufs()
3358 alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 || in alloc_dma_bufs()
3359 alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 || in alloc_dma_bufs()
3360 alloc_tmp_rbuf(info) < 0) { in alloc_dma_bufs()
3361 DBGERR(("%s DMA buffer alloc fail\n", info->device_name)); in alloc_dma_bufs()
3364 reset_rbufs(info); in alloc_dma_bufs()
3368 static void free_dma_bufs(struct slgt_info *info) in free_dma_bufs() argument
3370 if (info->bufs) { in free_dma_bufs()
3371 free_bufs(info, info->rbufs, info->rbuf_count); in free_dma_bufs()
3372 free_bufs(info, info->tbufs, info->tbuf_count); in free_dma_bufs()
3373 free_desc(info); in free_dma_bufs()
3375 free_tmp_rbuf(info); in free_dma_bufs()
3378 static int claim_resources(struct slgt_info *info) in claim_resources() argument
3380 if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) { in claim_resources()
3382 info->device_name, info->phys_reg_addr)); in claim_resources()
3383 info->init_error = DiagStatus_AddressConflict; in claim_resources()
3387 info->reg_addr_requested = true; in claim_resources()
3389 info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); in claim_resources()
3390 if (!info->reg_addr) { in claim_resources()
3392 info->device_name, info->phys_reg_addr)); in claim_resources()
3393 info->init_error = DiagStatus_CantAssignPciResources; in claim_resources()
3399 release_resources(info); in claim_resources()
3403 static void release_resources(struct slgt_info *info) in release_resources() argument
3405 if (info->irq_requested) { in release_resources()
3406 free_irq(info->irq_level, info); in release_resources()
3407 info->irq_requested = false; in release_resources()
3410 if (info->reg_addr_requested) { in release_resources()
3411 release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); in release_resources()
3412 info->reg_addr_requested = false; in release_resources()
3415 if (info->reg_addr) { in release_resources()
3416 iounmap(info->reg_addr); in release_resources()
3417 info->reg_addr = NULL; in release_resources()
3424 static void add_device(struct slgt_info *info) in add_device() argument
3428 info->next_device = NULL; in add_device()
3429 info->line = slgt_device_count; in add_device()
3430 sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line); in add_device()
3432 if (info->line < MAX_DEVICES) { in add_device()
3433 if (maxframe[info->line]) in add_device()
3434 info->max_frame_size = maxframe[info->line]; in add_device()
3440 slgt_device_list = info; in add_device()
3445 current_dev->next_device = info; in add_device()
3448 if (info->max_frame_size < 4096) in add_device()
3449 info->max_frame_size = 4096; in add_device()
3450 else if (info->max_frame_size > 65535) in add_device()
3451 info->max_frame_size = 65535; in add_device()
3453 switch(info->pdev->device) { in add_device()
3465 info->params.mode = MGSL_MODE_ASYNC; in add_device()
3471 devstr, info->device_name, info->phys_reg_addr, in add_device()
3472 info->irq_level, info->max_frame_size); in add_device()
3475 hdlcdev_init(info); in add_device()
3489 struct slgt_info *info; in alloc_dev() local
3491 info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL); in alloc_dev()
3493 if (!info) { in alloc_dev()
3497 tty_port_init(&info->port); in alloc_dev()
3498 info->port.ops = &slgt_port_ops; in alloc_dev()
3499 info->magic = MGSL_MAGIC; in alloc_dev()
3500 INIT_WORK(&info->task, bh_handler); in alloc_dev()
3501 info->max_frame_size = 4096; in alloc_dev()
3502 info->base_clock = 14745600; in alloc_dev()
3503 info->rbuf_fill_level = DMABUFSIZE; in alloc_dev()
3504 init_waitqueue_head(&info->status_event_wait_q); in alloc_dev()
3505 init_waitqueue_head(&info->event_wait_q); in alloc_dev()
3506 spin_lock_init(&info->netlock); in alloc_dev()
3507 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); in alloc_dev()
3508 info->idle_mode = HDLC_TXIDLE_FLAGS; in alloc_dev()
3509 info->adapter_num = adapter_num; in alloc_dev()
3510 info->port_num = port_num; in alloc_dev()
3512 timer_setup(&info->tx_timer, tx_timeout, 0); in alloc_dev()
3513 timer_setup(&info->rx_timer, rx_timeout, 0); in alloc_dev()
3515 /* Copy configuration info to device instance data */ in alloc_dev()
3516 info->pdev = pdev; in alloc_dev()
3517 info->irq_level = pdev->irq; in alloc_dev()
3518 info->phys_reg_addr = pci_resource_start(pdev,0); in alloc_dev()
3520 info->bus_type = MGSL_BUS_TYPE_PCI; in alloc_dev()
3521 info->irq_flags = IRQF_SHARED; in alloc_dev()
3523 info->init_error = -1; /* assume error, set to 0 on successful init */ in alloc_dev()
3526 return info; in alloc_dev()
3591 struct slgt_info *info = port_array[i]; in device_init() local
3592 tty_port_register_device(&info->port, serial_driver, info->line, in device_init()
3593 &info->pdev->dev); in device_init()
3641 struct slgt_info *info; in slgt_cleanup() local
3647 for (info=slgt_device_list ; info != NULL ; info=info->next_device) in slgt_cleanup()
3648 tty_unregister_device(serial_driver, info->line); in slgt_cleanup()
3654 info = slgt_device_list; in slgt_cleanup()
3655 while(info) { in slgt_cleanup()
3656 reset_port(info); in slgt_cleanup()
3657 info = info->next_device; in slgt_cleanup()
3661 info = slgt_device_list; in slgt_cleanup()
3662 while(info) { in slgt_cleanup()
3664 hdlcdev_exit(info); in slgt_cleanup()
3666 free_dma_bufs(info); in slgt_cleanup()
3667 free_tmp_rbuf(info); in slgt_cleanup()
3668 if (info->port_num == 0) in slgt_cleanup()
3669 release_resources(info); in slgt_cleanup()
3670 tmp = info; in slgt_cleanup()
3671 info = info->next_device; in slgt_cleanup()
3750 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3752 reg_addr += (info->port_num) * 32; \
3754 reg_addr += (info->port_num) * 16;
3756 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) in rd_reg8() argument
3762 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value) in wr_reg8() argument
3768 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr) in rd_reg16() argument
3774 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value) in wr_reg16() argument
3780 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr) in rd_reg32() argument
3786 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value) in wr_reg32() argument
3792 static void rdma_reset(struct slgt_info *info) in rdma_reset() argument
3797 wr_reg32(info, RDCSR, BIT1); in rdma_reset()
3801 if (!(rd_reg32(info, RDCSR) & BIT0)) in rdma_reset()
3805 static void tdma_reset(struct slgt_info *info) in tdma_reset() argument
3810 wr_reg32(info, TDCSR, BIT1); in tdma_reset()
3814 if (!(rd_reg32(info, TDCSR) & BIT0)) in tdma_reset()
3823 static void enable_loopback(struct slgt_info *info) in enable_loopback() argument
3826 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); in enable_loopback()
3828 if (info->params.mode != MGSL_MODE_ASYNC) { in enable_loopback()
3837 wr_reg8(info, CCR, 0x49); in enable_loopback()
3840 if (info->params.clock_speed) in enable_loopback()
3841 set_rate(info, info->params.clock_speed); in enable_loopback()
3843 set_rate(info, 3686400); in enable_loopback()
3850 static void set_rate(struct slgt_info *info, u32 rate) in set_rate() argument
3853 unsigned int osc = info->base_clock; in set_rate()
3865 wr_reg16(info, BDR, (unsigned short)div); in set_rate()
3869 static void rx_stop(struct slgt_info *info) in rx_stop() argument
3874 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_stop()
3875 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_stop()
3876 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_stop()
3878 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE); in rx_stop()
3881 wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER); in rx_stop()
3883 rdma_reset(info); in rx_stop()
3885 info->rx_enabled = false; in rx_stop()
3886 info->rx_restart = false; in rx_stop()
3889 static void rx_start(struct slgt_info *info) in rx_start() argument
3893 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA); in rx_start()
3896 wr_reg16(info, SSR, IRQ_RXOVER); in rx_start()
3899 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_start()
3900 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_start()
3901 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_start()
3903 rdma_reset(info); in rx_start()
3904 reset_rbufs(info); in rx_start()
3906 if (info->rx_pio) { in rx_start()
3908 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); in rx_start()
3909 slgt_irq_on(info, IRQ_RXDATA); in rx_start()
3910 if (info->params.mode == MGSL_MODE_ASYNC) { in rx_start()
3912 wr_reg32(info, RDCSR, BIT6); in rx_start()
3916 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); in rx_start()
3918 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); in rx_start()
3920 if (info->params.mode != MGSL_MODE_ASYNC) { in rx_start()
3922 wr_reg32(info, RDCSR, (BIT2 + BIT0)); in rx_start()
3925 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); in rx_start()
3929 slgt_irq_on(info, IRQ_RXOVER); in rx_start()
3932 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); in rx_start()
3934 info->rx_restart = false; in rx_start()
3935 info->rx_enabled = true; in rx_start()
3938 static void tx_start(struct slgt_info *info) in tx_start() argument
3940 if (!info->tx_enabled) { in tx_start()
3941 wr_reg16(info, TCR, in tx_start()
3942 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); in tx_start()
3943 info->tx_enabled = true; in tx_start()
3946 if (desc_count(info->tbufs[info->tbuf_start])) { in tx_start()
3947 info->drop_rts_on_tx_done = false; in tx_start()
3949 if (info->params.mode != MGSL_MODE_ASYNC) { in tx_start()
3950 if (info->params.flags & HDLC_FLAG_AUTO_RTS) { in tx_start()
3951 get_gtsignals(info); in tx_start()
3952 if (!(info->signals & SerialSignal_RTS)) { in tx_start()
3953 info->signals |= SerialSignal_RTS; in tx_start()
3954 set_gtsignals(info); in tx_start()
3955 info->drop_rts_on_tx_done = true; in tx_start()
3959 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3960 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); in tx_start()
3962 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_start()
3964 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3965 slgt_irq_on(info, IRQ_TXIDLE); in tx_start()
3967 wr_reg16(info, SSR, IRQ_TXIDLE); in tx_start()
3970 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); in tx_start()
3971 wr_reg32(info, TDCSR, BIT2 + BIT0); in tx_start()
3972 info->tx_active = true; in tx_start()
3976 static void tx_stop(struct slgt_info *info) in tx_stop() argument
3980 del_timer(&info->tx_timer); in tx_stop()
3982 tdma_reset(info); in tx_stop()
3985 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ in tx_stop()
3986 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in tx_stop()
3988 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in tx_stop()
3991 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_stop()
3993 reset_tbufs(info); in tx_stop()
3995 info->tx_enabled = false; in tx_stop()
3996 info->tx_active = false; in tx_stop()
3999 static void reset_port(struct slgt_info *info) in reset_port() argument
4001 if (!info->reg_addr) in reset_port()
4004 tx_stop(info); in reset_port()
4005 rx_stop(info); in reset_port()
4007 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in reset_port()
4008 set_gtsignals(info); in reset_port()
4010 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in reset_port()
4013 static void reset_adapter(struct slgt_info *info) in reset_adapter() argument
4016 for (i=0; i < info->port_count; ++i) { in reset_adapter()
4017 if (info->port_array[i]) in reset_adapter()
4018 reset_port(info->port_array[i]); in reset_adapter()
4022 static void async_mode(struct slgt_info *info) in async_mode() argument
4026 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in async_mode()
4027 tx_stop(info); in async_mode()
4028 rx_stop(info); in async_mode()
4050 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in async_mode()
4053 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4055 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4059 switch (info->params.data_bits) in async_mode()
4066 if (info->params.stop_bits != 1) in async_mode()
4069 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in async_mode()
4072 wr_reg16(info, TCR, val); in async_mode()
4093 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4095 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4099 switch (info->params.data_bits) in async_mode()
4106 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in async_mode()
4109 wr_reg16(info, RCR, val); in async_mode()
4120 wr_reg8(info, CCR, 0x69); in async_mode()
4122 msc_set_vcr(info); in async_mode()
4145 if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate && in async_mode()
4146 ((info->base_clock < (info->params.data_rate * 16)) || in async_mode()
4147 (info->base_clock % (info->params.data_rate * 16)))) { in async_mode()
4150 set_rate(info, info->params.data_rate * 8); in async_mode()
4153 set_rate(info, info->params.data_rate * 16); in async_mode()
4155 wr_reg16(info, SCR, val); in async_mode()
4157 slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER); in async_mode()
4159 if (info->params.loopback) in async_mode()
4160 enable_loopback(info); in async_mode()
4163 static void sync_mode(struct slgt_info *info) in sync_mode() argument
4167 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in sync_mode()
4168 tx_stop(info); in sync_mode()
4169 rx_stop(info); in sync_mode()
4193 switch(info->params.mode) { in sync_mode()
4201 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in sync_mode()
4204 switch(info->params.encoding) in sync_mode()
4215 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4221 if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE) in sync_mode()
4224 switch (info->params.preamble_length) in sync_mode()
4231 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in sync_mode()
4234 wr_reg16(info, TCR, val); in sync_mode()
4238 switch (info->params.preamble) in sync_mode()
4247 wr_reg8(info, TPR, (unsigned char)val); in sync_mode()
4268 switch(info->params.mode) { in sync_mode()
4277 switch(info->params.encoding) in sync_mode()
4288 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4294 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in sync_mode()
4297 wr_reg16(info, RCR, val); in sync_mode()
4308 if (info->params.flags & HDLC_FLAG_TXC_BRG) in sync_mode()
4313 if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4318 else if (info->params.flags & HDLC_FLAG_TXC_DPLL) in sync_mode()
4320 else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN) in sync_mode()
4323 if (info->params.flags & HDLC_FLAG_RXC_BRG) in sync_mode()
4325 else if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4327 else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN) in sync_mode()
4330 if (info->params.clock_speed) in sync_mode()
4333 wr_reg8(info, CCR, (unsigned char)val); in sync_mode()
4335 if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL)) in sync_mode()
4338 switch(info->params.encoding) in sync_mode()
4348 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val)); in sync_mode()
4351 set_rate(info, info->params.clock_speed * 16); in sync_mode()
4354 set_rate(info, info->params.clock_speed); in sync_mode()
4356 tx_set_idle(info); in sync_mode()
4358 msc_set_vcr(info); in sync_mode()
4379 wr_reg16(info, SCR, BIT15 + BIT14 + BIT0); in sync_mode()
4381 if (info->params.loopback) in sync_mode()
4382 enable_loopback(info); in sync_mode()
4388 static void tx_set_idle(struct slgt_info *info) in tx_set_idle() argument
4396 tcr = rd_reg16(info, TCR); in tx_set_idle()
4397 if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) { in tx_set_idle()
4401 wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff)); in tx_set_idle()
4406 wr_reg16(info, TCR, tcr); in tx_set_idle()
4408 if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) { in tx_set_idle()
4410 val = (unsigned char)(info->idle_mode & 0xff); in tx_set_idle()
4413 switch(info->idle_mode) in tx_set_idle()
4424 wr_reg8(info, TIR, val); in tx_set_idle()
4430 static void get_gtsignals(struct slgt_info *info) in get_gtsignals() argument
4432 unsigned short status = rd_reg16(info, SSR); in get_gtsignals()
4435 info->signals &= SerialSignal_RTS | SerialSignal_DTR; in get_gtsignals()
4438 info->signals |= SerialSignal_DSR; in get_gtsignals()
4440 info->signals |= SerialSignal_CTS; in get_gtsignals()
4442 info->signals |= SerialSignal_DCD; in get_gtsignals()
4444 info->signals |= SerialSignal_RI; in get_gtsignals()
4450 static void msc_set_vcr(struct slgt_info *info) in msc_set_vcr() argument
4463 switch(info->if_mode & MGSL_INTERFACE_MASK) in msc_set_vcr()
4476 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST) in msc_set_vcr()
4478 if (info->signals & SerialSignal_DTR) in msc_set_vcr()
4480 if (info->signals & SerialSignal_RTS) in msc_set_vcr()
4482 if (info->if_mode & MGSL_INTERFACE_LL) in msc_set_vcr()
4484 if (info->if_mode & MGSL_INTERFACE_RL) in msc_set_vcr()
4486 wr_reg8(info, VCR, val); in msc_set_vcr()
4492 static void set_gtsignals(struct slgt_info *info) in set_gtsignals() argument
4494 unsigned char val = rd_reg8(info, VCR); in set_gtsignals()
4495 if (info->signals & SerialSignal_DTR) in set_gtsignals()
4499 if (info->signals & SerialSignal_RTS) in set_gtsignals()
4503 wr_reg8(info, VCR, val); in set_gtsignals()
4509 static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last) in free_rbufs() argument
4515 info->rbufs[i].status = 0; in free_rbufs()
4516 set_desc_count(info->rbufs[i], info->rbuf_fill_level); in free_rbufs()
4519 if (++i == info->rbuf_count) in free_rbufs()
4522 info->rbuf_current = i; in free_rbufs()
4528 static void reset_rbufs(struct slgt_info *info) in reset_rbufs() argument
4530 free_rbufs(info, 0, info->rbuf_count - 1); in reset_rbufs()
4531 info->rbuf_fill_index = 0; in reset_rbufs()
4532 info->rbuf_fill_count = 0; in reset_rbufs()
4540 static bool rx_get_frame(struct slgt_info *info) in rx_get_frame() argument
4546 struct tty_struct *tty = info->port.tty; in rx_get_frame()
4550 switch (info->params.crc_type & HDLC_CRC_MASK) { in rx_get_frame()
4559 start = end = info->rbuf_current; in rx_get_frame()
4562 if (!desc_complete(info->rbufs[end])) in rx_get_frame()
4565 if (framesize == 0 && info->params.addr_filter != 0xff) in rx_get_frame()
4566 addr_field = info->rbufs[end].buf[0]; in rx_get_frame()
4568 framesize += desc_count(info->rbufs[end]); in rx_get_frame()
4570 if (desc_eof(info->rbufs[end])) in rx_get_frame()
4573 if (++end == info->rbuf_count) in rx_get_frame()
4576 if (end == info->rbuf_current) { in rx_get_frame()
4577 if (info->rx_enabled){ in rx_get_frame()
4578 spin_lock_irqsave(&info->lock,flags); in rx_get_frame()
4579 rx_start(info); in rx_get_frame()
4580 spin_unlock_irqrestore(&info->lock,flags); in rx_get_frame()
4595 status = desc_status(info->rbufs[end]); in rx_get_frame()
4598 if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE) in rx_get_frame()
4602 (addr_field != 0xff && addr_field != info->params.addr_filter)) { in rx_get_frame()
4603 free_rbufs(info, start, end); in rx_get_frame()
4608 info->icount.rxshort++; in rx_get_frame()
4611 info->icount.rxcrc++; in rx_get_frame()
4612 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) in rx_get_frame()
4618 info->netdev->stats.rx_errors++; in rx_get_frame()
4619 info->netdev->stats.rx_frame_errors++; in rx_get_frame()
4624 info->device_name, status, framesize)); in rx_get_frame()
4625 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx"); in rx_get_frame()
4628 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { in rx_get_frame()
4633 if (framesize > info->max_frame_size + crc_size) in rx_get_frame()
4634 info->icount.rxlong++; in rx_get_frame()
4639 unsigned char *p = info->tmp_rbuf; in rx_get_frame()
4640 info->tmp_rbuf_count = framesize; in rx_get_frame()
4642 info->icount.rxok++; in rx_get_frame()
4645 int partial_count = min_t(int, copy_count, info->rbuf_fill_level); in rx_get_frame()
4646 memcpy(p, info->rbufs[i].buf, partial_count); in rx_get_frame()
4649 if (++i == info->rbuf_count) in rx_get_frame()
4653 if (info->params.crc_type & HDLC_CRC_RETURN_EX) { in rx_get_frame()
4659 if (info->netcount) in rx_get_frame()
4660 hdlcdev_rx(info,info->tmp_rbuf, framesize); in rx_get_frame()
4663 ldisc_receive_buf(tty, info->tmp_rbuf, info->flag_buf, framesize); in rx_get_frame()
4666 free_rbufs(info, start, end); in rx_get_frame()
4677 static bool rx_get_buf(struct slgt_info *info) in rx_get_buf() argument
4679 unsigned int i = info->rbuf_current; in rx_get_buf()
4682 if (!desc_complete(info->rbufs[i])) in rx_get_buf()
4684 count = desc_count(info->rbufs[i]); in rx_get_buf()
4685 switch(info->params.mode) { in rx_get_buf()
4690 if (desc_residue(info->rbufs[i])) in rx_get_buf()
4694 DBGDATA(info, info->rbufs[i].buf, count, "rx"); in rx_get_buf()
4697 ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, in rx_get_buf()
4698 info->flag_buf, count); in rx_get_buf()
4699 free_rbufs(info, i, i); in rx_get_buf()
4703 static void reset_tbufs(struct slgt_info *info) in reset_tbufs() argument
4706 info->tbuf_current = 0; in reset_tbufs()
4707 for (i=0 ; i < info->tbuf_count ; i++) { in reset_tbufs()
4708 info->tbufs[i].status = 0; in reset_tbufs()
4709 info->tbufs[i].count = 0; in reset_tbufs()
4716 static unsigned int free_tbuf_count(struct slgt_info *info) in free_tbuf_count() argument
4719 unsigned int i = info->tbuf_current; in free_tbuf_count()
4723 if (desc_count(info->tbufs[i])) in free_tbuf_count()
4726 if (++i == info->tbuf_count) in free_tbuf_count()
4728 } while (i != info->tbuf_current); in free_tbuf_count()
4731 if (count && (rd_reg32(info, TDCSR) & BIT0)) in free_tbuf_count()
4741 static unsigned int tbuf_bytes(struct slgt_info *info) in tbuf_bytes() argument
4744 unsigned int i = info->tbuf_current; in tbuf_bytes()
4761 count = desc_count(info->tbufs[i]); in tbuf_bytes()
4765 active_buf_count = info->tbufs[i].buf_count; in tbuf_bytes()
4766 if (++i == info->tbuf_count) in tbuf_bytes()
4768 } while (i != info->tbuf_current); in tbuf_bytes()
4771 reg_value = rd_reg32(info, TDCSR); in tbuf_bytes()
4781 if (info->tx_active) in tbuf_bytes()
4791 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) in tx_load() argument
4798 if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) in tx_load()
4801 DBGDATA(info, buf, size, "tx"); in tx_load()
4814 info->tbuf_start = i = info->tbuf_current; in tx_load()
4817 d = &info->tbufs[i]; in tx_load()
4829 if ((!size && info->params.mode == MGSL_MODE_HDLC) || in tx_load()
4830 info->params.mode == MGSL_MODE_RAW) in tx_load()
4836 if (i != info->tbuf_start) in tx_load()
4840 if (++i == info->tbuf_count) in tx_load()
4844 info->tbuf_current = i; in tx_load()
4847 d = &info->tbufs[info->tbuf_start]; in tx_load()
4851 if (!info->tx_active) in tx_load()
4852 tx_start(info); in tx_load()
4853 update_tx_timer(info); in tx_load()
4858 static int register_test(struct slgt_info *info) in register_test() argument
4867 wr_reg16(info, TIR, patterns[i]); in register_test()
4868 wr_reg16(info, BDR, patterns[(i+1)%count]); in register_test()
4869 if ((rd_reg16(info, TIR) != patterns[i]) || in register_test()
4870 (rd_reg16(info, BDR) != patterns[(i+1)%count])) { in register_test()
4875 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0; in register_test()
4876 info->init_error = rc ? 0 : DiagStatus_AddressFailure; in register_test()
4880 static int irq_test(struct slgt_info *info) in irq_test() argument
4884 struct tty_struct *oldtty = info->port.tty; in irq_test()
4885 u32 speed = info->params.data_rate; in irq_test()
4887 info->params.data_rate = 921600; in irq_test()
4888 info->port.tty = NULL; in irq_test()
4890 spin_lock_irqsave(&info->lock, flags); in irq_test()
4891 async_mode(info); in irq_test()
4892 slgt_irq_on(info, IRQ_TXIDLE); in irq_test()
4895 wr_reg16(info, TCR, in irq_test()
4896 (unsigned short)(rd_reg16(info, TCR) | BIT1)); in irq_test()
4899 wr_reg16(info, TDR, 0); in irq_test()
4902 info->init_error = DiagStatus_IrqFailure; in irq_test()
4903 info->irq_occurred = false; in irq_test()
4905 spin_unlock_irqrestore(&info->lock, flags); in irq_test()
4908 while(timeout-- && !info->irq_occurred) in irq_test()
4911 spin_lock_irqsave(&info->lock,flags); in irq_test()
4912 reset_port(info); in irq_test()
4913 spin_unlock_irqrestore(&info->lock,flags); in irq_test()
4915 info->params.data_rate = speed; in irq_test()
4916 info->port.tty = oldtty; in irq_test()
4918 info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure; in irq_test()
4919 return info->irq_occurred ? 0 : -ENODEV; in irq_test()
4922 static int loopback_test_rx(struct slgt_info *info) in loopback_test_rx() argument
4927 if (desc_complete(info->rbufs[0])) { in loopback_test_rx()
4928 count = desc_count(info->rbufs[0]); in loopback_test_rx()
4929 src = info->rbufs[0].buf; in loopback_test_rx()
4930 dest = info->tmp_rbuf; in loopback_test_rx()
4937 info->tmp_rbuf_count++; in loopback_test_rx()
4940 DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx"); in loopback_test_rx()
4946 static int loopback_test(struct slgt_info *info) in loopback_test() argument
4956 struct tty_struct *oldtty = info->port.tty; in loopback_test()
4959 memcpy(&params, &info->params, sizeof(params)); in loopback_test()
4961 info->params.mode = MGSL_MODE_ASYNC; in loopback_test()
4962 info->params.data_rate = 921600; in loopback_test()
4963 info->params.loopback = 1; in loopback_test()
4964 info->port.tty = NULL; in loopback_test()
4970 info->tmp_rbuf_count = 0; in loopback_test()
4971 memset(info->tmp_rbuf, 0, TESTFRAMESIZE); in loopback_test()
4974 spin_lock_irqsave(&info->lock,flags); in loopback_test()
4975 async_mode(info); in loopback_test()
4976 rx_start(info); in loopback_test()
4977 tx_load(info, buf, count); in loopback_test()
4978 spin_unlock_irqrestore(&info->lock, flags); in loopback_test()
4983 if (loopback_test_rx(info)) { in loopback_test()
4990 if (!rc && (info->tmp_rbuf_count != count || in loopback_test()
4991 memcmp(buf, info->tmp_rbuf, count))) { in loopback_test()
4995 spin_lock_irqsave(&info->lock,flags); in loopback_test()
4996 reset_adapter(info); in loopback_test()
4997 spin_unlock_irqrestore(&info->lock,flags); in loopback_test()
4999 memcpy(&info->params, &params, sizeof(info->params)); in loopback_test()
5000 info->port.tty = oldtty; in loopback_test()
5002 info->init_error = rc ? DiagStatus_DmaFailure : 0; in loopback_test()
5006 static int adapter_test(struct slgt_info *info) in adapter_test() argument
5008 DBGINFO(("testing %s\n", info->device_name)); in adapter_test()
5009 if (register_test(info) < 0) { in adapter_test()
5011 info->device_name, info->phys_reg_addr); in adapter_test()
5012 } else if (irq_test(info) < 0) { in adapter_test()
5014 info->device_name, info->irq_level); in adapter_test()
5015 } else if (loopback_test(info) < 0) { in adapter_test()
5016 printk("loopback test failure %s\n", info->device_name); in adapter_test()
5018 return info->init_error; in adapter_test()
5026 struct slgt_info *info = from_timer(info, t, tx_timer); in tx_timeout() local
5029 DBGINFO(("%s tx_timeout\n", info->device_name)); in tx_timeout()
5030 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) { in tx_timeout()
5031 info->icount.txtimeout++; in tx_timeout()
5033 spin_lock_irqsave(&info->lock,flags); in tx_timeout()
5034 tx_stop(info); in tx_timeout()
5035 spin_unlock_irqrestore(&info->lock,flags); in tx_timeout()
5038 if (info->netcount) in tx_timeout()
5039 hdlcdev_tx_done(info); in tx_timeout()
5042 bh_transmit(info); in tx_timeout()
5050 struct slgt_info *info = from_timer(info, t, rx_timer); in rx_timeout() local
5053 DBGINFO(("%s rx_timeout\n", info->device_name)); in rx_timeout()
5054 spin_lock_irqsave(&info->lock, flags); in rx_timeout()
5055 info->pending_bh |= BH_RECEIVE; in rx_timeout()
5056 spin_unlock_irqrestore(&info->lock, flags); in rx_timeout()
5057 bh_handler(&info->task); in rx_timeout()