Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: dgrp: remove driver

Remove the driver as it hasn't been cleaned up and it doesn't look like
anyone is going to work on it anymore. This can be reverted if someone
wants to work to fix the remaining issues the driver has.

Signed-off-by: Kristina Martšenko <kristina.martsenko@gmail.com>
Cc: Bill Pemberton <wfp5p@worldbroken.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Kristina Martšenko and committed by
Greg Kroah-Hartman
19b1e769 929b2d48

-10404
-2
drivers/staging/Kconfig
··· 114 114 115 115 source "drivers/staging/imx-drm/Kconfig" 116 116 117 - source "drivers/staging/dgrp/Kconfig" 118 - 119 117 source "drivers/staging/fwserial/Kconfig" 120 118 121 119 source "drivers/staging/goldfish/Kconfig"
-1
drivers/staging/Makefile
··· 50 50 obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/ 51 51 obj-$(CONFIG_CED1401) += ced1401/ 52 52 obj-$(CONFIG_DRM_IMX) += imx-drm/ 53 - obj-$(CONFIG_DGRP) += dgrp/ 54 53 obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ 55 54 obj-$(CONFIG_GOLDFISH) += goldfish/ 56 55 obj-$(CONFIG_LUSTRE_FS) += lustre/
-9
drivers/staging/dgrp/Kconfig
··· 1 - config DGRP 2 - tristate "Digi Realport driver" 3 - default n 4 - depends on SYSFS && TTY 5 - ---help--- 6 - Support for Digi Realport devices. These devices allow you to 7 - access remote serial ports as if they are local tty devices. This 8 - will build the kernel driver, you will still need the userspace 9 - component to make your Realport device work.
-12
drivers/staging/dgrp/Makefile
··· 1 - obj-$(CONFIG_DGRP) += dgrp.o 2 - 3 - dgrp-y := \ 4 - dgrp_common.o \ 5 - dgrp_dpa_ops.o \ 6 - dgrp_driver.o \ 7 - dgrp_mon_ops.o \ 8 - dgrp_net_ops.o \ 9 - dgrp_ports_ops.o \ 10 - dgrp_specproc.o \ 11 - dgrp_tty.o \ 12 - dgrp_sysfs.o
-2
drivers/staging/dgrp/README
··· 1 - The user space code to work with this driver is located at 2 - https://github.com/wfp5p/dgrp-utils
-13
drivers/staging/dgrp/TODO
··· 1 - - Use configfs for config stuff. This will require changes to the 2 - user space code. 3 - 4 - - dgrp_send() and dgrp_receive() could use some refactoring 5 - 6 - - Don't automatically create CHAN_MAX (64) channel array entries for 7 - every device as many devices are going to have much less than 64 8 - channels. 9 - 10 - - The locking needs to be checked. It seems haphazardly done in most 11 - places. 12 - 13 - - Check Kconfig dependencies
-169
drivers/staging/dgrp/dgrp_common.c
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - /* 19 - * 20 - * Filename: 21 - * 22 - * dgrp_common.c 23 - * 24 - * Description: 25 - * 26 - * Definitions of global variables and functions which are either 27 - * shared by the tty, mon, and net drivers; or which cross them 28 - * functionally (like the poller). 29 - * 30 - * Author: 31 - * 32 - * James A. Puzzo 33 - * 34 - */ 35 - 36 - #include <linux/errno.h> 37 - #include <linux/tty.h> 38 - #include <linux/sched.h> 39 - #include <linux/cred.h> 40 - 41 - #include "dgrp_common.h" 42 - 43 - /** 44 - * dgrp_carrier -- check for carrier change state and act 45 - * @ch: struct ch_struct * 46 - */ 47 - void dgrp_carrier(struct ch_struct *ch) 48 - { 49 - struct nd_struct *nd; 50 - 51 - int virt_carrier = 0; 52 - int phys_carrier = 0; 53 - 54 - /* fix case when the tty has already closed. */ 55 - 56 - if (!ch) 57 - return; 58 - nd = ch->ch_nd; 59 - if (!nd) 60 - return; 61 - 62 - /* 63 - * If we are currently waiting to determine the status of the port, 64 - * we don't yet know the state of the modem lines. As a result, 65 - * we ignore state changes when we are waiting for the modem lines 66 - * to be established. We know, as a result of code in dgrp_net_ops, 67 - * that we will be called again immediately following the reception 68 - * of the status message with the true modem status flags in it. 69 - */ 70 - if (ch->ch_expect & RR_STATUS) 71 - return; 72 - 73 - /* 74 - * If CH_HANGUP is set, we gotta keep trying to get all the processes 75 - * that have the port open to close the port. 76 - * So lets just keep sending a hangup every time we get here. 77 - */ 78 - if ((ch->ch_flag & CH_HANGUP) && 79 - (ch->ch_tun.un_open_count > 0)) 80 - tty_hangup(ch->ch_tun.un_tty); 81 - 82 - /* 83 - * Compute the effective state of both the physical and virtual 84 - * senses of carrier. 85 - */ 86 - 87 - if (ch->ch_s_mlast & DM_CD) 88 - phys_carrier = 1; 89 - 90 - if ((ch->ch_s_mlast & DM_CD) || 91 - (ch->ch_digi.digi_flags & DIGI_FORCEDCD) || 92 - (ch->ch_flag & CH_CLOCAL)) 93 - virt_carrier = 1; 94 - 95 - /* 96 - * Test for a VIRTUAL carrier transition to HIGH. 97 - * 98 - * The CH_HANGUP condition is intended to prevent any action 99 - * except for close. As a result, we ignore positive carrier 100 - * transitions during CH_HANGUP. 101 - */ 102 - if (((ch->ch_flag & CH_HANGUP) == 0) && 103 - ((ch->ch_flag & CH_VIRT_CD) == 0) && 104 - (virt_carrier == 1)) { 105 - /* 106 - * When carrier rises, wake any threads waiting 107 - * for carrier in the open routine. 108 - */ 109 - nd->nd_tx_work = 1; 110 - 111 - if (waitqueue_active(&ch->ch_flag_wait)) 112 - wake_up_interruptible(&ch->ch_flag_wait); 113 - } 114 - 115 - /* 116 - * Test for a PHYSICAL transition to low, so long as we aren't 117 - * currently ignoring physical transitions (which is what "virtual 118 - * carrier" indicates). 119 - * 120 - * The transition of the virtual carrier to low really doesn't 121 - * matter... it really only means "ignore carrier state", not 122 - * "make pretend that carrier is there". 123 - */ 124 - if ((virt_carrier == 0) && 125 - ((ch->ch_flag & CH_PHYS_CD) != 0) && 126 - (phys_carrier == 0)) { 127 - /* 128 - * When carrier drops: 129 - * 130 - * Do a Hard Hangup if that is called for. 131 - * 132 - * Drop carrier on all open units. 133 - * 134 - * Flush queues, waking up any task waiting in the 135 - * line discipline. 136 - * 137 - * Send a hangup to the control terminal. 138 - * 139 - * Enable all select calls. 140 - */ 141 - 142 - nd->nd_tx_work = 1; 143 - 144 - ch->ch_flag &= ~(CH_LOW | CH_EMPTY | CH_DRAIN | CH_INPUT); 145 - 146 - if (waitqueue_active(&ch->ch_flag_wait)) 147 - wake_up_interruptible(&ch->ch_flag_wait); 148 - 149 - if (ch->ch_tun.un_open_count > 0) 150 - tty_hangup(ch->ch_tun.un_tty); 151 - 152 - if (ch->ch_pun.un_open_count > 0) 153 - tty_hangup(ch->ch_pun.un_tty); 154 - } 155 - 156 - /* 157 - * Make sure that our cached values reflect the current reality. 158 - */ 159 - if (virt_carrier == 1) 160 - ch->ch_flag |= CH_VIRT_CD; 161 - else 162 - ch->ch_flag &= ~CH_VIRT_CD; 163 - 164 - if (phys_carrier == 1) 165 - ch->ch_flag |= CH_PHYS_CD; 166 - else 167 - ch->ch_flag &= ~CH_PHYS_CD; 168 - 169 - }
-150
drivers/staging/dgrp/dgrp_common.h
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - #ifndef __DGRP_COMMON_H 19 - #define __DGRP_COMMON_H 20 - 21 - #define DIGI_VERSION "1.9-29" 22 - 23 - #include <linux/fs.h> 24 - #include <linux/timer.h> 25 - #include "drp.h" 26 - 27 - #define DGRP_TTIME 100 28 - #define DGRP_RTIME 100 29 - 30 - /************************************************************************ 31 - * All global storage allocation. 32 - ************************************************************************/ 33 - 34 - extern int dgrp_register_cudevices; /* enable legacy cu devices */ 35 - extern int dgrp_register_prdevices; /* enable transparent print devices */ 36 - extern int dgrp_poll_tick; /* Poll interval - in ms */ 37 - 38 - extern struct list_head nd_struct_list; 39 - 40 - struct dgrp_poll_data { 41 - spinlock_t poll_lock; 42 - struct timer_list timer; 43 - int poll_tick; 44 - ulong poll_round; /* Timer rouding factor */ 45 - long node_active_count; 46 - }; 47 - 48 - extern struct dgrp_poll_data dgrp_poll_data; 49 - extern void dgrp_poll_handler(unsigned long arg); 50 - 51 - /* from dgrp_mon_ops.c */ 52 - extern const struct file_operations dgrp_mon_ops; 53 - 54 - /* from dgrp_tty.c */ 55 - extern int dgrp_tty_init(struct nd_struct *nd); 56 - extern void dgrp_tty_uninit(struct nd_struct *nd); 57 - 58 - /* from dgrp_ports_ops.c */ 59 - extern const struct file_operations dgrp_ports_ops; 60 - 61 - /* from dgrp_net_ops.c */ 62 - extern const struct file_operations dgrp_net_ops; 63 - 64 - /* from dgrp_dpa_ops.c */ 65 - extern const struct file_operations dgrp_dpa_ops; 66 - extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int); 67 - 68 - /* from dgrp_sysfs.c */ 69 - extern int dgrp_create_class_sysfs_files(void); 70 - extern void dgrp_remove_class_sysfs_files(void); 71 - 72 - extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd); 73 - extern void dgrp_remove_node_class_sysfs_files(struct nd_struct *nd); 74 - 75 - extern void dgrp_create_tty_sysfs(struct un_struct *un, struct device *c); 76 - extern void dgrp_remove_tty_sysfs(struct device *c); 77 - 78 - /* from dgrp_specproc.c */ 79 - extern void dgrp_unregister_proc(void); 80 - extern void dgrp_register_proc(void); 81 - 82 - /*-----------------------------------------------------------------------* 83 - * 84 - * Declarations for common operations: 85 - * 86 - * (either used by more than one of net, mon, or tty, 87 - * or in interrupt context (i.e. the poller)) 88 - * 89 - *-----------------------------------------------------------------------*/ 90 - 91 - void dgrp_carrier(struct ch_struct *ch); 92 - 93 - 94 - /* 95 - * ID manipulation macros (where c1 & c2 are characters, i is 96 - * a long integer, and s is a character array of at least three members 97 - */ 98 - 99 - static inline void ID_TO_CHAR(long i, char *s) 100 - { 101 - s[0] = ((i & 0xff00)>>8); 102 - s[1] = (i & 0xff); 103 - s[2] = 0; 104 - } 105 - 106 - static inline long CHAR_TO_ID(char *s) 107 - { 108 - return ((s[0] & 0xff) << 8) | (s[1] & 0xff); 109 - } 110 - 111 - static inline struct nd_struct *nd_struct_get(long major) 112 - { 113 - struct nd_struct *nd; 114 - 115 - list_for_each_entry(nd, &nd_struct_list, list) { 116 - if (major == nd->nd_major) 117 - return nd; 118 - } 119 - 120 - return NULL; 121 - } 122 - 123 - static inline int nd_struct_add(struct nd_struct *entry) 124 - { 125 - struct nd_struct *ptr; 126 - 127 - ptr = nd_struct_get(entry->nd_major); 128 - 129 - if (ptr) 130 - return -EBUSY; 131 - 132 - list_add_tail(&entry->list, &nd_struct_list); 133 - 134 - return 0; 135 - } 136 - 137 - static inline int nd_struct_del(struct nd_struct *entry) 138 - { 139 - struct nd_struct *nd; 140 - 141 - nd = nd_struct_get(entry->nd_major); 142 - 143 - if (!nd) 144 - return -ENODEV; 145 - 146 - list_del(&nd->list); 147 - return 0; 148 - } 149 - 150 - #endif /* __DGRP_COMMON_H */
-534
drivers/staging/dgrp/dgrp_dpa_ops.c
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - /* 19 - * 20 - * Filename: 21 - * 22 - * dgrp_dpa_ops.c 23 - * 24 - * Description: 25 - * 26 - * Handle the file operations required for the "dpa" devices. 27 - * Includes those functions required to register the "dpa" devices 28 - * in "/proc". 29 - * 30 - * Author: 31 - * 32 - * James A. Puzzo 33 - * 34 - */ 35 - 36 - #include <linux/module.h> 37 - #include <linux/proc_fs.h> 38 - #include <linux/tty.h> 39 - #include <linux/poll.h> 40 - #include <linux/cred.h> 41 - #include <linux/sched.h> 42 - #include <linux/ratelimit.h> 43 - #include <linux/slab.h> 44 - #include <asm/unaligned.h> 45 - 46 - #include "dgrp_common.h" 47 - 48 - /* File operation declarations */ 49 - static int dgrp_dpa_open(struct inode *, struct file *); 50 - static int dgrp_dpa_release(struct inode *, struct file *); 51 - static ssize_t dgrp_dpa_read(struct file *, char __user *, size_t, loff_t *); 52 - static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd, 53 - unsigned long arg); 54 - static unsigned int dgrp_dpa_select(struct file *, struct poll_table_struct *); 55 - 56 - const struct file_operations dgrp_dpa_ops = { 57 - .owner = THIS_MODULE, 58 - .read = dgrp_dpa_read, 59 - .poll = dgrp_dpa_select, 60 - .unlocked_ioctl = dgrp_dpa_ioctl, 61 - .open = dgrp_dpa_open, 62 - .release = dgrp_dpa_release, 63 - }; 64 - 65 - struct digi_node { 66 - uint nd_state; /* Node state: 1 = up, 0 = down. */ 67 - uint nd_chan_count; /* Number of channels found */ 68 - uint nd_tx_byte; /* Tx data count */ 69 - uint nd_rx_byte; /* RX data count */ 70 - u8 nd_ps_desc[MAX_DESC_LEN]; /* Description from PS */ 71 - }; 72 - 73 - #define DIGI_GETNODE (('d'<<8) | 249) /* get board info */ 74 - 75 - 76 - struct digi_chan { 77 - uint ch_port; /* Port number to get info on */ 78 - uint ch_open; /* 1 if open, 0 if not */ 79 - uint ch_txcount; /* TX data count */ 80 - uint ch_rxcount; /* RX data count */ 81 - uint ch_s_brate; /* Realport BRATE */ 82 - uint ch_s_estat; /* Realport ELAST */ 83 - uint ch_s_cflag; /* Realport CFLAG */ 84 - uint ch_s_iflag; /* Realport IFLAG */ 85 - uint ch_s_oflag; /* Realport OFLAG */ 86 - uint ch_s_xflag; /* Realport XFLAG */ 87 - uint ch_s_mstat; /* Realport MLAST */ 88 - }; 89 - 90 - #define DIGI_GETCHAN (('d'<<8) | 248) /* get channel info */ 91 - 92 - 93 - struct digi_vpd { 94 - int vpd_len; 95 - char vpd_data[VPDSIZE]; 96 - }; 97 - 98 - #define DIGI_GETVPD (('d'<<8) | 246) /* get VPD info */ 99 - 100 - 101 - struct digi_debug { 102 - int onoff; 103 - int port; 104 - }; 105 - 106 - #define DIGI_SETDEBUG (('d'<<8) | 247) /* set debug info */ 107 - 108 - 109 - /* 110 - * dgrp_dpa_open -- open the DPA device for a particular PortServer 111 - */ 112 - static int dgrp_dpa_open(struct inode *inode, struct file *file) 113 - { 114 - struct nd_struct *nd; 115 - int rtn = 0; 116 - 117 - rtn = try_module_get(THIS_MODULE); 118 - if (!rtn) 119 - return -ENXIO; 120 - 121 - rtn = 0; 122 - 123 - if (!capable(CAP_SYS_ADMIN)) { 124 - rtn = -EPERM; 125 - goto done; 126 - } 127 - 128 - /* 129 - * Make sure that the "private_data" field hasn't already been used. 130 - */ 131 - if (file->private_data) { 132 - rtn = -EINVAL; 133 - goto done; 134 - } 135 - 136 - /* 137 - * Get the node pointer, and fail if it doesn't exist. 138 - */ 139 - nd = PDE_DATA(inode); 140 - if (!nd) { 141 - rtn = -ENXIO; 142 - goto done; 143 - } 144 - 145 - file->private_data = (void *) nd; 146 - 147 - /* 148 - * Allocate the DPA buffer. 149 - */ 150 - 151 - if (nd->nd_dpa_buf) { 152 - rtn = -EBUSY; 153 - } else { 154 - nd->nd_dpa_buf = kmalloc(DPA_MAX, GFP_KERNEL); 155 - 156 - if (!nd->nd_dpa_buf) { 157 - rtn = -ENOMEM; 158 - } else { 159 - nd->nd_dpa_out = 0; 160 - nd->nd_dpa_in = 0; 161 - nd->nd_dpa_lbolt = jiffies; 162 - } 163 - } 164 - 165 - done: 166 - 167 - if (rtn) 168 - module_put(THIS_MODULE); 169 - return rtn; 170 - } 171 - 172 - /* 173 - * dgrp_dpa_release -- close the DPA device for a particular PortServer 174 - */ 175 - static int dgrp_dpa_release(struct inode *inode, struct file *file) 176 - { 177 - struct nd_struct *nd; 178 - u8 *buf; 179 - unsigned long lock_flags; 180 - 181 - /* 182 - * Get the node pointer, and quit if it doesn't exist. 183 - */ 184 - nd = (struct nd_struct *)(file->private_data); 185 - if (!nd) 186 - goto done; 187 - 188 - /* 189 - * Free the dpa buffer. 190 - */ 191 - 192 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 193 - 194 - buf = nd->nd_dpa_buf; 195 - 196 - nd->nd_dpa_buf = NULL; 197 - nd->nd_dpa_out = nd->nd_dpa_in; 198 - 199 - /* 200 - * Wakeup any thread waiting for buffer space. 201 - */ 202 - 203 - if (nd->nd_dpa_flag & DPA_WAIT_SPACE) { 204 - nd->nd_dpa_flag &= ~DPA_WAIT_SPACE; 205 - wake_up_interruptible(&nd->nd_dpa_wqueue); 206 - } 207 - 208 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 209 - 210 - kfree(buf); 211 - 212 - done: 213 - module_put(THIS_MODULE); 214 - file->private_data = NULL; 215 - return 0; 216 - } 217 - 218 - /* 219 - * dgrp_dpa_read 220 - * 221 - * Copy data from the monitoring buffer to the user, freeing space 222 - * in the monitoring buffer for more messages 223 - */ 224 - static ssize_t dgrp_dpa_read(struct file *file, char __user *buf, size_t count, 225 - loff_t *ppos) 226 - { 227 - struct nd_struct *nd; 228 - int n; 229 - int r; 230 - int offset = 0; 231 - int res = 0; 232 - ssize_t rtn; 233 - unsigned long lock_flags; 234 - 235 - /* 236 - * Get the node pointer, and quit if it doesn't exist. 237 - */ 238 - nd = (struct nd_struct *)(file->private_data); 239 - if (!nd) 240 - return -ENXIO; 241 - 242 - /* 243 - * Wait for some data to appear in the buffer. 244 - */ 245 - 246 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 247 - 248 - for (;;) { 249 - n = (nd->nd_dpa_in - nd->nd_dpa_out) & DPA_MASK; 250 - 251 - if (n != 0) 252 - break; 253 - 254 - nd->nd_dpa_flag |= DPA_WAIT_DATA; 255 - 256 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 257 - 258 - /* 259 - * Go to sleep waiting until the condition becomes true. 260 - */ 261 - rtn = wait_event_interruptible(nd->nd_dpa_wqueue, 262 - ((nd->nd_dpa_flag & DPA_WAIT_DATA) == 0)); 263 - 264 - if (rtn) 265 - return rtn; 266 - 267 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 268 - } 269 - 270 - /* 271 - * Read whatever is there. 272 - */ 273 - 274 - if (n > count) 275 - n = count; 276 - 277 - res = n; 278 - 279 - r = DPA_MAX - nd->nd_dpa_out; 280 - 281 - if (r <= n) { 282 - 283 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 284 - rtn = copy_to_user((void __user *)buf, 285 - nd->nd_dpa_buf + nd->nd_dpa_out, r); 286 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 287 - 288 - if (rtn) { 289 - rtn = -EFAULT; 290 - goto done; 291 - } 292 - 293 - nd->nd_dpa_out = 0; 294 - n -= r; 295 - offset = r; 296 - } 297 - 298 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 299 - rtn = copy_to_user((void __user *)buf + offset, 300 - nd->nd_dpa_buf + nd->nd_dpa_out, n); 301 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 302 - 303 - if (rtn) { 304 - rtn = -EFAULT; 305 - goto done; 306 - } 307 - 308 - nd->nd_dpa_out += n; 309 - 310 - *ppos += res; 311 - 312 - rtn = res; 313 - 314 - /* 315 - * Wakeup any thread waiting for buffer space. 316 - */ 317 - 318 - n = (nd->nd_dpa_in - nd->nd_dpa_out) & DPA_MASK; 319 - 320 - if (nd->nd_dpa_flag & DPA_WAIT_SPACE && 321 - (DPA_MAX - n) > DPA_HIGH_WATER) { 322 - nd->nd_dpa_flag &= ~DPA_WAIT_SPACE; 323 - wake_up_interruptible(&nd->nd_dpa_wqueue); 324 - } 325 - 326 - done: 327 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 328 - return rtn; 329 - } 330 - 331 - static unsigned int dgrp_dpa_select(struct file *file, 332 - struct poll_table_struct *table) 333 - { 334 - unsigned int retval = 0; 335 - struct nd_struct *nd = file->private_data; 336 - 337 - if (nd->nd_dpa_out != nd->nd_dpa_in) 338 - retval |= POLLIN | POLLRDNORM; /* Conditionally readable */ 339 - 340 - retval |= POLLOUT | POLLWRNORM; /* Always writeable */ 341 - 342 - return retval; 343 - } 344 - 345 - static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd, 346 - unsigned long arg) 347 - { 348 - 349 - struct nd_struct *nd; 350 - struct digi_chan getchan; 351 - struct digi_node getnode; 352 - struct ch_struct *ch; 353 - struct digi_debug setdebug; 354 - struct digi_vpd vpd; 355 - unsigned int port; 356 - void __user *uarg = (void __user *) arg; 357 - 358 - nd = file->private_data; 359 - 360 - switch (cmd) { 361 - case DIGI_GETCHAN: 362 - if (copy_from_user(&getchan, uarg, sizeof(struct digi_chan))) 363 - return -EFAULT; 364 - 365 - port = getchan.ch_port; 366 - 367 - if (port > nd->nd_chan_count) 368 - return -EINVAL; 369 - 370 - ch = nd->nd_chan + port; 371 - 372 - getchan.ch_open = (ch->ch_open_count > 0) ? 1 : 0; 373 - getchan.ch_txcount = ch->ch_txcount; 374 - getchan.ch_rxcount = ch->ch_rxcount; 375 - getchan.ch_s_brate = ch->ch_s_brate; 376 - getchan.ch_s_estat = ch->ch_s_elast; 377 - getchan.ch_s_cflag = ch->ch_s_cflag; 378 - getchan.ch_s_iflag = ch->ch_s_iflag; 379 - getchan.ch_s_oflag = ch->ch_s_oflag; 380 - getchan.ch_s_xflag = ch->ch_s_xflag; 381 - getchan.ch_s_mstat = ch->ch_s_mlast; 382 - 383 - if (copy_to_user(uarg, &getchan, sizeof(struct digi_chan))) 384 - return -EFAULT; 385 - break; 386 - 387 - 388 - case DIGI_GETNODE: 389 - getnode.nd_state = (nd->nd_state & NS_READY) ? 1 : 0; 390 - getnode.nd_chan_count = nd->nd_chan_count; 391 - getnode.nd_tx_byte = nd->nd_tx_byte; 392 - getnode.nd_rx_byte = nd->nd_rx_byte; 393 - 394 - memset(&getnode.nd_ps_desc, 0, MAX_DESC_LEN); 395 - strlcpy(getnode.nd_ps_desc, nd->nd_ps_desc, MAX_DESC_LEN); 396 - 397 - if (copy_to_user(uarg, &getnode, sizeof(struct digi_node))) 398 - return -EFAULT; 399 - break; 400 - 401 - 402 - case DIGI_SETDEBUG: 403 - if (copy_from_user(&setdebug, uarg, sizeof(struct digi_debug))) 404 - return -EFAULT; 405 - 406 - nd->nd_dpa_debug = setdebug.onoff; 407 - nd->nd_dpa_port = setdebug.port; 408 - break; 409 - 410 - 411 - case DIGI_GETVPD: 412 - memset(&vpd, 0, sizeof(vpd)); 413 - if (nd->nd_vpd_len > 0) { 414 - vpd.vpd_len = nd->nd_vpd_len; 415 - memcpy(&vpd.vpd_data, &nd->nd_vpd, nd->nd_vpd_len); 416 - } else { 417 - vpd.vpd_len = 0; 418 - } 419 - 420 - if (copy_to_user(uarg, &vpd, sizeof(struct digi_vpd))) 421 - return -EFAULT; 422 - break; 423 - } 424 - 425 - return 0; 426 - } 427 - 428 - /** 429 - * dgrp_dpa() -- send data to the device monitor queue 430 - * @nd: pointer to a node structure 431 - * @buf: buffer of data to copy to the monitoring buffer 432 - * @len: number of bytes to transfer to the buffer 433 - * 434 - * Called by the net device routines to send data to the device 435 - * monitor queue. If the device monitor buffer is too full to 436 - * accept the data, it waits until the buffer is ready. 437 - */ 438 - static void dgrp_dpa(struct nd_struct *nd, u8 *buf, int nbuf) 439 - { 440 - int n; 441 - int r; 442 - unsigned long lock_flags; 443 - 444 - /* 445 - * Grab DPA lock. 446 - */ 447 - spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); 448 - 449 - /* 450 - * Loop while data remains. 451 - */ 452 - while (nbuf > 0 && nd->nd_dpa_buf != NULL) { 453 - 454 - n = (nd->nd_dpa_out - nd->nd_dpa_in - 1) & DPA_MASK; 455 - 456 - /* 457 - * Enforce flow control on the DPA device. 458 - */ 459 - if (n < (DPA_MAX - DPA_HIGH_WATER)) 460 - nd->nd_dpa_flag |= DPA_WAIT_SPACE; 461 - 462 - /* 463 - * This should never happen, as the flow control above 464 - * should have stopped things before they got to this point. 465 - */ 466 - if (n == 0) { 467 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 468 - return; 469 - } 470 - 471 - /* 472 - * Copy as much data as will fit. 473 - */ 474 - 475 - if (n > nbuf) 476 - n = nbuf; 477 - 478 - r = DPA_MAX - nd->nd_dpa_in; 479 - 480 - if (r <= n) { 481 - memcpy(nd->nd_dpa_buf + nd->nd_dpa_in, buf, r); 482 - 483 - n -= r; 484 - 485 - nd->nd_dpa_in = 0; 486 - 487 - buf += r; 488 - nbuf -= r; 489 - } 490 - 491 - memcpy(nd->nd_dpa_buf + nd->nd_dpa_in, buf, n); 492 - 493 - nd->nd_dpa_in += n; 494 - 495 - buf += n; 496 - nbuf -= n; 497 - 498 - if (nd->nd_dpa_in >= DPA_MAX) 499 - pr_info_ratelimited("%s - nd->nd_dpa_in (%i) >= DPA_MAX\n", 500 - __func__, nd->nd_dpa_in); 501 - 502 - /* 503 - * Wakeup any thread waiting for data 504 - */ 505 - if (nd->nd_dpa_flag & DPA_WAIT_DATA) { 506 - nd->nd_dpa_flag &= ~DPA_WAIT_DATA; 507 - wake_up_interruptible(&nd->nd_dpa_wqueue); 508 - } 509 - } 510 - 511 - /* 512 - * Release the DPA lock. 513 - */ 514 - spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); 515 - } 516 - 517 - /** 518 - * dgrp_monitor_data() -- builds a DPA data packet 519 - * @nd: pointer to a node structure 520 - * @type: type of message to be logged in the DPA buffer 521 - * @buf: buffer of data to be logged in the DPA buffer 522 - * @size -- number of bytes in the "buf" buffer 523 - */ 524 - void dgrp_dpa_data(struct nd_struct *nd, int type, u8 *buf, int size) 525 - { 526 - u8 header[5]; 527 - 528 - header[0] = type; 529 - 530 - put_unaligned_be32(size, header + 1); 531 - 532 - dgrp_dpa(nd, header, sizeof(header)); 533 - dgrp_dpa(nd, buf, size); 534 - }
-105
drivers/staging/dgrp/dgrp_driver.c
··· 1 - /* 2 - * 3 - * Copyright 1999-2003 Digi International (www.digi.com) 4 - * Jeff Randall 5 - * James Puzzo <jamesp at digi dot com> 6 - * Scott Kilau <Scott_Kilau at digi dot com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2, or (at your option) 11 - * any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 15 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 - * PURPOSE. See the GNU General Public License for more details. 17 - * 18 - */ 19 - 20 - /* 21 - * Driver specific includes 22 - */ 23 - #include <linux/module.h> 24 - #include <linux/slab.h> 25 - #include <linux/tty.h> 26 - 27 - /* 28 - * PortServer includes 29 - */ 30 - #include "dgrp_common.h" 31 - 32 - 33 - MODULE_LICENSE("GPL"); 34 - MODULE_AUTHOR("Digi International, http://www.digi.com"); 35 - MODULE_DESCRIPTION("RealPort driver for Digi's ethernet-based serial connectivity product line"); 36 - MODULE_VERSION(DIGI_VERSION); 37 - 38 - struct list_head nd_struct_list; 39 - struct dgrp_poll_data dgrp_poll_data; 40 - 41 - int dgrp_register_cudevices = 1;/* Turn on/off registering legacy cu devices */ 42 - int dgrp_register_prdevices = 1;/* Turn on/off registering transparent print */ 43 - int dgrp_poll_tick = 20; /* Poll interval - in ms */ 44 - 45 - module_param_named(register_cudevices, dgrp_register_cudevices, int, 0644); 46 - MODULE_PARM_DESC(register_cudevices, "Turn on/off registering legacy cu devices"); 47 - 48 - module_param_named(register_prdevices, dgrp_register_prdevices, int, 0644); 49 - MODULE_PARM_DESC(register_prdevices, "Turn on/off registering transparent print devices"); 50 - 51 - module_param_named(pollrate, dgrp_poll_tick, int, 0644); 52 - MODULE_PARM_DESC(pollrate, "Poll interval in ms"); 53 - 54 - /* 55 - * init_module() 56 - * 57 - * Module load. This is where it all starts. 58 - */ 59 - static int __init dgrp_init_module(void) 60 - { 61 - int ret; 62 - 63 - INIT_LIST_HEAD(&nd_struct_list); 64 - 65 - spin_lock_init(&dgrp_poll_data.poll_lock); 66 - init_timer(&dgrp_poll_data.timer); 67 - dgrp_poll_data.poll_tick = dgrp_poll_tick; 68 - dgrp_poll_data.timer.function = dgrp_poll_handler; 69 - dgrp_poll_data.timer.data = (unsigned long) &dgrp_poll_data; 70 - 71 - ret = dgrp_create_class_sysfs_files(); 72 - if (ret) 73 - return ret; 74 - 75 - dgrp_register_proc(); 76 - 77 - return 0; 78 - } 79 - 80 - 81 - /* 82 - * Module unload. This is where it all ends. 83 - */ 84 - static void __exit dgrp_cleanup_module(void) 85 - { 86 - struct nd_struct *nd, *next; 87 - 88 - /* 89 - * Attempting to free resources in backwards 90 - * order of allocation, in case that helps 91 - * memory pool fragmentation. 92 - */ 93 - dgrp_unregister_proc(); 94 - 95 - dgrp_remove_class_sysfs_files(); 96 - 97 - 98 - list_for_each_entry_safe(nd, next, &nd_struct_list, list) { 99 - dgrp_tty_uninit(nd); 100 - kfree(nd); 101 - } 102 - } 103 - 104 - module_init(dgrp_init_module); 105 - module_exit(dgrp_cleanup_module);
-327
drivers/staging/dgrp/dgrp_mon_ops.c
··· 1 - /***************************************************************************** 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - /* 19 - * 20 - * Filename: 21 - * 22 - * dgrp_mon_ops.c 23 - * 24 - * Description: 25 - * 26 - * Handle the file operations required for the "monitor" devices. 27 - * Includes those functions required to register the "mon" devices 28 - * in "/proc". 29 - * 30 - * Author: 31 - * 32 - * James A. Puzzo 33 - * 34 - */ 35 - 36 - #include <linux/module.h> 37 - #include <linux/tty.h> 38 - #include <linux/sched.h> 39 - #include <asm/unaligned.h> 40 - #include <linux/slab.h> 41 - #include <linux/proc_fs.h> 42 - #include <linux/uaccess.h> 43 - 44 - #include "dgrp_common.h" 45 - 46 - /* File operation declarations */ 47 - static int dgrp_mon_open(struct inode *, struct file *); 48 - static int dgrp_mon_release(struct inode *, struct file *); 49 - static ssize_t dgrp_mon_read(struct file *, char __user *, size_t, loff_t *); 50 - static long dgrp_mon_ioctl(struct file *file, unsigned int cmd, 51 - unsigned long arg); 52 - 53 - const struct file_operations dgrp_mon_ops = { 54 - .owner = THIS_MODULE, 55 - .read = dgrp_mon_read, 56 - .unlocked_ioctl = dgrp_mon_ioctl, 57 - .open = dgrp_mon_open, 58 - .release = dgrp_mon_release, 59 - }; 60 - 61 - /** 62 - * dgrp_mon_open() -- open /proc/dgrp/ports device for a PortServer 63 - * @inode: struct inode * 64 - * @file: struct file * 65 - * 66 - * Open function to open the /proc/dgrp/ports device for a PortServer. 67 - */ 68 - static int dgrp_mon_open(struct inode *inode, struct file *file) 69 - { 70 - struct nd_struct *nd; 71 - struct timeval tv; 72 - uint32_t time; 73 - u8 *buf; 74 - int rtn; 75 - 76 - rtn = try_module_get(THIS_MODULE); 77 - if (!rtn) 78 - return -ENXIO; 79 - 80 - rtn = 0; 81 - 82 - if (!capable(CAP_SYS_ADMIN)) { 83 - rtn = -EPERM; 84 - goto done; 85 - } 86 - 87 - /* 88 - * Make sure that the "private_data" field hasn't already been used. 89 - */ 90 - if (file->private_data) { 91 - rtn = -EINVAL; 92 - goto done; 93 - } 94 - 95 - /* 96 - * Get the node pointer, and fail if it doesn't exist. 97 - */ 98 - nd = PDE_DATA(inode); 99 - if (!nd) { 100 - rtn = -ENXIO; 101 - goto done; 102 - } 103 - 104 - file->private_data = (void *) nd; 105 - 106 - /* 107 - * Allocate the monitor buffer. 108 - */ 109 - 110 - /* 111 - * Grab the MON lock. 112 - */ 113 - down(&nd->nd_mon_semaphore); 114 - 115 - if (nd->nd_mon_buf) { 116 - rtn = -EBUSY; 117 - goto done_up; 118 - } 119 - 120 - nd->nd_mon_buf = kmalloc(MON_MAX, GFP_KERNEL); 121 - 122 - if (!nd->nd_mon_buf) { 123 - rtn = -ENOMEM; 124 - goto done_up; 125 - } 126 - 127 - /* 128 - * Enter an RPDUMP file header into the buffer. 129 - */ 130 - 131 - buf = nd->nd_mon_buf; 132 - 133 - strcpy(buf, RPDUMP_MAGIC); 134 - buf += strlen(buf) + 1; 135 - 136 - do_gettimeofday(&tv); 137 - 138 - /* 139 - * tv.tv_sec might be a 64 bit quantity. Pare 140 - * it down to 32 bits before attempting to encode 141 - * it. 142 - */ 143 - time = (uint32_t) (tv.tv_sec & 0xffffffff); 144 - 145 - put_unaligned_be32(time, buf); 146 - put_unaligned_be16(0, buf + 4); 147 - buf += 6; 148 - 149 - if (nd->nd_tx_module) { 150 - buf[0] = RPDUMP_CLIENT; 151 - put_unaligned_be32(0, buf + 1); 152 - put_unaligned_be16(1, buf + 5); 153 - buf[7] = 0xf0 + nd->nd_tx_module; 154 - buf += 8; 155 - } 156 - 157 - if (nd->nd_rx_module) { 158 - buf[0] = RPDUMP_SERVER; 159 - put_unaligned_be32(0, buf + 1); 160 - put_unaligned_be16(1, buf + 5); 161 - buf[7] = 0xf0 + nd->nd_rx_module; 162 - buf += 8; 163 - } 164 - 165 - nd->nd_mon_out = 0; 166 - nd->nd_mon_in = buf - nd->nd_mon_buf; 167 - nd->nd_mon_lbolt = jiffies; 168 - 169 - done_up: 170 - up(&nd->nd_mon_semaphore); 171 - 172 - done: 173 - if (rtn) 174 - module_put(THIS_MODULE); 175 - return rtn; 176 - } 177 - 178 - 179 - /** 180 - * dgrp_mon_release() - Close the MON device for a particular PortServer 181 - * @inode: struct inode * 182 - * @file: struct file * 183 - */ 184 - static int dgrp_mon_release(struct inode *inode, struct file *file) 185 - { 186 - struct nd_struct *nd; 187 - 188 - /* 189 - * Get the node pointer, and quit if it doesn't exist. 190 - */ 191 - nd = (struct nd_struct *)(file->private_data); 192 - if (!nd) 193 - goto done; 194 - 195 - /* 196 - * Free the monitor buffer. 197 - */ 198 - 199 - down(&nd->nd_mon_semaphore); 200 - 201 - kfree(nd->nd_mon_buf); 202 - nd->nd_mon_buf = NULL; 203 - nd->nd_mon_out = nd->nd_mon_in; 204 - 205 - /* 206 - * Wakeup any thread waiting for buffer space. 207 - */ 208 - 209 - if (nd->nd_mon_flag & MON_WAIT_SPACE) { 210 - nd->nd_mon_flag &= ~MON_WAIT_SPACE; 211 - wake_up_interruptible(&nd->nd_mon_wqueue); 212 - } 213 - 214 - up(&nd->nd_mon_semaphore); 215 - 216 - /* 217 - * Make sure there is no thread in the middle of writing a packet. 218 - */ 219 - down(&nd->nd_net_semaphore); 220 - up(&nd->nd_net_semaphore); 221 - 222 - done: 223 - module_put(THIS_MODULE); 224 - file->private_data = NULL; 225 - return 0; 226 - } 227 - 228 - /** 229 - * dgrp_mon_read() -- Copy data from the monitoring buffer to the user 230 - */ 231 - static ssize_t dgrp_mon_read(struct file *file, char __user *buf, size_t count, 232 - loff_t *ppos) 233 - { 234 - struct nd_struct *nd; 235 - int r; 236 - int offset = 0; 237 - int res = 0; 238 - ssize_t rtn; 239 - 240 - /* 241 - * Get the node pointer, and quit if it doesn't exist. 242 - */ 243 - nd = (struct nd_struct *)(file->private_data); 244 - if (!nd) 245 - return -ENXIO; 246 - 247 - /* 248 - * Wait for some data to appear in the buffer. 249 - */ 250 - 251 - down(&nd->nd_mon_semaphore); 252 - 253 - for (;;) { 254 - res = (nd->nd_mon_in - nd->nd_mon_out) & MON_MASK; 255 - 256 - if (res) 257 - break; 258 - 259 - nd->nd_mon_flag |= MON_WAIT_DATA; 260 - 261 - up(&nd->nd_mon_semaphore); 262 - 263 - /* 264 - * Go to sleep waiting until the condition becomes true. 265 - */ 266 - rtn = wait_event_interruptible(nd->nd_mon_wqueue, 267 - ((nd->nd_mon_flag & MON_WAIT_DATA) == 0)); 268 - 269 - if (rtn) 270 - return rtn; 271 - 272 - down(&nd->nd_mon_semaphore); 273 - } 274 - 275 - /* 276 - * Read whatever is there. 277 - */ 278 - 279 - if (res > count) 280 - res = count; 281 - 282 - r = MON_MAX - nd->nd_mon_out; 283 - 284 - if (r <= res) { 285 - rtn = copy_to_user((void __user *)buf, 286 - nd->nd_mon_buf + nd->nd_mon_out, r); 287 - if (rtn) { 288 - up(&nd->nd_mon_semaphore); 289 - return -EFAULT; 290 - } 291 - 292 - nd->nd_mon_out = 0; 293 - res -= r; 294 - offset = r; 295 - } 296 - 297 - rtn = copy_to_user((void __user *) buf + offset, 298 - nd->nd_mon_buf + nd->nd_mon_out, res); 299 - if (rtn) { 300 - up(&nd->nd_mon_semaphore); 301 - return -EFAULT; 302 - } 303 - 304 - nd->nd_mon_out += res; 305 - 306 - *ppos += res; 307 - 308 - up(&nd->nd_mon_semaphore); 309 - 310 - /* 311 - * Wakeup any thread waiting for buffer space. 312 - */ 313 - 314 - if (nd->nd_mon_flag & MON_WAIT_SPACE) { 315 - nd->nd_mon_flag &= ~MON_WAIT_SPACE; 316 - wake_up_interruptible(&nd->nd_mon_wqueue); 317 - } 318 - 319 - return res; 320 - } 321 - 322 - /* ioctl is not valid on monitor device */ 323 - static long dgrp_mon_ioctl(struct file *file, unsigned int cmd, 324 - unsigned long arg) 325 - { 326 - return -EINVAL; 327 - }
-3666
drivers/staging/dgrp/dgrp_net_ops.c
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - /* 19 - * 20 - * Filename: 21 - * 22 - * dgrp_net_ops.c 23 - * 24 - * Description: 25 - * 26 - * Handle the file operations required for the "network" devices. 27 - * Includes those functions required to register the "net" devices 28 - * in "/proc". 29 - * 30 - * Author: 31 - * 32 - * James A. Puzzo 33 - * 34 - */ 35 - 36 - #include <linux/module.h> 37 - #include <linux/proc_fs.h> 38 - #include <linux/slab.h> 39 - #include <linux/string.h> 40 - #include <linux/device.h> 41 - #include <linux/tty.h> 42 - #include <linux/tty_flip.h> 43 - #include <linux/spinlock.h> 44 - #include <linux/poll.h> 45 - #include <linux/sched.h> 46 - #include <linux/ratelimit.h> 47 - #include <asm/unaligned.h> 48 - 49 - #define MYFLIPLEN TBUF_MAX 50 - 51 - #include "dgrp_common.h" 52 - 53 - #define TTY_FLIPBUF_SIZE 512 54 - #define DEVICE_NAME_SIZE 50 55 - 56 - /* 57 - * Generic helper function declarations 58 - */ 59 - static void parity_scan(struct ch_struct *ch, unsigned char *cbuf, 60 - unsigned char *fbuf, int *len); 61 - 62 - /* 63 - * File operation declarations 64 - */ 65 - static int dgrp_net_open(struct inode *, struct file *); 66 - static int dgrp_net_release(struct inode *, struct file *); 67 - static ssize_t dgrp_net_read(struct file *, char __user *, size_t, loff_t *); 68 - static ssize_t dgrp_net_write(struct file *, const char __user *, size_t, 69 - loff_t *); 70 - static long dgrp_net_ioctl(struct file *file, unsigned int cmd, 71 - unsigned long arg); 72 - static unsigned int dgrp_net_select(struct file *file, 73 - struct poll_table_struct *table); 74 - 75 - const struct file_operations dgrp_net_ops = { 76 - .owner = THIS_MODULE, 77 - .read = dgrp_net_read, 78 - .write = dgrp_net_write, 79 - .poll = dgrp_net_select, 80 - .unlocked_ioctl = dgrp_net_ioctl, 81 - .open = dgrp_net_open, 82 - .release = dgrp_net_release, 83 - }; 84 - 85 - /** 86 - * dgrp_dump() -- prints memory for debugging purposes. 87 - * @mem: Memory location which should be printed to the console 88 - * @len: Number of bytes to be dumped 89 - */ 90 - static void dgrp_dump(u8 *mem, int len) 91 - { 92 - int i; 93 - 94 - pr_debug("dgrp dump length = %d, data = ", len); 95 - for (i = 0; i < len; ++i) 96 - pr_debug("%.2x ", mem[i]); 97 - pr_debug("\n"); 98 - } 99 - 100 - /** 101 - * dgrp_read_data_block() -- Read a data block 102 - * @ch: struct ch_struct * 103 - * @flipbuf: u8 * 104 - * @flipbuf_size: size of flipbuf 105 - */ 106 - static void dgrp_read_data_block(struct ch_struct *ch, u8 *flipbuf, 107 - int flipbuf_size) 108 - { 109 - int t; 110 - int n; 111 - 112 - if (flipbuf_size <= 0) 113 - return; 114 - 115 - t = RBUF_MAX - ch->ch_rout; 116 - n = flipbuf_size; 117 - 118 - if (n >= t) { 119 - memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, t); 120 - flipbuf += t; 121 - n -= t; 122 - ch->ch_rout = 0; 123 - } 124 - 125 - memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, n); 126 - flipbuf += n; 127 - ch->ch_rout += n; 128 - } 129 - 130 - 131 - /** 132 - * dgrp_input() -- send data to the line disipline 133 - * @ch: pointer to channel struct 134 - * 135 - * Copys the rbuf to the flipbuf and sends to line discipline. 136 - * Sends input buffer data to the line discipline. 137 - * 138 - */ 139 - static void dgrp_input(struct ch_struct *ch) 140 - { 141 - struct nd_struct *nd; 142 - struct tty_struct *tty; 143 - int data_len; 144 - int len; 145 - int tty_count; 146 - ulong lock_flags; 147 - u8 *myflipbuf; 148 - u8 *myflipflagbuf; 149 - 150 - if (!ch) 151 - return; 152 - 153 - nd = ch->ch_nd; 154 - 155 - if (!nd) 156 - return; 157 - 158 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 159 - 160 - myflipbuf = nd->nd_inputbuf; 161 - myflipflagbuf = nd->nd_inputflagbuf; 162 - 163 - if (!ch->ch_open_count) { 164 - ch->ch_rout = ch->ch_rin; 165 - goto out; 166 - } 167 - 168 - if (ch->ch_tun.un_flag & UN_CLOSING) { 169 - ch->ch_rout = ch->ch_rin; 170 - goto out; 171 - } 172 - 173 - tty = (ch->ch_tun).un_tty; 174 - 175 - 176 - if (!tty || tty->magic != TTY_MAGIC) { 177 - ch->ch_rout = ch->ch_rin; 178 - goto out; 179 - } 180 - 181 - tty_count = tty->count; 182 - if (!tty_count) { 183 - ch->ch_rout = ch->ch_rin; 184 - goto out; 185 - } 186 - 187 - if (tty->closing || test_bit(TTY_CLOSING, &tty->flags)) { 188 - ch->ch_rout = ch->ch_rin; 189 - goto out; 190 - } 191 - 192 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 193 - 194 - /* data_len should be the number of chars that we read in */ 195 - data_len = (ch->ch_rin - ch->ch_rout) & RBUF_MASK; 196 - 197 - /* len is the amount of data we are going to transfer here */ 198 - len = tty_buffer_request_room(&ch->port, data_len); 199 - 200 - /* Check DPA flow control */ 201 - if ((nd->nd_dpa_debug) && 202 - (nd->nd_dpa_flag & DPA_WAIT_SPACE) && 203 - (nd->nd_dpa_port == MINOR(tty_devnum(ch->ch_tun.un_tty)))) 204 - len = 0; 205 - 206 - if ((len) && !(ch->ch_flag & CH_RXSTOP)) { 207 - 208 - dgrp_read_data_block(ch, myflipbuf, len); 209 - 210 - if (I_PARMRK(tty) || I_BRKINT(tty) || I_INPCK(tty)) 211 - parity_scan(ch, myflipbuf, myflipflagbuf, &len); 212 - else 213 - memset(myflipflagbuf, TTY_NORMAL, len); 214 - 215 - if ((nd->nd_dpa_debug) && 216 - (nd->nd_dpa_port == PORT_NUM(MINOR(tty_devnum(tty))))) 217 - dgrp_dpa_data(nd, 1, myflipbuf, len); 218 - 219 - tty_insert_flip_string_flags(&ch->port, myflipbuf, 220 - myflipflagbuf, len); 221 - tty_flip_buffer_push(&ch->port); 222 - 223 - ch->ch_rxcount += len; 224 - } 225 - 226 - /* 227 - * Wake up any sleepers (maybe dgrp close) that might be waiting 228 - * for a channel flag state change. 229 - */ 230 - wake_up_interruptible(&ch->ch_flag_wait); 231 - return; 232 - 233 - out: 234 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 235 - } 236 - 237 - 238 - /* 239 - * parity_scan 240 - * 241 - * Loop to inspect each single character or 0xFF escape. 242 - * 243 - * if PARMRK & ~DOSMODE: 244 - * 0xFF 0xFF Normal 0xFF character, escaped 245 - * to eliminate confusion. 246 - * 0xFF 0x00 0x00 Break 247 - * 0xFF 0x00 CC Error character CC. 248 - * CC Normal character CC. 249 - * 250 - * if PARMRK & DOSMODE: 251 - * 0xFF 0x18 0x00 Break 252 - * 0xFF 0x08 0x00 Framing Error 253 - * 0xFF 0x04 0x00 Parity error 254 - * 0xFF 0x0C 0x00 Both Framing and Parity error 255 - * 256 - * TODO: do we need to do the XMODEM, XOFF, XON, XANY processing?? 257 - * as per protocol 258 - */ 259 - static void parity_scan(struct ch_struct *ch, unsigned char *cbuf, 260 - unsigned char *fbuf, int *len) 261 - { 262 - int l = *len; 263 - int count = 0; 264 - int DOS = ((ch->ch_iflag & IF_DOSMODE) == 0 ? 0 : 1); 265 - unsigned char *cout; /* character buffer */ 266 - unsigned char *fout; /* flag buffer */ 267 - unsigned char *in; 268 - unsigned char c; 269 - 270 - in = cbuf; 271 - cout = cbuf; 272 - fout = fbuf; 273 - 274 - while (l--) { 275 - c = *in; 276 - in++; 277 - 278 - switch (ch->ch_pscan_state) { 279 - default: 280 - /* reset to sanity and fall through */ 281 - ch->ch_pscan_state = 0; 282 - 283 - case 0: 284 - /* No FF seen yet */ 285 - if (c == 0xff) /* delete this character from stream */ 286 - ch->ch_pscan_state = 1; 287 - else { 288 - *cout++ = c; 289 - *fout++ = TTY_NORMAL; 290 - count += 1; 291 - } 292 - break; 293 - 294 - case 1: 295 - /* first FF seen */ 296 - if (c == 0xff) { 297 - /* doubled ff, transform to single ff */ 298 - *cout++ = c; 299 - *fout++ = TTY_NORMAL; 300 - count += 1; 301 - ch->ch_pscan_state = 0; 302 - } else { 303 - /* save value examination in next state */ 304 - ch->ch_pscan_savechar = c; 305 - ch->ch_pscan_state = 2; 306 - } 307 - break; 308 - 309 - case 2: 310 - /* third character of ff sequence */ 311 - *cout++ = c; 312 - if (DOS) { 313 - if (ch->ch_pscan_savechar & 0x10) 314 - *fout++ = TTY_BREAK; 315 - else if (ch->ch_pscan_savechar & 0x08) 316 - *fout++ = TTY_FRAME; 317 - else 318 - /* 319 - * either marked as a parity error, 320 - * indeterminate, or not in DOSMODE 321 - * call it a parity error 322 - */ 323 - *fout++ = TTY_PARITY; 324 - } else { 325 - /* case FF XX ?? where XX is not 00 */ 326 - if (ch->ch_pscan_savechar & 0xff) { 327 - /* this should not happen */ 328 - pr_info("%s: parity_scan: error unexpected byte\n", 329 - __func__); 330 - *fout++ = TTY_PARITY; 331 - } 332 - /* case FF 00 XX where XX is not 00 */ 333 - else if (c == 0xff) 334 - *fout++ = TTY_PARITY; 335 - /* case FF 00 00 */ 336 - else 337 - *fout++ = TTY_BREAK; 338 - 339 - } 340 - count += 1; 341 - ch->ch_pscan_state = 0; 342 - } 343 - } 344 - *len = count; 345 - } 346 - 347 - 348 - /** 349 - * dgrp_net_idle() -- Idle the network connection 350 - * @nd: pointer to node structure to idle 351 - */ 352 - static void dgrp_net_idle(struct nd_struct *nd) 353 - { 354 - struct ch_struct *ch; 355 - int i; 356 - 357 - nd->nd_tx_work = 1; 358 - 359 - nd->nd_state = NS_IDLE; 360 - nd->nd_flag = 0; 361 - 362 - for (i = nd->nd_seq_out; ; i = (i + 1) & SEQ_MASK) { 363 - if (!nd->nd_seq_wait[i]) { 364 - nd->nd_seq_wait[i] = 0; 365 - wake_up_interruptible(&nd->nd_seq_wque[i]); 366 - } 367 - 368 - if (i == nd->nd_seq_in) 369 - break; 370 - } 371 - 372 - nd->nd_seq_out = nd->nd_seq_in; 373 - 374 - nd->nd_unack = 0; 375 - nd->nd_remain = 0; 376 - 377 - nd->nd_tx_module = 0x10; 378 - nd->nd_rx_module = 0x00; 379 - 380 - for (i = 0, ch = nd->nd_chan; i < CHAN_MAX; i++, ch++) { 381 - ch->ch_state = CS_IDLE; 382 - 383 - ch->ch_otype = 0; 384 - ch->ch_otype_waiting = 0; 385 - } 386 - } 387 - 388 - /* 389 - * Increase the number of channels, waking up any 390 - * threads that might be waiting for the channels 391 - * to appear. 392 - */ 393 - static void increase_channel_count(struct nd_struct *nd, int n) 394 - { 395 - struct ch_struct *ch; 396 - struct device *classp; 397 - char name[DEVICE_NAME_SIZE]; 398 - int ret; 399 - u8 *buf; 400 - int i; 401 - 402 - for (i = nd->nd_chan_count; i < n; ++i) { 403 - ch = nd->nd_chan + i; 404 - 405 - /* FIXME: return a useful error instead! */ 406 - buf = kmalloc(TBUF_MAX, GFP_KERNEL); 407 - if (!buf) 408 - return; 409 - 410 - if (ch->ch_tbuf) 411 - pr_info_ratelimited("%s - ch_tbuf was not NULL\n", 412 - __func__); 413 - 414 - ch->ch_tbuf = buf; 415 - 416 - buf = kmalloc(RBUF_MAX, GFP_KERNEL); 417 - if (!buf) 418 - return; 419 - 420 - if (ch->ch_rbuf) 421 - pr_info("%s - ch_rbuf was not NULL\n", 422 - __func__); 423 - ch->ch_rbuf = buf; 424 - 425 - classp = tty_port_register_device(&ch->port, 426 - nd->nd_serial_ttdriver, i, 427 - NULL); 428 - 429 - ch->ch_tun.un_sysfs = classp; 430 - snprintf(name, DEVICE_NAME_SIZE, "tty_%d", i); 431 - 432 - dgrp_create_tty_sysfs(&ch->ch_tun, classp); 433 - ret = sysfs_create_link(&nd->nd_class_dev->kobj, 434 - &classp->kobj, name); 435 - 436 - /* NOTE: We don't support "cu" devices anymore, 437 - * so you will notice we don't register them 438 - * here anymore. */ 439 - if (dgrp_register_prdevices) { 440 - classp = tty_register_device(nd->nd_xprint_ttdriver, 441 - i, NULL); 442 - ch->ch_pun.un_sysfs = classp; 443 - snprintf(name, DEVICE_NAME_SIZE, "pr_%d", i); 444 - 445 - dgrp_create_tty_sysfs(&ch->ch_pun, classp); 446 - ret = sysfs_create_link(&nd->nd_class_dev->kobj, 447 - &classp->kobj, name); 448 - } 449 - 450 - nd->nd_chan_count = i + 1; 451 - wake_up_interruptible(&ch->ch_flag_wait); 452 - } 453 - } 454 - 455 - /* 456 - * Decrease the number of channels, and wake up any threads that might 457 - * be waiting on the channels that vanished. 458 - */ 459 - static void decrease_channel_count(struct nd_struct *nd, int n) 460 - { 461 - struct ch_struct *ch; 462 - char name[DEVICE_NAME_SIZE]; 463 - int i; 464 - 465 - for (i = nd->nd_chan_count - 1; i >= n; --i) { 466 - ch = nd->nd_chan + i; 467 - 468 - /* 469 - * Make any open ports inoperative. 470 - */ 471 - ch->ch_state = CS_IDLE; 472 - 473 - ch->ch_otype = 0; 474 - ch->ch_otype_waiting = 0; 475 - 476 - /* 477 - * Only "HANGUP" if we care about carrier 478 - * transitions and we are already open. 479 - */ 480 - if (ch->ch_open_count != 0) { 481 - ch->ch_flag |= CH_HANGUP; 482 - dgrp_carrier(ch); 483 - } 484 - 485 - /* 486 - * Unlike the CH_HANGUP flag above, use another 487 - * flag to indicate to the RealPort state machine 488 - * that this port has disappeared. 489 - */ 490 - if (ch->ch_open_count != 0) 491 - ch->ch_flag |= CH_PORT_GONE; 492 - 493 - wake_up_interruptible(&ch->ch_flag_wait); 494 - 495 - nd->nd_chan_count = i; 496 - 497 - kfree(ch->ch_tbuf); 498 - ch->ch_tbuf = NULL; 499 - 500 - kfree(ch->ch_rbuf); 501 - ch->ch_rbuf = NULL; 502 - 503 - nd->nd_chan_count = i; 504 - 505 - dgrp_remove_tty_sysfs(ch->ch_tun.un_sysfs); 506 - snprintf(name, DEVICE_NAME_SIZE, "tty_%d", i); 507 - sysfs_remove_link(&nd->nd_class_dev->kobj, name); 508 - tty_unregister_device(nd->nd_serial_ttdriver, i); 509 - 510 - /* 511 - * NOTE: We don't support "cu" devices anymore, so don't 512 - * unregister them here anymore. 513 - */ 514 - 515 - if (dgrp_register_prdevices) { 516 - dgrp_remove_tty_sysfs(ch->ch_pun.un_sysfs); 517 - snprintf(name, DEVICE_NAME_SIZE, "pr_%d", i); 518 - sysfs_remove_link(&nd->nd_class_dev->kobj, name); 519 - tty_unregister_device(nd->nd_xprint_ttdriver, i); 520 - } 521 - } 522 - } 523 - 524 - /** 525 - * dgrp_chan_count() -- Adjust the node channel count. 526 - * @nd: pointer to a node structure 527 - * @n: new value for channel count 528 - * 529 - * Adjusts the node channel count. If new ports have appeared, it tries 530 - * to signal those processes that might have been waiting for ports to 531 - * appear. If ports have disappeared it tries to signal those processes 532 - * that might be hung waiting for a response for the now non-existant port. 533 - */ 534 - static void dgrp_chan_count(struct nd_struct *nd, int n) 535 - { 536 - if (n == nd->nd_chan_count) 537 - return; 538 - 539 - if (n > nd->nd_chan_count) 540 - increase_channel_count(nd, n); 541 - 542 - if (n < nd->nd_chan_count) 543 - decrease_channel_count(nd, n); 544 - } 545 - 546 - /** 547 - * dgrp_monitor() -- send data to the device monitor queue 548 - * @nd: pointer to a node structure 549 - * @buf: data to copy to the monitoring buffer 550 - * @len: number of bytes to transfer to the buffer 551 - * 552 - * Called by the net device routines to send data to the device 553 - * monitor queue. If the device monitor buffer is too full to 554 - * accept the data, it waits until the buffer is ready. 555 - */ 556 - static void dgrp_monitor(struct nd_struct *nd, u8 *buf, int len) 557 - { 558 - int n; 559 - int r; 560 - int rtn; 561 - 562 - /* 563 - * Grab monitor lock. 564 - */ 565 - down(&nd->nd_mon_semaphore); 566 - 567 - /* 568 - * Loop while data remains. 569 - */ 570 - while ((len > 0) && (nd->nd_mon_buf)) { 571 - /* 572 - * Determine the amount of available space left in the 573 - * buffer. If there's none, wait until some appears. 574 - */ 575 - 576 - n = (nd->nd_mon_out - nd->nd_mon_in - 1) & MON_MASK; 577 - 578 - if (!n) { 579 - nd->nd_mon_flag |= MON_WAIT_SPACE; 580 - 581 - up(&nd->nd_mon_semaphore); 582 - 583 - /* 584 - * Go to sleep waiting until the condition becomes true. 585 - */ 586 - rtn = wait_event_interruptible(nd->nd_mon_wqueue, 587 - ((nd->nd_mon_flag & MON_WAIT_SPACE) == 0)); 588 - 589 - /* FIXME: really ignore rtn? */ 590 - 591 - /* 592 - * We can't exit here if we receive a signal, since 593 - * to do so would trash the debug stream. 594 - */ 595 - 596 - down(&nd->nd_mon_semaphore); 597 - 598 - continue; 599 - } 600 - 601 - /* 602 - * Copy as much data as will fit. 603 - */ 604 - 605 - if (n > len) 606 - n = len; 607 - 608 - r = MON_MAX - nd->nd_mon_in; 609 - 610 - if (r <= n) { 611 - memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, r); 612 - 613 - n -= r; 614 - 615 - nd->nd_mon_in = 0; 616 - 617 - buf += r; 618 - len -= r; 619 - } 620 - 621 - memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, n); 622 - 623 - nd->nd_mon_in += n; 624 - 625 - buf += n; 626 - len -= n; 627 - 628 - if (nd->nd_mon_in >= MON_MAX) 629 - pr_info_ratelimited("%s - nd_mon_in (%i) >= MON_MAX\n", 630 - __func__, nd->nd_mon_in); 631 - 632 - /* 633 - * Wakeup any thread waiting for data 634 - */ 635 - 636 - if (nd->nd_mon_flag & MON_WAIT_DATA) { 637 - nd->nd_mon_flag &= ~MON_WAIT_DATA; 638 - wake_up_interruptible(&nd->nd_mon_wqueue); 639 - } 640 - } 641 - 642 - /* 643 - * Release the monitor lock. 644 - */ 645 - up(&nd->nd_mon_semaphore); 646 - } 647 - 648 - /** 649 - * dgrp_encode_time() -- Encodes rpdump time into a 4-byte quantity. 650 - * @nd: pointer to a node structure 651 - * @buf: destination buffer 652 - * 653 - * Encodes "rpdump" time into a 4-byte quantity. Time is measured since 654 - * open. 655 - */ 656 - static void dgrp_encode_time(struct nd_struct *nd, u8 *buf) 657 - { 658 - ulong t; 659 - 660 - /* 661 - * Convert time in HZ since open to time in milliseconds 662 - * since open. 663 - */ 664 - t = jiffies - nd->nd_mon_lbolt; 665 - t = 1000 * (t / HZ) + 1000 * (t % HZ) / HZ; 666 - 667 - put_unaligned_be32((uint)(t & 0xffffffff), buf); 668 - } 669 - 670 - 671 - 672 - /** 673 - * dgrp_monitor_message() -- Builds a rpdump style message. 674 - * @nd: pointer to a node structure 675 - * @message: destination buffer 676 - */ 677 - static void dgrp_monitor_message(struct nd_struct *nd, char *message) 678 - { 679 - u8 header[7]; 680 - int n; 681 - 682 - header[0] = RPDUMP_MESSAGE; 683 - 684 - dgrp_encode_time(nd, header + 1); 685 - 686 - n = strlen(message); 687 - 688 - put_unaligned_be16(n, header + 5); 689 - 690 - dgrp_monitor(nd, header, sizeof(header)); 691 - dgrp_monitor(nd, (u8 *) message, n); 692 - } 693 - 694 - 695 - 696 - /** 697 - * dgrp_monitor_reset() -- Note a reset in the monitoring buffer. 698 - * @nd: pointer to a node structure 699 - */ 700 - static void dgrp_monitor_reset(struct nd_struct *nd) 701 - { 702 - u8 header[5]; 703 - 704 - header[0] = RPDUMP_RESET; 705 - 706 - dgrp_encode_time(nd, header + 1); 707 - 708 - dgrp_monitor(nd, header, sizeof(header)); 709 - } 710 - 711 - /** 712 - * dgrp_monitor_data() -- builds a monitor data packet 713 - * @nd: pointer to a node structure 714 - * @type: type of message to be logged 715 - * @buf: data to be logged 716 - * @size: number of bytes in the buffer 717 - */ 718 - static void dgrp_monitor_data(struct nd_struct *nd, u8 type, u8 *buf, int size) 719 - { 720 - u8 header[7]; 721 - 722 - header[0] = type; 723 - 724 - dgrp_encode_time(nd, header + 1); 725 - 726 - put_unaligned_be16(size, header + 5); 727 - 728 - dgrp_monitor(nd, header, sizeof(header)); 729 - dgrp_monitor(nd, buf, size); 730 - } 731 - 732 - static int alloc_nd_buffers(struct nd_struct *nd) 733 - { 734 - 735 - nd->nd_iobuf = NULL; 736 - nd->nd_writebuf = NULL; 737 - nd->nd_inputbuf = NULL; 738 - nd->nd_inputflagbuf = NULL; 739 - 740 - /* 741 - * Allocate the network read/write buffer. 742 - */ 743 - nd->nd_iobuf = kzalloc(UIO_MAX + 10, GFP_KERNEL); 744 - if (!nd->nd_iobuf) 745 - goto out_err; 746 - 747 - /* 748 - * Allocate a buffer for doing the copy from user space to 749 - * kernel space in the write routines. 750 - */ 751 - nd->nd_writebuf = kzalloc(WRITEBUFLEN, GFP_KERNEL); 752 - if (!nd->nd_writebuf) 753 - goto out_err; 754 - 755 - /* 756 - * Allocate a buffer for doing the copy from kernel space to 757 - * tty buffer space in the read routines. 758 - */ 759 - nd->nd_inputbuf = kzalloc(MYFLIPLEN, GFP_KERNEL); 760 - if (!nd->nd_inputbuf) 761 - goto out_err; 762 - 763 - /* 764 - * Allocate a buffer for doing the copy from kernel space to 765 - * tty buffer space in the read routines. 766 - */ 767 - nd->nd_inputflagbuf = kzalloc(MYFLIPLEN, GFP_KERNEL); 768 - if (!nd->nd_inputflagbuf) 769 - goto out_err; 770 - 771 - return 0; 772 - 773 - out_err: 774 - kfree(nd->nd_iobuf); 775 - kfree(nd->nd_writebuf); 776 - kfree(nd->nd_inputbuf); 777 - kfree(nd->nd_inputflagbuf); 778 - return -ENOMEM; 779 - } 780 - 781 - /* 782 - * dgrp_net_open() -- Open the NET device for a particular PortServer 783 - */ 784 - static int dgrp_net_open(struct inode *inode, struct file *file) 785 - { 786 - struct nd_struct *nd; 787 - ulong lock_flags; 788 - int rtn; 789 - 790 - rtn = try_module_get(THIS_MODULE); 791 - if (!rtn) 792 - return -EAGAIN; 793 - 794 - if (!capable(CAP_SYS_ADMIN)) { 795 - rtn = -EPERM; 796 - goto done; 797 - } 798 - 799 - /* 800 - * Make sure that the "private_data" field hasn't already been used. 801 - */ 802 - if (file->private_data) { 803 - rtn = -EINVAL; 804 - goto done; 805 - } 806 - 807 - /* 808 - * Get the node pointer, and fail if it doesn't exist. 809 - */ 810 - nd = PDE_DATA(inode); 811 - if (!nd) { 812 - rtn = -ENXIO; 813 - goto done; 814 - } 815 - 816 - file->private_data = (void *) nd; 817 - 818 - /* 819 - * Grab the NET lock. 820 - */ 821 - down(&nd->nd_net_semaphore); 822 - 823 - if (nd->nd_state != NS_CLOSED) { 824 - rtn = -EBUSY; 825 - goto unlock; 826 - } 827 - 828 - /* 829 - * Initialize the link speed parameters. 830 - */ 831 - 832 - nd->nd_link.lk_fast_rate = UIO_MAX; 833 - nd->nd_link.lk_slow_rate = UIO_MAX; 834 - 835 - nd->nd_link.lk_fast_delay = 1000; 836 - nd->nd_link.lk_slow_delay = 1000; 837 - 838 - nd->nd_link.lk_header_size = 46; 839 - 840 - 841 - rtn = alloc_nd_buffers(nd); 842 - if (rtn) 843 - goto unlock; 844 - 845 - /* 846 - * The port is now open, so move it to the IDLE state 847 - */ 848 - dgrp_net_idle(nd); 849 - 850 - nd->nd_tx_time = jiffies; 851 - 852 - /* 853 - * If the polling routing is not running, start it running here 854 - */ 855 - spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags); 856 - 857 - if (!dgrp_poll_data.node_active_count) { 858 - dgrp_poll_data.node_active_count = 2; 859 - dgrp_poll_data.timer.expires = jiffies + 860 - dgrp_poll_tick * HZ / 1000; 861 - add_timer(&dgrp_poll_data.timer); 862 - } 863 - 864 - spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags); 865 - 866 - dgrp_monitor_message(nd, "Net Open"); 867 - 868 - unlock: 869 - /* 870 - * Release the NET lock. 871 - */ 872 - up(&nd->nd_net_semaphore); 873 - 874 - done: 875 - if (rtn) 876 - module_put(THIS_MODULE); 877 - 878 - return rtn; 879 - } 880 - 881 - /* dgrp_net_release() -- close the NET device for a particular PortServer */ 882 - static int dgrp_net_release(struct inode *inode, struct file *file) 883 - { 884 - struct nd_struct *nd; 885 - ulong lock_flags; 886 - 887 - nd = (struct nd_struct *)(file->private_data); 888 - if (!nd) 889 - goto done; 890 - 891 - /* TODO : historical locking placeholder */ 892 - /* 893 - * In the HPUX version of the RealPort driver (which served as a basis 894 - * for this driver) this locking code was used. Saved if ever we need 895 - * to review the locking under Linux. 896 - */ 897 - /* spinlock(&nd->nd_lock); */ 898 - 899 - 900 - /* 901 - * Grab the NET lock. 902 - */ 903 - down(&nd->nd_net_semaphore); 904 - 905 - /* 906 - * Before "closing" the internal connection, make sure all 907 - * ports are "idle". 908 - */ 909 - dgrp_net_idle(nd); 910 - 911 - nd->nd_state = NS_CLOSED; 912 - nd->nd_flag = 0; 913 - 914 - /* 915 - * TODO ... must the wait queue be reset on close? 916 - * should any pending waiters be reset? 917 - * Let's decide to assert that the waitq is empty... and see 918 - * how soon we break. 919 - */ 920 - if (waitqueue_active(&nd->nd_tx_waitq)) 921 - pr_info("%s - expected waitqueue_active to be false\n", 922 - __func__); 923 - 924 - nd->nd_send = 0; 925 - 926 - kfree(nd->nd_iobuf); 927 - nd->nd_iobuf = NULL; 928 - 929 - /* TODO : historical locking placeholder */ 930 - /* 931 - * In the HPUX version of the RealPort driver (which served as a basis 932 - * for this driver) this locking code was used. Saved if ever we need 933 - * to review the locking under Linux. 934 - */ 935 - /* spinunlock( &nd->nd_lock ); */ 936 - 937 - 938 - kfree(nd->nd_writebuf); 939 - nd->nd_writebuf = NULL; 940 - 941 - kfree(nd->nd_inputbuf); 942 - nd->nd_inputbuf = NULL; 943 - 944 - kfree(nd->nd_inputflagbuf); 945 - nd->nd_inputflagbuf = NULL; 946 - 947 - /* TODO : historical locking placeholder */ 948 - /* 949 - * In the HPUX version of the RealPort driver (which served as a basis 950 - * for this driver) this locking code was used. Saved if ever we need 951 - * to review the locking under Linux. 952 - */ 953 - /* spinlock(&nd->nd_lock); */ 954 - 955 - /* 956 - * Set the active port count to zero. 957 - */ 958 - dgrp_chan_count(nd, 0); 959 - 960 - /* TODO : historical locking placeholder */ 961 - /* 962 - * In the HPUX version of the RealPort driver (which served as a basis 963 - * for this driver) this locking code was used. Saved if ever we need 964 - * to review the locking under Linux. 965 - */ 966 - /* spinunlock(&nd->nd_lock); */ 967 - 968 - /* 969 - * Release the NET lock. 970 - */ 971 - up(&nd->nd_net_semaphore); 972 - 973 - /* 974 - * Cause the poller to stop scheduling itself if this is 975 - * the last active node. 976 - */ 977 - spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags); 978 - 979 - if (dgrp_poll_data.node_active_count == 2) { 980 - del_timer(&dgrp_poll_data.timer); 981 - dgrp_poll_data.node_active_count = 0; 982 - } 983 - 984 - spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags); 985 - 986 - down(&nd->nd_net_semaphore); 987 - 988 - dgrp_monitor_message(nd, "Net Close"); 989 - 990 - up(&nd->nd_net_semaphore); 991 - 992 - done: 993 - module_put(THIS_MODULE); 994 - file->private_data = NULL; 995 - return 0; 996 - } 997 - 998 - /* used in dgrp_send to setup command header */ 999 - static inline u8 *set_cmd_header(u8 *b, u8 port, u8 cmd) 1000 - { 1001 - *b++ = 0xb0 + (port & 0x0f); 1002 - *b++ = cmd; 1003 - return b; 1004 - } 1005 - 1006 - /** 1007 - * dgrp_send() -- build a packet for transmission to the server 1008 - * @nd: pointer to a node structure 1009 - * @tmax: maximum bytes to transmit 1010 - * 1011 - * returns number of bytes sent 1012 - */ 1013 - static int dgrp_send(struct nd_struct *nd, long tmax) 1014 - { 1015 - struct ch_struct *ch = nd->nd_chan; 1016 - u8 *b; 1017 - u8 *buf; 1018 - u8 *mbuf; 1019 - u8 port; 1020 - int mod; 1021 - long send; 1022 - int maxport; 1023 - long lastport = -1; 1024 - ushort rwin; 1025 - long in; 1026 - ushort n; 1027 - long t; 1028 - long ttotal; 1029 - long tchan; 1030 - long tsend; 1031 - ushort tsafe; 1032 - long work; 1033 - long send_sync; 1034 - long wanted_sync_port = -1; 1035 - ushort tdata[CHAN_MAX]; 1036 - long used_buffer; 1037 - 1038 - mbuf = nd->nd_iobuf + UIO_BASE; 1039 - buf = b = mbuf; 1040 - 1041 - send_sync = nd->nd_link.lk_slow_rate < UIO_MAX; 1042 - 1043 - ttotal = 0; 1044 - tchan = 0; 1045 - 1046 - memset(tdata, 0, sizeof(tdata)); 1047 - 1048 - 1049 - /* 1050 - * If there are any outstanding requests to be serviced, 1051 - * service them here. 1052 - */ 1053 - if (nd->nd_send & NR_PASSWORD) { 1054 - 1055 - /* 1056 - * Send Password response. 1057 - */ 1058 - 1059 - b[0] = 0xfc; 1060 - b[1] = 0x20; 1061 - put_unaligned_be16(strlen(nd->password), b + 2); 1062 - b += 4; 1063 - b += strlen(nd->password); 1064 - nd->nd_send &= ~(NR_PASSWORD); 1065 - } 1066 - 1067 - 1068 - /* 1069 - * Loop over all modules to generate commands, and determine 1070 - * the amount of data queued for transmit. 1071 - */ 1072 - 1073 - for (mod = 0, port = 0; port < nd->nd_chan_count; mod++) { 1074 - /* 1075 - * If this is not the current module, enter a module select 1076 - * code in the buffer. 1077 - */ 1078 - 1079 - if (mod != nd->nd_tx_module) 1080 - mbuf = ++b; 1081 - 1082 - /* 1083 - * Loop to process one module. 1084 - */ 1085 - 1086 - maxport = port + 16; 1087 - 1088 - if (maxport > nd->nd_chan_count) 1089 - maxport = nd->nd_chan_count; 1090 - 1091 - for (; port < maxport; port++, ch++) { 1092 - /* 1093 - * Switch based on channel state. 1094 - */ 1095 - 1096 - switch (ch->ch_state) { 1097 - /* 1098 - * Send requests when the port is closed, and there 1099 - * are no Open, Close or Cancel requests expected. 1100 - */ 1101 - 1102 - case CS_IDLE: 1103 - /* 1104 - * Wait until any open error code 1105 - * has been delivered to all 1106 - * associated ports. 1107 - */ 1108 - 1109 - if (ch->ch_open_error) { 1110 - if (ch->ch_wait_count[ch->ch_otype]) { 1111 - work = 1; 1112 - break; 1113 - } 1114 - 1115 - ch->ch_open_error = 0; 1116 - } 1117 - 1118 - /* 1119 - * Wait until the channel HANGUP flag is reset 1120 - * before sending the first open. We can only 1121 - * get to this state after a server disconnect. 1122 - */ 1123 - 1124 - if ((ch->ch_flag & CH_HANGUP) != 0) 1125 - break; 1126 - 1127 - /* 1128 - * If recovering from a TCP disconnect, or if 1129 - * there is an immediate open pending, send an 1130 - * Immediate Open request. 1131 - */ 1132 - if ((ch->ch_flag & CH_PORT_GONE) || 1133 - ch->ch_wait_count[OTYPE_IMMEDIATE] != 0) { 1134 - b = set_cmd_header(b, port, 10); 1135 - *b++ = 0; 1136 - 1137 - ch->ch_state = CS_WAIT_OPEN; 1138 - ch->ch_otype = OTYPE_IMMEDIATE; 1139 - break; 1140 - } 1141 - 1142 - /* 1143 - * If there is no Persistent or Incoming Open on the wait 1144 - * list in the server, and a thread is waiting for a 1145 - * Persistent or Incoming Open, send a Persistent or Incoming 1146 - * Open Request. 1147 - */ 1148 - if (ch->ch_otype_waiting == 0) { 1149 - if (ch->ch_wait_count[OTYPE_PERSISTENT] != 0) { 1150 - b = set_cmd_header(b, port, 10); 1151 - *b++ = 1; 1152 - 1153 - ch->ch_state = CS_WAIT_OPEN; 1154 - ch->ch_otype = OTYPE_PERSISTENT; 1155 - } else if (ch->ch_wait_count[OTYPE_INCOMING] != 0) { 1156 - b = set_cmd_header(b, port, 10); 1157 - *b++ = 2; 1158 - 1159 - ch->ch_state = CS_WAIT_OPEN; 1160 - ch->ch_otype = OTYPE_INCOMING; 1161 - } 1162 - break; 1163 - } 1164 - 1165 - /* 1166 - * If a Persistent or Incoming Open is pending in 1167 - * the server, but there is no longer an open 1168 - * thread waiting for it, cancel the request. 1169 - */ 1170 - 1171 - if (ch->ch_wait_count[ch->ch_otype_waiting] == 0) { 1172 - b = set_cmd_header(b, port, 10); 1173 - *b++ = 4; 1174 - 1175 - ch->ch_state = CS_WAIT_CANCEL; 1176 - ch->ch_otype = ch->ch_otype_waiting; 1177 - } 1178 - break; 1179 - 1180 - /* 1181 - * Send port parameter queries. 1182 - */ 1183 - case CS_SEND_QUERY: 1184 - /* 1185 - * Clear out all FEP state that might remain 1186 - * from the last connection. 1187 - */ 1188 - 1189 - ch->ch_flag |= CH_PARAM; 1190 - 1191 - ch->ch_flag &= ~CH_RX_FLUSH; 1192 - 1193 - ch->ch_expect = 0; 1194 - 1195 - ch->ch_s_tin = 0; 1196 - ch->ch_s_tpos = 0; 1197 - ch->ch_s_tsize = 0; 1198 - ch->ch_s_treq = 0; 1199 - ch->ch_s_elast = 0; 1200 - 1201 - ch->ch_s_rin = 0; 1202 - ch->ch_s_rwin = 0; 1203 - ch->ch_s_rsize = 0; 1204 - 1205 - ch->ch_s_tmax = 0; 1206 - ch->ch_s_ttime = 0; 1207 - ch->ch_s_rmax = 0; 1208 - ch->ch_s_rtime = 0; 1209 - ch->ch_s_rlow = 0; 1210 - ch->ch_s_rhigh = 0; 1211 - 1212 - ch->ch_s_brate = 0; 1213 - ch->ch_s_iflag = 0; 1214 - ch->ch_s_cflag = 0; 1215 - ch->ch_s_oflag = 0; 1216 - ch->ch_s_xflag = 0; 1217 - 1218 - ch->ch_s_mout = 0; 1219 - ch->ch_s_mflow = 0; 1220 - ch->ch_s_mctrl = 0; 1221 - ch->ch_s_xon = 0; 1222 - ch->ch_s_xoff = 0; 1223 - ch->ch_s_lnext = 0; 1224 - ch->ch_s_xxon = 0; 1225 - ch->ch_s_xxoff = 0; 1226 - 1227 - /* Send Sequence Request */ 1228 - b = set_cmd_header(b, port, 14); 1229 - 1230 - /* Configure Event Conditions Packet */ 1231 - b = set_cmd_header(b, port, 42); 1232 - put_unaligned_be16(0x02c0, b); 1233 - b += 2; 1234 - *b++ = (DM_DTR | DM_RTS | DM_CTS | 1235 - DM_DSR | DM_RI | DM_CD); 1236 - 1237 - /* Send Status Request */ 1238 - b = set_cmd_header(b, port, 16); 1239 - 1240 - /* Send Buffer Request */ 1241 - b = set_cmd_header(b, port, 20); 1242 - 1243 - /* Send Port Capability Request */ 1244 - b = set_cmd_header(b, port, 22); 1245 - 1246 - ch->ch_expect = (RR_SEQUENCE | 1247 - RR_STATUS | 1248 - RR_BUFFER | 1249 - RR_CAPABILITY); 1250 - 1251 - ch->ch_state = CS_WAIT_QUERY; 1252 - 1253 - /* Raise modem signals */ 1254 - b = set_cmd_header(b, port, 44); 1255 - 1256 - if (ch->ch_flag & CH_PORT_GONE) 1257 - ch->ch_s_mout = ch->ch_mout; 1258 - else 1259 - ch->ch_s_mout = ch->ch_mout = DM_DTR | DM_RTS; 1260 - 1261 - *b++ = ch->ch_mout; 1262 - *b++ = ch->ch_s_mflow = 0; 1263 - *b++ = ch->ch_s_mctrl = ch->ch_mctrl = 0; 1264 - 1265 - if (ch->ch_flag & CH_PORT_GONE) 1266 - ch->ch_flag &= ~CH_PORT_GONE; 1267 - 1268 - break; 1269 - 1270 - /* 1271 - * Handle normal open and ready mode. 1272 - */ 1273 - 1274 - case CS_READY: 1275 - 1276 - /* 1277 - * If the port is not open, and there are no 1278 - * no longer any ports requesting an open, 1279 - * then close the port. 1280 - */ 1281 - 1282 - if (ch->ch_open_count == 0 && 1283 - ch->ch_wait_count[ch->ch_otype] == 0) { 1284 - goto send_close; 1285 - } 1286 - 1287 - /* 1288 - * Process waiting input. 1289 - * 1290 - * If there is no one to read it, discard the data. 1291 - * 1292 - * Otherwise if we are not in fastcook mode, or if there is a 1293 - * fastcook thread waiting for data, send the data to the 1294 - * line discipline. 1295 - */ 1296 - if (ch->ch_rin != ch->ch_rout) { 1297 - if (ch->ch_tun.un_open_count == 0 || 1298 - (ch->ch_tun.un_flag & UN_CLOSING) || 1299 - (ch->ch_cflag & CF_CREAD) == 0) { 1300 - ch->ch_rout = ch->ch_rin; 1301 - } else if ((ch->ch_flag & CH_FAST_READ) == 0 || 1302 - ch->ch_inwait != 0) { 1303 - dgrp_input(ch); 1304 - 1305 - if (ch->ch_rin != ch->ch_rout) 1306 - work = 1; 1307 - } 1308 - } 1309 - 1310 - /* 1311 - * Handle receive flush, and changes to 1312 - * server port parameters. 1313 - */ 1314 - 1315 - if (ch->ch_flag & (CH_RX_FLUSH | CH_PARAM)) { 1316 - /* 1317 - * If we are in receive flush mode, 1318 - * and enough data has gone by, reset 1319 - * receive flush mode. 1320 - */ 1321 - if (ch->ch_flag & CH_RX_FLUSH) { 1322 - if (((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) > 1323 - ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) 1324 - ch->ch_flag &= ~CH_RX_FLUSH; 1325 - else 1326 - work = 1; 1327 - } 1328 - 1329 - /* 1330 - * Send TMAX, TTIME. 1331 - */ 1332 - 1333 - if (ch->ch_s_tmax != ch->ch_tmax || 1334 - ch->ch_s_ttime != ch->ch_ttime) { 1335 - b = set_cmd_header(b, port, 48); 1336 - 1337 - ch->ch_s_tmax = ch->ch_tmax; 1338 - ch->ch_s_ttime = ch->ch_ttime; 1339 - 1340 - put_unaligned_be16(ch->ch_s_tmax, 1341 - b); 1342 - b += 2; 1343 - 1344 - put_unaligned_be16(ch->ch_s_ttime, 1345 - b); 1346 - b += 2; 1347 - } 1348 - 1349 - /* 1350 - * Send RLOW, RHIGH. 1351 - */ 1352 - 1353 - if (ch->ch_s_rlow != ch->ch_rlow || 1354 - ch->ch_s_rhigh != ch->ch_rhigh) { 1355 - b = set_cmd_header(b, port, 45); 1356 - 1357 - ch->ch_s_rlow = ch->ch_rlow; 1358 - ch->ch_s_rhigh = ch->ch_rhigh; 1359 - 1360 - put_unaligned_be16(ch->ch_s_rlow, 1361 - b); 1362 - b += 2; 1363 - 1364 - put_unaligned_be16(ch->ch_s_rhigh, 1365 - b); 1366 - b += 2; 1367 - } 1368 - 1369 - /* 1370 - * Send BRATE, CFLAG, IFLAG, 1371 - * OFLAG, XFLAG. 1372 - */ 1373 - 1374 - if (ch->ch_s_brate != ch->ch_brate || 1375 - ch->ch_s_cflag != ch->ch_cflag || 1376 - ch->ch_s_iflag != ch->ch_iflag || 1377 - ch->ch_s_oflag != ch->ch_oflag || 1378 - ch->ch_s_xflag != ch->ch_xflag) { 1379 - b = set_cmd_header(b, port, 40); 1380 - 1381 - ch->ch_s_brate = ch->ch_brate; 1382 - ch->ch_s_cflag = ch->ch_cflag; 1383 - ch->ch_s_iflag = ch->ch_iflag; 1384 - ch->ch_s_oflag = ch->ch_oflag; 1385 - ch->ch_s_xflag = ch->ch_xflag; 1386 - 1387 - put_unaligned_be16(ch->ch_s_brate, 1388 - b); 1389 - b += 2; 1390 - 1391 - put_unaligned_be16(ch->ch_s_cflag, 1392 - b); 1393 - b += 2; 1394 - 1395 - put_unaligned_be16(ch->ch_s_iflag, 1396 - b); 1397 - b += 2; 1398 - 1399 - put_unaligned_be16(ch->ch_s_oflag, 1400 - b); 1401 - b += 2; 1402 - 1403 - put_unaligned_be16(ch->ch_s_xflag, 1404 - b); 1405 - b += 2; 1406 - } 1407 - 1408 - /* 1409 - * Send MOUT, MFLOW, MCTRL. 1410 - */ 1411 - 1412 - if (ch->ch_s_mout != ch->ch_mout || 1413 - ch->ch_s_mflow != ch->ch_mflow || 1414 - ch->ch_s_mctrl != ch->ch_mctrl) { 1415 - b = set_cmd_header(b, port, 44); 1416 - 1417 - *b++ = ch->ch_s_mout = ch->ch_mout; 1418 - *b++ = ch->ch_s_mflow = ch->ch_mflow; 1419 - *b++ = ch->ch_s_mctrl = ch->ch_mctrl; 1420 - } 1421 - 1422 - /* 1423 - * Send Flow control characters. 1424 - */ 1425 - 1426 - if (ch->ch_s_xon != ch->ch_xon || 1427 - ch->ch_s_xoff != ch->ch_xoff || 1428 - ch->ch_s_lnext != ch->ch_lnext || 1429 - ch->ch_s_xxon != ch->ch_xxon || 1430 - ch->ch_s_xxoff != ch->ch_xxoff) { 1431 - b = set_cmd_header(b, port, 46); 1432 - 1433 - *b++ = ch->ch_s_xon = ch->ch_xon; 1434 - *b++ = ch->ch_s_xoff = ch->ch_xoff; 1435 - *b++ = ch->ch_s_lnext = ch->ch_lnext; 1436 - *b++ = ch->ch_s_xxon = ch->ch_xxon; 1437 - *b++ = ch->ch_s_xxoff = ch->ch_xxoff; 1438 - } 1439 - 1440 - /* 1441 - * Send RMAX, RTIME. 1442 - */ 1443 - 1444 - if (ch->ch_s_rmax != ch->ch_rmax || 1445 - ch->ch_s_rtime != ch->ch_rtime) { 1446 - b = set_cmd_header(b, port, 47); 1447 - 1448 - ch->ch_s_rmax = ch->ch_rmax; 1449 - ch->ch_s_rtime = ch->ch_rtime; 1450 - 1451 - put_unaligned_be16(ch->ch_s_rmax, 1452 - b); 1453 - b += 2; 1454 - 1455 - put_unaligned_be16(ch->ch_s_rtime, 1456 - b); 1457 - b += 2; 1458 - } 1459 - 1460 - ch->ch_flag &= ~CH_PARAM; 1461 - wake_up_interruptible(&ch->ch_flag_wait); 1462 - } 1463 - 1464 - 1465 - /* 1466 - * Handle action commands. 1467 - */ 1468 - 1469 - if (ch->ch_send != 0) { 1470 - /* int send = ch->ch_send & ~ch->ch_expect; */ 1471 - send = ch->ch_send & ~ch->ch_expect; 1472 - 1473 - /* Send character immediate */ 1474 - if ((send & RR_TX_ICHAR) != 0) { 1475 - b = set_cmd_header(b, port, 60); 1476 - 1477 - *b++ = ch->ch_xon; 1478 - ch->ch_expect |= RR_TX_ICHAR; 1479 - } 1480 - 1481 - /* BREAK request */ 1482 - if ((send & RR_TX_BREAK) != 0) { 1483 - if (ch->ch_break_time != 0) { 1484 - b = set_cmd_header(b, port, 61); 1485 - put_unaligned_be16(ch->ch_break_time, 1486 - b); 1487 - b += 2; 1488 - 1489 - ch->ch_expect |= RR_TX_BREAK; 1490 - ch->ch_break_time = 0; 1491 - } else { 1492 - ch->ch_send &= ~RR_TX_BREAK; 1493 - ch->ch_flag &= ~CH_TX_BREAK; 1494 - wake_up_interruptible(&ch->ch_flag_wait); 1495 - } 1496 - } 1497 - 1498 - /* 1499 - * Flush input/output buffers. 1500 - */ 1501 - 1502 - if ((send & (RR_RX_FLUSH | RR_TX_FLUSH)) != 0) { 1503 - b = set_cmd_header(b, port, 62); 1504 - 1505 - *b++ = ((send & RR_TX_FLUSH) == 0 ? 1 : 1506 - (send & RR_RX_FLUSH) == 0 ? 2 : 3); 1507 - 1508 - if (send & RR_RX_FLUSH) { 1509 - ch->ch_flush_seq = nd->nd_seq_in; 1510 - ch->ch_flag |= CH_RX_FLUSH; 1511 - work = 1; 1512 - send_sync = 1; 1513 - wanted_sync_port = port; 1514 - } 1515 - 1516 - ch->ch_send &= ~(RR_RX_FLUSH | RR_TX_FLUSH); 1517 - } 1518 - 1519 - /* Pause input/output */ 1520 - if ((send & (RR_RX_STOP | RR_TX_STOP)) != 0) { 1521 - b = set_cmd_header(b, port, 63); 1522 - *b = 0; 1523 - 1524 - if ((send & RR_TX_STOP) != 0) 1525 - *b |= EV_OPU; 1526 - 1527 - if ((send & RR_RX_STOP) != 0) 1528 - *b |= EV_IPU; 1529 - 1530 - b++; 1531 - 1532 - ch->ch_send &= ~(RR_RX_STOP | RR_TX_STOP); 1533 - } 1534 - 1535 - /* Start input/output */ 1536 - if ((send & (RR_RX_START | RR_TX_START)) != 0) { 1537 - b = set_cmd_header(b, port, 64); 1538 - *b = 0; 1539 - 1540 - if ((send & RR_TX_START) != 0) 1541 - *b |= EV_OPU | EV_OPS | EV_OPX; 1542 - 1543 - if ((send & RR_RX_START) != 0) 1544 - *b |= EV_IPU | EV_IPS; 1545 - 1546 - b++; 1547 - 1548 - ch->ch_send &= ~(RR_RX_START | RR_TX_START); 1549 - } 1550 - } 1551 - 1552 - 1553 - /* 1554 - * Send a window sequence to acknowledge received data. 1555 - */ 1556 - 1557 - rwin = (ch->ch_s_rin + 1558 - ((ch->ch_rout - ch->ch_rin - 1) & RBUF_MASK)); 1559 - 1560 - n = (rwin - ch->ch_s_rwin) & 0xffff; 1561 - 1562 - if (n >= RBUF_MAX / 4) { 1563 - b[0] = 0xa0 + (port & 0xf); 1564 - ch->ch_s_rwin = rwin; 1565 - put_unaligned_be16(rwin, b + 1); 1566 - b += 3; 1567 - } 1568 - 1569 - /* 1570 - * If the terminal is waiting on LOW 1571 - * water or EMPTY, and the condition 1572 - * is now satisfied, call the line 1573 - * discipline to put more data in the 1574 - * buffer. 1575 - */ 1576 - 1577 - n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1578 - 1579 - if ((ch->ch_tun.un_flag & (UN_EMPTY|UN_LOW)) != 0) { 1580 - if ((ch->ch_tun.un_flag & UN_LOW) != 0 ? 1581 - (n <= TBUF_LOW) : 1582 - (n == 0 && ch->ch_s_tpos == ch->ch_s_tin)) { 1583 - ch->ch_tun.un_flag &= ~(UN_EMPTY|UN_LOW); 1584 - 1585 - if (waitqueue_active(&((ch->ch_tun.un_tty)->write_wait))) 1586 - wake_up_interruptible(&((ch->ch_tun.un_tty)->write_wait)); 1587 - tty_wakeup(ch->ch_tun.un_tty); 1588 - n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1589 - } 1590 - } 1591 - 1592 - /* 1593 - * If the printer is waiting on LOW 1594 - * water, TIME, EMPTY or PWAIT, and is 1595 - * now ready to put more data in the 1596 - * buffer, call the line discipline to 1597 - * do the job. 1598 - */ 1599 - 1600 - /* FIXME: jiffies - ch->ch_waketime can never 1601 - be < 0. Someone needs to work out what is 1602 - actually intended here */ 1603 - if (ch->ch_pun.un_open_count && 1604 - (ch->ch_pun.un_flag & 1605 - (UN_EMPTY|UN_TIME|UN_LOW|UN_PWAIT)) != 0) { 1606 - 1607 - if ((ch->ch_pun.un_flag & UN_LOW) != 0 ? 1608 - (n <= TBUF_LOW) : 1609 - (ch->ch_pun.un_flag & UN_TIME) != 0 ? 1610 - time_is_before_jiffies(ch->ch_waketime) : 1611 - (n == 0 && ch->ch_s_tpos == ch->ch_s_tin) && 1612 - ((ch->ch_pun.un_flag & UN_EMPTY) != 0 || 1613 - ((ch->ch_tun.un_open_count && 1614 - ch->ch_tun.un_tty->ops->chars_in_buffer) ? 1615 - (ch->ch_tun.un_tty->ops->chars_in_buffer)(ch->ch_tun.un_tty) == 0 1616 - : 1 1617 - ) 1618 - )) { 1619 - ch->ch_pun.un_flag &= ~(UN_EMPTY | UN_TIME | UN_LOW | UN_PWAIT); 1620 - 1621 - if (waitqueue_active(&((ch->ch_pun.un_tty)->write_wait))) 1622 - wake_up_interruptible(&((ch->ch_pun.un_tty)->write_wait)); 1623 - tty_wakeup(ch->ch_pun.un_tty); 1624 - n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1625 - 1626 - } else if ((ch->ch_pun.un_flag & UN_TIME) != 0) { 1627 - work = 1; 1628 - } 1629 - } 1630 - 1631 - 1632 - /* 1633 - * Determine the max number of bytes 1634 - * this port can send, including 1635 - * packet header overhead. 1636 - */ 1637 - 1638 - t = ((ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff); 1639 - 1640 - if (n > t) 1641 - n = t; 1642 - 1643 - if (n != 0) { 1644 - n += (n <= 8 ? 1 : n <= 255 ? 2 : 3); 1645 - 1646 - tdata[tchan++] = n; 1647 - ttotal += n; 1648 - } 1649 - break; 1650 - 1651 - /* 1652 - * Close the port. 1653 - */ 1654 - 1655 - send_close: 1656 - case CS_SEND_CLOSE: 1657 - b = set_cmd_header(b, port, 10); 1658 - if (ch->ch_otype == OTYPE_IMMEDIATE) 1659 - *b++ = 3; 1660 - else 1661 - *b++ = 4; 1662 - 1663 - ch->ch_state = CS_WAIT_CLOSE; 1664 - break; 1665 - 1666 - /* 1667 - * Wait for a previous server request. 1668 - */ 1669 - 1670 - case CS_WAIT_OPEN: 1671 - case CS_WAIT_CANCEL: 1672 - case CS_WAIT_FAIL: 1673 - case CS_WAIT_QUERY: 1674 - case CS_WAIT_CLOSE: 1675 - break; 1676 - 1677 - default: 1678 - pr_info("%s - unexpected channel state (%i)\n", 1679 - __func__, ch->ch_state); 1680 - } 1681 - } 1682 - 1683 - /* 1684 - * If a module select code is needed, drop one in. If space 1685 - * was reserved for one, but none is needed, recover the space. 1686 - */ 1687 - 1688 - if (mod != nd->nd_tx_module) { 1689 - if (b != mbuf) { 1690 - mbuf[-1] = 0xf0 | mod; 1691 - nd->nd_tx_module = mod; 1692 - } else { 1693 - b--; 1694 - } 1695 - } 1696 - } 1697 - 1698 - /* 1699 - * Adjust "tmax" so that under worst case conditions we do 1700 - * not overflow either the daemon buffer or the internal 1701 - * buffer in the loop that follows. Leave a safe area 1702 - * of 64 bytes so we start getting asserts before we start 1703 - * losing data or clobbering memory. 1704 - */ 1705 - 1706 - n = UIO_MAX - UIO_BASE; 1707 - 1708 - if (tmax > n) 1709 - tmax = n; 1710 - 1711 - tmax -= 64; 1712 - 1713 - tsafe = tmax; 1714 - 1715 - /* 1716 - * Allocate space for 5 Module Selects, 1 Sequence Request, 1717 - * and 1 Set TREQ for each active channel. 1718 - */ 1719 - 1720 - tmax -= 5 + 3 + 4 * nd->nd_chan_count; 1721 - 1722 - /* 1723 - * Further reduce "tmax" to the available transmit credit. 1724 - * Note that this is a soft constraint; The transmit credit 1725 - * can go negative for a time and then recover. 1726 - */ 1727 - 1728 - n = nd->nd_tx_deposit - nd->nd_tx_charge - nd->nd_link.lk_header_size; 1729 - 1730 - if (tmax > n) 1731 - tmax = n; 1732 - 1733 - /* 1734 - * Finally reduce tmax by the number of bytes already in 1735 - * the buffer. 1736 - */ 1737 - 1738 - tmax -= b - buf; 1739 - 1740 - /* 1741 - * Suspend data transmit unless every ready channel can send 1742 - * at least 1 character. 1743 - */ 1744 - if (tmax < 2 * nd->nd_chan_count) { 1745 - tsend = 1; 1746 - 1747 - } else if (tchan > 1 && ttotal > tmax) { 1748 - 1749 - /* 1750 - * If transmit is limited by the credit budget, find the 1751 - * largest number of characters we can send without driving 1752 - * the credit negative. 1753 - */ 1754 - 1755 - long tm = tmax; 1756 - int tc = tchan; 1757 - int try; 1758 - 1759 - tsend = tm / tc; 1760 - 1761 - for (try = 0; try < 3; try++) { 1762 - int i; 1763 - int c = 0; 1764 - 1765 - for (i = 0; i < tc; i++) { 1766 - if (tsend < tdata[i]) 1767 - tdata[c++] = tdata[i]; 1768 - else 1769 - tm -= tdata[i]; 1770 - } 1771 - 1772 - if (c == tc) 1773 - break; 1774 - 1775 - tsend = tm / c; 1776 - 1777 - if (c == 1) 1778 - break; 1779 - 1780 - tc = c; 1781 - } 1782 - 1783 - tsend = tm / nd->nd_chan_count; 1784 - 1785 - if (tsend < 2) 1786 - tsend = 1; 1787 - 1788 - } else { 1789 - /* 1790 - * If no budgetary constraints, or only one channel ready 1791 - * to send, set the character limit to the remaining 1792 - * buffer size. 1793 - */ 1794 - 1795 - tsend = tmax; 1796 - } 1797 - 1798 - tsend -= (tsend <= 9) ? 1 : (tsend <= 257) ? 2 : 3; 1799 - 1800 - /* 1801 - * Loop over all channels, sending queued data. 1802 - */ 1803 - 1804 - port = 0; 1805 - ch = nd->nd_chan; 1806 - used_buffer = tmax; 1807 - 1808 - for (mod = 0; port < nd->nd_chan_count; mod++) { 1809 - /* 1810 - * If this is not the current module, enter a module select 1811 - * code in the buffer. 1812 - */ 1813 - 1814 - if (mod != nd->nd_tx_module) 1815 - mbuf = ++b; 1816 - 1817 - /* 1818 - * Loop to process one module. 1819 - */ 1820 - 1821 - maxport = port + 16; 1822 - 1823 - if (maxport > nd->nd_chan_count) 1824 - maxport = nd->nd_chan_count; 1825 - 1826 - for (; port < maxport; port++, ch++) { 1827 - if (ch->ch_state != CS_READY) 1828 - continue; 1829 - 1830 - lastport = port; 1831 - 1832 - n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1833 - 1834 - /* 1835 - * If there is data that can be sent, send it. 1836 - */ 1837 - 1838 - if (n != 0 && used_buffer > 0) { 1839 - t = (ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff; 1840 - 1841 - if (n > t) 1842 - n = t; 1843 - 1844 - if (n > tsend) { 1845 - work = 1; 1846 - n = tsend; 1847 - } 1848 - 1849 - if (n > used_buffer) { 1850 - work = 1; 1851 - n = used_buffer; 1852 - } 1853 - 1854 - if (n <= 0) 1855 - continue; 1856 - 1857 - /* 1858 - * Create the correct size transmit header, 1859 - * depending on the amount of data to transmit. 1860 - */ 1861 - 1862 - if (n <= 8) { 1863 - 1864 - b[0] = ((n - 1) << 4) + (port & 0xf); 1865 - b += 1; 1866 - 1867 - } else if (n <= 255) { 1868 - 1869 - b[0] = 0x80 + (port & 0xf); 1870 - b[1] = n; 1871 - b += 2; 1872 - 1873 - } else { 1874 - 1875 - b[0] = 0x90 + (port & 0xf); 1876 - put_unaligned_be16(n, b + 1); 1877 - b += 3; 1878 - } 1879 - 1880 - ch->ch_s_tin = (ch->ch_s_tin + n) & 0xffff; 1881 - 1882 - /* 1883 - * Copy transmit data to the packet. 1884 - */ 1885 - 1886 - t = TBUF_MAX - ch->ch_tout; 1887 - 1888 - if (n >= t) { 1889 - memcpy(b, ch->ch_tbuf + ch->ch_tout, t); 1890 - b += t; 1891 - n -= t; 1892 - used_buffer -= t; 1893 - ch->ch_tout = 0; 1894 - } 1895 - 1896 - memcpy(b, ch->ch_tbuf + ch->ch_tout, n); 1897 - b += n; 1898 - used_buffer -= n; 1899 - ch->ch_tout += n; 1900 - n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1901 - } 1902 - 1903 - /* 1904 - * Wake any terminal unit process waiting in the 1905 - * dgrp_write routine for low water. 1906 - */ 1907 - 1908 - if (n > TBUF_LOW) 1909 - continue; 1910 - 1911 - if ((ch->ch_flag & CH_LOW) != 0) { 1912 - ch->ch_flag &= ~CH_LOW; 1913 - wake_up_interruptible(&ch->ch_flag_wait); 1914 - } 1915 - 1916 - /* selwakeup tty_sel */ 1917 - if (ch->ch_tun.un_open_count) { 1918 - struct tty_struct *tty = (ch->ch_tun.un_tty); 1919 - 1920 - if (waitqueue_active(&tty->write_wait)) 1921 - wake_up_interruptible(&tty->write_wait); 1922 - 1923 - tty_wakeup(tty); 1924 - } 1925 - 1926 - if (ch->ch_pun.un_open_count) { 1927 - struct tty_struct *tty = (ch->ch_pun.un_tty); 1928 - 1929 - if (waitqueue_active(&tty->write_wait)) 1930 - wake_up_interruptible(&tty->write_wait); 1931 - 1932 - tty_wakeup(tty); 1933 - } 1934 - 1935 - /* 1936 - * Do EMPTY processing. 1937 - */ 1938 - 1939 - if (n != 0) 1940 - continue; 1941 - 1942 - if ((ch->ch_flag & (CH_EMPTY | CH_DRAIN)) != 0 || 1943 - (ch->ch_pun.un_flag & UN_EMPTY) != 0) { 1944 - /* 1945 - * If there is still data in the server, ask the server 1946 - * to notify us when its all gone. 1947 - */ 1948 - 1949 - if (ch->ch_s_treq != ch->ch_s_tin) { 1950 - b = set_cmd_header(b, port, 43); 1951 - 1952 - ch->ch_s_treq = ch->ch_s_tin; 1953 - put_unaligned_be16(ch->ch_s_treq, 1954 - b); 1955 - b += 2; 1956 - } 1957 - 1958 - /* 1959 - * If there is a thread waiting for buffer empty, 1960 - * and we are truly empty, wake the thread. 1961 - */ 1962 - 1963 - else if ((ch->ch_flag & CH_EMPTY) != 0 && 1964 - (ch->ch_send & RR_TX_BREAK) == 0) { 1965 - ch->ch_flag &= ~CH_EMPTY; 1966 - 1967 - wake_up_interruptible(&ch->ch_flag_wait); 1968 - } 1969 - } 1970 - } 1971 - 1972 - /* 1973 - * If a module select code is needed, drop one in. If space 1974 - * was reserved for one, but none is needed, recover the space. 1975 - */ 1976 - 1977 - if (mod != nd->nd_tx_module) { 1978 - if (b != mbuf) { 1979 - mbuf[-1] = 0xf0 | mod; 1980 - nd->nd_tx_module = mod; 1981 - } else { 1982 - b--; 1983 - } 1984 - } 1985 - } 1986 - 1987 - /* 1988 - * Send a synchronization sequence associated with the last open 1989 - * channel that sent data, and remember the time when the data was 1990 - * sent. 1991 - */ 1992 - 1993 - in = nd->nd_seq_in; 1994 - 1995 - if ((send_sync || nd->nd_seq_wait[in] != 0) && lastport >= 0) { 1996 - u8 *bb = b; 1997 - 1998 - /* 1999 - * Attempt the use the port that really wanted the sync. 2000 - * This gets around a race condition where the "lastport" is in 2001 - * the middle of the close() routine, and by the time we 2002 - * send this command, it will have already acked the close, and 2003 - * thus not send the sync response. 2004 - */ 2005 - if (wanted_sync_port >= 0) 2006 - lastport = wanted_sync_port; 2007 - /* 2008 - * Set a flag just in case the port is in the middle of a close, 2009 - * it will not be permitted to actually close until we get an 2010 - * sync response, and clear the flag there. 2011 - */ 2012 - ch = nd->nd_chan + lastport; 2013 - ch->ch_flag |= CH_WAITING_SYNC; 2014 - 2015 - mod = lastport >> 4; 2016 - 2017 - if (mod != nd->nd_tx_module) { 2018 - bb[0] = 0xf0 + mod; 2019 - bb += 1; 2020 - 2021 - nd->nd_tx_module = mod; 2022 - } 2023 - 2024 - bb = set_cmd_header(bb, lastport, 12); 2025 - *bb++ = in; 2026 - 2027 - nd->nd_seq_size[in] = bb - buf; 2028 - nd->nd_seq_time[in] = jiffies; 2029 - 2030 - if (++in >= SEQ_MAX) 2031 - in = 0; 2032 - 2033 - if (in != nd->nd_seq_out) { 2034 - b = bb; 2035 - nd->nd_seq_in = in; 2036 - nd->nd_unack += b - buf; 2037 - } 2038 - } 2039 - 2040 - /* 2041 - * If there are no open ports, a sync cannot be sent. 2042 - * There is nothing left to wait for anyway, so wake any 2043 - * thread waiting for an acknowledgement. 2044 - */ 2045 - 2046 - else if (nd->nd_seq_wait[in] != 0) { 2047 - nd->nd_seq_wait[in] = 0; 2048 - 2049 - wake_up_interruptible(&nd->nd_seq_wque[in]); 2050 - } 2051 - 2052 - /* 2053 - * If there is no traffic for an interval of IDLE_MAX, then 2054 - * send a single byte packet. 2055 - */ 2056 - 2057 - if (b != buf) { 2058 - nd->nd_tx_time = jiffies; 2059 - } else if ((ulong)(jiffies - nd->nd_tx_time) >= IDLE_MAX) { 2060 - *b++ = 0xf0 | nd->nd_tx_module; 2061 - nd->nd_tx_time = jiffies; 2062 - } 2063 - 2064 - n = b - buf; 2065 - 2066 - if (n >= tsafe) 2067 - pr_info("%s - n(%i) >= tsafe(%i)\n", 2068 - __func__, n, tsafe); 2069 - 2070 - if (tsend < 0) 2071 - dgrp_dump(buf, n); 2072 - 2073 - nd->nd_tx_work = work; 2074 - 2075 - return n; 2076 - } 2077 - 2078 - /* 2079 - * dgrp_net_read() 2080 - * Data to be sent TO the PortServer from the "async." half of the driver. 2081 - */ 2082 - static ssize_t dgrp_net_read(struct file *file, char __user *buf, size_t count, 2083 - loff_t *ppos) 2084 - { 2085 - struct nd_struct *nd; 2086 - long n; 2087 - u8 *local_buf; 2088 - u8 *b; 2089 - ssize_t rtn; 2090 - 2091 - /* 2092 - * Get the node pointer, and quit if it doesn't exist. 2093 - */ 2094 - nd = (struct nd_struct *)(file->private_data); 2095 - if (!nd) 2096 - return -ENXIO; 2097 - 2098 - if (count < UIO_MIN) 2099 - return -EINVAL; 2100 - 2101 - /* 2102 - * Only one read/write operation may be in progress at 2103 - * any given time. 2104 - */ 2105 - 2106 - /* 2107 - * Grab the NET lock. 2108 - */ 2109 - down(&nd->nd_net_semaphore); 2110 - 2111 - nd->nd_read_count++; 2112 - 2113 - nd->nd_tx_ready = 0; 2114 - 2115 - /* 2116 - * Determine the effective size of the buffer. 2117 - */ 2118 - 2119 - if (nd->nd_remain > UIO_BASE) 2120 - pr_info_ratelimited("%s - nd_remain(%i) > UIO_BASE\n", 2121 - __func__, nd->nd_remain); 2122 - 2123 - b = local_buf = nd->nd_iobuf + UIO_BASE; 2124 - 2125 - /* 2126 - * Generate data according to the node state. 2127 - */ 2128 - 2129 - switch (nd->nd_state) { 2130 - /* 2131 - * Initialize the connection. 2132 - */ 2133 - 2134 - case NS_IDLE: 2135 - if (nd->nd_mon_buf) 2136 - dgrp_monitor_reset(nd); 2137 - 2138 - /* 2139 - * Request a Product ID Packet. 2140 - */ 2141 - 2142 - b[0] = 0xfb; 2143 - b[1] = 0x01; 2144 - b += 2; 2145 - 2146 - nd->nd_expect |= NR_IDENT; 2147 - 2148 - /* 2149 - * Request a Server Capability ID Response. 2150 - */ 2151 - 2152 - b[0] = 0xfb; 2153 - b[1] = 0x02; 2154 - b += 2; 2155 - 2156 - nd->nd_expect |= NR_CAPABILITY; 2157 - 2158 - /* 2159 - * Request a Server VPD Response. 2160 - */ 2161 - 2162 - b[0] = 0xfb; 2163 - b[1] = 0x18; 2164 - b += 2; 2165 - 2166 - nd->nd_expect |= NR_VPD; 2167 - 2168 - nd->nd_state = NS_WAIT_QUERY; 2169 - break; 2170 - 2171 - /* 2172 - * We do serious communication with the server only in 2173 - * the READY state. 2174 - */ 2175 - 2176 - case NS_READY: 2177 - b = dgrp_send(nd, count) + local_buf; 2178 - break; 2179 - 2180 - /* 2181 - * Send off an error after receiving a bogus message 2182 - * from the server. 2183 - */ 2184 - 2185 - case NS_SEND_ERROR: 2186 - n = strlen(nd->nd_error); 2187 - 2188 - b[0] = 0xff; 2189 - b[1] = n; 2190 - memcpy(b + 2, nd->nd_error, n); 2191 - b += 2 + n; 2192 - 2193 - dgrp_net_idle(nd); 2194 - /* 2195 - * Set the active port count to zero. 2196 - */ 2197 - dgrp_chan_count(nd, 0); 2198 - break; 2199 - 2200 - default: 2201 - break; 2202 - } 2203 - 2204 - n = b - local_buf; 2205 - 2206 - if (n != 0) { 2207 - nd->nd_send_count++; 2208 - 2209 - nd->nd_tx_byte += n + nd->nd_link.lk_header_size; 2210 - nd->nd_tx_charge += n + nd->nd_link.lk_header_size; 2211 - } 2212 - 2213 - rtn = copy_to_user((void __user *)buf, local_buf, n); 2214 - if (rtn) { 2215 - rtn = -EFAULT; 2216 - goto done; 2217 - } 2218 - 2219 - *ppos += n; 2220 - 2221 - rtn = n; 2222 - 2223 - if (nd->nd_mon_buf) 2224 - dgrp_monitor_data(nd, RPDUMP_CLIENT, local_buf, n); 2225 - 2226 - /* 2227 - * Release the NET lock. 2228 - */ 2229 - done: 2230 - up(&nd->nd_net_semaphore); 2231 - 2232 - return rtn; 2233 - } 2234 - 2235 - /** 2236 - * dgrp_receive() -- decode data packets received from the remote PortServer. 2237 - * @nd: pointer to a node structure 2238 - */ 2239 - static void dgrp_receive(struct nd_struct *nd) 2240 - { 2241 - struct ch_struct *ch; 2242 - u8 *buf; 2243 - u8 *b; 2244 - u8 *dbuf; 2245 - char *error; 2246 - long port; 2247 - long dlen; 2248 - long plen; 2249 - long remain; 2250 - long n; 2251 - long mlast; 2252 - long elast; 2253 - long mstat; 2254 - long estat; 2255 - 2256 - char ID[3]; 2257 - 2258 - nd->nd_tx_time = jiffies; 2259 - 2260 - ID_TO_CHAR(nd->nd_ID, ID); 2261 - 2262 - b = buf = nd->nd_iobuf; 2263 - remain = nd->nd_remain; 2264 - 2265 - /* 2266 - * Loop to process Realport protocol packets. 2267 - */ 2268 - 2269 - while (remain > 0) { 2270 - int n0 = b[0] >> 4; 2271 - int n1 = b[0] & 0x0f; 2272 - 2273 - if (n0 <= 12) { 2274 - port = (nd->nd_rx_module << 4) + n1; 2275 - 2276 - if (port >= nd->nd_chan_count) { 2277 - error = "Improper Port Number"; 2278 - goto prot_error; 2279 - } 2280 - 2281 - ch = nd->nd_chan + port; 2282 - } else { 2283 - port = -1; 2284 - ch = NULL; 2285 - } 2286 - 2287 - /* 2288 - * Process by major packet type. 2289 - */ 2290 - 2291 - switch (n0) { 2292 - 2293 - /* 2294 - * Process 1-byte header data packet. 2295 - */ 2296 - 2297 - case 0: 2298 - case 1: 2299 - case 2: 2300 - case 3: 2301 - case 4: 2302 - case 5: 2303 - case 6: 2304 - case 7: 2305 - dlen = n0 + 1; 2306 - plen = dlen + 1; 2307 - 2308 - dbuf = b + 1; 2309 - goto data; 2310 - 2311 - /* 2312 - * Process 2-byte header data packet. 2313 - */ 2314 - 2315 - case 8: 2316 - if (remain < 3) 2317 - goto done; 2318 - 2319 - dlen = b[1]; 2320 - plen = dlen + 2; 2321 - 2322 - dbuf = b + 2; 2323 - goto data; 2324 - 2325 - /* 2326 - * Process 3-byte header data packet. 2327 - */ 2328 - 2329 - case 9: 2330 - if (remain < 4) 2331 - goto done; 2332 - 2333 - dlen = get_unaligned_be16(b + 1); 2334 - plen = dlen + 3; 2335 - 2336 - dbuf = b + 3; 2337 - 2338 - /* 2339 - * Common packet handling code. 2340 - */ 2341 - 2342 - data: 2343 - nd->nd_tx_work = 1; 2344 - 2345 - /* 2346 - * Otherwise data should appear only when we are 2347 - * in the CS_READY state. 2348 - */ 2349 - 2350 - if (ch->ch_state < CS_READY) { 2351 - error = "Data received before RWIN established"; 2352 - goto prot_error; 2353 - } 2354 - 2355 - /* 2356 - * Assure that the data received is within the 2357 - * allowable window. 2358 - */ 2359 - 2360 - n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff; 2361 - 2362 - if (dlen > n) { 2363 - error = "Receive data overrun"; 2364 - goto prot_error; 2365 - } 2366 - 2367 - /* 2368 - * If we received 3 or less characters, 2369 - * assume it is a human typing, and set RTIME 2370 - * to 10 milliseconds. 2371 - * 2372 - * If we receive 10 or more characters, 2373 - * assume its not a human typing, and set RTIME 2374 - * to 100 milliseconds. 2375 - */ 2376 - 2377 - if (ch->ch_edelay != DGRP_RTIME) { 2378 - if (ch->ch_rtime != ch->ch_edelay) { 2379 - ch->ch_rtime = ch->ch_edelay; 2380 - ch->ch_flag |= CH_PARAM; 2381 - } 2382 - } else if (dlen <= 3) { 2383 - if (ch->ch_rtime != 10) { 2384 - ch->ch_rtime = 10; 2385 - ch->ch_flag |= CH_PARAM; 2386 - } 2387 - } else { 2388 - if (ch->ch_rtime != DGRP_RTIME) { 2389 - ch->ch_rtime = DGRP_RTIME; 2390 - ch->ch_flag |= CH_PARAM; 2391 - } 2392 - } 2393 - 2394 - /* 2395 - * If a portion of the packet is outside the 2396 - * buffer, shorten the effective length of the 2397 - * data packet to be the amount of data received. 2398 - */ 2399 - 2400 - if (remain < plen) 2401 - dlen -= plen - remain; 2402 - 2403 - /* 2404 - * Detect if receive flush is now complete. 2405 - */ 2406 - 2407 - if ((ch->ch_flag & CH_RX_FLUSH) != 0 && 2408 - ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >= 2409 - ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) { 2410 - ch->ch_flag &= ~CH_RX_FLUSH; 2411 - } 2412 - 2413 - /* 2414 - * If we are ready to receive, move the data into 2415 - * the receive buffer. 2416 - */ 2417 - 2418 - ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff; 2419 - 2420 - if (ch->ch_state == CS_READY && 2421 - (ch->ch_tun.un_open_count != 0) && 2422 - (ch->ch_tun.un_flag & UN_CLOSING) == 0 && 2423 - (ch->ch_cflag & CF_CREAD) != 0 && 2424 - (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 && 2425 - (ch->ch_send & RR_RX_FLUSH) == 0) { 2426 - 2427 - if (ch->ch_rin + dlen >= RBUF_MAX) { 2428 - n = RBUF_MAX - ch->ch_rin; 2429 - 2430 - memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n); 2431 - 2432 - ch->ch_rin = 0; 2433 - dbuf += n; 2434 - dlen -= n; 2435 - } 2436 - 2437 - memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen); 2438 - 2439 - ch->ch_rin += dlen; 2440 - 2441 - 2442 - /* 2443 - * If we are not in fastcook mode, or 2444 - * if there is a fastcook thread 2445 - * waiting for data, send the data to 2446 - * the line discipline. 2447 - */ 2448 - 2449 - if ((ch->ch_flag & CH_FAST_READ) == 0 || 2450 - ch->ch_inwait != 0) { 2451 - dgrp_input(ch); 2452 - } 2453 - 2454 - /* 2455 - * If there is a read thread waiting 2456 - * in select, and we are in fastcook 2457 - * mode, wake him up. 2458 - */ 2459 - 2460 - if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) && 2461 - (ch->ch_flag & CH_FAST_READ) != 0) 2462 - wake_up_interruptible(&ch->ch_tun.un_tty->read_wait); 2463 - 2464 - /* 2465 - * Wake any thread waiting in the 2466 - * fastcook loop. 2467 - */ 2468 - 2469 - if ((ch->ch_flag & CH_INPUT) != 0) { 2470 - ch->ch_flag &= ~CH_INPUT; 2471 - 2472 - wake_up_interruptible(&ch->ch_flag_wait); 2473 - } 2474 - } 2475 - 2476 - /* 2477 - * Fabricate and insert a data packet header to 2478 - * preced the remaining data when it comes in. 2479 - */ 2480 - 2481 - if (remain < plen) { 2482 - dlen = plen - remain; 2483 - b = buf; 2484 - 2485 - b[0] = 0x90 + n1; 2486 - put_unaligned_be16(dlen, b + 1); 2487 - 2488 - remain = 3; 2489 - goto done; 2490 - } 2491 - break; 2492 - 2493 - /* 2494 - * Handle Window Sequence packets. 2495 - */ 2496 - 2497 - case 10: 2498 - plen = 3; 2499 - if (remain < plen) 2500 - goto done; 2501 - 2502 - nd->nd_tx_work = 1; 2503 - 2504 - { 2505 - ushort tpos = get_unaligned_be16(b + 1); 2506 - 2507 - ushort ack = (tpos - ch->ch_s_tpos) & 0xffff; 2508 - ushort unack = (ch->ch_s_tin - ch->ch_s_tpos) & 0xffff; 2509 - ushort notify = (ch->ch_s_treq - ch->ch_s_tpos) & 0xffff; 2510 - 2511 - if (ch->ch_state < CS_READY || ack > unack) { 2512 - error = "Improper Window Sequence"; 2513 - goto prot_error; 2514 - } 2515 - 2516 - ch->ch_s_tpos = tpos; 2517 - 2518 - if (notify <= ack) 2519 - ch->ch_s_treq = tpos; 2520 - } 2521 - break; 2522 - 2523 - /* 2524 - * Handle Command response packets. 2525 - */ 2526 - 2527 - case 11: 2528 - 2529 - /* 2530 - * RealPort engine fix - 03/11/2004 2531 - * 2532 - * This check did not used to be here. 2533 - * 2534 - * We were using b[1] without verifying that the data 2535 - * is actually there and valid. On a split packet, it 2536 - * might not be yet. 2537 - * 2538 - * NOTE: I have never actually seen the failure happen 2539 - * under Linux, but since I have seen it occur 2540 - * under both Solaris and HP-UX, the assumption 2541 - * is that it *could* happen here as well... 2542 - */ 2543 - if (remain < 2) 2544 - goto done; 2545 - 2546 - 2547 - switch (b[1]) { 2548 - 2549 - /* 2550 - * Handle Open Response. 2551 - */ 2552 - 2553 - case 11: 2554 - plen = 6; 2555 - if (remain < plen) 2556 - goto done; 2557 - 2558 - nd->nd_tx_work = 1; 2559 - 2560 - { 2561 - int req = b[2]; 2562 - int resp = b[3]; 2563 - port = get_unaligned_be16(b + 4); 2564 - 2565 - if (port >= nd->nd_chan_count) { 2566 - error = "Open channel number out of range"; 2567 - goto prot_error; 2568 - } 2569 - 2570 - ch = nd->nd_chan + port; 2571 - 2572 - /* 2573 - * How we handle an open response depends primarily 2574 - * on our current channel state. 2575 - */ 2576 - 2577 - switch (ch->ch_state) { 2578 - case CS_IDLE: 2579 - 2580 - /* 2581 - * Handle a delayed open. 2582 - */ 2583 - 2584 - if (ch->ch_otype_waiting != 0 && 2585 - req == ch->ch_otype_waiting && 2586 - resp == 0) { 2587 - ch->ch_otype = req; 2588 - ch->ch_otype_waiting = 0; 2589 - ch->ch_state = CS_SEND_QUERY; 2590 - break; 2591 - } 2592 - goto open_error; 2593 - 2594 - case CS_WAIT_OPEN: 2595 - 2596 - /* 2597 - * Handle the open response. 2598 - */ 2599 - 2600 - if (req == ch->ch_otype) { 2601 - switch (resp) { 2602 - 2603 - /* 2604 - * On successful response, open the 2605 - * port and proceed normally. 2606 - */ 2607 - 2608 - case 0: 2609 - ch->ch_state = CS_SEND_QUERY; 2610 - break; 2611 - 2612 - /* 2613 - * On a busy response to a persistent open, 2614 - * remember that the open is pending. 2615 - */ 2616 - 2617 - case 1: 2618 - case 2: 2619 - if (req != OTYPE_IMMEDIATE) { 2620 - ch->ch_otype_waiting = req; 2621 - ch->ch_state = CS_IDLE; 2622 - break; 2623 - } 2624 - 2625 - /* 2626 - * Otherwise the server open failed. If 2627 - * the Unix port is open, hang it up. 2628 - */ 2629 - 2630 - default: 2631 - if (ch->ch_open_count != 0) { 2632 - ch->ch_flag |= CH_HANGUP; 2633 - dgrp_carrier(ch); 2634 - ch->ch_state = CS_IDLE; 2635 - break; 2636 - } 2637 - 2638 - ch->ch_open_error = resp; 2639 - ch->ch_state = CS_IDLE; 2640 - 2641 - wake_up_interruptible(&ch->ch_flag_wait); 2642 - } 2643 - break; 2644 - } 2645 - 2646 - /* 2647 - * Handle delayed response arrival preceding 2648 - * the open response we are waiting for. 2649 - */ 2650 - 2651 - if (ch->ch_otype_waiting != 0 && 2652 - req == ch->ch_otype_waiting && 2653 - resp == 0) { 2654 - ch->ch_otype = ch->ch_otype_waiting; 2655 - ch->ch_otype_waiting = 0; 2656 - ch->ch_state = CS_WAIT_FAIL; 2657 - break; 2658 - } 2659 - goto open_error; 2660 - 2661 - 2662 - case CS_WAIT_FAIL: 2663 - 2664 - /* 2665 - * Handle response to immediate open arriving 2666 - * after a delayed open success. 2667 - */ 2668 - 2669 - if (req == OTYPE_IMMEDIATE) { 2670 - ch->ch_state = CS_SEND_QUERY; 2671 - break; 2672 - } 2673 - goto open_error; 2674 - 2675 - 2676 - case CS_WAIT_CANCEL: 2677 - /* 2678 - * Handle delayed open response arriving before 2679 - * the cancel response. 2680 - */ 2681 - 2682 - if (req == ch->ch_otype_waiting && 2683 - resp == 0) { 2684 - ch->ch_otype_waiting = 0; 2685 - break; 2686 - } 2687 - 2688 - /* 2689 - * Handle cancel response. 2690 - */ 2691 - 2692 - if (req == 4 && resp == 0) { 2693 - ch->ch_otype_waiting = 0; 2694 - ch->ch_state = CS_IDLE; 2695 - break; 2696 - } 2697 - goto open_error; 2698 - 2699 - 2700 - case CS_WAIT_CLOSE: 2701 - /* 2702 - * Handle a successful response to a port 2703 - * close. 2704 - */ 2705 - 2706 - if (req >= 3) { 2707 - ch->ch_state = CS_IDLE; 2708 - break; 2709 - } 2710 - goto open_error; 2711 - 2712 - open_error: 2713 - default: 2714 - { 2715 - error = "Improper Open Response"; 2716 - goto prot_error; 2717 - } 2718 - } 2719 - } 2720 - break; 2721 - 2722 - /* 2723 - * Handle Synchronize Response. 2724 - */ 2725 - 2726 - case 13: 2727 - plen = 3; 2728 - if (remain < plen) 2729 - goto done; 2730 - { 2731 - int seq = b[2]; 2732 - int s; 2733 - 2734 - /* 2735 - * If channel was waiting for this sync response, 2736 - * unset the flag, and wake up anyone waiting 2737 - * on the event. 2738 - */ 2739 - if (ch->ch_flag & CH_WAITING_SYNC) { 2740 - ch->ch_flag &= ~(CH_WAITING_SYNC); 2741 - wake_up_interruptible(&ch->ch_flag_wait); 2742 - } 2743 - 2744 - if (((seq - nd->nd_seq_out) & SEQ_MASK) >= 2745 - ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) { 2746 - break; 2747 - } 2748 - 2749 - for (s = nd->nd_seq_out;; s = (s + 1) & SEQ_MASK) { 2750 - if (nd->nd_seq_wait[s] != 0) { 2751 - nd->nd_seq_wait[s] = 0; 2752 - 2753 - wake_up_interruptible(&nd->nd_seq_wque[s]); 2754 - } 2755 - 2756 - nd->nd_unack -= nd->nd_seq_size[s]; 2757 - 2758 - if (s == seq) 2759 - break; 2760 - } 2761 - 2762 - nd->nd_seq_out = (seq + 1) & SEQ_MASK; 2763 - } 2764 - break; 2765 - 2766 - /* 2767 - * Handle Sequence Response. 2768 - */ 2769 - 2770 - case 15: 2771 - plen = 6; 2772 - if (remain < plen) 2773 - goto done; 2774 - 2775 - { 2776 - /* Record that we have received the Sequence 2777 - * Response, but we aren't interested in the 2778 - * sequence numbers. We were using RIN like it 2779 - * was ROUT and that was causing problems, 2780 - * fixed 7-13-2001 David Fries. See comment in 2781 - * drp.h for ch_s_rin variable. 2782 - int rin = get_unaligned_be16(b + 2); 2783 - int tpos = get_unaligned_be16(b + 4); 2784 - */ 2785 - 2786 - ch->ch_send &= ~RR_SEQUENCE; 2787 - ch->ch_expect &= ~RR_SEQUENCE; 2788 - } 2789 - goto check_query; 2790 - 2791 - /* 2792 - * Handle Status Response. 2793 - */ 2794 - 2795 - case 17: 2796 - plen = 5; 2797 - if (remain < plen) 2798 - goto done; 2799 - 2800 - { 2801 - ch->ch_s_elast = get_unaligned_be16(b + 2); 2802 - ch->ch_s_mlast = b[4]; 2803 - 2804 - ch->ch_expect &= ~RR_STATUS; 2805 - ch->ch_send &= ~RR_STATUS; 2806 - 2807 - /* 2808 - * CH_PHYS_CD is cleared because something _could_ be 2809 - * waiting for the initial sense of carrier... and if 2810 - * carrier is high immediately, we want to be sure to 2811 - * wake them as soon as possible. 2812 - */ 2813 - ch->ch_flag &= ~CH_PHYS_CD; 2814 - 2815 - dgrp_carrier(ch); 2816 - } 2817 - goto check_query; 2818 - 2819 - /* 2820 - * Handle Line Error Response. 2821 - */ 2822 - 2823 - case 19: 2824 - plen = 14; 2825 - if (remain < plen) 2826 - goto done; 2827 - 2828 - break; 2829 - 2830 - /* 2831 - * Handle Buffer Response. 2832 - */ 2833 - 2834 - case 21: 2835 - plen = 6; 2836 - if (remain < plen) 2837 - goto done; 2838 - 2839 - { 2840 - ch->ch_s_rsize = get_unaligned_be16(b + 2); 2841 - ch->ch_s_tsize = get_unaligned_be16(b + 4); 2842 - 2843 - ch->ch_send &= ~RR_BUFFER; 2844 - ch->ch_expect &= ~RR_BUFFER; 2845 - } 2846 - goto check_query; 2847 - 2848 - /* 2849 - * Handle Port Capability Response. 2850 - */ 2851 - 2852 - case 23: 2853 - plen = 32; 2854 - if (remain < plen) 2855 - goto done; 2856 - 2857 - { 2858 - ch->ch_send &= ~RR_CAPABILITY; 2859 - ch->ch_expect &= ~RR_CAPABILITY; 2860 - } 2861 - 2862 - /* 2863 - * When all queries are complete, set those parameters 2864 - * derived from the query results, then transition 2865 - * to the READY state. 2866 - */ 2867 - 2868 - check_query: 2869 - if (ch->ch_state == CS_WAIT_QUERY && 2870 - (ch->ch_expect & (RR_SEQUENCE | 2871 - RR_STATUS | 2872 - RR_BUFFER | 2873 - RR_CAPABILITY)) == 0) { 2874 - ch->ch_tmax = ch->ch_s_tsize / 4; 2875 - 2876 - if (ch->ch_edelay == DGRP_TTIME) 2877 - ch->ch_ttime = DGRP_TTIME; 2878 - else 2879 - ch->ch_ttime = ch->ch_edelay; 2880 - 2881 - ch->ch_rmax = ch->ch_s_rsize / 4; 2882 - 2883 - if (ch->ch_edelay == DGRP_RTIME) 2884 - ch->ch_rtime = DGRP_RTIME; 2885 - else 2886 - ch->ch_rtime = ch->ch_edelay; 2887 - 2888 - ch->ch_rlow = 2 * ch->ch_s_rsize / 8; 2889 - ch->ch_rhigh = 6 * ch->ch_s_rsize / 8; 2890 - 2891 - ch->ch_state = CS_READY; 2892 - 2893 - nd->nd_tx_work = 1; 2894 - wake_up_interruptible(&ch->ch_flag_wait); 2895 - 2896 - } 2897 - break; 2898 - 2899 - default: 2900 - goto decode_error; 2901 - } 2902 - break; 2903 - 2904 - /* 2905 - * Handle Events. 2906 - */ 2907 - 2908 - case 12: 2909 - plen = 4; 2910 - if (remain < plen) 2911 - goto done; 2912 - 2913 - mlast = ch->ch_s_mlast; 2914 - elast = ch->ch_s_elast; 2915 - 2916 - mstat = ch->ch_s_mlast = b[1]; 2917 - estat = ch->ch_s_elast = get_unaligned_be16(b + 2); 2918 - 2919 - /* 2920 - * Handle modem changes. 2921 - */ 2922 - 2923 - if (((mstat ^ mlast) & DM_CD) != 0) 2924 - dgrp_carrier(ch); 2925 - 2926 - 2927 - /* 2928 - * Handle received break. 2929 - */ 2930 - 2931 - if ((estat & ~elast & EV_RXB) != 0 && 2932 - (ch->ch_tun.un_open_count != 0) && 2933 - I_BRKINT(ch->ch_tun.un_tty) && 2934 - !(I_IGNBRK(ch->ch_tun.un_tty))) { 2935 - 2936 - tty_buffer_request_room(&ch->port, 1); 2937 - tty_insert_flip_char(&ch->port, 0, TTY_BREAK); 2938 - tty_flip_buffer_push(&ch->port); 2939 - 2940 - } 2941 - 2942 - /* 2943 - * On transmit break complete, if more break traffic 2944 - * is waiting then send it. Otherwise wake any threads 2945 - * waiting for transmitter empty. 2946 - */ 2947 - 2948 - if ((~estat & elast & EV_TXB) != 0 && 2949 - (ch->ch_expect & RR_TX_BREAK) != 0) { 2950 - 2951 - nd->nd_tx_work = 1; 2952 - 2953 - ch->ch_expect &= ~RR_TX_BREAK; 2954 - 2955 - if (ch->ch_break_time != 0) { 2956 - ch->ch_send |= RR_TX_BREAK; 2957 - } else { 2958 - ch->ch_send &= ~RR_TX_BREAK; 2959 - ch->ch_flag &= ~CH_TX_BREAK; 2960 - wake_up_interruptible(&ch->ch_flag_wait); 2961 - } 2962 - } 2963 - break; 2964 - 2965 - case 13: 2966 - case 14: 2967 - error = "Unrecognized command"; 2968 - goto prot_error; 2969 - 2970 - /* 2971 - * Decode Special Codes. 2972 - */ 2973 - 2974 - case 15: 2975 - switch (n1) { 2976 - /* 2977 - * One byte module select. 2978 - */ 2979 - 2980 - case 0: 2981 - case 1: 2982 - case 2: 2983 - case 3: 2984 - case 4: 2985 - case 5: 2986 - case 6: 2987 - case 7: 2988 - plen = 1; 2989 - nd->nd_rx_module = n1; 2990 - break; 2991 - 2992 - /* 2993 - * Two byte module select. 2994 - */ 2995 - 2996 - case 8: 2997 - plen = 2; 2998 - if (remain < plen) 2999 - goto done; 3000 - 3001 - nd->nd_rx_module = b[1]; 3002 - break; 3003 - 3004 - /* 3005 - * ID Request packet. 3006 - */ 3007 - 3008 - case 11: 3009 - if (remain < 4) 3010 - goto done; 3011 - 3012 - plen = get_unaligned_be16(b + 2); 3013 - 3014 - if (plen < 12 || plen > 1000) { 3015 - error = "Response Packet length error"; 3016 - goto prot_error; 3017 - } 3018 - 3019 - nd->nd_tx_work = 1; 3020 - 3021 - switch (b[1]) { 3022 - /* 3023 - * Echo packet. 3024 - */ 3025 - 3026 - case 0: 3027 - nd->nd_send |= NR_ECHO; 3028 - break; 3029 - 3030 - /* 3031 - * ID Response packet. 3032 - */ 3033 - 3034 - case 1: 3035 - nd->nd_send |= NR_IDENT; 3036 - break; 3037 - 3038 - /* 3039 - * ID Response packet. 3040 - */ 3041 - 3042 - case 32: 3043 - nd->nd_send |= NR_PASSWORD; 3044 - break; 3045 - 3046 - } 3047 - break; 3048 - 3049 - /* 3050 - * Various node-level response packets. 3051 - */ 3052 - 3053 - case 12: 3054 - if (remain < 4) 3055 - goto done; 3056 - 3057 - plen = get_unaligned_be16(b + 2); 3058 - 3059 - if (plen < 4 || plen > 1000) { 3060 - error = "Response Packet length error"; 3061 - goto prot_error; 3062 - } 3063 - 3064 - nd->nd_tx_work = 1; 3065 - 3066 - switch (b[1]) { 3067 - /* 3068 - * Echo packet. 3069 - */ 3070 - 3071 - case 0: 3072 - nd->nd_expect &= ~NR_ECHO; 3073 - break; 3074 - 3075 - /* 3076 - * Product Response Packet. 3077 - */ 3078 - 3079 - case 1: 3080 - { 3081 - int desclen; 3082 - 3083 - nd->nd_hw_ver = (b[8] << 8) | b[9]; 3084 - nd->nd_sw_ver = (b[10] << 8) | b[11]; 3085 - nd->nd_hw_id = b[6]; 3086 - desclen = (plen - 12 > MAX_DESC_LEN - 1) ? MAX_DESC_LEN - 1 : 3087 - plen - 12; 3088 - 3089 - if (desclen <= 0) { 3090 - error = "Response Packet desclen error"; 3091 - goto prot_error; 3092 - } 3093 - 3094 - strncpy(nd->nd_ps_desc, b + 12, desclen); 3095 - nd->nd_ps_desc[desclen] = 0; 3096 - } 3097 - 3098 - nd->nd_expect &= ~NR_IDENT; 3099 - break; 3100 - 3101 - /* 3102 - * Capability Response Packet. 3103 - */ 3104 - 3105 - case 2: 3106 - { 3107 - int nn = get_unaligned_be16(b + 4); 3108 - 3109 - if (nn > CHAN_MAX) 3110 - nn = CHAN_MAX; 3111 - 3112 - dgrp_chan_count(nd, nn); 3113 - } 3114 - 3115 - nd->nd_expect &= ~NR_CAPABILITY; 3116 - break; 3117 - 3118 - /* 3119 - * VPD Response Packet. 3120 - */ 3121 - 3122 - case 15: 3123 - /* 3124 - * NOTE: case 15 is here ONLY because the EtherLite 3125 - * is broken, and sends a response to 24 back as 15. 3126 - * To resolve this, the EtherLite firmware is now 3127 - * fixed to send back 24 correctly, but, for backwards 3128 - * compatibility, we now have reserved 15 for the 3129 - * bad EtherLite response to 24 as well. 3130 - */ 3131 - 3132 - /* Fallthru! */ 3133 - 3134 - case 24: 3135 - 3136 - /* 3137 - * If the product doesn't support VPD, 3138 - * it will send back a null IDRESP, 3139 - * which is a length of 4 bytes. 3140 - */ 3141 - if (plen > 4) { 3142 - memcpy(nd->nd_vpd, b + 4, min(plen - 4, (long) VPDSIZE)); 3143 - nd->nd_vpd_len = min(plen - 4, (long) VPDSIZE); 3144 - } 3145 - 3146 - nd->nd_expect &= ~NR_VPD; 3147 - break; 3148 - 3149 - default: 3150 - goto decode_error; 3151 - } 3152 - 3153 - if (nd->nd_expect == 0 && 3154 - nd->nd_state == NS_WAIT_QUERY) { 3155 - nd->nd_state = NS_READY; 3156 - } 3157 - break; 3158 - 3159 - /* 3160 - * Debug packet. 3161 - */ 3162 - 3163 - case 14: 3164 - if (remain < 4) 3165 - goto done; 3166 - 3167 - plen = get_unaligned_be16(b + 2) + 4; 3168 - 3169 - if (plen > 1000) { 3170 - error = "Debug Packet too large"; 3171 - goto prot_error; 3172 - } 3173 - 3174 - if (remain < plen) 3175 - goto done; 3176 - break; 3177 - 3178 - /* 3179 - * Handle reset packet. 3180 - */ 3181 - 3182 - case 15: 3183 - if (remain < 2) 3184 - goto done; 3185 - 3186 - plen = 2 + b[1]; 3187 - 3188 - if (remain < plen) 3189 - goto done; 3190 - 3191 - nd->nd_tx_work = 1; 3192 - 3193 - n = b[plen]; 3194 - b[plen] = 0; 3195 - 3196 - b[plen] = n; 3197 - 3198 - error = "Client Reset Acknowledge"; 3199 - goto prot_error; 3200 - 3201 - default: 3202 - goto decode_error; 3203 - } 3204 - break; 3205 - 3206 - default: 3207 - goto decode_error; 3208 - } 3209 - 3210 - b += plen; 3211 - remain -= plen; 3212 - } 3213 - 3214 - /* 3215 - * When the buffer is exhausted, copy any data left at the 3216 - * top of the buffer back down to the bottom for the next 3217 - * read request. 3218 - */ 3219 - 3220 - done: 3221 - if (remain > 0 && b != buf) 3222 - memcpy(buf, b, remain); 3223 - 3224 - nd->nd_remain = remain; 3225 - return; 3226 - 3227 - /* 3228 - * Handle a decode error. 3229 - */ 3230 - 3231 - decode_error: 3232 - error = "Protocol decode error"; 3233 - 3234 - /* 3235 - * Handle a general protocol error. 3236 - */ 3237 - 3238 - prot_error: 3239 - nd->nd_remain = 0; 3240 - nd->nd_state = NS_SEND_ERROR; 3241 - nd->nd_error = error; 3242 - } 3243 - 3244 - /* 3245 - * dgrp_net_write() -- write data to the network device. 3246 - * 3247 - * A zero byte write indicates that the connection to the RealPort 3248 - * device has been broken. 3249 - * 3250 - * A non-zero write indicates data from the RealPort device. 3251 - */ 3252 - static ssize_t dgrp_net_write(struct file *file, const char __user *buf, 3253 - size_t count, loff_t *ppos) 3254 - { 3255 - struct nd_struct *nd; 3256 - ssize_t rtn = 0; 3257 - long n; 3258 - long total = 0; 3259 - 3260 - /* 3261 - * Get the node pointer, and quit if it doesn't exist. 3262 - */ 3263 - nd = (struct nd_struct *)(file->private_data); 3264 - if (!nd) 3265 - return -ENXIO; 3266 - 3267 - /* 3268 - * Grab the NET lock. 3269 - */ 3270 - down(&nd->nd_net_semaphore); 3271 - 3272 - nd->nd_write_count++; 3273 - 3274 - /* 3275 - * Handle disconnect. 3276 - */ 3277 - 3278 - if (count == 0) { 3279 - dgrp_net_idle(nd); 3280 - /* 3281 - * Set the active port count to zero. 3282 - */ 3283 - dgrp_chan_count(nd, 0); 3284 - goto unlock; 3285 - } 3286 - 3287 - /* 3288 - * Loop to process entire receive packet. 3289 - */ 3290 - 3291 - while (count > 0) { 3292 - n = UIO_MAX - nd->nd_remain; 3293 - 3294 - if (n > count) 3295 - n = count; 3296 - 3297 - nd->nd_rx_byte += n + nd->nd_link.lk_header_size; 3298 - 3299 - rtn = copy_from_user(nd->nd_iobuf + nd->nd_remain, 3300 - (void __user *) buf + total, n); 3301 - if (rtn) { 3302 - rtn = -EFAULT; 3303 - goto unlock; 3304 - } 3305 - 3306 - *ppos += n; 3307 - 3308 - total += n; 3309 - 3310 - count -= n; 3311 - 3312 - if (nd->nd_mon_buf) 3313 - dgrp_monitor_data(nd, RPDUMP_SERVER, 3314 - nd->nd_iobuf + nd->nd_remain, n); 3315 - 3316 - nd->nd_remain += n; 3317 - 3318 - dgrp_receive(nd); 3319 - } 3320 - 3321 - rtn = total; 3322 - 3323 - unlock: 3324 - /* 3325 - * Release the NET lock. 3326 - */ 3327 - up(&nd->nd_net_semaphore); 3328 - 3329 - return rtn; 3330 - } 3331 - 3332 - 3333 - /* 3334 - * dgrp_net_select() 3335 - * Determine whether a device is ready to be read or written to, and 3336 - * sleep if not. 3337 - */ 3338 - static unsigned int dgrp_net_select(struct file *file, 3339 - struct poll_table_struct *table) 3340 - { 3341 - unsigned int retval = 0; 3342 - struct nd_struct *nd = file->private_data; 3343 - 3344 - poll_wait(file, &nd->nd_tx_waitq, table); 3345 - 3346 - if (nd->nd_tx_ready) 3347 - retval |= POLLIN | POLLRDNORM; /* Conditionally readable */ 3348 - 3349 - retval |= POLLOUT | POLLWRNORM; /* Always writeable */ 3350 - 3351 - return retval; 3352 - } 3353 - 3354 - /* 3355 - * dgrp_net_ioctl 3356 - * 3357 - * Implement those functions which allow the network daemon to control 3358 - * the network parameters in the driver. The ioctls include ones to 3359 - * get and set the link speed parameters for the PortServer. 3360 - */ 3361 - static long dgrp_net_ioctl(struct file *file, unsigned int cmd, 3362 - unsigned long arg) 3363 - { 3364 - struct nd_struct *nd; 3365 - int rtn = 0; 3366 - long size = _IOC_SIZE(cmd); 3367 - struct link_struct link; 3368 - 3369 - nd = file->private_data; 3370 - 3371 - if (_IOC_DIR(cmd) & _IOC_READ) 3372 - rtn = access_ok(VERIFY_WRITE, (void __user *) arg, size); 3373 - else if (_IOC_DIR(cmd) & _IOC_WRITE) 3374 - rtn = access_ok(VERIFY_READ, (void __user *) arg, size); 3375 - 3376 - if (!rtn) 3377 - return rtn; 3378 - 3379 - switch (cmd) { 3380 - case DIGI_SETLINK: 3381 - if (size != sizeof(struct link_struct)) 3382 - return -EINVAL; 3383 - 3384 - if (copy_from_user(&link, (void __user *)arg, size)) 3385 - return -EFAULT; 3386 - 3387 - if (link.lk_fast_rate < 9600) 3388 - link.lk_fast_rate = 9600; 3389 - 3390 - if (link.lk_slow_rate < 2400) 3391 - link.lk_slow_rate = 2400; 3392 - 3393 - if (link.lk_fast_rate > 10000000) 3394 - link.lk_fast_rate = 10000000; 3395 - 3396 - if (link.lk_slow_rate > link.lk_fast_rate) 3397 - link.lk_slow_rate = link.lk_fast_rate; 3398 - 3399 - if (link.lk_fast_delay > 2000) 3400 - link.lk_fast_delay = 2000; 3401 - 3402 - if (link.lk_slow_delay > 10000) 3403 - link.lk_slow_delay = 10000; 3404 - 3405 - if (link.lk_fast_delay < 60) 3406 - link.lk_fast_delay = 60; 3407 - 3408 - if (link.lk_slow_delay < link.lk_fast_delay) 3409 - link.lk_slow_delay = link.lk_fast_delay; 3410 - 3411 - if (link.lk_header_size < 2) 3412 - link.lk_header_size = 2; 3413 - 3414 - if (link.lk_header_size > 128) 3415 - link.lk_header_size = 128; 3416 - 3417 - link.lk_fast_rate /= 8 * 1000 / dgrp_poll_tick; 3418 - link.lk_slow_rate /= 8 * 1000 / dgrp_poll_tick; 3419 - 3420 - link.lk_fast_delay /= dgrp_poll_tick; 3421 - link.lk_slow_delay /= dgrp_poll_tick; 3422 - 3423 - nd->nd_link = link; 3424 - 3425 - break; 3426 - 3427 - case DIGI_GETLINK: 3428 - if (size != sizeof(struct link_struct)) 3429 - return -EINVAL; 3430 - 3431 - if (copy_to_user((void __user *)arg, (void *)(&nd->nd_link), 3432 - size)) 3433 - return -EFAULT; 3434 - 3435 - break; 3436 - 3437 - default: 3438 - return -EINVAL; 3439 - 3440 - } 3441 - 3442 - return 0; 3443 - } 3444 - 3445 - /** 3446 - * dgrp_poll_handler() -- handler for poll timer 3447 - * 3448 - * As each timer expires, it determines (a) whether the "transmit" 3449 - * waiter needs to be woken up, and (b) whether the poller needs to 3450 - * be rescheduled. 3451 - */ 3452 - void dgrp_poll_handler(unsigned long arg) 3453 - { 3454 - struct dgrp_poll_data *poll_data; 3455 - struct nd_struct *nd; 3456 - struct link_struct *lk; 3457 - ulong time; 3458 - ulong poll_time; 3459 - ulong freq; 3460 - ulong lock_flags; 3461 - 3462 - poll_data = (struct dgrp_poll_data *) arg; 3463 - freq = 1000 / poll_data->poll_tick; 3464 - poll_data->poll_round += 17; 3465 - 3466 - if (poll_data->poll_round >= freq) 3467 - poll_data->poll_round -= freq; 3468 - 3469 - /* 3470 - * Loop to process all open nodes. 3471 - * 3472 - * For each node, determine the rate at which it should 3473 - * be transmitting data. Then if the node should wake up 3474 - * and transmit data now, enable the net receive select 3475 - * to get the transmit going. 3476 - */ 3477 - 3478 - list_for_each_entry(nd, &nd_struct_list, list) { 3479 - 3480 - lk = &nd->nd_link; 3481 - 3482 - /* 3483 - * Decrement statistics. These are only for use with 3484 - * KME, so don't worry that the operations are done 3485 - * unlocked, and so the results are occasionally wrong. 3486 - */ 3487 - 3488 - nd->nd_read_count -= (nd->nd_read_count + 3489 - poll_data->poll_round) / freq; 3490 - nd->nd_write_count -= (nd->nd_write_count + 3491 - poll_data->poll_round) / freq; 3492 - nd->nd_send_count -= (nd->nd_send_count + 3493 - poll_data->poll_round) / freq; 3494 - nd->nd_tx_byte -= (nd->nd_tx_byte + 3495 - poll_data->poll_round) / freq; 3496 - nd->nd_rx_byte -= (nd->nd_rx_byte + 3497 - poll_data->poll_round) / freq; 3498 - 3499 - /* 3500 - * Wake the daemon to transmit data only when there is 3501 - * enough byte credit to send data. 3502 - * 3503 - * The results are approximate because the operations 3504 - * are performed unlocked, and we are inspecting 3505 - * data asynchronously updated elsewhere. The whole 3506 - * thing is just approximation anyway, so that should 3507 - * be okay. 3508 - */ 3509 - 3510 - if (lk->lk_slow_rate >= UIO_MAX) { 3511 - 3512 - nd->nd_delay = 0; 3513 - nd->nd_rate = UIO_MAX; 3514 - 3515 - nd->nd_tx_deposit = nd->nd_tx_charge + 3 * UIO_MAX; 3516 - nd->nd_tx_credit = 3 * UIO_MAX; 3517 - 3518 - } else { 3519 - 3520 - long rate; 3521 - long delay; 3522 - long deposit; 3523 - long charge; 3524 - long size; 3525 - long excess; 3526 - 3527 - long seq_in = nd->nd_seq_in; 3528 - long seq_out = nd->nd_seq_out; 3529 - 3530 - /* 3531 - * If there are no outstanding packets, run at the 3532 - * fastest rate. 3533 - */ 3534 - 3535 - if (seq_in == seq_out) { 3536 - delay = 0; 3537 - rate = lk->lk_fast_rate; 3538 - } 3539 - 3540 - /* 3541 - * Otherwise compute the transmit rate based on the 3542 - * delay since the oldest packet. 3543 - */ 3544 - 3545 - else { 3546 - /* 3547 - * The actual delay is computed as the 3548 - * time since the oldest unacknowledged 3549 - * packet was sent, minus the time it 3550 - * took to send that packet to the server. 3551 - */ 3552 - 3553 - delay = ((jiffies - nd->nd_seq_time[seq_out]) 3554 - - (nd->nd_seq_size[seq_out] / 3555 - lk->lk_fast_rate)); 3556 - 3557 - /* 3558 - * If the delay is less than the "fast" 3559 - * delay, transmit full speed. If greater 3560 - * than the "slow" delay, transmit at the 3561 - * "slow" speed. In between, interpolate 3562 - * between the fast and slow speeds. 3563 - */ 3564 - 3565 - rate = 3566 - (delay <= lk->lk_fast_delay ? 3567 - lk->lk_fast_rate : 3568 - delay >= lk->lk_slow_delay ? 3569 - lk->lk_slow_rate : 3570 - (lk->lk_slow_rate + 3571 - (lk->lk_slow_delay - delay) * 3572 - (lk->lk_fast_rate - lk->lk_slow_rate) / 3573 - (lk->lk_slow_delay - lk->lk_fast_delay) 3574 - ) 3575 - ); 3576 - } 3577 - 3578 - nd->nd_delay = delay; 3579 - nd->nd_rate = rate; 3580 - 3581 - /* 3582 - * Increase the transmit credit by depositing the 3583 - * current transmit rate. 3584 - */ 3585 - 3586 - deposit = nd->nd_tx_deposit; 3587 - charge = nd->nd_tx_charge; 3588 - 3589 - deposit += rate; 3590 - 3591 - /* 3592 - * If the available transmit credit becomes too large, 3593 - * reduce the deposit to correct the value. 3594 - * 3595 - * Too large is the max of: 3596 - * 6 times the header size 3597 - * 3 times the current transmit rate. 3598 - */ 3599 - 3600 - size = 2 * nd->nd_link.lk_header_size; 3601 - 3602 - if (size < rate) 3603 - size = rate; 3604 - 3605 - size *= 3; 3606 - 3607 - excess = deposit - charge - size; 3608 - 3609 - if (excess > 0) 3610 - deposit -= excess; 3611 - 3612 - nd->nd_tx_deposit = deposit; 3613 - nd->nd_tx_credit = deposit - charge; 3614 - 3615 - /* 3616 - * Wake the transmit task only if the transmit credit 3617 - * is at least 3 times the transmit header size. 3618 - */ 3619 - 3620 - size = 3 * lk->lk_header_size; 3621 - 3622 - if (nd->nd_tx_credit < size) 3623 - continue; 3624 - } 3625 - 3626 - 3627 - /* 3628 - * Enable the READ select to wake the daemon if there 3629 - * is useful work for the drp_read routine to perform. 3630 - */ 3631 - 3632 - if (waitqueue_active(&nd->nd_tx_waitq) && 3633 - (nd->nd_tx_work != 0 || 3634 - (ulong)(jiffies - nd->nd_tx_time) >= IDLE_MAX)) { 3635 - nd->nd_tx_ready = 1; 3636 - 3637 - wake_up_interruptible(&nd->nd_tx_waitq); 3638 - 3639 - /* not needed */ 3640 - /* nd->nd_flag &= ~ND_SELECT; */ 3641 - } 3642 - } 3643 - 3644 - 3645 - /* 3646 - * Schedule ourself back at the nominal wakeup interval. 3647 - */ 3648 - spin_lock_irqsave(&poll_data->poll_lock, lock_flags); 3649 - 3650 - poll_data->node_active_count--; 3651 - if (poll_data->node_active_count > 0) { 3652 - poll_data->node_active_count++; 3653 - poll_time = poll_data->timer.expires + 3654 - poll_data->poll_tick * HZ / 1000; 3655 - 3656 - time = poll_time - jiffies; 3657 - 3658 - if (time >= 2 * poll_data->poll_tick) 3659 - poll_time = jiffies + dgrp_poll_tick * HZ / 1000; 3660 - 3661 - poll_data->timer.expires = poll_time; 3662 - add_timer(&poll_data->timer); 3663 - } 3664 - 3665 - spin_unlock_irqrestore(&poll_data->poll_lock, lock_flags); 3666 - }
-156
drivers/staging/dgrp/dgrp_ports_ops.c
··· 1 - /* 2 - * 3 - * Copyright 1999-2000 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 - * 20 - */ 21 - 22 - /* 23 - * 24 - * Filename: 25 - * 26 - * dgrp_ports_ops.c 27 - * 28 - * Description: 29 - * 30 - * Handle the file operations required for the /proc/dgrp/ports/... 31 - * devices. Basically gathers tty status for the node and returns it. 32 - * 33 - * Author: 34 - * 35 - * James A. Puzzo 36 - * 37 - */ 38 - 39 - #include <linux/module.h> 40 - #include <linux/proc_fs.h> 41 - #include <linux/tty.h> 42 - #include <linux/sched.h> 43 - #include <linux/seq_file.h> 44 - 45 - #include "dgrp_common.h" 46 - 47 - /* File operation declarations */ 48 - static int dgrp_ports_open(struct inode *, struct file *); 49 - 50 - const struct file_operations dgrp_ports_ops = { 51 - .owner = THIS_MODULE, 52 - .open = dgrp_ports_open, 53 - .read = seq_read, 54 - .llseek = seq_lseek, 55 - .release = seq_release 56 - }; 57 - 58 - static void *dgrp_ports_seq_start(struct seq_file *seq, loff_t *pos) 59 - { 60 - if (*pos == 0) 61 - seq_puts(seq, "#num tty_open pr_open tot_wait MSTAT IFLAG OFLAG CFLAG BPS DIGIFLAGS\n"); 62 - 63 - return pos; 64 - } 65 - 66 - static void *dgrp_ports_seq_next(struct seq_file *seq, void *v, loff_t *pos) 67 - { 68 - struct nd_struct *nd = seq->private; 69 - 70 - if (*pos >= nd->nd_chan_count) 71 - return NULL; 72 - 73 - *pos += 1; 74 - 75 - return pos; 76 - } 77 - 78 - static void dgrp_ports_seq_stop(struct seq_file *seq, void *v) 79 - { 80 - } 81 - 82 - static int dgrp_ports_seq_show(struct seq_file *seq, void *v) 83 - { 84 - loff_t *pos = v; 85 - struct nd_struct *nd; 86 - struct ch_struct *ch; 87 - struct un_struct *tun, *pun; 88 - unsigned int totcnt; 89 - 90 - nd = seq->private; 91 - if (!nd) 92 - return 0; 93 - 94 - if (*pos >= nd->nd_chan_count) 95 - return 0; 96 - 97 - ch = &nd->nd_chan[*pos]; 98 - tun = &ch->ch_tun; 99 - pun = &ch->ch_pun; 100 - 101 - /* 102 - * If port is not open and no one is waiting to 103 - * open it, the modem signal values can't be 104 - * trusted, and will be zeroed. 105 - */ 106 - totcnt = tun->un_open_count + 107 - pun->un_open_count + 108 - ch->ch_wait_count[0] + 109 - ch->ch_wait_count[1] + 110 - ch->ch_wait_count[2]; 111 - 112 - seq_printf(seq, "%02d %02d %02d %02d 0x%04X 0x%04X 0x%04X 0x%04X %-6d 0x%04X\n", 113 - (int) *pos, 114 - tun->un_open_count, 115 - pun->un_open_count, 116 - ch->ch_wait_count[0] + 117 - ch->ch_wait_count[1] + 118 - ch->ch_wait_count[2], 119 - (totcnt ? ch->ch_s_mlast : 0), 120 - ch->ch_s_iflag, 121 - ch->ch_s_oflag, 122 - ch->ch_s_cflag, 123 - (ch->ch_s_brate ? (1843200 / ch->ch_s_brate) : 0), 124 - ch->ch_digi.digi_flags); 125 - 126 - return 0; 127 - } 128 - 129 - static const struct seq_operations ports_seq_ops = { 130 - .start = dgrp_ports_seq_start, 131 - .next = dgrp_ports_seq_next, 132 - .stop = dgrp_ports_seq_stop, 133 - .show = dgrp_ports_seq_show, 134 - }; 135 - 136 - /** 137 - * dgrp_ports_open -- open the /proc/dgrp/ports/... device 138 - * @inode: struct inode * 139 - * @file: struct file * 140 - * 141 - * Open function to open the /proc/dgrp/ports device for a PortServer. 142 - * This is the open function for struct file_operations 143 - */ 144 - static int dgrp_ports_open(struct inode *inode, struct file *file) 145 - { 146 - struct seq_file *seq; 147 - int rtn; 148 - 149 - rtn = seq_open(file, &ports_seq_ops); 150 - if (!rtn) { 151 - seq = file->private_data; 152 - seq->private = PDE_DATA(inode); 153 - } 154 - 155 - return rtn; 156 - }
-541
drivers/staging/dgrp/dgrp_specproc.c
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * James Puzzo <jamesp at digi dot com> 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2, or (at your option) 9 - * any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 13 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 14 - * PURPOSE. See the GNU General Public License for more details. 15 - * 16 - */ 17 - 18 - /* 19 - * 20 - * Filename: 21 - * 22 - * dgrp_specproc.c 23 - * 24 - * Description: 25 - * 26 - * Handle the "config" proc entry for the linux realport device driver 27 - * and provide slots for the "net" and "mon" devices 28 - * 29 - * Author: 30 - * 31 - * James A. Puzzo 32 - * 33 - */ 34 - 35 - #include <linux/module.h> 36 - #include <linux/tty.h> 37 - #include <linux/sched.h> 38 - #include <linux/cred.h> 39 - #include <linux/proc_fs.h> 40 - #include <linux/slab.h> 41 - #include <linux/ctype.h> 42 - #include <linux/seq_file.h> 43 - #include <linux/uaccess.h> 44 - #include <linux/vmalloc.h> 45 - 46 - #include "dgrp_common.h" 47 - 48 - static struct proc_dir_entry *dgrp_proc_dir_entry; 49 - 50 - static int dgrp_add_id(long id); 51 - static int dgrp_remove_nd(struct nd_struct *nd); 52 - static struct proc_dir_entry *add_proc_file(struct nd_struct *node, 53 - struct proc_dir_entry *root, 54 - const struct file_operations *fops); 55 - 56 - /* File operation declarations */ 57 - static int parse_write_config(char *); 58 - 59 - static ssize_t dgrp_config_proc_write(struct file *file, 60 - const char __user *buffer, 61 - size_t count, loff_t *pos); 62 - 63 - static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file); 64 - static int dgrp_info_proc_open(struct inode *inode, struct file *file); 65 - static int dgrp_config_proc_open(struct inode *inode, struct file *file); 66 - 67 - static const struct file_operations config_proc_file_ops = { 68 - .owner = THIS_MODULE, 69 - .open = dgrp_config_proc_open, 70 - .read = seq_read, 71 - .llseek = seq_lseek, 72 - .release = seq_release, 73 - .write = dgrp_config_proc_write, 74 - }; 75 - 76 - static const struct file_operations info_proc_file_ops = { 77 - .owner = THIS_MODULE, 78 - .open = dgrp_info_proc_open, 79 - .read = seq_read, 80 - .llseek = seq_lseek, 81 - .release = single_release, 82 - }; 83 - 84 - static const struct file_operations nodeinfo_proc_file_ops = { 85 - .owner = THIS_MODULE, 86 - .open = dgrp_nodeinfo_proc_open, 87 - .read = seq_read, 88 - .llseek = seq_lseek, 89 - .release = seq_release, 90 - }; 91 - 92 - static struct proc_dir_entry *net_entry_pointer; 93 - static struct proc_dir_entry *mon_entry_pointer; 94 - static struct proc_dir_entry *dpa_entry_pointer; 95 - static struct proc_dir_entry *ports_entry_pointer; 96 - 97 - static void remove_files(struct nd_struct *nd) 98 - { 99 - char buf[3]; 100 - ID_TO_CHAR(nd->nd_ID, buf); 101 - dgrp_remove_node_class_sysfs_files(nd); 102 - if (nd->nd_net_de) 103 - remove_proc_entry(buf, net_entry_pointer); 104 - if (nd->nd_mon_de) 105 - remove_proc_entry(buf, mon_entry_pointer); 106 - if (nd->nd_dpa_de) 107 - remove_proc_entry(buf, dpa_entry_pointer); 108 - if (nd->nd_ports_de) 109 - remove_proc_entry(buf, ports_entry_pointer); 110 - } 111 - 112 - void dgrp_unregister_proc(void) 113 - { 114 - net_entry_pointer = NULL; 115 - mon_entry_pointer = NULL; 116 - dpa_entry_pointer = NULL; 117 - ports_entry_pointer = NULL; 118 - 119 - if (dgrp_proc_dir_entry) { 120 - struct nd_struct *nd; 121 - list_for_each_entry(nd, &nd_struct_list, list) 122 - remove_files(nd); 123 - remove_proc_entry("dgrp/config", NULL); 124 - remove_proc_entry("dgrp/info", NULL); 125 - remove_proc_entry("dgrp/nodeinfo", NULL); 126 - remove_proc_entry("dgrp/net", NULL); 127 - remove_proc_entry("dgrp/mon", NULL); 128 - remove_proc_entry("dgrp/dpa", NULL); 129 - remove_proc_entry("dgrp/ports", NULL); 130 - remove_proc_entry("dgrp", NULL); 131 - dgrp_proc_dir_entry = NULL; 132 - } 133 - } 134 - 135 - void dgrp_register_proc(void) 136 - { 137 - /* 138 - * Register /proc/dgrp 139 - */ 140 - dgrp_proc_dir_entry = proc_mkdir("dgrp", NULL); 141 - if (!dgrp_proc_dir_entry) 142 - return; 143 - proc_create("dgrp/config", 0644, NULL, &config_proc_file_ops); 144 - proc_create("dgrp/info", 0644, NULL, &info_proc_file_ops); 145 - proc_create("dgrp/nodeinfo", 0644, NULL, &nodeinfo_proc_file_ops); 146 - net_entry_pointer = proc_mkdir_mode("dgrp/net", 0500, NULL); 147 - mon_entry_pointer = proc_mkdir_mode("dgrp/mon", 0500, NULL); 148 - dpa_entry_pointer = proc_mkdir_mode("dgrp/dpa", 0500, NULL); 149 - ports_entry_pointer = proc_mkdir_mode("dgrp/ports", 0500, NULL); 150 - } 151 - 152 - static void *dgrp_config_proc_start(struct seq_file *m, loff_t *pos) 153 - { 154 - return seq_list_start_head(&nd_struct_list, *pos); 155 - } 156 - 157 - static void *dgrp_config_proc_next(struct seq_file *p, void *v, loff_t *pos) 158 - { 159 - return seq_list_next(v, &nd_struct_list, pos); 160 - } 161 - 162 - static void dgrp_config_proc_stop(struct seq_file *m, void *v) 163 - { 164 - } 165 - 166 - static int dgrp_config_proc_show(struct seq_file *m, void *v) 167 - { 168 - struct nd_struct *nd; 169 - char tmp_id[4]; 170 - 171 - if (v == &nd_struct_list) { 172 - seq_puts(m, "#-----------------------------------------------------------------------------\n"); 173 - seq_puts(m, "# Avail\n"); 174 - seq_puts(m, "# ID Major State Ports\n"); 175 - return 0; 176 - } 177 - 178 - nd = list_entry(v, struct nd_struct, list); 179 - 180 - ID_TO_CHAR(nd->nd_ID, tmp_id); 181 - 182 - seq_printf(m, " %-2.2s %-5ld %-10.10s %-5d\n", 183 - tmp_id, 184 - nd->nd_major, 185 - ND_STATE_STR(nd->nd_state), 186 - nd->nd_chan_count); 187 - 188 - return 0; 189 - } 190 - 191 - static const struct seq_operations proc_config_ops = { 192 - .start = dgrp_config_proc_start, 193 - .next = dgrp_config_proc_next, 194 - .stop = dgrp_config_proc_stop, 195 - .show = dgrp_config_proc_show, 196 - }; 197 - 198 - static int dgrp_config_proc_open(struct inode *inode, struct file *file) 199 - { 200 - return seq_open(file, &proc_config_ops); 201 - } 202 - 203 - 204 - /* 205 - * When writing configuration information, each "record" (i.e. each 206 - * write) is treated as an independent request. See the "parse" 207 - * description for more details. 208 - */ 209 - static ssize_t dgrp_config_proc_write(struct file *file, 210 - const char __user *buffer, 211 - size_t count, loff_t *pos) 212 - { 213 - ssize_t retval; 214 - char *inbuf, *sp; 215 - char *line, *ldelim; 216 - 217 - if (count > 32768) 218 - return -EINVAL; 219 - 220 - inbuf = sp = vzalloc(count + 1); 221 - if (!inbuf) 222 - return -ENOMEM; 223 - 224 - if (copy_from_user(inbuf, buffer, count)) { 225 - retval = -EFAULT; 226 - goto done; 227 - } 228 - 229 - inbuf[count] = 0; 230 - 231 - ldelim = "\n"; 232 - 233 - line = strpbrk(sp, ldelim); 234 - while (line) { 235 - *line = 0; 236 - retval = parse_write_config(sp); 237 - if (retval) 238 - goto done; 239 - 240 - sp = line + 1; 241 - line = strpbrk(sp, ldelim); 242 - } 243 - 244 - retval = count; 245 - done: 246 - vfree(inbuf); 247 - return retval; 248 - } 249 - 250 - /* 251 - * ------------------------------------------------------------------------ 252 - * 253 - * The following are the functions to parse input 254 - * 255 - * ------------------------------------------------------------------------ 256 - */ 257 - static inline char *skip_past_ws(const char *str) 258 - { 259 - while ((*str) && !isspace(*str)) 260 - ++str; 261 - 262 - return skip_spaces(str); 263 - } 264 - 265 - static int parse_id(char **c, char *cID) 266 - { 267 - int tmp = **c; 268 - 269 - if (isalnum(tmp) || (tmp == '_')) 270 - cID[0] = tmp; 271 - else 272 - return -EINVAL; 273 - 274 - (*c)++; tmp = **c; 275 - 276 - if (isalnum(tmp) || (tmp == '_')) { 277 - cID[1] = tmp; 278 - (*c)++; 279 - } else 280 - cID[1] = 0; 281 - 282 - return 0; 283 - } 284 - 285 - static int parse_add_config(char *buf) 286 - { 287 - char *c = buf; 288 - int retval; 289 - char cID[2]; 290 - long ID; 291 - 292 - c = skip_past_ws(c); 293 - 294 - retval = parse_id(&c, cID); 295 - if (retval < 0) 296 - return retval; 297 - 298 - ID = CHAR_TO_ID(cID); 299 - 300 - c = skip_past_ws(c); 301 - 302 - return dgrp_add_id(ID); 303 - } 304 - 305 - static int parse_del_config(char *buf) 306 - { 307 - char *c = buf; 308 - int retval; 309 - struct nd_struct *nd; 310 - char cID[2]; 311 - long ID; 312 - long major; 313 - 314 - c = skip_past_ws(c); 315 - 316 - retval = parse_id(&c, cID); 317 - if (retval < 0) 318 - return retval; 319 - 320 - ID = CHAR_TO_ID(cID); 321 - 322 - c = skip_past_ws(c); 323 - 324 - retval = kstrtol(c, 10, &major); 325 - if (retval) 326 - return retval; 327 - 328 - nd = nd_struct_get(major); 329 - if (!nd) 330 - return -EINVAL; 331 - 332 - if ((nd->nd_major != major) || (nd->nd_ID != ID)) 333 - return -EINVAL; 334 - 335 - return dgrp_remove_nd(nd); 336 - } 337 - 338 - static int parse_chg_config(char *buf) 339 - { 340 - return -EINVAL; 341 - } 342 - 343 - /* 344 - * The passed character buffer represents a single configuration request. 345 - * If the first character is a "+", it is parsed as a request to add a 346 - * PortServer 347 - * If the first character is a "-", it is parsed as a request to delete a 348 - * PortServer 349 - * If the first character is a "*", it is parsed as a request to change a 350 - * PortServer 351 - * Any other character (including whitespace) causes the record to be 352 - * ignored. 353 - */ 354 - static int parse_write_config(char *buf) 355 - { 356 - int retval; 357 - 358 - switch (buf[0]) { 359 - case '+': 360 - retval = parse_add_config(buf); 361 - break; 362 - case '-': 363 - retval = parse_del_config(buf); 364 - break; 365 - case '*': 366 - retval = parse_chg_config(buf); 367 - break; 368 - default: 369 - retval = -EINVAL; 370 - } 371 - 372 - return retval; 373 - } 374 - 375 - static int dgrp_info_proc_show(struct seq_file *m, void *v) 376 - { 377 - seq_printf(m, "version: %s\n", DIGI_VERSION); 378 - seq_puts(m, "register_with_sysfs: 1\n"); 379 - seq_printf(m, "pollrate: 0x%08x\t(%d)\n", 380 - dgrp_poll_tick, dgrp_poll_tick); 381 - 382 - return 0; 383 - } 384 - 385 - static int dgrp_info_proc_open(struct inode *inode, struct file *file) 386 - { 387 - return single_open(file, dgrp_info_proc_show, NULL); 388 - } 389 - 390 - 391 - static void *dgrp_nodeinfo_start(struct seq_file *m, loff_t *pos) 392 - { 393 - return seq_list_start_head(&nd_struct_list, *pos); 394 - } 395 - 396 - static void *dgrp_nodeinfo_next(struct seq_file *p, void *v, loff_t *pos) 397 - { 398 - return seq_list_next(v, &nd_struct_list, pos); 399 - } 400 - 401 - static void dgrp_nodeinfo_stop(struct seq_file *m, void *v) 402 - { 403 - } 404 - 405 - static int dgrp_nodeinfo_show(struct seq_file *m, void *v) 406 - { 407 - struct nd_struct *nd; 408 - char hwver[8]; 409 - char swver[8]; 410 - char tmp_id[4]; 411 - 412 - if (v == &nd_struct_list) { 413 - seq_puts(m, "#-----------------------------------------------------------------------------\n"); 414 - seq_puts(m, "# HW HW SW\n"); 415 - seq_puts(m, "# ID State Version ID Version Description\n"); 416 - return 0; 417 - } 418 - 419 - nd = list_entry(v, struct nd_struct, list); 420 - 421 - ID_TO_CHAR(nd->nd_ID, tmp_id); 422 - 423 - if (nd->nd_state == NS_READY) { 424 - sprintf(hwver, "%d.%d", (nd->nd_hw_ver >> 8) & 0xff, 425 - nd->nd_hw_ver & 0xff); 426 - sprintf(swver, "%d.%d", (nd->nd_sw_ver >> 8) & 0xff, 427 - nd->nd_sw_ver & 0xff); 428 - seq_printf(m, " %-2.2s %-10.10s %-7.7s %-3d %-7.7s %-35.35s\n", 429 - tmp_id, 430 - ND_STATE_STR(nd->nd_state), 431 - hwver, 432 - nd->nd_hw_id, 433 - swver, 434 - nd->nd_ps_desc); 435 - 436 - } else { 437 - seq_printf(m, " %-2.2s %-10.10s\n", 438 - tmp_id, 439 - ND_STATE_STR(nd->nd_state)); 440 - } 441 - 442 - return 0; 443 - } 444 - 445 - 446 - static const struct seq_operations nodeinfo_ops = { 447 - .start = dgrp_nodeinfo_start, 448 - .next = dgrp_nodeinfo_next, 449 - .stop = dgrp_nodeinfo_stop, 450 - .show = dgrp_nodeinfo_show, 451 - }; 452 - 453 - static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file) 454 - { 455 - return seq_open(file, &nodeinfo_ops); 456 - } 457 - 458 - /** 459 - * dgrp_add_id() -- creates new nd struct and adds it to list 460 - * @id: id of device to add 461 - */ 462 - static int dgrp_add_id(long id) 463 - { 464 - struct nd_struct *nd; 465 - int ret; 466 - int i; 467 - 468 - nd = kzalloc(sizeof(struct nd_struct), GFP_KERNEL); 469 - if (!nd) 470 - return -ENOMEM; 471 - 472 - nd->nd_major = 0; 473 - nd->nd_ID = id; 474 - 475 - spin_lock_init(&nd->nd_lock); 476 - 477 - init_waitqueue_head(&nd->nd_tx_waitq); 478 - init_waitqueue_head(&nd->nd_mon_wqueue); 479 - init_waitqueue_head(&nd->nd_dpa_wqueue); 480 - sema_init(&nd->nd_mon_semaphore, 1); 481 - sema_init(&nd->nd_net_semaphore, 1); 482 - spin_lock_init(&nd->nd_dpa_lock); 483 - nd->nd_state = NS_CLOSED; 484 - for (i = 0; i < SEQ_MAX; i++) 485 - init_waitqueue_head(&nd->nd_seq_wque[i]); 486 - 487 - /* setup the structures to get the major number */ 488 - ret = dgrp_tty_init(nd); 489 - if (ret) 490 - goto error_out; 491 - 492 - nd->nd_major = nd->nd_serial_ttdriver->major; 493 - 494 - ret = nd_struct_add(nd); 495 - if (ret) 496 - goto error_out; 497 - 498 - dgrp_create_node_class_sysfs_files(nd); 499 - nd->nd_net_de = add_proc_file(nd, net_entry_pointer, &dgrp_net_ops); 500 - nd->nd_mon_de = add_proc_file(nd, mon_entry_pointer, &dgrp_mon_ops); 501 - nd->nd_dpa_de = add_proc_file(nd, dpa_entry_pointer, &dgrp_dpa_ops); 502 - nd->nd_ports_de = add_proc_file(nd, ports_entry_pointer, 503 - &dgrp_ports_ops); 504 - return 0; 505 - 506 - /* FIXME this guy should free the tty driver stored in nd and destroy 507 - * all channel ports */ 508 - error_out: 509 - kfree(nd); 510 - return ret; 511 - 512 - } 513 - 514 - static int dgrp_remove_nd(struct nd_struct *nd) 515 - { 516 - int ret; 517 - 518 - /* Check to see if the selected structure is in use */ 519 - if (nd->nd_tty_ref_cnt) 520 - return -EBUSY; 521 - 522 - remove_files(nd); 523 - 524 - dgrp_tty_uninit(nd); 525 - 526 - ret = nd_struct_del(nd); 527 - if (ret) 528 - return ret; 529 - 530 - kfree(nd); 531 - return 0; 532 - } 533 - 534 - static struct proc_dir_entry *add_proc_file(struct nd_struct *node, 535 - struct proc_dir_entry *root, 536 - const struct file_operations *fops) 537 - { 538 - char buf[3]; 539 - ID_TO_CHAR(node->nd_ID, buf); 540 - return proc_create_data(buf, 0600, root, fops, node); 541 - }
-558
drivers/staging/dgrp/dgrp_sysfs.c
··· 1 - /* 2 - * Copyright 2004 Digi International (www.digi.com) 3 - * Scott H Kilau <Scott_Kilau at digi dot com> 4 - * 5 - * This program is free software; you can redistribute it and/or modify 6 - * it under the terms of the GNU General Public License as published by 7 - * the Free Software Foundation; either version 2, or (at your option) 8 - * any later version. 9 - * 10 - * This program is distributed in the hope that it will be useful, 11 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 12 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 - * PURPOSE. See the GNU General Public License for more details. 14 - * 15 - */ 16 - 17 - #include "dgrp_common.h" 18 - 19 - #include <linux/kernel.h> 20 - #include <linux/module.h> 21 - #include <linux/ctype.h> 22 - #include <linux/string.h> 23 - #include <linux/serial_reg.h> 24 - #include <linux/pci.h> 25 - #include <linux/kdev_t.h> 26 - 27 - 28 - #define PORTSERVER_DIVIDEND 1843200 29 - #define SERIAL_TYPE_NORMAL 1 30 - #define SERIAL_TYPE_CALLOUT 2 31 - #define SERIAL_TYPE_XPRINT 3 32 - 33 - 34 - static struct class *dgrp_class; 35 - static struct device *dgrp_class_nodes_dev; 36 - static struct device *dgrp_class_global_settings_dev; 37 - 38 - 39 - static ssize_t dgrp_class_version_show(struct class *class, 40 - struct class_attribute *attr, char *buf) 41 - { 42 - return snprintf(buf, PAGE_SIZE, "%s\n", DIGI_VERSION); 43 - } 44 - static CLASS_ATTR(driver_version, 0400, dgrp_class_version_show, NULL); 45 - 46 - 47 - static ssize_t dgrp_class_register_with_sysfs_show(struct device *c, 48 - struct device_attribute *attr, 49 - char *buf) 50 - { 51 - return snprintf(buf, PAGE_SIZE, "1\n"); 52 - } 53 - static DEVICE_ATTR(register_with_sysfs, 0400, 54 - dgrp_class_register_with_sysfs_show, NULL); 55 - 56 - 57 - static ssize_t dgrp_class_pollrate_show(struct device *c, 58 - struct device_attribute *attr, 59 - char *buf) 60 - { 61 - return snprintf(buf, PAGE_SIZE, "%d\n", dgrp_poll_tick); 62 - } 63 - 64 - static ssize_t dgrp_class_pollrate_store(struct device *c, 65 - struct device_attribute *attr, 66 - const char *buf, size_t count) 67 - { 68 - if (sscanf(buf, "0x%x\n", &dgrp_poll_tick) != 1) 69 - return -EINVAL; 70 - 71 - return count; 72 - } 73 - static DEVICE_ATTR(pollrate, 0600, dgrp_class_pollrate_show, 74 - dgrp_class_pollrate_store); 75 - 76 - static struct attribute *dgrp_sysfs_global_settings_entries[] = { 77 - &dev_attr_pollrate.attr, 78 - &dev_attr_register_with_sysfs.attr, 79 - NULL 80 - }; 81 - 82 - 83 - static struct attribute_group dgrp_global_settings_attribute_group = { 84 - .name = NULL, 85 - .attrs = dgrp_sysfs_global_settings_entries, 86 - }; 87 - 88 - 89 - 90 - int dgrp_create_class_sysfs_files(void) 91 - { 92 - int ret = 0; 93 - int max_majors = 1U << (32 - MINORBITS); 94 - 95 - dgrp_class = class_create(THIS_MODULE, "digi_realport"); 96 - if (IS_ERR(dgrp_class)) 97 - return PTR_ERR(dgrp_class); 98 - ret = class_create_file(dgrp_class, &class_attr_driver_version); 99 - if (ret) 100 - goto err_class; 101 - 102 - dgrp_class_global_settings_dev = device_create(dgrp_class, NULL, 103 - MKDEV(0, max_majors + 1), NULL, "driver_settings"); 104 - if (IS_ERR(dgrp_class_global_settings_dev)) { 105 - ret = PTR_ERR(dgrp_class_global_settings_dev); 106 - goto err_file; 107 - } 108 - ret = sysfs_create_group(&dgrp_class_global_settings_dev->kobj, 109 - &dgrp_global_settings_attribute_group); 110 - if (ret) { 111 - pr_alert("%s: failed to create sysfs global settings device attributes.\n", 112 - __func__); 113 - goto err_dev1; 114 - } 115 - 116 - dgrp_class_nodes_dev = device_create(dgrp_class, NULL, 117 - MKDEV(0, max_majors + 2), NULL, "nodes"); 118 - if (IS_ERR(dgrp_class_nodes_dev)) { 119 - ret = PTR_ERR(dgrp_class_nodes_dev); 120 - goto err_group; 121 - } 122 - 123 - return 0; 124 - err_group: 125 - sysfs_remove_group(&dgrp_class_global_settings_dev->kobj, 126 - &dgrp_global_settings_attribute_group); 127 - err_dev1: 128 - device_destroy(dgrp_class, MKDEV(0, max_majors + 1)); 129 - err_file: 130 - class_remove_file(dgrp_class, &class_attr_driver_version); 131 - err_class: 132 - class_destroy(dgrp_class); 133 - return ret; 134 - } 135 - 136 - 137 - void dgrp_remove_class_sysfs_files(void) 138 - { 139 - struct nd_struct *nd; 140 - int max_majors = 1U << (32 - MINORBITS); 141 - 142 - list_for_each_entry(nd, &nd_struct_list, list) 143 - dgrp_remove_node_class_sysfs_files(nd); 144 - 145 - sysfs_remove_group(&dgrp_class_global_settings_dev->kobj, 146 - &dgrp_global_settings_attribute_group); 147 - 148 - class_remove_file(dgrp_class, &class_attr_driver_version); 149 - 150 - device_destroy(dgrp_class, MKDEV(0, max_majors + 1)); 151 - device_destroy(dgrp_class, MKDEV(0, max_majors + 2)); 152 - class_destroy(dgrp_class); 153 - } 154 - 155 - static ssize_t dgrp_node_state_show(struct device *c, 156 - struct device_attribute *attr, char *buf) 157 - { 158 - struct nd_struct *nd; 159 - 160 - if (!c) 161 - return 0; 162 - nd = dev_get_drvdata(c); 163 - if (!nd) 164 - return 0; 165 - 166 - return snprintf(buf, PAGE_SIZE, "%s\n", ND_STATE_STR(nd->nd_state)); 167 - } 168 - 169 - static DEVICE_ATTR(state, 0600, dgrp_node_state_show, NULL); 170 - 171 - static ssize_t dgrp_node_description_show(struct device *c, 172 - struct device_attribute *attr, 173 - char *buf) 174 - { 175 - struct nd_struct *nd; 176 - 177 - if (!c) 178 - return 0; 179 - nd = dev_get_drvdata(c); 180 - if (!nd) 181 - return 0; 182 - 183 - if (nd->nd_state == NS_READY) 184 - return snprintf(buf, PAGE_SIZE, "%s\n", nd->nd_ps_desc); 185 - return 0; 186 - } 187 - static DEVICE_ATTR(description_info, 0600, dgrp_node_description_show, NULL); 188 - 189 - static ssize_t dgrp_node_hw_version_show(struct device *c, 190 - struct device_attribute *attr, 191 - char *buf) 192 - { 193 - struct nd_struct *nd; 194 - 195 - if (!c) 196 - return 0; 197 - nd = dev_get_drvdata(c); 198 - if (!nd) 199 - return 0; 200 - 201 - if (nd->nd_state == NS_READY) 202 - return snprintf(buf, PAGE_SIZE, "%d.%d\n", 203 - (nd->nd_hw_ver >> 8) & 0xff, 204 - nd->nd_hw_ver & 0xff); 205 - 206 - return 0; 207 - } 208 - static DEVICE_ATTR(hw_version_info, 0600, dgrp_node_hw_version_show, NULL); 209 - 210 - static ssize_t dgrp_node_hw_id_show(struct device *c, 211 - struct device_attribute *attr, char *buf) 212 - { 213 - struct nd_struct *nd; 214 - 215 - if (!c) 216 - return 0; 217 - nd = dev_get_drvdata(c); 218 - if (!nd) 219 - return 0; 220 - 221 - 222 - if (nd->nd_state == NS_READY) 223 - return snprintf(buf, PAGE_SIZE, "%d\n", nd->nd_hw_id); 224 - return 0; 225 - } 226 - static DEVICE_ATTR(hw_id_info, 0600, dgrp_node_hw_id_show, NULL); 227 - 228 - static ssize_t dgrp_node_sw_version_show(struct device *c, 229 - struct device_attribute *attr, 230 - char *buf) 231 - { 232 - struct nd_struct *nd; 233 - 234 - if (!c) 235 - return 0; 236 - 237 - nd = dev_get_drvdata(c); 238 - if (!nd) 239 - return 0; 240 - 241 - if (nd->nd_state == NS_READY) 242 - return snprintf(buf, PAGE_SIZE, "%d.%d\n", 243 - (nd->nd_sw_ver >> 8) & 0xff, 244 - nd->nd_sw_ver & 0xff); 245 - 246 - return 0; 247 - } 248 - static DEVICE_ATTR(sw_version_info, 0600, dgrp_node_sw_version_show, NULL); 249 - 250 - 251 - static struct attribute *dgrp_sysfs_node_entries[] = { 252 - &dev_attr_state.attr, 253 - &dev_attr_description_info.attr, 254 - &dev_attr_hw_version_info.attr, 255 - &dev_attr_hw_id_info.attr, 256 - &dev_attr_sw_version_info.attr, 257 - NULL 258 - }; 259 - 260 - 261 - static struct attribute_group dgrp_node_attribute_group = { 262 - .name = NULL, 263 - .attrs = dgrp_sysfs_node_entries, 264 - }; 265 - 266 - 267 - void dgrp_create_node_class_sysfs_files(struct nd_struct *nd) 268 - { 269 - int ret; 270 - char name[10]; 271 - 272 - if (nd->nd_ID) 273 - ID_TO_CHAR(nd->nd_ID, name); 274 - else 275 - sprintf(name, "node%ld", nd->nd_major); 276 - 277 - nd->nd_class_dev = device_create(dgrp_class, dgrp_class_nodes_dev, 278 - MKDEV(0, nd->nd_major), NULL, "%s", name); 279 - 280 - ret = sysfs_create_group(&nd->nd_class_dev->kobj, 281 - &dgrp_node_attribute_group); 282 - 283 - if (ret) { 284 - pr_alert("%s: failed to create sysfs node device attributes.\n", 285 - __func__); 286 - sysfs_remove_group(&nd->nd_class_dev->kobj, 287 - &dgrp_node_attribute_group); 288 - return; 289 - } 290 - 291 - dev_set_drvdata(nd->nd_class_dev, nd); 292 - 293 - } 294 - 295 - 296 - void dgrp_remove_node_class_sysfs_files(struct nd_struct *nd) 297 - { 298 - if (nd->nd_class_dev) { 299 - sysfs_remove_group(&nd->nd_class_dev->kobj, 300 - &dgrp_node_attribute_group); 301 - 302 - device_destroy(dgrp_class, MKDEV(0, nd->nd_major)); 303 - nd->nd_class_dev = NULL; 304 - } 305 - } 306 - 307 - 308 - 309 - static ssize_t dgrp_tty_state_show(struct device *d, 310 - struct device_attribute *attr, char *buf) 311 - { 312 - struct un_struct *un; 313 - 314 - if (!d) 315 - return 0; 316 - un = dev_get_drvdata(d); 317 - if (!un) 318 - return 0; 319 - 320 - return snprintf(buf, PAGE_SIZE, "%s\n", 321 - un->un_open_count ? "Open" : "Closed"); 322 - } 323 - static DEVICE_ATTR(state_info, 0600, dgrp_tty_state_show, NULL); 324 - 325 - static ssize_t dgrp_tty_baud_show(struct device *d, 326 - struct device_attribute *attr, char *buf) 327 - { 328 - struct ch_struct *ch; 329 - struct un_struct *un; 330 - 331 - if (!d) 332 - return 0; 333 - un = dev_get_drvdata(d); 334 - if (!un) 335 - return 0; 336 - ch = un->un_ch; 337 - if (!ch) 338 - return 0; 339 - return snprintf(buf, PAGE_SIZE, "%d\n", 340 - un->un_open_count ? (PORTSERVER_DIVIDEND / ch->ch_s_brate) : 0); 341 - } 342 - static DEVICE_ATTR(baud_info, 0400, dgrp_tty_baud_show, NULL); 343 - 344 - 345 - static ssize_t dgrp_tty_msignals_show(struct device *d, 346 - struct device_attribute *attr, char *buf) 347 - { 348 - struct ch_struct *ch; 349 - struct un_struct *un; 350 - 351 - if (!d) 352 - return 0; 353 - un = dev_get_drvdata(d); 354 - if (!un) 355 - return 0; 356 - ch = un->un_ch; 357 - if (!ch) 358 - return 0; 359 - 360 - if (ch->ch_open_count) { 361 - return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n", 362 - (ch->ch_s_mlast & DM_RTS) ? "RTS" : "", 363 - (ch->ch_s_mlast & DM_CTS) ? "CTS" : "", 364 - (ch->ch_s_mlast & DM_DTR) ? "DTR" : "", 365 - (ch->ch_s_mlast & DM_DSR) ? "DSR" : "", 366 - (ch->ch_s_mlast & DM_CD) ? "DCD" : "", 367 - (ch->ch_s_mlast & DM_RI) ? "RI" : ""); 368 - } 369 - return 0; 370 - } 371 - static DEVICE_ATTR(msignals_info, 0400, dgrp_tty_msignals_show, NULL); 372 - 373 - 374 - static ssize_t dgrp_tty_iflag_show(struct device *d, 375 - struct device_attribute *attr, char *buf) 376 - { 377 - struct ch_struct *ch; 378 - struct un_struct *un; 379 - 380 - if (!d) 381 - return 0; 382 - un = dev_get_drvdata(d); 383 - if (!un) 384 - return 0; 385 - ch = un->un_ch; 386 - if (!ch) 387 - return 0; 388 - return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_s_iflag); 389 - } 390 - static DEVICE_ATTR(iflag_info, 0600, dgrp_tty_iflag_show, NULL); 391 - 392 - 393 - static ssize_t dgrp_tty_cflag_show(struct device *d, 394 - struct device_attribute *attr, char *buf) 395 - { 396 - struct ch_struct *ch; 397 - struct un_struct *un; 398 - 399 - if (!d) 400 - return 0; 401 - un = dev_get_drvdata(d); 402 - if (!un) 403 - return 0; 404 - ch = un->un_ch; 405 - if (!ch) 406 - return 0; 407 - return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_s_cflag); 408 - } 409 - static DEVICE_ATTR(cflag_info, 0600, dgrp_tty_cflag_show, NULL); 410 - 411 - 412 - static ssize_t dgrp_tty_oflag_show(struct device *d, 413 - struct device_attribute *attr, char *buf) 414 - { 415 - struct ch_struct *ch; 416 - struct un_struct *un; 417 - 418 - if (!d) 419 - return 0; 420 - un = dev_get_drvdata(d); 421 - if (!un) 422 - return 0; 423 - ch = un->un_ch; 424 - if (!ch) 425 - return 0; 426 - return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_s_oflag); 427 - } 428 - static DEVICE_ATTR(oflag_info, 0600, dgrp_tty_oflag_show, NULL); 429 - 430 - 431 - static ssize_t dgrp_tty_digi_flag_show(struct device *d, 432 - struct device_attribute *attr, char *buf) 433 - { 434 - struct ch_struct *ch; 435 - struct un_struct *un; 436 - 437 - if (!d) 438 - return 0; 439 - un = dev_get_drvdata(d); 440 - if (!un) 441 - return 0; 442 - ch = un->un_ch; 443 - if (!ch) 444 - return 0; 445 - return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags); 446 - } 447 - static DEVICE_ATTR(digi_flag_info, 0600, dgrp_tty_digi_flag_show, NULL); 448 - 449 - 450 - static ssize_t dgrp_tty_rxcount_show(struct device *d, 451 - struct device_attribute *attr, char *buf) 452 - { 453 - struct ch_struct *ch; 454 - struct un_struct *un; 455 - 456 - if (!d) 457 - return 0; 458 - un = dev_get_drvdata(d); 459 - if (!un) 460 - return 0; 461 - ch = un->un_ch; 462 - if (!ch) 463 - return 0; 464 - return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_rxcount); 465 - } 466 - static DEVICE_ATTR(rxcount_info, 0600, dgrp_tty_rxcount_show, NULL); 467 - 468 - 469 - static ssize_t dgrp_tty_txcount_show(struct device *d, 470 - struct device_attribute *attr, char *buf) 471 - { 472 - struct ch_struct *ch; 473 - struct un_struct *un; 474 - 475 - if (!d) 476 - return 0; 477 - un = dev_get_drvdata(d); 478 - if (!un) 479 - return 0; 480 - ch = un->un_ch; 481 - if (!ch) 482 - return 0; 483 - return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_txcount); 484 - } 485 - static DEVICE_ATTR(txcount_info, 0600, dgrp_tty_txcount_show, NULL); 486 - 487 - 488 - static ssize_t dgrp_tty_name_show(struct device *d, 489 - struct device_attribute *attr, char *buf) 490 - { 491 - struct nd_struct *nd; 492 - struct ch_struct *ch; 493 - struct un_struct *un; 494 - char name[10]; 495 - 496 - if (!d) 497 - return 0; 498 - un = dev_get_drvdata(d); 499 - if (!un) 500 - return 0; 501 - ch = un->un_ch; 502 - if (!ch) 503 - return 0; 504 - nd = ch->ch_nd; 505 - if (!nd) 506 - return 0; 507 - 508 - ID_TO_CHAR(nd->nd_ID, name); 509 - 510 - return snprintf(buf, PAGE_SIZE, "%s%s%02d\n", 511 - un->un_type == SERIAL_TYPE_XPRINT ? "pr" : "tty", 512 - name, ch->ch_portnum); 513 - } 514 - static DEVICE_ATTR(custom_name, 0600, dgrp_tty_name_show, NULL); 515 - 516 - 517 - static struct attribute *dgrp_sysfs_tty_entries[] = { 518 - &dev_attr_state_info.attr, 519 - &dev_attr_baud_info.attr, 520 - &dev_attr_msignals_info.attr, 521 - &dev_attr_iflag_info.attr, 522 - &dev_attr_cflag_info.attr, 523 - &dev_attr_oflag_info.attr, 524 - &dev_attr_digi_flag_info.attr, 525 - &dev_attr_rxcount_info.attr, 526 - &dev_attr_txcount_info.attr, 527 - &dev_attr_custom_name.attr, 528 - NULL 529 - }; 530 - 531 - 532 - static struct attribute_group dgrp_tty_attribute_group = { 533 - .name = NULL, 534 - .attrs = dgrp_sysfs_tty_entries, 535 - }; 536 - 537 - 538 - void dgrp_create_tty_sysfs(struct un_struct *un, struct device *c) 539 - { 540 - int ret; 541 - 542 - ret = sysfs_create_group(&c->kobj, &dgrp_tty_attribute_group); 543 - if (ret) { 544 - pr_alert("%s: failed to create sysfs tty device attributes.\n", 545 - __func__); 546 - sysfs_remove_group(&c->kobj, &dgrp_tty_attribute_group); 547 - return; 548 - } 549 - 550 - dev_set_drvdata(c, un); 551 - 552 - } 553 - 554 - 555 - void dgrp_remove_tty_sysfs(struct device *c) 556 - { 557 - sysfs_remove_group(&c->kobj, &dgrp_tty_attribute_group); 558 - }
-3337
drivers/staging/dgrp/dgrp_tty.c
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * Gene Olson <Gene_Olson at digi dot com> 5 - * James Puzzo <jamesp at digi dot com> 6 - * Jeff Randall 7 - * Scott Kilau <scottk at digi dot com> 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of the GNU General Public License as published by 11 - * the Free Software Foundation; either version 2, or (at your option) 12 - * any later version. 13 - * 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 16 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 17 - * PURPOSE. See the GNU General Public License for more details. 18 - * 19 - */ 20 - 21 - /* 22 - * 23 - * Filename: 24 - * 25 - * dgrp_tty.c 26 - * 27 - * Description: 28 - * 29 - * This file implements the tty driver functionality for the 30 - * RealPort driver software. 31 - * 32 - * Author: 33 - * 34 - * James A. Puzzo 35 - * Ann-Marie Westgate 36 - * 37 - */ 38 - 39 - #include <linux/slab.h> 40 - #include <linux/tty.h> 41 - #include <linux/tty_flip.h> 42 - #include <linux/device.h> 43 - #include <linux/sched.h> 44 - #include <linux/uaccess.h> 45 - 46 - #include "dgrp_common.h" 47 - 48 - #ifndef _POSIX_VDISABLE 49 - #define _POSIX_VDISABLE ('\0') 50 - #endif 51 - 52 - /* 53 - * forward declarations 54 - */ 55 - 56 - static void drp_param(struct ch_struct *); 57 - static void dgrp_tty_close(struct tty_struct *, struct file *); 58 - 59 - /* ioctl helper functions */ 60 - static int set_modem_info(struct ch_struct *, unsigned int, unsigned int *); 61 - static int get_modem_info(struct ch_struct *, unsigned int *); 62 - static void dgrp_set_custom_speed(struct ch_struct *, int); 63 - static int dgrp_tty_digigetedelay(struct tty_struct *, int *); 64 - static int dgrp_tty_digisetedelay(struct tty_struct *, int *); 65 - static int dgrp_send_break(struct ch_struct *, int); 66 - 67 - static ushort tty_to_ch_flags(struct tty_struct *, char); 68 - static tcflag_t ch_to_tty_flags(unsigned short, char); 69 - 70 - static void dgrp_tty_input_start(struct tty_struct *); 71 - static void dgrp_tty_input_stop(struct tty_struct *); 72 - 73 - static void drp_wmove(struct ch_struct *, int, void*, int); 74 - 75 - static int dgrp_tty_open(struct tty_struct *, struct file *); 76 - static void dgrp_tty_close(struct tty_struct *, struct file *); 77 - static int dgrp_tty_write(struct tty_struct *, const unsigned char *, int); 78 - static int dgrp_tty_write_room(struct tty_struct *); 79 - static void dgrp_tty_flush_buffer(struct tty_struct *); 80 - static int dgrp_tty_chars_in_buffer(struct tty_struct *); 81 - static int dgrp_tty_ioctl(struct tty_struct *, unsigned int, unsigned long); 82 - static void dgrp_tty_set_termios(struct tty_struct *, struct ktermios *); 83 - static void dgrp_tty_stop(struct tty_struct *); 84 - static void dgrp_tty_start(struct tty_struct *); 85 - static void dgrp_tty_throttle(struct tty_struct *); 86 - static void dgrp_tty_unthrottle(struct tty_struct *); 87 - static void dgrp_tty_hangup(struct tty_struct *); 88 - static int dgrp_tty_put_char(struct tty_struct *, unsigned char); 89 - static int dgrp_tty_tiocmget(struct tty_struct *); 90 - static int dgrp_tty_tiocmset(struct tty_struct *, unsigned int, unsigned int); 91 - static int dgrp_tty_send_break(struct tty_struct *, int); 92 - static void dgrp_tty_send_xchar(struct tty_struct *, char); 93 - 94 - /* 95 - * tty defines 96 - */ 97 - #define SERIAL_TYPE_NORMAL 1 98 - #define SERIAL_TYPE_CALLOUT 2 99 - #define SERIAL_TYPE_XPRINT 3 100 - 101 - 102 - /* 103 - * tty globals/statics 104 - */ 105 - 106 - 107 - #define PORTSERVER_DIVIDEND 1843200 108 - 109 - /* 110 - * Default transparent print information. 111 - */ 112 - static struct digi_struct digi_init = { 113 - .digi_flags = DIGI_COOK, /* Flags */ 114 - .digi_maxcps = 100, /* Max CPS */ 115 - .digi_maxchar = 50, /* Max chars in print queue */ 116 - .digi_bufsize = 100, /* Printer buffer size */ 117 - .digi_onlen = 4, /* size of printer on string */ 118 - .digi_offlen = 4, /* size of printer off string */ 119 - .digi_onstr = "\033[5i", /* ANSI printer on string */ 120 - .digi_offstr = "\033[4i", /* ANSI printer off string */ 121 - .digi_term = "ansi" /* default terminal type */ 122 - }; 123 - 124 - /* 125 - * Define a local default termios struct. All ports will be created 126 - * with this termios initially. 127 - * 128 - * This defines a raw port at 9600 baud, 8 data bits, no parity, 129 - * 1 stop bit. 130 - */ 131 - static struct ktermios DefaultTermios = { 132 - .c_iflag = (ICRNL | IXON), 133 - .c_oflag = (OPOST | ONLCR), 134 - .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), 135 - .c_lflag = (ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL 136 - | ECHOKE | IEXTEN), 137 - .c_cc = INIT_C_CC, 138 - .c_line = 0, 139 - }; 140 - 141 - /* Define our tty operations struct */ 142 - static const struct tty_operations dgrp_tty_ops = { 143 - .open = dgrp_tty_open, 144 - .close = dgrp_tty_close, 145 - .write = dgrp_tty_write, 146 - .write_room = dgrp_tty_write_room, 147 - .flush_buffer = dgrp_tty_flush_buffer, 148 - .chars_in_buffer = dgrp_tty_chars_in_buffer, 149 - .flush_chars = NULL, 150 - .ioctl = dgrp_tty_ioctl, 151 - .set_termios = dgrp_tty_set_termios, 152 - .stop = dgrp_tty_stop, 153 - .start = dgrp_tty_start, 154 - .throttle = dgrp_tty_throttle, 155 - .unthrottle = dgrp_tty_unthrottle, 156 - .hangup = dgrp_tty_hangup, 157 - .put_char = dgrp_tty_put_char, 158 - .tiocmget = dgrp_tty_tiocmget, 159 - .tiocmset = dgrp_tty_tiocmset, 160 - .break_ctl = dgrp_tty_send_break, 161 - .send_xchar = dgrp_tty_send_xchar 162 - }; 163 - 164 - 165 - static int calc_baud_rate(struct un_struct *un) 166 - { 167 - int i; 168 - int brate; 169 - 170 - struct baud_rates { 171 - unsigned int rate; 172 - unsigned int cflag; 173 - }; 174 - 175 - static struct baud_rates baud_rates[] = { 176 - { 921600, B921600 }, 177 - { 460800, B460800 }, 178 - { 230400, B230400 }, 179 - { 115200, B115200 }, 180 - { 57600, B57600 }, 181 - { 38400, B38400 }, 182 - { 19200, B19200 }, 183 - { 9600, B9600 }, 184 - { 4800, B4800 }, 185 - { 2400, B2400 }, 186 - { 1200, B1200 }, 187 - { 600, B600 }, 188 - { 300, B300 }, 189 - { 200, B200 }, 190 - { 150, B150 }, 191 - { 134, B134 }, 192 - { 110, B110 }, 193 - { 75, B75 }, 194 - { 50, B50 }, 195 - { 0, B9600 } 196 - }; 197 - 198 - brate = C_BAUD(un->un_tty); 199 - 200 - for (i = 0; baud_rates[i].rate; i++) { 201 - if (baud_rates[i].cflag == brate) 202 - break; 203 - } 204 - 205 - return baud_rates[i].rate; 206 - } 207 - 208 - static int calc_fastbaud_rate(struct un_struct *un, struct ktermios *uts) 209 - { 210 - int i; 211 - int brate; 212 - 213 - ulong bauds[2][16] = { 214 - { /* fastbaud*/ 215 - 0, 57600, 76800, 115200, 216 - 131657, 153600, 230400, 460800, 217 - 921600, 1200, 1800, 2400, 218 - 4800, 9600, 19200, 38400 }, 219 - { /* fastbaud & CBAUDEX */ 220 - 0, 57600, 115200, 230400, 221 - 460800, 150, 200, 921600, 222 - 600, 1200, 1800, 2400, 223 - 4800, 9600, 19200, 38400 } 224 - }; 225 - 226 - brate = C_BAUD(un->un_tty) & 0xff; 227 - 228 - i = (uts->c_cflag & CBAUDEX) ? 1 : 0; 229 - 230 - 231 - if ((i >= 0) && (i < 2) && (brate >= 0) && (brate < 16)) 232 - brate = bauds[i][brate]; 233 - else 234 - brate = 0; 235 - 236 - return brate; 237 - } 238 - 239 - /** 240 - * drp_param() -- send parameter values to be sent to the node 241 - * @ch: channel structure of port to modify 242 - * 243 - * Interprets the tty and modem changes made by an application 244 - * program (by examining the termios structures) and sets up 245 - * parameter values to be sent to the node. 246 - */ 247 - static void drp_param(struct ch_struct *ch) 248 - { 249 - struct nd_struct *nd; 250 - struct un_struct *un; 251 - int brate; 252 - int mflow; 253 - int xflag; 254 - int iflag; 255 - struct ktermios *tts, *pts, *uts; 256 - 257 - nd = ch->ch_nd; 258 - 259 - /* 260 - * If the terminal device is open, use it to set up all tty 261 - * modes and functions. Otherwise use the printer device. 262 - */ 263 - 264 - if (ch->ch_tun.un_open_count) { 265 - 266 - un = &ch->ch_tun; 267 - tts = &ch->ch_tun.un_tty->termios; 268 - 269 - /* 270 - * If both devices are open, copy critical line 271 - * parameters from the tty device to the printer, 272 - * so that if the tty is closed, the printer will 273 - * continue without disruption. 274 - */ 275 - 276 - if (ch->ch_pun.un_open_count) { 277 - 278 - pts = &ch->ch_pun.un_tty->termios; 279 - 280 - pts->c_cflag ^= 281 - (pts->c_cflag ^ tts->c_cflag) & 282 - (CBAUD | CSIZE | CSTOPB | CREAD | PARENB | 283 - PARODD | HUPCL | CLOCAL); 284 - 285 - pts->c_iflag ^= 286 - (pts->c_iflag ^ tts->c_iflag) & 287 - (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | 288 - ISTRIP | IXON | IXANY | IXOFF); 289 - 290 - pts->c_cc[VSTART] = tts->c_cc[VSTART]; 291 - pts->c_cc[VSTOP] = tts->c_cc[VSTOP]; 292 - } 293 - } else if (ch->ch_pun.un_open_count == 0) { 294 - pr_warn("%s - ch_pun.un_open_count shouldn't be 0\n", 295 - __func__); 296 - return; 297 - } else { 298 - un = &ch->ch_pun; 299 - } 300 - 301 - uts = &un->un_tty->termios; 302 - 303 - /* 304 - * Determine if FAST writes can be performed. 305 - */ 306 - 307 - if ((ch->ch_digi.digi_flags & DIGI_COOK) != 0 && 308 - (ch->ch_tun.un_open_count != 0) && 309 - !((un->un_tty)->ldisc->ops->flags & LDISC_FLAG_DEFINED) && 310 - !(L_XCASE(un->un_tty))) { 311 - ch->ch_flag |= CH_FAST_WRITE; 312 - } else { 313 - ch->ch_flag &= ~CH_FAST_WRITE; 314 - } 315 - 316 - /* 317 - * If FAST writes can be performed, and OPOST is on in the 318 - * terminal device, do OPOST handling in the server. 319 - */ 320 - 321 - if ((ch->ch_flag & CH_FAST_WRITE) && 322 - O_OPOST(un->un_tty) != 0) { 323 - int oflag = tty_to_ch_flags(un->un_tty, 'o'); 324 - 325 - /* add to ch_ocook any processing flags set in the termio */ 326 - ch->ch_ocook |= oflag & (OF_OLCUC | 327 - OF_ONLCR | 328 - OF_OCRNL | 329 - OF_ONLRET | 330 - OF_TABDLY); 331 - 332 - /* 333 - * the hpux driver clears any flags set in ch_ocook 334 - * from the termios oflag. It is STILL reported though 335 - * by a TCGETA 336 - */ 337 - 338 - oflag = ch_to_tty_flags(ch->ch_ocook, 'o'); 339 - uts->c_oflag &= ~oflag; 340 - 341 - } else { 342 - /* clear the ch->ch_ocook flag */ 343 - int oflag = ch_to_tty_flags(ch->ch_ocook, 'o'); 344 - uts->c_oflag |= oflag; 345 - ch->ch_ocook = 0; 346 - } 347 - 348 - ch->ch_oflag = ch->ch_ocook; 349 - 350 - 351 - ch->ch_flag &= ~CH_FAST_READ; 352 - 353 - /* 354 - * Generate channel flags 355 - */ 356 - 357 - if (C_BAUD(un->un_tty) == B0) { 358 - if (!(ch->ch_flag & CH_BAUD0)) { 359 - /* TODO : the HPUX driver flushes line */ 360 - /* TODO : discipline, I assume I don't have to */ 361 - 362 - ch->ch_tout = ch->ch_tin; 363 - ch->ch_rout = ch->ch_rin; 364 - 365 - ch->ch_break_time = 0; 366 - 367 - ch->ch_send |= RR_TX_FLUSH | RR_RX_FLUSH; 368 - 369 - ch->ch_mout &= ~(DM_DTR | DM_RTS); 370 - 371 - ch->ch_flag |= CH_BAUD0; 372 - } 373 - } else if (ch->ch_custom_speed) { 374 - ch->ch_brate = PORTSERVER_DIVIDEND / ch->ch_custom_speed; 375 - 376 - if (ch->ch_flag & CH_BAUD0) { 377 - ch->ch_mout |= DM_DTR | DM_RTS; 378 - 379 - ch->ch_flag &= ~CH_BAUD0; 380 - } 381 - } else { 382 - /* 383 - * Baud rate mapping. 384 - * 385 - * If FASTBAUD isn't on, we can scan the new baud rate list 386 - * as required. 387 - * 388 - * However, if FASTBAUD is on, we must go to the old 389 - * baud rate mapping that existed many many moons ago, 390 - * for compatibility reasons. 391 - */ 392 - 393 - if (!(ch->ch_digi.digi_flags & DIGI_FAST)) 394 - brate = calc_baud_rate(un); 395 - else 396 - brate = calc_fastbaud_rate(un, uts); 397 - 398 - if (brate == 0) 399 - brate = 9600; 400 - 401 - ch->ch_brate = PORTSERVER_DIVIDEND / brate; 402 - 403 - if (ch->ch_flag & CH_BAUD0) { 404 - ch->ch_mout |= DM_DTR | DM_RTS; 405 - 406 - ch->ch_flag &= ~CH_BAUD0; 407 - } 408 - } 409 - 410 - /* 411 - * Generate channel cflags from the termio. 412 - */ 413 - 414 - ch->ch_cflag = tty_to_ch_flags(un->un_tty, 'c'); 415 - 416 - /* 417 - * Generate channel iflags from the termio. 418 - */ 419 - 420 - iflag = (int) tty_to_ch_flags(un->un_tty, 'i'); 421 - 422 - if (START_CHAR(un->un_tty) == _POSIX_VDISABLE || 423 - STOP_CHAR(un->un_tty) == _POSIX_VDISABLE) { 424 - iflag &= ~(IF_IXON | IF_IXANY | IF_IXOFF); 425 - } 426 - 427 - ch->ch_iflag = iflag; 428 - 429 - /* 430 - * Generate flow control characters 431 - */ 432 - 433 - /* 434 - * From the POSIX.1 spec (7.1.2.6): "If {_POSIX_VDISABLE} 435 - * is defined for the terminal device file, and the value 436 - * of one of the changeable special control characters (see 437 - * 7.1.1.9) is {_POSIX_VDISABLE}, that function shall be 438 - * disabled, that is, no input data shall be recognized as 439 - * the disabled special character." 440 - * 441 - * OK, so we don't ever assign S/DXB XON or XOFF to _POSIX_VDISABLE. 442 - */ 443 - 444 - if (uts->c_cc[VSTART] != _POSIX_VDISABLE) 445 - ch->ch_xon = uts->c_cc[VSTART]; 446 - if (uts->c_cc[VSTOP] != _POSIX_VDISABLE) 447 - ch->ch_xoff = uts->c_cc[VSTOP]; 448 - 449 - ch->ch_lnext = (uts->c_cc[VLNEXT] == _POSIX_VDISABLE ? 0 : 450 - uts->c_cc[VLNEXT]); 451 - 452 - /* 453 - * Also, if either c_cc[START] or c_cc[STOP] is set to 454 - * _POSIX_VDISABLE, we can't really do software flow 455 - * control--in either direction--so we turn it off as 456 - * far as S/DXB is concerned. In essence, if you disable 457 - * one, you disable the other too. 458 - */ 459 - if ((uts->c_cc[VSTART] == _POSIX_VDISABLE) || 460 - (uts->c_cc[VSTOP] == _POSIX_VDISABLE)) 461 - ch->ch_iflag &= ~(IF_IXOFF | IF_IXON); 462 - 463 - /* 464 - * Update xflags. 465 - */ 466 - 467 - xflag = 0; 468 - 469 - if (ch->ch_digi.digi_flags & DIGI_AIXON) 470 - xflag = XF_XIXON; 471 - 472 - if ((ch->ch_xxon == _POSIX_VDISABLE) || 473 - (ch->ch_xxoff == _POSIX_VDISABLE)) 474 - xflag &= ~XF_XIXON; 475 - 476 - ch->ch_xflag = xflag; 477 - 478 - 479 - /* 480 - * Figure effective DCD value. 481 - */ 482 - 483 - if (C_CLOCAL(un->un_tty)) 484 - ch->ch_flag |= CH_CLOCAL; 485 - else 486 - ch->ch_flag &= ~CH_CLOCAL; 487 - 488 - /* 489 - * Check modem signals 490 - */ 491 - 492 - dgrp_carrier(ch); 493 - 494 - /* 495 - * Get hardware handshake value. 496 - */ 497 - 498 - mflow = 0; 499 - 500 - if (C_CRTSCTS(un->un_tty)) 501 - mflow |= (DM_RTS | DM_CTS); 502 - 503 - if (ch->ch_digi.digi_flags & RTSPACE) 504 - mflow |= DM_RTS; 505 - 506 - if (ch->ch_digi.digi_flags & DTRPACE) 507 - mflow |= DM_DTR; 508 - 509 - if (ch->ch_digi.digi_flags & CTSPACE) 510 - mflow |= DM_CTS; 511 - 512 - if (ch->ch_digi.digi_flags & DSRPACE) 513 - mflow |= DM_DSR; 514 - 515 - if (ch->ch_digi.digi_flags & DCDPACE) 516 - mflow |= DM_CD; 517 - 518 - if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) 519 - mflow |= DM_RTS_TOGGLE; 520 - 521 - ch->ch_mflow = mflow; 522 - 523 - /* 524 - * Send the changes to the server. 525 - */ 526 - 527 - ch->ch_flag |= CH_PARAM; 528 - (ch->ch_nd)->nd_tx_work = 1; 529 - 530 - if (waitqueue_active(&ch->ch_flag_wait)) 531 - wake_up_interruptible(&ch->ch_flag_wait); 532 - } 533 - 534 - /* 535 - * This function is just used as a callback for timeouts 536 - * waiting on the ch_sleep flag. 537 - */ 538 - static void wake_up_drp_sleep_timer(unsigned long ptr) 539 - { 540 - struct ch_struct *ch = (struct ch_struct *) ptr; 541 - if (ch) 542 - wake_up(&ch->ch_sleep); 543 - } 544 - 545 - 546 - /* 547 - * Set up our own sleep that can't be cancelled 548 - * until our timeout occurs. 549 - */ 550 - static void drp_my_sleep(struct ch_struct *ch) 551 - { 552 - struct timer_list drp_wakeup_timer; 553 - DECLARE_WAITQUEUE(wait, current); 554 - 555 - /* 556 - * First make sure we're ready to receive the wakeup. 557 - */ 558 - 559 - add_wait_queue(&ch->ch_sleep, &wait); 560 - current->state = TASK_UNINTERRUPTIBLE; 561 - 562 - /* 563 - * Since we are uninterruptible, set a timer to 564 - * unset the uninterruptable state in 1 second. 565 - */ 566 - 567 - init_timer(&drp_wakeup_timer); 568 - drp_wakeup_timer.function = wake_up_drp_sleep_timer; 569 - drp_wakeup_timer.data = (unsigned long) ch; 570 - drp_wakeup_timer.expires = jiffies + (1 * HZ); 571 - add_timer(&drp_wakeup_timer); 572 - 573 - schedule(); 574 - 575 - del_timer(&drp_wakeup_timer); 576 - 577 - remove_wait_queue(&ch->ch_sleep, &wait); 578 - } 579 - 580 - /* 581 - * dgrp_tty_open() 582 - * 583 - * returns: 584 - * -EBUSY - this is a callout device and the normal device is active 585 - * - there is an error in opening the tty 586 - * -ENODEV - the channel does not exist 587 - * -EAGAIN - we are in the middle of hanging up or closing 588 - * - IMMEDIATE_OPEN fails 589 - * -ENXIO or -EAGAIN 590 - * - if the port is outside physical range 591 - * -EINTR - the open is interrupted 592 - * 593 - */ 594 - static int dgrp_tty_open(struct tty_struct *tty, struct file *file) 595 - { 596 - int retval = 0; 597 - struct nd_struct *nd; 598 - struct ch_struct *ch; 599 - struct un_struct *un; 600 - int port; 601 - int delay_error; 602 - int otype; 603 - int unf; 604 - int wait_carrier; 605 - int category; 606 - int counts_were_incremented = 0; 607 - ulong lock_flags; 608 - DECLARE_WAITQUEUE(wait, current); 609 - 610 - /* 611 - * Do some initial checks to see if the node and port exist 612 - */ 613 - 614 - nd = nd_struct_get(MAJOR(tty_devnum(tty))); 615 - port = PORT_NUM(MINOR(tty_devnum(tty))); 616 - category = OPEN_CATEGORY(MINOR(tty_devnum(tty))); 617 - 618 - if (!nd) 619 - return -ENODEV; 620 - 621 - if (port >= CHAN_MAX) 622 - return -ENODEV; 623 - 624 - /* 625 - * The channel exists. 626 - */ 627 - 628 - ch = nd->nd_chan + port; 629 - 630 - un = IS_PRINT(MINOR(tty_devnum(tty))) ? &ch->ch_pun : &ch->ch_tun; 631 - un->un_tty = tty; 632 - tty->driver_data = un; 633 - 634 - /* 635 - * If we are in the middle of hanging up, 636 - * then return an error 637 - */ 638 - if (tty_hung_up_p(file)) { 639 - retval = ((un->un_flag & UN_HUP_NOTIFY) ? 640 - -EAGAIN : -ERESTARTSYS); 641 - goto done; 642 - } 643 - 644 - /* 645 - * If the port is in the middle of closing, then block 646 - * until it is done, then try again. 647 - */ 648 - retval = wait_event_interruptible(un->un_close_wait, 649 - ((un->un_flag & UN_CLOSING) == 0)); 650 - 651 - if (retval) 652 - goto done; 653 - 654 - /* 655 - * If the port is in the middle of a reopen after a network disconnect, 656 - * wait until it is done, then try again. 657 - */ 658 - retval = wait_event_interruptible(ch->ch_flag_wait, 659 - ((ch->ch_flag & CH_PORT_GONE) == 0)); 660 - 661 - if (retval) 662 - goto done; 663 - 664 - /* 665 - * If this is a callout device, then just make sure the normal 666 - * device isn't being used. 667 - */ 668 - 669 - if (tty->driver->subtype == SERIAL_TYPE_CALLOUT) { 670 - if (un->un_flag & UN_NORMAL_ACTIVE) { 671 - retval = -EBUSY; 672 - goto done; 673 - } else { 674 - un->un_flag |= UN_CALLOUT_ACTIVE; 675 - } 676 - } 677 - 678 - /* 679 - * Loop waiting until the open can be successfully completed. 680 - */ 681 - 682 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 683 - 684 - nd->nd_tx_work = 1; 685 - 686 - for (;;) { 687 - wait_carrier = 0; 688 - 689 - /* 690 - * Determine the open type from the flags provided. 691 - */ 692 - 693 - /* 694 - * If the port is not enabled, then exit 695 - */ 696 - if (test_bit(TTY_IO_ERROR, &tty->flags)) { 697 - /* there was an error in opening the tty */ 698 - if (un->un_flag & UN_CALLOUT_ACTIVE) 699 - retval = -EBUSY; 700 - else 701 - un->un_flag |= UN_NORMAL_ACTIVE; 702 - goto unlock; 703 - } 704 - 705 - if (file->f_flags & O_NONBLOCK) { 706 - 707 - /* 708 - * if the O_NONBLOCK is set, errors on read and write 709 - * must return -EAGAIN immediately and NOT sleep 710 - * on the waitqs. 711 - */ 712 - otype = OTYPE_IMMEDIATE; 713 - delay_error = -EAGAIN; 714 - 715 - } else if (!OPEN_WAIT_AVAIL(category) || 716 - (file->f_flags & O_NDELAY) != 0) { 717 - otype = OTYPE_IMMEDIATE; 718 - delay_error = -EBUSY; 719 - 720 - } else if (!OPEN_WAIT_CARRIER(category) || 721 - ((ch->ch_digi.digi_flags & DIGI_FORCEDCD) != 0) || 722 - C_CLOCAL(tty)) { 723 - otype = OTYPE_PERSISTENT; 724 - delay_error = 0; 725 - 726 - } else { 727 - otype = OTYPE_INCOMING; 728 - delay_error = 0; 729 - } 730 - 731 - /* 732 - * Handle port currently outside physical port range. 733 - */ 734 - 735 - if (port >= nd->nd_chan_count) { 736 - if (otype == OTYPE_IMMEDIATE) { 737 - retval = (nd->nd_state == NS_READY) ? 738 - -ENXIO : -EAGAIN; 739 - goto unlock; 740 - } 741 - } 742 - 743 - /* 744 - * Handle port not currently open. 745 - */ 746 - 747 - else if (ch->ch_open_count == 0) { 748 - /* 749 - * Return an error when an Incoming Open 750 - * response indicates the port is busy. 751 - */ 752 - 753 - if (ch->ch_open_error != 0 && otype == ch->ch_otype) { 754 - retval = (ch->ch_open_error <= 2) ? 755 - delay_error : -ENXIO; 756 - goto unlock; 757 - } 758 - 759 - /* 760 - * Fail any new Immediate open if we do not have 761 - * a normal connection to the server. 762 - */ 763 - 764 - if (nd->nd_state != NS_READY && 765 - otype == OTYPE_IMMEDIATE) { 766 - retval = -EAGAIN; 767 - goto unlock; 768 - } 769 - 770 - /* 771 - * If a Realport open of the correct type has 772 - * succeeded, complete the open. 773 - */ 774 - 775 - if (ch->ch_state == CS_READY && ch->ch_otype == otype) 776 - break; 777 - } 778 - 779 - /* 780 - * Handle port already open and active as a device 781 - * of same category. 782 - */ 783 - 784 - else if ((ch->ch_category == category) || 785 - IS_PRINT(MINOR(tty_devnum(tty)))) { 786 - /* 787 - * Fail if opening the device now would 788 - * violate exclusive use. 789 - */ 790 - unf = ch->ch_tun.un_flag | ch->ch_pun.un_flag; 791 - 792 - if ((file->f_flags & O_EXCL) || (unf & UN_EXCL)) { 793 - retval = -EBUSY; 794 - goto unlock; 795 - } 796 - 797 - /* 798 - * If the open device is in the hangup state, all 799 - * system calls fail except close(). 800 - */ 801 - 802 - /* TODO : check on hangup_p calls */ 803 - 804 - if (ch->ch_flag & CH_HANGUP) { 805 - retval = -ENXIO; 806 - goto unlock; 807 - } 808 - 809 - /* 810 - * If the port is ready, and carrier is ignored 811 - * or present, then complete the open. 812 - */ 813 - 814 - if (ch->ch_state == CS_READY && 815 - (otype != OTYPE_INCOMING || 816 - ch->ch_flag & CH_VIRT_CD)) 817 - break; 818 - 819 - wait_carrier = 1; 820 - } 821 - 822 - /* 823 - * Handle port active with a different category device. 824 - */ 825 - 826 - else { 827 - if (otype == OTYPE_IMMEDIATE) { 828 - retval = delay_error; 829 - goto unlock; 830 - } 831 - } 832 - 833 - /* 834 - * Wait until conditions change, then take another 835 - * try at the open. 836 - */ 837 - 838 - ch->ch_wait_count[otype]++; 839 - 840 - if (wait_carrier) 841 - ch->ch_wait_carrier++; 842 - 843 - /* 844 - * Prepare the task to accept the wakeup, then 845 - * release our locks and release control. 846 - */ 847 - 848 - add_wait_queue(&ch->ch_flag_wait, &wait); 849 - current->state = TASK_INTERRUPTIBLE; 850 - 851 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 852 - 853 - /* 854 - * Give up control, we'll come back if we're 855 - * interrupted or are woken up. 856 - */ 857 - schedule(); 858 - remove_wait_queue(&ch->ch_flag_wait, &wait); 859 - 860 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 861 - 862 - current->state = TASK_RUNNING; 863 - 864 - ch->ch_wait_count[otype]--; 865 - 866 - if (wait_carrier) 867 - ch->ch_wait_carrier--; 868 - 869 - nd->nd_tx_work = 1; 870 - 871 - if (signal_pending(current)) { 872 - retval = -EINTR; 873 - goto unlock; 874 - } 875 - } /* end for(;;) */ 876 - 877 - /* 878 - * The open has succeeded. No turning back. 879 - */ 880 - counts_were_incremented = 1; 881 - un->un_open_count++; 882 - ch->ch_open_count++; 883 - 884 - /* 885 - * Initialize the channel, if it's not already open. 886 - */ 887 - 888 - if (ch->ch_open_count == 1) { 889 - ch->ch_flag = 0; 890 - ch->ch_inwait = 0; 891 - ch->ch_category = category; 892 - ch->ch_pscan_state = 0; 893 - 894 - /* TODO : find out what PS-1 bug Gene was referring to */ 895 - /* TODO : in the following comment. */ 896 - 897 - ch->ch_send = RR_TX_START | RR_RX_START; /* PS-1 bug */ 898 - 899 - if (C_CLOCAL(tty) || 900 - ch->ch_s_mlast & DM_CD || 901 - ch->ch_digi.digi_flags & DIGI_FORCEDCD) 902 - ch->ch_flag |= CH_VIRT_CD; 903 - else if (OPEN_FORCES_CARRIER(category)) 904 - ch->ch_flag |= CH_VIRT_CD; 905 - 906 - } 907 - 908 - /* 909 - * Initialize the unit, if it is not already open. 910 - */ 911 - 912 - if (un->un_open_count == 1) { 913 - /* 914 - * Since all terminal options are always sticky in Linux, 915 - * we don't need the UN_STICKY flag to be handled specially. 916 - */ 917 - /* clears all the digi flags, leaves serial flags */ 918 - un->un_flag &= ~UN_DIGI_MASK; 919 - 920 - if (file->f_flags & O_EXCL) 921 - un->un_flag |= UN_EXCL; 922 - 923 - /* TODO : include "session" and "pgrp" */ 924 - 925 - /* 926 - * In Linux, all terminal parameters are intended to be sticky. 927 - * as a result, we "remove" the code which once reset the ports 928 - * to sane values. 929 - */ 930 - 931 - drp_param(ch); 932 - 933 - } 934 - 935 - un->un_flag |= UN_INITIALIZED; 936 - 937 - retval = 0; 938 - 939 - unlock: 940 - 941 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 942 - 943 - done: 944 - /* 945 - * Linux does a close for every open, even failed ones! 946 - */ 947 - if (!counts_were_incremented) { 948 - un->un_open_count++; 949 - ch->ch_open_count++; 950 - } 951 - 952 - if (retval) 953 - dev_err(tty->dev, "tty open bad return (%i)\n", retval); 954 - 955 - return retval; 956 - } 957 - 958 - 959 - 960 - 961 - /* 962 - * dgrp_tty_close() -- close function for tty_operations 963 - */ 964 - static void dgrp_tty_close(struct tty_struct *tty, struct file *file) 965 - { 966 - struct ch_struct *ch; 967 - struct un_struct *un; 968 - struct nd_struct *nd; 969 - int tpos; 970 - int port; 971 - int err = 0; 972 - int s = 0; 973 - ulong waketime; 974 - ulong lock_flags; 975 - int sent_printer_offstr = 0; 976 - 977 - port = PORT_NUM(MINOR(tty_devnum(tty))); 978 - 979 - un = tty->driver_data; 980 - 981 - if (!un) 982 - return; 983 - 984 - ch = un->un_ch; 985 - 986 - if (!ch) 987 - return; 988 - 989 - nd = ch->ch_nd; 990 - 991 - if (!nd) 992 - return; 993 - 994 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 995 - 996 - 997 - /* Used to be on channel basis, now we check on a unit basis. */ 998 - if (un->un_open_count != 1) 999 - goto unlock; 1000 - 1001 - /* 1002 - * OK, its the last close on the unit 1003 - */ 1004 - un->un_flag |= UN_CLOSING; 1005 - 1006 - /* 1007 - * Notify the discipline to only process XON/XOFF characters. 1008 - */ 1009 - tty->closing = 1; 1010 - 1011 - /* 1012 - * Wait for output to drain only if this is 1013 - * the last close against the channel 1014 - */ 1015 - 1016 - if (ch->ch_open_count == 1) { 1017 - /* 1018 - * If its the print device, we need to ensure at all costs that 1019 - * the offstr will fit. If it won't, flush our tbuf. 1020 - */ 1021 - if (IS_PRINT(MINOR(tty_devnum(tty))) && 1022 - (((ch->ch_tout - ch->ch_tin - 1) & TBUF_MASK) < 1023 - ch->ch_digi.digi_offlen)) 1024 - ch->ch_tin = ch->ch_tout; 1025 - 1026 - /* 1027 - * Turn off the printer. Don't bother checking to see if its 1028 - * IS_PRINT... Since this is the last close the flag is going 1029 - * to be cleared, so we MUST make sure the offstr gets inserted 1030 - * into tbuf. 1031 - */ 1032 - 1033 - if ((ch->ch_flag & CH_PRON) != 0) { 1034 - drp_wmove(ch, 0, ch->ch_digi.digi_offstr, 1035 - ch->ch_digi.digi_offlen); 1036 - ch->ch_flag &= ~CH_PRON; 1037 - sent_printer_offstr = 1; 1038 - } 1039 - } 1040 - 1041 - /* 1042 - * Wait until either the output queue has drained, or we see 1043 - * absolutely no progress for 15 seconds. 1044 - */ 1045 - 1046 - tpos = ch->ch_s_tpos; 1047 - 1048 - waketime = jiffies + 15 * HZ; 1049 - 1050 - for (;;) { 1051 - 1052 - /* 1053 - * Make sure the port still exists. 1054 - */ 1055 - 1056 - if (port >= nd->nd_chan_count) { 1057 - err = 1; 1058 - break; 1059 - } 1060 - 1061 - if (signal_pending(current)) { 1062 - err = 1; 1063 - break; 1064 - } 1065 - 1066 - /* 1067 - * If the port is idle (not opened on the server), we have 1068 - * no way of draining/flushing/closing the port on that server. 1069 - * So break out of loop. 1070 - */ 1071 - if (ch->ch_state == CS_IDLE) 1072 - break; 1073 - 1074 - nd->nd_tx_work = 1; 1075 - 1076 - /* 1077 - * Exit if the queues for this unit are empty, 1078 - * and either the other unit is still open or all 1079 - * data has drained. 1080 - */ 1081 - 1082 - if ((un->un_tty)->ops->chars_in_buffer ? 1083 - ((un->un_tty)->ops->chars_in_buffer)(un->un_tty) == 0 : 1) { 1084 - 1085 - /* 1086 - * We don't need to wait for a buffer to drain 1087 - * if the other unit is open. 1088 - */ 1089 - 1090 - if (ch->ch_open_count != un->un_open_count) 1091 - break; 1092 - 1093 - /* 1094 - * The wait is complete when all queues are 1095 - * drained, and any break in progress is complete. 1096 - */ 1097 - 1098 - if (ch->ch_tin == ch->ch_tout && 1099 - ch->ch_s_tin == ch->ch_s_tpos && 1100 - (ch->ch_send & RR_TX_BREAK) == 0) { 1101 - break; 1102 - } 1103 - } 1104 - 1105 - /* 1106 - * Flush TX data and exit the wait if NDELAY is set, 1107 - * or this is not a DIGI printer, and the close timeout 1108 - * expires. 1109 - */ 1110 - 1111 - if ((file->f_flags & (O_NDELAY | O_NONBLOCK)) || 1112 - ((long)(jiffies - waketime) >= 0 && 1113 - (ch->ch_digi.digi_flags & DIGI_PRINTER) == 0)) { 1114 - 1115 - /* 1116 - * If we sent the printer off string, we cannot 1117 - * flush our internal buffers, or we might lose 1118 - * the offstr. 1119 - */ 1120 - if (!sent_printer_offstr) 1121 - dgrp_tty_flush_buffer(tty); 1122 - 1123 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 1124 - tty_ldisc_flush(tty); 1125 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 1126 - break; 1127 - } 1128 - 1129 - /* 1130 - * Otherwise take a short nap. 1131 - */ 1132 - 1133 - ch->ch_flag |= CH_DRAIN; 1134 - 1135 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 1136 - 1137 - schedule_timeout_interruptible(1); 1138 - s = signal_pending(current); 1139 - 1140 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 1141 - 1142 - if (s) { 1143 - /* 1144 - * If we had sent the printer off string, we now have 1145 - * some problems. 1146 - * 1147 - * The system won't let us sleep since we got an error 1148 - * back from sleep, presumably because the user did 1149 - * a ctrl-c... 1150 - * But we need to ensure that the offstr gets sent! 1151 - * Thus, we have to do something else besides sleeping. 1152 - * The plan: 1153 - * 1) Make this task uninterruptable. 1154 - * 2) Set up a timer to go off in 1 sec. 1155 - * 3) Act as tho we just got out of the sleep above. 1156 - * 1157 - * Thankfully, in the real world, this just 1158 - * never happens. 1159 - */ 1160 - 1161 - if (sent_printer_offstr) { 1162 - spin_unlock_irqrestore(&nd->nd_lock, 1163 - lock_flags); 1164 - drp_my_sleep(ch); 1165 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 1166 - } else { 1167 - err = 1; 1168 - break; 1169 - } 1170 - } 1171 - 1172 - /* 1173 - * Restart the wait if any progress is seen. 1174 - */ 1175 - 1176 - if (ch->ch_s_tpos != tpos) { 1177 - tpos = ch->ch_s_tpos; 1178 - 1179 - /* TODO: this gives us timeout problems with nist ?? */ 1180 - waketime = jiffies + 15 * HZ; 1181 - } 1182 - } 1183 - 1184 - /* 1185 - * Close the line discipline 1186 - */ 1187 - 1188 - /* this is done in tty_io.c */ 1189 - /* if ((un->un_tty)->ldisc.close) 1190 - * ((un->un_tty)->ldisc.close)(un->un_tty); 1191 - */ 1192 - 1193 - /* don't do this here */ 1194 - /* un->un_flag = 0; */ 1195 - 1196 - /* 1197 - * Flush the receive buffer on terminal unit close only. 1198 - */ 1199 - 1200 - if (!IS_PRINT(MINOR(tty_devnum(tty)))) 1201 - ch->ch_rout = ch->ch_rin; 1202 - 1203 - 1204 - /* 1205 - * Don't permit the close to happen until we get any pending 1206 - * sync request responses. 1207 - * There could be other ports depending upon the response as well. 1208 - * 1209 - * Also, don't permit the close to happen until any parameter 1210 - * changes have been sent out from the state machine as well. 1211 - * This is required because of a ditty -a race with -HUPCL 1212 - * We MUST make sure all channel parameters have been sent to the 1213 - * Portserver before sending a close. 1214 - */ 1215 - 1216 - if ((err != 1) && (ch->ch_state != CS_IDLE)) { 1217 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 1218 - s = wait_event_interruptible(ch->ch_flag_wait, 1219 - ((ch->ch_flag & (CH_WAITING_SYNC | CH_PARAM)) == 0)); 1220 - spin_lock_irqsave(&nd->nd_lock, lock_flags); 1221 - } 1222 - 1223 - /* 1224 - * Cleanup the channel if last unit open. 1225 - */ 1226 - 1227 - if (ch->ch_open_count == 1) { 1228 - ch->ch_flag = 0; 1229 - ch->ch_category = 0; 1230 - ch->ch_send = 0; 1231 - ch->ch_expect = 0; 1232 - ch->ch_tout = ch->ch_tin; 1233 - /* (un->un_tty)->device = 0; */ 1234 - 1235 - if (ch->ch_state == CS_READY) 1236 - ch->ch_state = CS_SEND_CLOSE; 1237 - } 1238 - 1239 - /* 1240 - * Send the changes to the server 1241 - */ 1242 - if (ch->ch_state != CS_IDLE) { 1243 - ch->ch_flag |= CH_PARAM; 1244 - wake_up_interruptible(&ch->ch_flag_wait); 1245 - } 1246 - 1247 - nd->nd_tx_work = 1; 1248 - nd->nd_tx_ready = 1; 1249 - 1250 - unlock: 1251 - tty->closing = 0; 1252 - 1253 - if (ch->ch_open_count <= 0) 1254 - dev_info(tty->dev, 1255 - "%s - unexpected value for ch->ch_open_count: %i\n", 1256 - __func__, ch->ch_open_count); 1257 - else 1258 - ch->ch_open_count--; 1259 - 1260 - if (un->un_open_count <= 0) 1261 - dev_info(tty->dev, 1262 - "%s - unexpected value for un->un_open_count: %i\n", 1263 - __func__, un->un_open_count); 1264 - else 1265 - un->un_open_count--; 1266 - 1267 - un->un_flag &= ~(UN_NORMAL_ACTIVE | UN_CALLOUT_ACTIVE | UN_CLOSING); 1268 - if (waitqueue_active(&un->un_close_wait)) 1269 - wake_up_interruptible(&un->un_close_wait); 1270 - 1271 - spin_unlock_irqrestore(&nd->nd_lock, lock_flags); 1272 - 1273 - return; 1274 - 1275 - } 1276 - 1277 - static void drp_wmove(struct ch_struct *ch, int from_user, void *buf, int count) 1278 - { 1279 - int n; 1280 - int ret = 0; 1281 - 1282 - ch->ch_nd->nd_tx_work = 1; 1283 - 1284 - n = TBUF_MAX - ch->ch_tin; 1285 - 1286 - if (count >= n) { 1287 - if (from_user) 1288 - ret = copy_from_user(ch->ch_tbuf + ch->ch_tin, 1289 - (void __user *) buf, n); 1290 - else 1291 - memcpy(ch->ch_tbuf + ch->ch_tin, buf, n); 1292 - 1293 - buf = (char *) buf + n; 1294 - count -= n; 1295 - ch->ch_tin = 0; 1296 - } 1297 - 1298 - if (from_user) 1299 - ret = copy_from_user(ch->ch_tbuf + ch->ch_tin, 1300 - (void __user *) buf, count); 1301 - else 1302 - memcpy(ch->ch_tbuf + ch->ch_tin, buf, count); 1303 - 1304 - ch->ch_tin += count; 1305 - } 1306 - 1307 - 1308 - static int dgrp_calculate_txprint_bounds(struct ch_struct *ch, int space, 1309 - int *un_flag) 1310 - { 1311 - clock_t tt; 1312 - clock_t mt; 1313 - unsigned short tmax = 0; 1314 - 1315 - /* 1316 - * If the terminal device is busy, reschedule when 1317 - * the terminal device becomes idle. 1318 - */ 1319 - 1320 - if (ch->ch_tun.un_open_count != 0 && 1321 - ch->ch_tun.un_tty->ops->chars_in_buffer && 1322 - ((ch->ch_tun.un_tty->ops->chars_in_buffer) 1323 - (ch->ch_tun.un_tty) != 0)) { 1324 - *un_flag = UN_PWAIT; 1325 - return 0; 1326 - } 1327 - 1328 - /* 1329 - * Assure that whenever there is printer data in the output 1330 - * buffer, there always remains enough space after it to 1331 - * turn the printer off. 1332 - */ 1333 - space -= ch->ch_digi.digi_offlen; 1334 - 1335 - if (space <= 0) { 1336 - *un_flag = UN_EMPTY; 1337 - return 0; 1338 - } 1339 - 1340 - /* 1341 - * We measure printer CPS speed by incrementing 1342 - * ch_cpstime by (HZ / digi_maxcps) for every 1343 - * character we output, restricting output so 1344 - * that ch_cpstime never exceeds lbolt. 1345 - * 1346 - * However if output has not been done for some 1347 - * time, lbolt will grow to very much larger than 1348 - * ch_cpstime, which would allow essentially 1349 - * unlimited amounts of output until ch_cpstime 1350 - * finally caught up. To avoid this, we adjust 1351 - * cps_time when necessary so the difference 1352 - * between lbolt and ch_cpstime never results 1353 - * in sending more than digi_bufsize characters. 1354 - * 1355 - * This nicely models a printer with an internal 1356 - * buffer of digi_bufsize characters. 1357 - * 1358 - * Get the time between lbolt and ch->ch_cpstime; 1359 - */ 1360 - 1361 - tt = jiffies - ch->ch_cpstime; 1362 - 1363 - /* 1364 - * Compute the time required to send digi_bufsize 1365 - * characters. 1366 - */ 1367 - 1368 - mt = HZ * ch->ch_digi.digi_bufsize / ch->ch_digi.digi_maxcps; 1369 - 1370 - /* 1371 - * Compute the number of characters that can be sent 1372 - * without violating the time constraint. If the 1373 - * direct calculation of this number is bigger than 1374 - * digi_bufsize, limit the number to digi_bufsize, 1375 - * and adjust cpstime to match. 1376 - */ 1377 - 1378 - if ((clock_t)(tt + HZ) > (clock_t)(mt + HZ)) { 1379 - tmax = ch->ch_digi.digi_bufsize; 1380 - ch->ch_cpstime = jiffies - mt; 1381 - } else { 1382 - tmax = ch->ch_digi.digi_maxcps * tt / HZ; 1383 - } 1384 - 1385 - /* 1386 - * If the time constraint now binds, limit the transmit 1387 - * count accordingly, and tentatively arrange to be 1388 - * rescheduled based on time. 1389 - */ 1390 - 1391 - if (tmax < space) { 1392 - *un_flag = UN_TIME; 1393 - space = tmax; 1394 - } 1395 - 1396 - /* 1397 - * Compute the total number of characters we can 1398 - * output before the total number of characters known 1399 - * to be in the output queue exceeds digi_maxchar. 1400 - */ 1401 - 1402 - tmax = (ch->ch_digi.digi_maxchar - 1403 - ((ch->ch_tin - ch->ch_tout) & TBUF_MASK) - 1404 - ((ch->ch_s_tin - ch->ch_s_tpos) & 0xffff)); 1405 - 1406 - 1407 - /* 1408 - * If the digi_maxchar constraint now holds, limit 1409 - * the transmit count accordingly, and arrange to 1410 - * be rescheduled when the queue becomes empty. 1411 - */ 1412 - 1413 - if (space > tmax) { 1414 - *un_flag = UN_EMPTY; 1415 - space = tmax; 1416 - } 1417 - 1418 - if (space <= 0) 1419 - *un_flag |= UN_EMPTY; 1420 - 1421 - return space; 1422 - } 1423 - 1424 - 1425 - static int dgrp_tty_write(struct tty_struct *tty, 1426 - const unsigned char *buf, 1427 - int count) 1428 - { 1429 - struct nd_struct *nd; 1430 - struct un_struct *un; 1431 - struct ch_struct *ch; 1432 - int space; 1433 - int n; 1434 - int t; 1435 - int sendcount; 1436 - int un_flag; 1437 - ulong lock_flags; 1438 - 1439 - if (tty == NULL) 1440 - return 0; 1441 - 1442 - un = tty->driver_data; 1443 - if (!un) 1444 - return 0; 1445 - 1446 - ch = un->un_ch; 1447 - if (!ch) 1448 - return 0; 1449 - 1450 - nd = ch->ch_nd; 1451 - if (!nd) 1452 - return 0; 1453 - 1454 - /* 1455 - * Ignore the request if the channel is not ready. 1456 - */ 1457 - if (ch->ch_state != CS_READY) 1458 - return 0; 1459 - 1460 - spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags); 1461 - 1462 - /* 1463 - * Ignore the request if output is blocked. 1464 - */ 1465 - if ((un->un_flag & (UN_EMPTY | UN_LOW | UN_TIME | UN_PWAIT)) != 0) { 1466 - count = 0; 1467 - goto out; 1468 - } 1469 - 1470 - /* 1471 - * Also ignore the request if DPA has this port open, 1472 - * and is flow controlled on reading more data. 1473 - */ 1474 - if (nd->nd_dpa_debug && nd->nd_dpa_flag & DPA_WAIT_SPACE && 1475 - nd->nd_dpa_port == MINOR(tty_devnum(ch->ch_tun.un_tty))) { 1476 - count = 0; 1477 - goto out; 1478 - } 1479 - 1480 - /* 1481 - * Limit amount we will write to the amount of space 1482 - * available in the channel buffer. 1483 - */ 1484 - sendcount = 0; 1485 - 1486 - space = (ch->ch_tout - ch->ch_tin - 1) & TBUF_MASK; 1487 - 1488 - /* 1489 - * Handle the printer device. 1490 - */ 1491 - 1492 - un_flag = UN_LOW; 1493 - 1494 - if (IS_PRINT(MINOR(tty_devnum(tty)))) { 1495 - clock_t tt; 1496 - clock_t mt; 1497 - unsigned short tmax = 0; 1498 - 1499 - /* 1500 - * If the terminal device is busy, reschedule when 1501 - * the terminal device becomes idle. 1502 - */ 1503 - 1504 - if (ch->ch_tun.un_open_count != 0 && 1505 - ((ch->ch_tun.un_tty->ops->chars_in_buffer) 1506 - (ch->ch_tun.un_tty) != 0)) { 1507 - un->un_flag |= UN_PWAIT; 1508 - count = 0; 1509 - goto out; 1510 - } 1511 - 1512 - /* 1513 - * Assure that whenever there is printer data in the output 1514 - * buffer, there always remains enough space after it to 1515 - * turn the printer off. 1516 - */ 1517 - space -= ch->ch_digi.digi_offlen; 1518 - 1519 - /* 1520 - * Output the printer on string. 1521 - */ 1522 - 1523 - if ((ch->ch_flag & CH_PRON) == 0) { 1524 - space -= ch->ch_digi.digi_onlen; 1525 - 1526 - if (space < 0) { 1527 - un->un_flag |= UN_EMPTY; 1528 - (ch->ch_nd)->nd_tx_work = 1; 1529 - count = 0; 1530 - goto out; 1531 - } 1532 - 1533 - drp_wmove(ch, 0, ch->ch_digi.digi_onstr, 1534 - ch->ch_digi.digi_onlen); 1535 - 1536 - ch->ch_flag |= CH_PRON; 1537 - } 1538 - 1539 - /* 1540 - * We measure printer CPS speed by incrementing 1541 - * ch_cpstime by (HZ / digi_maxcps) for every 1542 - * character we output, restricting output so 1543 - * that ch_cpstime never exceeds lbolt. 1544 - * 1545 - * However if output has not been done for some 1546 - * time, lbolt will grow to very much larger than 1547 - * ch_cpstime, which would allow essentially 1548 - * unlimited amounts of output until ch_cpstime 1549 - * finally caught up. To avoid this, we adjust 1550 - * cps_time when necessary so the difference 1551 - * between lbolt and ch_cpstime never results 1552 - * in sending more than digi_bufsize characters. 1553 - * 1554 - * This nicely models a printer with an internal 1555 - * buffer of digi_bufsize characters. 1556 - * 1557 - * Get the time between lbolt and ch->ch_cpstime; 1558 - */ 1559 - 1560 - tt = jiffies - ch->ch_cpstime; 1561 - 1562 - /* 1563 - * Compute the time required to send digi_bufsize 1564 - * characters. 1565 - */ 1566 - 1567 - mt = HZ * ch->ch_digi.digi_bufsize / ch->ch_digi.digi_maxcps; 1568 - 1569 - /* 1570 - * Compute the number of characters that can be sent 1571 - * without violating the time constraint. If the 1572 - * direct calculation of this number is bigger than 1573 - * digi_bufsize, limit the number to digi_bufsize, 1574 - * and adjust cpstime to match. 1575 - */ 1576 - 1577 - if ((clock_t)(tt + HZ) > (clock_t)(mt + HZ)) { 1578 - tmax = ch->ch_digi.digi_bufsize; 1579 - ch->ch_cpstime = jiffies - mt; 1580 - } else { 1581 - tmax = ch->ch_digi.digi_maxcps * tt / HZ; 1582 - } 1583 - 1584 - /* 1585 - * If the time constraint now binds, limit the transmit 1586 - * count accordingly, and tentatively arrange to be 1587 - * rescheduled based on time. 1588 - */ 1589 - 1590 - if (tmax < space) { 1591 - space = tmax; 1592 - un_flag = UN_TIME; 1593 - } 1594 - 1595 - /* 1596 - * Compute the total number of characters we can 1597 - * output before the total number of characters known 1598 - * to be in the output queue exceeds digi_maxchar. 1599 - */ 1600 - 1601 - tmax = (ch->ch_digi.digi_maxchar - 1602 - ((ch->ch_tin - ch->ch_tout) & TBUF_MASK) - 1603 - ((ch->ch_s_tin - ch->ch_s_tpos) & 0xffff)); 1604 - 1605 - 1606 - /* 1607 - * If the digi_maxchar constraint now holds, limit 1608 - * the transmit count accordingly, and arrange to 1609 - * be rescheduled when the queue becomes empty. 1610 - */ 1611 - 1612 - if (space > tmax) { 1613 - space = tmax; 1614 - un_flag = UN_EMPTY; 1615 - } 1616 - 1617 - } 1618 - /* 1619 - * Handle the terminal device. 1620 - */ 1621 - else { 1622 - 1623 - /* 1624 - * If the printer device is on, turn it off. 1625 - */ 1626 - 1627 - if ((ch->ch_flag & CH_PRON) != 0) { 1628 - 1629 - space -= ch->ch_digi.digi_offlen; 1630 - 1631 - drp_wmove(ch, 0, ch->ch_digi.digi_offstr, 1632 - ch->ch_digi.digi_offlen); 1633 - 1634 - ch->ch_flag &= ~CH_PRON; 1635 - } 1636 - } 1637 - 1638 - /* 1639 - * If space is 0 and its because the ch->tbuf 1640 - * is full, then Linux will handle a callback when queue 1641 - * space becomes available. 1642 - * tty_write returns count = 0 1643 - */ 1644 - 1645 - if (space <= 0) { 1646 - /* the linux tty_io.c handles this if we return 0 */ 1647 - /* if (fp->flags & O_NONBLOCK) return -EAGAIN; */ 1648 - 1649 - un->un_flag |= UN_EMPTY; 1650 - (ch->ch_nd)->nd_tx_work = 1; 1651 - count = 0; 1652 - goto out; 1653 - } 1654 - 1655 - count = min(count, space); 1656 - 1657 - if (count > 0) { 1658 - 1659 - un->un_tbusy++; 1660 - 1661 - /* 1662 - * Copy the buffer contents to the ch_tbuf 1663 - * being careful to wrap around the circular queue 1664 - */ 1665 - 1666 - t = TBUF_MAX - ch->ch_tin; 1667 - n = count; 1668 - 1669 - if (n >= t) { 1670 - memcpy(ch->ch_tbuf + ch->ch_tin, buf, t); 1671 - if (nd->nd_dpa_debug && nd->nd_dpa_port == 1672 - PORT_NUM(MINOR(tty_devnum(un->un_tty)))) 1673 - dgrp_dpa_data(nd, 0, (char *) buf, t); 1674 - buf += t; 1675 - n -= t; 1676 - ch->ch_tin = 0; 1677 - sendcount += n; 1678 - } 1679 - 1680 - memcpy(ch->ch_tbuf + ch->ch_tin, buf, n); 1681 - if (nd->nd_dpa_debug && nd->nd_dpa_port == 1682 - PORT_NUM(MINOR(tty_devnum(un->un_tty)))) 1683 - dgrp_dpa_data(nd, 0, (char *) buf, n); 1684 - buf += n; 1685 - ch->ch_tin += n; 1686 - sendcount += n; 1687 - 1688 - un->un_tbusy--; 1689 - (ch->ch_nd)->nd_tx_work = 1; 1690 - if (ch->ch_edelay != DGRP_RTIME) { 1691 - (ch->ch_nd)->nd_tx_ready = 1; 1692 - wake_up_interruptible(&nd->nd_tx_waitq); 1693 - } 1694 - } 1695 - 1696 - ch->ch_txcount += count; 1697 - 1698 - if (IS_PRINT(MINOR(tty_devnum(tty)))) { 1699 - 1700 - /* 1701 - * Adjust ch_cpstime to account 1702 - * for the characters just output. 1703 - */ 1704 - 1705 - if (sendcount > 0) { 1706 - int cc = HZ * sendcount + ch->ch_cpsrem; 1707 - 1708 - ch->ch_cpstime += cc / ch->ch_digi.digi_maxcps; 1709 - ch->ch_cpsrem = cc % ch->ch_digi.digi_maxcps; 1710 - } 1711 - 1712 - /* 1713 - * If we are now waiting on time, schedule ourself 1714 - * back when we'll be able to send a block of 1715 - * digi_maxchar characters. 1716 - */ 1717 - 1718 - if ((un_flag & UN_TIME) != 0) { 1719 - ch->ch_waketime = (ch->ch_cpstime + 1720 - (ch->ch_digi.digi_maxchar * HZ / 1721 - ch->ch_digi.digi_maxcps)); 1722 - } 1723 - } 1724 - 1725 - /* 1726 - * If the printer unit is waiting for completion 1727 - * of terminal output, get him going again. 1728 - */ 1729 - 1730 - if ((ch->ch_pun.un_flag & UN_PWAIT) != 0) 1731 - (ch->ch_nd)->nd_tx_work = 1; 1732 - 1733 - out: 1734 - spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags); 1735 - 1736 - return count; 1737 - } 1738 - 1739 - 1740 - /* 1741 - * Put a character into ch->ch_buf 1742 - * 1743 - * - used by the line discipline for OPOST processing 1744 - */ 1745 - 1746 - static int dgrp_tty_put_char(struct tty_struct *tty, unsigned char new_char) 1747 - { 1748 - struct un_struct *un; 1749 - struct ch_struct *ch; 1750 - ulong lock_flags; 1751 - int space; 1752 - int retval = 0; 1753 - 1754 - if (tty == NULL) 1755 - return 0; 1756 - 1757 - un = tty->driver_data; 1758 - if (!un) 1759 - return 0; 1760 - 1761 - ch = un->un_ch; 1762 - if (!ch) 1763 - return 0; 1764 - 1765 - if (ch->ch_state != CS_READY) 1766 - return 0; 1767 - 1768 - spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags); 1769 - 1770 - 1771 - /* 1772 - * If space is 0 and its because the ch->tbuf 1773 - * Warn and dump the character, there isn't anything else 1774 - * we can do about it. David_Fries@digi.com 1775 - */ 1776 - 1777 - space = (ch->ch_tout - ch->ch_tin - 1) & TBUF_MASK; 1778 - 1779 - un->un_tbusy++; 1780 - 1781 - /* 1782 - * Output the printer on string if device is TXPrint. 1783 - */ 1784 - if (IS_PRINT(MINOR(tty_devnum(tty))) && (ch->ch_flag & CH_PRON) == 0) { 1785 - if (space < ch->ch_digi.digi_onlen) { 1786 - un->un_tbusy--; 1787 - goto out; 1788 - } 1789 - space -= ch->ch_digi.digi_onlen; 1790 - drp_wmove(ch, 0, ch->ch_digi.digi_onstr, 1791 - ch->ch_digi.digi_onlen); 1792 - ch->ch_flag |= CH_PRON; 1793 - } 1794 - 1795 - /* 1796 - * Output the printer off string if device is NOT TXPrint. 1797 - */ 1798 - 1799 - if (!IS_PRINT(MINOR(tty_devnum(tty))) && 1800 - ((ch->ch_flag & CH_PRON) != 0)) { 1801 - if (space < ch->ch_digi.digi_offlen) { 1802 - un->un_tbusy--; 1803 - goto out; 1804 - } 1805 - 1806 - space -= ch->ch_digi.digi_offlen; 1807 - drp_wmove(ch, 0, ch->ch_digi.digi_offstr, 1808 - ch->ch_digi.digi_offlen); 1809 - ch->ch_flag &= ~CH_PRON; 1810 - } 1811 - 1812 - if (!space) { 1813 - un->un_tbusy--; 1814 - goto out; 1815 - } 1816 - 1817 - /* 1818 - * Copy the character to the ch_tbuf being 1819 - * careful to wrap around the circular queue 1820 - */ 1821 - ch->ch_tbuf[ch->ch_tin] = new_char; 1822 - ch->ch_tin = (1 + ch->ch_tin) & TBUF_MASK; 1823 - 1824 - if (IS_PRINT(MINOR(tty_devnum(tty)))) { 1825 - 1826 - /* 1827 - * Adjust ch_cpstime to account 1828 - * for the character just output. 1829 - */ 1830 - 1831 - int cc = HZ + ch->ch_cpsrem; 1832 - 1833 - ch->ch_cpstime += cc / ch->ch_digi.digi_maxcps; 1834 - ch->ch_cpsrem = cc % ch->ch_digi.digi_maxcps; 1835 - 1836 - /* 1837 - * If we are now waiting on time, schedule ourself 1838 - * back when we'll be able to send a block of 1839 - * digi_maxchar characters. 1840 - */ 1841 - 1842 - ch->ch_waketime = (ch->ch_cpstime + 1843 - (ch->ch_digi.digi_maxchar * HZ / 1844 - ch->ch_digi.digi_maxcps)); 1845 - } 1846 - 1847 - 1848 - un->un_tbusy--; 1849 - (ch->ch_nd)->nd_tx_work = 1; 1850 - 1851 - retval = 1; 1852 - out: 1853 - spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags); 1854 - return retval; 1855 - } 1856 - 1857 - 1858 - 1859 - /* 1860 - * Flush TX buffer (make in == out) 1861 - * 1862 - * check tty_ioctl.c -- this is called after TCOFLUSH 1863 - */ 1864 - static void dgrp_tty_flush_buffer(struct tty_struct *tty) 1865 - { 1866 - struct un_struct *un; 1867 - struct ch_struct *ch; 1868 - 1869 - if (!tty) 1870 - return; 1871 - un = tty->driver_data; 1872 - if (!un) 1873 - return; 1874 - 1875 - ch = un->un_ch; 1876 - if (!ch) 1877 - return; 1878 - 1879 - ch->ch_tout = ch->ch_tin; 1880 - /* do NOT do this here! */ 1881 - /* ch->ch_s_tpos = ch->ch_s_tin = 0; */ 1882 - 1883 - /* send the flush output command now */ 1884 - ch->ch_send |= RR_TX_FLUSH; 1885 - (ch->ch_nd)->nd_tx_ready = 1; 1886 - (ch->ch_nd)->nd_tx_work = 1; 1887 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 1888 - 1889 - if (waitqueue_active(&tty->write_wait)) 1890 - wake_up_interruptible(&tty->write_wait); 1891 - 1892 - tty_wakeup(tty); 1893 - 1894 - } 1895 - 1896 - /* 1897 - * Return space available in Tx buffer 1898 - * count = ( ch->ch_tout - ch->ch_tin ) mod (TBUF_MAX - 1) 1899 - */ 1900 - static int dgrp_tty_write_room(struct tty_struct *tty) 1901 - { 1902 - struct un_struct *un; 1903 - struct ch_struct *ch; 1904 - int count; 1905 - 1906 - if (!tty) 1907 - return 0; 1908 - 1909 - un = tty->driver_data; 1910 - if (!un) 1911 - return 0; 1912 - 1913 - ch = un->un_ch; 1914 - if (!ch) 1915 - return 0; 1916 - 1917 - count = (ch->ch_tout - ch->ch_tin - 1) & TBUF_MASK; 1918 - 1919 - /* We *MUST* check this, and return 0 if the Printer Unit cannot 1920 - * take any more data within its time constraints... If we don't 1921 - * return 0 and the printer has hit it time constraint, the ld will 1922 - * call us back doing a put_char, which cannot be rejected!!! 1923 - */ 1924 - if (IS_PRINT(MINOR(tty_devnum(tty)))) { 1925 - int un_flag = 0; 1926 - count = dgrp_calculate_txprint_bounds(ch, count, &un_flag); 1927 - if (count <= 0) 1928 - count = 0; 1929 - 1930 - ch->ch_pun.un_flag |= un_flag; 1931 - (ch->ch_nd)->nd_tx_work = 1; 1932 - } 1933 - 1934 - return count; 1935 - } 1936 - 1937 - /* 1938 - * Return number of characters that have not been transmitted yet. 1939 - * chars_in_buffer = ( ch->ch_tin - ch->ch_tout ) mod (TBUF_MAX - 1) 1940 - * + ( ch->ch_s_tin - ch->ch_s_tout ) mod (0xffff) 1941 - * = number of characters "in transit" 1942 - * 1943 - * Remember that sequence number math is always with a sixteen bit 1944 - * mask, not the TBUF_MASK. 1945 - */ 1946 - 1947 - static int dgrp_tty_chars_in_buffer(struct tty_struct *tty) 1948 - { 1949 - struct un_struct *un; 1950 - struct ch_struct *ch; 1951 - int count; 1952 - int count1; 1953 - 1954 - if (!tty) 1955 - return 0; 1956 - 1957 - un = tty->driver_data; 1958 - if (!un) 1959 - return 0; 1960 - 1961 - ch = un->un_ch; 1962 - if (!ch) 1963 - return 0; 1964 - 1965 - count1 = count = (ch->ch_tin - ch->ch_tout) & TBUF_MASK; 1966 - count += (ch->ch_s_tin - ch->ch_s_tpos) & 0xffff; 1967 - /* one for tbuf, one for the PS */ 1968 - 1969 - /* 1970 - * If we are busy transmitting add 1 1971 - */ 1972 - count += un->un_tbusy; 1973 - 1974 - return count; 1975 - } 1976 - 1977 - 1978 - /***************************************************************************** 1979 - * 1980 - * Helper applications for dgrp_tty_ioctl() 1981 - * 1982 - ***************************************************************************** 1983 - */ 1984 - 1985 - 1986 - /** 1987 - * ch_to_tty_flags() -- convert channel flags to termio flags 1988 - * @ch_flag: Digi channel flags 1989 - * @flagtype: type of ch_flag (iflag, oflag or cflag) 1990 - * 1991 - * take the channel flags of the specified type and return the 1992 - * corresponding termio flag 1993 - */ 1994 - static tcflag_t ch_to_tty_flags(ushort ch_flag, char flagtype) 1995 - { 1996 - tcflag_t retval = 0; 1997 - 1998 - switch (flagtype) { 1999 - case 'i': 2000 - retval = ((ch_flag & IF_IGNBRK) ? IGNBRK : 0) 2001 - | ((ch_flag & IF_BRKINT) ? BRKINT : 0) 2002 - | ((ch_flag & IF_IGNPAR) ? IGNPAR : 0) 2003 - | ((ch_flag & IF_PARMRK) ? PARMRK : 0) 2004 - | ((ch_flag & IF_INPCK) ? INPCK : 0) 2005 - | ((ch_flag & IF_ISTRIP) ? ISTRIP : 0) 2006 - | ((ch_flag & IF_IXON) ? IXON : 0) 2007 - | ((ch_flag & IF_IXANY) ? IXANY : 0) 2008 - | ((ch_flag & IF_IXOFF) ? IXOFF : 0); 2009 - break; 2010 - 2011 - case 'o': 2012 - retval = ((ch_flag & OF_OLCUC) ? OLCUC : 0) 2013 - | ((ch_flag & OF_ONLCR) ? ONLCR : 0) 2014 - | ((ch_flag & OF_OCRNL) ? OCRNL : 0) 2015 - | ((ch_flag & OF_ONOCR) ? ONOCR : 0) 2016 - | ((ch_flag & OF_ONLRET) ? ONLRET : 0) 2017 - /* | ((ch_flag & OF_OTAB3) ? OFILL : 0) */ 2018 - | ((ch_flag & OF_TABDLY) ? TABDLY : 0); 2019 - break; 2020 - 2021 - case 'c': 2022 - retval = ((ch_flag & CF_CSTOPB) ? CSTOPB : 0) 2023 - | ((ch_flag & CF_CREAD) ? CREAD : 0) 2024 - | ((ch_flag & CF_PARENB) ? PARENB : 0) 2025 - | ((ch_flag & CF_PARODD) ? PARODD : 0) 2026 - | ((ch_flag & CF_HUPCL) ? HUPCL : 0); 2027 - 2028 - switch (ch_flag & CF_CSIZE) { 2029 - case CF_CS5: 2030 - retval |= CS5; 2031 - break; 2032 - case CF_CS6: 2033 - retval |= CS6; 2034 - break; 2035 - case CF_CS7: 2036 - retval |= CS7; 2037 - break; 2038 - case CF_CS8: 2039 - retval |= CS8; 2040 - break; 2041 - default: 2042 - retval |= CS8; 2043 - break; 2044 - } 2045 - break; 2046 - case 'x': 2047 - break; 2048 - case 'l': 2049 - break; 2050 - default: 2051 - return 0; 2052 - } 2053 - 2054 - return retval; 2055 - } 2056 - 2057 - 2058 - /** 2059 - * tty_to_ch_flags() -- convert termio flags to digi channel flags 2060 - * @tty: pointer to a TTY structure holding flag to be converted 2061 - * @flagtype: identifies which flag (iflags, oflags, or cflags) should 2062 - * be converted 2063 - * 2064 - * take the termio flag of the specified type and return the 2065 - * corresponding Digi version of the flags 2066 - */ 2067 - static ushort tty_to_ch_flags(struct tty_struct *tty, char flagtype) 2068 - { 2069 - ushort retval = 0; 2070 - tcflag_t tflag = 0; 2071 - 2072 - switch (flagtype) { 2073 - case 'i': 2074 - tflag = tty->termios.c_iflag; 2075 - retval = (I_IGNBRK(tty) ? IF_IGNBRK : 0) 2076 - | (I_BRKINT(tty) ? IF_BRKINT : 0) 2077 - | (I_IGNPAR(tty) ? IF_IGNPAR : 0) 2078 - | (I_PARMRK(tty) ? IF_PARMRK : 0) 2079 - | (I_INPCK(tty) ? IF_INPCK : 0) 2080 - | (I_ISTRIP(tty) ? IF_ISTRIP : 0) 2081 - | (I_IXON(tty) ? IF_IXON : 0) 2082 - | (I_IXANY(tty) ? IF_IXANY : 0) 2083 - | (I_IXOFF(tty) ? IF_IXOFF : 0); 2084 - break; 2085 - case 'o': 2086 - tflag = tty->termios.c_oflag; 2087 - /* 2088 - * If OPOST is set, then do the post processing in the 2089 - * firmware by setting all the processing flags on. 2090 - * If ~OPOST, then make sure we are not doing any 2091 - * output processing!! 2092 - */ 2093 - if (!O_OPOST(tty)) 2094 - retval = 0; 2095 - else 2096 - retval = (O_OLCUC(tty) ? OF_OLCUC : 0) 2097 - | (O_ONLCR(tty) ? OF_ONLCR : 0) 2098 - | (O_OCRNL(tty) ? OF_OCRNL : 0) 2099 - | (O_ONOCR(tty) ? OF_ONOCR : 0) 2100 - | (O_ONLRET(tty) ? OF_ONLRET : 0) 2101 - /* | (O_OFILL(tty) ? OF_TAB3 : 0) */ 2102 - | (O_TABDLY(tty) ? OF_TABDLY : 0); 2103 - break; 2104 - case 'c': 2105 - tflag = tty->termios.c_cflag; 2106 - retval = (C_CSTOPB(tty) ? CF_CSTOPB : 0) 2107 - | (C_CREAD(tty) ? CF_CREAD : 0) 2108 - | (C_PARENB(tty) ? CF_PARENB : 0) 2109 - | (C_PARODD(tty) ? CF_PARODD : 0) 2110 - | (C_HUPCL(tty) ? CF_HUPCL : 0); 2111 - switch (C_CSIZE(tty)) { 2112 - case CS8: 2113 - retval |= CF_CS8; 2114 - break; 2115 - case CS7: 2116 - retval |= CF_CS7; 2117 - break; 2118 - case CS6: 2119 - retval |= CF_CS6; 2120 - break; 2121 - case CS5: 2122 - retval |= CF_CS5; 2123 - break; 2124 - default: 2125 - retval |= CF_CS8; 2126 - break; 2127 - } 2128 - break; 2129 - case 'x': 2130 - break; 2131 - case 'l': 2132 - break; 2133 - default: 2134 - return 0; 2135 - } 2136 - 2137 - return retval; 2138 - } 2139 - 2140 - 2141 - static int dgrp_tty_send_break(struct tty_struct *tty, int msec) 2142 - { 2143 - struct un_struct *un; 2144 - struct ch_struct *ch; 2145 - int ret = -EIO; 2146 - 2147 - if (!tty) 2148 - return ret; 2149 - 2150 - un = tty->driver_data; 2151 - if (!un) 2152 - return ret; 2153 - 2154 - ch = un->un_ch; 2155 - if (!ch) 2156 - return ret; 2157 - 2158 - dgrp_send_break(ch, msec); 2159 - return 0; 2160 - } 2161 - 2162 - 2163 - /* 2164 - * This routine sends a break character out the serial port. 2165 - * 2166 - * duration is in 1/1000's of a second 2167 - */ 2168 - static int dgrp_send_break(struct ch_struct *ch, int msec) 2169 - { 2170 - ulong x; 2171 - 2172 - wait_event_interruptible(ch->ch_flag_wait, 2173 - ((ch->ch_flag & CH_TX_BREAK) == 0)); 2174 - ch->ch_break_time += max(msec, 250); 2175 - ch->ch_send |= RR_TX_BREAK; 2176 - ch->ch_flag |= CH_TX_BREAK; 2177 - (ch->ch_nd)->nd_tx_work = 1; 2178 - 2179 - x = (msec * HZ) / 1000; 2180 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 2181 - 2182 - return 0; 2183 - } 2184 - 2185 - 2186 - /* 2187 - * Return modem signals to ld. 2188 - */ 2189 - static int dgrp_tty_tiocmget(struct tty_struct *tty) 2190 - { 2191 - unsigned int mlast; 2192 - struct un_struct *un = tty->driver_data; 2193 - struct ch_struct *ch; 2194 - 2195 - if (!un) 2196 - return -ENODEV; 2197 - 2198 - ch = un->un_ch; 2199 - if (!ch) 2200 - return -ENODEV; 2201 - 2202 - mlast = ((ch->ch_s_mlast & ~(DM_RTS | DM_DTR)) | 2203 - (ch->ch_mout & (DM_RTS | DM_DTR))); 2204 - 2205 - /* defined in /usr/include/asm/termios.h */ 2206 - mlast = ((mlast & DM_RTS) ? TIOCM_RTS : 0) 2207 - | ((mlast & DM_DTR) ? TIOCM_DTR : 0) 2208 - | ((mlast & DM_CD) ? TIOCM_CAR : 0) 2209 - | ((mlast & DM_RI) ? TIOCM_RNG : 0) 2210 - | ((mlast & DM_DSR) ? TIOCM_DSR : 0) 2211 - | ((mlast & DM_CTS) ? TIOCM_CTS : 0); 2212 - 2213 - return mlast; 2214 - } 2215 - 2216 - 2217 - /* 2218 - * Set modem lines 2219 - */ 2220 - static int dgrp_tty_tiocmset(struct tty_struct *tty, 2221 - unsigned int set, unsigned int clear) 2222 - { 2223 - ulong lock_flags; 2224 - struct un_struct *un = tty->driver_data; 2225 - struct ch_struct *ch; 2226 - 2227 - if (!un) 2228 - return -ENODEV; 2229 - 2230 - ch = un->un_ch; 2231 - if (!ch) 2232 - return -ENODEV; 2233 - 2234 - if (set & TIOCM_RTS) 2235 - ch->ch_mout |= DM_RTS; 2236 - 2237 - if (set & TIOCM_DTR) 2238 - ch->ch_mout |= DM_DTR; 2239 - 2240 - if (clear & TIOCM_RTS) 2241 - ch->ch_mout &= ~(DM_RTS); 2242 - 2243 - if (clear & TIOCM_DTR) 2244 - ch->ch_mout &= ~(DM_DTR); 2245 - 2246 - spin_lock_irqsave(&(ch->ch_nd)->nd_lock, lock_flags); 2247 - ch->ch_flag |= CH_PARAM; 2248 - (ch->ch_nd)->nd_tx_work = 1; 2249 - wake_up_interruptible(&ch->ch_flag_wait); 2250 - 2251 - spin_unlock_irqrestore(&(ch->ch_nd)->nd_lock, lock_flags); 2252 - 2253 - return 0; 2254 - } 2255 - 2256 - 2257 - 2258 - /* 2259 - * Get current modem status 2260 - */ 2261 - static int get_modem_info(struct ch_struct *ch, unsigned int *value) 2262 - { 2263 - unsigned int mlast; 2264 - 2265 - mlast = ((ch->ch_s_mlast & ~(DM_RTS | DM_DTR)) | 2266 - (ch->ch_mout & (DM_RTS | DM_DTR))); 2267 - 2268 - /* defined in /usr/include/asm/termios.h */ 2269 - mlast = ((mlast & DM_RTS) ? TIOCM_RTS : 0) 2270 - | ((mlast & DM_DTR) ? TIOCM_DTR : 0) 2271 - | ((mlast & DM_CD) ? TIOCM_CAR : 0) 2272 - | ((mlast & DM_RI) ? TIOCM_RNG : 0) 2273 - | ((mlast & DM_DSR) ? TIOCM_DSR : 0) 2274 - | ((mlast & DM_CTS) ? TIOCM_CTS : 0); 2275 - return put_user(mlast, (unsigned int __user *) value); 2276 - } 2277 - 2278 - /* 2279 - * Set modem lines 2280 - */ 2281 - static int set_modem_info(struct ch_struct *ch, unsigned int command, 2282 - unsigned int *value) 2283 - { 2284 - int error; 2285 - unsigned int arg; 2286 - int mval = 0; 2287 - ulong lock_flags; 2288 - 2289 - error = access_ok(VERIFY_READ, (void __user *) value, sizeof(int)); 2290 - if (error == 0) 2291 - return -EFAULT; 2292 - 2293 - if (get_user(arg, (unsigned int __user *) value)) 2294 - return -EFAULT; 2295 - mval |= ((arg & TIOCM_RTS) ? DM_RTS : 0) 2296 - | ((arg & TIOCM_DTR) ? DM_DTR : 0); 2297 - 2298 - switch (command) { 2299 - case TIOCMBIS: /* set flags */ 2300 - ch->ch_mout |= mval; 2301 - break; 2302 - case TIOCMBIC: /* clear flags */ 2303 - ch->ch_mout &= ~mval; 2304 - break; 2305 - case TIOCMSET: 2306 - ch->ch_mout = mval; 2307 - break; 2308 - default: 2309 - return -EINVAL; 2310 - } 2311 - 2312 - spin_lock_irqsave(&(ch->ch_nd)->nd_lock, lock_flags); 2313 - 2314 - ch->ch_flag |= CH_PARAM; 2315 - (ch->ch_nd)->nd_tx_work = 1; 2316 - wake_up_interruptible(&ch->ch_flag_wait); 2317 - 2318 - spin_unlock_irqrestore(&(ch->ch_nd)->nd_lock, lock_flags); 2319 - 2320 - return 0; 2321 - } 2322 - 2323 - 2324 - /* 2325 - * Assign the custom baud rate to the channel structure 2326 - */ 2327 - static void dgrp_set_custom_speed(struct ch_struct *ch, int newrate) 2328 - { 2329 - int testdiv; 2330 - int testrate_high; 2331 - int testrate_low; 2332 - 2333 - int deltahigh, deltalow; 2334 - 2335 - if (newrate < 0) 2336 - newrate = 0; 2337 - 2338 - /* 2339 - * Since the divisor is stored in a 16-bit integer, we make sure 2340 - * we don't allow any rates smaller than a 16-bit integer would allow. 2341 - * And of course, rates above the dividend won't fly. 2342 - */ 2343 - if (newrate && newrate < ((PORTSERVER_DIVIDEND / 0xFFFF) + 1)) 2344 - newrate = ((PORTSERVER_DIVIDEND / 0xFFFF) + 1); 2345 - if (newrate && newrate > PORTSERVER_DIVIDEND) 2346 - newrate = PORTSERVER_DIVIDEND; 2347 - 2348 - while (newrate > 0) { 2349 - testdiv = PORTSERVER_DIVIDEND / newrate; 2350 - 2351 - /* 2352 - * If we try to figure out what rate the PortServer would use 2353 - * with the test divisor, it will be either equal or higher 2354 - * than the requested baud rate. If we then determine the 2355 - * rate with a divisor one higher, we will get the next lower 2356 - * supported rate below the requested. 2357 - */ 2358 - testrate_high = PORTSERVER_DIVIDEND / testdiv; 2359 - testrate_low = PORTSERVER_DIVIDEND / (testdiv + 1); 2360 - 2361 - /* 2362 - * If the rate for the requested divisor is correct, just 2363 - * use it and be done. 2364 - */ 2365 - if (testrate_high == newrate) 2366 - break; 2367 - 2368 - /* 2369 - * Otherwise, pick the rate that is closer (i.e. whichever rate 2370 - * has a smaller delta). 2371 - */ 2372 - deltahigh = testrate_high - newrate; 2373 - deltalow = newrate - testrate_low; 2374 - 2375 - if (deltahigh < deltalow) 2376 - newrate = testrate_high; 2377 - else 2378 - newrate = testrate_low; 2379 - 2380 - break; 2381 - } 2382 - 2383 - ch->ch_custom_speed = newrate; 2384 - 2385 - drp_param(ch); 2386 - 2387 - return; 2388 - } 2389 - 2390 - 2391 - /* 2392 - # dgrp_tty_digiseta() 2393 - * 2394 - * Ioctl to set the information from ditty. 2395 - * 2396 - * NOTE: DIGI_IXON, DSRPACE, DCDPACE, and DTRPACE are unsupported. JAR 990922 2397 - */ 2398 - static int dgrp_tty_digiseta(struct tty_struct *tty, 2399 - struct digi_struct *new_info) 2400 - { 2401 - struct un_struct *un = tty->driver_data; 2402 - struct ch_struct *ch; 2403 - 2404 - if (!un) 2405 - return -ENODEV; 2406 - 2407 - ch = un->un_ch; 2408 - if (!ch) 2409 - return -ENODEV; 2410 - 2411 - if (copy_from_user(&ch->ch_digi, (void __user *) new_info, 2412 - sizeof(struct digi_struct))) 2413 - return -EFAULT; 2414 - 2415 - if ((ch->ch_digi.digi_flags & RTSPACE) || 2416 - (ch->ch_digi.digi_flags & CTSPACE)) 2417 - tty->termios.c_cflag |= CRTSCTS; 2418 - else 2419 - tty->termios.c_cflag &= ~CRTSCTS; 2420 - 2421 - if (ch->ch_digi.digi_maxcps < 1) 2422 - ch->ch_digi.digi_maxcps = 1; 2423 - 2424 - if (ch->ch_digi.digi_maxcps > 10000) 2425 - ch->ch_digi.digi_maxcps = 10000; 2426 - 2427 - if (ch->ch_digi.digi_bufsize < 10) 2428 - ch->ch_digi.digi_bufsize = 10; 2429 - 2430 - if (ch->ch_digi.digi_maxchar < 1) 2431 - ch->ch_digi.digi_maxchar = 1; 2432 - 2433 - if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize) 2434 - ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize; 2435 - 2436 - if (ch->ch_digi.digi_onlen > DIGI_PLEN) 2437 - ch->ch_digi.digi_onlen = DIGI_PLEN; 2438 - 2439 - if (ch->ch_digi.digi_offlen > DIGI_PLEN) 2440 - ch->ch_digi.digi_offlen = DIGI_PLEN; 2441 - 2442 - /* make the changes now */ 2443 - drp_param(ch); 2444 - 2445 - return 0; 2446 - } 2447 - 2448 - 2449 - 2450 - /* 2451 - * dgrp_tty_digigetedelay() 2452 - * 2453 - * Ioctl to get the current edelay setting. 2454 - * 2455 - * 2456 - * 2457 - */ 2458 - static int dgrp_tty_digigetedelay(struct tty_struct *tty, int *retinfo) 2459 - { 2460 - struct un_struct *un; 2461 - struct ch_struct *ch; 2462 - int tmp; 2463 - 2464 - if (!retinfo) 2465 - return -EFAULT; 2466 - 2467 - if (!tty || tty->magic != TTY_MAGIC) 2468 - return -EFAULT; 2469 - 2470 - un = tty->driver_data; 2471 - 2472 - if (!un) 2473 - return -ENODEV; 2474 - 2475 - ch = un->un_ch; 2476 - if (!ch) 2477 - return -ENODEV; 2478 - 2479 - tmp = ch->ch_edelay; 2480 - 2481 - if (copy_to_user((void __user *) retinfo, &tmp, sizeof(*retinfo))) 2482 - return -EFAULT; 2483 - 2484 - return 0; 2485 - } 2486 - 2487 - 2488 - /* 2489 - * dgrp_tty_digisetedelay() 2490 - * 2491 - * Ioctl to set the EDELAY setting 2492 - * 2493 - */ 2494 - static int dgrp_tty_digisetedelay(struct tty_struct *tty, int *new_info) 2495 - { 2496 - struct un_struct *un; 2497 - struct ch_struct *ch; 2498 - int new_digi; 2499 - 2500 - if (!tty || tty->magic != TTY_MAGIC) 2501 - return -EFAULT; 2502 - 2503 - un = tty->driver_data; 2504 - 2505 - if (!un) 2506 - return -ENODEV; 2507 - 2508 - ch = un->un_ch; 2509 - if (!ch) 2510 - return -ENODEV; 2511 - 2512 - if (copy_from_user(&new_digi, (void __user *)new_info, sizeof(int))) 2513 - return -EFAULT; 2514 - 2515 - ch->ch_edelay = new_digi; 2516 - 2517 - /* make the changes now */ 2518 - drp_param(ch); 2519 - 2520 - return 0; 2521 - } 2522 - 2523 - 2524 - /* 2525 - * The usual assortment of ioctl's 2526 - * 2527 - * note: use tty_check_change to make sure that we are not 2528 - * changing the state of a terminal when we are not a process 2529 - * in the forground. See tty_io.c 2530 - * rc = tty_check_change(tty); 2531 - * if (rc) return rc; 2532 - */ 2533 - static int dgrp_tty_ioctl(struct tty_struct *tty, unsigned int cmd, 2534 - unsigned long arg) 2535 - { 2536 - struct un_struct *un; 2537 - struct ch_struct *ch; 2538 - int rc; 2539 - struct digiflow_struct dflow; 2540 - 2541 - if (!tty) 2542 - return -ENODEV; 2543 - 2544 - un = tty->driver_data; 2545 - if (!un) 2546 - return -ENODEV; 2547 - 2548 - ch = un->un_ch; 2549 - if (!ch) 2550 - return -ENODEV; 2551 - 2552 - switch (cmd) { 2553 - 2554 - /* 2555 - * Here are all the standard ioctl's that we MUST implement 2556 - */ 2557 - 2558 - case TCSBRK: 2559 - /* 2560 - * TCSBRK is SVID version: non-zero arg --> no break 2561 - * this behaviour is exploited by tcdrain(). 2562 - * 2563 - * According to POSIX.1 spec (7.2.2.1.2) breaks should be 2564 - * between 0.25 and 0.5 seconds 2565 - */ 2566 - 2567 - rc = tty_check_change(tty); 2568 - if (rc) 2569 - return rc; 2570 - tty_wait_until_sent(tty, 0); 2571 - 2572 - if (!arg) 2573 - rc = dgrp_send_break(ch, 250); /* 1/4 second */ 2574 - 2575 - if (dgrp_tty_chars_in_buffer(tty) != 0) 2576 - return -EINTR; 2577 - 2578 - return 0; 2579 - 2580 - case TCSBRKP: 2581 - /* support for POSIX tcsendbreak() 2582 - * 2583 - * According to POSIX.1 spec (7.2.2.1.2) breaks should be 2584 - * between 0.25 and 0.5 seconds so we'll ask for something 2585 - * in the middle: 0.375 seconds. 2586 - */ 2587 - rc = tty_check_change(tty); 2588 - if (rc) 2589 - return rc; 2590 - tty_wait_until_sent(tty, 0); 2591 - 2592 - rc = dgrp_send_break(ch, arg ? arg*250 : 250); 2593 - 2594 - if (dgrp_tty_chars_in_buffer(tty) != 0) 2595 - return -EINTR; 2596 - return 0; 2597 - 2598 - case TIOCSBRK: 2599 - rc = tty_check_change(tty); 2600 - if (rc) 2601 - return rc; 2602 - tty_wait_until_sent(tty, 0); 2603 - 2604 - /* 2605 - * RealPort doesn't support turning on a break unconditionally. 2606 - * The RealPort device will stop sending a break automatically 2607 - * after the specified time value that we send in. 2608 - */ 2609 - rc = dgrp_send_break(ch, 250); /* 1/4 second */ 2610 - 2611 - if (dgrp_tty_chars_in_buffer(tty) != 0) 2612 - return -EINTR; 2613 - return 0; 2614 - 2615 - case TIOCCBRK: 2616 - /* 2617 - * RealPort doesn't support turning off a break unconditionally. 2618 - * The RealPort device will stop sending a break automatically 2619 - * after the specified time value that was sent when turning on 2620 - * the break. 2621 - */ 2622 - return 0; 2623 - 2624 - case TIOCMGET: 2625 - rc = access_ok(VERIFY_WRITE, (void __user *) arg, 2626 - sizeof(unsigned int)); 2627 - if (rc == 0) 2628 - return -EFAULT; 2629 - return get_modem_info(ch, (unsigned int *) arg); 2630 - 2631 - case TIOCMBIS: 2632 - case TIOCMBIC: 2633 - case TIOCMSET: 2634 - return set_modem_info(ch, cmd, (unsigned int *) arg); 2635 - 2636 - /* 2637 - * Here are any additional ioctl's that we want to implement 2638 - */ 2639 - 2640 - case TCFLSH: 2641 - /* 2642 - * The linux tty driver doesn't have a flush 2643 - * input routine for the driver, assuming all backed 2644 - * up data is in the line disc. buffers. However, 2645 - * we all know that's not the case. Here, we 2646 - * act on the ioctl, but then lie and say we didn't 2647 - * so the line discipline will process the flush 2648 - * also. 2649 - */ 2650 - rc = tty_check_change(tty); 2651 - if (rc) 2652 - return rc; 2653 - 2654 - switch (arg) { 2655 - case TCIFLUSH: 2656 - case TCIOFLUSH: 2657 - /* only flush input if this is the only open unit */ 2658 - if (!IS_PRINT(MINOR(tty_devnum(tty)))) { 2659 - ch->ch_rout = ch->ch_rin; 2660 - ch->ch_send |= RR_RX_FLUSH; 2661 - (ch->ch_nd)->nd_tx_work = 1; 2662 - (ch->ch_nd)->nd_tx_ready = 1; 2663 - wake_up_interruptible( 2664 - &(ch->ch_nd)->nd_tx_waitq); 2665 - } 2666 - if (arg == TCIFLUSH) 2667 - break; 2668 - 2669 - case TCOFLUSH: /* flush output, or the receive buffer */ 2670 - /* 2671 - * This is handled in the tty_ioctl.c code 2672 - * calling tty_flush_buffer 2673 - */ 2674 - break; 2675 - 2676 - default: 2677 - /* POSIX.1 says return EINVAL if we got a bad arg */ 2678 - return -EINVAL; 2679 - } 2680 - /* pretend we didn't recognize this IOCTL */ 2681 - return -ENOIOCTLCMD; 2682 - 2683 - #ifdef TIOCGETP 2684 - case TIOCGETP: 2685 - #endif 2686 - /***************************************** 2687 - Linux HPUX Function 2688 - TCSETA TCSETA - set the termios 2689 - TCSETAF TCSETAF - wait for drain first, then set termios 2690 - TCSETAW TCSETAW - wait for drain, 2691 - flush the input queue, then set termios 2692 - - looking at the tty_ioctl code, these command all call our 2693 - tty_set_termios at the driver's end, when a TCSETA* is sent, 2694 - it is expecting the tty to have a termio structure, 2695 - NOT a termios structure. These two structures differ in size 2696 - and the tty_ioctl code does a conversion before processing them both. 2697 - - we should treat the TCSETAW TCSETAF ioctls the same, and let 2698 - the tty_ioctl code do the conversion stuff. 2699 - 2700 - TCSETS 2701 - TCSETSF (none) 2702 - TCSETSW 2703 - - the associated tty structure has a termios structure. 2704 - *****************************************/ 2705 - 2706 - case TCGETS: 2707 - case TCGETA: 2708 - return -ENOIOCTLCMD; 2709 - 2710 - case TCSETAW: 2711 - case TCSETAF: 2712 - case TCSETSF: 2713 - case TCSETSW: 2714 - /* 2715 - * The linux tty driver doesn't have a flush 2716 - * input routine for the driver, assuming all backed 2717 - * up data is in the line disc. buffers. However, 2718 - * we all know that's not the case. Here, we 2719 - * act on the ioctl, but then lie and say we didn't 2720 - * so the line discipline will process the flush 2721 - * also. 2722 - */ 2723 - 2724 - /* 2725 - * Also, now that we have TXPrint, we have to check 2726 - * if this is the TXPrint device and the terminal 2727 - * device is open. If so, do NOT run check_change, 2728 - * as the terminal device is ALWAYS the parent. 2729 - */ 2730 - if (!IS_PRINT(MINOR(tty_devnum(tty))) || 2731 - !ch->ch_tun.un_open_count) { 2732 - rc = tty_check_change(tty); 2733 - if (rc) 2734 - return rc; 2735 - } 2736 - 2737 - /* wait for all the characters in tbuf to drain */ 2738 - tty_wait_until_sent(tty, 0); 2739 - 2740 - if ((cmd == TCSETSF) || (cmd == TCSETAF)) { 2741 - /* flush the contents of the rbuf queue */ 2742 - /* TODO: check if this is print device? */ 2743 - ch->ch_send |= RR_RX_FLUSH; 2744 - (ch->ch_nd)->nd_tx_ready = 1; 2745 - (ch->ch_nd)->nd_tx_work = 1; 2746 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 2747 - /* do we need to do this? just to be safe! */ 2748 - ch->ch_rout = ch->ch_rin; 2749 - } 2750 - 2751 - /* pretend we didn't recognize this */ 2752 - return -ENOIOCTLCMD; 2753 - 2754 - case TCXONC: 2755 - /* 2756 - * The Linux Line Discipline (LD) would do this for us if we 2757 - * let it, but we have the special firmware options to do this 2758 - * the "right way" regardless of hardware or software flow 2759 - * control so we'll do it outselves instead of letting the LD 2760 - * do it. 2761 - */ 2762 - rc = tty_check_change(tty); 2763 - if (rc) 2764 - return rc; 2765 - 2766 - switch (arg) { 2767 - case TCOON: 2768 - dgrp_tty_start(tty); 2769 - return 0; 2770 - case TCOOFF: 2771 - dgrp_tty_stop(tty); 2772 - return 0; 2773 - case TCION: 2774 - dgrp_tty_input_start(tty); 2775 - return 0; 2776 - case TCIOFF: 2777 - dgrp_tty_input_stop(tty); 2778 - return 0; 2779 - default: 2780 - return -EINVAL; 2781 - } 2782 - 2783 - case DIGI_GETA: 2784 - /* get information for ditty */ 2785 - if (copy_to_user((struct digi_struct __user *) arg, 2786 - &ch->ch_digi, sizeof(struct digi_struct))) 2787 - return -EFAULT; 2788 - break; 2789 - 2790 - case DIGI_SETAW: 2791 - case DIGI_SETAF: 2792 - /* wait for all the characters in tbuf to drain */ 2793 - tty_wait_until_sent(tty, 0); 2794 - 2795 - if (cmd == DIGI_SETAF) { 2796 - /* flush the contents of the rbuf queue */ 2797 - /* send down a packet with RR_RX_FLUSH set */ 2798 - ch->ch_send |= RR_RX_FLUSH; 2799 - (ch->ch_nd)->nd_tx_ready = 1; 2800 - (ch->ch_nd)->nd_tx_work = 1; 2801 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 2802 - /* do we need to do this? just to be safe! */ 2803 - ch->ch_rout = ch->ch_rin; 2804 - } 2805 - 2806 - /* pretend we didn't recognize this */ 2807 - /* fall-through */ 2808 - 2809 - case DIGI_SETA: 2810 - return dgrp_tty_digiseta(tty, (struct digi_struct *) arg); 2811 - 2812 - case DIGI_SEDELAY: 2813 - return dgrp_tty_digisetedelay(tty, (int *) arg); 2814 - 2815 - case DIGI_GEDELAY: 2816 - return dgrp_tty_digigetedelay(tty, (int *) arg); 2817 - 2818 - case DIGI_GETFLOW: 2819 - case DIGI_GETAFLOW: 2820 - if (cmd == (DIGI_GETFLOW)) { 2821 - dflow.startc = tty->termios.c_cc[VSTART]; 2822 - dflow.stopc = tty->termios.c_cc[VSTOP]; 2823 - } else { 2824 - dflow.startc = ch->ch_xxon; 2825 - dflow.stopc = ch->ch_xxoff; 2826 - } 2827 - 2828 - if (copy_to_user((char __user *)arg, &dflow, sizeof(dflow))) 2829 - return -EFAULT; 2830 - break; 2831 - 2832 - case DIGI_SETFLOW: 2833 - case DIGI_SETAFLOW: 2834 - 2835 - if (copy_from_user(&dflow, (char __user *)arg, sizeof(dflow))) 2836 - return -EFAULT; 2837 - 2838 - if (cmd == (DIGI_SETFLOW)) { 2839 - tty->termios.c_cc[VSTART] = dflow.startc; 2840 - tty->termios.c_cc[VSTOP] = dflow.stopc; 2841 - } else { 2842 - ch->ch_xxon = dflow.startc; 2843 - ch->ch_xxoff = dflow.stopc; 2844 - } 2845 - break; 2846 - 2847 - case DIGI_GETCUSTOMBAUD: 2848 - if (put_user(ch->ch_custom_speed, (unsigned int __user *) arg)) 2849 - return -EFAULT; 2850 - break; 2851 - 2852 - case DIGI_SETCUSTOMBAUD: 2853 - { 2854 - int new_rate; 2855 - 2856 - if (get_user(new_rate, (unsigned int __user *) arg)) 2857 - return -EFAULT; 2858 - dgrp_set_custom_speed(ch, new_rate); 2859 - 2860 - break; 2861 - } 2862 - 2863 - default: 2864 - return -ENOIOCTLCMD; 2865 - } 2866 - 2867 - return 0; 2868 - } 2869 - 2870 - /* 2871 - * This routine allows the tty driver to be notified when 2872 - * the device's termios setting have changed. Note that we 2873 - * should be prepared to accept the case where old == NULL 2874 - * and try to do something rational. 2875 - * 2876 - * So we need to make sure that our copies of ch_oflag, 2877 - * ch_clag, and ch_iflag reflect the tty->termios flags. 2878 - */ 2879 - static void dgrp_tty_set_termios(struct tty_struct *tty, struct ktermios *old) 2880 - { 2881 - struct ktermios *ts; 2882 - struct ch_struct *ch; 2883 - struct un_struct *un; 2884 - 2885 - /* seems silly, but we have to check all these! */ 2886 - if (!tty) 2887 - return; 2888 - 2889 - un = tty->driver_data; 2890 - if (!un) 2891 - return; 2892 - 2893 - ts = &tty->termios; 2894 - 2895 - ch = un->un_ch; 2896 - if (!ch) 2897 - return; 2898 - 2899 - drp_param(ch); 2900 - 2901 - /* the CLOCAL flag has just been set */ 2902 - if (!(old->c_cflag & CLOCAL) && C_CLOCAL(tty)) 2903 - wake_up_interruptible(&un->un_open_wait); 2904 - } 2905 - 2906 - 2907 - /* 2908 - * Throttle receiving data. We just set a bit and stop reading 2909 - * data out of the channel buffer. It will back up and the 2910 - * FEP will do whatever is necessary to stop the far end. 2911 - */ 2912 - static void dgrp_tty_throttle(struct tty_struct *tty) 2913 - { 2914 - struct ch_struct *ch; 2915 - 2916 - if (!tty) 2917 - return; 2918 - 2919 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 2920 - if (!ch) 2921 - return; 2922 - 2923 - ch->ch_flag |= CH_RXSTOP; 2924 - } 2925 - 2926 - 2927 - static void dgrp_tty_unthrottle(struct tty_struct *tty) 2928 - { 2929 - struct ch_struct *ch; 2930 - 2931 - if (!tty) 2932 - return; 2933 - 2934 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 2935 - if (!ch) 2936 - return; 2937 - 2938 - ch->ch_flag &= ~CH_RXSTOP; 2939 - } 2940 - 2941 - /* 2942 - * Stop the transmitter 2943 - */ 2944 - static void dgrp_tty_stop(struct tty_struct *tty) 2945 - { 2946 - struct ch_struct *ch; 2947 - 2948 - if (!tty) 2949 - return; 2950 - 2951 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 2952 - if (!ch) 2953 - return; 2954 - 2955 - ch->ch_send |= RR_TX_STOP; 2956 - ch->ch_send &= ~RR_TX_START; 2957 - 2958 - /* make the change NOW! */ 2959 - (ch->ch_nd)->nd_tx_ready = 1; 2960 - if (waitqueue_active(&(ch->ch_nd)->nd_tx_waitq)) 2961 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 2962 - } 2963 - 2964 - /* 2965 - * Start the transmitter 2966 - */ 2967 - static void dgrp_tty_start(struct tty_struct *tty) 2968 - { 2969 - struct ch_struct *ch; 2970 - 2971 - if (!tty) 2972 - return; 2973 - 2974 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 2975 - if (!ch) 2976 - return; 2977 - 2978 - /* TODO: don't do anything if the transmitter is not stopped */ 2979 - 2980 - ch->ch_send |= RR_TX_START; 2981 - ch->ch_send &= ~RR_TX_STOP; 2982 - 2983 - /* make the change NOW! */ 2984 - (ch->ch_nd)->nd_tx_ready = 1; 2985 - (ch->ch_nd)->nd_tx_work = 1; 2986 - if (waitqueue_active(&(ch->ch_nd)->nd_tx_waitq)) 2987 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 2988 - 2989 - } 2990 - 2991 - /* 2992 - * Stop the receiver 2993 - */ 2994 - static void dgrp_tty_input_stop(struct tty_struct *tty) 2995 - { 2996 - struct ch_struct *ch; 2997 - 2998 - if (!tty) 2999 - return; 3000 - 3001 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 3002 - if (!ch) 3003 - return; 3004 - 3005 - ch->ch_send |= RR_RX_STOP; 3006 - ch->ch_send &= ~RR_RX_START; 3007 - (ch->ch_nd)->nd_tx_ready = 1; 3008 - if (waitqueue_active(&(ch->ch_nd)->nd_tx_waitq)) 3009 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 3010 - 3011 - } 3012 - 3013 - 3014 - static void dgrp_tty_send_xchar(struct tty_struct *tty, char c) 3015 - { 3016 - struct un_struct *un; 3017 - struct ch_struct *ch; 3018 - 3019 - if (!tty) 3020 - return; 3021 - 3022 - un = tty->driver_data; 3023 - if (!un) 3024 - return; 3025 - 3026 - ch = un->un_ch; 3027 - if (!ch) 3028 - return; 3029 - if (c == STOP_CHAR(tty)) 3030 - ch->ch_send |= RR_RX_STOP; 3031 - else if (c == START_CHAR(tty)) 3032 - ch->ch_send |= RR_RX_START; 3033 - 3034 - ch->ch_nd->nd_tx_ready = 1; 3035 - ch->ch_nd->nd_tx_work = 1; 3036 - 3037 - return; 3038 - } 3039 - 3040 - 3041 - static void dgrp_tty_input_start(struct tty_struct *tty) 3042 - { 3043 - struct ch_struct *ch; 3044 - 3045 - if (!tty) 3046 - return; 3047 - 3048 - ch = ((struct un_struct *) tty->driver_data)->un_ch; 3049 - if (!ch) 3050 - return; 3051 - 3052 - ch->ch_send |= RR_RX_START; 3053 - ch->ch_send &= ~RR_RX_STOP; 3054 - (ch->ch_nd)->nd_tx_ready = 1; 3055 - (ch->ch_nd)->nd_tx_work = 1; 3056 - if (waitqueue_active(&(ch->ch_nd)->nd_tx_waitq)) 3057 - wake_up_interruptible(&(ch->ch_nd)->nd_tx_waitq); 3058 - 3059 - } 3060 - 3061 - 3062 - /* 3063 - * Hangup the port. Like a close, but don't wait for output 3064 - * to drain. 3065 - * 3066 - * How do we close all the channels that are open? 3067 - */ 3068 - static void dgrp_tty_hangup(struct tty_struct *tty) 3069 - { 3070 - struct ch_struct *ch; 3071 - struct nd_struct *nd; 3072 - struct un_struct *un; 3073 - 3074 - if (!tty) 3075 - return; 3076 - 3077 - un = tty->driver_data; 3078 - if (!un) 3079 - return; 3080 - 3081 - ch = un->un_ch; 3082 - if (!ch) 3083 - return; 3084 - 3085 - nd = ch->ch_nd; 3086 - 3087 - if (C_HUPCL(tty)) { 3088 - /* LOWER DTR */ 3089 - ch->ch_mout &= ~DM_DTR; 3090 - /* Don't do this here */ 3091 - /* ch->ch_flag |= CH_HANGUP; */ 3092 - ch->ch_nd->nd_tx_ready = 1; 3093 - ch->ch_nd->nd_tx_work = 1; 3094 - if (waitqueue_active(&ch->ch_flag_wait)) 3095 - wake_up_interruptible(&ch->ch_flag_wait); 3096 - } 3097 - 3098 - } 3099 - 3100 - /************************************************************************/ 3101 - /* */ 3102 - /* TTY Initialization/Cleanup Functions */ 3103 - /* */ 3104 - /************************************************************************/ 3105 - 3106 - /* 3107 - * Uninitialize the TTY portion of the supplied node. Free all 3108 - * memory and resources associated with this node. Do it in reverse 3109 - * allocation order: this might possibly result in less fragmentation 3110 - * of memory, though I don't know this for sure. 3111 - */ 3112 - void 3113 - dgrp_tty_uninit(struct nd_struct *nd) 3114 - { 3115 - unsigned int i; 3116 - char id[3]; 3117 - 3118 - ID_TO_CHAR(nd->nd_ID, id); 3119 - 3120 - if (nd->nd_ttdriver_flags & SERIAL_TTDRV_REG) { 3121 - tty_unregister_driver(nd->nd_serial_ttdriver); 3122 - 3123 - kfree(nd->nd_serial_ttdriver->ttys); 3124 - nd->nd_serial_ttdriver->ttys = NULL; 3125 - 3126 - put_tty_driver(nd->nd_serial_ttdriver); 3127 - nd->nd_ttdriver_flags &= ~SERIAL_TTDRV_REG; 3128 - } 3129 - 3130 - if (nd->nd_ttdriver_flags & CALLOUT_TTDRV_REG) { 3131 - tty_unregister_driver(nd->nd_callout_ttdriver); 3132 - 3133 - kfree(nd->nd_callout_ttdriver->ttys); 3134 - nd->nd_callout_ttdriver->ttys = NULL; 3135 - 3136 - put_tty_driver(nd->nd_callout_ttdriver); 3137 - nd->nd_ttdriver_flags &= ~CALLOUT_TTDRV_REG; 3138 - } 3139 - 3140 - if (nd->nd_ttdriver_flags & XPRINT_TTDRV_REG) { 3141 - tty_unregister_driver(nd->nd_xprint_ttdriver); 3142 - 3143 - kfree(nd->nd_xprint_ttdriver->ttys); 3144 - nd->nd_xprint_ttdriver->ttys = NULL; 3145 - 3146 - put_tty_driver(nd->nd_xprint_ttdriver); 3147 - nd->nd_ttdriver_flags &= ~XPRINT_TTDRV_REG; 3148 - } 3149 - for (i = 0; i < CHAN_MAX; i++) 3150 - tty_port_destroy(&nd->nd_chan[i].port); 3151 - } 3152 - 3153 - 3154 - 3155 - /* 3156 - * Initialize the TTY portion of the supplied node. 3157 - */ 3158 - int 3159 - dgrp_tty_init(struct nd_struct *nd) 3160 - { 3161 - char id[3]; 3162 - int rc; 3163 - int i; 3164 - 3165 - ID_TO_CHAR(nd->nd_ID, id); 3166 - 3167 - /* 3168 - * Initialize the TTDRIVER structures. 3169 - */ 3170 - 3171 - nd->nd_serial_ttdriver = alloc_tty_driver(CHAN_MAX); 3172 - if (!nd->nd_serial_ttdriver) 3173 - return -ENOMEM; 3174 - 3175 - sprintf(nd->nd_serial_name, "tty_dgrp_%s_", id); 3176 - 3177 - nd->nd_serial_ttdriver->owner = THIS_MODULE; 3178 - nd->nd_serial_ttdriver->name = nd->nd_serial_name; 3179 - nd->nd_serial_ttdriver->name_base = 0; 3180 - nd->nd_serial_ttdriver->major = 0; 3181 - nd->nd_serial_ttdriver->minor_start = 0; 3182 - nd->nd_serial_ttdriver->type = TTY_DRIVER_TYPE_SERIAL; 3183 - nd->nd_serial_ttdriver->subtype = SERIAL_TYPE_NORMAL; 3184 - nd->nd_serial_ttdriver->init_termios = DefaultTermios; 3185 - nd->nd_serial_ttdriver->driver_name = "dgrp"; 3186 - nd->nd_serial_ttdriver->flags = (TTY_DRIVER_REAL_RAW | 3187 - TTY_DRIVER_DYNAMIC_DEV | 3188 - TTY_DRIVER_HARDWARE_BREAK); 3189 - 3190 - /* The kernel wants space to store pointers to tty_structs. */ 3191 - nd->nd_serial_ttdriver->ttys = 3192 - kzalloc(CHAN_MAX * sizeof(struct tty_struct *), GFP_KERNEL); 3193 - if (!nd->nd_serial_ttdriver->ttys) 3194 - return -ENOMEM; 3195 - 3196 - tty_set_operations(nd->nd_serial_ttdriver, &dgrp_tty_ops); 3197 - 3198 - if (!(nd->nd_ttdriver_flags & SERIAL_TTDRV_REG)) { 3199 - /* 3200 - * Register tty devices 3201 - */ 3202 - rc = tty_register_driver(nd->nd_serial_ttdriver); 3203 - if (rc < 0) { 3204 - /* 3205 - * If errno is EBUSY, this means there are no more 3206 - * slots available to have us auto-majored. 3207 - * (Which is currently supported up to 256) 3208 - * 3209 - * We can still request majors above 256, 3210 - * we just have to do it manually. 3211 - */ 3212 - if (rc == -EBUSY) { 3213 - int i; 3214 - int max_majors = 1U << (32 - MINORBITS); 3215 - for (i = 256; i < max_majors; i++) { 3216 - nd->nd_serial_ttdriver->major = i; 3217 - rc = tty_register_driver 3218 - (nd->nd_serial_ttdriver); 3219 - if (rc >= 0) 3220 - break; 3221 - } 3222 - /* Really fail now, since we ran out 3223 - * of majors to try. */ 3224 - if (i == max_majors) 3225 - return rc; 3226 - 3227 - } else { 3228 - return rc; 3229 - } 3230 - } 3231 - nd->nd_ttdriver_flags |= SERIAL_TTDRV_REG; 3232 - } 3233 - 3234 - nd->nd_callout_ttdriver = alloc_tty_driver(CHAN_MAX); 3235 - if (!nd->nd_callout_ttdriver) 3236 - return -ENOMEM; 3237 - 3238 - sprintf(nd->nd_callout_name, "cu_dgrp_%s_", id); 3239 - 3240 - nd->nd_callout_ttdriver->owner = THIS_MODULE; 3241 - nd->nd_callout_ttdriver->name = nd->nd_callout_name; 3242 - nd->nd_callout_ttdriver->name_base = 0; 3243 - nd->nd_callout_ttdriver->major = nd->nd_serial_ttdriver->major; 3244 - nd->nd_callout_ttdriver->minor_start = 0x40; 3245 - nd->nd_callout_ttdriver->type = TTY_DRIVER_TYPE_SERIAL; 3246 - nd->nd_callout_ttdriver->subtype = SERIAL_TYPE_CALLOUT; 3247 - nd->nd_callout_ttdriver->init_termios = DefaultTermios; 3248 - nd->nd_callout_ttdriver->driver_name = "dgrp"; 3249 - nd->nd_callout_ttdriver->flags = (TTY_DRIVER_REAL_RAW | 3250 - TTY_DRIVER_DYNAMIC_DEV | 3251 - TTY_DRIVER_HARDWARE_BREAK); 3252 - 3253 - /* The kernel wants space to store pointers to tty_structs. */ 3254 - nd->nd_callout_ttdriver->ttys = 3255 - kzalloc(CHAN_MAX * sizeof(struct tty_struct *), GFP_KERNEL); 3256 - if (!nd->nd_callout_ttdriver->ttys) 3257 - return -ENOMEM; 3258 - 3259 - tty_set_operations(nd->nd_callout_ttdriver, &dgrp_tty_ops); 3260 - 3261 - if (dgrp_register_cudevices) { 3262 - if (!(nd->nd_ttdriver_flags & CALLOUT_TTDRV_REG)) { 3263 - /* 3264 - * Register cu devices 3265 - */ 3266 - rc = tty_register_driver(nd->nd_callout_ttdriver); 3267 - if (rc < 0) 3268 - return rc; 3269 - nd->nd_ttdriver_flags |= CALLOUT_TTDRV_REG; 3270 - } 3271 - } 3272 - 3273 - 3274 - nd->nd_xprint_ttdriver = alloc_tty_driver(CHAN_MAX); 3275 - if (!nd->nd_xprint_ttdriver) 3276 - return -ENOMEM; 3277 - 3278 - sprintf(nd->nd_xprint_name, "pr_dgrp_%s_", id); 3279 - 3280 - nd->nd_xprint_ttdriver->owner = THIS_MODULE; 3281 - nd->nd_xprint_ttdriver->name = nd->nd_xprint_name; 3282 - nd->nd_xprint_ttdriver->name_base = 0; 3283 - nd->nd_xprint_ttdriver->major = nd->nd_serial_ttdriver->major; 3284 - nd->nd_xprint_ttdriver->minor_start = 0x80; 3285 - nd->nd_xprint_ttdriver->type = TTY_DRIVER_TYPE_SERIAL; 3286 - nd->nd_xprint_ttdriver->subtype = SERIAL_TYPE_XPRINT; 3287 - nd->nd_xprint_ttdriver->init_termios = DefaultTermios; 3288 - nd->nd_xprint_ttdriver->driver_name = "dgrp"; 3289 - nd->nd_xprint_ttdriver->flags = (TTY_DRIVER_REAL_RAW | 3290 - TTY_DRIVER_DYNAMIC_DEV | 3291 - TTY_DRIVER_HARDWARE_BREAK); 3292 - 3293 - /* The kernel wants space to store pointers to tty_structs. */ 3294 - nd->nd_xprint_ttdriver->ttys = 3295 - kzalloc(CHAN_MAX * sizeof(struct tty_struct *), GFP_KERNEL); 3296 - if (!nd->nd_xprint_ttdriver->ttys) 3297 - return -ENOMEM; 3298 - 3299 - tty_set_operations(nd->nd_xprint_ttdriver, &dgrp_tty_ops); 3300 - 3301 - if (dgrp_register_prdevices) { 3302 - if (!(nd->nd_ttdriver_flags & XPRINT_TTDRV_REG)) { 3303 - /* 3304 - * Register transparent print devices 3305 - */ 3306 - rc = tty_register_driver(nd->nd_xprint_ttdriver); 3307 - if (rc < 0) 3308 - return rc; 3309 - nd->nd_ttdriver_flags |= XPRINT_TTDRV_REG; 3310 - } 3311 - } 3312 - 3313 - for (i = 0; i < CHAN_MAX; i++) { 3314 - struct ch_struct *ch = nd->nd_chan + i; 3315 - 3316 - ch->ch_nd = nd; 3317 - ch->ch_digi = digi_init; 3318 - ch->ch_edelay = 100; 3319 - ch->ch_custom_speed = 0; 3320 - ch->ch_portnum = i; 3321 - ch->ch_tun.un_ch = ch; 3322 - ch->ch_pun.un_ch = ch; 3323 - ch->ch_tun.un_type = SERIAL_TYPE_NORMAL; 3324 - ch->ch_pun.un_type = SERIAL_TYPE_XPRINT; 3325 - 3326 - init_waitqueue_head(&(ch->ch_flag_wait)); 3327 - init_waitqueue_head(&(ch->ch_sleep)); 3328 - 3329 - init_waitqueue_head(&(ch->ch_tun.un_open_wait)); 3330 - init_waitqueue_head(&(ch->ch_tun.un_close_wait)); 3331 - 3332 - init_waitqueue_head(&(ch->ch_pun.un_open_wait)); 3333 - init_waitqueue_head(&(ch->ch_pun.un_close_wait)); 3334 - tty_port_init(&ch->port); 3335 - } 3336 - return 0; 3337 - }
-129
drivers/staging/dgrp/digirp.h
··· 1 - /************************************************************************ 2 - * HP-UX Realport Daemon interface file. 3 - * 4 - * Copyright (C) 1998, by Digi International. All Rights Reserved. 5 - ************************************************************************/ 6 - 7 - #ifndef _DIGIDRP_H 8 - #define _DIGIDRP_H 9 - 10 - /************************************************************************ 11 - * This file contains defines for the ioctl() interface to 12 - * the realport driver. This ioctl() interface is used by the 13 - * daemon to set speed setup parameters honored by the driver. 14 - ************************************************************************/ 15 - 16 - struct link_struct { 17 - int lk_fast_rate; /* Fast line rate to be used 18 - when the delay is less-equal 19 - to lk_fast_delay */ 20 - 21 - int lk_fast_delay; /* Fast line rate delay in 22 - milliseconds */ 23 - 24 - int lk_slow_rate; /* Slow line rate to be used when 25 - the delay is greater-equal 26 - to lk_slow_delay */ 27 - 28 - int lk_slow_delay; /* Slow line rate delay in 29 - milliseconds */ 30 - 31 - int lk_header_size; /* Estimated packet header size 32 - when sent across the slowest 33 - link. */ 34 - }; 35 - 36 - #define DIGI_GETLINK _IOW('e', 103, struct link_struct) /* Get link parameters */ 37 - #define DIGI_SETLINK _IOW('e', 104, struct link_struct) /* Set link parameters */ 38 - 39 - 40 - /************************************************************************ 41 - * This module provides application access to special Digi 42 - * serial line enhancements which are not standard UNIX(tm) features. 43 - ************************************************************************/ 44 - 45 - struct digiflow_struct { 46 - unsigned char startc; /* flow cntl start char */ 47 - unsigned char stopc; /* flow cntl stop char */ 48 - }; 49 - 50 - /************************************************************************ 51 - * Values for digi_flags 52 - ************************************************************************/ 53 - #define DIGI_IXON 0x0001 /* Handle IXON in the FEP */ 54 - #define DIGI_FAST 0x0002 /* Fast baud rates */ 55 - #define RTSPACE 0x0004 /* RTS input flow control */ 56 - #define CTSPACE 0x0008 /* CTS output flow control */ 57 - #define DSRPACE 0x0010 /* DSR output flow control */ 58 - #define DCDPACE 0x0020 /* DCD output flow control */ 59 - #define DTRPACE 0x0040 /* DTR input flow control */ 60 - #define DIGI_COOK 0x0080 /* Cooked processing done in FEP */ 61 - #define DIGI_FORCEDCD 0x0100 /* Force carrier */ 62 - #define DIGI_ALTPIN 0x0200 /* Alternate RJ-45 pin config */ 63 - #define DIGI_AIXON 0x0400 /* Aux flow control in fep */ 64 - #define DIGI_PRINTER 0x0800 /* Hold port open for flow cntrl */ 65 - #define DIGI_PP_INPUT 0x1000 /* Change parallel port to input */ 66 - #define DIGI_422 0x4000 /* Change parallel port to input */ 67 - #define DIGI_RTS_TOGGLE 0x8000 /* Support RTS Toggle */ 68 - 69 - 70 - /************************************************************************ 71 - * Values associated with transparent print 72 - ************************************************************************/ 73 - #define DIGI_PLEN 8 /* String length */ 74 - #define DIGI_TSIZ 10 /* Terminal string len */ 75 - 76 - 77 - /************************************************************************ 78 - * Structure used with ioctl commands for DIGI parameters. 79 - ************************************************************************/ 80 - struct digi_struct { 81 - unsigned short digi_flags; /* Flags (see above) */ 82 - unsigned short digi_maxcps; /* Max printer CPS */ 83 - unsigned short digi_maxchar; /* Max chars in print queue */ 84 - unsigned short digi_bufsize; /* Buffer size */ 85 - unsigned char digi_onlen; /* Length of ON string */ 86 - unsigned char digi_offlen; /* Length of OFF string */ 87 - char digi_onstr[DIGI_PLEN]; /* Printer on string */ 88 - char digi_offstr[DIGI_PLEN]; /* Printer off string */ 89 - char digi_term[DIGI_TSIZ]; /* terminal string */ 90 - }; 91 - 92 - /************************************************************************ 93 - * Ioctl command arguments for DIGI parameters. 94 - ************************************************************************/ 95 - /* Read params */ 96 - #define DIGI_GETA _IOR('e', 94, struct digi_struct) 97 - 98 - /* Set params */ 99 - #define DIGI_SETA _IOW('e', 95, struct digi_struct) 100 - 101 - /* Drain & set params */ 102 - #define DIGI_SETAW _IOW('e', 96, struct digi_struct) 103 - 104 - /* Drain, flush & set params */ 105 - #define DIGI_SETAF _IOW('e', 97, struct digi_struct) 106 - 107 - /* Get startc/stopc flow control characters */ 108 - #define DIGI_GETFLOW _IOR('e', 99, struct digiflow_struct) 109 - 110 - /* Set startc/stopc flow control characters */ 111 - #define DIGI_SETFLOW _IOW('e', 100, struct digiflow_struct) 112 - 113 - /* Get Aux. startc/stopc flow control chars */ 114 - #define DIGI_GETAFLOW _IOR('e', 101, struct digiflow_struct) 115 - 116 - /* Set Aux. startc/stopc flow control chars */ 117 - #define DIGI_SETAFLOW _IOW('e', 102, struct digiflow_struct) 118 - 119 - /* Set integer baud rate */ 120 - #define DIGI_SETCUSTOMBAUD _IOW('e', 106, int) 121 - 122 - /* Get integer baud rate */ 123 - #define DIGI_GETCUSTOMBAUD _IOR('e', 107, int) 124 - 125 - #define DIGI_GEDELAY _IOR('d', 246, int) /* Get edelay */ 126 - #define DIGI_SEDELAY _IOW('d', 247, int) /* Get edelay */ 127 - 128 - 129 - #endif /* _DIGIDRP_H */
-693
drivers/staging/dgrp/drp.h
··· 1 - /* 2 - * 3 - * Copyright 1999 Digi International (www.digi.com) 4 - * Gene Olson <gene at digi dot com> 5 - * James Puzzo <jamesp at digi dot com> 6 - * Scott Kilau <scottk at digi dot com> 7 - * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2, or (at your option) 11 - * any later version. 12 - * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the 15 - * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 - * PURPOSE. See the GNU General Public License for more details. 17 - * 18 - */ 19 - 20 - /************************************************************************ 21 - * Master include file for Linux Realport Driver. 22 - ************************************************************************/ 23 - 24 - #ifndef __DRP_H 25 - #define __DRP_H 26 - 27 - #include <linux/types.h> 28 - #include <linux/wait.h> 29 - #include <linux/semaphore.h> 30 - #include <linux/tty.h> 31 - 32 - 33 - #include "digirp.h" 34 - 35 - /************************************************************************ 36 - * Tuning parameters. 37 - ************************************************************************/ 38 - 39 - #define CHAN_MAX 64 /* Max # ports per server */ 40 - 41 - #define SEQ_MAX 128 /* Max # transmit sequences (2^n) */ 42 - #define SEQ_MASK (SEQ_MAX-1) /* Sequence buffer modulus mask */ 43 - 44 - #define TBUF_MAX 4096 /* Size of transmit buffer (2^n) */ 45 - #define RBUF_MAX 4096 /* Size of receive buffer (2^n) */ 46 - 47 - #define TBUF_MASK (TBUF_MAX-1) /* Transmit buffer modulus mask */ 48 - #define RBUF_MASK (RBUF_MAX-1) /* Receive buffer modulus mask */ 49 - 50 - #define TBUF_LOW 1000 /* Transmit low water mark */ 51 - 52 - #define UIO_BASE 1000 /* Base for write operations */ 53 - #define UIO_MIN 2000 /* Minimum size application buffer */ 54 - #define UIO_MAX 8100 /* Unix I/O buffer size */ 55 - 56 - #define MON_MAX 65536 /* Monitor buffer size (2^n) */ 57 - #define MON_MASK (MON_MAX-1) /* Monitor wrap mask */ 58 - 59 - #define DPA_MAX 65536 /* DPA buffer size (2^n) */ 60 - #define DPA_MASK (DPA_MAX-1) /* DPA wrap mask */ 61 - #define DPA_HIGH_WATER 58000 /* Enforce flow control when 62 - * over this amount 63 - */ 64 - 65 - #define IDLE_MAX (20 * HZ) /* Max TCP link idle time */ 66 - 67 - #define MAX_DESC_LEN 100 /* Maximum length of stored PS 68 - * description 69 - */ 70 - 71 - #define WRITEBUFLEN ((4096) + 4) /* 4 extra for alignment play space */ 72 - 73 - #define VPDSIZE 512 74 - 75 - /************************************************************************ 76 - * Minor device decoding conventions. 77 - ************************************************************************ 78 - * 79 - * For Linux, the net and mon devices are handled via "proc", so we 80 - * only have to mux the "tty" devices. Since every PortServer will 81 - * have an individual major number, the PortServer number does not 82 - * need to be encoded, and in fact, does not need to exist. 83 - * 84 - */ 85 - 86 - /* 87 - * Port device decoding conventions: 88 - * 89 - * Device 00 - 3f 64 dial-in modem devices. (tty) 90 - * Device 40 - 7f 64 dial-out tty devices. (cu) 91 - * Device 80 - bf 64 dial-out printer devices. 92 - * 93 - * IS_PRINT(dev) This is a printer device. 94 - * 95 - * OPEN_CATEGORY(dev) Specifies the device category. No two 96 - * devices of different categories may be open 97 - * at the same time. 98 - * 99 - * The following require the category returned by OPEN_CATEGORY(). 100 - * 101 - * OPEN_WAIT_AVAIL(cat) Waits on open until the device becomes 102 - * available. Fails if NDELAY specified. 103 - * 104 - * OPEN_WAIT_CARRIER(cat) Waits on open if carrier is not present. 105 - * Succeeds if NDELAY is given. 106 - * 107 - * OPEN_FORCES_CARRIER(cat) Carrier is forced high on open. 108 - * 109 - */ 110 - 111 - #define PORT_NUM(dev) ((dev) & 0x3f) 112 - 113 - #define OPEN_CATEGORY(dev) ((((dev) & 0x80) & 0x40)) 114 - #define IS_PRINT(dev) (((dev) & 0xff) >= 0x80) 115 - 116 - #define OPEN_WAIT_AVAIL(cat) (((cat) & 0x40) == 0x000) 117 - #define OPEN_WAIT_CARRIER(cat) (((cat) & 0x40) == 0x000) 118 - #define OPEN_FORCES_CARRIER(cat) (((cat) & 0x40) != 0x000) 119 - 120 - 121 - /************************************************************************ 122 - * Modem signal defines for 16450/16550 compatible FEP. 123 - * set in ch_mout, ch_mflow, ch_mlast etc 124 - ************************************************************************/ 125 - 126 - /* TODO : Re-verify that these modem signal definitions are correct */ 127 - 128 - #define DM_DTR 0x01 129 - #define DM_RTS 0x02 130 - #define DM_RTS_TOGGLE 0x04 131 - 132 - #define DM_OUT1 0x04 133 - #define DM_OUT2 0x08 134 - 135 - #define DM_CTS 0x10 136 - #define DM_DSR 0x20 137 - #define DM_RI 0x40 138 - #define DM_CD 0x80 /* This is the DCD flag */ 139 - 140 - 141 - /************************************************************************ 142 - * Realport Event Flags. 143 - ************************************************************************/ 144 - 145 - #define EV_OPU 0x0001 /* Ouput paused by client */ 146 - #define EV_OPS 0x0002 /* Output paused by XOFF */ 147 - #define EV_OPX 0x0004 /* Output paused by XXOFF */ 148 - #define EV_OPH 0x0008 /* Output paused by MFLOW */ 149 - #define EV_IPU 0x0010 /* Input paused by client */ 150 - #define EV_IPS 0x0020 /* Input paused by hi/low water */ 151 - #define EV_TXB 0x0040 /* Transmit break pending */ 152 - #define EV_TXI 0x0080 /* Transmit immediate pending */ 153 - #define EV_TXF 0x0100 /* Transmit flow control pending */ 154 - #define EV_RXB 0x0200 /* Break received */ 155 - 156 - 157 - /************************************************************************ 158 - * Realport CFLAGS. 159 - ************************************************************************/ 160 - 161 - #define CF_CS5 0x0000 /* 5 bit characters */ 162 - #define CF_CS6 0x0010 /* 6 bit characters */ 163 - #define CF_CS7 0x0020 /* 7 bit characters */ 164 - #define CF_CS8 0x0030 /* 8 bit characters */ 165 - #define CF_CSIZE 0x0030 /* Character size */ 166 - #define CF_CSTOPB 0x0040 /* Two stop bits */ 167 - #define CF_CREAD 0x0080 /* Enable receiver */ 168 - #define CF_PARENB 0x0100 /* Enable parity */ 169 - #define CF_PARODD 0x0200 /* Odd parity */ 170 - #define CF_HUPCL 0x0400 /* Drop DTR on close */ 171 - 172 - 173 - /************************************************************************ 174 - * Realport XFLAGS. 175 - ************************************************************************/ 176 - 177 - #define XF_XPAR 0x0001 /* Enable Mark/Space Parity */ 178 - #define XF_XMODEM 0x0002 /* Enable in-band modem signalling */ 179 - #define XF_XCASE 0x0004 /* Convert special characters */ 180 - #define XF_XEDATA 0x0008 /* Error data in stream */ 181 - #define XF_XTOSS 0x0010 /* Toss IXANY characters */ 182 - #define XF_XIXON 0x0020 /* xxon/xxoff enable */ 183 - 184 - 185 - /************************************************************************ 186 - * Realport IFLAGS. 187 - ************************************************************************/ 188 - 189 - #define IF_IGNBRK 0x0001 /* Ignore input break */ 190 - #define IF_BRKINT 0x0002 /* Break interrupt */ 191 - #define IF_IGNPAR 0x0004 /* Ignore error characters */ 192 - #define IF_PARMRK 0x0008 /* Error chars marked with 0xff */ 193 - #define IF_INPCK 0x0010 /* Input parity checking enabled */ 194 - #define IF_ISTRIP 0x0020 /* Input chars masked with 0x7F */ 195 - #define IF_IXON 0x0400 /* Output software flow control */ 196 - #define IF_IXANY 0x0800 /* Restart output on any char */ 197 - #define IF_IXOFF 0x1000 /* Input software flow control */ 198 - #define IF_DOSMODE 0x8000 /* 16450-compatible errors */ 199 - 200 - 201 - /************************************************************************ 202 - * Realport OFLAGS. 203 - ************************************************************************/ 204 - 205 - #define OF_OLCUC 0x0002 /* Map lower to upper case */ 206 - #define OF_ONLCR 0x0004 /* Map NL to CR-NL */ 207 - #define OF_OCRNL 0x0008 /* Map CR to NL */ 208 - #define OF_ONOCR 0x0010 /* No CR output at column 0 */ 209 - #define OF_ONLRET 0x0020 /* Assume NL does NL/CR */ 210 - #define OF_TAB3 0x1800 /* Tabs expand to 8 spaces */ 211 - #define OF_TABDLY 0x1800 /* Tab delay */ 212 - 213 - /************************************************************************ 214 - * Unit flag definitions for un_flag. 215 - ************************************************************************/ 216 - 217 - /* These are the DIGI unit flags */ 218 - #define UN_EXCL 0x00010000 /* Exclusive open */ 219 - #define UN_STICKY 0x00020000 /* TTY Settings are now sticky */ 220 - #define UN_BUSY 0x00040000 /* Some work this channel */ 221 - #define UN_PWAIT 0x00080000 /* Printer waiting for terminal */ 222 - #define UN_TIME 0x00100000 /* Waiting on time */ 223 - #define UN_EMPTY 0x00200000 /* Waiting output queue empty */ 224 - #define UN_LOW 0x00400000 /* Waiting output low water */ 225 - #define UN_DIGI_MASK 0x00FF0000 /* Waiting output low water */ 226 - 227 - /* 228 - * Definitions for async_struct (and serial_struct) flags field 229 - * 230 - * these are the ASYNC flags copied from serial.h 231 - * 232 - */ 233 - #define UN_HUP_NOTIFY 0x0001 /* Notify getty on hangups and 234 - * closes on the callout port 235 - */ 236 - #define UN_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */ 237 - #define UN_SAK 0x0004 /* Secure Attention Key (Orange book) */ 238 - #define UN_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */ 239 - 240 - #define UN_SPD_MASK 0x0030 241 - #define UN_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */ 242 - #define UN_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */ 243 - #define UN_SPD_CUST 0x0030 /* Use user-specified divisor */ 244 - 245 - #define UN_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */ 246 - #define UN_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */ 247 - 248 - #define UN_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */ 249 - #define UN_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */ 250 - #define UN_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */ 251 - 252 - #define UN_FLAGS 0x0FFF /* Possible legal async flags */ 253 - #define UN_USR_MASK 0x0430 /* Legal flags that non-privileged 254 - * users can set or reset 255 - */ 256 - 257 - #define UN_INITIALIZED 0x80000000 /* Serial port was initialized */ 258 - #define UN_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */ 259 - #define UN_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ 260 - #define UN_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ 261 - #define UN_CLOSING 0x08000000 /* Serial port is closing */ 262 - #define UN_CTS_FLOW 0x04000000 /* Do CTS flow control */ 263 - #define UN_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 264 - #define UN_SHARE_IRQ 0x01000000 /* for multifunction cards */ 265 - 266 - 267 - /************************************************************************ 268 - * Structure for terminal or printer unit. struct un_struct 269 - * 270 - * Note that in some places the code assumes the "tty_t" is placed 271 - * first in the structure. 272 - ************************************************************************/ 273 - 274 - struct un_struct { 275 - struct tty_struct *un_tty; /* System TTY struct */ 276 - struct ch_struct *un_ch; /* Associated channel */ 277 - 278 - ushort un_open_count; /* Successful open count */ 279 - int un_flag; /* Unit flags */ 280 - ushort un_tbusy; /* Busy transmit count */ 281 - 282 - wait_queue_head_t un_open_wait; 283 - wait_queue_head_t un_close_wait; 284 - ushort un_type; 285 - struct device *un_sysfs; 286 - }; 287 - 288 - 289 - /************************************************************************ 290 - * Channel State Numbers for ch_state. 291 - ************************************************************************/ 292 - 293 - /* 294 - * The ordering is important. 295 - * 296 - * state <= CS_WAIT_CANCEL implies the channel is definitely closed. 297 - * 298 - * state >= CS_WAIT_FAIL implies the channel is definitely open. 299 - * 300 - * state >= CS_READY implies data is allowed on the channel. 301 - */ 302 - 303 - enum dgrp_ch_state_t { 304 - CS_IDLE = 0, /* Channel is idle */ 305 - CS_WAIT_OPEN = 1, /* Waiting for Immediate Open Resp */ 306 - CS_WAIT_CANCEL = 2, /* Waiting for Per/Incom Cancel Resp */ 307 - CS_WAIT_FAIL = 3, /* Waiting for Immed Open Failure */ 308 - CS_SEND_QUERY = 4, /* Ready to send Port Query */ 309 - CS_WAIT_QUERY = 5, /* Waiting for Port Query Response */ 310 - CS_READY = 6, /* Ready to accept commands and data */ 311 - CS_SEND_CLOSE = 7, /* Ready to send Close Request */ 312 - CS_WAIT_CLOSE = 8 /* Waiting for Close Response */ 313 - }; 314 - 315 - /************************************************************************ 316 - * Device flag definitions for ch_flag. 317 - ************************************************************************/ 318 - 319 - /* 320 - * Note that the state of the two carrier based flags is key. When 321 - * we check for carrier state transitions, we look at the current 322 - * physical state of the DCD line and compare it with PHYS_CD (which 323 - * was the state the last time we checked), and we also determine 324 - * a new virtual state (composite of the physical state, FORCEDCD, 325 - * CLOCAL, etc.) and compare it with VIRT_CD. 326 - * 327 - * VIRTUAL transitions high will have the side effect of waking blocked 328 - * opens. 329 - * 330 - * PHYSICAL transitions low will cause hangups to occur _IF_ the virtual 331 - * state is also low. We DON'T want to hangup on a PURE virtual drop. 332 - */ 333 - 334 - #define CH_HANGUP 0x00002 /* Server port ready to close */ 335 - 336 - #define CH_VIRT_CD 0x00004 /* Carrier was virtually present */ 337 - #define CH_PHYS_CD 0x00008 /* Carrier was physically present */ 338 - 339 - #define CH_CLOCAL 0x00010 /* CLOCAL set in cflags */ 340 - #define CH_BAUD0 0x00020 /* Baud rate zero hangup */ 341 - 342 - #define CH_FAST_READ 0x00040 /* Fast reads are enabled */ 343 - #define CH_FAST_WRITE 0x00080 /* Fast writes are enabled */ 344 - 345 - #define CH_PRON 0x00100 /* Printer on string active */ 346 - #define CH_RX_FLUSH 0x00200 /* Flushing receive data */ 347 - #define CH_LOW 0x00400 /* Thread waiting for LOW water */ 348 - #define CH_EMPTY 0x00800 /* Thread waiting for EMPTY */ 349 - #define CH_DRAIN 0x01000 /* Close is waiting to drain */ 350 - #define CH_INPUT 0x02000 /* Thread waiting for INPUT */ 351 - #define CH_RXSTOP 0x04000 /* Stop output to ldisc */ 352 - #define CH_PARAM 0x08000 /* A parameter was updated */ 353 - #define CH_WAITING_SYNC 0x10000 /* A pending sync was assigned 354 - * to this port. 355 - */ 356 - #define CH_PORT_GONE 0x20000 /* Port has disappeared */ 357 - #define CH_TX_BREAK 0x40000 /* TX Break to be sent, 358 - * but has not yet. 359 - */ 360 - 361 - /************************************************************************ 362 - * Types of Open Requests for ch_otype. 363 - ************************************************************************/ 364 - 365 - #define OTYPE_IMMEDIATE 0 /* Immediate Open */ 366 - #define OTYPE_PERSISTENT 1 /* Persistent Open */ 367 - #define OTYPE_INCOMING 2 /* Incoming Open */ 368 - 369 - 370 - /************************************************************************ 371 - * Request/Response flags. 372 - ************************************************************************/ 373 - 374 - #define RR_SEQUENCE 0x0001 /* Get server RLAST, TIN */ 375 - #define RR_STATUS 0x0002 /* Get server MINT, EINT */ 376 - #define RR_BUFFER 0x0004 /* Get server RSIZE, TSIZE */ 377 - #define RR_CAPABILITY 0x0008 /* Get server port capabilities */ 378 - 379 - #define RR_TX_FLUSH 0x0040 /* Flush output buffers */ 380 - #define RR_RX_FLUSH 0x0080 /* Flush input buffers */ 381 - 382 - #define RR_TX_STOP 0x0100 /* Pause output */ 383 - #define RR_RX_STOP 0x0200 /* Pause input */ 384 - #define RR_TX_START 0x0400 /* Start output */ 385 - #define RR_RX_START 0x0800 /* Start input */ 386 - 387 - #define RR_TX_BREAK 0x1000 /* Send BREAK */ 388 - #define RR_TX_ICHAR 0x2000 /* Send character immediate */ 389 - 390 - 391 - /************************************************************************ 392 - * Channel information structure. struct ch_struct 393 - ************************************************************************/ 394 - 395 - struct ch_struct { 396 - struct digi_struct ch_digi; /* Digi variables */ 397 - int ch_edelay; /* Digi edelay */ 398 - 399 - struct tty_port port; 400 - struct un_struct ch_tun; /* Terminal unit info */ 401 - struct un_struct ch_pun; /* Printer unit info */ 402 - 403 - struct nd_struct *ch_nd; /* Node pointer */ 404 - u8 *ch_tbuf; /* Local Transmit Buffer */ 405 - u8 *ch_rbuf; /* Local Receive Buffer */ 406 - ulong ch_cpstime; /* Printer CPS time */ 407 - ulong ch_waketime; /* Printer wake time */ 408 - 409 - ulong ch_flag; /* CH_* flags */ 410 - 411 - enum dgrp_ch_state_t ch_state; /* CS_* Protocol state */ 412 - ushort ch_send; /* Bit vector of RR_* requests */ 413 - ushort ch_expect; /* Bit vector of RR_* responses */ 414 - ushort ch_wait_carrier; /* Thread count waiting for carrier */ 415 - ushort ch_wait_count[3]; /* Thread count waiting by otype */ 416 - 417 - ushort ch_portnum; /* Port number */ 418 - ushort ch_open_count; /* Successful open count */ 419 - ushort ch_category; /* Device category */ 420 - ushort ch_open_error; /* Last open error number */ 421 - ushort ch_break_time; /* Pending break request time */ 422 - ushort ch_cpsrem; /* Printer CPS remainder */ 423 - ushort ch_ocook; /* Realport fastcook oflags */ 424 - ushort ch_inwait; /* Thread count in CLIST input */ 425 - 426 - ushort ch_tin; /* Local transmit buffer in ptr */ 427 - ushort ch_tout; /* Local transmit buffer out ptr */ 428 - ushort ch_s_tin; /* Realport TIN */ 429 - ushort ch_s_tpos; /* Realport TPOS */ 430 - ushort ch_s_tsize; /* Realport TSIZE */ 431 - ushort ch_s_treq; /* Realport TREQ */ 432 - ushort ch_s_elast; /* Realport ELAST */ 433 - 434 - ushort ch_rin; /* Local receive buffer in ptr */ 435 - ushort ch_rout; /* Local receive buffer out ptr */ 436 - ushort ch_s_rin; /* Realport RIN */ 437 - /* David Fries 7-13-2001, ch_s_rin should be renamed ch_s_rout because 438 - * the variable we want to represent is the PortServer's ROUT, which is 439 - * the sequence number for the next byte the PortServer will send us. 440 - * RIN is the sequence number for the next byte the PortServer will 441 - * receive from the uart. The port server will send data as long as 442 - * ROUT is less than RWIN. What would happen is the port is opened, it 443 - * receives data, it gives the value of RIN, we set the RWIN to 444 - * RIN+RBUF_MAX-1, it sends us RWIN-ROUT bytes which overflows. ROUT 445 - * is set to zero when the port is opened, so we start at zero and 446 - * count up as data is received. 447 - */ 448 - ushort ch_s_rwin; /* Realport RWIN */ 449 - ushort ch_s_rsize; /* Realport RSIZE */ 450 - 451 - ushort ch_tmax; /* Local TMAX */ 452 - ushort ch_ttime; /* Local TTIME */ 453 - ushort ch_rmax; /* Local RMAX */ 454 - ushort ch_rtime; /* Local RTIME */ 455 - ushort ch_rlow; /* Local RLOW */ 456 - ushort ch_rhigh; /* Local RHIGH */ 457 - 458 - ushort ch_s_tmax; /* Realport TMAX */ 459 - ushort ch_s_ttime; /* Realport TTIME */ 460 - ushort ch_s_rmax; /* Realport RMAX */ 461 - ushort ch_s_rtime; /* Realport RTIME */ 462 - ushort ch_s_rlow; /* Realport RLOW */ 463 - ushort ch_s_rhigh; /* Realport RHIGH */ 464 - 465 - ushort ch_brate; /* Local baud rate */ 466 - ushort ch_cflag; /* Local tty cflags */ 467 - ushort ch_iflag; /* Local tty iflags */ 468 - ushort ch_oflag; /* Local tty oflags */ 469 - ushort ch_xflag; /* Local tty xflags */ 470 - 471 - ushort ch_s_brate; /* Realport BRATE */ 472 - ushort ch_s_cflag; /* Realport CFLAG */ 473 - ushort ch_s_iflag; /* Realport IFLAG */ 474 - ushort ch_s_oflag; /* Realport OFLAG */ 475 - ushort ch_s_xflag; /* Realport XFLAG */ 476 - 477 - u8 ch_otype; /* Open request type */ 478 - u8 ch_pscan_savechar; /* Last character read by parity scan */ 479 - u8 ch_pscan_state; /* PScan State based on last 2 chars */ 480 - u8 ch_otype_waiting; /* Type of open pending in server */ 481 - u8 ch_flush_seq; /* Receive flush end sequence */ 482 - u8 ch_s_mlast; /* Realport MLAST */ 483 - 484 - u8 ch_mout; /* Local MOUT */ 485 - u8 ch_mflow; /* Local MFLOW */ 486 - u8 ch_mctrl; /* Local MCTRL */ 487 - u8 ch_xon; /* Local XON */ 488 - u8 ch_xoff; /* Local XOFF */ 489 - u8 ch_lnext; /* Local LNEXT */ 490 - u8 ch_xxon; /* Local XXON */ 491 - u8 ch_xxoff; /* Local XXOFF */ 492 - 493 - u8 ch_s_mout; /* Realport MOUT */ 494 - u8 ch_s_mflow; /* Realport MFLOW */ 495 - u8 ch_s_mctrl; /* Realport MCTRL */ 496 - u8 ch_s_xon; /* Realport XON */ 497 - u8 ch_s_xoff; /* Realport XOFF */ 498 - u8 ch_s_lnext; /* Realport LNEXT */ 499 - u8 ch_s_xxon; /* Realport XXON */ 500 - u8 ch_s_xxoff; /* Realport XXOFF */ 501 - 502 - wait_queue_head_t ch_flag_wait; /* Wait queue for ch_flag changes */ 503 - wait_queue_head_t ch_sleep; /* Wait queue for my_sleep() */ 504 - 505 - int ch_custom_speed; /* Realport custom speed */ 506 - int ch_txcount; /* Running TX count */ 507 - int ch_rxcount; /* Running RX count */ 508 - }; 509 - 510 - 511 - /************************************************************************ 512 - * Node State definitions. 513 - ************************************************************************/ 514 - 515 - enum dgrp_nd_state_t { 516 - NS_CLOSED = 0, /* Network device is closed */ 517 - NS_IDLE = 1, /* Network connection inactive */ 518 - NS_SEND_QUERY = 2, /* Send server query */ 519 - NS_WAIT_QUERY = 3, /* Wait for query response */ 520 - NS_READY = 4, /* Network ready */ 521 - NS_SEND_ERROR = 5 /* Must send error hangup */ 522 - }; 523 - 524 - #define ND_STATE_STR(x) \ 525 - ((x) == NS_CLOSED ? "CLOSED" : \ 526 - ((x) == NS_IDLE ? "IDLE" : \ 527 - ((x) == NS_SEND_QUERY ? "SEND_QUERY" : \ 528 - ((x) == NS_WAIT_QUERY ? "WAIT_QUERY" : \ 529 - ((x) == NS_READY ? "READY" : \ 530 - ((x) == NS_SEND_ERROR ? "SEND_ERROR" : "UNKNOWN")))))) 531 - 532 - /************************************************************************ 533 - * Node Flag definitions. 534 - ************************************************************************/ 535 - 536 - #define ND_SELECT 0x0001 /* Multiple net read selects */ 537 - #define ND_DEB_WAIT 0x0002 /* Debug Device waiting */ 538 - 539 - 540 - /************************************************************************ 541 - * Monitoring flag definitions. 542 - ************************************************************************/ 543 - 544 - #define MON_WAIT_DATA 0x0001 /* Waiting for buffer data */ 545 - #define MON_WAIT_SPACE 0x0002 /* Waiting for buffer space */ 546 - 547 - /************************************************************************ 548 - * DPA flag definitions. 549 - ************************************************************************/ 550 - 551 - #define DPA_WAIT_DATA 0x0001 /* Waiting for buffer data */ 552 - #define DPA_WAIT_SPACE 0x0002 /* Waiting for buffer space */ 553 - 554 - 555 - /************************************************************************ 556 - * Definitions taken from Realport Dump. 557 - ************************************************************************/ 558 - 559 - #define RPDUMP_MAGIC "Digi-RealPort-1.0" 560 - 561 - #define RPDUMP_MESSAGE 0xE2 /* Descriptive message */ 562 - #define RPDUMP_RESET 0xE7 /* Connection reset */ 563 - #define RPDUMP_CLIENT 0xE8 /* Client data */ 564 - #define RPDUMP_SERVER 0xE9 /* Server data */ 565 - 566 - 567 - /************************************************************************ 568 - * Node request/response definitions. 569 - ************************************************************************/ 570 - 571 - #define NR_ECHO 0x0001 /* Server echo packet */ 572 - #define NR_IDENT 0x0002 /* Server Product ID */ 573 - #define NR_CAPABILITY 0x0004 /* Server Capabilties */ 574 - #define NR_VPD 0x0008 /* Server VPD, if any */ 575 - #define NR_PASSWORD 0x0010 /* Server Password */ 576 - 577 - /************************************************************************ 578 - * Registration status of the node's Linux struct tty_driver structures. 579 - ************************************************************************/ 580 - #define SERIAL_TTDRV_REG 0x0001 /* nd_serial_ttdriver registered */ 581 - #define CALLOUT_TTDRV_REG 0x0002 /* nd_callout_ttdriver registered */ 582 - #define XPRINT_TTDRV_REG 0x0004 /* nd_xprint_ttdriver registered */ 583 - 584 - 585 - /************************************************************************ 586 - * Node structure. There exists one of these for each associated 587 - * realport server. 588 - ************************************************************************/ 589 - 590 - struct nd_struct { 591 - struct list_head list; 592 - long nd_major; /* Node's major number */ 593 - long nd_ID; /* Node's ID code */ 594 - 595 - char nd_serial_name[50]; /* "tty_dgrp_<id>_" + null */ 596 - char nd_callout_name[50]; /* "cu_dgrp_<id>_" + null */ 597 - char nd_xprint_name[50]; /* "pr_dgrp_<id>_" + null */ 598 - 599 - char password[16]; /* Password for server, if needed */ 600 - int nd_tty_ref_cnt; /* Linux tty reference count */ 601 - 602 - struct proc_dir_entry *nd_net_de; /* Dir entry for /proc/dgrp/net */ 603 - struct proc_dir_entry *nd_mon_de; /* Dir entry for /proc/dgrp/mon */ 604 - struct proc_dir_entry *nd_ports_de; /* Dir entry for /proc/dgrp/ports*/ 605 - struct proc_dir_entry *nd_dpa_de; /* Dir entry for /proc/dgrp/dpa */ 606 - 607 - spinlock_t nd_lock; /* General node lock */ 608 - 609 - struct semaphore nd_net_semaphore; /* Net read/write lock */ 610 - struct semaphore nd_mon_semaphore; /* Monitor buffer lock */ 611 - spinlock_t nd_dpa_lock; /* DPA buffer lock */ 612 - 613 - enum dgrp_nd_state_t nd_state; /* NS_* network state */ 614 - int nd_chan_count; /* # active channels */ 615 - int nd_flag; /* Node flags */ 616 - int nd_send; /* Responses to send */ 617 - int nd_expect; /* Responses we expect */ 618 - 619 - u8 *nd_iobuf; /* Network R/W Buffer */ 620 - wait_queue_head_t nd_tx_waitq; /* Network select wait queue */ 621 - 622 - u8 *nd_inputbuf; /* Input Buffer */ 623 - u8 *nd_inputflagbuf; /* Input Flags Buffer */ 624 - 625 - int nd_tx_deposit; /* Accumulated transmit deposits */ 626 - int nd_tx_charge; /* Accumulated transmit charges */ 627 - int nd_tx_credit; /* Current TX credit */ 628 - int nd_tx_ready; /* Ready to transmit */ 629 - int nd_tx_work; /* TX work waiting */ 630 - ulong nd_tx_time; /* Last transmit time */ 631 - ulong nd_poll_time; /* Next scheduled poll time */ 632 - 633 - int nd_delay; /* Current TX delay */ 634 - int nd_rate; /* Current TX rate */ 635 - struct link_struct nd_link; /* Link speed params. */ 636 - 637 - int nd_seq_in; /* TX seq in ptr */ 638 - int nd_seq_out; /* TX seq out ptr */ 639 - int nd_unack; /* Unacknowledged byte count */ 640 - int nd_remain; /* Remaining receive bytes */ 641 - int nd_tx_module; /* Current TX module # */ 642 - int nd_rx_module; /* Current RX module # */ 643 - char *nd_error; /* Protocol error message */ 644 - 645 - int nd_write_count; /* drp_write() call count */ 646 - int nd_read_count; /* drp_read() count */ 647 - int nd_send_count; /* TCP message sent */ 648 - int nd_tx_byte; /* Transmit byte count */ 649 - int nd_rx_byte; /* Receive byte count */ 650 - 651 - ulong nd_mon_lbolt; /* Monitor start time */ 652 - int nd_mon_flag; /* Monitor flags */ 653 - int nd_mon_in; /* Monitor in pointer */ 654 - int nd_mon_out; /* Monitor out pointer */ 655 - wait_queue_head_t nd_mon_wqueue; /* Monitor wait queue (on flags) */ 656 - u8 *nd_mon_buf; /* Monitor buffer */ 657 - 658 - ulong nd_dpa_lbolt; /* DPA start time */ 659 - int nd_dpa_flag; /* DPA flags */ 660 - int nd_dpa_in; /* DPA in pointer */ 661 - int nd_dpa_out; /* DPA out pointer */ 662 - wait_queue_head_t nd_dpa_wqueue; /* DPA wait queue (on flags) */ 663 - u8 *nd_dpa_buf; /* DPA buffer */ 664 - 665 - uint nd_dpa_debug; 666 - uint nd_dpa_port; 667 - 668 - wait_queue_head_t nd_seq_wque[SEQ_MAX]; /* TX thread wait queues */ 669 - u8 nd_seq_wait[SEQ_MAX]; /* Transmit thread wait count */ 670 - 671 - ushort nd_seq_size[SEQ_MAX]; /* Transmit seq packet size */ 672 - ulong nd_seq_time[SEQ_MAX]; /* Transmit seq packet time */ 673 - 674 - ushort nd_hw_ver; /* HW version returned from PS */ 675 - ushort nd_sw_ver; /* SW version returned from PS */ 676 - uint nd_hw_id; /* HW ID returned from PS */ 677 - u8 nd_ps_desc[MAX_DESC_LEN]; /* Description from PS */ 678 - uint nd_vpd_len; /* VPD len, if any */ 679 - u8 nd_vpd[VPDSIZE]; /* VPD, if any */ 680 - 681 - ulong nd_ttdriver_flags; /* Registration status */ 682 - struct tty_driver *nd_serial_ttdriver; /* Linux TTYDRIVER structure */ 683 - struct tty_driver *nd_callout_ttdriver; /* Linux TTYDRIVER structure */ 684 - struct tty_driver *nd_xprint_ttdriver; /* Linux TTYDRIVER structure */ 685 - 686 - u8 *nd_writebuf; /* Used to cache data read 687 - * from user 688 - */ 689 - struct ch_struct nd_chan[CHAN_MAX]; /* Channel array */ 690 - struct device *nd_class_dev; /* Hang our sysfs stuff off of here */ 691 - }; 692 - 693 - #endif /* __DRP_H */