Lines Matching refs:info
41 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (b… argument
397 #define slgt_irq_on(info, mask) \ argument
398 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
399 #define slgt_irq_off(info, mask) \ argument
400 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
402 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
403 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
404 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
405 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
406 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
407 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
409 static void msc_set_vcr(struct slgt_info *info);
411 static int startup(struct slgt_info *info);
412 static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
413 static void shutdown(struct slgt_info *info);
414 static void program_hw(struct slgt_info *info);
415 static void change_params(struct slgt_info *info);
417 static int adapter_test(struct slgt_info *info);
419 static void reset_port(struct slgt_info *info);
420 static void async_mode(struct slgt_info *info);
421 static void sync_mode(struct slgt_info *info);
423 static void rx_stop(struct slgt_info *info);
424 static void rx_start(struct slgt_info *info);
425 static void reset_rbufs(struct slgt_info *info);
426 static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
427 static bool rx_get_frame(struct slgt_info *info);
428 static bool rx_get_buf(struct slgt_info *info);
430 static void tx_start(struct slgt_info *info);
431 static void tx_stop(struct slgt_info *info);
432 static void tx_set_idle(struct slgt_info *info);
433 static unsigned int tbuf_bytes(struct slgt_info *info);
434 static void reset_tbufs(struct slgt_info *info);
435 static void tdma_reset(struct slgt_info *info);
436 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
438 static void get_gtsignals(struct slgt_info *info);
439 static void set_gtsignals(struct slgt_info *info);
440 static void set_rate(struct slgt_info *info, u32 data_rate);
442 static void bh_transmit(struct slgt_info *info);
443 static void isr_txeom(struct slgt_info *info, unsigned short status);
451 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
452 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
453 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
454 static int get_txidle(struct slgt_info *info, int __user *idle_mode);
455 static int set_txidle(struct slgt_info *info, int idle_mode);
456 static int tx_enable(struct slgt_info *info, int enable);
457 static int tx_abort(struct slgt_info *info);
458 static int rx_enable(struct slgt_info *info, int enable);
459 static int modem_input_wait(struct slgt_info *info,int arg);
460 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
461 static int get_interface(struct slgt_info *info, int __user *if_mode);
462 static int set_interface(struct slgt_info *info, int if_mode);
463 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
464 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
465 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
466 static int get_xsync(struct slgt_info *info, int __user *if_mode);
467 static int set_xsync(struct slgt_info *info, int if_mode);
468 static int get_xctrl(struct slgt_info *info, int __user *if_mode);
469 static int set_xctrl(struct slgt_info *info, int if_mode);
474 static void release_resources(struct slgt_info *info);
493 static void trace_block(struct slgt_info *info, const char *data, int count, const char *label) in trace_block() argument
497 printk("%s %s data:\n",info->device_name, label); in trace_block()
516 #define DBGDATA(info, buf, size, label) argument
520 static void dump_tbufs(struct slgt_info *info) in dump_tbufs() argument
523 printk("tbuf_current=%d\n", info->tbuf_current); in dump_tbufs()
524 for (i=0 ; i < info->tbuf_count ; i++) { in dump_tbufs()
526 i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status)); in dump_tbufs()
530 #define DBGTBUF(info) argument
534 static void dump_rbufs(struct slgt_info *info) in dump_rbufs() argument
537 printk("rbuf_current=%d\n", info->rbuf_current); in dump_rbufs()
538 for (i=0 ; i < info->rbuf_count ; i++) { in dump_rbufs()
540 i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status)); in dump_rbufs()
544 #define DBGRBUF(info) argument
547 static inline int sanity_check(struct slgt_info *info, char *devname, const char *name) in sanity_check() argument
550 if (!info) { in sanity_check()
555 if (!info) in sanity_check()
587 struct slgt_info *info; in open() local
597 info = slgt_device_list; in open()
598 while(info && info->line != line) in open()
599 info = info->next_device; in open()
600 if (sanity_check(info, tty->name, "open")) in open()
602 if (info->init_error) { in open()
603 DBGERR(("%s init error=%d\n", info->device_name, info->init_error)); in open()
607 tty->driver_data = info; in open()
608 info->port.tty = tty; in open()
610 DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count)); in open()
612 mutex_lock(&info->port.mutex); in open()
614 spin_lock_irqsave(&info->netlock, flags); in open()
615 if (info->netcount) { in open()
617 spin_unlock_irqrestore(&info->netlock, flags); in open()
618 mutex_unlock(&info->port.mutex); in open()
621 info->port.count++; in open()
622 spin_unlock_irqrestore(&info->netlock, flags); in open()
624 if (info->port.count == 1) { in open()
626 retval = startup(info); in open()
628 mutex_unlock(&info->port.mutex); in open()
632 mutex_unlock(&info->port.mutex); in open()
633 retval = block_til_ready(tty, filp, info); in open()
635 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); in open()
644 info->port.tty = NULL; /* tty layer will release tty struct */ in open()
645 if(info->port.count) in open()
646 info->port.count--; in open()
649 DBGINFO(("%s open rc=%d\n", info->device_name, retval)); in open()
655 struct slgt_info *info = tty->driver_data; in close() local
657 if (sanity_check(info, tty->name, "close")) in close()
659 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); in close()
661 if (tty_port_close_start(&info->port, tty, filp) == 0) in close()
664 mutex_lock(&info->port.mutex); in close()
665 if (tty_port_initialized(&info->port)) in close()
666 wait_until_sent(tty, info->timeout); in close()
670 shutdown(info); in close()
671 mutex_unlock(&info->port.mutex); in close()
673 tty_port_close_end(&info->port, tty); in close()
674 info->port.tty = NULL; in close()
676 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); in close()
681 struct slgt_info *info = tty->driver_data; in hangup() local
684 if (sanity_check(info, tty->name, "hangup")) in hangup()
686 DBGINFO(("%s hangup\n", info->device_name)); in hangup()
690 mutex_lock(&info->port.mutex); in hangup()
691 shutdown(info); in hangup()
693 spin_lock_irqsave(&info->port.lock, flags); in hangup()
694 info->port.count = 0; in hangup()
695 info->port.tty = NULL; in hangup()
696 spin_unlock_irqrestore(&info->port.lock, flags); in hangup()
697 tty_port_set_active(&info->port, 0); in hangup()
698 mutex_unlock(&info->port.mutex); in hangup()
700 wake_up_interruptible(&info->port.open_wait); in hangup()
706 struct slgt_info *info = tty->driver_data; in set_termios() local
711 change_params(info); in set_termios()
715 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in set_termios()
716 spin_lock_irqsave(&info->lock,flags); in set_termios()
717 set_gtsignals(info); in set_termios()
718 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
723 info->signals |= SerialSignal_DTR; in set_termios()
725 info->signals |= SerialSignal_RTS; in set_termios()
726 spin_lock_irqsave(&info->lock,flags); in set_termios()
727 set_gtsignals(info); in set_termios()
728 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
738 static void update_tx_timer(struct slgt_info *info) in update_tx_timer() argument
744 if (info->params.mode == MGSL_MODE_HDLC) { in update_tx_timer()
745 int timeout = (tbuf_bytes(info) * 7) + 1000; in update_tx_timer()
746 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout)); in update_tx_timer()
754 struct slgt_info *info = tty->driver_data; in write() local
757 if (sanity_check(info, tty->name, "write")) in write()
760 DBGINFO(("%s write count=%d\n", info->device_name, count)); in write()
762 if (!info->tx_buf || (count > info->max_frame_size)) in write()
768 spin_lock_irqsave(&info->lock, flags); in write()
770 if (info->tx_count) { in write()
772 if (!tx_load(info, info->tx_buf, info->tx_count)) in write()
774 info->tx_count = 0; in write()
777 if (tx_load(info, buf, count)) in write()
781 spin_unlock_irqrestore(&info->lock, flags); in write()
782 DBGINFO(("%s write rc=%d\n", info->device_name, ret)); in write()
788 struct slgt_info *info = tty->driver_data; in put_char() local
792 if (sanity_check(info, tty->name, "put_char")) in put_char()
794 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); in put_char()
795 if (!info->tx_buf) in put_char()
797 spin_lock_irqsave(&info->lock,flags); in put_char()
798 if (info->tx_count < info->max_frame_size) { in put_char()
799 info->tx_buf[info->tx_count++] = ch; in put_char()
802 spin_unlock_irqrestore(&info->lock,flags); in put_char()
808 struct slgt_info *info = tty->driver_data; in send_xchar() local
811 if (sanity_check(info, tty->name, "send_xchar")) in send_xchar()
813 DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch)); in send_xchar()
814 info->x_char = ch; in send_xchar()
816 spin_lock_irqsave(&info->lock,flags); in send_xchar()
817 if (!info->tx_enabled) in send_xchar()
818 tx_start(info); in send_xchar()
819 spin_unlock_irqrestore(&info->lock,flags); in send_xchar()
825 struct slgt_info *info = tty->driver_data; in wait_until_sent() local
828 if (!info ) in wait_until_sent()
830 if (sanity_check(info, tty->name, "wait_until_sent")) in wait_until_sent()
832 DBGINFO(("%s wait_until_sent entry\n", info->device_name)); in wait_until_sent()
833 if (!tty_port_initialized(&info->port)) in wait_until_sent()
844 if (info->params.data_rate) { in wait_until_sent()
845 char_time = info->timeout/(32 * 5); in wait_until_sent()
854 while (info->tx_active) { in wait_until_sent()
862 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); in wait_until_sent()
867 struct slgt_info *info = tty->driver_data; in write_room() local
870 if (sanity_check(info, tty->name, "write_room")) in write_room()
872 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; in write_room()
873 DBGINFO(("%s write_room=%u\n", info->device_name, ret)); in write_room()
879 struct slgt_info *info = tty->driver_data; in flush_chars() local
882 if (sanity_check(info, tty->name, "flush_chars")) in flush_chars()
884 DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count)); in flush_chars()
886 if (info->tx_count <= 0 || tty->flow.stopped || in flush_chars()
887 tty->hw_stopped || !info->tx_buf) in flush_chars()
890 DBGINFO(("%s flush_chars start transmit\n", info->device_name)); in flush_chars()
892 spin_lock_irqsave(&info->lock,flags); in flush_chars()
893 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in flush_chars()
894 info->tx_count = 0; in flush_chars()
895 spin_unlock_irqrestore(&info->lock,flags); in flush_chars()
900 struct slgt_info *info = tty->driver_data; in flush_buffer() local
903 if (sanity_check(info, tty->name, "flush_buffer")) in flush_buffer()
905 DBGINFO(("%s flush_buffer\n", info->device_name)); in flush_buffer()
907 spin_lock_irqsave(&info->lock, flags); in flush_buffer()
908 info->tx_count = 0; in flush_buffer()
909 spin_unlock_irqrestore(&info->lock, flags); in flush_buffer()
919 struct slgt_info *info = tty->driver_data; in tx_hold() local
922 if (sanity_check(info, tty->name, "tx_hold")) in tx_hold()
924 DBGINFO(("%s tx_hold\n", info->device_name)); in tx_hold()
925 spin_lock_irqsave(&info->lock,flags); in tx_hold()
926 if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC) in tx_hold()
927 tx_stop(info); in tx_hold()
928 spin_unlock_irqrestore(&info->lock,flags); in tx_hold()
936 struct slgt_info *info = tty->driver_data; in tx_release() local
939 if (sanity_check(info, tty->name, "tx_release")) in tx_release()
941 DBGINFO(("%s tx_release\n", info->device_name)); in tx_release()
942 spin_lock_irqsave(&info->lock, flags); in tx_release()
943 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in tx_release()
944 info->tx_count = 0; in tx_release()
945 spin_unlock_irqrestore(&info->lock, flags); in tx_release()
962 struct slgt_info *info = tty->driver_data; in ioctl() local
966 if (sanity_check(info, tty->name, "ioctl")) in ioctl()
968 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); in ioctl()
977 return wait_mgsl_event(info, argp); in ioctl()
979 return modem_input_wait(info,(int)arg); in ioctl()
981 return set_gpio(info, argp); in ioctl()
983 return get_gpio(info, argp); in ioctl()
985 return wait_gpio(info, argp); in ioctl()
987 return get_xsync(info, argp); in ioctl()
989 return set_xsync(info, (int)arg); in ioctl()
991 return get_xctrl(info, argp); in ioctl()
993 return set_xctrl(info, (int)arg); in ioctl()
995 mutex_lock(&info->port.mutex); in ioctl()
998 ret = get_params(info, argp); in ioctl()
1001 ret = set_params(info, argp); in ioctl()
1004 ret = get_txidle(info, argp); in ioctl()
1007 ret = set_txidle(info, (int)arg); in ioctl()
1010 ret = tx_enable(info, (int)arg); in ioctl()
1013 ret = rx_enable(info, (int)arg); in ioctl()
1016 ret = tx_abort(info); in ioctl()
1019 ret = get_stats(info, argp); in ioctl()
1022 ret = get_interface(info, argp); in ioctl()
1025 ret = set_interface(info,(int)arg); in ioctl()
1030 mutex_unlock(&info->port.mutex); in ioctl()
1038 struct slgt_info *info = tty->driver_data; in get_icount() local
1042 spin_lock_irqsave(&info->lock,flags); in get_icount()
1043 cnow = info->icount; in get_icount()
1044 spin_unlock_irqrestore(&info->lock,flags); in get_icount()
1065 static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params) in get_params32() argument
1069 DBGINFO(("%s get_params32\n", info->device_name)); in get_params32()
1071 tmp_params.mode = (compat_ulong_t)info->params.mode; in get_params32()
1072 tmp_params.loopback = info->params.loopback; in get_params32()
1073 tmp_params.flags = info->params.flags; in get_params32()
1074 tmp_params.encoding = info->params.encoding; in get_params32()
1075 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed; in get_params32()
1076 tmp_params.addr_filter = info->params.addr_filter; in get_params32()
1077 tmp_params.crc_type = info->params.crc_type; in get_params32()
1078 tmp_params.preamble_length = info->params.preamble_length; in get_params32()
1079 tmp_params.preamble = info->params.preamble; in get_params32()
1080 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate; in get_params32()
1081 tmp_params.data_bits = info->params.data_bits; in get_params32()
1082 tmp_params.stop_bits = info->params.stop_bits; in get_params32()
1083 tmp_params.parity = info->params.parity; in get_params32()
1089 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params) in set_params32() argument
1093 DBGINFO(("%s set_params32\n", info->device_name)); in set_params32()
1097 spin_lock(&info->lock); in set_params32()
1099 info->base_clock = tmp_params.clock_speed; in set_params32()
1101 info->params.mode = tmp_params.mode; in set_params32()
1102 info->params.loopback = tmp_params.loopback; in set_params32()
1103 info->params.flags = tmp_params.flags; in set_params32()
1104 info->params.encoding = tmp_params.encoding; in set_params32()
1105 info->params.clock_speed = tmp_params.clock_speed; in set_params32()
1106 info->params.addr_filter = tmp_params.addr_filter; in set_params32()
1107 info->params.crc_type = tmp_params.crc_type; in set_params32()
1108 info->params.preamble_length = tmp_params.preamble_length; in set_params32()
1109 info->params.preamble = tmp_params.preamble; in set_params32()
1110 info->params.data_rate = tmp_params.data_rate; in set_params32()
1111 info->params.data_bits = tmp_params.data_bits; in set_params32()
1112 info->params.stop_bits = tmp_params.stop_bits; in set_params32()
1113 info->params.parity = tmp_params.parity; in set_params32()
1115 spin_unlock(&info->lock); in set_params32()
1117 program_hw(info); in set_params32()
1125 struct slgt_info *info = tty->driver_data; in slgt_compat_ioctl() local
1128 if (sanity_check(info, tty->name, "compat_ioctl")) in slgt_compat_ioctl()
1130 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd)); in slgt_compat_ioctl()
1134 rc = set_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1138 rc = get_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1157 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc)); in slgt_compat_ioctl()
1167 static inline void line_info(struct seq_file *m, struct slgt_info *info) in line_info() argument
1173 info->device_name, info->phys_reg_addr, in line_info()
1174 info->irq_level, info->max_frame_size); in line_info()
1177 spin_lock_irqsave(&info->lock,flags); in line_info()
1178 get_gtsignals(info); in line_info()
1179 spin_unlock_irqrestore(&info->lock,flags); in line_info()
1183 if (info->signals & SerialSignal_RTS) in line_info()
1185 if (info->signals & SerialSignal_CTS) in line_info()
1187 if (info->signals & SerialSignal_DTR) in line_info()
1189 if (info->signals & SerialSignal_DSR) in line_info()
1191 if (info->signals & SerialSignal_DCD) in line_info()
1193 if (info->signals & SerialSignal_RI) in line_info()
1196 if (info->params.mode != MGSL_MODE_ASYNC) { in line_info()
1198 info->icount.txok, info->icount.rxok); in line_info()
1199 if (info->icount.txunder) in line_info()
1200 seq_printf(m, " txunder:%d", info->icount.txunder); in line_info()
1201 if (info->icount.txabort) in line_info()
1202 seq_printf(m, " txabort:%d", info->icount.txabort); in line_info()
1203 if (info->icount.rxshort) in line_info()
1204 seq_printf(m, " rxshort:%d", info->icount.rxshort); in line_info()
1205 if (info->icount.rxlong) in line_info()
1206 seq_printf(m, " rxlong:%d", info->icount.rxlong); in line_info()
1207 if (info->icount.rxover) in line_info()
1208 seq_printf(m, " rxover:%d", info->icount.rxover); in line_info()
1209 if (info->icount.rxcrc) in line_info()
1210 seq_printf(m, " rxcrc:%d", info->icount.rxcrc); in line_info()
1213 info->icount.tx, info->icount.rx); in line_info()
1214 if (info->icount.frame) in line_info()
1215 seq_printf(m, " fe:%d", info->icount.frame); in line_info()
1216 if (info->icount.parity) in line_info()
1217 seq_printf(m, " pe:%d", info->icount.parity); in line_info()
1218 if (info->icount.brk) in line_info()
1219 seq_printf(m, " brk:%d", info->icount.brk); in line_info()
1220 if (info->icount.overrun) in line_info()
1221 seq_printf(m, " oe:%d", info->icount.overrun); in line_info()
1228 info->tx_active,info->bh_requested,info->bh_running, in line_info()
1229 info->pending_bh); in line_info()
1236 struct slgt_info *info; in synclink_gt_proc_show() local
1240 info = slgt_device_list; in synclink_gt_proc_show()
1241 while( info ) { in synclink_gt_proc_show()
1242 line_info(m, info); in synclink_gt_proc_show()
1243 info = info->next_device; in synclink_gt_proc_show()
1253 struct slgt_info *info = tty->driver_data; in chars_in_buffer() local
1255 if (sanity_check(info, tty->name, "chars_in_buffer")) in chars_in_buffer()
1257 count = tbuf_bytes(info); in chars_in_buffer()
1258 DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count)); in chars_in_buffer()
1267 struct slgt_info *info = tty->driver_data; in throttle() local
1270 if (sanity_check(info, tty->name, "throttle")) in throttle()
1272 DBGINFO(("%s throttle\n", info->device_name)); in throttle()
1276 spin_lock_irqsave(&info->lock,flags); in throttle()
1277 info->signals &= ~SerialSignal_RTS; in throttle()
1278 set_gtsignals(info); in throttle()
1279 spin_unlock_irqrestore(&info->lock,flags); in throttle()
1288 struct slgt_info *info = tty->driver_data; in unthrottle() local
1291 if (sanity_check(info, tty->name, "unthrottle")) in unthrottle()
1293 DBGINFO(("%s unthrottle\n", info->device_name)); in unthrottle()
1295 if (info->x_char) in unthrottle()
1296 info->x_char = 0; in unthrottle()
1301 spin_lock_irqsave(&info->lock,flags); in unthrottle()
1302 info->signals |= SerialSignal_RTS; in unthrottle()
1303 set_gtsignals(info); in unthrottle()
1304 spin_unlock_irqrestore(&info->lock,flags); in unthrottle()
1314 struct slgt_info *info = tty->driver_data; in set_break() local
1318 if (sanity_check(info, tty->name, "set_break")) in set_break()
1320 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); in set_break()
1322 spin_lock_irqsave(&info->lock,flags); in set_break()
1323 value = rd_reg16(info, TCR); in set_break()
1328 wr_reg16(info, TCR, value); in set_break()
1329 spin_unlock_irqrestore(&info->lock,flags); in set_break()
1348 struct slgt_info *info = dev_to_port(dev); in hdlcdev_attach() local
1353 if (info->port.count) in hdlcdev_attach()
1356 DBGINFO(("%s hdlcdev_attach\n", info->device_name)); in hdlcdev_attach()
1376 info->params.encoding = new_encoding; in hdlcdev_attach()
1377 info->params.crc_type = new_crctype; in hdlcdev_attach()
1380 if (info->netcount) in hdlcdev_attach()
1381 program_hw(info); in hdlcdev_attach()
1394 struct slgt_info *info = dev_to_port(dev); in hdlcdev_xmit() local
1412 spin_lock_irqsave(&info->lock, flags); in hdlcdev_xmit()
1413 tx_load(info, skb->data, skb->len); in hdlcdev_xmit()
1414 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_xmit()
1432 struct slgt_info *info = dev_to_port(dev); in hdlcdev_open() local
1447 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1448 if (info->port.count != 0 || info->netcount != 0) { in hdlcdev_open()
1450 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1453 info->netcount=1; in hdlcdev_open()
1454 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1457 if ((rc = startup(info)) != 0) { in hdlcdev_open()
1458 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1459 info->netcount=0; in hdlcdev_open()
1460 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1465 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in hdlcdev_open()
1466 program_hw(info); in hdlcdev_open()
1473 spin_lock_irqsave(&info->lock, flags); in hdlcdev_open()
1474 get_gtsignals(info); in hdlcdev_open()
1475 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_open()
1476 if (info->signals & SerialSignal_DCD) in hdlcdev_open()
1493 struct slgt_info *info = dev_to_port(dev); in hdlcdev_close() local
1501 shutdown(info); in hdlcdev_close()
1505 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_close()
1506 info->netcount=0; in hdlcdev_close()
1507 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_close()
1526 struct slgt_info *info = dev_to_port(dev); in hdlcdev_ioctl() local
1532 if (info->port.count) in hdlcdev_ioctl()
1546 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1559 new_line.clock_rate = info->params.clock_speed; in hdlcdev_ioctl()
1560 new_line.loopback = info->params.loopback ? 1:0; in hdlcdev_ioctl()
1579 case CLOCK_DEFAULT: flags = info->params.flags & in hdlcdev_ioctl()
1590 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1594 info->params.flags |= flags; in hdlcdev_ioctl()
1596 info->params.loopback = new_line.loopback; in hdlcdev_ioctl()
1599 info->params.clock_speed = new_line.clock_rate; in hdlcdev_ioctl()
1601 info->params.clock_speed = 0; in hdlcdev_ioctl()
1604 if (info->netcount) in hdlcdev_ioctl()
1605 program_hw(info); in hdlcdev_ioctl()
1620 struct slgt_info *info = dev_to_port(dev); in hdlcdev_tx_timeout() local
1628 spin_lock_irqsave(&info->lock,flags); in hdlcdev_tx_timeout()
1629 tx_stop(info); in hdlcdev_tx_timeout()
1630 spin_unlock_irqrestore(&info->lock,flags); in hdlcdev_tx_timeout()
1641 static void hdlcdev_tx_done(struct slgt_info *info) in hdlcdev_tx_done() argument
1643 if (netif_queue_stopped(info->netdev)) in hdlcdev_tx_done()
1644 netif_wake_queue(info->netdev); in hdlcdev_tx_done()
1655 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size) in hdlcdev_rx() argument
1658 struct net_device *dev = info->netdev; in hdlcdev_rx()
1694 static int hdlcdev_init(struct slgt_info *info) in hdlcdev_init() argument
1702 dev = alloc_hdlcdev(info); in hdlcdev_init()
1704 printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name); in hdlcdev_init()
1709 dev->mem_start = info->phys_reg_addr; in hdlcdev_init()
1710 dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1; in hdlcdev_init()
1711 dev->irq = info->irq_level; in hdlcdev_init()
1731 info->netdev = dev; in hdlcdev_init()
1741 static void hdlcdev_exit(struct slgt_info *info) in hdlcdev_exit() argument
1743 if (!info->netdev) in hdlcdev_exit()
1745 unregister_hdlc_device(info->netdev); in hdlcdev_exit()
1746 free_netdev(info->netdev); in hdlcdev_exit()
1747 info->netdev = NULL; in hdlcdev_exit()
1755 static void rx_async(struct slgt_info *info) in rx_async() argument
1757 struct mgsl_icount *icount = &info->icount; in rx_async()
1761 struct slgt_desc *bufs = info->rbufs; in rx_async()
1767 start = end = info->rbuf_current; in rx_async()
1770 count = desc_count(bufs[end]) - info->rbuf_index; in rx_async()
1771 p = bufs[end].buf + info->rbuf_index; in rx_async()
1773 DBGISR(("%s rx_async count=%d\n", info->device_name, count)); in rx_async()
1774 DBGDATA(info, p, count, "rx"); in rx_async()
1789 if (status & info->ignore_status_mask) in rx_async()
1796 tty_insert_flip_char(&info->port, ch, stat); in rx_async()
1802 info->rbuf_index += i; in rx_async()
1803 mod_timer(&info->rx_timer, jiffies + 1); in rx_async()
1807 info->rbuf_index = 0; in rx_async()
1808 free_rbufs(info, end, end); in rx_async()
1810 if (++end == info->rbuf_count) in rx_async()
1819 tty_flip_buffer_push(&info->port); in rx_async()
1825 static int bh_action(struct slgt_info *info) in bh_action() argument
1830 spin_lock_irqsave(&info->lock,flags); in bh_action()
1832 if (info->pending_bh & BH_RECEIVE) { in bh_action()
1833 info->pending_bh &= ~BH_RECEIVE; in bh_action()
1835 } else if (info->pending_bh & BH_TRANSMIT) { in bh_action()
1836 info->pending_bh &= ~BH_TRANSMIT; in bh_action()
1838 } else if (info->pending_bh & BH_STATUS) { in bh_action()
1839 info->pending_bh &= ~BH_STATUS; in bh_action()
1843 info->bh_running = false; in bh_action()
1844 info->bh_requested = false; in bh_action()
1848 spin_unlock_irqrestore(&info->lock,flags); in bh_action()
1858 struct slgt_info *info = container_of(work, struct slgt_info, task); in bh_handler() local
1861 info->bh_running = true; in bh_handler()
1863 while((action = bh_action(info))) { in bh_handler()
1866 DBGBH(("%s bh receive\n", info->device_name)); in bh_handler()
1867 switch(info->params.mode) { in bh_handler()
1869 rx_async(info); in bh_handler()
1872 while(rx_get_frame(info)); in bh_handler()
1878 while(rx_get_buf(info)); in bh_handler()
1882 if (info->rx_restart) in bh_handler()
1883 rx_start(info); in bh_handler()
1886 bh_transmit(info); in bh_handler()
1889 DBGBH(("%s bh status\n", info->device_name)); in bh_handler()
1890 info->ri_chkcount = 0; in bh_handler()
1891 info->dsr_chkcount = 0; in bh_handler()
1892 info->dcd_chkcount = 0; in bh_handler()
1893 info->cts_chkcount = 0; in bh_handler()
1896 DBGBH(("%s unknown action\n", info->device_name)); in bh_handler()
1900 DBGBH(("%s bh_handler exit\n", info->device_name)); in bh_handler()
1903 static void bh_transmit(struct slgt_info *info) in bh_transmit() argument
1905 struct tty_struct *tty = info->port.tty; in bh_transmit()
1907 DBGBH(("%s bh_transmit\n", info->device_name)); in bh_transmit()
1912 static void dsr_change(struct slgt_info *info, unsigned short status) in dsr_change() argument
1915 info->signals |= SerialSignal_DSR; in dsr_change()
1916 info->input_signal_events.dsr_up++; in dsr_change()
1918 info->signals &= ~SerialSignal_DSR; in dsr_change()
1919 info->input_signal_events.dsr_down++; in dsr_change()
1921 DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); in dsr_change()
1922 if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dsr_change()
1923 slgt_irq_off(info, IRQ_DSR); in dsr_change()
1926 info->icount.dsr++; in dsr_change()
1927 wake_up_interruptible(&info->status_event_wait_q); in dsr_change()
1928 wake_up_interruptible(&info->event_wait_q); in dsr_change()
1929 info->pending_bh |= BH_STATUS; in dsr_change()
1932 static void cts_change(struct slgt_info *info, unsigned short status) in cts_change() argument
1935 info->signals |= SerialSignal_CTS; in cts_change()
1936 info->input_signal_events.cts_up++; in cts_change()
1938 info->signals &= ~SerialSignal_CTS; in cts_change()
1939 info->input_signal_events.cts_down++; in cts_change()
1941 DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); in cts_change()
1942 if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in cts_change()
1943 slgt_irq_off(info, IRQ_CTS); in cts_change()
1946 info->icount.cts++; in cts_change()
1947 wake_up_interruptible(&info->status_event_wait_q); in cts_change()
1948 wake_up_interruptible(&info->event_wait_q); in cts_change()
1949 info->pending_bh |= BH_STATUS; in cts_change()
1951 if (tty_port_cts_enabled(&info->port)) { in cts_change()
1952 if (info->port.tty) { in cts_change()
1953 if (info->port.tty->hw_stopped) { in cts_change()
1954 if (info->signals & SerialSignal_CTS) { in cts_change()
1955 info->port.tty->hw_stopped = 0; in cts_change()
1956 info->pending_bh |= BH_TRANSMIT; in cts_change()
1960 if (!(info->signals & SerialSignal_CTS)) in cts_change()
1961 info->port.tty->hw_stopped = 1; in cts_change()
1967 static void dcd_change(struct slgt_info *info, unsigned short status) in dcd_change() argument
1970 info->signals |= SerialSignal_DCD; in dcd_change()
1971 info->input_signal_events.dcd_up++; in dcd_change()
1973 info->signals &= ~SerialSignal_DCD; in dcd_change()
1974 info->input_signal_events.dcd_down++; in dcd_change()
1976 DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); in dcd_change()
1977 if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dcd_change()
1978 slgt_irq_off(info, IRQ_DCD); in dcd_change()
1981 info->icount.dcd++; in dcd_change()
1983 if (info->netcount) { in dcd_change()
1984 if (info->signals & SerialSignal_DCD) in dcd_change()
1985 netif_carrier_on(info->netdev); in dcd_change()
1987 netif_carrier_off(info->netdev); in dcd_change()
1990 wake_up_interruptible(&info->status_event_wait_q); in dcd_change()
1991 wake_up_interruptible(&info->event_wait_q); in dcd_change()
1992 info->pending_bh |= BH_STATUS; in dcd_change()
1994 if (tty_port_check_carrier(&info->port)) { in dcd_change()
1995 if (info->signals & SerialSignal_DCD) in dcd_change()
1996 wake_up_interruptible(&info->port.open_wait); in dcd_change()
1998 if (info->port.tty) in dcd_change()
1999 tty_hangup(info->port.tty); in dcd_change()
2004 static void ri_change(struct slgt_info *info, unsigned short status) in ri_change() argument
2007 info->signals |= SerialSignal_RI; in ri_change()
2008 info->input_signal_events.ri_up++; in ri_change()
2010 info->signals &= ~SerialSignal_RI; in ri_change()
2011 info->input_signal_events.ri_down++; in ri_change()
2013 DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); in ri_change()
2014 if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in ri_change()
2015 slgt_irq_off(info, IRQ_RI); in ri_change()
2018 info->icount.rng++; in ri_change()
2019 wake_up_interruptible(&info->status_event_wait_q); in ri_change()
2020 wake_up_interruptible(&info->event_wait_q); in ri_change()
2021 info->pending_bh |= BH_STATUS; in ri_change()
2024 static void isr_rxdata(struct slgt_info *info) in isr_rxdata() argument
2026 unsigned int count = info->rbuf_fill_count; in isr_rxdata()
2027 unsigned int i = info->rbuf_fill_index; in isr_rxdata()
2030 while (rd_reg16(info, SSR) & IRQ_RXDATA) { in isr_rxdata()
2031 reg = rd_reg16(info, RDR); in isr_rxdata()
2032 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); in isr_rxdata()
2033 if (desc_complete(info->rbufs[i])) { in isr_rxdata()
2035 rx_stop(info); in isr_rxdata()
2036 info->rx_restart = true; in isr_rxdata()
2039 info->rbufs[i].buf[count++] = (unsigned char)reg; in isr_rxdata()
2041 if (info->params.mode == MGSL_MODE_ASYNC) in isr_rxdata()
2042 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); in isr_rxdata()
2043 if (count == info->rbuf_fill_level || (reg & BIT10)) { in isr_rxdata()
2045 set_desc_count(info->rbufs[i], count); in isr_rxdata()
2046 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); in isr_rxdata()
2047 info->rbuf_fill_count = count = 0; in isr_rxdata()
2048 if (++i == info->rbuf_count) in isr_rxdata()
2050 info->pending_bh |= BH_RECEIVE; in isr_rxdata()
2054 info->rbuf_fill_index = i; in isr_rxdata()
2055 info->rbuf_fill_count = count; in isr_rxdata()
2058 static void isr_serial(struct slgt_info *info) in isr_serial() argument
2060 unsigned short status = rd_reg16(info, SSR); in isr_serial()
2062 DBGISR(("%s isr_serial status=%04X\n", info->device_name, status)); in isr_serial()
2064 wr_reg16(info, SSR, status); /* clear pending */ in isr_serial()
2066 info->irq_occurred = true; in isr_serial()
2068 if (info->params.mode == MGSL_MODE_ASYNC) { in isr_serial()
2070 if (info->tx_active) in isr_serial()
2071 isr_txeom(info, status); in isr_serial()
2073 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2074 isr_rxdata(info); in isr_serial()
2076 info->icount.brk++; in isr_serial()
2078 if (info->port.tty) { in isr_serial()
2079 if (!(status & info->ignore_status_mask)) { in isr_serial()
2080 if (info->read_status_mask & MASK_BREAK) { in isr_serial()
2081 tty_insert_flip_char(&info->port, 0, TTY_BREAK); in isr_serial()
2082 if (info->port.flags & ASYNC_SAK) in isr_serial()
2083 do_SAK(info->port.tty); in isr_serial()
2090 isr_txeom(info, status); in isr_serial()
2091 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2092 isr_rxdata(info); in isr_serial()
2095 info->icount.rxidle++; in isr_serial()
2097 info->icount.exithunt++; in isr_serial()
2098 wake_up_interruptible(&info->event_wait_q); in isr_serial()
2102 rx_start(info); in isr_serial()
2106 dsr_change(info, status); in isr_serial()
2108 cts_change(info, status); in isr_serial()
2110 dcd_change(info, status); in isr_serial()
2112 ri_change(info, status); in isr_serial()
2115 static void isr_rdma(struct slgt_info *info) in isr_rdma() argument
2117 unsigned int status = rd_reg32(info, RDCSR); in isr_rdma()
2119 DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status)); in isr_rdma()
2132 wr_reg32(info, RDCSR, status); /* clear pending */ in isr_rdma()
2135 DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); in isr_rdma()
2136 info->rx_restart = true; in isr_rdma()
2138 info->pending_bh |= BH_RECEIVE; in isr_rdma()
2141 static void isr_tdma(struct slgt_info *info) in isr_tdma() argument
2143 unsigned int status = rd_reg32(info, TDCSR); in isr_tdma()
2145 DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status)); in isr_tdma()
2157 wr_reg32(info, TDCSR, status); /* clear pending */ in isr_tdma()
2162 info->pending_bh |= BH_TRANSMIT; in isr_tdma()
2172 static bool unsent_tbufs(struct slgt_info *info) in unsent_tbufs() argument
2174 unsigned int i = info->tbuf_current; in unsent_tbufs()
2186 i = info->tbuf_count - 1; in unsent_tbufs()
2187 if (!desc_count(info->tbufs[i])) in unsent_tbufs()
2189 info->tbuf_start = i; in unsent_tbufs()
2191 } while (i != info->tbuf_current); in unsent_tbufs()
2196 static void isr_txeom(struct slgt_info *info, unsigned short status) in isr_txeom() argument
2198 DBGISR(("%s txeom status=%04x\n", info->device_name, status)); in isr_txeom()
2200 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in isr_txeom()
2201 tdma_reset(info); in isr_txeom()
2203 unsigned short val = rd_reg16(info, TCR); in isr_txeom()
2204 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in isr_txeom()
2205 wr_reg16(info, TCR, val); /* clear reset bit */ in isr_txeom()
2208 if (info->tx_active) { in isr_txeom()
2209 if (info->params.mode != MGSL_MODE_ASYNC) { in isr_txeom()
2211 info->icount.txunder++; in isr_txeom()
2213 info->icount.txok++; in isr_txeom()
2216 if (unsent_tbufs(info)) { in isr_txeom()
2217 tx_start(info); in isr_txeom()
2218 update_tx_timer(info); in isr_txeom()
2221 info->tx_active = false; in isr_txeom()
2223 del_timer(&info->tx_timer); in isr_txeom()
2225 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { in isr_txeom()
2226 info->signals &= ~SerialSignal_RTS; in isr_txeom()
2227 info->drop_rts_on_tx_done = false; in isr_txeom()
2228 set_gtsignals(info); in isr_txeom()
2232 if (info->netcount) in isr_txeom()
2233 hdlcdev_tx_done(info); in isr_txeom()
2237 if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) { in isr_txeom()
2238 tx_stop(info); in isr_txeom()
2241 info->pending_bh |= BH_TRANSMIT; in isr_txeom()
2246 static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state) in isr_gpio() argument
2251 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) { in isr_gpio()
2258 info->gpio_wait_q = w->next; in isr_gpio()
2271 struct slgt_info *info = dev_id; in slgt_interrupt() local
2275 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); in slgt_interrupt()
2277 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { in slgt_interrupt()
2278 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); in slgt_interrupt()
2279 info->irq_occurred = true; in slgt_interrupt()
2280 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2281 if (info->port_array[i] == NULL) in slgt_interrupt()
2283 spin_lock(&info->port_array[i]->lock); in slgt_interrupt()
2285 isr_serial(info->port_array[i]); in slgt_interrupt()
2287 isr_rdma(info->port_array[i]); in slgt_interrupt()
2289 isr_tdma(info->port_array[i]); in slgt_interrupt()
2290 spin_unlock(&info->port_array[i]->lock); in slgt_interrupt()
2294 if (info->gpio_present) { in slgt_interrupt()
2297 spin_lock(&info->lock); in slgt_interrupt()
2298 while ((changed = rd_reg32(info, IOSR)) != 0) { in slgt_interrupt()
2299 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); in slgt_interrupt()
2301 state = rd_reg32(info, IOVR); in slgt_interrupt()
2303 wr_reg32(info, IOSR, changed); in slgt_interrupt()
2304 for (i=0 ; i < info->port_count ; i++) { in slgt_interrupt()
2305 if (info->port_array[i] != NULL) in slgt_interrupt()
2306 isr_gpio(info->port_array[i], changed, state); in slgt_interrupt()
2309 spin_unlock(&info->lock); in slgt_interrupt()
2312 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2313 struct slgt_info *port = info->port_array[i]; in slgt_interrupt()
2327 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); in slgt_interrupt()
2331 static int startup(struct slgt_info *info) in startup() argument
2333 DBGINFO(("%s startup\n", info->device_name)); in startup()
2335 if (tty_port_initialized(&info->port)) in startup()
2338 if (!info->tx_buf) { in startup()
2339 info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); in startup()
2340 if (!info->tx_buf) { in startup()
2341 DBGERR(("%s can't allocate tx buffer\n", info->device_name)); in startup()
2346 info->pending_bh = 0; in startup()
2348 memset(&info->icount, 0, sizeof(info->icount)); in startup()
2351 change_params(info); in startup()
2353 if (info->port.tty) in startup()
2354 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); in startup()
2356 tty_port_set_initialized(&info->port, 1); in startup()
2364 static void shutdown(struct slgt_info *info) in shutdown() argument
2368 if (!tty_port_initialized(&info->port)) in shutdown()
2371 DBGINFO(("%s shutdown\n", info->device_name)); in shutdown()
2375 wake_up_interruptible(&info->status_event_wait_q); in shutdown()
2376 wake_up_interruptible(&info->event_wait_q); in shutdown()
2378 del_timer_sync(&info->tx_timer); in shutdown()
2379 del_timer_sync(&info->rx_timer); in shutdown()
2381 kfree(info->tx_buf); in shutdown()
2382 info->tx_buf = NULL; in shutdown()
2384 spin_lock_irqsave(&info->lock,flags); in shutdown()
2386 tx_stop(info); in shutdown()
2387 rx_stop(info); in shutdown()
2389 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in shutdown()
2391 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { in shutdown()
2392 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in shutdown()
2393 set_gtsignals(info); in shutdown()
2396 flush_cond_wait(&info->gpio_wait_q); in shutdown()
2398 spin_unlock_irqrestore(&info->lock,flags); in shutdown()
2400 if (info->port.tty) in shutdown()
2401 set_bit(TTY_IO_ERROR, &info->port.tty->flags); in shutdown()
2403 tty_port_set_initialized(&info->port, 0); in shutdown()
2406 static void program_hw(struct slgt_info *info) in program_hw() argument
2410 spin_lock_irqsave(&info->lock,flags); in program_hw()
2412 rx_stop(info); in program_hw()
2413 tx_stop(info); in program_hw()
2415 if (info->params.mode != MGSL_MODE_ASYNC || in program_hw()
2416 info->netcount) in program_hw()
2417 sync_mode(info); in program_hw()
2419 async_mode(info); in program_hw()
2421 set_gtsignals(info); in program_hw()
2423 info->dcd_chkcount = 0; in program_hw()
2424 info->cts_chkcount = 0; in program_hw()
2425 info->ri_chkcount = 0; in program_hw()
2426 info->dsr_chkcount = 0; in program_hw()
2428 slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI); in program_hw()
2429 get_gtsignals(info); in program_hw()
2431 if (info->netcount || in program_hw()
2432 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) in program_hw()
2433 rx_start(info); in program_hw()
2435 spin_unlock_irqrestore(&info->lock,flags); in program_hw()
2441 static void change_params(struct slgt_info *info) in change_params() argument
2446 if (!info->port.tty) in change_params()
2448 DBGINFO(("%s change_params\n", info->device_name)); in change_params()
2450 cflag = info->port.tty->termios.c_cflag; in change_params()
2455 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in change_params()
2457 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in change_params()
2461 info->params.data_bits = tty_get_char_size(cflag); in change_params()
2462 info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1; in change_params()
2465 info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN; in change_params()
2467 info->params.parity = ASYNC_PARITY_NONE; in change_params()
2472 bits_per_char = info->params.data_bits + in change_params()
2473 info->params.stop_bits + 1; in change_params()
2475 info->params.data_rate = tty_get_baud_rate(info->port.tty); in change_params()
2477 if (info->params.data_rate) { in change_params()
2478 info->timeout = (32*HZ*bits_per_char) / in change_params()
2479 info->params.data_rate; in change_params()
2481 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_params()
2483 tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); in change_params()
2484 tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); in change_params()
2488 info->read_status_mask = IRQ_RXOVER; in change_params()
2489 if (I_INPCK(info->port.tty)) in change_params()
2490 info->read_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2491 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) in change_params()
2492 info->read_status_mask |= MASK_BREAK; in change_params()
2493 if (I_IGNPAR(info->port.tty)) in change_params()
2494 info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2495 if (I_IGNBRK(info->port.tty)) { in change_params()
2496 info->ignore_status_mask |= MASK_BREAK; in change_params()
2500 if (I_IGNPAR(info->port.tty)) in change_params()
2501 info->ignore_status_mask |= MASK_OVERRUN; in change_params()
2504 program_hw(info); in change_params()
2507 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount) in get_stats() argument
2509 DBGINFO(("%s get_stats\n", info->device_name)); in get_stats()
2511 memset(&info->icount, 0, sizeof(info->icount)); in get_stats()
2513 if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount))) in get_stats()
2519 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params) in get_params() argument
2521 DBGINFO(("%s get_params\n", info->device_name)); in get_params()
2522 if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS))) in get_params()
2527 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params) in set_params() argument
2532 DBGINFO(("%s set_params\n", info->device_name)); in set_params()
2536 spin_lock_irqsave(&info->lock, flags); in set_params()
2538 info->base_clock = tmp_params.clock_speed; in set_params()
2540 memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS)); in set_params()
2541 spin_unlock_irqrestore(&info->lock, flags); in set_params()
2543 program_hw(info); in set_params()
2548 static int get_txidle(struct slgt_info *info, int __user *idle_mode) in get_txidle() argument
2550 DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode)); in get_txidle()
2551 if (put_user(info->idle_mode, idle_mode)) in get_txidle()
2556 static int set_txidle(struct slgt_info *info, int idle_mode) in set_txidle() argument
2559 DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode)); in set_txidle()
2560 spin_lock_irqsave(&info->lock,flags); in set_txidle()
2561 info->idle_mode = idle_mode; in set_txidle()
2562 if (info->params.mode != MGSL_MODE_ASYNC) in set_txidle()
2563 tx_set_idle(info); in set_txidle()
2564 spin_unlock_irqrestore(&info->lock,flags); in set_txidle()
2568 static int tx_enable(struct slgt_info *info, int enable) in tx_enable() argument
2571 DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable)); in tx_enable()
2572 spin_lock_irqsave(&info->lock,flags); in tx_enable()
2574 if (!info->tx_enabled) in tx_enable()
2575 tx_start(info); in tx_enable()
2577 if (info->tx_enabled) in tx_enable()
2578 tx_stop(info); in tx_enable()
2580 spin_unlock_irqrestore(&info->lock,flags); in tx_enable()
2587 static int tx_abort(struct slgt_info *info) in tx_abort() argument
2590 DBGINFO(("%s tx_abort\n", info->device_name)); in tx_abort()
2591 spin_lock_irqsave(&info->lock,flags); in tx_abort()
2592 tdma_reset(info); in tx_abort()
2593 spin_unlock_irqrestore(&info->lock,flags); in tx_abort()
2597 static int rx_enable(struct slgt_info *info, int enable) in rx_enable() argument
2601 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable)); in rx_enable()
2602 spin_lock_irqsave(&info->lock,flags); in rx_enable()
2611 spin_unlock_irqrestore(&info->lock, flags); in rx_enable()
2614 info->rbuf_fill_level = rbuf_fill_level; in rx_enable()
2616 info->rx_pio = 1; /* PIO mode */ in rx_enable()
2618 info->rx_pio = 0; /* DMA mode */ in rx_enable()
2619 rx_stop(info); /* restart receiver to use new fill level */ in rx_enable()
2630 if (!info->rx_enabled) in rx_enable()
2631 rx_start(info); in rx_enable()
2634 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3); in rx_enable()
2637 if (info->rx_enabled) in rx_enable()
2638 rx_stop(info); in rx_enable()
2640 spin_unlock_irqrestore(&info->lock,flags); in rx_enable()
2647 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr) in wait_mgsl_event() argument
2661 DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask)); in wait_mgsl_event()
2663 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2666 get_gtsignals(info); in wait_mgsl_event()
2667 s = info->signals; in wait_mgsl_event()
2675 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2680 cprev = info->icount; in wait_mgsl_event()
2681 oldsigs = info->input_signal_events; in wait_mgsl_event()
2685 unsigned short val = rd_reg16(info, SCR); in wait_mgsl_event()
2687 wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE)); in wait_mgsl_event()
2691 add_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2693 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2703 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2704 cnow = info->icount; in wait_mgsl_event()
2705 newsigs = info->input_signal_events; in wait_mgsl_event()
2707 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2742 remove_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2747 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2748 if (!waitqueue_active(&info->event_wait_q)) { in wait_mgsl_event()
2750 wr_reg16(info, SCR, in wait_mgsl_event()
2751 (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE)); in wait_mgsl_event()
2753 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2761 static int get_interface(struct slgt_info *info, int __user *if_mode) in get_interface() argument
2763 DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode)); in get_interface()
2764 if (put_user(info->if_mode, if_mode)) in get_interface()
2769 static int set_interface(struct slgt_info *info, int if_mode) in set_interface() argument
2774 DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode)); in set_interface()
2775 spin_lock_irqsave(&info->lock,flags); in set_interface()
2776 info->if_mode = if_mode; in set_interface()
2778 msc_set_vcr(info); in set_interface()
2781 val = rd_reg16(info, TCR); in set_interface()
2782 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in set_interface()
2786 wr_reg16(info, TCR, val); in set_interface()
2788 spin_unlock_irqrestore(&info->lock,flags); in set_interface()
2792 static int get_xsync(struct slgt_info *info, int __user *xsync) in get_xsync() argument
2794 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync)); in get_xsync()
2795 if (put_user(info->xsync, xsync)) in get_xsync()
2806 static int set_xsync(struct slgt_info *info, int xsync) in set_xsync() argument
2810 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync)); in set_xsync()
2811 spin_lock_irqsave(&info->lock, flags); in set_xsync()
2812 info->xsync = xsync; in set_xsync()
2813 wr_reg32(info, XSR, xsync); in set_xsync()
2814 spin_unlock_irqrestore(&info->lock, flags); in set_xsync()
2818 static int get_xctrl(struct slgt_info *info, int __user *xctrl) in get_xctrl() argument
2820 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl)); in get_xctrl()
2821 if (put_user(info->xctrl, xctrl)) in get_xctrl()
2843 static int set_xctrl(struct slgt_info *info, int xctrl) in set_xctrl() argument
2847 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl)); in set_xctrl()
2848 spin_lock_irqsave(&info->lock, flags); in set_xctrl()
2849 info->xctrl = xctrl; in set_xctrl()
2850 wr_reg32(info, XCR, xctrl); in set_xctrl()
2851 spin_unlock_irqrestore(&info->lock, flags); in set_xctrl()
2864 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in set_gpio() argument
2870 if (!info->gpio_present) in set_gpio()
2875 info->device_name, gpio.state, gpio.smask, in set_gpio()
2878 spin_lock_irqsave(&info->port_array[0]->lock, flags); in set_gpio()
2880 data = rd_reg32(info, IODR); in set_gpio()
2883 wr_reg32(info, IODR, data); in set_gpio()
2886 data = rd_reg32(info, IOVR); in set_gpio()
2889 wr_reg32(info, IOVR, data); in set_gpio()
2891 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in set_gpio()
2899 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in get_gpio() argument
2902 if (!info->gpio_present) in get_gpio()
2904 gpio.state = rd_reg32(info, IOVR); in get_gpio()
2906 gpio.dir = rd_reg32(info, IODR); in get_gpio()
2911 info->device_name, gpio.state, gpio.dir)); in get_gpio()
2973 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in wait_gpio() argument
2981 if (!info->gpio_present) in wait_gpio()
2986 info->device_name, gpio.state, gpio.smask)); in wait_gpio()
2988 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0) in wait_gpio()
2992 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
2994 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); in wait_gpio()
2996 state = rd_reg32(info, IOVR); in wait_gpio()
3003 add_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3004 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3010 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3011 remove_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3015 if (info->gpio_wait_q == NULL) in wait_gpio()
3016 wr_reg32(info, IOER, 0); in wait_gpio()
3017 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3024 static int modem_input_wait(struct slgt_info *info,int arg) in modem_input_wait() argument
3032 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3033 cprev = info->icount; in modem_input_wait()
3034 add_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3036 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3046 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3047 cnow = info->icount; in modem_input_wait()
3049 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3069 remove_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3079 struct slgt_info *info = tty->driver_data; in tiocmget() local
3083 spin_lock_irqsave(&info->lock,flags); in tiocmget()
3084 get_gtsignals(info); in tiocmget()
3085 spin_unlock_irqrestore(&info->lock,flags); in tiocmget()
3087 result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) + in tiocmget()
3088 ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) + in tiocmget()
3089 ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) + in tiocmget()
3090 ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) + in tiocmget()
3091 ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) + in tiocmget()
3092 ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0); in tiocmget()
3094 DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result)); in tiocmget()
3108 struct slgt_info *info = tty->driver_data; in tiocmset() local
3111 DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear)); in tiocmset()
3114 info->signals |= SerialSignal_RTS; in tiocmset()
3116 info->signals |= SerialSignal_DTR; in tiocmset()
3118 info->signals &= ~SerialSignal_RTS; in tiocmset()
3120 info->signals &= ~SerialSignal_DTR; in tiocmset()
3122 spin_lock_irqsave(&info->lock,flags); in tiocmset()
3123 set_gtsignals(info); in tiocmset()
3124 spin_unlock_irqrestore(&info->lock,flags); in tiocmset()
3131 struct slgt_info *info = container_of(port, struct slgt_info, port); in carrier_raised() local
3133 spin_lock_irqsave(&info->lock,flags); in carrier_raised()
3134 get_gtsignals(info); in carrier_raised()
3135 spin_unlock_irqrestore(&info->lock,flags); in carrier_raised()
3136 return (info->signals & SerialSignal_DCD) ? 1 : 0; in carrier_raised()
3142 struct slgt_info *info = container_of(port, struct slgt_info, port); in dtr_rts() local
3144 spin_lock_irqsave(&info->lock,flags); in dtr_rts()
3146 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in dtr_rts()
3148 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in dtr_rts()
3149 set_gtsignals(info); in dtr_rts()
3150 spin_unlock_irqrestore(&info->lock,flags); in dtr_rts()
3158 struct slgt_info *info) in block_til_ready() argument
3165 struct tty_port *port = &info->port; in block_til_ready()
3188 spin_lock_irqsave(&info->lock, flags); in block_til_ready()
3190 spin_unlock_irqrestore(&info->lock, flags); in block_til_ready()
3240 static int alloc_tmp_rbuf(struct slgt_info *info) in alloc_tmp_rbuf() argument
3242 info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3243 if (info->tmp_rbuf == NULL) in alloc_tmp_rbuf()
3246 info->flag_buf = kzalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3247 if (!info->flag_buf) { in alloc_tmp_rbuf()
3248 kfree(info->tmp_rbuf); in alloc_tmp_rbuf()
3249 info->tmp_rbuf = NULL; in alloc_tmp_rbuf()
3255 static void free_tmp_rbuf(struct slgt_info *info) in free_tmp_rbuf() argument
3257 kfree(info->tmp_rbuf); in free_tmp_rbuf()
3258 info->tmp_rbuf = NULL; in free_tmp_rbuf()
3259 kfree(info->flag_buf); in free_tmp_rbuf()
3260 info->flag_buf = NULL; in free_tmp_rbuf()
3266 static int alloc_desc(struct slgt_info *info) in alloc_desc() argument
3272 info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE, in alloc_desc()
3273 &info->bufs_dma_addr, GFP_KERNEL); in alloc_desc()
3274 if (info->bufs == NULL) in alloc_desc()
3277 info->rbufs = (struct slgt_desc*)info->bufs; in alloc_desc()
3278 info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count; in alloc_desc()
3280 pbufs = (unsigned int)info->bufs_dma_addr; in alloc_desc()
3286 for (i=0; i < info->rbuf_count; i++) { in alloc_desc()
3288 info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc)); in alloc_desc()
3291 if (i == info->rbuf_count - 1) in alloc_desc()
3292 info->rbufs[i].next = cpu_to_le32(pbufs); in alloc_desc()
3294 info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc))); in alloc_desc()
3295 set_desc_count(info->rbufs[i], DMABUFSIZE); in alloc_desc()
3298 for (i=0; i < info->tbuf_count; i++) { in alloc_desc()
3300 info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc)); in alloc_desc()
3303 if (i == info->tbuf_count - 1) in alloc_desc()
3304 info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc)); in alloc_desc()
3306 …info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc))); in alloc_desc()
3312 static void free_desc(struct slgt_info *info) in free_desc() argument
3314 if (info->bufs != NULL) { in free_desc()
3315 dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE, in free_desc()
3316 info->bufs, info->bufs_dma_addr); in free_desc()
3317 info->bufs = NULL; in free_desc()
3318 info->rbufs = NULL; in free_desc()
3319 info->tbufs = NULL; in free_desc()
3323 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in alloc_bufs() argument
3327 bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE, in alloc_bufs()
3336 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in free_bufs() argument
3342 dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf, in free_bufs()
3348 static int alloc_dma_bufs(struct slgt_info *info) in alloc_dma_bufs() argument
3350 info->rbuf_count = 32; in alloc_dma_bufs()
3351 info->tbuf_count = 32; in alloc_dma_bufs()
3353 if (alloc_desc(info) < 0 || in alloc_dma_bufs()
3354 alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 || in alloc_dma_bufs()
3355 alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 || in alloc_dma_bufs()
3356 alloc_tmp_rbuf(info) < 0) { in alloc_dma_bufs()
3357 DBGERR(("%s DMA buffer alloc fail\n", info->device_name)); in alloc_dma_bufs()
3360 reset_rbufs(info); in alloc_dma_bufs()
3364 static void free_dma_bufs(struct slgt_info *info) in free_dma_bufs() argument
3366 if (info->bufs) { in free_dma_bufs()
3367 free_bufs(info, info->rbufs, info->rbuf_count); in free_dma_bufs()
3368 free_bufs(info, info->tbufs, info->tbuf_count); in free_dma_bufs()
3369 free_desc(info); in free_dma_bufs()
3371 free_tmp_rbuf(info); in free_dma_bufs()
3374 static int claim_resources(struct slgt_info *info) in claim_resources() argument
3376 if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) { in claim_resources()
3378 info->device_name, info->phys_reg_addr)); in claim_resources()
3379 info->init_error = DiagStatus_AddressConflict; in claim_resources()
3383 info->reg_addr_requested = true; in claim_resources()
3385 info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); in claim_resources()
3386 if (!info->reg_addr) { in claim_resources()
3388 info->device_name, info->phys_reg_addr)); in claim_resources()
3389 info->init_error = DiagStatus_CantAssignPciResources; in claim_resources()
3395 release_resources(info); in claim_resources()
3399 static void release_resources(struct slgt_info *info) in release_resources() argument
3401 if (info->irq_requested) { in release_resources()
3402 free_irq(info->irq_level, info); in release_resources()
3403 info->irq_requested = false; in release_resources()
3406 if (info->reg_addr_requested) { in release_resources()
3407 release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); in release_resources()
3408 info->reg_addr_requested = false; in release_resources()
3411 if (info->reg_addr) { in release_resources()
3412 iounmap(info->reg_addr); in release_resources()
3413 info->reg_addr = NULL; in release_resources()
3420 static void add_device(struct slgt_info *info) in add_device() argument
3424 info->next_device = NULL; in add_device()
3425 info->line = slgt_device_count; in add_device()
3426 sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line); in add_device()
3428 if (info->line < MAX_DEVICES) { in add_device()
3429 if (maxframe[info->line]) in add_device()
3430 info->max_frame_size = maxframe[info->line]; in add_device()
3436 slgt_device_list = info; in add_device()
3441 current_dev->next_device = info; in add_device()
3444 if (info->max_frame_size < 4096) in add_device()
3445 info->max_frame_size = 4096; in add_device()
3446 else if (info->max_frame_size > 65535) in add_device()
3447 info->max_frame_size = 65535; in add_device()
3449 switch(info->pdev->device) { in add_device()
3461 info->params.mode = MGSL_MODE_ASYNC; in add_device()
3467 devstr, info->device_name, info->phys_reg_addr, in add_device()
3468 info->irq_level, info->max_frame_size); in add_device()
3471 hdlcdev_init(info); in add_device()
3485 struct slgt_info *info; in alloc_dev() local
3487 info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL); in alloc_dev()
3489 if (!info) { in alloc_dev()
3493 tty_port_init(&info->port); in alloc_dev()
3494 info->port.ops = &slgt_port_ops; in alloc_dev()
3495 INIT_WORK(&info->task, bh_handler); in alloc_dev()
3496 info->max_frame_size = 4096; in alloc_dev()
3497 info->base_clock = 14745600; in alloc_dev()
3498 info->rbuf_fill_level = DMABUFSIZE; in alloc_dev()
3499 init_waitqueue_head(&info->status_event_wait_q); in alloc_dev()
3500 init_waitqueue_head(&info->event_wait_q); in alloc_dev()
3501 spin_lock_init(&info->netlock); in alloc_dev()
3502 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); in alloc_dev()
3503 info->idle_mode = HDLC_TXIDLE_FLAGS; in alloc_dev()
3504 info->adapter_num = adapter_num; in alloc_dev()
3505 info->port_num = port_num; in alloc_dev()
3507 timer_setup(&info->tx_timer, tx_timeout, 0); in alloc_dev()
3508 timer_setup(&info->rx_timer, rx_timeout, 0); in alloc_dev()
3511 info->pdev = pdev; in alloc_dev()
3512 info->irq_level = pdev->irq; in alloc_dev()
3513 info->phys_reg_addr = pci_resource_start(pdev,0); in alloc_dev()
3515 info->bus_type = MGSL_BUS_TYPE_PCI; in alloc_dev()
3516 info->irq_flags = IRQF_SHARED; in alloc_dev()
3518 info->init_error = -1; /* assume error, set to 0 on successful init */ in alloc_dev()
3521 return info; in alloc_dev()
3586 struct slgt_info *info = port_array[i]; in device_init() local
3587 tty_port_register_device(&info->port, serial_driver, info->line, in device_init()
3588 &info->pdev->dev); in device_init()
3636 struct slgt_info *info; in slgt_cleanup() local
3642 for (info=slgt_device_list ; info != NULL ; info=info->next_device) in slgt_cleanup()
3643 tty_unregister_device(serial_driver, info->line); in slgt_cleanup()
3649 info = slgt_device_list; in slgt_cleanup()
3650 while(info) { in slgt_cleanup()
3651 reset_port(info); in slgt_cleanup()
3652 info = info->next_device; in slgt_cleanup()
3656 info = slgt_device_list; in slgt_cleanup()
3657 while(info) { in slgt_cleanup()
3659 hdlcdev_exit(info); in slgt_cleanup()
3661 free_dma_bufs(info); in slgt_cleanup()
3662 free_tmp_rbuf(info); in slgt_cleanup()
3663 if (info->port_num == 0) in slgt_cleanup()
3664 release_resources(info); in slgt_cleanup()
3665 tmp = info; in slgt_cleanup()
3666 info = info->next_device; in slgt_cleanup()
3745 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3747 reg_addr += (info->port_num) * 32; \
3749 reg_addr += (info->port_num) * 16;
3751 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) in rd_reg8() argument
3757 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value) in wr_reg8() argument
3763 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr) in rd_reg16() argument
3769 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value) in wr_reg16() argument
3775 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr) in rd_reg32() argument
3781 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value) in wr_reg32() argument
3787 static void rdma_reset(struct slgt_info *info) in rdma_reset() argument
3792 wr_reg32(info, RDCSR, BIT1); in rdma_reset()
3796 if (!(rd_reg32(info, RDCSR) & BIT0)) in rdma_reset()
3800 static void tdma_reset(struct slgt_info *info) in tdma_reset() argument
3805 wr_reg32(info, TDCSR, BIT1); in tdma_reset()
3809 if (!(rd_reg32(info, TDCSR) & BIT0)) in tdma_reset()
3818 static void enable_loopback(struct slgt_info *info) in enable_loopback() argument
3821 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); in enable_loopback()
3823 if (info->params.mode != MGSL_MODE_ASYNC) { in enable_loopback()
3832 wr_reg8(info, CCR, 0x49); in enable_loopback()
3835 if (info->params.clock_speed) in enable_loopback()
3836 set_rate(info, info->params.clock_speed); in enable_loopback()
3838 set_rate(info, 3686400); in enable_loopback()
3845 static void set_rate(struct slgt_info *info, u32 rate) in set_rate() argument
3848 unsigned int osc = info->base_clock; in set_rate()
3860 wr_reg16(info, BDR, (unsigned short)div); in set_rate()
3864 static void rx_stop(struct slgt_info *info) in rx_stop() argument
3869 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_stop()
3870 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_stop()
3871 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_stop()
3873 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE); in rx_stop()
3876 wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER); in rx_stop()
3878 rdma_reset(info); in rx_stop()
3880 info->rx_enabled = false; in rx_stop()
3881 info->rx_restart = false; in rx_stop()
3884 static void rx_start(struct slgt_info *info) in rx_start() argument
3888 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA); in rx_start()
3891 wr_reg16(info, SSR, IRQ_RXOVER); in rx_start()
3894 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_start()
3895 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_start()
3896 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_start()
3898 rdma_reset(info); in rx_start()
3899 reset_rbufs(info); in rx_start()
3901 if (info->rx_pio) { in rx_start()
3903 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); in rx_start()
3904 slgt_irq_on(info, IRQ_RXDATA); in rx_start()
3905 if (info->params.mode == MGSL_MODE_ASYNC) { in rx_start()
3907 wr_reg32(info, RDCSR, BIT6); in rx_start()
3911 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); in rx_start()
3913 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); in rx_start()
3915 if (info->params.mode != MGSL_MODE_ASYNC) { in rx_start()
3917 wr_reg32(info, RDCSR, (BIT2 + BIT0)); in rx_start()
3920 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); in rx_start()
3924 slgt_irq_on(info, IRQ_RXOVER); in rx_start()
3927 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); in rx_start()
3929 info->rx_restart = false; in rx_start()
3930 info->rx_enabled = true; in rx_start()
3933 static void tx_start(struct slgt_info *info) in tx_start() argument
3935 if (!info->tx_enabled) { in tx_start()
3936 wr_reg16(info, TCR, in tx_start()
3937 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); in tx_start()
3938 info->tx_enabled = true; in tx_start()
3941 if (desc_count(info->tbufs[info->tbuf_start])) { in tx_start()
3942 info->drop_rts_on_tx_done = false; in tx_start()
3944 if (info->params.mode != MGSL_MODE_ASYNC) { in tx_start()
3945 if (info->params.flags & HDLC_FLAG_AUTO_RTS) { in tx_start()
3946 get_gtsignals(info); in tx_start()
3947 if (!(info->signals & SerialSignal_RTS)) { in tx_start()
3948 info->signals |= SerialSignal_RTS; in tx_start()
3949 set_gtsignals(info); in tx_start()
3950 info->drop_rts_on_tx_done = true; in tx_start()
3954 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3955 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); in tx_start()
3957 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_start()
3959 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
3960 slgt_irq_on(info, IRQ_TXIDLE); in tx_start()
3962 wr_reg16(info, SSR, IRQ_TXIDLE); in tx_start()
3965 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); in tx_start()
3966 wr_reg32(info, TDCSR, BIT2 + BIT0); in tx_start()
3967 info->tx_active = true; in tx_start()
3971 static void tx_stop(struct slgt_info *info) in tx_stop() argument
3975 del_timer(&info->tx_timer); in tx_stop()
3977 tdma_reset(info); in tx_stop()
3980 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ in tx_stop()
3981 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in tx_stop()
3983 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in tx_stop()
3986 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_stop()
3988 reset_tbufs(info); in tx_stop()
3990 info->tx_enabled = false; in tx_stop()
3991 info->tx_active = false; in tx_stop()
3994 static void reset_port(struct slgt_info *info) in reset_port() argument
3996 if (!info->reg_addr) in reset_port()
3999 tx_stop(info); in reset_port()
4000 rx_stop(info); in reset_port()
4002 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in reset_port()
4003 set_gtsignals(info); in reset_port()
4005 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in reset_port()
4008 static void reset_adapter(struct slgt_info *info) in reset_adapter() argument
4011 for (i=0; i < info->port_count; ++i) { in reset_adapter()
4012 if (info->port_array[i]) in reset_adapter()
4013 reset_port(info->port_array[i]); in reset_adapter()
4017 static void async_mode(struct slgt_info *info) in async_mode() argument
4021 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in async_mode()
4022 tx_stop(info); in async_mode()
4023 rx_stop(info); in async_mode()
4045 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in async_mode()
4048 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4050 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4054 switch (info->params.data_bits) in async_mode()
4061 if (info->params.stop_bits != 1) in async_mode()
4064 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in async_mode()
4067 wr_reg16(info, TCR, val); in async_mode()
4088 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4090 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4094 switch (info->params.data_bits) in async_mode()
4101 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in async_mode()
4104 wr_reg16(info, RCR, val); in async_mode()
4115 wr_reg8(info, CCR, 0x69); in async_mode()
4117 msc_set_vcr(info); in async_mode()
4140 if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate && in async_mode()
4141 ((info->base_clock < (info->params.data_rate * 16)) || in async_mode()
4142 (info->base_clock % (info->params.data_rate * 16)))) { in async_mode()
4145 set_rate(info, info->params.data_rate * 8); in async_mode()
4148 set_rate(info, info->params.data_rate * 16); in async_mode()
4150 wr_reg16(info, SCR, val); in async_mode()
4152 slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER); in async_mode()
4154 if (info->params.loopback) in async_mode()
4155 enable_loopback(info); in async_mode()
4158 static void sync_mode(struct slgt_info *info) in sync_mode() argument
4162 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in sync_mode()
4163 tx_stop(info); in sync_mode()
4164 rx_stop(info); in sync_mode()
4188 switch(info->params.mode) { in sync_mode()
4196 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in sync_mode()
4199 switch(info->params.encoding) in sync_mode()
4210 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4216 if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE) in sync_mode()
4219 switch (info->params.preamble_length) in sync_mode()
4226 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in sync_mode()
4229 wr_reg16(info, TCR, val); in sync_mode()
4233 switch (info->params.preamble) in sync_mode()
4242 wr_reg8(info, TPR, (unsigned char)val); in sync_mode()
4263 switch(info->params.mode) { in sync_mode()
4272 switch(info->params.encoding) in sync_mode()
4283 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4289 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in sync_mode()
4292 wr_reg16(info, RCR, val); in sync_mode()
4303 if (info->params.flags & HDLC_FLAG_TXC_BRG) in sync_mode()
4308 if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4313 else if (info->params.flags & HDLC_FLAG_TXC_DPLL) in sync_mode()
4315 else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN) in sync_mode()
4318 if (info->params.flags & HDLC_FLAG_RXC_BRG) in sync_mode()
4320 else if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4322 else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN) in sync_mode()
4325 if (info->params.clock_speed) in sync_mode()
4328 wr_reg8(info, CCR, (unsigned char)val); in sync_mode()
4330 if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL)) in sync_mode()
4333 switch(info->params.encoding) in sync_mode()
4343 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val)); in sync_mode()
4346 set_rate(info, info->params.clock_speed * 16); in sync_mode()
4349 set_rate(info, info->params.clock_speed); in sync_mode()
4351 tx_set_idle(info); in sync_mode()
4353 msc_set_vcr(info); in sync_mode()
4374 wr_reg16(info, SCR, BIT15 + BIT14 + BIT0); in sync_mode()
4376 if (info->params.loopback) in sync_mode()
4377 enable_loopback(info); in sync_mode()
4383 static void tx_set_idle(struct slgt_info *info) in tx_set_idle() argument
4391 tcr = rd_reg16(info, TCR); in tx_set_idle()
4392 if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) { in tx_set_idle()
4396 wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff)); in tx_set_idle()
4401 wr_reg16(info, TCR, tcr); in tx_set_idle()
4403 if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) { in tx_set_idle()
4405 val = (unsigned char)(info->idle_mode & 0xff); in tx_set_idle()
4408 switch(info->idle_mode) in tx_set_idle()
4419 wr_reg8(info, TIR, val); in tx_set_idle()
4425 static void get_gtsignals(struct slgt_info *info) in get_gtsignals() argument
4427 unsigned short status = rd_reg16(info, SSR); in get_gtsignals()
4430 info->signals &= SerialSignal_RTS | SerialSignal_DTR; in get_gtsignals()
4433 info->signals |= SerialSignal_DSR; in get_gtsignals()
4435 info->signals |= SerialSignal_CTS; in get_gtsignals()
4437 info->signals |= SerialSignal_DCD; in get_gtsignals()
4439 info->signals |= SerialSignal_RI; in get_gtsignals()
4445 static void msc_set_vcr(struct slgt_info *info) in msc_set_vcr() argument
4458 switch(info->if_mode & MGSL_INTERFACE_MASK) in msc_set_vcr()
4471 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST) in msc_set_vcr()
4473 if (info->signals & SerialSignal_DTR) in msc_set_vcr()
4475 if (info->signals & SerialSignal_RTS) in msc_set_vcr()
4477 if (info->if_mode & MGSL_INTERFACE_LL) in msc_set_vcr()
4479 if (info->if_mode & MGSL_INTERFACE_RL) in msc_set_vcr()
4481 wr_reg8(info, VCR, val); in msc_set_vcr()
4487 static void set_gtsignals(struct slgt_info *info) in set_gtsignals() argument
4489 unsigned char val = rd_reg8(info, VCR); in set_gtsignals()
4490 if (info->signals & SerialSignal_DTR) in set_gtsignals()
4494 if (info->signals & SerialSignal_RTS) in set_gtsignals()
4498 wr_reg8(info, VCR, val); in set_gtsignals()
4504 static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last) in free_rbufs() argument
4510 info->rbufs[i].status = 0; in free_rbufs()
4511 set_desc_count(info->rbufs[i], info->rbuf_fill_level); in free_rbufs()
4514 if (++i == info->rbuf_count) in free_rbufs()
4517 info->rbuf_current = i; in free_rbufs()
4523 static void reset_rbufs(struct slgt_info *info) in reset_rbufs() argument
4525 free_rbufs(info, 0, info->rbuf_count - 1); in reset_rbufs()
4526 info->rbuf_fill_index = 0; in reset_rbufs()
4527 info->rbuf_fill_count = 0; in reset_rbufs()
4535 static bool rx_get_frame(struct slgt_info *info) in rx_get_frame() argument
4541 struct tty_struct *tty = info->port.tty; in rx_get_frame()
4545 switch (info->params.crc_type & HDLC_CRC_MASK) { in rx_get_frame()
4554 start = end = info->rbuf_current; in rx_get_frame()
4557 if (!desc_complete(info->rbufs[end])) in rx_get_frame()
4560 if (framesize == 0 && info->params.addr_filter != 0xff) in rx_get_frame()
4561 addr_field = info->rbufs[end].buf[0]; in rx_get_frame()
4563 framesize += desc_count(info->rbufs[end]); in rx_get_frame()
4565 if (desc_eof(info->rbufs[end])) in rx_get_frame()
4568 if (++end == info->rbuf_count) in rx_get_frame()
4571 if (end == info->rbuf_current) { in rx_get_frame()
4572 if (info->rx_enabled){ in rx_get_frame()
4573 spin_lock_irqsave(&info->lock,flags); in rx_get_frame()
4574 rx_start(info); in rx_get_frame()
4575 spin_unlock_irqrestore(&info->lock,flags); in rx_get_frame()
4590 status = desc_status(info->rbufs[end]); in rx_get_frame()
4593 if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE) in rx_get_frame()
4597 (addr_field != 0xff && addr_field != info->params.addr_filter)) { in rx_get_frame()
4598 free_rbufs(info, start, end); in rx_get_frame()
4603 info->icount.rxshort++; in rx_get_frame()
4606 info->icount.rxcrc++; in rx_get_frame()
4607 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) in rx_get_frame()
4613 info->netdev->stats.rx_errors++; in rx_get_frame()
4614 info->netdev->stats.rx_frame_errors++; in rx_get_frame()
4619 info->device_name, status, framesize)); in rx_get_frame()
4620 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx"); in rx_get_frame()
4623 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { in rx_get_frame()
4628 if (framesize > info->max_frame_size + crc_size) in rx_get_frame()
4629 info->icount.rxlong++; in rx_get_frame()
4634 unsigned char *p = info->tmp_rbuf; in rx_get_frame()
4635 info->tmp_rbuf_count = framesize; in rx_get_frame()
4637 info->icount.rxok++; in rx_get_frame()
4640 int partial_count = min_t(int, copy_count, info->rbuf_fill_level); in rx_get_frame()
4641 memcpy(p, info->rbufs[i].buf, partial_count); in rx_get_frame()
4644 if (++i == info->rbuf_count) in rx_get_frame()
4648 if (info->params.crc_type & HDLC_CRC_RETURN_EX) { in rx_get_frame()
4654 if (info->netcount) in rx_get_frame()
4655 hdlcdev_rx(info,info->tmp_rbuf, framesize); in rx_get_frame()
4658 ldisc_receive_buf(tty, info->tmp_rbuf, info->flag_buf, framesize); in rx_get_frame()
4661 free_rbufs(info, start, end); in rx_get_frame()
4672 static bool rx_get_buf(struct slgt_info *info) in rx_get_buf() argument
4674 unsigned int i = info->rbuf_current; in rx_get_buf()
4677 if (!desc_complete(info->rbufs[i])) in rx_get_buf()
4679 count = desc_count(info->rbufs[i]); in rx_get_buf()
4680 switch(info->params.mode) { in rx_get_buf()
4685 if (desc_residue(info->rbufs[i])) in rx_get_buf()
4689 DBGDATA(info, info->rbufs[i].buf, count, "rx"); in rx_get_buf()
4692 ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, in rx_get_buf()
4693 info->flag_buf, count); in rx_get_buf()
4694 free_rbufs(info, i, i); in rx_get_buf()
4698 static void reset_tbufs(struct slgt_info *info) in reset_tbufs() argument
4701 info->tbuf_current = 0; in reset_tbufs()
4702 for (i=0 ; i < info->tbuf_count ; i++) { in reset_tbufs()
4703 info->tbufs[i].status = 0; in reset_tbufs()
4704 info->tbufs[i].count = 0; in reset_tbufs()
4711 static unsigned int free_tbuf_count(struct slgt_info *info) in free_tbuf_count() argument
4714 unsigned int i = info->tbuf_current; in free_tbuf_count()
4718 if (desc_count(info->tbufs[i])) in free_tbuf_count()
4721 if (++i == info->tbuf_count) in free_tbuf_count()
4723 } while (i != info->tbuf_current); in free_tbuf_count()
4726 if (count && (rd_reg32(info, TDCSR) & BIT0)) in free_tbuf_count()
4736 static unsigned int tbuf_bytes(struct slgt_info *info) in tbuf_bytes() argument
4739 unsigned int i = info->tbuf_current; in tbuf_bytes()
4756 count = desc_count(info->tbufs[i]); in tbuf_bytes()
4760 active_buf_count = info->tbufs[i].buf_count; in tbuf_bytes()
4761 if (++i == info->tbuf_count) in tbuf_bytes()
4763 } while (i != info->tbuf_current); in tbuf_bytes()
4766 reg_value = rd_reg32(info, TDCSR); in tbuf_bytes()
4776 if (info->tx_active) in tbuf_bytes()
4786 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) in tx_load() argument
4793 if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) in tx_load()
4796 DBGDATA(info, buf, size, "tx"); in tx_load()
4809 info->tbuf_start = i = info->tbuf_current; in tx_load()
4812 d = &info->tbufs[i]; in tx_load()
4824 if ((!size && info->params.mode == MGSL_MODE_HDLC) || in tx_load()
4825 info->params.mode == MGSL_MODE_RAW) in tx_load()
4831 if (i != info->tbuf_start) in tx_load()
4835 if (++i == info->tbuf_count) in tx_load()
4839 info->tbuf_current = i; in tx_load()
4842 d = &info->tbufs[info->tbuf_start]; in tx_load()
4846 if (!info->tx_active) in tx_load()
4847 tx_start(info); in tx_load()
4848 update_tx_timer(info); in tx_load()
4853 static int register_test(struct slgt_info *info) in register_test() argument
4862 wr_reg16(info, TIR, patterns[i]); in register_test()
4863 wr_reg16(info, BDR, patterns[(i+1)%count]); in register_test()
4864 if ((rd_reg16(info, TIR) != patterns[i]) || in register_test()
4865 (rd_reg16(info, BDR) != patterns[(i+1)%count])) { in register_test()
4870 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0; in register_test()
4871 info->init_error = rc ? 0 : DiagStatus_AddressFailure; in register_test()
4875 static int irq_test(struct slgt_info *info) in irq_test() argument
4879 struct tty_struct *oldtty = info->port.tty; in irq_test()
4880 u32 speed = info->params.data_rate; in irq_test()
4882 info->params.data_rate = 921600; in irq_test()
4883 info->port.tty = NULL; in irq_test()
4885 spin_lock_irqsave(&info->lock, flags); in irq_test()
4886 async_mode(info); in irq_test()
4887 slgt_irq_on(info, IRQ_TXIDLE); in irq_test()
4890 wr_reg16(info, TCR, in irq_test()
4891 (unsigned short)(rd_reg16(info, TCR) | BIT1)); in irq_test()
4894 wr_reg16(info, TDR, 0); in irq_test()
4897 info->init_error = DiagStatus_IrqFailure; in irq_test()
4898 info->irq_occurred = false; in irq_test()
4900 spin_unlock_irqrestore(&info->lock, flags); in irq_test()
4903 while(timeout-- && !info->irq_occurred) in irq_test()
4906 spin_lock_irqsave(&info->lock,flags); in irq_test()
4907 reset_port(info); in irq_test()
4908 spin_unlock_irqrestore(&info->lock,flags); in irq_test()
4910 info->params.data_rate = speed; in irq_test()
4911 info->port.tty = oldtty; in irq_test()
4913 info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure; in irq_test()
4914 return info->irq_occurred ? 0 : -ENODEV; in irq_test()
4917 static int loopback_test_rx(struct slgt_info *info) in loopback_test_rx() argument
4922 if (desc_complete(info->rbufs[0])) { in loopback_test_rx()
4923 count = desc_count(info->rbufs[0]); in loopback_test_rx()
4924 src = info->rbufs[0].buf; in loopback_test_rx()
4925 dest = info->tmp_rbuf; in loopback_test_rx()
4932 info->tmp_rbuf_count++; in loopback_test_rx()
4935 DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx"); in loopback_test_rx()
4941 static int loopback_test(struct slgt_info *info) in loopback_test() argument
4951 struct tty_struct *oldtty = info->port.tty; in loopback_test()
4954 memcpy(¶ms, &info->params, sizeof(params)); in loopback_test()
4956 info->params.mode = MGSL_MODE_ASYNC; in loopback_test()
4957 info->params.data_rate = 921600; in loopback_test()
4958 info->params.loopback = 1; in loopback_test()
4959 info->port.tty = NULL; in loopback_test()
4965 info->tmp_rbuf_count = 0; in loopback_test()
4966 memset(info->tmp_rbuf, 0, TESTFRAMESIZE); in loopback_test()
4969 spin_lock_irqsave(&info->lock,flags); in loopback_test()
4970 async_mode(info); in loopback_test()
4971 rx_start(info); in loopback_test()
4972 tx_load(info, buf, count); in loopback_test()
4973 spin_unlock_irqrestore(&info->lock, flags); in loopback_test()
4978 if (loopback_test_rx(info)) { in loopback_test()
4985 if (!rc && (info->tmp_rbuf_count != count || in loopback_test()
4986 memcmp(buf, info->tmp_rbuf, count))) { in loopback_test()
4990 spin_lock_irqsave(&info->lock,flags); in loopback_test()
4991 reset_adapter(info); in loopback_test()
4992 spin_unlock_irqrestore(&info->lock,flags); in loopback_test()
4994 memcpy(&info->params, ¶ms, sizeof(info->params)); in loopback_test()
4995 info->port.tty = oldtty; in loopback_test()
4997 info->init_error = rc ? DiagStatus_DmaFailure : 0; in loopback_test()
5001 static int adapter_test(struct slgt_info *info) in adapter_test() argument
5003 DBGINFO(("testing %s\n", info->device_name)); in adapter_test()
5004 if (register_test(info) < 0) { in adapter_test()
5006 info->device_name, info->phys_reg_addr); in adapter_test()
5007 } else if (irq_test(info) < 0) { in adapter_test()
5009 info->device_name, info->irq_level); in adapter_test()
5010 } else if (loopback_test(info) < 0) { in adapter_test()
5011 printk("loopback test failure %s\n", info->device_name); in adapter_test()
5013 return info->init_error; in adapter_test()
5021 struct slgt_info *info = from_timer(info, t, tx_timer); in tx_timeout() local
5024 DBGINFO(("%s tx_timeout\n", info->device_name)); in tx_timeout()
5025 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) { in tx_timeout()
5026 info->icount.txtimeout++; in tx_timeout()
5028 spin_lock_irqsave(&info->lock,flags); in tx_timeout()
5029 tx_stop(info); in tx_timeout()
5030 spin_unlock_irqrestore(&info->lock,flags); in tx_timeout()
5033 if (info->netcount) in tx_timeout()
5034 hdlcdev_tx_done(info); in tx_timeout()
5037 bh_transmit(info); in tx_timeout()
5045 struct slgt_info *info = from_timer(info, t, rx_timer); in rx_timeout() local
5048 DBGINFO(("%s rx_timeout\n", info->device_name)); in rx_timeout()
5049 spin_lock_irqsave(&info->lock, flags); in rx_timeout()
5050 info->pending_bh |= BH_RECEIVE; in rx_timeout()
5051 spin_unlock_irqrestore(&info->lock, flags); in rx_timeout()
5052 bh_handler(&info->task); in rx_timeout()