3 * Copyright 1999 Digi International (www.digi.com)
4 * James Puzzo <jamesp at digi dot com>
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)
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.
26 * Handle the file operations required for the "network" devices.
27 * Includes those functions required to register the "net" devices
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>
49 #define MYFLIPLEN TBUF_MAX
51 #include "dgrp_common.h"
53 #define TTY_FLIPBUF_SIZE 512
54 #define DEVICE_NAME_SIZE 50
57 * Generic helper function declarations
59 static void parity_scan(struct ch_struct *ch, unsigned char *cbuf,
60 unsigned char *fbuf, int *len);
63 * File operation declarations
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,
70 static long dgrp_net_ioctl(struct file *file, unsigned int cmd,
72 static unsigned int dgrp_net_select(struct file *file,
73 struct poll_table_struct *table);
75 const struct file_operations dgrp_net_ops = {
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,
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
90 static void dgrp_dump(u8 *mem, int len)
94 pr_debug("dgrp dump length = %d, data = ", len);
95 for (i = 0; i < len; ++i)
96 pr_debug("%.2x ", mem[i]);
101 * dgrp_read_data_block() -- Read a data block
102 * @ch: struct ch_struct *
104 * @flipbuf_size: size of flipbuf
106 static void dgrp_read_data_block(struct ch_struct *ch, u8 *flipbuf,
112 if (flipbuf_size <= 0)
115 t = RBUF_MAX - ch->ch_rout;
119 memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, t);
125 memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, n);
132 * dgrp_input() -- send data to the line disipline
133 * @ch: pointer to channel struct
135 * Copys the rbuf to the flipbuf and sends to line discipline.
136 * Sends input buffer data to the line discipline.
139 static void dgrp_input(struct ch_struct *ch)
141 struct nd_struct *nd;
142 struct tty_struct *tty;
158 spin_lock_irqsave(&nd->nd_lock, lock_flags);
160 myflipbuf = nd->nd_inputbuf;
161 myflipflagbuf = nd->nd_inputflagbuf;
163 if (!ch->ch_open_count) {
164 ch->ch_rout = ch->ch_rin;
168 if (ch->ch_tun.un_flag & UN_CLOSING) {
169 ch->ch_rout = ch->ch_rin;
173 tty = (ch->ch_tun).un_tty;
176 if (!tty || tty->magic != TTY_MAGIC) {
177 ch->ch_rout = ch->ch_rin;
181 tty_count = tty->count;
183 ch->ch_rout = ch->ch_rin;
187 if (tty->closing || test_bit(TTY_CLOSING, &tty->flags)) {
188 ch->ch_rout = ch->ch_rin;
192 spin_unlock_irqrestore(&nd->nd_lock, lock_flags);
194 /* data_len should be the number of chars that we read in */
195 data_len = (ch->ch_rin - ch->ch_rout) & RBUF_MASK;
197 /* len is the amount of data we are going to transfer here */
198 len = tty_buffer_request_room(&ch->port, data_len);
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))))
206 if ((len) && !(ch->ch_flag & CH_RXSTOP)) {
208 dgrp_read_data_block(ch, myflipbuf, len);
210 if (I_PARMRK(tty) || I_BRKINT(tty) || I_INPCK(tty))
211 parity_scan(ch, myflipbuf, myflipflagbuf, &len);
213 memset(myflipflagbuf, TTY_NORMAL, len);
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);
219 tty_insert_flip_string_flags(&ch->port, myflipbuf,
221 tty_flip_buffer_push(&ch->port);
223 ch->ch_rxcount += len;
227 * Wake up any sleepers (maybe dgrp close) that might be waiting
228 * for a channel flag state change.
230 wake_up_interruptible(&ch->ch_flag_wait);
234 spin_unlock_irqrestore(&nd->nd_lock, lock_flags);
241 * Loop to inspect each single character or 0xFF escape.
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.
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
256 * TODO: do we need to do the XMODEM, XOFF, XON, XANY processing??
259 static void parity_scan(struct ch_struct *ch, unsigned char *cbuf,
260 unsigned char *fbuf, int *len)
264 int DOS = ((ch->ch_iflag & IF_DOSMODE) == 0 ? 0 : 1);
265 unsigned char *cout; /* character buffer */
266 unsigned char *fout; /* flag buffer */
278 switch (ch->ch_pscan_state) {
280 /* reset to sanity and fall through */
281 ch->ch_pscan_state = 0;
285 if (c == 0xff) /* delete this character from stream */
286 ch->ch_pscan_state = 1;
289 *fout++ = TTY_NORMAL;
297 /* doubled ff, transform to single ff */
299 *fout++ = TTY_NORMAL;
301 ch->ch_pscan_state = 0;
303 /* save value examination in next state */
304 ch->ch_pscan_savechar = c;
305 ch->ch_pscan_state = 2;
310 /* third character of ff sequence */
313 if (ch->ch_pscan_savechar & 0x10)
315 else if (ch->ch_pscan_savechar & 0x08)
319 * either marked as a parity error,
320 * indeterminate, or not in DOSMODE
321 * call it a parity error
323 *fout++ = TTY_PARITY;
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",
330 *fout++ = TTY_PARITY;
332 /* case FF 00 XX where XX is not 00 */
334 *fout++ = TTY_PARITY;
341 ch->ch_pscan_state = 0;
349 * dgrp_net_idle() -- Idle the network connection
350 * @nd: pointer to node structure to idle
352 static void dgrp_net_idle(struct nd_struct *nd)
354 struct ch_struct *ch;
359 nd->nd_state = NS_IDLE;
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]);
368 if (i == nd->nd_seq_in)
372 nd->nd_seq_out = nd->nd_seq_in;
377 nd->nd_tx_module = 0x10;
378 nd->nd_rx_module = 0x00;
380 for (i = 0, ch = nd->nd_chan; i < CHAN_MAX; i++, ch++) {
381 ch->ch_state = CS_IDLE;
384 ch->ch_otype_waiting = 0;
389 * Increase the number of channels, waking up any
390 * threads that might be waiting for the channels
393 static void increase_channel_count(struct nd_struct *nd, int n)
395 struct ch_struct *ch;
396 struct device *classp;
397 char name[DEVICE_NAME_SIZE];
402 for (i = nd->nd_chan_count; i < n; ++i) {
403 ch = nd->nd_chan + i;
405 /* FIXME: return a useful error instead! */
406 buf = kmalloc(TBUF_MAX, GFP_KERNEL);
411 pr_info_ratelimited("%s - ch_tbuf was not NULL\n",
416 buf = kmalloc(RBUF_MAX, GFP_KERNEL);
421 pr_info("%s - ch_rbuf was not NULL\n",
425 classp = tty_port_register_device(&ch->port,
426 nd->nd_serial_ttdriver, i,
429 ch->ch_tun.un_sysfs = classp;
430 snprintf(name, DEVICE_NAME_SIZE, "tty_%d", i);
432 dgrp_create_tty_sysfs(&ch->ch_tun, classp);
433 ret = sysfs_create_link(&nd->nd_class_dev->kobj,
434 &classp->kobj, name);
436 /* NOTE: We don't support "cu" devices anymore,
437 * so you will notice we don't register them
439 if (dgrp_register_prdevices) {
440 classp = tty_register_device(nd->nd_xprint_ttdriver,
442 ch->ch_pun.un_sysfs = classp;
443 snprintf(name, DEVICE_NAME_SIZE, "pr_%d", i);
445 dgrp_create_tty_sysfs(&ch->ch_pun, classp);
446 ret = sysfs_create_link(&nd->nd_class_dev->kobj,
447 &classp->kobj, name);
450 nd->nd_chan_count = i + 1;
451 wake_up_interruptible(&ch->ch_flag_wait);
456 * Decrease the number of channels, and wake up any threads that might
457 * be waiting on the channels that vanished.
459 static void decrease_channel_count(struct nd_struct *nd, int n)
461 struct ch_struct *ch;
462 char name[DEVICE_NAME_SIZE];
465 for (i = nd->nd_chan_count - 1; i >= n; --i) {
466 ch = nd->nd_chan + i;
469 * Make any open ports inoperative.
471 ch->ch_state = CS_IDLE;
474 ch->ch_otype_waiting = 0;
477 * Only "HANGUP" if we care about carrier
478 * transitions and we are already open.
480 if (ch->ch_open_count != 0) {
481 ch->ch_flag |= CH_HANGUP;
486 * Unlike the CH_HANGUP flag above, use another
487 * flag to indicate to the RealPort state machine
488 * that this port has disappeared.
490 if (ch->ch_open_count != 0)
491 ch->ch_flag |= CH_PORT_GONE;
493 wake_up_interruptible(&ch->ch_flag_wait);
495 nd->nd_chan_count = i;
503 nd->nd_chan_count = i;
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);
511 * NOTE: We don't support "cu" devices anymore, so don't
512 * unregister them here anymore.
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);
525 * dgrp_chan_count() -- Adjust the node channel count.
526 * @nd: pointer to a node structure
527 * @n: new value for channel count
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.
534 static void dgrp_chan_count(struct nd_struct *nd, int n)
536 if (n == nd->nd_chan_count)
539 if (n > nd->nd_chan_count)
540 increase_channel_count(nd, n);
542 if (n < nd->nd_chan_count)
543 decrease_channel_count(nd, n);
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
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.
556 static void dgrp_monitor(struct nd_struct *nd, u8 *buf, int len)
565 down(&nd->nd_mon_semaphore);
568 * Loop while data remains.
570 while ((len > 0) && (nd->nd_mon_buf)) {
572 * Determine the amount of available space left in the
573 * buffer. If there's none, wait until some appears.
576 n = (nd->nd_mon_out - nd->nd_mon_in - 1) & MON_MASK;
579 nd->nd_mon_flag |= MON_WAIT_SPACE;
581 up(&nd->nd_mon_semaphore);
584 * Go to sleep waiting until the condition becomes true.
586 rtn = wait_event_interruptible(nd->nd_mon_wqueue,
587 ((nd->nd_mon_flag & MON_WAIT_SPACE) == 0));
589 /* FIXME: really ignore rtn? */
592 * We can't exit here if we receive a signal, since
593 * to do so would trash the debug stream.
596 down(&nd->nd_mon_semaphore);
602 * Copy as much data as will fit.
608 r = MON_MAX - nd->nd_mon_in;
611 memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, r);
621 memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, n);
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);
633 * Wakeup any thread waiting for data
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);
643 * Release the monitor lock.
645 up(&nd->nd_mon_semaphore);
649 * dgrp_encode_time() -- Encodes rpdump time into a 4-byte quantity.
650 * @nd: pointer to a node structure
651 * @buf: destination buffer
653 * Encodes "rpdump" time into a 4-byte quantity. Time is measured since
656 static void dgrp_encode_time(struct nd_struct *nd, u8 *buf)
661 * Convert time in HZ since open to time in milliseconds
664 t = jiffies - nd->nd_mon_lbolt;
665 t = 1000 * (t / HZ) + 1000 * (t % HZ) / HZ;
667 put_unaligned_be32((uint)(t & 0xffffffff), buf);
673 * dgrp_monitor_message() -- Builds a rpdump style message.
674 * @nd: pointer to a node structure
675 * @message: destination buffer
677 static void dgrp_monitor_message(struct nd_struct *nd, char *message)
682 header[0] = RPDUMP_MESSAGE;
684 dgrp_encode_time(nd, header + 1);
688 put_unaligned_be16(n, header + 5);
690 dgrp_monitor(nd, header, sizeof(header));
691 dgrp_monitor(nd, (u8 *) message, n);
697 * dgrp_monitor_reset() -- Note a reset in the monitoring buffer.
698 * @nd: pointer to a node structure
700 static void dgrp_monitor_reset(struct nd_struct *nd)
704 header[0] = RPDUMP_RESET;
706 dgrp_encode_time(nd, header + 1);
708 dgrp_monitor(nd, header, sizeof(header));
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
718 static void dgrp_monitor_data(struct nd_struct *nd, u8 type, u8 *buf, int size)
724 dgrp_encode_time(nd, header + 1);
726 put_unaligned_be16(size, header + 5);
728 dgrp_monitor(nd, header, sizeof(header));
729 dgrp_monitor(nd, buf, size);
732 static int alloc_nd_buffers(struct nd_struct *nd)
736 nd->nd_writebuf = NULL;
737 nd->nd_inputbuf = NULL;
738 nd->nd_inputflagbuf = NULL;
741 * Allocate the network read/write buffer.
743 nd->nd_iobuf = kzalloc(UIO_MAX + 10, GFP_KERNEL);
748 * Allocate a buffer for doing the copy from user space to
749 * kernel space in the write routines.
751 nd->nd_writebuf = kzalloc(WRITEBUFLEN, GFP_KERNEL);
752 if (!nd->nd_writebuf)
756 * Allocate a buffer for doing the copy from kernel space to
757 * tty buffer space in the read routines.
759 nd->nd_inputbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
760 if (!nd->nd_inputbuf)
764 * Allocate a buffer for doing the copy from kernel space to
765 * tty buffer space in the read routines.
767 nd->nd_inputflagbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
768 if (!nd->nd_inputflagbuf)
775 kfree(nd->nd_writebuf);
776 kfree(nd->nd_inputbuf);
777 kfree(nd->nd_inputflagbuf);
782 * dgrp_net_open() -- Open the NET device for a particular PortServer
784 static int dgrp_net_open(struct inode *inode, struct file *file)
786 struct nd_struct *nd;
790 rtn = try_module_get(THIS_MODULE);
794 if (!capable(CAP_SYS_ADMIN)) {
800 * Make sure that the "private_data" field hasn't already been used.
802 if (file->private_data) {
808 * Get the node pointer, and fail if it doesn't exist.
810 nd = PDE_DATA(inode);
816 file->private_data = (void *) nd;
821 down(&nd->nd_net_semaphore);
823 if (nd->nd_state != NS_CLOSED) {
829 * Initialize the link speed parameters.
832 nd->nd_link.lk_fast_rate = UIO_MAX;
833 nd->nd_link.lk_slow_rate = UIO_MAX;
835 nd->nd_link.lk_fast_delay = 1000;
836 nd->nd_link.lk_slow_delay = 1000;
838 nd->nd_link.lk_header_size = 46;
841 rtn = alloc_nd_buffers(nd);
846 * The port is now open, so move it to the IDLE state
850 nd->nd_tx_time = jiffies;
853 * If the polling routing is not running, start it running here
855 spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags);
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);
864 spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags);
866 dgrp_monitor_message(nd, "Net Open");
870 * Release the NET lock.
872 up(&nd->nd_net_semaphore);
876 module_put(THIS_MODULE);
881 /* dgrp_net_release() -- close the NET device for a particular PortServer */
882 static int dgrp_net_release(struct inode *inode, struct file *file)
884 struct nd_struct *nd;
887 nd = (struct nd_struct *)(file->private_data);
891 /* TODO : historical locking placeholder */
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.
897 /* spinlock(&nd->nd_lock); */
903 down(&nd->nd_net_semaphore);
906 * Before "closing" the internal connection, make sure all
911 nd->nd_state = NS_CLOSED;
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
920 if (waitqueue_active(&nd->nd_tx_waitq))
921 pr_info("%s - expected waitqueue_active to be false\n",
929 /* TODO : historical locking placeholder */
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.
935 /* spinunlock( &nd->nd_lock ); */
938 kfree(nd->nd_writebuf);
939 nd->nd_writebuf = NULL;
941 kfree(nd->nd_inputbuf);
942 nd->nd_inputbuf = NULL;
944 kfree(nd->nd_inputflagbuf);
945 nd->nd_inputflagbuf = NULL;
947 /* TODO : historical locking placeholder */
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.
953 /* spinlock(&nd->nd_lock); */
956 * Set the active port count to zero.
958 dgrp_chan_count(nd, 0);
960 /* TODO : historical locking placeholder */
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.
966 /* spinunlock(&nd->nd_lock); */
969 * Release the NET lock.
971 up(&nd->nd_net_semaphore);
974 * Cause the poller to stop scheduling itself if this is
975 * the last active node.
977 spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags);
979 if (dgrp_poll_data.node_active_count == 2) {
980 del_timer(&dgrp_poll_data.timer);
981 dgrp_poll_data.node_active_count = 0;
984 spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags);
986 down(&nd->nd_net_semaphore);
988 dgrp_monitor_message(nd, "Net Close");
990 up(&nd->nd_net_semaphore);
993 module_put(THIS_MODULE);
994 file->private_data = NULL;
998 /* used in dgrp_send to setup command header */
999 static inline u8 *set_cmd_header(u8 *b, u8 port, u8 cmd)
1001 *b++ = 0xb0 + (port & 0x0f);
1007 * dgrp_send() -- build a packet for transmission to the server
1008 * @nd: pointer to a node structure
1009 * @tmax: maximum bytes to transmit
1011 * returns number of bytes sent
1013 static int dgrp_send(struct nd_struct *nd, long tmax)
1015 struct ch_struct *ch = nd->nd_chan;
1034 long wanted_sync_port = -1;
1035 ushort tdata[CHAN_MAX];
1038 mbuf = nd->nd_iobuf + UIO_BASE;
1041 send_sync = nd->nd_link.lk_slow_rate < UIO_MAX;
1046 memset(tdata, 0, sizeof(tdata));
1050 * If there are any outstanding requests to be serviced,
1051 * service them here.
1053 if (nd->nd_send & NR_PASSWORD) {
1056 * Send Password response.
1061 put_unaligned_be16(strlen(nd->password), b + 2);
1063 b += strlen(nd->password);
1064 nd->nd_send &= ~(NR_PASSWORD);
1069 * Loop over all modules to generate commands, and determine
1070 * the amount of data queued for transmit.
1073 for (mod = 0, port = 0; port < nd->nd_chan_count; mod++) {
1075 * If this is not the current module, enter a module select
1076 * code in the buffer.
1079 if (mod != nd->nd_tx_module)
1083 * Loop to process one module.
1086 maxport = port + 16;
1088 if (maxport > nd->nd_chan_count)
1089 maxport = nd->nd_chan_count;
1091 for (; port < maxport; port++, ch++) {
1093 * Switch based on channel state.
1096 switch (ch->ch_state) {
1098 * Send requests when the port is closed, and there
1099 * are no Open, Close or Cancel requests expected.
1104 * Wait until any open error code
1105 * has been delivered to all
1109 if (ch->ch_open_error) {
1110 if (ch->ch_wait_count[ch->ch_otype]) {
1115 ch->ch_open_error = 0;
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.
1124 if ((ch->ch_flag & CH_HANGUP) != 0)
1128 * If recovering from a TCP disconnect, or if
1129 * there is an immediate open pending, send an
1130 * Immediate Open request.
1132 if ((ch->ch_flag & CH_PORT_GONE) ||
1133 ch->ch_wait_count[OTYPE_IMMEDIATE] != 0) {
1134 b = set_cmd_header(b, port, 10);
1137 ch->ch_state = CS_WAIT_OPEN;
1138 ch->ch_otype = OTYPE_IMMEDIATE;
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
1148 if (ch->ch_otype_waiting == 0) {
1149 if (ch->ch_wait_count[OTYPE_PERSISTENT] != 0) {
1150 b = set_cmd_header(b, port, 10);
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);
1159 ch->ch_state = CS_WAIT_OPEN;
1160 ch->ch_otype = OTYPE_INCOMING;
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.
1171 if (ch->ch_wait_count[ch->ch_otype_waiting] == 0) {
1172 b = set_cmd_header(b, port, 10);
1175 ch->ch_state = CS_WAIT_CANCEL;
1176 ch->ch_otype = ch->ch_otype_waiting;
1181 * Send port parameter queries.
1185 * Clear out all FEP state that might remain
1186 * from the last connection.
1189 ch->ch_flag |= CH_PARAM;
1191 ch->ch_flag &= ~CH_RX_FLUSH;
1227 /* Send Sequence Request */
1228 b = set_cmd_header(b, port, 14);
1230 /* Configure Event Conditions Packet */
1231 b = set_cmd_header(b, port, 42);
1232 put_unaligned_be16(0x02c0, b);
1234 *b++ = (DM_DTR | DM_RTS | DM_CTS |
1235 DM_DSR | DM_RI | DM_CD);
1237 /* Send Status Request */
1238 b = set_cmd_header(b, port, 16);
1240 /* Send Buffer Request */
1241 b = set_cmd_header(b, port, 20);
1243 /* Send Port Capability Request */
1244 b = set_cmd_header(b, port, 22);
1246 ch->ch_expect = (RR_SEQUENCE |
1251 ch->ch_state = CS_WAIT_QUERY;
1253 /* Raise modem signals */
1254 b = set_cmd_header(b, port, 44);
1256 if (ch->ch_flag & CH_PORT_GONE)
1257 ch->ch_s_mout = ch->ch_mout;
1259 ch->ch_s_mout = ch->ch_mout = DM_DTR | DM_RTS;
1262 *b++ = ch->ch_s_mflow = 0;
1263 *b++ = ch->ch_s_mctrl = ch->ch_mctrl = 0;
1265 if (ch->ch_flag & CH_PORT_GONE)
1266 ch->ch_flag &= ~CH_PORT_GONE;
1271 * Handle normal open and ready mode.
1277 * If the port is not open, and there are no
1278 * no longer any ports requesting an open,
1279 * then close the port.
1282 if (ch->ch_open_count == 0 &&
1283 ch->ch_wait_count[ch->ch_otype] == 0) {
1288 * Process waiting input.
1290 * If there is no one to read it, discard the data.
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
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) {
1305 if (ch->ch_rin != ch->ch_rout)
1311 * Handle receive flush, and changes to
1312 * server port parameters.
1315 if (ch->ch_flag & (CH_RX_FLUSH | CH_PARAM)) {
1317 * If we are in receive flush mode,
1318 * and enough data has gone by, reset
1319 * receive flush mode.
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;
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);
1337 ch->ch_s_tmax = ch->ch_tmax;
1338 ch->ch_s_ttime = ch->ch_ttime;
1340 put_unaligned_be16(ch->ch_s_tmax,
1344 put_unaligned_be16(ch->ch_s_ttime,
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);
1357 ch->ch_s_rlow = ch->ch_rlow;
1358 ch->ch_s_rhigh = ch->ch_rhigh;
1360 put_unaligned_be16(ch->ch_s_rlow,
1364 put_unaligned_be16(ch->ch_s_rhigh,
1370 * Send BRATE, CFLAG, IFLAG,
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);
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;
1387 put_unaligned_be16(ch->ch_s_brate,
1391 put_unaligned_be16(ch->ch_s_cflag,
1395 put_unaligned_be16(ch->ch_s_iflag,
1399 put_unaligned_be16(ch->ch_s_oflag,
1403 put_unaligned_be16(ch->ch_s_xflag,
1409 * Send MOUT, MFLOW, MCTRL.
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);
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;
1423 * Send Flow control characters.
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);
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;
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);
1448 ch->ch_s_rmax = ch->ch_rmax;
1449 ch->ch_s_rtime = ch->ch_rtime;
1451 put_unaligned_be16(ch->ch_s_rmax,
1455 put_unaligned_be16(ch->ch_s_rtime,
1460 ch->ch_flag &= ~CH_PARAM;
1461 wake_up_interruptible(&ch->ch_flag_wait);
1466 * Handle action commands.
1469 if (ch->ch_send != 0) {
1470 /* int send = ch->ch_send & ~ch->ch_expect; */
1471 send = ch->ch_send & ~ch->ch_expect;
1473 /* Send character immediate */
1474 if ((send & RR_TX_ICHAR) != 0) {
1475 b = set_cmd_header(b, port, 60);
1478 ch->ch_expect |= RR_TX_ICHAR;
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,
1489 ch->ch_expect |= RR_TX_BREAK;
1490 ch->ch_break_time = 0;
1492 ch->ch_send &= ~RR_TX_BREAK;
1493 ch->ch_flag &= ~CH_TX_BREAK;
1494 wake_up_interruptible(&ch->ch_flag_wait);
1499 * Flush input/output buffers.
1502 if ((send & (RR_RX_FLUSH | RR_TX_FLUSH)) != 0) {
1503 b = set_cmd_header(b, port, 62);
1505 *b++ = ((send & RR_TX_FLUSH) == 0 ? 1 :
1506 (send & RR_RX_FLUSH) == 0 ? 2 : 3);
1508 if (send & RR_RX_FLUSH) {
1509 ch->ch_flush_seq = nd->nd_seq_in;
1510 ch->ch_flag |= CH_RX_FLUSH;
1513 wanted_sync_port = port;
1516 ch->ch_send &= ~(RR_RX_FLUSH | RR_TX_FLUSH);
1519 /* Pause input/output */
1520 if ((send & (RR_RX_STOP | RR_TX_STOP)) != 0) {
1521 b = set_cmd_header(b, port, 63);
1524 if ((send & RR_TX_STOP) != 0)
1527 if ((send & RR_RX_STOP) != 0)
1532 ch->ch_send &= ~(RR_RX_STOP | RR_TX_STOP);
1535 /* Start input/output */
1536 if ((send & (RR_RX_START | RR_TX_START)) != 0) {
1537 b = set_cmd_header(b, port, 64);
1540 if ((send & RR_TX_START) != 0)
1541 *b |= EV_OPU | EV_OPS | EV_OPX;
1543 if ((send & RR_RX_START) != 0)
1544 *b |= EV_IPU | EV_IPS;
1548 ch->ch_send &= ~(RR_RX_START | RR_TX_START);
1554 * Send a window sequence to acknowledge received data.
1557 rwin = (ch->ch_s_rin +
1558 ((ch->ch_rout - ch->ch_rin - 1) & RBUF_MASK));
1560 n = (rwin - ch->ch_s_rwin) & 0xffff;
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);
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
1577 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1579 if ((ch->ch_tun.un_flag & (UN_EMPTY|UN_LOW)) != 0) {
1580 if ((ch->ch_tun.un_flag & UN_LOW) != 0 ?
1582 (n == 0 && ch->ch_s_tpos == ch->ch_s_tin)) {
1583 ch->ch_tun.un_flag &= ~(UN_EMPTY|UN_LOW);
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;
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
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) {
1607 if ((ch->ch_pun.un_flag & UN_LOW) != 0 ?
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
1619 ch->ch_pun.un_flag &= ~(UN_EMPTY | UN_TIME | UN_LOW | UN_PWAIT);
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;
1626 } else if ((ch->ch_pun.un_flag & UN_TIME) != 0) {
1633 * Determine the max number of bytes
1634 * this port can send, including
1635 * packet header overhead.
1638 t = ((ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff);
1644 n += (n <= 8 ? 1 : n <= 255 ? 2 : 3);
1657 b = set_cmd_header(b, port, 10);
1658 if (ch->ch_otype == OTYPE_IMMEDIATE)
1663 ch->ch_state = CS_WAIT_CLOSE;
1667 * Wait for a previous server request.
1671 case CS_WAIT_CANCEL:
1678 pr_info("%s - unexpected channel state (%i)\n",
1679 __func__, ch->ch_state);
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.
1688 if (mod != nd->nd_tx_module) {
1690 mbuf[-1] = 0xf0 | mod;
1691 nd->nd_tx_module = mod;
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.
1706 n = UIO_MAX - UIO_BASE;
1716 * Allocate space for 5 Module Selects, 1 Sequence Request,
1717 * and 1 Set TREQ for each active channel.
1720 tmax -= 5 + 3 + 4 * nd->nd_chan_count;
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.
1728 n = nd->nd_tx_deposit - nd->nd_tx_charge - nd->nd_link.lk_header_size;
1734 * Finally reduce tmax by the number of bytes already in
1741 * Suspend data transmit unless every ready channel can send
1742 * at least 1 character.
1744 if (tmax < 2 * nd->nd_chan_count) {
1747 } else if (tchan > 1 && ttotal > tmax) {
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.
1761 for (try = 0; try < 3; try++) {
1765 for (i = 0; i < tc; i++) {
1766 if (tsend < tdata[i])
1767 tdata[c++] = tdata[i];
1783 tsend = tm / nd->nd_chan_count;
1790 * If no budgetary constraints, or only one channel ready
1791 * to send, set the character limit to the remaining
1798 tsend -= (tsend <= 9) ? 1 : (tsend <= 257) ? 2 : 3;
1801 * Loop over all channels, sending queued data.
1808 for (mod = 0; port < nd->nd_chan_count; mod++) {
1810 * If this is not the current module, enter a module select
1811 * code in the buffer.
1814 if (mod != nd->nd_tx_module)
1818 * Loop to process one module.
1821 maxport = port + 16;
1823 if (maxport > nd->nd_chan_count)
1824 maxport = nd->nd_chan_count;
1826 for (; port < maxport; port++, ch++) {
1827 if (ch->ch_state != CS_READY)
1832 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1835 * If there is data that can be sent, send it.
1838 if (n != 0 && used_buffer > 0) {
1839 t = (ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff;
1849 if (n > used_buffer) {
1858 * Create the correct size transmit header,
1859 * depending on the amount of data to transmit.
1864 b[0] = ((n - 1) << 4) + (port & 0xf);
1867 } else if (n <= 255) {
1869 b[0] = 0x80 + (port & 0xf);
1875 b[0] = 0x90 + (port & 0xf);
1876 put_unaligned_be16(n, b + 1);
1880 ch->ch_s_tin = (ch->ch_s_tin + n) & 0xffff;
1883 * Copy transmit data to the packet.
1886 t = TBUF_MAX - ch->ch_tout;
1889 memcpy(b, ch->ch_tbuf + ch->ch_tout, t);
1896 memcpy(b, ch->ch_tbuf + ch->ch_tout, n);
1900 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1904 * Wake any terminal unit process waiting in the
1905 * dgrp_write routine for low water.
1911 if ((ch->ch_flag & CH_LOW) != 0) {
1912 ch->ch_flag &= ~CH_LOW;
1913 wake_up_interruptible(&ch->ch_flag_wait);
1916 /* selwakeup tty_sel */
1917 if (ch->ch_tun.un_open_count) {
1918 struct tty_struct *tty = (ch->ch_tun.un_tty);
1920 if (waitqueue_active(&tty->write_wait))
1921 wake_up_interruptible(&tty->write_wait);
1926 if (ch->ch_pun.un_open_count) {
1927 struct tty_struct *tty = (ch->ch_pun.un_tty);
1929 if (waitqueue_active(&tty->write_wait))
1930 wake_up_interruptible(&tty->write_wait);
1936 * Do EMPTY processing.
1942 if ((ch->ch_flag & (CH_EMPTY | CH_DRAIN)) != 0 ||
1943 (ch->ch_pun.un_flag & UN_EMPTY) != 0) {
1945 * If there is still data in the server, ask the server
1946 * to notify us when its all gone.
1949 if (ch->ch_s_treq != ch->ch_s_tin) {
1950 b = set_cmd_header(b, port, 43);
1952 ch->ch_s_treq = ch->ch_s_tin;
1953 put_unaligned_be16(ch->ch_s_treq,
1959 * If there is a thread waiting for buffer empty,
1960 * and we are truly empty, wake the thread.
1963 else if ((ch->ch_flag & CH_EMPTY) != 0 &&
1964 (ch->ch_send & RR_TX_BREAK) == 0) {
1965 ch->ch_flag &= ~CH_EMPTY;
1967 wake_up_interruptible(&ch->ch_flag_wait);
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.
1977 if (mod != nd->nd_tx_module) {
1979 mbuf[-1] = 0xf0 | mod;
1980 nd->nd_tx_module = mod;
1988 * Send a synchronization sequence associated with the last open
1989 * channel that sent data, and remember the time when the data was
1995 if ((send_sync || nd->nd_seq_wait[in] != 0) && lastport >= 0) {
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.
2005 if (wanted_sync_port >= 0)
2006 lastport = wanted_sync_port;
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.
2012 ch = nd->nd_chan + lastport;
2013 ch->ch_flag |= CH_WAITING_SYNC;
2015 mod = lastport >> 4;
2017 if (mod != nd->nd_tx_module) {
2021 nd->nd_tx_module = mod;
2024 bb = set_cmd_header(bb, lastport, 12);
2027 nd->nd_seq_size[in] = bb - buf;
2028 nd->nd_seq_time[in] = jiffies;
2030 if (++in >= SEQ_MAX)
2033 if (in != nd->nd_seq_out) {
2036 nd->nd_unack += b - buf;
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.
2046 else if (nd->nd_seq_wait[in] != 0) {
2047 nd->nd_seq_wait[in] = 0;
2049 wake_up_interruptible(&nd->nd_seq_wque[in]);
2053 * If there is no traffic for an interval of IDLE_MAX, then
2054 * send a single byte packet.
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;
2067 pr_info("%s - n(%i) >= tsafe(%i)\n",
2068 __func__, n, tsafe);
2073 nd->nd_tx_work = work;
2080 * Data to be sent TO the PortServer from the "async." half of the driver.
2082 static ssize_t dgrp_net_read(struct file *file, char __user *buf, size_t count,
2085 struct nd_struct *nd;
2092 * Get the node pointer, and quit if it doesn't exist.
2094 nd = (struct nd_struct *)(file->private_data);
2098 if (count < UIO_MIN)
2102 * Only one read/write operation may be in progress at
2107 * Grab the NET lock.
2109 down(&nd->nd_net_semaphore);
2111 nd->nd_read_count++;
2113 nd->nd_tx_ready = 0;
2116 * Determine the effective size of the buffer.
2119 if (nd->nd_remain > UIO_BASE)
2120 pr_info_ratelimited("%s - nd_remain(%i) > UIO_BASE\n",
2121 __func__, nd->nd_remain);
2123 b = local_buf = nd->nd_iobuf + UIO_BASE;
2126 * Generate data according to the node state.
2129 switch (nd->nd_state) {
2131 * Initialize the connection.
2136 dgrp_monitor_reset(nd);
2139 * Request a Product ID Packet.
2146 nd->nd_expect |= NR_IDENT;
2149 * Request a Server Capability ID Response.
2156 nd->nd_expect |= NR_CAPABILITY;
2159 * Request a Server VPD Response.
2166 nd->nd_expect |= NR_VPD;
2168 nd->nd_state = NS_WAIT_QUERY;
2172 * We do serious communication with the server only in
2177 b = dgrp_send(nd, count) + local_buf;
2181 * Send off an error after receiving a bogus message
2186 n = strlen(nd->nd_error);
2190 memcpy(b + 2, nd->nd_error, n);
2195 * Set the active port count to zero.
2197 dgrp_chan_count(nd, 0);
2207 nd->nd_send_count++;
2209 nd->nd_tx_byte += n + nd->nd_link.lk_header_size;
2210 nd->nd_tx_charge += n + nd->nd_link.lk_header_size;
2213 rtn = copy_to_user((void __user *)buf, local_buf, n);
2224 dgrp_monitor_data(nd, RPDUMP_CLIENT, local_buf, n);
2227 * Release the NET lock.
2230 up(&nd->nd_net_semaphore);
2236 * Common Packet Handling code
2239 static void handle_data_in_packet(struct nd_struct *nd, struct ch_struct *ch,
2240 long dlen, long plen, int n1, u8 *dbuf)
2248 remain = nd->nd_remain;
2252 * Otherwise data should appear only when we are
2253 * in the CS_READY state.
2256 if (ch->ch_state < CS_READY) {
2257 error = "Data received before RWIN established";
2259 nd->nd_state = NS_SEND_ERROR;
2260 nd->nd_error = error;
2264 * Assure that the data received is within the
2268 n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff;
2271 error = "Receive data overrun";
2273 nd->nd_state = NS_SEND_ERROR;
2274 nd->nd_error = error;
2278 * If we received 3 or less characters,
2279 * assume it is a human typing, and set RTIME
2280 * to 10 milliseconds.
2282 * If we receive 10 or more characters,
2283 * assume its not a human typing, and set RTIME
2284 * to 100 milliseconds.
2287 if (ch->ch_edelay != DGRP_RTIME) {
2288 if (ch->ch_rtime != ch->ch_edelay) {
2289 ch->ch_rtime = ch->ch_edelay;
2290 ch->ch_flag |= CH_PARAM;
2292 } else if (dlen <= 3) {
2293 if (ch->ch_rtime != 10) {
2295 ch->ch_flag |= CH_PARAM;
2298 if (ch->ch_rtime != DGRP_RTIME) {
2299 ch->ch_rtime = DGRP_RTIME;
2300 ch->ch_flag |= CH_PARAM;
2305 * If a portion of the packet is outside the
2306 * buffer, shorten the effective length of the
2307 * data packet to be the amount of data received.
2311 dlen -= plen - remain;
2314 * Detect if receive flush is now complete.
2317 if ((ch->ch_flag & CH_RX_FLUSH) != 0 &&
2318 ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >=
2319 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2320 ch->ch_flag &= ~CH_RX_FLUSH;
2324 * If we are ready to receive, move the data into
2325 * the receive buffer.
2328 ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff;
2330 if (ch->ch_state == CS_READY &&
2331 (ch->ch_tun.un_open_count != 0) &&
2332 (ch->ch_tun.un_flag & UN_CLOSING) == 0 &&
2333 (ch->ch_cflag & CF_CREAD) != 0 &&
2334 (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 &&
2335 (ch->ch_send & RR_RX_FLUSH) == 0) {
2337 if (ch->ch_rin + dlen >= RBUF_MAX) {
2338 n = RBUF_MAX - ch->ch_rin;
2340 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n);
2347 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen);
2353 * If we are not in fastcook mode, or
2354 * if there is a fastcook thread
2355 * waiting for data, send the data to
2356 * the line discipline.
2359 if ((ch->ch_flag & CH_FAST_READ) == 0 ||
2360 ch->ch_inwait != 0) {
2365 * If there is a read thread waiting
2366 * in select, and we are in fastcook
2367 * mode, wake him up.
2370 if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) &&
2371 (ch->ch_flag & CH_FAST_READ) != 0)
2372 wake_up_interruptible(&ch->ch_tun.un_tty->read_wait);
2375 * Wake any thread waiting in the
2379 if ((ch->ch_flag & CH_INPUT) != 0) {
2380 ch->ch_flag &= ~CH_INPUT;
2381 wake_up_interruptible(&ch->ch_flag_wait);
2386 * Fabricate and insert a data packet header to
2387 * preced the remaining data when it comes in.
2390 if (remain < plen) {
2391 dlen = plen - remain;
2395 put_unaligned_be16(dlen, b + 1);
2398 if (remain > 0 && b != buf)
2399 memcpy(buf, b, remain);
2401 nd->nd_remain = remain;
2407 * dgrp_receive() -- decode data packets received from the remote PortServer.
2408 * @nd: pointer to a node structure
2410 static void dgrp_receive(struct nd_struct *nd)
2412 struct ch_struct *ch;
2429 nd->nd_tx_time = jiffies;
2431 ID_TO_CHAR(nd->nd_ID, ID);
2433 b = buf = nd->nd_iobuf;
2434 remain = nd->nd_remain;
2437 * Loop to process Realport protocol packets.
2440 while (remain > 0) {
2442 int n1 = b[0] & 0x0f;
2445 port = (nd->nd_rx_module << 4) + n1;
2447 if (port >= nd->nd_chan_count) {
2448 error = "Improper Port Number";
2452 ch = nd->nd_chan + port;
2459 * Process by major packet type.
2465 * Process 1-byte header data packet.
2480 handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf);
2484 * Process 2-byte header data packet.
2495 handle_data_in_packet(nd, ch, dlen, plen, n1, dbuf);
2499 * Process 3-byte header data packet.
2506 dlen = get_unaligned_be16(b + 1);
2514 * Handle Window Sequence packets.
2525 ushort tpos = get_unaligned_be16(b + 1);
2527 ushort ack = (tpos - ch->ch_s_tpos) & 0xffff;
2528 ushort unack = (ch->ch_s_tin - ch->ch_s_tpos) & 0xffff;
2529 ushort notify = (ch->ch_s_treq - ch->ch_s_tpos) & 0xffff;
2531 if (ch->ch_state < CS_READY || ack > unack) {
2532 error = "Improper Window Sequence";
2536 ch->ch_s_tpos = tpos;
2539 ch->ch_s_treq = tpos;
2544 * Handle Command response packets.
2550 * RealPort engine fix - 03/11/2004
2552 * This check did not used to be here.
2554 * We were using b[1] without verifying that the data
2555 * is actually there and valid. On a split packet, it
2558 * NOTE: I have never actually seen the failure happen
2559 * under Linux, but since I have seen it occur
2560 * under both Solaris and HP-UX, the assumption
2561 * is that it *could* happen here as well...
2570 * Handle Open Response.
2583 port = get_unaligned_be16(b + 4);
2585 if (port >= nd->nd_chan_count) {
2586 error = "Open channel number out of range";
2590 ch = nd->nd_chan + port;
2593 * How we handle an open response depends primarily
2594 * on our current channel state.
2597 switch (ch->ch_state) {
2601 * Handle a delayed open.
2604 if (ch->ch_otype_waiting != 0 &&
2605 req == ch->ch_otype_waiting &&
2608 ch->ch_otype_waiting = 0;
2609 ch->ch_state = CS_SEND_QUERY;
2617 * Handle the open response.
2620 if (req == ch->ch_otype) {
2624 * On successful response, open the
2625 * port and proceed normally.
2629 ch->ch_state = CS_SEND_QUERY;
2633 * On a busy response to a persistent open,
2634 * remember that the open is pending.
2639 if (req != OTYPE_IMMEDIATE) {
2640 ch->ch_otype_waiting = req;
2641 ch->ch_state = CS_IDLE;
2646 * Otherwise the server open failed. If
2647 * the Unix port is open, hang it up.
2651 if (ch->ch_open_count != 0) {
2652 ch->ch_flag |= CH_HANGUP;
2654 ch->ch_state = CS_IDLE;
2658 ch->ch_open_error = resp;
2659 ch->ch_state = CS_IDLE;
2661 wake_up_interruptible(&ch->ch_flag_wait);
2667 * Handle delayed response arrival preceding
2668 * the open response we are waiting for.
2671 if (ch->ch_otype_waiting != 0 &&
2672 req == ch->ch_otype_waiting &&
2674 ch->ch_otype = ch->ch_otype_waiting;
2675 ch->ch_otype_waiting = 0;
2676 ch->ch_state = CS_WAIT_FAIL;
2685 * Handle response to immediate open arriving
2686 * after a delayed open success.
2689 if (req == OTYPE_IMMEDIATE) {
2690 ch->ch_state = CS_SEND_QUERY;
2696 case CS_WAIT_CANCEL:
2698 * Handle delayed open response arriving before
2699 * the cancel response.
2702 if (req == ch->ch_otype_waiting &&
2704 ch->ch_otype_waiting = 0;
2709 * Handle cancel response.
2712 if (req == 4 && resp == 0) {
2713 ch->ch_otype_waiting = 0;
2714 ch->ch_state = CS_IDLE;
2722 * Handle a successful response to a port
2727 ch->ch_state = CS_IDLE;
2735 error = "Improper Open Response";
2743 * Handle Synchronize Response.
2755 * If channel was waiting for this sync response,
2756 * unset the flag, and wake up anyone waiting
2759 if (ch->ch_flag & CH_WAITING_SYNC) {
2760 ch->ch_flag &= ~(CH_WAITING_SYNC);
2761 wake_up_interruptible(&ch->ch_flag_wait);
2764 if (((seq - nd->nd_seq_out) & SEQ_MASK) >=
2765 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2769 for (s = nd->nd_seq_out;; s = (s + 1) & SEQ_MASK) {
2770 if (nd->nd_seq_wait[s] != 0) {
2771 nd->nd_seq_wait[s] = 0;
2773 wake_up_interruptible(&nd->nd_seq_wque[s]);
2776 nd->nd_unack -= nd->nd_seq_size[s];
2782 nd->nd_seq_out = (seq + 1) & SEQ_MASK;
2787 * Handle Sequence Response.
2796 /* Record that we have received the Sequence
2797 * Response, but we aren't interested in the
2798 * sequence numbers. We were using RIN like it
2799 * was ROUT and that was causing problems,
2800 * fixed 7-13-2001 David Fries. See comment in
2801 * drp.h for ch_s_rin variable.
2802 int rin = get_unaligned_be16(b + 2);
2803 int tpos = get_unaligned_be16(b + 4);
2806 ch->ch_send &= ~RR_SEQUENCE;
2807 ch->ch_expect &= ~RR_SEQUENCE;
2812 * Handle Status Response.
2821 ch->ch_s_elast = get_unaligned_be16(b + 2);
2822 ch->ch_s_mlast = b[4];
2824 ch->ch_expect &= ~RR_STATUS;
2825 ch->ch_send &= ~RR_STATUS;
2828 * CH_PHYS_CD is cleared because something _could_ be
2829 * waiting for the initial sense of carrier... and if
2830 * carrier is high immediately, we want to be sure to
2831 * wake them as soon as possible.
2833 ch->ch_flag &= ~CH_PHYS_CD;
2840 * Handle Line Error Response.
2851 * Handle Buffer Response.
2860 ch->ch_s_rsize = get_unaligned_be16(b + 2);
2861 ch->ch_s_tsize = get_unaligned_be16(b + 4);
2863 ch->ch_send &= ~RR_BUFFER;
2864 ch->ch_expect &= ~RR_BUFFER;
2869 * Handle Port Capability Response.
2878 ch->ch_send &= ~RR_CAPABILITY;
2879 ch->ch_expect &= ~RR_CAPABILITY;
2883 * When all queries are complete, set those parameters
2884 * derived from the query results, then transition
2885 * to the READY state.
2889 if (ch->ch_state == CS_WAIT_QUERY &&
2890 (ch->ch_expect & (RR_SEQUENCE |
2893 RR_CAPABILITY)) == 0) {
2894 ch->ch_tmax = ch->ch_s_tsize / 4;
2896 if (ch->ch_edelay == DGRP_TTIME)
2897 ch->ch_ttime = DGRP_TTIME;
2899 ch->ch_ttime = ch->ch_edelay;
2901 ch->ch_rmax = ch->ch_s_rsize / 4;
2903 if (ch->ch_edelay == DGRP_RTIME)
2904 ch->ch_rtime = DGRP_RTIME;
2906 ch->ch_rtime = ch->ch_edelay;
2908 ch->ch_rlow = 2 * ch->ch_s_rsize / 8;
2909 ch->ch_rhigh = 6 * ch->ch_s_rsize / 8;
2911 ch->ch_state = CS_READY;
2914 wake_up_interruptible(&ch->ch_flag_wait);
2933 mlast = ch->ch_s_mlast;
2934 elast = ch->ch_s_elast;
2936 mstat = ch->ch_s_mlast = b[1];
2937 estat = ch->ch_s_elast = get_unaligned_be16(b + 2);
2940 * Handle modem changes.
2943 if (((mstat ^ mlast) & DM_CD) != 0)
2948 * Handle received break.
2951 if ((estat & ~elast & EV_RXB) != 0 &&
2952 (ch->ch_tun.un_open_count != 0) &&
2953 I_BRKINT(ch->ch_tun.un_tty) &&
2954 !(I_IGNBRK(ch->ch_tun.un_tty))) {
2956 tty_buffer_request_room(&ch->port, 1);
2957 tty_insert_flip_char(&ch->port, 0, TTY_BREAK);
2958 tty_flip_buffer_push(&ch->port);
2963 * On transmit break complete, if more break traffic
2964 * is waiting then send it. Otherwise wake any threads
2965 * waiting for transmitter empty.
2968 if ((~estat & elast & EV_TXB) != 0 &&
2969 (ch->ch_expect & RR_TX_BREAK) != 0) {
2973 ch->ch_expect &= ~RR_TX_BREAK;
2975 if (ch->ch_break_time != 0) {
2976 ch->ch_send |= RR_TX_BREAK;
2978 ch->ch_send &= ~RR_TX_BREAK;
2979 ch->ch_flag &= ~CH_TX_BREAK;
2980 wake_up_interruptible(&ch->ch_flag_wait);
2987 error = "Unrecognized command";
2991 * Decode Special Codes.
2997 * One byte module select.
3009 nd->nd_rx_module = n1;
3013 * Two byte module select.
3021 nd->nd_rx_module = b[1];
3025 * ID Request packet.
3032 plen = get_unaligned_be16(b + 2);
3034 if (plen < 12 || plen > 1000) {
3035 error = "Response Packet length error";
3047 nd->nd_send |= NR_ECHO;
3051 * ID Response packet.
3055 nd->nd_send |= NR_IDENT;
3059 * ID Response packet.
3063 nd->nd_send |= NR_PASSWORD;
3070 * Various node-level response packets.
3077 plen = get_unaligned_be16(b + 2);
3079 if (plen < 4 || plen > 1000) {
3080 error = "Response Packet length error";
3092 nd->nd_expect &= ~NR_ECHO;
3096 * Product Response Packet.
3103 nd->nd_hw_ver = (b[8] << 8) | b[9];
3104 nd->nd_sw_ver = (b[10] << 8) | b[11];
3105 nd->nd_hw_id = b[6];
3106 desclen = (plen - 12 > MAX_DESC_LEN - 1) ? MAX_DESC_LEN - 1 :
3110 error = "Response Packet desclen error";
3114 strncpy(nd->nd_ps_desc, b + 12, desclen);
3115 nd->nd_ps_desc[desclen] = 0;
3118 nd->nd_expect &= ~NR_IDENT;
3122 * Capability Response Packet.
3127 int nn = get_unaligned_be16(b + 4);
3132 dgrp_chan_count(nd, nn);
3135 nd->nd_expect &= ~NR_CAPABILITY;
3139 * VPD Response Packet.
3144 * NOTE: case 15 is here ONLY because the EtherLite
3145 * is broken, and sends a response to 24 back as 15.
3146 * To resolve this, the EtherLite firmware is now
3147 * fixed to send back 24 correctly, but, for backwards
3148 * compatibility, we now have reserved 15 for the
3149 * bad EtherLite response to 24 as well.
3157 * If the product doesn't support VPD,
3158 * it will send back a null IDRESP,
3159 * which is a length of 4 bytes.
3162 memcpy(nd->nd_vpd, b + 4, min(plen - 4, (long) VPDSIZE));
3163 nd->nd_vpd_len = min(plen - 4, (long) VPDSIZE);
3166 nd->nd_expect &= ~NR_VPD;
3173 if (nd->nd_expect == 0 &&
3174 nd->nd_state == NS_WAIT_QUERY) {
3175 nd->nd_state = NS_READY;
3187 plen = get_unaligned_be16(b + 2) + 4;
3190 error = "Debug Packet too large";
3199 * Handle reset packet.
3218 error = "Client Reset Acknowledge";
3235 * When the buffer is exhausted, copy any data left at the
3236 * top of the buffer back down to the bottom for the next
3241 if (remain > 0 && b != buf)
3242 memcpy(buf, b, remain);
3244 nd->nd_remain = remain;
3248 * Handle a decode error.
3252 error = "Protocol decode error";
3255 * Handle a general protocol error.
3260 nd->nd_state = NS_SEND_ERROR;
3261 nd->nd_error = error;
3265 * dgrp_net_write() -- write data to the network device.
3267 * A zero byte write indicates that the connection to the RealPort
3268 * device has been broken.
3270 * A non-zero write indicates data from the RealPort device.
3272 static ssize_t dgrp_net_write(struct file *file, const char __user *buf,
3273 size_t count, loff_t *ppos)
3275 struct nd_struct *nd;
3281 * Get the node pointer, and quit if it doesn't exist.
3283 nd = (struct nd_struct *)(file->private_data);
3288 * Grab the NET lock.
3290 down(&nd->nd_net_semaphore);
3292 nd->nd_write_count++;
3295 * Handle disconnect.
3301 * Set the active port count to zero.
3303 dgrp_chan_count(nd, 0);
3308 * Loop to process entire receive packet.
3312 n = UIO_MAX - nd->nd_remain;
3317 nd->nd_rx_byte += n + nd->nd_link.lk_header_size;
3319 rtn = copy_from_user(nd->nd_iobuf + nd->nd_remain,
3320 (void __user *) buf + total, n);
3333 dgrp_monitor_data(nd, RPDUMP_SERVER,
3334 nd->nd_iobuf + nd->nd_remain, n);
3345 * Release the NET lock.
3347 up(&nd->nd_net_semaphore);
3355 * Determine whether a device is ready to be read or written to, and
3358 static unsigned int dgrp_net_select(struct file *file,
3359 struct poll_table_struct *table)
3361 unsigned int retval = 0;
3362 struct nd_struct *nd = file->private_data;
3364 poll_wait(file, &nd->nd_tx_waitq, table);
3366 if (nd->nd_tx_ready)
3367 retval |= POLLIN | POLLRDNORM; /* Conditionally readable */
3369 retval |= POLLOUT | POLLWRNORM; /* Always writeable */
3377 * Implement those functions which allow the network daemon to control
3378 * the network parameters in the driver. The ioctls include ones to
3379 * get and set the link speed parameters for the PortServer.
3381 static long dgrp_net_ioctl(struct file *file, unsigned int cmd,
3384 struct nd_struct *nd;
3386 long size = _IOC_SIZE(cmd);
3387 struct link_struct link;
3389 nd = file->private_data;
3391 if (_IOC_DIR(cmd) & _IOC_READ)
3392 rtn = access_ok(VERIFY_WRITE, (void __user *) arg, size);
3393 else if (_IOC_DIR(cmd) & _IOC_WRITE)
3394 rtn = access_ok(VERIFY_READ, (void __user *) arg, size);
3401 if (size != sizeof(struct link_struct))
3404 if (copy_from_user(&link, (void __user *)arg, size))
3407 if (link.lk_fast_rate < 9600)
3408 link.lk_fast_rate = 9600;
3410 if (link.lk_slow_rate < 2400)
3411 link.lk_slow_rate = 2400;
3413 if (link.lk_fast_rate > 10000000)
3414 link.lk_fast_rate = 10000000;
3416 if (link.lk_slow_rate > link.lk_fast_rate)
3417 link.lk_slow_rate = link.lk_fast_rate;
3419 if (link.lk_fast_delay > 2000)
3420 link.lk_fast_delay = 2000;
3422 if (link.lk_slow_delay > 10000)
3423 link.lk_slow_delay = 10000;
3425 if (link.lk_fast_delay < 60)
3426 link.lk_fast_delay = 60;
3428 if (link.lk_slow_delay < link.lk_fast_delay)
3429 link.lk_slow_delay = link.lk_fast_delay;
3431 if (link.lk_header_size < 2)
3432 link.lk_header_size = 2;
3434 if (link.lk_header_size > 128)
3435 link.lk_header_size = 128;
3437 link.lk_fast_rate /= 8 * 1000 / dgrp_poll_tick;
3438 link.lk_slow_rate /= 8 * 1000 / dgrp_poll_tick;
3440 link.lk_fast_delay /= dgrp_poll_tick;
3441 link.lk_slow_delay /= dgrp_poll_tick;
3448 if (size != sizeof(struct link_struct))
3451 if (copy_to_user((void __user *)arg, (void *)(&nd->nd_link),
3466 * dgrp_poll_handler() -- handler for poll timer
3468 * As each timer expires, it determines (a) whether the "transmit"
3469 * waiter needs to be woken up, and (b) whether the poller needs to
3472 void dgrp_poll_handler(unsigned long arg)
3474 struct dgrp_poll_data *poll_data;
3475 struct nd_struct *nd;
3476 struct link_struct *lk;
3482 poll_data = (struct dgrp_poll_data *) arg;
3483 freq = 1000 / poll_data->poll_tick;
3484 poll_data->poll_round += 17;
3486 if (poll_data->poll_round >= freq)
3487 poll_data->poll_round -= freq;
3490 * Loop to process all open nodes.
3492 * For each node, determine the rate at which it should
3493 * be transmitting data. Then if the node should wake up
3494 * and transmit data now, enable the net receive select
3495 * to get the transmit going.
3498 list_for_each_entry(nd, &nd_struct_list, list) {
3503 * Decrement statistics. These are only for use with
3504 * KME, so don't worry that the operations are done
3505 * unlocked, and so the results are occasionally wrong.
3508 nd->nd_read_count -= (nd->nd_read_count +
3509 poll_data->poll_round) / freq;
3510 nd->nd_write_count -= (nd->nd_write_count +
3511 poll_data->poll_round) / freq;
3512 nd->nd_send_count -= (nd->nd_send_count +
3513 poll_data->poll_round) / freq;
3514 nd->nd_tx_byte -= (nd->nd_tx_byte +
3515 poll_data->poll_round) / freq;
3516 nd->nd_rx_byte -= (nd->nd_rx_byte +
3517 poll_data->poll_round) / freq;
3520 * Wake the daemon to transmit data only when there is
3521 * enough byte credit to send data.
3523 * The results are approximate because the operations
3524 * are performed unlocked, and we are inspecting
3525 * data asynchronously updated elsewhere. The whole
3526 * thing is just approximation anyway, so that should
3530 if (lk->lk_slow_rate >= UIO_MAX) {
3533 nd->nd_rate = UIO_MAX;
3535 nd->nd_tx_deposit = nd->nd_tx_charge + 3 * UIO_MAX;
3536 nd->nd_tx_credit = 3 * UIO_MAX;
3547 long seq_in = nd->nd_seq_in;
3548 long seq_out = nd->nd_seq_out;
3551 * If there are no outstanding packets, run at the
3555 if (seq_in == seq_out) {
3557 rate = lk->lk_fast_rate;
3561 * Otherwise compute the transmit rate based on the
3562 * delay since the oldest packet.
3567 * The actual delay is computed as the
3568 * time since the oldest unacknowledged
3569 * packet was sent, minus the time it
3570 * took to send that packet to the server.
3573 delay = ((jiffies - nd->nd_seq_time[seq_out])
3574 - (nd->nd_seq_size[seq_out] /
3578 * If the delay is less than the "fast"
3579 * delay, transmit full speed. If greater
3580 * than the "slow" delay, transmit at the
3581 * "slow" speed. In between, interpolate
3582 * between the fast and slow speeds.
3586 (delay <= lk->lk_fast_delay ?
3588 delay >= lk->lk_slow_delay ?
3591 (lk->lk_slow_delay - delay) *
3592 (lk->lk_fast_rate - lk->lk_slow_rate) /
3593 (lk->lk_slow_delay - lk->lk_fast_delay)
3598 nd->nd_delay = delay;
3602 * Increase the transmit credit by depositing the
3603 * current transmit rate.
3606 deposit = nd->nd_tx_deposit;
3607 charge = nd->nd_tx_charge;
3612 * If the available transmit credit becomes too large,
3613 * reduce the deposit to correct the value.
3615 * Too large is the max of:
3616 * 6 times the header size
3617 * 3 times the current transmit rate.
3620 size = 2 * nd->nd_link.lk_header_size;
3627 excess = deposit - charge - size;
3632 nd->nd_tx_deposit = deposit;
3633 nd->nd_tx_credit = deposit - charge;
3636 * Wake the transmit task only if the transmit credit
3637 * is at least 3 times the transmit header size.
3640 size = 3 * lk->lk_header_size;
3642 if (nd->nd_tx_credit < size)
3648 * Enable the READ select to wake the daemon if there
3649 * is useful work for the drp_read routine to perform.
3652 if (waitqueue_active(&nd->nd_tx_waitq) &&
3653 (nd->nd_tx_work != 0 ||
3654 (ulong)(jiffies - nd->nd_tx_time) >= IDLE_MAX)) {
3655 nd->nd_tx_ready = 1;
3657 wake_up_interruptible(&nd->nd_tx_waitq);
3660 /* nd->nd_flag &= ~ND_SELECT; */
3666 * Schedule ourself back at the nominal wakeup interval.
3668 spin_lock_irqsave(&poll_data->poll_lock, lock_flags);
3670 poll_data->node_active_count--;
3671 if (poll_data->node_active_count > 0) {
3672 poll_data->node_active_count++;
3673 poll_time = poll_data->timer.expires +
3674 poll_data->poll_tick * HZ / 1000;
3676 time = poll_time - jiffies;
3678 if (time >= 2 * poll_data->poll_tick)
3679 poll_time = jiffies + dgrp_poll_tick * HZ / 1000;
3681 poll_data->timer.expires = poll_time;
3682 add_timer(&poll_data->timer);
3685 spin_unlock_irqrestore(&poll_data->poll_lock, lock_flags);