Lines Matching full:info

41 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (b…  argument
42 /*#define DBGTBUF(info) dump_tbufs(info)*/
43 /*#define DBGRBUF(info) dump_rbufs(info)*/
166 static void hdlcdev_tx_done(struct slgt_info *info);
167 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size);
168 static int hdlcdev_init(struct slgt_info *info);
169 static void hdlcdev_exit(struct slgt_info *info);
426 #define slgt_irq_on(info, mask) \ argument
427 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
428 #define slgt_irq_off(info, mask) \ argument
429 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
431 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
432 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
433 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
434 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
435 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
436 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
438 static void msc_set_vcr(struct slgt_info *info);
440 static int startup(struct slgt_info *info);
441 static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
442 static void shutdown(struct slgt_info *info);
443 static void program_hw(struct slgt_info *info);
444 static void change_params(struct slgt_info *info);
446 static int register_test(struct slgt_info *info);
447 static int irq_test(struct slgt_info *info);
448 static int loopback_test(struct slgt_info *info);
449 static int adapter_test(struct slgt_info *info);
451 static void reset_adapter(struct slgt_info *info);
452 static void reset_port(struct slgt_info *info);
453 static void async_mode(struct slgt_info *info);
454 static void sync_mode(struct slgt_info *info);
456 static void rx_stop(struct slgt_info *info);
457 static void rx_start(struct slgt_info *info);
458 static void reset_rbufs(struct slgt_info *info);
459 static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
460 static void rdma_reset(struct slgt_info *info);
461 static bool rx_get_frame(struct slgt_info *info);
462 static bool rx_get_buf(struct slgt_info *info);
464 static void tx_start(struct slgt_info *info);
465 static void tx_stop(struct slgt_info *info);
466 static void tx_set_idle(struct slgt_info *info);
467 static unsigned int free_tbuf_count(struct slgt_info *info);
468 static unsigned int tbuf_bytes(struct slgt_info *info);
469 static void reset_tbufs(struct slgt_info *info);
470 static void tdma_reset(struct slgt_info *info);
471 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
473 static void get_signals(struct slgt_info *info);
474 static void set_signals(struct slgt_info *info);
475 static void enable_loopback(struct slgt_info *info);
476 static void set_rate(struct slgt_info *info, u32 data_rate);
478 static int bh_action(struct slgt_info *info);
480 static void bh_transmit(struct slgt_info *info);
481 static void isr_serial(struct slgt_info *info);
482 static void isr_rdma(struct slgt_info *info);
483 static void isr_txeom(struct slgt_info *info, unsigned short status);
484 static void isr_tdma(struct slgt_info *info);
486 static int alloc_dma_bufs(struct slgt_info *info);
487 static void free_dma_bufs(struct slgt_info *info);
488 static int alloc_desc(struct slgt_info *info);
489 static void free_desc(struct slgt_info *info);
490 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count);
491 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count);
493 static int alloc_tmp_rbuf(struct slgt_info *info);
494 static void free_tmp_rbuf(struct slgt_info *info);
502 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
503 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
504 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
505 static int get_txidle(struct slgt_info *info, int __user *idle_mode);
506 static int set_txidle(struct slgt_info *info, int idle_mode);
507 static int tx_enable(struct slgt_info *info, int enable);
508 static int tx_abort(struct slgt_info *info);
509 static int rx_enable(struct slgt_info *info, int enable);
510 static int modem_input_wait(struct slgt_info *info,int arg);
511 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
516 static int get_interface(struct slgt_info *info, int __user *if_mode);
517 static int set_interface(struct slgt_info *info, int if_mode);
518 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
519 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
520 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
521 static int get_xsync(struct slgt_info *info, int __user *if_mode);
522 static int set_xsync(struct slgt_info *info, int if_mode);
523 static int get_xctrl(struct slgt_info *info, int __user *if_mode);
524 static int set_xctrl(struct slgt_info *info, int if_mode);
529 static void add_device(struct slgt_info *info);
531 static int claim_resources(struct slgt_info *info);
532 static void release_resources(struct slgt_info *info);
551 static void trace_block(struct slgt_info *info, const char *data, int count, const char *label) in trace_block() argument
555 printk("%s %s data:\n",info->device_name, label); in trace_block()
574 #define DBGDATA(info, buf, size, label) argument
578 static void dump_tbufs(struct slgt_info *info) in dump_tbufs() argument
581 printk("tbuf_current=%d\n", info->tbuf_current); in dump_tbufs()
582 for (i=0 ; i < info->tbuf_count ; i++) { in dump_tbufs()
584 i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status)); in dump_tbufs()
588 #define DBGTBUF(info) argument
592 static void dump_rbufs(struct slgt_info *info) in dump_rbufs() argument
595 printk("rbuf_current=%d\n", info->rbuf_current); in dump_rbufs()
596 for (i=0 ; i < info->rbuf_count ; i++) { in dump_rbufs()
598 i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status)); in dump_rbufs()
602 #define DBGRBUF(info) argument
605 static inline int sanity_check(struct slgt_info *info, char *devname, const char *name) in sanity_check() argument
608 if (!info) { in sanity_check()
612 if (info->magic != MGSL_MAGIC) { in sanity_check()
617 if (!info) in sanity_check()
649 struct slgt_info *info; in open() local
659 info = slgt_device_list; in open()
660 while(info && info->line != line) in open()
661 info = info->next_device; in open()
662 if (sanity_check(info, tty->name, "open")) in open()
664 if (info->init_error) { in open()
665 DBGERR(("%s init error=%d\n", info->device_name, info->init_error)); in open()
669 tty->driver_data = info; in open()
670 info->port.tty = tty; in open()
672 DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count)); in open()
674 mutex_lock(&info->port.mutex); in open()
675 info->port.low_latency = (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; in open()
677 spin_lock_irqsave(&info->netlock, flags); in open()
678 if (info->netcount) { in open()
680 spin_unlock_irqrestore(&info->netlock, flags); in open()
681 mutex_unlock(&info->port.mutex); in open()
684 info->port.count++; in open()
685 spin_unlock_irqrestore(&info->netlock, flags); in open()
687 if (info->port.count == 1) { in open()
689 retval = startup(info); in open()
691 mutex_unlock(&info->port.mutex); in open()
695 mutex_unlock(&info->port.mutex); in open()
696 retval = block_til_ready(tty, filp, info); in open()
698 DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval)); in open()
707 info->port.tty = NULL; /* tty layer will release tty struct */ in open()
708 if(info->port.count) in open()
709 info->port.count--; in open()
712 DBGINFO(("%s open rc=%d\n", info->device_name, retval)); in open()
718 struct slgt_info *info = tty->driver_data; in close() local
720 if (sanity_check(info, tty->name, "close")) in close()
722 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); in close()
724 if (tty_port_close_start(&info->port, tty, filp) == 0) in close()
727 mutex_lock(&info->port.mutex); in close()
728 if (tty_port_initialized(&info->port)) in close()
729 wait_until_sent(tty, info->timeout); in close()
733 shutdown(info); in close()
734 mutex_unlock(&info->port.mutex); in close()
736 tty_port_close_end(&info->port, tty); in close()
737 info->port.tty = NULL; in close()
739 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); in close()
744 struct slgt_info *info = tty->driver_data; in hangup() local
747 if (sanity_check(info, tty->name, "hangup")) in hangup()
749 DBGINFO(("%s hangup\n", info->device_name)); in hangup()
753 mutex_lock(&info->port.mutex); in hangup()
754 shutdown(info); in hangup()
756 spin_lock_irqsave(&info->port.lock, flags); in hangup()
757 info->port.count = 0; in hangup()
758 info->port.tty = NULL; in hangup()
759 spin_unlock_irqrestore(&info->port.lock, flags); in hangup()
760 tty_port_set_active(&info->port, 0); in hangup()
761 mutex_unlock(&info->port.mutex); in hangup()
763 wake_up_interruptible(&info->port.open_wait); in hangup()
768 struct slgt_info *info = tty->driver_data; in set_termios() local
773 change_params(info); in set_termios()
777 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in set_termios()
778 spin_lock_irqsave(&info->lock,flags); in set_termios()
779 set_signals(info); in set_termios()
780 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
785 info->signals |= SerialSignal_DTR; in set_termios()
787 info->signals |= SerialSignal_RTS; in set_termios()
788 spin_lock_irqsave(&info->lock,flags); in set_termios()
789 set_signals(info); in set_termios()
790 spin_unlock_irqrestore(&info->lock,flags); in set_termios()
800 static void update_tx_timer(struct slgt_info *info) in update_tx_timer() argument
806 if (info->params.mode == MGSL_MODE_HDLC) { in update_tx_timer()
807 int timeout = (tbuf_bytes(info) * 7) + 1000; in update_tx_timer()
808 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout)); in update_tx_timer()
816 struct slgt_info *info = tty->driver_data; in write() local
819 if (sanity_check(info, tty->name, "write")) in write()
822 DBGINFO(("%s write count=%d\n", info->device_name, count)); in write()
824 if (!info->tx_buf || (count > info->max_frame_size)) in write()
830 spin_lock_irqsave(&info->lock, flags); in write()
832 if (info->tx_count) { in write()
834 if (!tx_load(info, info->tx_buf, info->tx_count)) in write()
836 info->tx_count = 0; in write()
839 if (tx_load(info, buf, count)) in write()
843 spin_unlock_irqrestore(&info->lock, flags); in write()
844 DBGINFO(("%s write rc=%d\n", info->device_name, ret)); in write()
850 struct slgt_info *info = tty->driver_data; in put_char() local
854 if (sanity_check(info, tty->name, "put_char")) in put_char()
856 DBGINFO(("%s put_char(%d)\n", info->device_name, ch)); in put_char()
857 if (!info->tx_buf) in put_char()
859 spin_lock_irqsave(&info->lock,flags); in put_char()
860 if (info->tx_count < info->max_frame_size) { in put_char()
861 info->tx_buf[info->tx_count++] = ch; in put_char()
864 spin_unlock_irqrestore(&info->lock,flags); in put_char()
870 struct slgt_info *info = tty->driver_data; in send_xchar() local
873 if (sanity_check(info, tty->name, "send_xchar")) in send_xchar()
875 DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch)); in send_xchar()
876 info->x_char = ch; in send_xchar()
878 spin_lock_irqsave(&info->lock,flags); in send_xchar()
879 if (!info->tx_enabled) in send_xchar()
880 tx_start(info); in send_xchar()
881 spin_unlock_irqrestore(&info->lock,flags); in send_xchar()
887 struct slgt_info *info = tty->driver_data; in wait_until_sent() local
890 if (!info ) in wait_until_sent()
892 if (sanity_check(info, tty->name, "wait_until_sent")) in wait_until_sent()
894 DBGINFO(("%s wait_until_sent entry\n", info->device_name)); in wait_until_sent()
895 if (!tty_port_initialized(&info->port)) in wait_until_sent()
906 if (info->params.data_rate) { in wait_until_sent()
907 char_time = info->timeout/(32 * 5); in wait_until_sent()
916 while (info->tx_active) { in wait_until_sent()
924 DBGINFO(("%s wait_until_sent exit\n", info->device_name)); in wait_until_sent()
929 struct slgt_info *info = tty->driver_data; in write_room() local
932 if (sanity_check(info, tty->name, "write_room")) in write_room()
934 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE; in write_room()
935 DBGINFO(("%s write_room=%d\n", info->device_name, ret)); in write_room()
941 struct slgt_info *info = tty->driver_data; in flush_chars() local
944 if (sanity_check(info, tty->name, "flush_chars")) in flush_chars()
946 DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count)); in flush_chars()
948 if (info->tx_count <= 0 || tty->stopped || in flush_chars()
949 tty->hw_stopped || !info->tx_buf) in flush_chars()
952 DBGINFO(("%s flush_chars start transmit\n", info->device_name)); in flush_chars()
954 spin_lock_irqsave(&info->lock,flags); in flush_chars()
955 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in flush_chars()
956 info->tx_count = 0; in flush_chars()
957 spin_unlock_irqrestore(&info->lock,flags); in flush_chars()
962 struct slgt_info *info = tty->driver_data; in flush_buffer() local
965 if (sanity_check(info, tty->name, "flush_buffer")) in flush_buffer()
967 DBGINFO(("%s flush_buffer\n", info->device_name)); in flush_buffer()
969 spin_lock_irqsave(&info->lock, flags); in flush_buffer()
970 info->tx_count = 0; in flush_buffer()
971 spin_unlock_irqrestore(&info->lock, flags); in flush_buffer()
981 struct slgt_info *info = tty->driver_data; in tx_hold() local
984 if (sanity_check(info, tty->name, "tx_hold")) in tx_hold()
986 DBGINFO(("%s tx_hold\n", info->device_name)); in tx_hold()
987 spin_lock_irqsave(&info->lock,flags); in tx_hold()
988 if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC) in tx_hold()
989 tx_stop(info); in tx_hold()
990 spin_unlock_irqrestore(&info->lock,flags); in tx_hold()
998 struct slgt_info *info = tty->driver_data; in tx_release() local
1001 if (sanity_check(info, tty->name, "tx_release")) in tx_release()
1003 DBGINFO(("%s tx_release\n", info->device_name)); in tx_release()
1004 spin_lock_irqsave(&info->lock, flags); in tx_release()
1005 if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count)) in tx_release()
1006 info->tx_count = 0; in tx_release()
1007 spin_unlock_irqrestore(&info->lock, flags); in tx_release()
1024 struct slgt_info *info = tty->driver_data; in ioctl() local
1028 if (sanity_check(info, tty->name, "ioctl")) in ioctl()
1030 DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd)); in ioctl()
1039 return wait_mgsl_event(info, argp); in ioctl()
1041 return modem_input_wait(info,(int)arg); in ioctl()
1043 return set_gpio(info, argp); in ioctl()
1045 return get_gpio(info, argp); in ioctl()
1047 return wait_gpio(info, argp); in ioctl()
1049 return get_xsync(info, argp); in ioctl()
1051 return set_xsync(info, (int)arg); in ioctl()
1053 return get_xctrl(info, argp); in ioctl()
1055 return set_xctrl(info, (int)arg); in ioctl()
1057 mutex_lock(&info->port.mutex); in ioctl()
1060 ret = get_params(info, argp); in ioctl()
1063 ret = set_params(info, argp); in ioctl()
1066 ret = get_txidle(info, argp); in ioctl()
1069 ret = set_txidle(info, (int)arg); in ioctl()
1072 ret = tx_enable(info, (int)arg); in ioctl()
1075 ret = rx_enable(info, (int)arg); in ioctl()
1078 ret = tx_abort(info); in ioctl()
1081 ret = get_stats(info, argp); in ioctl()
1084 ret = get_interface(info, argp); in ioctl()
1087 ret = set_interface(info,(int)arg); in ioctl()
1092 mutex_unlock(&info->port.mutex); in ioctl()
1100 struct slgt_info *info = tty->driver_data; in get_icount() local
1104 spin_lock_irqsave(&info->lock,flags); in get_icount()
1105 cnow = info->icount; in get_icount()
1106 spin_unlock_irqrestore(&info->lock,flags); in get_icount()
1127 static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params) in get_params32() argument
1131 DBGINFO(("%s get_params32\n", info->device_name)); in get_params32()
1133 tmp_params.mode = (compat_ulong_t)info->params.mode; in get_params32()
1134 tmp_params.loopback = info->params.loopback; in get_params32()
1135 tmp_params.flags = info->params.flags; in get_params32()
1136 tmp_params.encoding = info->params.encoding; in get_params32()
1137 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed; in get_params32()
1138 tmp_params.addr_filter = info->params.addr_filter; in get_params32()
1139 tmp_params.crc_type = info->params.crc_type; in get_params32()
1140 tmp_params.preamble_length = info->params.preamble_length; in get_params32()
1141 tmp_params.preamble = info->params.preamble; in get_params32()
1142 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate; in get_params32()
1143 tmp_params.data_bits = info->params.data_bits; in get_params32()
1144 tmp_params.stop_bits = info->params.stop_bits; in get_params32()
1145 tmp_params.parity = info->params.parity; in get_params32()
1151 static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params) in set_params32() argument
1155 DBGINFO(("%s set_params32\n", info->device_name)); in set_params32()
1159 spin_lock(&info->lock); in set_params32()
1161 info->base_clock = tmp_params.clock_speed; in set_params32()
1163 info->params.mode = tmp_params.mode; in set_params32()
1164 info->params.loopback = tmp_params.loopback; in set_params32()
1165 info->params.flags = tmp_params.flags; in set_params32()
1166 info->params.encoding = tmp_params.encoding; in set_params32()
1167 info->params.clock_speed = tmp_params.clock_speed; in set_params32()
1168 info->params.addr_filter = tmp_params.addr_filter; in set_params32()
1169 info->params.crc_type = tmp_params.crc_type; in set_params32()
1170 info->params.preamble_length = tmp_params.preamble_length; in set_params32()
1171 info->params.preamble = tmp_params.preamble; in set_params32()
1172 info->params.data_rate = tmp_params.data_rate; in set_params32()
1173 info->params.data_bits = tmp_params.data_bits; in set_params32()
1174 info->params.stop_bits = tmp_params.stop_bits; in set_params32()
1175 info->params.parity = tmp_params.parity; in set_params32()
1177 spin_unlock(&info->lock); in set_params32()
1179 program_hw(info); in set_params32()
1187 struct slgt_info *info = tty->driver_data; in slgt_compat_ioctl() local
1190 if (sanity_check(info, tty->name, "compat_ioctl")) in slgt_compat_ioctl()
1192 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd)); in slgt_compat_ioctl()
1196 rc = set_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1200 rc = get_params32(info, compat_ptr(arg)); in slgt_compat_ioctl()
1219 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc)); in slgt_compat_ioctl()
1229 static inline void line_info(struct seq_file *m, struct slgt_info *info) in line_info() argument
1235 info->device_name, info->phys_reg_addr, in line_info()
1236 info->irq_level, info->max_frame_size); in line_info()
1239 spin_lock_irqsave(&info->lock,flags); in line_info()
1240 get_signals(info); in line_info()
1241 spin_unlock_irqrestore(&info->lock,flags); in line_info()
1245 if (info->signals & SerialSignal_RTS) in line_info()
1247 if (info->signals & SerialSignal_CTS) in line_info()
1249 if (info->signals & SerialSignal_DTR) in line_info()
1251 if (info->signals & SerialSignal_DSR) in line_info()
1253 if (info->signals & SerialSignal_DCD) in line_info()
1255 if (info->signals & SerialSignal_RI) in line_info()
1258 if (info->params.mode != MGSL_MODE_ASYNC) { in line_info()
1260 info->icount.txok, info->icount.rxok); in line_info()
1261 if (info->icount.txunder) in line_info()
1262 seq_printf(m, " txunder:%d", info->icount.txunder); in line_info()
1263 if (info->icount.txabort) in line_info()
1264 seq_printf(m, " txabort:%d", info->icount.txabort); in line_info()
1265 if (info->icount.rxshort) in line_info()
1266 seq_printf(m, " rxshort:%d", info->icount.rxshort); in line_info()
1267 if (info->icount.rxlong) in line_info()
1268 seq_printf(m, " rxlong:%d", info->icount.rxlong); in line_info()
1269 if (info->icount.rxover) in line_info()
1270 seq_printf(m, " rxover:%d", info->icount.rxover); in line_info()
1271 if (info->icount.rxcrc) in line_info()
1272 seq_printf(m, " rxcrc:%d", info->icount.rxcrc); in line_info()
1275 info->icount.tx, info->icount.rx); in line_info()
1276 if (info->icount.frame) in line_info()
1277 seq_printf(m, " fe:%d", info->icount.frame); in line_info()
1278 if (info->icount.parity) in line_info()
1279 seq_printf(m, " pe:%d", info->icount.parity); in line_info()
1280 if (info->icount.brk) in line_info()
1281 seq_printf(m, " brk:%d", info->icount.brk); in line_info()
1282 if (info->icount.overrun) in line_info()
1283 seq_printf(m, " oe:%d", info->icount.overrun); in line_info()
1290 info->tx_active,info->bh_requested,info->bh_running, in line_info()
1291 info->pending_bh); in line_info()
1298 struct slgt_info *info; in synclink_gt_proc_show() local
1302 info = slgt_device_list; in synclink_gt_proc_show()
1303 while( info ) { in synclink_gt_proc_show()
1304 line_info(m, info); in synclink_gt_proc_show()
1305 info = info->next_device; in synclink_gt_proc_show()
1315 struct slgt_info *info = tty->driver_data; in chars_in_buffer() local
1317 if (sanity_check(info, tty->name, "chars_in_buffer")) in chars_in_buffer()
1319 count = tbuf_bytes(info); in chars_in_buffer()
1320 DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count)); in chars_in_buffer()
1329 struct slgt_info *info = tty->driver_data; in throttle() local
1332 if (sanity_check(info, tty->name, "throttle")) in throttle()
1334 DBGINFO(("%s throttle\n", info->device_name)); in throttle()
1338 spin_lock_irqsave(&info->lock,flags); in throttle()
1339 info->signals &= ~SerialSignal_RTS; in throttle()
1340 set_signals(info); in throttle()
1341 spin_unlock_irqrestore(&info->lock,flags); in throttle()
1350 struct slgt_info *info = tty->driver_data; in unthrottle() local
1353 if (sanity_check(info, tty->name, "unthrottle")) in unthrottle()
1355 DBGINFO(("%s unthrottle\n", info->device_name)); in unthrottle()
1357 if (info->x_char) in unthrottle()
1358 info->x_char = 0; in unthrottle()
1363 spin_lock_irqsave(&info->lock,flags); in unthrottle()
1364 info->signals |= SerialSignal_RTS; in unthrottle()
1365 set_signals(info); in unthrottle()
1366 spin_unlock_irqrestore(&info->lock,flags); in unthrottle()
1376 struct slgt_info *info = tty->driver_data; in set_break() local
1380 if (sanity_check(info, tty->name, "set_break")) in set_break()
1382 DBGINFO(("%s set_break(%d)\n", info->device_name, break_state)); in set_break()
1384 spin_lock_irqsave(&info->lock,flags); in set_break()
1385 value = rd_reg16(info, TCR); in set_break()
1390 wr_reg16(info, TCR, value); in set_break()
1391 spin_unlock_irqrestore(&info->lock,flags); in set_break()
1410 struct slgt_info *info = dev_to_port(dev); in hdlcdev_attach() local
1415 if (info->port.count) in hdlcdev_attach()
1418 DBGINFO(("%s hdlcdev_attach\n", info->device_name)); in hdlcdev_attach()
1438 info->params.encoding = new_encoding; in hdlcdev_attach()
1439 info->params.crc_type = new_crctype; in hdlcdev_attach()
1442 if (info->netcount) in hdlcdev_attach()
1443 program_hw(info); in hdlcdev_attach()
1456 struct slgt_info *info = dev_to_port(dev); in hdlcdev_xmit() local
1474 spin_lock_irqsave(&info->lock, flags); in hdlcdev_xmit()
1475 tx_load(info, skb->data, skb->len); in hdlcdev_xmit()
1476 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_xmit()
1494 struct slgt_info *info = dev_to_port(dev); in hdlcdev_open() local
1509 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1510 if (info->port.count != 0 || info->netcount != 0) { in hdlcdev_open()
1512 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1515 info->netcount=1; in hdlcdev_open()
1516 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1519 if ((rc = startup(info)) != 0) { in hdlcdev_open()
1520 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_open()
1521 info->netcount=0; in hdlcdev_open()
1522 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_open()
1527 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in hdlcdev_open()
1528 program_hw(info); in hdlcdev_open()
1535 spin_lock_irqsave(&info->lock, flags); in hdlcdev_open()
1536 get_signals(info); in hdlcdev_open()
1537 spin_unlock_irqrestore(&info->lock, flags); in hdlcdev_open()
1538 if (info->signals & SerialSignal_DCD) in hdlcdev_open()
1555 struct slgt_info *info = dev_to_port(dev); in hdlcdev_close() local
1563 shutdown(info); in hdlcdev_close()
1567 spin_lock_irqsave(&info->netlock, flags); in hdlcdev_close()
1568 info->netcount=0; in hdlcdev_close()
1569 spin_unlock_irqrestore(&info->netlock, flags); in hdlcdev_close()
1588 struct slgt_info *info = dev_to_port(dev); in hdlcdev_ioctl() local
1594 if (info->port.count) in hdlcdev_ioctl()
1611 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1624 new_line.clock_rate = info->params.clock_speed; in hdlcdev_ioctl()
1625 new_line.loopback = info->params.loopback ? 1:0; in hdlcdev_ioctl()
1644 case CLOCK_DEFAULT: flags = info->params.flags & in hdlcdev_ioctl()
1655 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL | in hdlcdev_ioctl()
1659 info->params.flags |= flags; in hdlcdev_ioctl()
1661 info->params.loopback = new_line.loopback; in hdlcdev_ioctl()
1664 info->params.clock_speed = new_line.clock_rate; in hdlcdev_ioctl()
1666 info->params.clock_speed = 0; in hdlcdev_ioctl()
1669 if (info->netcount) in hdlcdev_ioctl()
1670 program_hw(info); in hdlcdev_ioctl()
1684 struct slgt_info *info = dev_to_port(dev); in hdlcdev_tx_timeout() local
1692 spin_lock_irqsave(&info->lock,flags); in hdlcdev_tx_timeout()
1693 tx_stop(info); in hdlcdev_tx_timeout()
1694 spin_unlock_irqrestore(&info->lock,flags); in hdlcdev_tx_timeout()
1701 * @info: pointer to device instance information
1705 static void hdlcdev_tx_done(struct slgt_info *info) in hdlcdev_tx_done() argument
1707 if (netif_queue_stopped(info->netdev)) in hdlcdev_tx_done()
1708 netif_wake_queue(info->netdev); in hdlcdev_tx_done()
1713 * @info: pointer to device instance information
1719 static void hdlcdev_rx(struct slgt_info *info, char *buf, int size) in hdlcdev_rx() argument
1722 struct net_device *dev = info->netdev; in hdlcdev_rx()
1752 * @info: pointer to device instance information
1758 static int hdlcdev_init(struct slgt_info *info) in hdlcdev_init() argument
1766 dev = alloc_hdlcdev(info); in hdlcdev_init()
1768 printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name); in hdlcdev_init()
1773 dev->mem_start = info->phys_reg_addr; in hdlcdev_init()
1774 dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1; in hdlcdev_init()
1775 dev->irq = info->irq_level; in hdlcdev_init()
1795 info->netdev = dev; in hdlcdev_init()
1801 * @info: pointer to device instance information
1805 static void hdlcdev_exit(struct slgt_info *info) in hdlcdev_exit() argument
1807 unregister_hdlc_device(info->netdev); in hdlcdev_exit()
1808 free_netdev(info->netdev); in hdlcdev_exit()
1809 info->netdev = NULL; in hdlcdev_exit()
1817 static void rx_async(struct slgt_info *info) in rx_async() argument
1819 struct mgsl_icount *icount = &info->icount; in rx_async()
1823 struct slgt_desc *bufs = info->rbufs; in rx_async()
1829 start = end = info->rbuf_current; in rx_async()
1832 count = desc_count(bufs[end]) - info->rbuf_index; in rx_async()
1833 p = bufs[end].buf + info->rbuf_index; in rx_async()
1835 DBGISR(("%s rx_async count=%d\n", info->device_name, count)); in rx_async()
1836 DBGDATA(info, p, count, "rx"); in rx_async()
1851 if (status & info->ignore_status_mask) in rx_async()
1858 tty_insert_flip_char(&info->port, ch, stat); in rx_async()
1864 info->rbuf_index += i; in rx_async()
1865 mod_timer(&info->rx_timer, jiffies + 1); in rx_async()
1869 info->rbuf_index = 0; in rx_async()
1870 free_rbufs(info, end, end); in rx_async()
1872 if (++end == info->rbuf_count) in rx_async()
1881 tty_flip_buffer_push(&info->port); in rx_async()
1887 static int bh_action(struct slgt_info *info) in bh_action() argument
1892 spin_lock_irqsave(&info->lock,flags); in bh_action()
1894 if (info->pending_bh & BH_RECEIVE) { in bh_action()
1895 info->pending_bh &= ~BH_RECEIVE; in bh_action()
1897 } else if (info->pending_bh & BH_TRANSMIT) { in bh_action()
1898 info->pending_bh &= ~BH_TRANSMIT; in bh_action()
1900 } else if (info->pending_bh & BH_STATUS) { in bh_action()
1901 info->pending_bh &= ~BH_STATUS; in bh_action()
1905 info->bh_running = false; in bh_action()
1906 info->bh_requested = false; in bh_action()
1910 spin_unlock_irqrestore(&info->lock,flags); in bh_action()
1920 struct slgt_info *info = container_of(work, struct slgt_info, task); in bh_handler() local
1923 info->bh_running = true; in bh_handler()
1925 while((action = bh_action(info))) { in bh_handler()
1928 DBGBH(("%s bh receive\n", info->device_name)); in bh_handler()
1929 switch(info->params.mode) { in bh_handler()
1931 rx_async(info); in bh_handler()
1934 while(rx_get_frame(info)); in bh_handler()
1940 while(rx_get_buf(info)); in bh_handler()
1944 if (info->rx_restart) in bh_handler()
1945 rx_start(info); in bh_handler()
1948 bh_transmit(info); in bh_handler()
1951 DBGBH(("%s bh status\n", info->device_name)); in bh_handler()
1952 info->ri_chkcount = 0; in bh_handler()
1953 info->dsr_chkcount = 0; in bh_handler()
1954 info->dcd_chkcount = 0; in bh_handler()
1955 info->cts_chkcount = 0; in bh_handler()
1958 DBGBH(("%s unknown action\n", info->device_name)); in bh_handler()
1962 DBGBH(("%s bh_handler exit\n", info->device_name)); in bh_handler()
1965 static void bh_transmit(struct slgt_info *info) in bh_transmit() argument
1967 struct tty_struct *tty = info->port.tty; in bh_transmit()
1969 DBGBH(("%s bh_transmit\n", info->device_name)); in bh_transmit()
1974 static void dsr_change(struct slgt_info *info, unsigned short status) in dsr_change() argument
1977 info->signals |= SerialSignal_DSR; in dsr_change()
1978 info->input_signal_events.dsr_up++; in dsr_change()
1980 info->signals &= ~SerialSignal_DSR; in dsr_change()
1981 info->input_signal_events.dsr_down++; in dsr_change()
1983 DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); in dsr_change()
1984 if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dsr_change()
1985 slgt_irq_off(info, IRQ_DSR); in dsr_change()
1988 info->icount.dsr++; in dsr_change()
1989 wake_up_interruptible(&info->status_event_wait_q); in dsr_change()
1990 wake_up_interruptible(&info->event_wait_q); in dsr_change()
1991 info->pending_bh |= BH_STATUS; in dsr_change()
1994 static void cts_change(struct slgt_info *info, unsigned short status) in cts_change() argument
1997 info->signals |= SerialSignal_CTS; in cts_change()
1998 info->input_signal_events.cts_up++; in cts_change()
2000 info->signals &= ~SerialSignal_CTS; in cts_change()
2001 info->input_signal_events.cts_down++; in cts_change()
2003 DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); in cts_change()
2004 if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in cts_change()
2005 slgt_irq_off(info, IRQ_CTS); in cts_change()
2008 info->icount.cts++; in cts_change()
2009 wake_up_interruptible(&info->status_event_wait_q); in cts_change()
2010 wake_up_interruptible(&info->event_wait_q); in cts_change()
2011 info->pending_bh |= BH_STATUS; in cts_change()
2013 if (tty_port_cts_enabled(&info->port)) { in cts_change()
2014 if (info->port.tty) { in cts_change()
2015 if (info->port.tty->hw_stopped) { in cts_change()
2016 if (info->signals & SerialSignal_CTS) { in cts_change()
2017 info->port.tty->hw_stopped = 0; in cts_change()
2018 info->pending_bh |= BH_TRANSMIT; in cts_change()
2022 if (!(info->signals & SerialSignal_CTS)) in cts_change()
2023 info->port.tty->hw_stopped = 1; in cts_change()
2029 static void dcd_change(struct slgt_info *info, unsigned short status) in dcd_change() argument
2032 info->signals |= SerialSignal_DCD; in dcd_change()
2033 info->input_signal_events.dcd_up++; in dcd_change()
2035 info->signals &= ~SerialSignal_DCD; in dcd_change()
2036 info->input_signal_events.dcd_down++; in dcd_change()
2038 DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); in dcd_change()
2039 if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in dcd_change()
2040 slgt_irq_off(info, IRQ_DCD); in dcd_change()
2043 info->icount.dcd++; in dcd_change()
2045 if (info->netcount) { in dcd_change()
2046 if (info->signals & SerialSignal_DCD) in dcd_change()
2047 netif_carrier_on(info->netdev); in dcd_change()
2049 netif_carrier_off(info->netdev); in dcd_change()
2052 wake_up_interruptible(&info->status_event_wait_q); in dcd_change()
2053 wake_up_interruptible(&info->event_wait_q); in dcd_change()
2054 info->pending_bh |= BH_STATUS; in dcd_change()
2056 if (tty_port_check_carrier(&info->port)) { in dcd_change()
2057 if (info->signals & SerialSignal_DCD) in dcd_change()
2058 wake_up_interruptible(&info->port.open_wait); in dcd_change()
2060 if (info->port.tty) in dcd_change()
2061 tty_hangup(info->port.tty); in dcd_change()
2066 static void ri_change(struct slgt_info *info, unsigned short status) in ri_change() argument
2069 info->signals |= SerialSignal_RI; in ri_change()
2070 info->input_signal_events.ri_up++; in ri_change()
2072 info->signals &= ~SerialSignal_RI; in ri_change()
2073 info->input_signal_events.ri_down++; in ri_change()
2075 DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); in ri_change()
2076 if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { in ri_change()
2077 slgt_irq_off(info, IRQ_RI); in ri_change()
2080 info->icount.rng++; in ri_change()
2081 wake_up_interruptible(&info->status_event_wait_q); in ri_change()
2082 wake_up_interruptible(&info->event_wait_q); in ri_change()
2083 info->pending_bh |= BH_STATUS; in ri_change()
2086 static void isr_rxdata(struct slgt_info *info) in isr_rxdata() argument
2088 unsigned int count = info->rbuf_fill_count; in isr_rxdata()
2089 unsigned int i = info->rbuf_fill_index; in isr_rxdata()
2092 while (rd_reg16(info, SSR) & IRQ_RXDATA) { in isr_rxdata()
2093 reg = rd_reg16(info, RDR); in isr_rxdata()
2094 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg)); in isr_rxdata()
2095 if (desc_complete(info->rbufs[i])) { in isr_rxdata()
2097 rx_stop(info); in isr_rxdata()
2098 info->rx_restart = true; in isr_rxdata()
2101 info->rbufs[i].buf[count++] = (unsigned char)reg; in isr_rxdata()
2103 if (info->params.mode == MGSL_MODE_ASYNC) in isr_rxdata()
2104 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8); in isr_rxdata()
2105 if (count == info->rbuf_fill_level || (reg & BIT10)) { in isr_rxdata()
2107 set_desc_count(info->rbufs[i], count); in isr_rxdata()
2108 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8)); in isr_rxdata()
2109 info->rbuf_fill_count = count = 0; in isr_rxdata()
2110 if (++i == info->rbuf_count) in isr_rxdata()
2112 info->pending_bh |= BH_RECEIVE; in isr_rxdata()
2116 info->rbuf_fill_index = i; in isr_rxdata()
2117 info->rbuf_fill_count = count; in isr_rxdata()
2120 static void isr_serial(struct slgt_info *info) in isr_serial() argument
2122 unsigned short status = rd_reg16(info, SSR); in isr_serial()
2124 DBGISR(("%s isr_serial status=%04X\n", info->device_name, status)); in isr_serial()
2126 wr_reg16(info, SSR, status); /* clear pending */ in isr_serial()
2128 info->irq_occurred = true; in isr_serial()
2130 if (info->params.mode == MGSL_MODE_ASYNC) { in isr_serial()
2132 if (info->tx_active) in isr_serial()
2133 isr_txeom(info, status); in isr_serial()
2135 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2136 isr_rxdata(info); in isr_serial()
2138 info->icount.brk++; in isr_serial()
2140 if (info->port.tty) { in isr_serial()
2141 if (!(status & info->ignore_status_mask)) { in isr_serial()
2142 if (info->read_status_mask & MASK_BREAK) { in isr_serial()
2143 tty_insert_flip_char(&info->port, 0, TTY_BREAK); in isr_serial()
2144 if (info->port.flags & ASYNC_SAK) in isr_serial()
2145 do_SAK(info->port.tty); in isr_serial()
2152 isr_txeom(info, status); in isr_serial()
2153 if (info->rx_pio && (status & IRQ_RXDATA)) in isr_serial()
2154 isr_rxdata(info); in isr_serial()
2157 info->icount.rxidle++; in isr_serial()
2159 info->icount.exithunt++; in isr_serial()
2160 wake_up_interruptible(&info->event_wait_q); in isr_serial()
2164 rx_start(info); in isr_serial()
2168 dsr_change(info, status); in isr_serial()
2170 cts_change(info, status); in isr_serial()
2172 dcd_change(info, status); in isr_serial()
2174 ri_change(info, status); in isr_serial()
2177 static void isr_rdma(struct slgt_info *info) in isr_rdma() argument
2179 unsigned int status = rd_reg32(info, RDCSR); in isr_rdma()
2181 DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status)); in isr_rdma()
2194 wr_reg32(info, RDCSR, status); /* clear pending */ in isr_rdma()
2197 DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); in isr_rdma()
2198 info->rx_restart = true; in isr_rdma()
2200 info->pending_bh |= BH_RECEIVE; in isr_rdma()
2203 static void isr_tdma(struct slgt_info *info) in isr_tdma() argument
2205 unsigned int status = rd_reg32(info, TDCSR); in isr_tdma()
2207 DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status)); in isr_tdma()
2219 wr_reg32(info, TDCSR, status); /* clear pending */ in isr_tdma()
2224 info->pending_bh |= BH_TRANSMIT; in isr_tdma()
2231 * if there are unsent buffers then info->tbuf_start
2234 static bool unsent_tbufs(struct slgt_info *info) in unsent_tbufs() argument
2236 unsigned int i = info->tbuf_current; in unsent_tbufs()
2248 i = info->tbuf_count - 1; in unsent_tbufs()
2249 if (!desc_count(info->tbufs[i])) in unsent_tbufs()
2251 info->tbuf_start = i; in unsent_tbufs()
2253 } while (i != info->tbuf_current); in unsent_tbufs()
2258 static void isr_txeom(struct slgt_info *info, unsigned short status) in isr_txeom() argument
2260 DBGISR(("%s txeom status=%04x\n", info->device_name, status)); in isr_txeom()
2262 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in isr_txeom()
2263 tdma_reset(info); in isr_txeom()
2265 unsigned short val = rd_reg16(info, TCR); in isr_txeom()
2266 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in isr_txeom()
2267 wr_reg16(info, TCR, val); /* clear reset bit */ in isr_txeom()
2270 if (info->tx_active) { in isr_txeom()
2271 if (info->params.mode != MGSL_MODE_ASYNC) { in isr_txeom()
2273 info->icount.txunder++; in isr_txeom()
2275 info->icount.txok++; in isr_txeom()
2278 if (unsent_tbufs(info)) { in isr_txeom()
2279 tx_start(info); in isr_txeom()
2280 update_tx_timer(info); in isr_txeom()
2283 info->tx_active = false; in isr_txeom()
2285 del_timer(&info->tx_timer); in isr_txeom()
2287 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { in isr_txeom()
2288 info->signals &= ~SerialSignal_RTS; in isr_txeom()
2289 info->drop_rts_on_tx_done = false; in isr_txeom()
2290 set_signals(info); in isr_txeom()
2294 if (info->netcount) in isr_txeom()
2295 hdlcdev_tx_done(info); in isr_txeom()
2299 if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) { in isr_txeom()
2300 tx_stop(info); in isr_txeom()
2303 info->pending_bh |= BH_TRANSMIT; in isr_txeom()
2308 static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state) in isr_gpio() argument
2313 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) { in isr_gpio()
2320 info->gpio_wait_q = w->next; in isr_gpio()
2333 struct slgt_info *info = dev_id; in slgt_interrupt() local
2337 DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); in slgt_interrupt()
2339 while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { in slgt_interrupt()
2340 DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); in slgt_interrupt()
2341 info->irq_occurred = true; in slgt_interrupt()
2342 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2343 if (info->port_array[i] == NULL) in slgt_interrupt()
2345 spin_lock(&info->port_array[i]->lock); in slgt_interrupt()
2347 isr_serial(info->port_array[i]); in slgt_interrupt()
2349 isr_rdma(info->port_array[i]); in slgt_interrupt()
2351 isr_tdma(info->port_array[i]); in slgt_interrupt()
2352 spin_unlock(&info->port_array[i]->lock); in slgt_interrupt()
2356 if (info->gpio_present) { in slgt_interrupt()
2359 spin_lock(&info->lock); in slgt_interrupt()
2360 while ((changed = rd_reg32(info, IOSR)) != 0) { in slgt_interrupt()
2361 DBGISR(("%s iosr=%08x\n", info->device_name, changed)); in slgt_interrupt()
2363 state = rd_reg32(info, IOVR); in slgt_interrupt()
2365 wr_reg32(info, IOSR, changed); in slgt_interrupt()
2366 for (i=0 ; i < info->port_count ; i++) { in slgt_interrupt()
2367 if (info->port_array[i] != NULL) in slgt_interrupt()
2368 isr_gpio(info->port_array[i], changed, state); in slgt_interrupt()
2371 spin_unlock(&info->lock); in slgt_interrupt()
2374 for(i=0; i < info->port_count ; i++) { in slgt_interrupt()
2375 struct slgt_info *port = info->port_array[i]; in slgt_interrupt()
2389 DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); in slgt_interrupt()
2393 static int startup(struct slgt_info *info) in startup() argument
2395 DBGINFO(("%s startup\n", info->device_name)); in startup()
2397 if (tty_port_initialized(&info->port)) in startup()
2400 if (!info->tx_buf) { in startup()
2401 info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL); in startup()
2402 if (!info->tx_buf) { in startup()
2403 DBGERR(("%s can't allocate tx buffer\n", info->device_name)); in startup()
2408 info->pending_bh = 0; in startup()
2410 memset(&info->icount, 0, sizeof(info->icount)); in startup()
2413 change_params(info); in startup()
2415 if (info->port.tty) in startup()
2416 clear_bit(TTY_IO_ERROR, &info->port.tty->flags); in startup()
2418 tty_port_set_initialized(&info->port, 1); in startup()
2426 static void shutdown(struct slgt_info *info) in shutdown() argument
2430 if (!tty_port_initialized(&info->port)) in shutdown()
2433 DBGINFO(("%s shutdown\n", info->device_name)); in shutdown()
2437 wake_up_interruptible(&info->status_event_wait_q); in shutdown()
2438 wake_up_interruptible(&info->event_wait_q); in shutdown()
2440 del_timer_sync(&info->tx_timer); in shutdown()
2441 del_timer_sync(&info->rx_timer); in shutdown()
2443 kfree(info->tx_buf); in shutdown()
2444 info->tx_buf = NULL; in shutdown()
2446 spin_lock_irqsave(&info->lock,flags); in shutdown()
2448 tx_stop(info); in shutdown()
2449 rx_stop(info); in shutdown()
2451 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in shutdown()
2453 if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) { in shutdown()
2454 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in shutdown()
2455 set_signals(info); in shutdown()
2458 flush_cond_wait(&info->gpio_wait_q); in shutdown()
2460 spin_unlock_irqrestore(&info->lock,flags); in shutdown()
2462 if (info->port.tty) in shutdown()
2463 set_bit(TTY_IO_ERROR, &info->port.tty->flags); in shutdown()
2465 tty_port_set_initialized(&info->port, 0); in shutdown()
2468 static void program_hw(struct slgt_info *info) in program_hw() argument
2472 spin_lock_irqsave(&info->lock,flags); in program_hw()
2474 rx_stop(info); in program_hw()
2475 tx_stop(info); in program_hw()
2477 if (info->params.mode != MGSL_MODE_ASYNC || in program_hw()
2478 info->netcount) in program_hw()
2479 sync_mode(info); in program_hw()
2481 async_mode(info); in program_hw()
2483 set_signals(info); in program_hw()
2485 info->dcd_chkcount = 0; in program_hw()
2486 info->cts_chkcount = 0; in program_hw()
2487 info->ri_chkcount = 0; in program_hw()
2488 info->dsr_chkcount = 0; in program_hw()
2490 slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI); in program_hw()
2491 get_signals(info); in program_hw()
2493 if (info->netcount || in program_hw()
2494 (info->port.tty && info->port.tty->termios.c_cflag & CREAD)) in program_hw()
2495 rx_start(info); in program_hw()
2497 spin_unlock_irqrestore(&info->lock,flags); in program_hw()
2503 static void change_params(struct slgt_info *info) in change_params() argument
2508 if (!info->port.tty) in change_params()
2510 DBGINFO(("%s change_params\n", info->device_name)); in change_params()
2512 cflag = info->port.tty->termios.c_cflag; in change_params()
2517 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in change_params()
2519 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in change_params()
2524 case CS5: info->params.data_bits = 5; break; in change_params()
2525 case CS6: info->params.data_bits = 6; break; in change_params()
2526 case CS7: info->params.data_bits = 7; break; in change_params()
2527 case CS8: info->params.data_bits = 8; break; in change_params()
2528 default: info->params.data_bits = 7; break; in change_params()
2531 info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1; in change_params()
2534 info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN; in change_params()
2536 info->params.parity = ASYNC_PARITY_NONE; in change_params()
2541 bits_per_char = info->params.data_bits + in change_params()
2542 info->params.stop_bits + 1; in change_params()
2544 info->params.data_rate = tty_get_baud_rate(info->port.tty); in change_params()
2546 if (info->params.data_rate) { in change_params()
2547 info->timeout = (32*HZ*bits_per_char) / in change_params()
2548 info->params.data_rate; in change_params()
2550 info->timeout += HZ/50; /* Add .02 seconds of slop */ in change_params()
2552 tty_port_set_cts_flow(&info->port, cflag & CRTSCTS); in change_params()
2553 tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL); in change_params()
2557 info->read_status_mask = IRQ_RXOVER; in change_params()
2558 if (I_INPCK(info->port.tty)) in change_params()
2559 info->read_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2560 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) in change_params()
2561 info->read_status_mask |= MASK_BREAK; in change_params()
2562 if (I_IGNPAR(info->port.tty)) in change_params()
2563 info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING; in change_params()
2564 if (I_IGNBRK(info->port.tty)) { in change_params()
2565 info->ignore_status_mask |= MASK_BREAK; in change_params()
2569 if (I_IGNPAR(info->port.tty)) in change_params()
2570 info->ignore_status_mask |= MASK_OVERRUN; in change_params()
2573 program_hw(info); in change_params()
2576 static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount) in get_stats() argument
2578 DBGINFO(("%s get_stats\n", info->device_name)); in get_stats()
2580 memset(&info->icount, 0, sizeof(info->icount)); in get_stats()
2582 if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount))) in get_stats()
2588 static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params) in get_params() argument
2590 DBGINFO(("%s get_params\n", info->device_name)); in get_params()
2591 if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS))) in get_params()
2596 static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params) in set_params() argument
2601 DBGINFO(("%s set_params\n", info->device_name)); in set_params()
2605 spin_lock_irqsave(&info->lock, flags); in set_params()
2607 info->base_clock = tmp_params.clock_speed; in set_params()
2609 memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS)); in set_params()
2610 spin_unlock_irqrestore(&info->lock, flags); in set_params()
2612 program_hw(info); in set_params()
2617 static int get_txidle(struct slgt_info *info, int __user *idle_mode) in get_txidle() argument
2619 DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode)); in get_txidle()
2620 if (put_user(info->idle_mode, idle_mode)) in get_txidle()
2625 static int set_txidle(struct slgt_info *info, int idle_mode) in set_txidle() argument
2628 DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode)); in set_txidle()
2629 spin_lock_irqsave(&info->lock,flags); in set_txidle()
2630 info->idle_mode = idle_mode; in set_txidle()
2631 if (info->params.mode != MGSL_MODE_ASYNC) in set_txidle()
2632 tx_set_idle(info); in set_txidle()
2633 spin_unlock_irqrestore(&info->lock,flags); in set_txidle()
2637 static int tx_enable(struct slgt_info *info, int enable) in tx_enable() argument
2640 DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable)); in tx_enable()
2641 spin_lock_irqsave(&info->lock,flags); in tx_enable()
2643 if (!info->tx_enabled) in tx_enable()
2644 tx_start(info); in tx_enable()
2646 if (info->tx_enabled) in tx_enable()
2647 tx_stop(info); in tx_enable()
2649 spin_unlock_irqrestore(&info->lock,flags); in tx_enable()
2656 static int tx_abort(struct slgt_info *info) in tx_abort() argument
2659 DBGINFO(("%s tx_abort\n", info->device_name)); in tx_abort()
2660 spin_lock_irqsave(&info->lock,flags); in tx_abort()
2661 tdma_reset(info); in tx_abort()
2662 spin_unlock_irqrestore(&info->lock,flags); in tx_abort()
2666 static int rx_enable(struct slgt_info *info, int enable) in rx_enable() argument
2670 DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable)); in rx_enable()
2671 spin_lock_irqsave(&info->lock,flags); in rx_enable()
2680 spin_unlock_irqrestore(&info->lock, flags); in rx_enable()
2683 info->rbuf_fill_level = rbuf_fill_level; in rx_enable()
2685 info->rx_pio = 1; /* PIO mode */ in rx_enable()
2687 info->rx_pio = 0; /* DMA mode */ in rx_enable()
2688 rx_stop(info); /* restart receiver to use new fill level */ in rx_enable()
2699 if (!info->rx_enabled) in rx_enable()
2700 rx_start(info); in rx_enable()
2703 wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3); in rx_enable()
2706 if (info->rx_enabled) in rx_enable()
2707 rx_stop(info); in rx_enable()
2709 spin_unlock_irqrestore(&info->lock,flags); in rx_enable()
2716 static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr) in wait_mgsl_event() argument
2730 DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask)); in wait_mgsl_event()
2732 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2735 get_signals(info); in wait_mgsl_event()
2736 s = info->signals; in wait_mgsl_event()
2744 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2749 cprev = info->icount; in wait_mgsl_event()
2750 oldsigs = info->input_signal_events; in wait_mgsl_event()
2754 unsigned short val = rd_reg16(info, SCR); in wait_mgsl_event()
2756 wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE)); in wait_mgsl_event()
2760 add_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2762 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2772 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2773 cnow = info->icount; in wait_mgsl_event()
2774 newsigs = info->input_signal_events; in wait_mgsl_event()
2776 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2811 remove_wait_queue(&info->event_wait_q, &wait); in wait_mgsl_event()
2816 spin_lock_irqsave(&info->lock,flags); in wait_mgsl_event()
2817 if (!waitqueue_active(&info->event_wait_q)) { in wait_mgsl_event()
2819 wr_reg16(info, SCR, in wait_mgsl_event()
2820 (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE)); in wait_mgsl_event()
2822 spin_unlock_irqrestore(&info->lock,flags); in wait_mgsl_event()
2830 static int get_interface(struct slgt_info *info, int __user *if_mode) in get_interface() argument
2832 DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode)); in get_interface()
2833 if (put_user(info->if_mode, if_mode)) in get_interface()
2838 static int set_interface(struct slgt_info *info, int if_mode) in set_interface() argument
2843 DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode)); in set_interface()
2844 spin_lock_irqsave(&info->lock,flags); in set_interface()
2845 info->if_mode = if_mode; in set_interface()
2847 msc_set_vcr(info); in set_interface()
2850 val = rd_reg16(info, TCR); in set_interface()
2851 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in set_interface()
2855 wr_reg16(info, TCR, val); in set_interface()
2857 spin_unlock_irqrestore(&info->lock,flags); in set_interface()
2861 static int get_xsync(struct slgt_info *info, int __user *xsync) in get_xsync() argument
2863 DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync)); in get_xsync()
2864 if (put_user(info->xsync, xsync)) in get_xsync()
2875 static int set_xsync(struct slgt_info *info, int xsync) in set_xsync() argument
2879 DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync)); in set_xsync()
2880 spin_lock_irqsave(&info->lock, flags); in set_xsync()
2881 info->xsync = xsync; in set_xsync()
2882 wr_reg32(info, XSR, xsync); in set_xsync()
2883 spin_unlock_irqrestore(&info->lock, flags); in set_xsync()
2887 static int get_xctrl(struct slgt_info *info, int __user *xctrl) in get_xctrl() argument
2889 DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl)); in get_xctrl()
2890 if (put_user(info->xctrl, xctrl)) in get_xctrl()
2912 static int set_xctrl(struct slgt_info *info, int xctrl) in set_xctrl() argument
2916 DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl)); in set_xctrl()
2917 spin_lock_irqsave(&info->lock, flags); in set_xctrl()
2918 info->xctrl = xctrl; in set_xctrl()
2919 wr_reg32(info, XCR, xctrl); in set_xctrl()
2920 spin_unlock_irqrestore(&info->lock, flags); in set_xctrl()
2933 static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in set_gpio() argument
2939 if (!info->gpio_present) in set_gpio()
2944 info->device_name, gpio.state, gpio.smask, in set_gpio()
2947 spin_lock_irqsave(&info->port_array[0]->lock, flags); in set_gpio()
2949 data = rd_reg32(info, IODR); in set_gpio()
2952 wr_reg32(info, IODR, data); in set_gpio()
2955 data = rd_reg32(info, IOVR); in set_gpio()
2958 wr_reg32(info, IOVR, data); in set_gpio()
2960 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in set_gpio()
2968 static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in get_gpio() argument
2971 if (!info->gpio_present) in get_gpio()
2973 gpio.state = rd_reg32(info, IOVR); in get_gpio()
2975 gpio.dir = rd_reg32(info, IODR); in get_gpio()
2980 info->device_name, gpio.state, gpio.dir)); in get_gpio()
3042 static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio) in wait_gpio() argument
3050 if (!info->gpio_present) in wait_gpio()
3055 info->device_name, gpio.state, gpio.smask)); in wait_gpio()
3057 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0) in wait_gpio()
3061 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3063 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask); in wait_gpio()
3065 state = rd_reg32(info, IOVR); in wait_gpio()
3072 add_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3073 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3079 spin_lock_irqsave(&info->port_array[0]->lock, flags); in wait_gpio()
3080 remove_cond_wait(&info->gpio_wait_q, &wait); in wait_gpio()
3084 if (info->gpio_wait_q == NULL) in wait_gpio()
3085 wr_reg32(info, IOER, 0); in wait_gpio()
3086 spin_unlock_irqrestore(&info->port_array[0]->lock, flags); in wait_gpio()
3093 static int modem_input_wait(struct slgt_info *info,int arg) in modem_input_wait() argument
3101 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3102 cprev = info->icount; in modem_input_wait()
3103 add_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3105 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3115 spin_lock_irqsave(&info->lock,flags); in modem_input_wait()
3116 cnow = info->icount; in modem_input_wait()
3118 spin_unlock_irqrestore(&info->lock,flags); in modem_input_wait()
3138 remove_wait_queue(&info->status_event_wait_q, &wait); in modem_input_wait()
3148 struct slgt_info *info = tty->driver_data; in tiocmget() local
3152 spin_lock_irqsave(&info->lock,flags); in tiocmget()
3153 get_signals(info); in tiocmget()
3154 spin_unlock_irqrestore(&info->lock,flags); in tiocmget()
3156 result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) + in tiocmget()
3157 ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) + in tiocmget()
3158 ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) + in tiocmget()
3159 ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) + in tiocmget()
3160 ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) + in tiocmget()
3161 ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0); in tiocmget()
3163 DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result)); in tiocmget()
3177 struct slgt_info *info = tty->driver_data; in tiocmset() local
3180 DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear)); in tiocmset()
3183 info->signals |= SerialSignal_RTS; in tiocmset()
3185 info->signals |= SerialSignal_DTR; in tiocmset()
3187 info->signals &= ~SerialSignal_RTS; in tiocmset()
3189 info->signals &= ~SerialSignal_DTR; in tiocmset()
3191 spin_lock_irqsave(&info->lock,flags); in tiocmset()
3192 set_signals(info); in tiocmset()
3193 spin_unlock_irqrestore(&info->lock,flags); in tiocmset()
3200 struct slgt_info *info = container_of(port, struct slgt_info, port); in carrier_raised() local
3202 spin_lock_irqsave(&info->lock,flags); in carrier_raised()
3203 get_signals(info); in carrier_raised()
3204 spin_unlock_irqrestore(&info->lock,flags); in carrier_raised()
3205 return (info->signals & SerialSignal_DCD) ? 1 : 0; in carrier_raised()
3211 struct slgt_info *info = container_of(port, struct slgt_info, port); in dtr_rts() local
3213 spin_lock_irqsave(&info->lock,flags); in dtr_rts()
3215 info->signals |= SerialSignal_RTS | SerialSignal_DTR; in dtr_rts()
3217 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in dtr_rts()
3218 set_signals(info); in dtr_rts()
3219 spin_unlock_irqrestore(&info->lock,flags); in dtr_rts()
3227 struct slgt_info *info) in block_til_ready() argument
3234 struct tty_port *port = &info->port; in block_til_ready()
3257 spin_lock_irqsave(&info->lock, flags); in block_til_ready()
3259 spin_unlock_irqrestore(&info->lock, flags); in block_til_ready()
3309 static int alloc_tmp_rbuf(struct slgt_info *info) in alloc_tmp_rbuf() argument
3311 info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3312 if (info->tmp_rbuf == NULL) in alloc_tmp_rbuf()
3315 info->flag_buf = kzalloc(info->max_frame_size + 5, GFP_KERNEL); in alloc_tmp_rbuf()
3316 if (!info->flag_buf) { in alloc_tmp_rbuf()
3317 kfree(info->tmp_rbuf); in alloc_tmp_rbuf()
3318 info->tmp_rbuf = NULL; in alloc_tmp_rbuf()
3324 static void free_tmp_rbuf(struct slgt_info *info) in free_tmp_rbuf() argument
3326 kfree(info->tmp_rbuf); in free_tmp_rbuf()
3327 info->tmp_rbuf = NULL; in free_tmp_rbuf()
3328 kfree(info->flag_buf); in free_tmp_rbuf()
3329 info->flag_buf = NULL; in free_tmp_rbuf()
3335 static int alloc_desc(struct slgt_info *info) in alloc_desc() argument
3341 info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE, in alloc_desc()
3342 &info->bufs_dma_addr, GFP_KERNEL); in alloc_desc()
3343 if (info->bufs == NULL) in alloc_desc()
3346 info->rbufs = (struct slgt_desc*)info->bufs; in alloc_desc()
3347 info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count; in alloc_desc()
3349 pbufs = (unsigned int)info->bufs_dma_addr; in alloc_desc()
3355 for (i=0; i < info->rbuf_count; i++) { in alloc_desc()
3357 info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc)); in alloc_desc()
3360 if (i == info->rbuf_count - 1) in alloc_desc()
3361 info->rbufs[i].next = cpu_to_le32(pbufs); in alloc_desc()
3363 info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc))); in alloc_desc()
3364 set_desc_count(info->rbufs[i], DMABUFSIZE); in alloc_desc()
3367 for (i=0; i < info->tbuf_count; i++) { in alloc_desc()
3369 info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc)); in alloc_desc()
3372 if (i == info->tbuf_count - 1) in alloc_desc()
3373 info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc)); in alloc_desc()
3375info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc))); in alloc_desc()
3381 static void free_desc(struct slgt_info *info) in free_desc() argument
3383 if (info->bufs != NULL) { in free_desc()
3384 dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE, in free_desc()
3385 info->bufs, info->bufs_dma_addr); in free_desc()
3386 info->bufs = NULL; in free_desc()
3387 info->rbufs = NULL; in free_desc()
3388 info->tbufs = NULL; in free_desc()
3392 static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in alloc_bufs() argument
3396 bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE, in alloc_bufs()
3405 static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count) in free_bufs() argument
3411 dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf, in free_bufs()
3417 static int alloc_dma_bufs(struct slgt_info *info) in alloc_dma_bufs() argument
3419 info->rbuf_count = 32; in alloc_dma_bufs()
3420 info->tbuf_count = 32; in alloc_dma_bufs()
3422 if (alloc_desc(info) < 0 || in alloc_dma_bufs()
3423 alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 || in alloc_dma_bufs()
3424 alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 || in alloc_dma_bufs()
3425 alloc_tmp_rbuf(info) < 0) { in alloc_dma_bufs()
3426 DBGERR(("%s DMA buffer alloc fail\n", info->device_name)); in alloc_dma_bufs()
3429 reset_rbufs(info); in alloc_dma_bufs()
3433 static void free_dma_bufs(struct slgt_info *info) in free_dma_bufs() argument
3435 if (info->bufs) { in free_dma_bufs()
3436 free_bufs(info, info->rbufs, info->rbuf_count); in free_dma_bufs()
3437 free_bufs(info, info->tbufs, info->tbuf_count); in free_dma_bufs()
3438 free_desc(info); in free_dma_bufs()
3440 free_tmp_rbuf(info); in free_dma_bufs()
3443 static int claim_resources(struct slgt_info *info) in claim_resources() argument
3445 if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) { in claim_resources()
3447 info->device_name, info->phys_reg_addr)); in claim_resources()
3448 info->init_error = DiagStatus_AddressConflict; in claim_resources()
3452 info->reg_addr_requested = true; in claim_resources()
3454 info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); in claim_resources()
3455 if (!info->reg_addr) { in claim_resources()
3457 info->device_name, info->phys_reg_addr)); in claim_resources()
3458 info->init_error = DiagStatus_CantAssignPciResources; in claim_resources()
3464 release_resources(info); in claim_resources()
3468 static void release_resources(struct slgt_info *info) in release_resources() argument
3470 if (info->irq_requested) { in release_resources()
3471 free_irq(info->irq_level, info); in release_resources()
3472 info->irq_requested = false; in release_resources()
3475 if (info->reg_addr_requested) { in release_resources()
3476 release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); in release_resources()
3477 info->reg_addr_requested = false; in release_resources()
3480 if (info->reg_addr) { in release_resources()
3481 iounmap(info->reg_addr); in release_resources()
3482 info->reg_addr = NULL; in release_resources()
3489 static void add_device(struct slgt_info *info) in add_device() argument
3493 info->next_device = NULL; in add_device()
3494 info->line = slgt_device_count; in add_device()
3495 sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line); in add_device()
3497 if (info->line < MAX_DEVICES) { in add_device()
3498 if (maxframe[info->line]) in add_device()
3499 info->max_frame_size = maxframe[info->line]; in add_device()
3505 slgt_device_list = info; in add_device()
3510 current_dev->next_device = info; in add_device()
3513 if (info->max_frame_size < 4096) in add_device()
3514 info->max_frame_size = 4096; in add_device()
3515 else if (info->max_frame_size > 65535) in add_device()
3516 info->max_frame_size = 65535; in add_device()
3518 switch(info->pdev->device) { in add_device()
3530 info->params.mode = MGSL_MODE_ASYNC; in add_device()
3536 devstr, info->device_name, info->phys_reg_addr, in add_device()
3537 info->irq_level, info->max_frame_size); in add_device()
3540 hdlcdev_init(info); in add_device()
3554 struct slgt_info *info; in alloc_dev() local
3556 info = kzalloc(sizeof(struct slgt_info), GFP_KERNEL); in alloc_dev()
3558 if (!info) { in alloc_dev()
3562 tty_port_init(&info->port); in alloc_dev()
3563 info->port.ops = &slgt_port_ops; in alloc_dev()
3564 info->magic = MGSL_MAGIC; in alloc_dev()
3565 INIT_WORK(&info->task, bh_handler); in alloc_dev()
3566 info->max_frame_size = 4096; in alloc_dev()
3567 info->base_clock = 14745600; in alloc_dev()
3568 info->rbuf_fill_level = DMABUFSIZE; in alloc_dev()
3569 info->port.close_delay = 5*HZ/10; in alloc_dev()
3570 info->port.closing_wait = 30*HZ; in alloc_dev()
3571 init_waitqueue_head(&info->status_event_wait_q); in alloc_dev()
3572 init_waitqueue_head(&info->event_wait_q); in alloc_dev()
3573 spin_lock_init(&info->netlock); in alloc_dev()
3574 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS)); in alloc_dev()
3575 info->idle_mode = HDLC_TXIDLE_FLAGS; in alloc_dev()
3576 info->adapter_num = adapter_num; in alloc_dev()
3577 info->port_num = port_num; in alloc_dev()
3579 timer_setup(&info->tx_timer, tx_timeout, 0); in alloc_dev()
3580 timer_setup(&info->rx_timer, rx_timeout, 0); in alloc_dev()
3582 /* Copy configuration info to device instance data */ in alloc_dev()
3583 info->pdev = pdev; in alloc_dev()
3584 info->irq_level = pdev->irq; in alloc_dev()
3585 info->phys_reg_addr = pci_resource_start(pdev,0); in alloc_dev()
3587 info->bus_type = MGSL_BUS_TYPE_PCI; in alloc_dev()
3588 info->irq_flags = IRQF_SHARED; in alloc_dev()
3590 info->init_error = -1; /* assume error, set to 0 on successful init */ in alloc_dev()
3593 return info; in alloc_dev()
3658 struct slgt_info *info = port_array[i]; in device_init() local
3659 tty_port_register_device(&info->port, serial_driver, info->line, in device_init()
3660 &info->pdev->dev); in device_init()
3709 struct slgt_info *info; in slgt_cleanup() local
3715 for (info=slgt_device_list ; info != NULL ; info=info->next_device) in slgt_cleanup()
3716 tty_unregister_device(serial_driver, info->line); in slgt_cleanup()
3724 info = slgt_device_list; in slgt_cleanup()
3725 while(info) { in slgt_cleanup()
3726 reset_port(info); in slgt_cleanup()
3727 info = info->next_device; in slgt_cleanup()
3731 info = slgt_device_list; in slgt_cleanup()
3732 while(info) { in slgt_cleanup()
3734 hdlcdev_exit(info); in slgt_cleanup()
3736 free_dma_bufs(info); in slgt_cleanup()
3737 free_tmp_rbuf(info); in slgt_cleanup()
3738 if (info->port_num == 0) in slgt_cleanup()
3739 release_resources(info); in slgt_cleanup()
3740 tmp = info; in slgt_cleanup()
3741 info = info->next_device; in slgt_cleanup()
3820 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3822 reg_addr += (info->port_num) * 32; \
3824 reg_addr += (info->port_num) * 16;
3826 static __u8 rd_reg8(struct slgt_info *info, unsigned int addr) in rd_reg8() argument
3832 static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value) in wr_reg8() argument
3838 static __u16 rd_reg16(struct slgt_info *info, unsigned int addr) in rd_reg16() argument
3844 static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value) in wr_reg16() argument
3850 static __u32 rd_reg32(struct slgt_info *info, unsigned int addr) in rd_reg32() argument
3856 static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value) in wr_reg32() argument
3862 static void rdma_reset(struct slgt_info *info) in rdma_reset() argument
3867 wr_reg32(info, RDCSR, BIT1); in rdma_reset()
3871 if (!(rd_reg32(info, RDCSR) & BIT0)) in rdma_reset()
3875 static void tdma_reset(struct slgt_info *info) in tdma_reset() argument
3880 wr_reg32(info, TDCSR, BIT1); in tdma_reset()
3884 if (!(rd_reg32(info, TDCSR) & BIT0)) in tdma_reset()
3893 static void enable_loopback(struct slgt_info *info) in enable_loopback() argument
3896 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2)); in enable_loopback()
3898 if (info->params.mode != MGSL_MODE_ASYNC) { in enable_loopback()
3907 wr_reg8(info, CCR, 0x49); in enable_loopback()
3910 if (info->params.clock_speed) in enable_loopback()
3911 set_rate(info, info->params.clock_speed); in enable_loopback()
3913 set_rate(info, 3686400); in enable_loopback()
3920 static void set_rate(struct slgt_info *info, u32 rate) in set_rate() argument
3923 unsigned int osc = info->base_clock; in set_rate()
3935 wr_reg16(info, BDR, (unsigned short)div); in set_rate()
3939 static void rx_stop(struct slgt_info *info) in rx_stop() argument
3944 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_stop()
3945 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_stop()
3946 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_stop()
3948 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE); in rx_stop()
3951 wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER); in rx_stop()
3953 rdma_reset(info); in rx_stop()
3955 info->rx_enabled = false; in rx_stop()
3956 info->rx_restart = false; in rx_stop()
3959 static void rx_start(struct slgt_info *info) in rx_start() argument
3963 slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA); in rx_start()
3966 wr_reg16(info, SSR, IRQ_RXOVER); in rx_start()
3969 val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */ in rx_start()
3970 wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */ in rx_start()
3971 wr_reg16(info, RCR, val); /* clear reset bit */ in rx_start()
3973 rdma_reset(info); in rx_start()
3974 reset_rbufs(info); in rx_start()
3976 if (info->rx_pio) { in rx_start()
3978 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14)); in rx_start()
3979 slgt_irq_on(info, IRQ_RXDATA); in rx_start()
3980 if (info->params.mode == MGSL_MODE_ASYNC) { in rx_start()
3982 wr_reg32(info, RDCSR, BIT6); in rx_start()
3986 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14)); in rx_start()
3988 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); in rx_start()
3990 if (info->params.mode != MGSL_MODE_ASYNC) { in rx_start()
3992 wr_reg32(info, RDCSR, (BIT2 + BIT0)); in rx_start()
3995 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); in rx_start()
3999 slgt_irq_on(info, IRQ_RXOVER); in rx_start()
4002 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); in rx_start()
4004 info->rx_restart = false; in rx_start()
4005 info->rx_enabled = true; in rx_start()
4008 static void tx_start(struct slgt_info *info) in tx_start() argument
4010 if (!info->tx_enabled) { in tx_start()
4011 wr_reg16(info, TCR, in tx_start()
4012 (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); in tx_start()
4013 info->tx_enabled = true; in tx_start()
4016 if (desc_count(info->tbufs[info->tbuf_start])) { in tx_start()
4017 info->drop_rts_on_tx_done = false; in tx_start()
4019 if (info->params.mode != MGSL_MODE_ASYNC) { in tx_start()
4020 if (info->params.flags & HDLC_FLAG_AUTO_RTS) { in tx_start()
4021 get_signals(info); in tx_start()
4022 if (!(info->signals & SerialSignal_RTS)) { in tx_start()
4023 info->signals |= SerialSignal_RTS; in tx_start()
4024 set_signals(info); in tx_start()
4025 info->drop_rts_on_tx_done = true; in tx_start()
4029 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
4030 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); in tx_start()
4032 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_start()
4034 slgt_irq_off(info, IRQ_TXDATA); in tx_start()
4035 slgt_irq_on(info, IRQ_TXIDLE); in tx_start()
4037 wr_reg16(info, SSR, IRQ_TXIDLE); in tx_start()
4040 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); in tx_start()
4041 wr_reg32(info, TDCSR, BIT2 + BIT0); in tx_start()
4042 info->tx_active = true; in tx_start()
4046 static void tx_stop(struct slgt_info *info) in tx_stop() argument
4050 del_timer(&info->tx_timer); in tx_stop()
4052 tdma_reset(info); in tx_stop()
4055 val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */ in tx_stop()
4056 wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */ in tx_stop()
4058 slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER); in tx_stop()
4061 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); in tx_stop()
4063 reset_tbufs(info); in tx_stop()
4065 info->tx_enabled = false; in tx_stop()
4066 info->tx_active = false; in tx_stop()
4069 static void reset_port(struct slgt_info *info) in reset_port() argument
4071 if (!info->reg_addr) in reset_port()
4074 tx_stop(info); in reset_port()
4075 rx_stop(info); in reset_port()
4077 info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR); in reset_port()
4078 set_signals(info); in reset_port()
4080 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in reset_port()
4083 static void reset_adapter(struct slgt_info *info) in reset_adapter() argument
4086 for (i=0; i < info->port_count; ++i) { in reset_adapter()
4087 if (info->port_array[i]) in reset_adapter()
4088 reset_port(info->port_array[i]); in reset_adapter()
4092 static void async_mode(struct slgt_info *info) in async_mode() argument
4096 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in async_mode()
4097 tx_stop(info); in async_mode()
4098 rx_stop(info); in async_mode()
4120 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in async_mode()
4123 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4125 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4129 switch (info->params.data_bits) in async_mode()
4136 if (info->params.stop_bits != 1) in async_mode()
4139 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in async_mode()
4142 wr_reg16(info, TCR, val); in async_mode()
4163 if (info->params.parity != ASYNC_PARITY_NONE) { in async_mode()
4165 if (info->params.parity == ASYNC_PARITY_ODD) in async_mode()
4169 switch (info->params.data_bits) in async_mode()
4176 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in async_mode()
4179 wr_reg16(info, RCR, val); in async_mode()
4190 wr_reg8(info, CCR, 0x69); in async_mode()
4192 msc_set_vcr(info); in async_mode()
4215 if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate && in async_mode()
4216 ((info->base_clock < (info->params.data_rate * 16)) || in async_mode()
4217 (info->base_clock % (info->params.data_rate * 16)))) { in async_mode()
4220 set_rate(info, info->params.data_rate * 8); in async_mode()
4223 set_rate(info, info->params.data_rate * 16); in async_mode()
4225 wr_reg16(info, SCR, val); in async_mode()
4227 slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER); in async_mode()
4229 if (info->params.loopback) in async_mode()
4230 enable_loopback(info); in async_mode()
4233 static void sync_mode(struct slgt_info *info) in sync_mode() argument
4237 slgt_irq_off(info, IRQ_ALL | IRQ_MASTER); in sync_mode()
4238 tx_stop(info); in sync_mode()
4239 rx_stop(info); in sync_mode()
4263 switch(info->params.mode) { in sync_mode()
4271 if (info->if_mode & MGSL_INTERFACE_RTS_EN) in sync_mode()
4274 switch(info->params.encoding) in sync_mode()
4285 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4291 if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE) in sync_mode()
4294 switch (info->params.preamble_length) in sync_mode()
4301 if (info->params.flags & HDLC_FLAG_AUTO_CTS) in sync_mode()
4304 wr_reg16(info, TCR, val); in sync_mode()
4308 switch (info->params.preamble) in sync_mode()
4317 wr_reg8(info, TPR, (unsigned char)val); in sync_mode()
4338 switch(info->params.mode) { in sync_mode()
4347 switch(info->params.encoding) in sync_mode()
4358 switch (info->params.crc_type & HDLC_CRC_MASK) in sync_mode()
4364 if (info->params.flags & HDLC_FLAG_AUTO_DCD) in sync_mode()
4367 wr_reg16(info, RCR, val); in sync_mode()
4378 if (info->params.flags & HDLC_FLAG_TXC_BRG) in sync_mode()
4383 if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4388 else if (info->params.flags & HDLC_FLAG_TXC_DPLL) in sync_mode()
4390 else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN) in sync_mode()
4393 if (info->params.flags & HDLC_FLAG_RXC_BRG) in sync_mode()
4395 else if (info->params.flags & HDLC_FLAG_RXC_DPLL) in sync_mode()
4397 else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN) in sync_mode()
4400 if (info->params.clock_speed) in sync_mode()
4403 wr_reg8(info, CCR, (unsigned char)val); in sync_mode()
4405 if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL)) in sync_mode()
4408 switch(info->params.encoding) in sync_mode()
4418 wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val)); in sync_mode()
4421 set_rate(info, info->params.clock_speed * 16); in sync_mode()
4424 set_rate(info, info->params.clock_speed); in sync_mode()
4426 tx_set_idle(info); in sync_mode()
4428 msc_set_vcr(info); in sync_mode()
4449 wr_reg16(info, SCR, BIT15 + BIT14 + BIT0); in sync_mode()
4451 if (info->params.loopback) in sync_mode()
4452 enable_loopback(info); in sync_mode()
4458 static void tx_set_idle(struct slgt_info *info) in tx_set_idle() argument
4466 tcr = rd_reg16(info, TCR); in tx_set_idle()
4467 if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) { in tx_set_idle()
4471 wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff)); in tx_set_idle()
4476 wr_reg16(info, TCR, tcr); in tx_set_idle()
4478 if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) { in tx_set_idle()
4480 val = (unsigned char)(info->idle_mode & 0xff); in tx_set_idle()
4483 switch(info->idle_mode) in tx_set_idle()
4494 wr_reg8(info, TIR, val); in tx_set_idle()
4500 static void get_signals(struct slgt_info *info) in get_signals() argument
4502 unsigned short status = rd_reg16(info, SSR); in get_signals()
4505 info->signals &= SerialSignal_RTS | SerialSignal_DTR; in get_signals()
4508 info->signals |= SerialSignal_DSR; in get_signals()
4510 info->signals |= SerialSignal_CTS; in get_signals()
4512 info->signals |= SerialSignal_DCD; in get_signals()
4514 info->signals |= SerialSignal_RI; in get_signals()
4520 static void msc_set_vcr(struct slgt_info *info) in msc_set_vcr() argument
4533 switch(info->if_mode & MGSL_INTERFACE_MASK) in msc_set_vcr()
4546 if (info->if_mode & MGSL_INTERFACE_MSB_FIRST) in msc_set_vcr()
4548 if (info->signals & SerialSignal_DTR) in msc_set_vcr()
4550 if (info->signals & SerialSignal_RTS) in msc_set_vcr()
4552 if (info->if_mode & MGSL_INTERFACE_LL) in msc_set_vcr()
4554 if (info->if_mode & MGSL_INTERFACE_RL) in msc_set_vcr()
4556 wr_reg8(info, VCR, val); in msc_set_vcr()
4562 static void set_signals(struct slgt_info *info) in set_signals() argument
4564 unsigned char val = rd_reg8(info, VCR); in set_signals()
4565 if (info->signals & SerialSignal_DTR) in set_signals()
4569 if (info->signals & SerialSignal_RTS) in set_signals()
4573 wr_reg8(info, VCR, val); in set_signals()
4579 static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last) in free_rbufs() argument
4585 info->rbufs[i].status = 0; in free_rbufs()
4586 set_desc_count(info->rbufs[i], info->rbuf_fill_level); in free_rbufs()
4589 if (++i == info->rbuf_count) in free_rbufs()
4592 info->rbuf_current = i; in free_rbufs()
4598 static void reset_rbufs(struct slgt_info *info) in reset_rbufs() argument
4600 free_rbufs(info, 0, info->rbuf_count - 1); in reset_rbufs()
4601 info->rbuf_fill_index = 0; in reset_rbufs()
4602 info->rbuf_fill_count = 0; in reset_rbufs()
4610 static bool rx_get_frame(struct slgt_info *info) in rx_get_frame() argument
4616 struct tty_struct *tty = info->port.tty; in rx_get_frame()
4620 switch (info->params.crc_type & HDLC_CRC_MASK) { in rx_get_frame()
4629 start = end = info->rbuf_current; in rx_get_frame()
4632 if (!desc_complete(info->rbufs[end])) in rx_get_frame()
4635 if (framesize == 0 && info->params.addr_filter != 0xff) in rx_get_frame()
4636 addr_field = info->rbufs[end].buf[0]; in rx_get_frame()
4638 framesize += desc_count(info->rbufs[end]); in rx_get_frame()
4640 if (desc_eof(info->rbufs[end])) in rx_get_frame()
4643 if (++end == info->rbuf_count) in rx_get_frame()
4646 if (end == info->rbuf_current) { in rx_get_frame()
4647 if (info->rx_enabled){ in rx_get_frame()
4648 spin_lock_irqsave(&info->lock,flags); in rx_get_frame()
4649 rx_start(info); in rx_get_frame()
4650 spin_unlock_irqrestore(&info->lock,flags); in rx_get_frame()
4665 status = desc_status(info->rbufs[end]); in rx_get_frame()
4668 if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE) in rx_get_frame()
4672 (addr_field != 0xff && addr_field != info->params.addr_filter)) { in rx_get_frame()
4673 free_rbufs(info, start, end); in rx_get_frame()
4678 info->icount.rxshort++; in rx_get_frame()
4681 info->icount.rxcrc++; in rx_get_frame()
4682 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) in rx_get_frame()
4688 info->netdev->stats.rx_errors++; in rx_get_frame()
4689 info->netdev->stats.rx_frame_errors++; in rx_get_frame()
4694 info->device_name, status, framesize)); in rx_get_frame()
4695 DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx"); in rx_get_frame()
4698 if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) { in rx_get_frame()
4703 if (framesize > info->max_frame_size + crc_size) in rx_get_frame()
4704 info->icount.rxlong++; in rx_get_frame()
4709 unsigned char *p = info->tmp_rbuf; in rx_get_frame()
4710 info->tmp_rbuf_count = framesize; in rx_get_frame()
4712 info->icount.rxok++; in rx_get_frame()
4715 int partial_count = min_t(int, copy_count, info->rbuf_fill_level); in rx_get_frame()
4716 memcpy(p, info->rbufs[i].buf, partial_count); in rx_get_frame()
4719 if (++i == info->rbuf_count) in rx_get_frame()
4723 if (info->params.crc_type & HDLC_CRC_RETURN_EX) { in rx_get_frame()
4729 if (info->netcount) in rx_get_frame()
4730 hdlcdev_rx(info,info->tmp_rbuf, framesize); in rx_get_frame()
4733 ldisc_receive_buf(tty, info->tmp_rbuf, info->flag_buf, framesize); in rx_get_frame()
4736 free_rbufs(info, start, end); in rx_get_frame()
4747 static bool rx_get_buf(struct slgt_info *info) in rx_get_buf() argument
4749 unsigned int i = info->rbuf_current; in rx_get_buf()
4752 if (!desc_complete(info->rbufs[i])) in rx_get_buf()
4754 count = desc_count(info->rbufs[i]); in rx_get_buf()
4755 switch(info->params.mode) { in rx_get_buf()
4760 if (desc_residue(info->rbufs[i])) in rx_get_buf()
4764 DBGDATA(info, info->rbufs[i].buf, count, "rx"); in rx_get_buf()
4767 ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, in rx_get_buf()
4768 info->flag_buf, count); in rx_get_buf()
4769 free_rbufs(info, i, i); in rx_get_buf()
4773 static void reset_tbufs(struct slgt_info *info) in reset_tbufs() argument
4776 info->tbuf_current = 0; in reset_tbufs()
4777 for (i=0 ; i < info->tbuf_count ; i++) { in reset_tbufs()
4778 info->tbufs[i].status = 0; in reset_tbufs()
4779 info->tbufs[i].count = 0; in reset_tbufs()
4786 static unsigned int free_tbuf_count(struct slgt_info *info) in free_tbuf_count() argument
4789 unsigned int i = info->tbuf_current; in free_tbuf_count()
4793 if (desc_count(info->tbufs[i])) in free_tbuf_count()
4796 if (++i == info->tbuf_count) in free_tbuf_count()
4798 } while (i != info->tbuf_current); in free_tbuf_count()
4801 if (count && (rd_reg32(info, TDCSR) & BIT0)) in free_tbuf_count()
4811 static unsigned int tbuf_bytes(struct slgt_info *info) in tbuf_bytes() argument
4814 unsigned int i = info->tbuf_current; in tbuf_bytes()
4831 count = desc_count(info->tbufs[i]); in tbuf_bytes()
4835 active_buf_count = info->tbufs[i].buf_count; in tbuf_bytes()
4836 if (++i == info->tbuf_count) in tbuf_bytes()
4838 } while (i != info->tbuf_current); in tbuf_bytes()
4841 reg_value = rd_reg32(info, TDCSR); in tbuf_bytes()
4851 if (info->tx_active) in tbuf_bytes()
4861 static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size) in tx_load() argument
4868 if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info)) in tx_load()
4871 DBGDATA(info, buf, size, "tx"); in tx_load()
4884 info->tbuf_start = i = info->tbuf_current; in tx_load()
4887 d = &info->tbufs[i]; in tx_load()
4899 if ((!size && info->params.mode == MGSL_MODE_HDLC) || in tx_load()
4900 info->params.mode == MGSL_MODE_RAW) in tx_load()
4906 if (i != info->tbuf_start) in tx_load()
4910 if (++i == info->tbuf_count) in tx_load()
4914 info->tbuf_current = i; in tx_load()
4917 d = &info->tbufs[info->tbuf_start]; in tx_load()
4921 if (!info->tx_active) in tx_load()
4922 tx_start(info); in tx_load()
4923 update_tx_timer(info); in tx_load()
4928 static int register_test(struct slgt_info *info) in register_test() argument
4937 wr_reg16(info, TIR, patterns[i]); in register_test()
4938 wr_reg16(info, BDR, patterns[(i+1)%count]); in register_test()
4939 if ((rd_reg16(info, TIR) != patterns[i]) || in register_test()
4940 (rd_reg16(info, BDR) != patterns[(i+1)%count])) { in register_test()
4945 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0; in register_test()
4946 info->init_error = rc ? 0 : DiagStatus_AddressFailure; in register_test()
4950 static int irq_test(struct slgt_info *info) in irq_test() argument
4954 struct tty_struct *oldtty = info->port.tty; in irq_test()
4955 u32 speed = info->params.data_rate; in irq_test()
4957 info->params.data_rate = 921600; in irq_test()
4958 info->port.tty = NULL; in irq_test()
4960 spin_lock_irqsave(&info->lock, flags); in irq_test()
4961 async_mode(info); in irq_test()
4962 slgt_irq_on(info, IRQ_TXIDLE); in irq_test()
4965 wr_reg16(info, TCR, in irq_test()
4966 (unsigned short)(rd_reg16(info, TCR) | BIT1)); in irq_test()
4969 wr_reg16(info, TDR, 0); in irq_test()
4972 info->init_error = DiagStatus_IrqFailure; in irq_test()
4973 info->irq_occurred = false; in irq_test()
4975 spin_unlock_irqrestore(&info->lock, flags); in irq_test()
4978 while(timeout-- && !info->irq_occurred) in irq_test()
4981 spin_lock_irqsave(&info->lock,flags); in irq_test()
4982 reset_port(info); in irq_test()
4983 spin_unlock_irqrestore(&info->lock,flags); in irq_test()
4985 info->params.data_rate = speed; in irq_test()
4986 info->port.tty = oldtty; in irq_test()
4988 info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure; in irq_test()
4989 return info->irq_occurred ? 0 : -ENODEV; in irq_test()
4992 static int loopback_test_rx(struct slgt_info *info) in loopback_test_rx() argument
4997 if (desc_complete(info->rbufs[0])) { in loopback_test_rx()
4998 count = desc_count(info->rbufs[0]); in loopback_test_rx()
4999 src = info->rbufs[0].buf; in loopback_test_rx()
5000 dest = info->tmp_rbuf; in loopback_test_rx()
5007 info->tmp_rbuf_count++; in loopback_test_rx()
5010 DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx"); in loopback_test_rx()
5016 static int loopback_test(struct slgt_info *info) in loopback_test() argument
5026 struct tty_struct *oldtty = info->port.tty; in loopback_test()
5029 memcpy(&params, &info->params, sizeof(params)); in loopback_test()
5031 info->params.mode = MGSL_MODE_ASYNC; in loopback_test()
5032 info->params.data_rate = 921600; in loopback_test()
5033 info->params.loopback = 1; in loopback_test()
5034 info->port.tty = NULL; in loopback_test()
5040 info->tmp_rbuf_count = 0; in loopback_test()
5041 memset(info->tmp_rbuf, 0, TESTFRAMESIZE); in loopback_test()
5044 spin_lock_irqsave(&info->lock,flags); in loopback_test()
5045 async_mode(info); in loopback_test()
5046 rx_start(info); in loopback_test()
5047 tx_load(info, buf, count); in loopback_test()
5048 spin_unlock_irqrestore(&info->lock, flags); in loopback_test()
5053 if (loopback_test_rx(info)) { in loopback_test()
5060 if (!rc && (info->tmp_rbuf_count != count || in loopback_test()
5061 memcmp(buf, info->tmp_rbuf, count))) { in loopback_test()
5065 spin_lock_irqsave(&info->lock,flags); in loopback_test()
5066 reset_adapter(info); in loopback_test()
5067 spin_unlock_irqrestore(&info->lock,flags); in loopback_test()
5069 memcpy(&info->params, &params, sizeof(info->params)); in loopback_test()
5070 info->port.tty = oldtty; in loopback_test()
5072 info->init_error = rc ? DiagStatus_DmaFailure : 0; in loopback_test()
5076 static int adapter_test(struct slgt_info *info) in adapter_test() argument
5078 DBGINFO(("testing %s\n", info->device_name)); in adapter_test()
5079 if (register_test(info) < 0) { in adapter_test()
5081 info->device_name, info->phys_reg_addr); in adapter_test()
5082 } else if (irq_test(info) < 0) { in adapter_test()
5084 info->device_name, info->irq_level); in adapter_test()
5085 } else if (loopback_test(info) < 0) { in adapter_test()
5086 printk("loopback test failure %s\n", info->device_name); in adapter_test()
5088 return info->init_error; in adapter_test()
5096 struct slgt_info *info = from_timer(info, t, tx_timer); in tx_timeout() local
5099 DBGINFO(("%s tx_timeout\n", info->device_name)); in tx_timeout()
5100 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) { in tx_timeout()
5101 info->icount.txtimeout++; in tx_timeout()
5103 spin_lock_irqsave(&info->lock,flags); in tx_timeout()
5104 tx_stop(info); in tx_timeout()
5105 spin_unlock_irqrestore(&info->lock,flags); in tx_timeout()
5108 if (info->netcount) in tx_timeout()
5109 hdlcdev_tx_done(info); in tx_timeout()
5112 bh_transmit(info); in tx_timeout()
5120 struct slgt_info *info = from_timer(info, t, rx_timer); in rx_timeout() local
5123 DBGINFO(("%s rx_timeout\n", info->device_name)); in rx_timeout()
5124 spin_lock_irqsave(&info->lock, flags); in rx_timeout()
5125 info->pending_bh |= BH_RECEIVE; in rx_timeout()
5126 spin_unlock_irqrestore(&info->lock, flags); in rx_timeout()
5127 bh_handler(&info->task); in rx_timeout()