Lines Matching refs:info
41 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (b… argument
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()
620 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; in open()
622 spin_lock_irqsave(&info->netlock, flags); in open()
623 if (info->netcount) { in open()
625 spin_unlock_irqrestore(&info->netlock, flags); in open()
626 mutex_unlock(&info->port.mutex); in open()
629 info->port.count++; in open()
630 spin_unlock_irqrestore(&info->netlock, flags); in open()
632 if (info->port.count == 1) { in open()
634 retval = startup(info); in open()
636 mutex_unlock(&info->port.mutex); in open()
640 mutex_unlock(&info->port.mutex); in open()
641 retval = block_til_ready(tty, filp, info); in open()
643 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); in open()
652 info->port.tty = NULL; /* tty layer will release tty struct */ in open()
653 if(info->port.count) in open()
654 info->port.count--; in open()
657 DBGINFO(("%s open rc=%d\n", info->device_name, retval)); in open()
663 struct slgt_info *info = tty->driver_data; in close() local
665 if (sanity_check(info, tty->name, "close")) in close()
667 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); in close()
669 if (tty_port_close_start(&info->port, tty, filp) == 0) in close()
672 mutex_lock(&info->port.mutex); in close()
673 if (tty_port_initialized(&info->port)) in close()
674 wait_until_sent(tty, info->timeout); in close()
678 shutdown(info); in close()
679 mutex_unlock(&info->port.mutex); in close()
681 tty_port_close_end(&info->port, tty); in close()
682 info->port.tty = NULL; in close()
684 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); in close()
689 struct slgt_info *info = tty->driver_data; in hangup() local
692 if (sanity_check(info, tty->name, "hangup")) in hangup()
694 DBGINFO(("%s hangup\n", info->device_name)); in hangup()
698 mutex_lock(&info->port.mutex); in hangup()
699 shutdown(info); in hangup()
701 spin_lock_irqsave(&info->port.lock, flags); in hangup()
702 info->port.count = 0; in hangup()
703 info->port.tty = NULL; in hangup()
704 spin_unlock_irqrestore(&info->port.lock, flags); in hangup()
705 tty_port_set_active(&info->port, 0); in hangup()
706 mutex_unlock(&info->port.mutex); in hangup()
708 wake_up_interruptible(&info->port.open_wait); in hangup()
713 struct slgt_info *info = tty->driver_data; in set_termios() local
718 change_params(info); in set_termios()
722 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in set_termios()
723 spin_lock_irqsave(&info->lock,flags); in set_termios()
724 set_gtsignals(info); in set_termios()
725 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
730 info->signals |= SerialSignal_DTR; in set_termios()
732 info->signals |= SerialSignal_RTS; in set_termios()
733 spin_lock_irqsave(&info->lock,flags); in set_termios()
734 set_gtsignals(info); in set_termios()
735 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
745 static void update_tx_timer(struct slgt_info *info) in update_tx_timer() argument
751 if (info->params.mode == MGSL_MODE_HDLC) { in update_tx_timer()
752 int timeout = (tbuf_bytes(info) * 7) + 1000; in update_tx_timer()
753 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout)); in update_tx_timer()
761 struct slgt_info *info = tty->driver_data; in write() local
764 if (sanity_check(info, tty->name, "write")) in write()
767 DBGINFO(("%s write count=%d\n", info->device_name, count)); in write()
769 if (!info->tx_buf || (count > info->max_frame_size)) in write()
775 spin_lock_irqsave(&info->lock, flags); in write()
777 if (info->tx_count) { in write()
779 if (!tx_load(info, info->tx_buf, info->tx_count)) in write()
781 info->tx_count = 0; in write()
784 if (tx_load(info, buf, count)) in write()
788 spin_unlock_irqrestore(&info->lock, flags); in write()
789 DBGINFO(("%s write rc=%d\n", info->device_name, ret)); in write()
795 struct slgt_info *info = tty->driver_data; in put_char() local
799 if (sanity_check(info, tty->name, "put_char")) in put_char()
801 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); in put_char()
802 if (!info->tx_buf) in put_char()
804 spin_lock_irqsave(&info->lock,flags); in put_char()
805 if (info->tx_count < info->max_frame_size) { in put_char()
806 info->tx_buf[info->tx_count++] = ch; in put_char()
809 spin_unlock_irqrestore(&info->lock,flags); in put_char()
815 struct slgt_info *info = tty->driver_data; in send_xchar() local
818 if (sanity_check(info, tty->name, "send_xchar")) in send_xchar()
820 DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch)); in send_xchar()
821 info->x_char = ch; in send_xchar()
823 spin_lock_irqsave(&info->lock,flags); in send_xchar()
824 if (!info->tx_enabled) in send_xchar()
825 tx_start(info); in send_xchar()
826 spin_unlock_irqrestore(&info->lock,flags); in send_xchar()
832 struct slgt_info *info = tty->driver_data; in wait_until_sent() local
835 if (!info ) in wait_until_sent()
837 if (sanity_check(info, tty->name, "wait_until_sent")) in wait_until_sent()
839 DBGINFO(("%s wait_until_sent entry\n", info->device_name)); in wait_until_sent()
840 if (!tty_port_initialized(&info->port)) in wait_until_sent()
851 if (info->params.data_rate) { in wait_until_sent()
852 char_time = info->timeout/(32 * 5); in wait_until_sent()
861 while (info->tx_active) { in wait_until_sent()
869 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); in wait_until_sent()
874 struct slgt_info *info = tty->driver_data; in write_room() local
877 if (sanity_check(info, tty->name, "write_room")) in write_room()
879 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; in write_room()
880 DBGINFO(("%s write_room=%d\n", info->device_name, ret)); in write_room()
886 struct slgt_info *info = tty->driver_data; in flush_chars() local
889 if (sanity_check(info, tty->name, "flush_chars")) in flush_chars()
891 DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count)); in flush_chars()
893 if (info->tx_count <= 0 || tty->stopped || in flush_chars()
894 tty->hw_stopped || !info->tx_buf) in flush_chars()
897 DBGINFO(("%s flush_chars start transmit\n", info->device_name)); in flush_chars()
899 spin_lock_irqsave(&info->lock,flags); in flush_chars()
900 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in flush_chars()
901 info->tx_count = 0; in flush_chars()
902 spin_unlock_irqrestore(&info->lock,flags); in flush_chars()
907 struct slgt_info *info = tty->driver_data; in flush_buffer() local
910 if (sanity_check(info, tty->name, "flush_buffer")) in flush_buffer()
912 DBGINFO(("%s flush_buffer\n", info->device_name)); in flush_buffer()
914 spin_lock_irqsave(&info->lock, flags); in flush_buffer()
915 info->tx_count = 0; in flush_buffer()
916 spin_unlock_irqrestore(&info->lock, flags); in flush_buffer()
926 struct slgt_info *info = tty->driver_data; in tx_hold() local
929 if (sanity_check(info, tty->name, "tx_hold")) in tx_hold()
931 DBGINFO(("%s tx_hold\n", info->device_name)); in tx_hold()
932 spin_lock_irqsave(&info->lock,flags); in tx_hold()
933 if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC) in tx_hold()
934 tx_stop(info); in tx_hold()
935 spin_unlock_irqrestore(&info->lock,flags); in tx_hold()
943 struct slgt_info *info = tty->driver_data; in tx_release() local
946 if (sanity_check(info, tty->name, "tx_release")) in tx_release()
948 DBGINFO(("%s tx_release\n", info->device_name)); in tx_release()
949 spin_lock_irqsave(&info->lock, flags); in tx_release()
950 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in tx_release()
951 info->tx_count = 0; in tx_release()
952 spin_unlock_irqrestore(&info->lock, flags); in tx_release()
969 struct slgt_info *info = tty->driver_data; in ioctl() local
973 if (sanity_check(info, tty->name, "ioctl")) in ioctl()
975 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); in ioctl()
984 return wait_mgsl_event(info, argp); in ioctl()
986 return modem_input_wait(info,(int)arg); in ioctl()
988 return set_gpio(info, argp); in ioctl()
990 return get_gpio(info, argp); in ioctl()
992 return wait_gpio(info, argp); in ioctl()
994 return get_xsync(info, argp); in ioctl()
996 return set_xsync(info, (int)arg); in ioctl()
998 return get_xctrl(info, argp); in ioctl()
1000 return set_xctrl(info, (int)arg); in ioctl()
1002 mutex_lock(&info->port.mutex); in ioctl()
1005 ret = get_params(info, argp); in ioctl()
1008 ret = set_params(info, argp); in ioctl()
1011 ret = get_txidle(info, argp); in ioctl()
1014 ret = set_txidle(info, (int)arg); in ioctl()
1017 ret = tx_enable(info, (int)arg); in ioctl()
1020 ret = rx_enable(info, (int)arg); in ioctl()
1023 ret = tx_abort(info); in ioctl()
1026 ret = get_stats(info, argp); in ioctl()
1029 ret = get_interface(info, argp); in ioctl()
1032 ret = set_interface(info,(int)arg); in ioctl()
1037 mutex_unlock(&info->port.mutex); in ioctl()
1045 struct slgt_info *info = tty->driver_data; in get_icount() local
1049 spin_lock_irqsave(&info->lock,flags); in get_icount()
1050 cnow = info->icount; in get_icount()
1051 spin_unlock_irqrestore(&info->lock,flags); in get_icount()
1072 static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params) in get_params32() argument
1076 DBGINFO(("%s get_params32\n", info->device_name)); in get_params32()
1078 tmp_params.mode = (compat_ulong_t)info->params.mode; in get_params32()
1079 tmp_params.loopback = info->params.loopback; in get_params32()
1080 tmp_params.flags = info->params.flags; in get_params32()
1081 tmp_params.encoding = info->params.encoding; in get_params32()
1082 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed; in get_params32()
1083 tmp_params.addr_filter = info->params.addr_filter; in get_params32()
1084 tmp_params.crc_type = info->params.crc_type; in get_params32()
1085 tmp_params.preamble_length = info->params.preamble_length; in get_params32()
1086 tmp_params.preamble = info->params.preamble; in get_params32()
1087 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate; in get_params32()
1088 tmp_params.data_bits = info->params.data_bits; in get_params32()
1089 tmp_params.stop_bits = info->params.stop_bits; in get_params32()
1090 tmp_params.parity = info->params.parity; in get_params32()
1096 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params) in set_params32() argument
1100 DBGINFO(("%s set_params32\n", info->device_name)); in set_params32()
1104 spin_lock(&info->lock); in set_params32()
1106 info->base_clock = tmp_params.clock_speed; in set_params32()
1108 info->params.mode = tmp_params.mode; in set_params32()
1109 info->params.loopback = tmp_params.loopback; in set_params32()
1110 info->params.flags = tmp_params.flags; in set_params32()
1111 info->params.encoding = tmp_params.encoding; in set_params32()
1112 info->params.clock_speed = tmp_params.clock_speed; in set_params32()
1113 info->params.addr_filter = tmp_params.addr_filter; in set_params32()
1114 info->params.crc_type = tmp_params.crc_type; in set_params32()
1115 info->params.preamble_length = tmp_params.preamble_length; in set_params32()
1116 info->params.preamble = tmp_params.preamble; in set_params32()
1117 info->params.data_rate = tmp_params.data_rate; in set_params32()
1118 info->params.data_bits = tmp_params.data_bits; in set_params32()
1119 info->params.stop_bits = tmp_params.stop_bits; in set_params32()
1120 info->params.parity = tmp_params.parity; in set_params32()
1122 spin_unlock(&info->lock); in set_params32()
1124 program_hw(info); in set_params32()
1132 struct slgt_info *info = tty->driver_data; in slgt_compat_ioctl() local
1135 if (sanity_check(info, tty->name, "compat_ioctl")) in slgt_compat_ioctl()
1137 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd)); in slgt_compat_ioctl()
1141 rc = set_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1145 rc = get_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1164 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc)); in slgt_compat_ioctl()
1174 static inline void line_info(struct seq_file *m, struct slgt_info *info) in line_info() argument
1180 info->device_name, info->phys_reg_addr, in line_info()
1181 info->irq_level, info->max_frame_size); in line_info()
1184 spin_lock_irqsave(&info->lock,flags); in line_info()
1185 get_gtsignals(info); in line_info()
1186 spin_unlock_irqrestore(&info->lock,flags); in line_info()
1190 if (info->signals & SerialSignal_RTS) in line_info()
1192 if (info->signals & SerialSignal_CTS) in line_info()
1194 if (info->signals & SerialSignal_DTR) in line_info()
1196 if (info->signals & SerialSignal_DSR) in line_info()
1198 if (info->signals & SerialSignal_DCD) in line_info()
1200 if (info->signals & SerialSignal_RI) in line_info()
1203 if (info->params.mode != MGSL_MODE_ASYNC) { in line_info()
1205 info->icount.txok, info->icount.rxok); in line_info()
1206 if (info->icount.txunder) in line_info()
1207 seq_printf(m, " txunder:%d", info->icount.txunder); in line_info()
1208 if (info->icount.txabort) in line_info()
1209 seq_printf(m, " txabort:%d", info->icount.txabort); in line_info()
1210 if (info->icount.rxshort) in line_info()
1211 seq_printf(m, " rxshort:%d", info->icount.rxshort); in line_info()
1212 if (info->icount.rxlong) in line_info()
1213 seq_printf(m, " rxlong:%d", info->icount.rxlong); in line_info()
1214 if (info->icount.rxover) in line_info()
1215 seq_printf(m, " rxover:%d", info->icount.rxover); in line_info()
1216 if (info->icount.rxcrc) in line_info()
1217 seq_printf(m, " rxcrc:%d", info->icount.rxcrc); in line_info()
1220 info->icount.tx, info->icount.rx); in line_info()
1221 if (info->icount.frame) in line_info()
1222 seq_printf(m, " fe:%d", info->icount.frame); in line_info()
1223 if (info->icount.parity) in line_info()
1224 seq_printf(m, " pe:%d", info->icount.parity); in line_info()
1225 if (info->icount.brk) in line_info()
1226 seq_printf(m, " brk:%d", info->icount.brk); in line_info()
1227 if (info->icount.overrun) in line_info()
1228 seq_printf(m, " oe:%d", info->icount.overrun); in line_info()
1235 info->tx_active,info->bh_requested,info->bh_running, in line_info()
1236 info->pending_bh); in line_info()
1243 struct slgt_info *info; in synclink_gt_proc_show() local
1247 info = slgt_device_list; in synclink_gt_proc_show()
1248 while( info ) { in synclink_gt_proc_show()
1249 line_info(m, info); in synclink_gt_proc_show()
1250 info = info->next_device; in synclink_gt_proc_show()
1260 struct slgt_info *info = tty->driver_data; in chars_in_buffer() local
1262 if (sanity_check(info, tty->name, "chars_in_buffer")) in chars_in_buffer()
1264 count = tbuf_bytes(info); in chars_in_buffer()
1265 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count)); in chars_in_buffer()
1274 struct slgt_info *info = tty->driver_data; in throttle() local
1277 if (sanity_check(info, tty->name, "throttle")) in throttle()
1279 DBGINFO(("%s throttle\n", info->device_name)); in throttle()
1283 spin_lock_irqsave(&info->lock,flags); in throttle()
1284 info->signals &= ~SerialSignal_RTS; in throttle()
1285 set_gtsignals(info); in throttle()
1286 spin_unlock_irqrestore(&info->lock,flags); in throttle()
1295 struct slgt_info *info = tty->driver_data; in unthrottle() local
1298 if (sanity_check(info, tty->name, "unthrottle")) in unthrottle()
1300 DBGINFO(("%s unthrottle\n", info->device_name)); in unthrottle()
1302 if (info->x_char) in unthrottle()
1303 info->x_char = 0; in unthrottle()
1308 spin_lock_irqsave(&info->lock,flags); in unthrottle()
1309 info->signals |= SerialSignal_RTS; in unthrottle()
1310 set_gtsignals(info); in unthrottle()
1311 spin_unlock_irqrestore(&info->lock,flags); in unthrottle()
1321 struct slgt_info *info = tty->driver_data; in set_break() local
1325 if (sanity_check(info, tty->name, "set_break")) in set_break()
1327 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); in set_break()
1329 spin_lock_irqsave(&info->lock,flags); in set_break()
1330 value = rd_reg16(info, TCR); in set_break()
1335 wr_reg16(info, TCR, value); in set_break()
1336 spin_unlock_irqrestore(&info->lock,flags); in set_break()
1355 struct slgt_info *info = dev_to_port(dev); in hdlcdev_attach() local
1360 if (info->port.count) in hdlcdev_attach()
1363 DBGINFO(("%s hdlcdev_attach\n", info->device_name)); in hdlcdev_attach()
1383 info->params.encoding = new_encoding; in hdlcdev_attach()
1384 info->params.crc_type = new_crctype; in hdlcdev_attach()
1387 if (info->netcount) in hdlcdev_attach()
1388 program_hw(info); in hdlcdev_attach()
1401 struct slgt_info *info = dev_to_port(dev); in hdlcdev_xmit() local
1419 spin_lock_irqsave(&info->lock, flags); in hdlcdev_xmit()
1420 tx_load(info, skb->data, skb->len); in hdlcdev_xmit()
1421 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_xmit()
1439 struct slgt_info *info = dev_to_port(dev); in hdlcdev_open() local
1454 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1455 if (info->port.count != 0 || info->netcount != 0) { in hdlcdev_open()
1457 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1460 info->netcount=1; in hdlcdev_open()
1461 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1464 if ((rc = startup(info)) != 0) { in hdlcdev_open()
1465 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1466 info->netcount=0; in hdlcdev_open()
1467 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1472 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in hdlcdev_open()
1473 program_hw(info); in hdlcdev_open()
1480 spin_lock_irqsave(&info->lock, flags); in hdlcdev_open()
1481 get_gtsignals(info); in hdlcdev_open()
1482 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_open()
1483 if (info->signals & SerialSignal_DCD) in hdlcdev_open()
1500 struct slgt_info *info = dev_to_port(dev); in hdlcdev_close() local
1508 shutdown(info); in hdlcdev_close()
1512 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_close()
1513 info->netcount=0; in hdlcdev_close()
1514 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_close()
1533 struct slgt_info *info = dev_to_port(dev); in hdlcdev_ioctl() local
1539 if (info->port.count) in hdlcdev_ioctl()
1556 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1569 new_line.clock_rate = info->params.clock_speed; in hdlcdev_ioctl()
1570 new_line.loopback = info->params.loopback ? 1:0; in hdlcdev_ioctl()
1589 case CLOCK_DEFAULT: flags = info->params.flags & in hdlcdev_ioctl()
1600 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1604 info->params.flags |= flags; in hdlcdev_ioctl()
1606 info->params.loopback = new_line.loopback; in hdlcdev_ioctl()
1609 info->params.clock_speed = new_line.clock_rate; in hdlcdev_ioctl()
1611 info->params.clock_speed = 0; in hdlcdev_ioctl()
1614 if (info->netcount) in hdlcdev_ioctl()
1615 program_hw(info); in hdlcdev_ioctl()
1629 struct slgt_info *info = dev_to_port(dev); in hdlcdev_tx_timeout() local
1637 spin_lock_irqsave(&info->lock,flags); in hdlcdev_tx_timeout()
1638 tx_stop(info); in hdlcdev_tx_timeout()
1639 spin_unlock_irqrestore(&info->lock,flags); in hdlcdev_tx_timeout()
1650 static void hdlcdev_tx_done(struct slgt_info *info) in hdlcdev_tx_done() argument
1652 if (netif_queue_stopped(info->netdev)) in hdlcdev_tx_done()
1653 netif_wake_queue(info->netdev); in hdlcdev_tx_done()
1664 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size) in hdlcdev_rx() argument
1667 struct net_device *dev = info->netdev; in hdlcdev_rx()
1703 static int hdlcdev_init(struct slgt_info *info) in hdlcdev_init() argument
1711 dev = alloc_hdlcdev(info); in hdlcdev_init()
1713 printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name); in hdlcdev_init()
1718 dev->mem_start = info->phys_reg_addr; in hdlcdev_init()
1719 dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1; in hdlcdev_init()
1720 dev->irq = info->irq_level; in hdlcdev_init()
1740 info->netdev = dev; in hdlcdev_init()
1750 static void hdlcdev_exit(struct slgt_info *info) in hdlcdev_exit() argument
1752 if (!info->netdev) in hdlcdev_exit()
1754 unregister_hdlc_device(info->netdev); in hdlcdev_exit()
1755 free_netdev(info->netdev); in hdlcdev_exit()
1756 info->netdev = NULL; in hdlcdev_exit()
1764 static void rx_async(struct slgt_info *info) in rx_async() argument
1766 struct mgsl_icount *icount = &info->icount; in rx_async()
1770 struct slgt_desc *bufs = info->rbufs; in rx_async()
1776 start = end = info->rbuf_current; in rx_async()
1779 count = desc_count(bufs[end]) - info->rbuf_index; in rx_async()
1780 p = bufs[end].buf + info->rbuf_index; in rx_async()
1782 DBGISR(("%s rx_async count=%d\n", info->device_name, count)); in rx_async()
1783 DBGDATA(info, p, count, "rx"); in rx_async()
1798 if (status & info->ignore_status_mask) in rx_async()
1805 tty_insert_flip_char(&info->port, ch, stat); in rx_async()
1811 info->rbuf_index += i; in rx_async()
1812 mod_timer(&info->rx_timer, jiffies + 1); in rx_async()
1816 info->rbuf_index = 0; in rx_async()
1817 free_rbufs(info, end, end); in rx_async()
1819 if (++end == info->rbuf_count) in rx_async()
1828 tty_flip_buffer_push(&info->port); in rx_async()
1834 static int bh_action(struct slgt_info *info) in bh_action() argument
1839 spin_lock_irqsave(&info->lock,flags); in bh_action()
1841 if (info->pending_bh & BH_RECEIVE) { in bh_action()
1842 info->pending_bh &= ~BH_RECEIVE; in bh_action()
1844 } else if (info->pending_bh & BH_TRANSMIT) { in bh_action()
1845 info->pending_bh &= ~BH_TRANSMIT; in bh_action()
1847 } else if (info->pending_bh & BH_STATUS) { in bh_action()
1848 info->pending_bh &= ~BH_STATUS; in bh_action()
1852 info->bh_running = false; in bh_action()
1853 info->bh_requested = false; in bh_action()
1857 spin_unlock_irqrestore(&info->lock,flags); in bh_action()
1867 struct slgt_info *info = container_of(work, struct slgt_info, task); in bh_handler() local
1870 info->bh_running = true; in bh_handler()
1872 while((action = bh_action(info))) { in bh_handler()
1875 DBGBH(("%s bh receive\n", info->device_name)); in bh_handler()
1876 switch(info->params.mode) { in bh_handler()
1878 rx_async(info); in bh_handler()
1881 while(rx_get_frame(info)); in bh_handler()
1887 while(rx_get_buf(info)); in bh_handler()
1891 if (info->rx_restart) in bh_handler()
1892 rx_start(info); in bh_handler()
1895 bh_transmit(info); in bh_handler()
1898 DBGBH(("%s bh status\n", info->device_name)); in bh_handler()
1899 info->ri_chkcount = 0; in bh_handler()
1900 info->dsr_chkcount = 0; in bh_handler()
1901 info->dcd_chkcount = 0; in bh_handler()
1902 info->cts_chkcount = 0; in bh_handler()
1905 DBGBH(("%s unknown action\n", info->device_name)); in bh_handler()
1909 DBGBH(("%s bh_handler exit\n", info->device_name)); in bh_handler()
1912 static void bh_transmit(struct slgt_info *info) in bh_transmit() argument
1914 struct tty_struct *tty = info->port.tty; in bh_transmit()
1916 DBGBH(("%s bh_transmit\n", info->device_name)); in bh_transmit()
1921 static void dsr_change(struct slgt_info *info, unsigned short status) in dsr_change() argument
1924 info->signals |= SerialSignal_DSR; in dsr_change()
1925 info->input_signal_events.dsr_up++; in dsr_change()
1927 info->signals &= ~SerialSignal_DSR; in dsr_change()
1928 info->input_signal_events.dsr_down++; in dsr_change()
1930 DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); in dsr_change()
1931 if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dsr_change()
1932 slgt_irq_off(info, IRQ_DSR); in dsr_change()
1935 info->icount.dsr++; in dsr_change()
1936 wake_up_interruptible(&info->status_event_wait_q); in dsr_change()
1937 wake_up_interruptible(&info->event_wait_q); in dsr_change()
1938 info->pending_bh |= BH_STATUS; in dsr_change()
1941 static void cts_change(struct slgt_info *info, unsigned short status) in cts_change() argument
1944 info->signals |= SerialSignal_CTS; in cts_change()
1945 info->input_signal_events.cts_up++; in cts_change()
1947 info->signals &= ~SerialSignal_CTS; in cts_change()
1948 info->input_signal_events.cts_down++; in cts_change()
1950 DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); in cts_change()
1951 if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in cts_change()
1952 slgt_irq_off(info, IRQ_CTS); in cts_change()
1955 info->icount.cts++; in cts_change()
1956 wake_up_interruptible(&info->status_event_wait_q); in cts_change()
1957 wake_up_interruptible(&info->event_wait_q); in cts_change()
1958 info->pending_bh |= BH_STATUS; in cts_change()
1960 if (tty_port_cts_enabled(&info->port)) { in cts_change()
1961 if (info->port.tty) { in cts_change()
1962 if (info->port.tty->hw_stopped) { in cts_change()
1963 if (info->signals & SerialSignal_CTS) { in cts_change()
1964 info->port.tty->hw_stopped = 0; in cts_change()
1965 info->pending_bh |= BH_TRANSMIT; in cts_change()
1969 if (!(info->signals & SerialSignal_CTS)) in cts_change()
1970 info->port.tty->hw_stopped = 1; in cts_change()
1976 static void dcd_change(struct slgt_info *info, unsigned short status) in dcd_change() argument
1979 info->signals |= SerialSignal_DCD; in dcd_change()
1980 info->input_signal_events.dcd_up++; in dcd_change()
1982 info->signals &= ~SerialSignal_DCD; in dcd_change()
1983 info->input_signal_events.dcd_down++; in dcd_change()
1985 DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); in dcd_change()
1986 if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dcd_change()
1987 slgt_irq_off(info, IRQ_DCD); in dcd_change()
1990 info->icount.dcd++; in dcd_change()
1992 if (info->netcount) { in dcd_change()
1993 if (info->signals & SerialSignal_DCD) in dcd_change()
1994 netif_carrier_on(info->netdev); in dcd_change()
1996 netif_carrier_off(info->netdev); in dcd_change()
1999 wake_up_interruptible(&info->status_event_wait_q); in dcd_change()
2000 wake_up_interruptible(&info->event_wait_q); in dcd_change()
2001 info->pending_bh |= BH_STATUS; in dcd_change()
2003 if (tty_port_check_carrier(&info->port)) { in dcd_change()
2004 if (info->signals & SerialSignal_DCD) in dcd_change()
2005 wake_up_interruptible(&info->port.open_wait); in dcd_change()
2007 if (info->port.tty) in dcd_change()
2008 tty_hangup(info->port.tty); in dcd_change()
2013 static void ri_change(struct slgt_info *info, unsigned short status) in ri_change() argument
2016 info->signals |= SerialSignal_RI; in ri_change()
2017 info->input_signal_events.ri_up++; in ri_change()
2019 info->signals &= ~SerialSignal_RI; in ri_change()
2020 info->input_signal_events.ri_down++; in ri_change()
2022 DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); in ri_change()
2023 if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in ri_change()
2024 slgt_irq_off(info, IRQ_RI); in ri_change()
2027 info->icount.rng++; in ri_change()
2028 wake_up_interruptible(&info->status_event_wait_q); in ri_change()
2029 wake_up_interruptible(&info->event_wait_q); in ri_change()
2030 info->pending_bh |= BH_STATUS; in ri_change()
2033 static void isr_rxdata(struct slgt_info *info) in isr_rxdata() argument
2035 unsigned int count = info->rbuf_fill_count; in isr_rxdata()
2036 unsigned int i = info->rbuf_fill_index; in isr_rxdata()
2039 while (rd_reg16(info, SSR) & IRQ_RXDATA) { in isr_rxdata()
2040 reg = rd_reg16(info, RDR); in isr_rxdata()
2041 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); in isr_rxdata()
2042 if (desc_complete(info->rbufs[i])) { in isr_rxdata()
2044 rx_stop(info); in isr_rxdata()
2045 info->rx_restart = true; in isr_rxdata()
2048 info->rbufs[i].buf[count++] = (unsigned char)reg; in isr_rxdata()
2050 if (info->params.mode == MGSL_MODE_ASYNC) in isr_rxdata()
2051 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); in isr_rxdata()
2052 if (count == info->rbuf_fill_level || (reg & BIT10)) { in isr_rxdata()
2054 set_desc_count(info->rbufs[i], count); in isr_rxdata()
2055 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); in isr_rxdata()
2056 info->rbuf_fill_count = count = 0; in isr_rxdata()
2057 if (++i == info->rbuf_count) in isr_rxdata()
2059 info->pending_bh |= BH_RECEIVE; in isr_rxdata()
2063 info->rbuf_fill_index = i; in isr_rxdata()
2064 info->rbuf_fill_count = count; in isr_rxdata()
2067 static void isr_serial(struct slgt_info *info) in isr_serial() argument
2069 unsigned short status = rd_reg16(info, SSR); in isr_serial()
2071 DBGISR(("%s isr_serial status=%04X\n", info->device_name, status)); in isr_serial()
2073 wr_reg16(info, SSR, status); /* clear pending */ in isr_serial()
2075 info->irq_occurred = true; in isr_serial()
2077 if (info->params.mode == MGSL_MODE_ASYNC) { in isr_serial()
2079 if (info->tx_active) in isr_serial()
2080 isr_txeom(info, status); in isr_serial()
2082 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2083 isr_rxdata(info); in isr_serial()
2085 info->icount.brk++; in isr_serial()
2087 if (info->port.tty) { in isr_serial()
2088 if (!(status & info->ignore_status_mask)) { in isr_serial()
2089 if (info->read_status_mask & MASK_BREAK) { in isr_serial()
2090 tty_insert_flip_char(&info->port, 0, TTY_BREAK); in isr_serial()
2091 if (info->port.flags & ASYNC_SAK) in isr_serial()
2092 do_SAK(info->port.tty); in isr_serial()
2099 isr_txeom(info, status); in isr_serial()
2100 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2101 isr_rxdata(info); in isr_serial()
2104 info->icount.rxidle++; in isr_serial()
2106 info->icount.exithunt++; in isr_serial()
2107 wake_up_interruptible(&info->event_wait_q); in isr_serial()
2111 rx_start(info); in isr_serial()
2115 dsr_change(info, status); in isr_serial()
2117 cts_change(info, status); in isr_serial()
2119 dcd_change(info, status); in isr_serial()
2121 ri_change(info, status); in isr_serial()
2124 static void isr_rdma(struct slgt_info *info) in isr_rdma() argument
2126 unsigned int status = rd_reg32(info, RDCSR); in isr_rdma()
2128 DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status)); in isr_rdma()
2141 wr_reg32(info, RDCSR, status); /* clear pending */ in isr_rdma()
2144 DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); in isr_rdma()
2145 info->rx_restart = true; in isr_rdma()
2147 info->pending_bh |= BH_RECEIVE; in isr_rdma()
2150 static void isr_tdma(struct slgt_info *info) in isr_tdma() argument
2152 unsigned int status = rd_reg32(info, TDCSR); in isr_tdma()
2154 DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status)); in isr_tdma()
2166 wr_reg32(info, TDCSR, status); /* clear pending */ in isr_tdma()
2171 info->pending_bh |= BH_TRANSMIT; in isr_tdma()
2181 static bool unsent_tbufs(struct slgt_info *info) in unsent_tbufs() argument
2183 unsigned int i = info->tbuf_current; in unsent_tbufs()
2195 i = info->tbuf_count - 1; in unsent_tbufs()
2196 if (!desc_count(info->tbufs[i])) in unsent_tbufs()
2198 info->tbuf_start = i; in unsent_tbufs()
2200 } while (i != info->tbuf_current); in unsent_tbufs()
2205 static void isr_txeom(struct slgt_info *info, unsigned short status) in isr_txeom() argument
2207 DBGISR(("%s txeom status=%04x\n", info->device_name, status)); in isr_txeom()
2209 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in isr_txeom()
2210 tdma_reset(info); in isr_txeom()
2212 unsigned short val = rd_reg16(info, TCR); in isr_txeom()
2213 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in isr_txeom()
2214 wr_reg16(info, TCR, val); /* clear reset bit */ in isr_txeom()
2217 if (info->tx_active) { in isr_txeom()
2218 if (info->params.mode != MGSL_MODE_ASYNC) { in isr_txeom()
2220 info->icount.txunder++; in isr_txeom()
2222 info->icount.txok++; in isr_txeom()
2225 if (unsent_tbufs(info)) { in isr_txeom()
2226 tx_start(info); in isr_txeom()
2227 update_tx_timer(info); in isr_txeom()
2230 info->tx_active = false; in isr_txeom()
2232 del_timer(&info->tx_timer); in isr_txeom()
2234 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { in isr_txeom()
2235 info->signals &= ~SerialSignal_RTS; in isr_txeom()
2236 info->drop_rts_on_tx_done = false; in isr_txeom()
2237 set_gtsignals(info); in isr_txeom()
2241 if (info->netcount) in isr_txeom()
2242 hdlcdev_tx_done(info); in isr_txeom()
2246 if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) { in isr_txeom()
2247 tx_stop(info); in isr_txeom()
2250 info->pending_bh |= BH_TRANSMIT; in isr_txeom()
2255 static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state) in isr_gpio() argument
2260 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) { in isr_gpio()
2267 info->gpio_wait_q = w->next; in isr_gpio()
2280 struct slgt_info *info = dev_id; in slgt_interrupt() local
2284 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); in slgt_interrupt()
2286 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { in slgt_interrupt()
2287 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); in slgt_interrupt()
2288 info->irq_occurred = true; in slgt_interrupt()
2289 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2290 if (info->port_array[i] == NULL) in slgt_interrupt()
2292 spin_lock(&info->port_array[i]->lock); in slgt_interrupt()
2294 isr_serial(info->port_array[i]); in slgt_interrupt()
2296 isr_rdma(info->port_array[i]); in slgt_interrupt()
2298 isr_tdma(info->port_array[i]); in slgt_interrupt()
2299 spin_unlock(&info->port_array[i]->lock); in slgt_interrupt()
2303 if (info->gpio_present) { in slgt_interrupt()
2306 spin_lock(&info->lock); in slgt_interrupt()
2307 while ((changed = rd_reg32(info, IOSR)) != 0) { in slgt_interrupt()
2308 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); in slgt_interrupt()
2310 state = rd_reg32(info, IOVR); in slgt_interrupt()
2312 wr_reg32(info, IOSR, changed); in slgt_interrupt()
2313 for (i=0 ; i < info->port_count ; i++) { in slgt_interrupt()
2314 if (info->port_array[i] != NULL) in slgt_interrupt()
2315 isr_gpio(info->port_array[i], changed, state); in slgt_interrupt()
2318 spin_unlock(&info->lock); in slgt_interrupt()
2321 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2322 struct slgt_info *port = info->port_array[i]; in slgt_interrupt()
2336 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); in slgt_interrupt()
2340 static int startup(struct slgt_info *info) in startup() argument
2342 DBGINFO(("%s startup\n", info->device_name)); in startup()
2344 if (tty_port_initialized(&info->port)) in startup()
2347 if (!info->tx_buf) { in startup()
2348 info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); in startup()
2349 if (!info->tx_buf) { in startup()
2350 DBGERR(("%s can't allocate tx buffer\n", info->device_name)); in startup()
2355 info->pending_bh = 0; in startup()
2357 memset(&info->icount, 0, sizeof(info->icount)); in startup()
2360 change_params(info); in startup()
2362 if (info->port.tty) in startup()
2363 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); in startup()
2365 tty_port_set_initialized(&info->port, 1); in startup()
2373 static void shutdown(struct slgt_info *info) in shutdown() argument
2377 if (!tty_port_initialized(&info->port)) in shutdown()
2380 DBGINFO(("%s shutdown\n", info->device_name)); in shutdown()
2384 wake_up_interruptible(&info->status_event_wait_q); in shutdown()
2385 wake_up_interruptible(&info->event_wait_q); in shutdown()
2387 del_timer_sync(&info->tx_timer); in shutdown()
2388 del_timer_sync(&info->rx_timer); in shutdown()
2390 kfree(info->tx_buf); in shutdown()
2391 info->tx_buf = NULL; in shutdown()
2393 spin_lock_irqsave(&info->lock,flags); in shutdown()
2395 tx_stop(info); in shutdown()
2396 rx_stop(info); in shutdown()
2398 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in shutdown()
2400 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { in shutdown()
2401 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in shutdown()
2402 set_gtsignals(info); in shutdown()
2405 flush_cond_wait(&info->gpio_wait_q); in shutdown()
2407 spin_unlock_irqrestore(&info->lock,flags); in shutdown()
2409 if (info->port.tty) in shutdown()
2410 set_bit(TTY_IO_ERROR, &info->port.tty->flags); in shutdown()
2412 tty_port_set_initialized(&info->port, 0); in shutdown()
2415 static void program_hw(struct slgt_info *info) in program_hw() argument
2419 spin_lock_irqsave(&info->lock,flags); in program_hw()
2421 rx_stop(info); in program_hw()
2422 tx_stop(info); in program_hw()
2424 if (info->params.mode != MGSL_MODE_ASYNC || in program_hw()
2425 info->netcount) in program_hw()
2426 sync_mode(info); in program_hw()
2428 async_mode(info); in program_hw()
2430 set_gtsignals(info); in program_hw()
2432 info->dcd_chkcount = 0; in program_hw()
2433 info->cts_chkcount = 0; in program_hw()
2434 info->ri_chkcount = 0; in program_hw()
2435 info->dsr_chkcount = 0; in program_hw()
2437 slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI); in program_hw()
2438 get_gtsignals(info); in program_hw()
2440 if (info->netcount || in program_hw()
2441 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) in program_hw()
2442 rx_start(info); in program_hw()
2444 spin_unlock_irqrestore(&info->lock,flags); in program_hw()
2450 static void change_params(struct slgt_info *info) in change_params() argument
2455 if (!info->port.tty) in change_params()
2457 DBGINFO(("%s change_params\n", info->device_name)); in change_params()
2459 cflag = info->port.tty->termios.c_cflag; in change_params()
2464 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in change_params()
2466 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in change_params()
2471 case CS5: info->params.data_bits = 5; break; in change_params()
2472 case CS6: info->params.data_bits = 6; break; in change_params()
2473 case CS7: info->params.data_bits = 7; break; in change_params()
2474 case CS8: info->params.data_bits = 8; break; in change_params()
2475 default: info->params.data_bits = 7; break; in change_params()
2478 info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1; in change_params()
2481 info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN; in change_params()
2483 info->params.parity = ASYNC_PARITY_NONE; in change_params()
2488 bits_per_char = info->params.data_bits + in change_params()
2489 info->params.stop_bits + 1; in change_params()
2491 info->params.data_rate = tty_get_baud_rate(info->port.tty); in change_params()
2493 if (info->params.data_rate) { in change_params()
2494 info->timeout = (32*HZ*bits_per_char) / in change_params()
2495 info->params.data_rate; in change_params()
2497 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_params()
2499 tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); in change_params()
2500 tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); in change_params()
2504 info->read_status_mask = IRQ_RXOVER; in change_params()
2505 if (I_INPCK(info->port.tty)) in change_params()
2506 info->read_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2507 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) in change_params()
2508 info->read_status_mask |= MASK_BREAK; in change_params()
2509 if (I_IGNPAR(info->port.tty)) in change_params()
2510 info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2511 if (I_IGNBRK(info->port.tty)) { in change_params()
2512 info->ignore_status_mask |= MASK_BREAK; in change_params()
2516 if (I_IGNPAR(info->port.tty)) in change_params()
2517 info->ignore_status_mask |= MASK_OVERRUN; in change_params()
2520 program_hw(info); in change_params()
2523 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount) in get_stats() argument
2525 DBGINFO(("%s get_stats\n", info->device_name)); in get_stats()
2527 memset(&info->icount, 0, sizeof(info->icount)); in get_stats()
2529 if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount))) in get_stats()
2535 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params) in get_params() argument
2537 DBGINFO(("%s get_params\n", info->device_name)); in get_params()
2538 if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS))) in get_params()
2543 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params) in set_params() argument
2548 DBGINFO(("%s set_params\n", info->device_name)); in set_params()
2552 spin_lock_irqsave(&info->lock, flags); in set_params()
2554 info->base_clock = tmp_params.clock_speed; in set_params()
2556 memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS)); in set_params()
2557 spin_unlock_irqrestore(&info->lock, flags); in set_params()
2559 program_hw(info); in set_params()
2564 static int get_txidle(struct slgt_info *info, int __user *idle_mode) in get_txidle() argument
2566 DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode)); in get_txidle()
2567 if (put_user(info->idle_mode, idle_mode)) in get_txidle()
2572 static int set_txidle(struct slgt_info *info, int idle_mode) in set_txidle() argument
2575 DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode)); in set_txidle()
2576 spin_lock_irqsave(&info->lock,flags); in set_txidle()
2577 info->idle_mode = idle_mode; in set_txidle()
2578 if (info->params.mode != MGSL_MODE_ASYNC) in set_txidle()
2579 tx_set_idle(info); in set_txidle()
2580 spin_unlock_irqrestore(&info->lock,flags); in set_txidle()
2584 static int tx_enable(struct slgt_info *info, int enable) in tx_enable() argument
2587 DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable)); in tx_enable()
2588 spin_lock_irqsave(&info->lock,flags); in tx_enable()
2590 if (!info->tx_enabled) in tx_enable()
2591 tx_start(info); in tx_enable()
2593 if (info->tx_enabled) in tx_enable()
2594 tx_stop(info); in tx_enable()
2596 spin_unlock_irqrestore(&info->lock,flags); in tx_enable()
2603 static int tx_abort(struct slgt_info *info) in tx_abort() argument
2606 DBGINFO(("%s tx_abort\n", info->device_name)); in tx_abort()
2607 spin_lock_irqsave(&info->lock,flags); in tx_abort()
2608 tdma_reset(info); in tx_abort()
2609 spin_unlock_irqrestore(&info->lock,flags); in tx_abort()
2613 static int rx_enable(struct slgt_info *info, int enable) in rx_enable() argument
2617 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable)); in rx_enable()
2618 spin_lock_irqsave(&info->lock,flags); in rx_enable()
2627 spin_unlock_irqrestore(&info->lock, flags); in rx_enable()
2630 info->rbuf_fill_level = rbuf_fill_level; in rx_enable()
2632 info->rx_pio = 1; /* PIO mode */ in rx_enable()
2634 info->rx_pio = 0; /* DMA mode */ in rx_enable()
2635 rx_stop(info); /* restart receiver to use new fill level */ in rx_enable()
2646 if (!info->rx_enabled) in rx_enable()
2647 rx_start(info); in rx_enable()
2650 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3); in rx_enable()
2653 if (info->rx_enabled) in rx_enable()
2654 rx_stop(info); in rx_enable()
2656 spin_unlock_irqrestore(&info->lock,flags); in rx_enable()
2663 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr) in wait_mgsl_event() argument
2677 DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask)); in wait_mgsl_event()
2679 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2682 get_gtsignals(info); in wait_mgsl_event()
2683 s = info->signals; in wait_mgsl_event()
2691 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2696 cprev = info->icount; in wait_mgsl_event()
2697 oldsigs = info->input_signal_events; in wait_mgsl_event()
2701 unsigned short val = rd_reg16(info, SCR); in wait_mgsl_event()
2703 wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE)); in wait_mgsl_event()
2707 add_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2709 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2719 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2720 cnow = info->icount; in wait_mgsl_event()
2721 newsigs = info->input_signal_events; in wait_mgsl_event()
2723 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2758 remove_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2763 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2764 if (!waitqueue_active(&info->event_wait_q)) { in wait_mgsl_event()
2766 wr_reg16(info, SCR, in wait_mgsl_event()
2767 (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE)); in wait_mgsl_event()
2769 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2777 static int get_interface(struct slgt_info *info, int __user *if_mode) in get_interface() argument
2779 DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode)); in get_interface()
2780 if (put_user(info->if_mode, if_mode)) in get_interface()
2785 static int set_interface(struct slgt_info *info, int if_mode) in set_interface() argument
2790 DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode)); in set_interface()
2791 spin_lock_irqsave(&info->lock,flags); in set_interface()
2792 info->if_mode = if_mode; in set_interface()
2794 msc_set_vcr(info); in set_interface()
2797 val = rd_reg16(info, TCR); in set_interface()
2798 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in set_interface()
2802 wr_reg16(info, TCR, val); in set_interface()
2804 spin_unlock_irqrestore(&info->lock,flags); in set_interface()
2808 static int get_xsync(struct slgt_info *info, int __user *xsync) in get_xsync() argument
2810 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync)); in get_xsync()
2811 if (put_user(info->xsync, xsync)) in get_xsync()
2822 static int set_xsync(struct slgt_info *info, int xsync) in set_xsync() argument
2826 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync)); in set_xsync()
2827 spin_lock_irqsave(&info->lock, flags); in set_xsync()
2828 info->xsync = xsync; in set_xsync()
2829 wr_reg32(info, XSR, xsync); in set_xsync()
2830 spin_unlock_irqrestore(&info->lock, flags); in set_xsync()
2834 static int get_xctrl(struct slgt_info *info, int __user *xctrl) in get_xctrl() argument
2836 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl)); in get_xctrl()
2837 if (put_user(info->xctrl, xctrl)) in get_xctrl()
2859 static int set_xctrl(struct slgt_info *info, int xctrl) in set_xctrl() argument
2863 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl)); in set_xctrl()
2864 spin_lock_irqsave(&info->lock, flags); in set_xctrl()
2865 info->xctrl = xctrl; in set_xctrl()
2866 wr_reg32(info, XCR, xctrl); in set_xctrl()
2867 spin_unlock_irqrestore(&info->lock, flags); in set_xctrl()
2880 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in set_gpio() argument
2886 if (!info->gpio_present) in set_gpio()
2891 info->device_name, gpio.state, gpio.smask, in set_gpio()
2894 spin_lock_irqsave(&info->port_array[0]->lock, flags); in set_gpio()
2896 data = rd_reg32(info, IODR); in set_gpio()
2899 wr_reg32(info, IODR, data); in set_gpio()
2902 data = rd_reg32(info, IOVR); in set_gpio()
2905 wr_reg32(info, IOVR, data); in set_gpio()
2907 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in set_gpio()
2915 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in get_gpio() argument
2918 if (!info->gpio_present) in get_gpio()
2920 gpio.state = rd_reg32(info, IOVR); in get_gpio()
2922 gpio.dir = rd_reg32(info, IODR); in get_gpio()
2927 info->device_name, gpio.state, gpio.dir)); in get_gpio()
2989 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in wait_gpio() argument
2997 if (!info->gpio_present) in wait_gpio()
3002 info->device_name, gpio.state, gpio.smask)); in wait_gpio()
3004 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0) in wait_gpio()
3008 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3010 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); in wait_gpio()
3012 state = rd_reg32(info, IOVR); in wait_gpio()
3019 add_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3020 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3026 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3027 remove_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3031 if (info->gpio_wait_q == NULL) in wait_gpio()
3032 wr_reg32(info, IOER, 0); in wait_gpio()
3033 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3040 static int modem_input_wait(struct slgt_info *info,int arg) in modem_input_wait() argument
3048 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3049 cprev = info->icount; in modem_input_wait()
3050 add_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3052 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3062 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3063 cnow = info->icount; in modem_input_wait()
3065 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3085 remove_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3095 struct slgt_info *info = tty->driver_data; in tiocmget() local
3099 spin_lock_irqsave(&info->lock,flags); in tiocmget()
3100 get_gtsignals(info); in tiocmget()
3101 spin_unlock_irqrestore(&info->lock,flags); in tiocmget()
3103 result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) + in tiocmget()
3104 ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) + in tiocmget()
3105 ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) + in tiocmget()
3106 ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) + in tiocmget()
3107 ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) + in tiocmget()
3108 ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0); in tiocmget()
3110 DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result)); in tiocmget()
3124 struct slgt_info *info = tty->driver_data; in tiocmset() local
3127 DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear)); in tiocmset()
3130 info->signals |= SerialSignal_RTS; in tiocmset()
3132 info->signals |= SerialSignal_DTR; in tiocmset()
3134 info->signals &= ~SerialSignal_RTS; in tiocmset()
3136 info->signals &= ~SerialSignal_DTR; in tiocmset()
3138 spin_lock_irqsave(&info->lock,flags); in tiocmset()
3139 set_gtsignals(info); in tiocmset()
3140 spin_unlock_irqrestore(&info->lock,flags); in tiocmset()
3147 struct slgt_info *info = container_of(port, struct slgt_info, port); in carrier_raised() local
3149 spin_lock_irqsave(&info->lock,flags); in carrier_raised()
3150 get_gtsignals(info); in carrier_raised()
3151 spin_unlock_irqrestore(&info->lock,flags); in carrier_raised()
3152 return (info->signals & SerialSignal_DCD) ? 1 : 0; in carrier_raised()
3158 struct slgt_info *info = container_of(port, struct slgt_info, port); in dtr_rts() local
3160 spin_lock_irqsave(&info->lock,flags); in dtr_rts()
3162 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in dtr_rts()
3164 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in dtr_rts()
3165 set_gtsignals(info); in dtr_rts()
3166 spin_unlock_irqrestore(&info->lock,flags); in dtr_rts()
3174 struct slgt_info *info) in block_til_ready() argument
3181 struct tty_port *port = &info->port; in block_til_ready()
3204 spin_lock_irqsave(&info->lock, flags); in block_til_ready()
3206 spin_unlock_irqrestore(&info->lock, flags); in block_til_ready()
3256 static int alloc_tmp_rbuf(struct slgt_info *info) in alloc_tmp_rbuf() argument
3258 info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3259 if (info->tmp_rbuf == NULL) in alloc_tmp_rbuf()
3262 info->flag_buf = kzalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3263 if (!info->flag_buf) { in alloc_tmp_rbuf()
3264 kfree(info->tmp_rbuf); in alloc_tmp_rbuf()
3265 info->tmp_rbuf = NULL; in alloc_tmp_rbuf()
3271 static void free_tmp_rbuf(struct slgt_info *info) in free_tmp_rbuf() argument
3273 kfree(info->tmp_rbuf); in free_tmp_rbuf()
3274 info->tmp_rbuf = NULL; in free_tmp_rbuf()
3275 kfree(info->flag_buf); in free_tmp_rbuf()
3276 info->flag_buf = NULL; in free_tmp_rbuf()
3282 static int alloc_desc(struct slgt_info *info) in alloc_desc() argument
3288 info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE, in alloc_desc()
3289 &info->bufs_dma_addr, GFP_KERNEL); in alloc_desc()
3290 if (info->bufs == NULL) in alloc_desc()
3293 info->rbufs = (struct slgt_desc*)info->bufs; in alloc_desc()
3294 info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count; in alloc_desc()
3296 pbufs = (unsigned int)info->bufs_dma_addr; in alloc_desc()
3302 for (i=0; i < info->rbuf_count; i++) { in alloc_desc()
3304 info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc)); in alloc_desc()
3307 if (i == info->rbuf_count - 1) in alloc_desc()
3308 info->rbufs[i].next = cpu_to_le32(pbufs); in alloc_desc()
3310 info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc))); in alloc_desc()
3311 set_desc_count(info->rbufs[i], DMABUFSIZE); in alloc_desc()
3314 for (i=0; i < info->tbuf_count; i++) { in alloc_desc()
3316 info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc)); in alloc_desc()
3319 if (i == info->tbuf_count - 1) in alloc_desc()
3320 info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc)); in alloc_desc()
3322 …info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc))); in alloc_desc()
3328 static void free_desc(struct slgt_info *info) in free_desc() argument
3330 if (info->bufs != NULL) { in free_desc()
3331 dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE, in free_desc()
3332 info->bufs, info->bufs_dma_addr); in free_desc()
3333 info->bufs = NULL; in free_desc()
3334 info->rbufs = NULL; in free_desc()
3335 info->tbufs = NULL; in free_desc()
3339 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in alloc_bufs() argument
3343 bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE, in alloc_bufs()
3352 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in free_bufs() argument
3358 dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf, in free_bufs()
3364 static int alloc_dma_bufs(struct slgt_info *info) in alloc_dma_bufs() argument
3366 info->rbuf_count = 32; in alloc_dma_bufs()
3367 info->tbuf_count = 32; in alloc_dma_bufs()
3369 if (alloc_desc(info) < 0 || in alloc_dma_bufs()
3370 alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 || in alloc_dma_bufs()
3371 alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 || in alloc_dma_bufs()
3372 alloc_tmp_rbuf(info) < 0) { in alloc_dma_bufs()
3373 DBGERR(("%s DMA buffer alloc fail\n", info->device_name)); in alloc_dma_bufs()
3376 reset_rbufs(info); in alloc_dma_bufs()
3380 static void free_dma_bufs(struct slgt_info *info) in free_dma_bufs() argument
3382 if (info->bufs) { in free_dma_bufs()
3383 free_bufs(info, info->rbufs, info->rbuf_count); in free_dma_bufs()
3384 free_bufs(info, info->tbufs, info->tbuf_count); in free_dma_bufs()
3385 free_desc(info); in free_dma_bufs()
3387 free_tmp_rbuf(info); in free_dma_bufs()
3390 static int claim_resources(struct slgt_info *info) in claim_resources() argument
3392 if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) { in claim_resources()
3394 info->device_name, info->phys_reg_addr)); in claim_resources()
3395 info->init_error = DiagStatus_AddressConflict; in claim_resources()
3399 info->reg_addr_requested = true; in claim_resources()
3401 info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); in claim_resources()
3402 if (!info->reg_addr) { in claim_resources()
3404 info->device_name, info->phys_reg_addr)); in claim_resources()
3405 info->init_error = DiagStatus_CantAssignPciResources; in claim_resources()
3411 release_resources(info); in claim_resources()
3415 static void release_resources(struct slgt_info *info) in release_resources() argument
3417 if (info->irq_requested) { in release_resources()
3418 free_irq(info->irq_level, info); in release_resources()
3419 info->irq_requested = false; in release_resources()
3422 if (info->reg_addr_requested) { in release_resources()
3423 release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); in release_resources()
3424 info->reg_addr_requested = false; in release_resources()
3427 if (info->reg_addr) { in release_resources()
3428 iounmap(info->reg_addr); in release_resources()
3429 info->reg_addr = NULL; in release_resources()
3436 static void add_device(struct slgt_info *info) in add_device() argument
3440 info->next_device = NULL; in add_device()
3441 info->line = slgt_device_count; in add_device()
3442 sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line); in add_device()
3444 if (info->line < MAX_DEVICES) { in add_device()
3445 if (maxframe[info->line]) in add_device()
3446 info->max_frame_size = maxframe[info->line]; in add_device()
3452 slgt_device_list = info; in add_device()
3457 current_dev->next_device = info; in add_device()
3460 if (info->max_frame_size < 4096) in add_device()
3461 info->max_frame_size = 4096; in add_device()
3462 else if (info->max_frame_size > 65535) in add_device()
3463 info->max_frame_size = 65535; in add_device()
3465 switch(info->pdev->device) { in add_device()
3477 info->params.mode = MGSL_MODE_ASYNC; in add_device()
3483 devstr, info->device_name, info->phys_reg_addr, in add_device()
3484 info->irq_level, info->max_frame_size); in add_device()
3487 hdlcdev_init(info); in add_device()
3501 struct slgt_info *info; in alloc_dev() local
3503 info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL); in alloc_dev()
3505 if (!info) { in alloc_dev()
3509 tty_port_init(&info->port); in alloc_dev()
3510 info->port.ops = &slgt_port_ops; in alloc_dev()
3511 info->magic = MGSL_MAGIC; in alloc_dev()
3512 INIT_WORK(&info->task, bh_handler); in alloc_dev()
3513 info->max_frame_size = 4096; in alloc_dev()
3514 info->base_clock = 14745600; in alloc_dev()
3515 info->rbuf_fill_level = DMABUFSIZE; in alloc_dev()
3516 info->port.close_delay = 5*HZ/10; in alloc_dev()
3517 info->port.closing_wait = 30*HZ; in alloc_dev()
3518 init_waitqueue_head(&info->status_event_wait_q); in alloc_dev()
3519 init_waitqueue_head(&info->event_wait_q); in alloc_dev()
3520 spin_lock_init(&info->netlock); in alloc_dev()
3521 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); in alloc_dev()
3522 info->idle_mode = HDLC_TXIDLE_FLAGS; in alloc_dev()
3523 info->adapter_num = adapter_num; in alloc_dev()
3524 info->port_num = port_num; in alloc_dev()
3526 timer_setup(&info->tx_timer, tx_timeout, 0); in alloc_dev()
3527 timer_setup(&info->rx_timer, rx_timeout, 0); in alloc_dev()
3530 info->pdev = pdev; in alloc_dev()
3531 info->irq_level = pdev->irq; in alloc_dev()
3532 info->phys_reg_addr = pci_resource_start(pdev,0); in alloc_dev()
3534 info->bus_type = MGSL_BUS_TYPE_PCI; in alloc_dev()
3535 info->irq_flags = IRQF_SHARED; in alloc_dev()
3537 info->init_error = -1; /* assume error, set to 0 on successful init */ in alloc_dev()
3540 return info; in alloc_dev()
3605 struct slgt_info *info = port_array[i]; in device_init() local
3606 tty_port_register_device(&info->port, serial_driver, info->line, in device_init()
3607 &info->pdev->dev); in device_init()
3656 struct slgt_info *info; in slgt_cleanup() local
3662 for (info=slgt_device_list ; info != NULL ; info=info->next_device) in slgt_cleanup()
3663 tty_unregister_device(serial_driver, info->line); in slgt_cleanup()
3671 info = slgt_device_list; in slgt_cleanup()
3672 while(info) { in slgt_cleanup()
3673 reset_port(info); in slgt_cleanup()
3674 info = info->next_device; in slgt_cleanup()
3678 info = slgt_device_list; in slgt_cleanup()
3679 while(info) { in slgt_cleanup()
3681 hdlcdev_exit(info); in slgt_cleanup()
3683 free_dma_bufs(info); in slgt_cleanup()
3684 free_tmp_rbuf(info); in slgt_cleanup()
3685 if (info->port_num == 0) in slgt_cleanup()
3686 release_resources(info); in slgt_cleanup()
3687 tmp = info; in slgt_cleanup()
3688 info = info->next_device; in slgt_cleanup()
3767 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3769 reg_addr += (info->port_num) * 32; \
3771 reg_addr += (info->port_num) * 16;
3773 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) in rd_reg8() argument
3779 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value) in wr_reg8() argument
3785 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr) in rd_reg16() argument
3791 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value) in wr_reg16() argument
3797 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr) in rd_reg32() argument
3803 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value) in wr_reg32() argument
3809 static void rdma_reset(struct slgt_info *info) in rdma_reset() argument
3814 wr_reg32(info, RDCSR, BIT1); in rdma_reset()
3818 if (!(rd_reg32(info, RDCSR) & BIT0)) in rdma_reset()
3822 static void tdma_reset(struct slgt_info *info) in tdma_reset() argument
3827 wr_reg32(info, TDCSR, BIT1); in tdma_reset()
3831 if (!(rd_reg32(info, TDCSR) & BIT0)) in tdma_reset()
3840 static void enable_loopback(struct slgt_info *info) in enable_loopback() argument
3843 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); in enable_loopback()
3845 if (info->params.mode != MGSL_MODE_ASYNC) { in enable_loopback()
3854 wr_reg8(info, CCR, 0x49); in enable_loopback()
3857 if (info->params.clock_speed) in enable_loopback()
3858 set_rate(info, info->params.clock_speed); in enable_loopback()
3860 set_rate(info, 3686400); in enable_loopback()
3867 static void set_rate(struct slgt_info *info, u32 rate) in set_rate() argument
3870 unsigned int osc = info->base_clock; in set_rate()
3882 wr_reg16(info, BDR, (unsigned short)div); in set_rate()
3886 static void rx_stop(struct slgt_info *info) in rx_stop() argument
3891 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_stop()
3892 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_stop()
3893 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_stop()
3895 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE); in rx_stop()
3898 wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER); in rx_stop()
3900 rdma_reset(info); in rx_stop()
3902 info->rx_enabled = false; in rx_stop()
3903 info->rx_restart = false; in rx_stop()
3906 static void rx_start(struct slgt_info *info) in rx_start() argument
3910 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA); in rx_start()
3913 wr_reg16(info, SSR, IRQ_RXOVER); in rx_start()
3916 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_start()
3917 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_start()
3918 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_start()
3920 rdma_reset(info); in rx_start()
3921 reset_rbufs(info); in rx_start()
3923 if (info->rx_pio) { in rx_start()
3925 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); in rx_start()
3926 slgt_irq_on(info, IRQ_RXDATA); in rx_start()
3927 if (info->params.mode == MGSL_MODE_ASYNC) { in rx_start()
3929 wr_reg32(info, RDCSR, BIT6); in rx_start()
3933 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); in rx_start()
3935 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); in rx_start()
3937 if (info->params.mode != MGSL_MODE_ASYNC) { in rx_start()
3939 wr_reg32(info, RDCSR, (BIT2 + BIT0)); in rx_start()
3942 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); in rx_start()
3946 slgt_irq_on(info, IRQ_RXOVER); in rx_start()
3949 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); in rx_start()
3951 info->rx_restart = false; in rx_start()
3952 info->rx_enabled = true; in rx_start()
3955 static void tx_start(struct slgt_info *info) in tx_start() argument
3957 if (!info->tx_enabled) { in tx_start()
3958 wr_reg16(info, TCR, in tx_start()
3959 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); in tx_start()
3960 info->tx_enabled = true; in tx_start()
3963 if (desc_count(info->tbufs[info->tbuf_start])) { in tx_start()
3964 info->drop_rts_on_tx_done = false; in tx_start()
3966 if (info->params.mode != MGSL_MODE_ASYNC) { in tx_start()
3967 if (info->params.flags & HDLC_FLAG_AUTO_RTS) { in tx_start()
3968 get_gtsignals(info); in tx_start()
3969 if (!(info->signals & SerialSignal_RTS)) { in tx_start()
3970 info->signals |= SerialSignal_RTS; in tx_start()
3971 set_gtsignals(info); in tx_start()
3972 info->drop_rts_on_tx_done = true; in tx_start()
3976 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3977 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); in tx_start()
3979 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_start()
3981 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3982 slgt_irq_on(info, IRQ_TXIDLE); in tx_start()
3984 wr_reg16(info, SSR, IRQ_TXIDLE); in tx_start()
3987 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); in tx_start()
3988 wr_reg32(info, TDCSR, BIT2 + BIT0); in tx_start()
3989 info->tx_active = true; in tx_start()
3993 static void tx_stop(struct slgt_info *info) in tx_stop() argument
3997 del_timer(&info->tx_timer); in tx_stop()
3999 tdma_reset(info); in tx_stop()
4002 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ in tx_stop()
4003 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in tx_stop()
4005 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in tx_stop()
4008 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_stop()
4010 reset_tbufs(info); in tx_stop()
4012 info->tx_enabled = false; in tx_stop()
4013 info->tx_active = false; in tx_stop()
4016 static void reset_port(struct slgt_info *info) in reset_port() argument
4018 if (!info->reg_addr) in reset_port()
4021 tx_stop(info); in reset_port()
4022 rx_stop(info); in reset_port()
4024 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in reset_port()
4025 set_gtsignals(info); in reset_port()
4027 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in reset_port()
4030 static void reset_adapter(struct slgt_info *info) in reset_adapter() argument
4033 for (i=0; i < info->port_count; ++i) { in reset_adapter()
4034 if (info->port_array[i]) in reset_adapter()
4035 reset_port(info->port_array[i]); in reset_adapter()
4039 static void async_mode(struct slgt_info *info) in async_mode() argument
4043 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in async_mode()
4044 tx_stop(info); in async_mode()
4045 rx_stop(info); in async_mode()
4067 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in async_mode()
4070 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4072 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4076 switch (info->params.data_bits) in async_mode()
4083 if (info->params.stop_bits != 1) in async_mode()
4086 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in async_mode()
4089 wr_reg16(info, TCR, val); in async_mode()
4110 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4112 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4116 switch (info->params.data_bits) in async_mode()
4123 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in async_mode()
4126 wr_reg16(info, RCR, val); in async_mode()
4137 wr_reg8(info, CCR, 0x69); in async_mode()
4139 msc_set_vcr(info); in async_mode()
4162 if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate && in async_mode()
4163 ((info->base_clock < (info->params.data_rate * 16)) || in async_mode()
4164 (info->base_clock % (info->params.data_rate * 16)))) { in async_mode()
4167 set_rate(info, info->params.data_rate * 8); in async_mode()
4170 set_rate(info, info->params.data_rate * 16); in async_mode()
4172 wr_reg16(info, SCR, val); in async_mode()
4174 slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER); in async_mode()
4176 if (info->params.loopback) in async_mode()
4177 enable_loopback(info); in async_mode()
4180 static void sync_mode(struct slgt_info *info) in sync_mode() argument
4184 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in sync_mode()
4185 tx_stop(info); in sync_mode()
4186 rx_stop(info); in sync_mode()
4210 switch(info->params.mode) { in sync_mode()
4218 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in sync_mode()
4221 switch(info->params.encoding) in sync_mode()
4232 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4238 if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE) in sync_mode()
4241 switch (info->params.preamble_length) in sync_mode()
4248 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in sync_mode()
4251 wr_reg16(info, TCR, val); in sync_mode()
4255 switch (info->params.preamble) in sync_mode()
4264 wr_reg8(info, TPR, (unsigned char)val); in sync_mode()
4285 switch(info->params.mode) { in sync_mode()
4294 switch(info->params.encoding) in sync_mode()
4305 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4311 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in sync_mode()
4314 wr_reg16(info, RCR, val); in sync_mode()
4325 if (info->params.flags & HDLC_FLAG_TXC_BRG) in sync_mode()
4330 if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4335 else if (info->params.flags & HDLC_FLAG_TXC_DPLL) in sync_mode()
4337 else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN) in sync_mode()
4340 if (info->params.flags & HDLC_FLAG_RXC_BRG) in sync_mode()
4342 else if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4344 else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN) in sync_mode()
4347 if (info->params.clock_speed) in sync_mode()
4350 wr_reg8(info, CCR, (unsigned char)val); in sync_mode()
4352 if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL)) in sync_mode()
4355 switch(info->params.encoding) in sync_mode()
4365 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val)); in sync_mode()
4368 set_rate(info, info->params.clock_speed * 16); in sync_mode()
4371 set_rate(info, info->params.clock_speed); in sync_mode()
4373 tx_set_idle(info); in sync_mode()
4375 msc_set_vcr(info); in sync_mode()
4396 wr_reg16(info, SCR, BIT15 + BIT14 + BIT0); in sync_mode()
4398 if (info->params.loopback) in sync_mode()
4399 enable_loopback(info); in sync_mode()
4405 static void tx_set_idle(struct slgt_info *info) in tx_set_idle() argument
4413 tcr = rd_reg16(info, TCR); in tx_set_idle()
4414 if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) { in tx_set_idle()
4418 wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff)); in tx_set_idle()
4423 wr_reg16(info, TCR, tcr); in tx_set_idle()
4425 if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) { in tx_set_idle()
4427 val = (unsigned char)(info->idle_mode & 0xff); in tx_set_idle()
4430 switch(info->idle_mode) in tx_set_idle()
4441 wr_reg8(info, TIR, val); in tx_set_idle()
4447 static void get_gtsignals(struct slgt_info *info) in get_gtsignals() argument
4449 unsigned short status = rd_reg16(info, SSR); in get_gtsignals()
4452 info->signals &= SerialSignal_RTS | SerialSignal_DTR; in get_gtsignals()
4455 info->signals |= SerialSignal_DSR; in get_gtsignals()
4457 info->signals |= SerialSignal_CTS; in get_gtsignals()
4459 info->signals |= SerialSignal_DCD; in get_gtsignals()
4461 info->signals |= SerialSignal_RI; in get_gtsignals()
4467 static void msc_set_vcr(struct slgt_info *info) in msc_set_vcr() argument
4480 switch(info->if_mode & MGSL_INTERFACE_MASK) in msc_set_vcr()
4493 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST) in msc_set_vcr()
4495 if (info->signals & SerialSignal_DTR) in msc_set_vcr()
4497 if (info->signals & SerialSignal_RTS) in msc_set_vcr()
4499 if (info->if_mode & MGSL_INTERFACE_LL) in msc_set_vcr()
4501 if (info->if_mode & MGSL_INTERFACE_RL) in msc_set_vcr()
4503 wr_reg8(info, VCR, val); in msc_set_vcr()
4509 static void set_gtsignals(struct slgt_info *info) in set_gtsignals() argument
4511 unsigned char val = rd_reg8(info, VCR); in set_gtsignals()
4512 if (info->signals & SerialSignal_DTR) in set_gtsignals()
4516 if (info->signals & SerialSignal_RTS) in set_gtsignals()
4520 wr_reg8(info, VCR, val); in set_gtsignals()
4526 static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last) in free_rbufs() argument
4532 info->rbufs[i].status = 0; in free_rbufs()
4533 set_desc_count(info->rbufs[i], info->rbuf_fill_level); in free_rbufs()
4536 if (++i == info->rbuf_count) in free_rbufs()
4539 info->rbuf_current = i; in free_rbufs()
4545 static void reset_rbufs(struct slgt_info *info) in reset_rbufs() argument
4547 free_rbufs(info, 0, info->rbuf_count - 1); in reset_rbufs()
4548 info->rbuf_fill_index = 0; in reset_rbufs()
4549 info->rbuf_fill_count = 0; in reset_rbufs()
4557 static bool rx_get_frame(struct slgt_info *info) in rx_get_frame() argument
4563 struct tty_struct *tty = info->port.tty; in rx_get_frame()
4567 switch (info->params.crc_type & HDLC_CRC_MASK) { in rx_get_frame()
4576 start = end = info->rbuf_current; in rx_get_frame()
4579 if (!desc_complete(info->rbufs[end])) in rx_get_frame()
4582 if (framesize == 0 && info->params.addr_filter != 0xff) in rx_get_frame()
4583 addr_field = info->rbufs[end].buf[0]; in rx_get_frame()
4585 framesize += desc_count(info->rbufs[end]); in rx_get_frame()
4587 if (desc_eof(info->rbufs[end])) in rx_get_frame()
4590 if (++end == info->rbuf_count) in rx_get_frame()
4593 if (end == info->rbuf_current) { in rx_get_frame()
4594 if (info->rx_enabled){ in rx_get_frame()
4595 spin_lock_irqsave(&info->lock,flags); in rx_get_frame()
4596 rx_start(info); in rx_get_frame()
4597 spin_unlock_irqrestore(&info->lock,flags); in rx_get_frame()
4612 status = desc_status(info->rbufs[end]); in rx_get_frame()
4615 if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE) in rx_get_frame()
4619 (addr_field != 0xff && addr_field != info->params.addr_filter)) { in rx_get_frame()
4620 free_rbufs(info, start, end); in rx_get_frame()
4625 info->icount.rxshort++; in rx_get_frame()
4628 info->icount.rxcrc++; in rx_get_frame()
4629 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) in rx_get_frame()
4635 info->netdev->stats.rx_errors++; in rx_get_frame()
4636 info->netdev->stats.rx_frame_errors++; in rx_get_frame()
4641 info->device_name, status, framesize)); in rx_get_frame()
4642 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx"); in rx_get_frame()
4645 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { in rx_get_frame()
4650 if (framesize > info->max_frame_size + crc_size) in rx_get_frame()
4651 info->icount.rxlong++; in rx_get_frame()
4656 unsigned char *p = info->tmp_rbuf; in rx_get_frame()
4657 info->tmp_rbuf_count = framesize; in rx_get_frame()
4659 info->icount.rxok++; in rx_get_frame()
4662 int partial_count = min_t(int, copy_count, info->rbuf_fill_level); in rx_get_frame()
4663 memcpy(p, info->rbufs[i].buf, partial_count); in rx_get_frame()
4666 if (++i == info->rbuf_count) in rx_get_frame()
4670 if (info->params.crc_type & HDLC_CRC_RETURN_EX) { in rx_get_frame()
4676 if (info->netcount) in rx_get_frame()
4677 hdlcdev_rx(info,info->tmp_rbuf, framesize); in rx_get_frame()
4680 ldisc_receive_buf(tty, info->tmp_rbuf, info->flag_buf, framesize); in rx_get_frame()
4683 free_rbufs(info, start, end); in rx_get_frame()
4694 static bool rx_get_buf(struct slgt_info *info) in rx_get_buf() argument
4696 unsigned int i = info->rbuf_current; in rx_get_buf()
4699 if (!desc_complete(info->rbufs[i])) in rx_get_buf()
4701 count = desc_count(info->rbufs[i]); in rx_get_buf()
4702 switch(info->params.mode) { in rx_get_buf()
4707 if (desc_residue(info->rbufs[i])) in rx_get_buf()
4711 DBGDATA(info, info->rbufs[i].buf, count, "rx"); in rx_get_buf()
4714 ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, in rx_get_buf()
4715 info->flag_buf, count); in rx_get_buf()
4716 free_rbufs(info, i, i); in rx_get_buf()
4720 static void reset_tbufs(struct slgt_info *info) in reset_tbufs() argument
4723 info->tbuf_current = 0; in reset_tbufs()
4724 for (i=0 ; i < info->tbuf_count ; i++) { in reset_tbufs()
4725 info->tbufs[i].status = 0; in reset_tbufs()
4726 info->tbufs[i].count = 0; in reset_tbufs()
4733 static unsigned int free_tbuf_count(struct slgt_info *info) in free_tbuf_count() argument
4736 unsigned int i = info->tbuf_current; in free_tbuf_count()
4740 if (desc_count(info->tbufs[i])) in free_tbuf_count()
4743 if (++i == info->tbuf_count) in free_tbuf_count()
4745 } while (i != info->tbuf_current); in free_tbuf_count()
4748 if (count && (rd_reg32(info, TDCSR) & BIT0)) in free_tbuf_count()
4758 static unsigned int tbuf_bytes(struct slgt_info *info) in tbuf_bytes() argument
4761 unsigned int i = info->tbuf_current; in tbuf_bytes()
4778 count = desc_count(info->tbufs[i]); in tbuf_bytes()
4782 active_buf_count = info->tbufs[i].buf_count; in tbuf_bytes()
4783 if (++i == info->tbuf_count) in tbuf_bytes()
4785 } while (i != info->tbuf_current); in tbuf_bytes()
4788 reg_value = rd_reg32(info, TDCSR); in tbuf_bytes()
4798 if (info->tx_active) in tbuf_bytes()
4808 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) in tx_load() argument
4815 if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) in tx_load()
4818 DBGDATA(info, buf, size, "tx"); in tx_load()
4831 info->tbuf_start = i = info->tbuf_current; in tx_load()
4834 d = &info->tbufs[i]; in tx_load()
4846 if ((!size && info->params.mode == MGSL_MODE_HDLC) || in tx_load()
4847 info->params.mode == MGSL_MODE_RAW) in tx_load()
4853 if (i != info->tbuf_start) in tx_load()
4857 if (++i == info->tbuf_count) in tx_load()
4861 info->tbuf_current = i; in tx_load()
4864 d = &info->tbufs[info->tbuf_start]; in tx_load()
4868 if (!info->tx_active) in tx_load()
4869 tx_start(info); in tx_load()
4870 update_tx_timer(info); in tx_load()
4875 static int register_test(struct slgt_info *info) in register_test() argument
4884 wr_reg16(info, TIR, patterns[i]); in register_test()
4885 wr_reg16(info, BDR, patterns[(i+1)%count]); in register_test()
4886 if ((rd_reg16(info, TIR) != patterns[i]) || in register_test()
4887 (rd_reg16(info, BDR) != patterns[(i+1)%count])) { in register_test()
4892 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0; in register_test()
4893 info->init_error = rc ? 0 : DiagStatus_AddressFailure; in register_test()
4897 static int irq_test(struct slgt_info *info) in irq_test() argument
4901 struct tty_struct *oldtty = info->port.tty; in irq_test()
4902 u32 speed = info->params.data_rate; in irq_test()
4904 info->params.data_rate = 921600; in irq_test()
4905 info->port.tty = NULL; in irq_test()
4907 spin_lock_irqsave(&info->lock, flags); in irq_test()
4908 async_mode(info); in irq_test()
4909 slgt_irq_on(info, IRQ_TXIDLE); in irq_test()
4912 wr_reg16(info, TCR, in irq_test()
4913 (unsigned short)(rd_reg16(info, TCR) | BIT1)); in irq_test()
4916 wr_reg16(info, TDR, 0); in irq_test()
4919 info->init_error = DiagStatus_IrqFailure; in irq_test()
4920 info->irq_occurred = false; in irq_test()
4922 spin_unlock_irqrestore(&info->lock, flags); in irq_test()
4925 while(timeout-- && !info->irq_occurred) in irq_test()
4928 spin_lock_irqsave(&info->lock,flags); in irq_test()
4929 reset_port(info); in irq_test()
4930 spin_unlock_irqrestore(&info->lock,flags); in irq_test()
4932 info->params.data_rate = speed; in irq_test()
4933 info->port.tty = oldtty; in irq_test()
4935 info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure; in irq_test()
4936 return info->irq_occurred ? 0 : -ENODEV; in irq_test()
4939 static int loopback_test_rx(struct slgt_info *info) in loopback_test_rx() argument
4944 if (desc_complete(info->rbufs[0])) { in loopback_test_rx()
4945 count = desc_count(info->rbufs[0]); in loopback_test_rx()
4946 src = info->rbufs[0].buf; in loopback_test_rx()
4947 dest = info->tmp_rbuf; in loopback_test_rx()
4954 info->tmp_rbuf_count++; in loopback_test_rx()
4957 DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx"); in loopback_test_rx()
4963 static int loopback_test(struct slgt_info *info) in loopback_test() argument
4973 struct tty_struct *oldtty = info->port.tty; in loopback_test()
4976 memcpy(¶ms, &info->params, sizeof(params)); in loopback_test()
4978 info->params.mode = MGSL_MODE_ASYNC; in loopback_test()
4979 info->params.data_rate = 921600; in loopback_test()
4980 info->params.loopback = 1; in loopback_test()
4981 info->port.tty = NULL; in loopback_test()
4987 info->tmp_rbuf_count = 0; in loopback_test()
4988 memset(info->tmp_rbuf, 0, TESTFRAMESIZE); in loopback_test()
4991 spin_lock_irqsave(&info->lock,flags); in loopback_test()
4992 async_mode(info); in loopback_test()
4993 rx_start(info); in loopback_test()
4994 tx_load(info, buf, count); in loopback_test()
4995 spin_unlock_irqrestore(&info->lock, flags); in loopback_test()
5000 if (loopback_test_rx(info)) { in loopback_test()
5007 if (!rc && (info->tmp_rbuf_count != count || in loopback_test()
5008 memcmp(buf, info->tmp_rbuf, count))) { in loopback_test()
5012 spin_lock_irqsave(&info->lock,flags); in loopback_test()
5013 reset_adapter(info); in loopback_test()
5014 spin_unlock_irqrestore(&info->lock,flags); in loopback_test()
5016 memcpy(&info->params, ¶ms, sizeof(info->params)); in loopback_test()
5017 info->port.tty = oldtty; in loopback_test()
5019 info->init_error = rc ? DiagStatus_DmaFailure : 0; in loopback_test()
5023 static int adapter_test(struct slgt_info *info) in adapter_test() argument
5025 DBGINFO(("testing %s\n", info->device_name)); in adapter_test()
5026 if (register_test(info) < 0) { in adapter_test()
5028 info->device_name, info->phys_reg_addr); in adapter_test()
5029 } else if (irq_test(info) < 0) { in adapter_test()
5031 info->device_name, info->irq_level); in adapter_test()
5032 } else if (loopback_test(info) < 0) { in adapter_test()
5033 printk("loopback test failure %s\n", info->device_name); in adapter_test()
5035 return info->init_error; in adapter_test()
5043 struct slgt_info *info = from_timer(info, t, tx_timer); in tx_timeout() local
5046 DBGINFO(("%s tx_timeout\n", info->device_name)); in tx_timeout()
5047 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) { in tx_timeout()
5048 info->icount.txtimeout++; in tx_timeout()
5050 spin_lock_irqsave(&info->lock,flags); in tx_timeout()
5051 tx_stop(info); in tx_timeout()
5052 spin_unlock_irqrestore(&info->lock,flags); in tx_timeout()
5055 if (info->netcount) in tx_timeout()
5056 hdlcdev_tx_done(info); in tx_timeout()
5059 bh_transmit(info); in tx_timeout()
5067 struct slgt_info *info = from_timer(info, t, rx_timer); in rx_timeout() local
5070 DBGINFO(("%s rx_timeout\n", info->device_name)); in rx_timeout()
5071 spin_lock_irqsave(&info->lock, flags); in rx_timeout()
5072 info->pending_bh |= BH_RECEIVE; in rx_timeout()
5073 spin_unlock_irqrestore(&info->lock, flags); in rx_timeout()
5074 bh_handler(&info->task); in rx_timeout()