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/types.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 static const struct file_operations 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,
85 static struct inode_operations net_inode_ops = {
86 .permission = dgrp_inode_permission
89 void dgrp_register_net_hook(struct proc_dir_entry *de)
91 struct nd_struct *node = de->data;
93 de->proc_iops = &net_inode_ops;
94 de->proc_fops = &net_ops;
96 sema_init(&node->nd_net_semaphore, 1);
97 node->nd_state = NS_CLOSED;
98 dgrp_create_node_class_sysfs_files(node);
103 * dgrp_dump() -- prints memory for debugging purposes.
104 * @mem: Memory location which should be printed to the console
105 * @len: Number of bytes to be dumped
107 static void dgrp_dump(u8 *mem, int len)
111 pr_debug("dgrp dump length = %d, data = ", len);
112 for (i = 0; i < len; ++i)
113 pr_debug("%.2x ", mem[i]);
118 * dgrp_read_data_block() -- Read a data block
119 * @ch: struct ch_struct *
121 * @flipbuf_size: size of flipbuf
123 static void dgrp_read_data_block(struct ch_struct *ch, u8 *flipbuf,
129 if (flipbuf_size <= 0)
132 t = RBUF_MAX - ch->ch_rout;
136 memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, t);
142 memcpy(flipbuf, ch->ch_rbuf + ch->ch_rout, n);
149 * dgrp_input() -- send data to the line disipline
150 * @ch: pointer to channel struct
152 * Copys the rbuf to the flipbuf and sends to line discipline.
153 * Sends input buffer data to the line discipline.
156 static void dgrp_input(struct ch_struct *ch)
158 struct nd_struct *nd;
159 struct tty_struct *tty;
175 spin_lock_irqsave(&nd->nd_lock, lock_flags);
177 myflipbuf = nd->nd_inputbuf;
178 myflipflagbuf = nd->nd_inputflagbuf;
180 if (!ch->ch_open_count) {
181 ch->ch_rout = ch->ch_rin;
185 if (ch->ch_tun.un_flag & UN_CLOSING) {
186 ch->ch_rout = ch->ch_rin;
190 tty = (ch->ch_tun).un_tty;
193 if (!tty || tty->magic != TTY_MAGIC) {
194 ch->ch_rout = ch->ch_rin;
198 tty_count = tty->count;
200 ch->ch_rout = ch->ch_rin;
204 if (tty->closing || test_bit(TTY_CLOSING, &tty->flags)) {
205 ch->ch_rout = ch->ch_rin;
209 spin_unlock_irqrestore(&nd->nd_lock, lock_flags);
211 /* data_len should be the number of chars that we read in */
212 data_len = (ch->ch_rin - ch->ch_rout) & RBUF_MASK;
214 /* len is the amount of data we are going to transfer here */
215 len = tty_buffer_request_room(&ch->port, data_len);
217 /* Check DPA flow control */
218 if ((nd->nd_dpa_debug) &&
219 (nd->nd_dpa_flag & DPA_WAIT_SPACE) &&
220 (nd->nd_dpa_port == MINOR(tty_devnum(ch->ch_tun.un_tty))))
223 if ((len) && !(ch->ch_flag & CH_RXSTOP)) {
225 dgrp_read_data_block(ch, myflipbuf, len);
227 if (I_PARMRK(tty) || I_BRKINT(tty) || I_INPCK(tty))
228 parity_scan(ch, myflipbuf, myflipflagbuf, &len);
230 memset(myflipflagbuf, TTY_NORMAL, len);
232 if ((nd->nd_dpa_debug) &&
233 (nd->nd_dpa_port == PORT_NUM(MINOR(tty_devnum(tty)))))
234 dgrp_dpa_data(nd, 1, myflipbuf, len);
236 tty_insert_flip_string_flags(&ch->port, myflipbuf,
238 tty_flip_buffer_push(&ch->port);
240 ch->ch_rxcount += len;
244 * Wake up any sleepers (maybe dgrp close) that might be waiting
245 * for a channel flag state change.
247 wake_up_interruptible(&ch->ch_flag_wait);
251 spin_unlock_irqrestore(&nd->nd_lock, lock_flags);
258 * Loop to inspect each single character or 0xFF escape.
260 * if PARMRK & ~DOSMODE:
261 * 0xFF 0xFF Normal 0xFF character, escaped
262 * to eliminate confusion.
263 * 0xFF 0x00 0x00 Break
264 * 0xFF 0x00 CC Error character CC.
265 * CC Normal character CC.
267 * if PARMRK & DOSMODE:
268 * 0xFF 0x18 0x00 Break
269 * 0xFF 0x08 0x00 Framing Error
270 * 0xFF 0x04 0x00 Parity error
271 * 0xFF 0x0C 0x00 Both Framing and Parity error
273 * TODO: do we need to do the XMODEM, XOFF, XON, XANY processing??
276 static void parity_scan(struct ch_struct *ch, unsigned char *cbuf,
277 unsigned char *fbuf, int *len)
281 int DOS = ((ch->ch_iflag & IF_DOSMODE) == 0 ? 0 : 1);
282 unsigned char *cout; /* character buffer */
283 unsigned char *fout; /* flag buffer */
295 switch (ch->ch_pscan_state) {
297 /* reset to sanity and fall through */
298 ch->ch_pscan_state = 0 ;
302 if (c == 0xff) /* delete this character from stream */
303 ch->ch_pscan_state = 1;
306 *fout++ = TTY_NORMAL;
314 /* doubled ff, transform to single ff */
316 *fout++ = TTY_NORMAL;
318 ch->ch_pscan_state = 0;
320 /* save value examination in next state */
321 ch->ch_pscan_savechar = c;
322 ch->ch_pscan_state = 2;
327 /* third character of ff sequence */
330 if (ch->ch_pscan_savechar & 0x10)
332 else if (ch->ch_pscan_savechar & 0x08)
336 * either marked as a parity error,
337 * indeterminate, or not in DOSMODE
338 * call it a parity error
340 *fout++ = TTY_PARITY;
342 /* case FF XX ?? where XX is not 00 */
343 if (ch->ch_pscan_savechar & 0xff) {
344 /* this should not happen */
345 pr_info("%s: parity_scan: error unexpected byte\n",
347 *fout++ = TTY_PARITY;
349 /* case FF 00 XX where XX is not 00 */
351 *fout++ = TTY_PARITY;
358 ch->ch_pscan_state = 0;
366 * dgrp_net_idle() -- Idle the network connection
367 * @nd: pointer to node structure to idle
369 static void dgrp_net_idle(struct nd_struct *nd)
371 struct ch_struct *ch;
376 nd->nd_state = NS_IDLE;
379 for (i = nd->nd_seq_out; ; i = (i + 1) & SEQ_MASK) {
380 if (!nd->nd_seq_wait[i]) {
381 nd->nd_seq_wait[i] = 0;
382 wake_up_interruptible(&nd->nd_seq_wque[i]);
385 if (i == nd->nd_seq_in)
389 nd->nd_seq_out = nd->nd_seq_in;
394 nd->nd_tx_module = 0x10;
395 nd->nd_rx_module = 0x00;
397 for (i = 0, ch = nd->nd_chan; i < CHAN_MAX; i++, ch++) {
398 ch->ch_state = CS_IDLE;
401 ch->ch_otype_waiting = 0;
406 * Increase the number of channels, waking up any
407 * threads that might be waiting for the channels
410 static void increase_channel_count(struct nd_struct *nd, int n)
412 struct ch_struct *ch;
413 struct device *classp;
414 char name[DEVICE_NAME_SIZE];
419 for (i = nd->nd_chan_count; i < n; ++i) {
420 ch = nd->nd_chan + i;
422 /* FIXME: return a useful error instead! */
423 buf = kmalloc(TBUF_MAX, GFP_KERNEL);
428 pr_info_ratelimited("%s - ch_tbuf was not NULL\n",
433 buf = kmalloc(RBUF_MAX, GFP_KERNEL);
438 pr_info("%s - ch_rbuf was not NULL\n",
442 classp = tty_port_register_device(&ch->port,
443 nd->nd_serial_ttdriver, i,
446 ch->ch_tun.un_sysfs = classp;
447 snprintf(name, DEVICE_NAME_SIZE, "tty_%d", i);
449 dgrp_create_tty_sysfs(&ch->ch_tun, classp);
450 ret = sysfs_create_link(&nd->nd_class_dev->kobj,
451 &classp->kobj, name);
453 /* NOTE: We don't support "cu" devices anymore,
454 * so you will notice we don't register them
456 if (dgrp_register_prdevices) {
457 classp = tty_register_device(nd->nd_xprint_ttdriver,
459 ch->ch_pun.un_sysfs = classp;
460 snprintf(name, DEVICE_NAME_SIZE, "pr_%d", i);
462 dgrp_create_tty_sysfs(&ch->ch_pun, classp);
463 ret = sysfs_create_link(&nd->nd_class_dev->kobj,
464 &classp->kobj, name);
467 nd->nd_chan_count = i + 1;
468 wake_up_interruptible(&ch->ch_flag_wait);
473 * Decrease the number of channels, and wake up any threads that might
474 * be waiting on the channels that vanished.
476 static void decrease_channel_count(struct nd_struct *nd, int n)
478 struct ch_struct *ch;
479 char name[DEVICE_NAME_SIZE];
482 for (i = nd->nd_chan_count - 1; i >= n; --i) {
483 ch = nd->nd_chan + i;
486 * Make any open ports inoperative.
488 ch->ch_state = CS_IDLE;
491 ch->ch_otype_waiting = 0;
494 * Only "HANGUP" if we care about carrier
495 * transitions and we are already open.
497 if (ch->ch_open_count != 0) {
498 ch->ch_flag |= CH_HANGUP;
503 * Unlike the CH_HANGUP flag above, use another
504 * flag to indicate to the RealPort state machine
505 * that this port has disappeared.
507 if (ch->ch_open_count != 0)
508 ch->ch_flag |= CH_PORT_GONE;
510 wake_up_interruptible(&ch->ch_flag_wait);
512 nd->nd_chan_count = i;
520 nd->nd_chan_count = i;
522 dgrp_remove_tty_sysfs(ch->ch_tun.un_sysfs);
523 snprintf(name, DEVICE_NAME_SIZE, "tty_%d", i);
524 sysfs_remove_link(&nd->nd_class_dev->kobj, name);
525 tty_unregister_device(nd->nd_serial_ttdriver, i);
528 * NOTE: We don't support "cu" devices anymore, so don't
529 * unregister them here anymore.
532 if (dgrp_register_prdevices) {
533 dgrp_remove_tty_sysfs(ch->ch_pun.un_sysfs);
534 snprintf(name, DEVICE_NAME_SIZE, "pr_%d", i);
535 sysfs_remove_link(&nd->nd_class_dev->kobj, name);
536 tty_unregister_device(nd->nd_xprint_ttdriver, i);
542 * dgrp_chan_count() -- Adjust the node channel count.
543 * @nd: pointer to a node structure
544 * @n: new value for channel count
546 * Adjusts the node channel count. If new ports have appeared, it tries
547 * to signal those processes that might have been waiting for ports to
548 * appear. If ports have disappeared it tries to signal those processes
549 * that might be hung waiting for a response for the now non-existant port.
551 static void dgrp_chan_count(struct nd_struct *nd, int n)
553 if (n == nd->nd_chan_count)
556 if (n > nd->nd_chan_count)
557 increase_channel_count(nd, n);
559 if (n < nd->nd_chan_count)
560 decrease_channel_count(nd, n);
564 * dgrp_monitor() -- send data to the device monitor queue
565 * @nd: pointer to a node structure
566 * @buf: data to copy to the monitoring buffer
567 * @len: number of bytes to transfer to the buffer
569 * Called by the net device routines to send data to the device
570 * monitor queue. If the device monitor buffer is too full to
571 * accept the data, it waits until the buffer is ready.
573 static void dgrp_monitor(struct nd_struct *nd, u8 *buf, int len)
582 down(&nd->nd_mon_semaphore);
585 * Loop while data remains.
587 while ((len > 0) && (nd->nd_mon_buf)) {
589 * Determine the amount of available space left in the
590 * buffer. If there's none, wait until some appears.
593 n = (nd->nd_mon_out - nd->nd_mon_in - 1) & MON_MASK;
596 nd->nd_mon_flag |= MON_WAIT_SPACE;
598 up(&nd->nd_mon_semaphore);
601 * Go to sleep waiting until the condition becomes true.
603 rtn = wait_event_interruptible(nd->nd_mon_wqueue,
604 ((nd->nd_mon_flag & MON_WAIT_SPACE) == 0));
606 /* FIXME: really ignore rtn? */
609 * We can't exit here if we receive a signal, since
610 * to do so would trash the debug stream.
613 down(&nd->nd_mon_semaphore);
619 * Copy as much data as will fit.
625 r = MON_MAX - nd->nd_mon_in;
628 memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, r);
638 memcpy(nd->nd_mon_buf + nd->nd_mon_in, buf, n);
645 if (nd->nd_mon_in >= MON_MAX)
646 pr_info_ratelimited("%s - nd_mon_in (%i) >= MON_MAX\n",
647 __func__, nd->nd_mon_in);
650 * Wakeup any thread waiting for data
653 if (nd->nd_mon_flag & MON_WAIT_DATA) {
654 nd->nd_mon_flag &= ~MON_WAIT_DATA;
655 wake_up_interruptible(&nd->nd_mon_wqueue);
660 * Release the monitor lock.
662 up(&nd->nd_mon_semaphore);
666 * dgrp_encode_time() -- Encodes rpdump time into a 4-byte quantity.
667 * @nd: pointer to a node structure
668 * @buf: destination buffer
670 * Encodes "rpdump" time into a 4-byte quantity. Time is measured since
673 static void dgrp_encode_time(struct nd_struct *nd, u8 *buf)
678 * Convert time in HZ since open to time in milliseconds
681 t = jiffies - nd->nd_mon_lbolt;
682 t = 1000 * (t / HZ) + 1000 * (t % HZ) / HZ;
684 put_unaligned_be32((uint)(t & 0xffffffff), buf);
690 * dgrp_monitor_message() -- Builds a rpdump style message.
691 * @nd: pointer to a node structure
692 * @message: destination buffer
694 static void dgrp_monitor_message(struct nd_struct *nd, char *message)
699 header[0] = RPDUMP_MESSAGE;
701 dgrp_encode_time(nd, header + 1);
705 put_unaligned_be16(n, header + 5);
707 dgrp_monitor(nd, header, sizeof(header));
708 dgrp_monitor(nd, (u8 *) message, n);
714 * dgrp_monitor_reset() -- Note a reset in the monitoring buffer.
715 * @nd: pointer to a node structure
717 static void dgrp_monitor_reset(struct nd_struct *nd)
721 header[0] = RPDUMP_RESET;
723 dgrp_encode_time(nd, header + 1);
725 dgrp_monitor(nd, header, sizeof(header));
729 * dgrp_monitor_data() -- builds a monitor data packet
730 * @nd: pointer to a node structure
731 * @type: type of message to be logged
732 * @buf: data to be logged
733 * @size: number of bytes in the buffer
735 static void dgrp_monitor_data(struct nd_struct *nd, u8 type, u8 *buf, int size)
741 dgrp_encode_time(nd, header + 1);
743 put_unaligned_be16(size, header + 5);
745 dgrp_monitor(nd, header, sizeof(header));
746 dgrp_monitor(nd, buf, size);
749 static int alloc_nd_buffers(struct nd_struct *nd)
753 nd->nd_writebuf = NULL;
754 nd->nd_inputbuf = NULL;
755 nd->nd_inputflagbuf = NULL;
758 * Allocate the network read/write buffer.
760 nd->nd_iobuf = kzalloc(UIO_MAX + 10, GFP_KERNEL);
765 * Allocate a buffer for doing the copy from user space to
766 * kernel space in the write routines.
768 nd->nd_writebuf = kzalloc(WRITEBUFLEN, GFP_KERNEL);
769 if (!nd->nd_writebuf)
773 * Allocate a buffer for doing the copy from kernel space to
774 * tty buffer space in the read routines.
776 nd->nd_inputbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
777 if (!nd->nd_inputbuf)
781 * Allocate a buffer for doing the copy from kernel space to
782 * tty buffer space in the read routines.
784 nd->nd_inputflagbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
785 if (!nd->nd_inputflagbuf)
792 kfree(nd->nd_writebuf);
793 kfree(nd->nd_inputbuf);
794 kfree(nd->nd_inputflagbuf);
799 * dgrp_net_open() -- Open the NET device for a particular PortServer
801 static int dgrp_net_open(struct inode *inode, struct file *file)
803 struct nd_struct *nd;
804 struct proc_dir_entry *de;
808 rtn = try_module_get(THIS_MODULE);
812 if (!capable(CAP_SYS_ADMIN)) {
818 * Make sure that the "private_data" field hasn't already been used.
820 if (file->private_data) {
826 * Get the node pointer, and fail if it doesn't exist.
834 nd = (struct nd_struct *) de->data;
840 file->private_data = (void *) nd;
845 down(&nd->nd_net_semaphore);
847 if (nd->nd_state != NS_CLOSED) {
853 * Initialize the link speed parameters.
856 nd->nd_link.lk_fast_rate = UIO_MAX;
857 nd->nd_link.lk_slow_rate = UIO_MAX;
859 nd->nd_link.lk_fast_delay = 1000;
860 nd->nd_link.lk_slow_delay = 1000;
862 nd->nd_link.lk_header_size = 46;
865 rtn = alloc_nd_buffers(nd);
870 * The port is now open, so move it to the IDLE state
874 nd->nd_tx_time = jiffies;
877 * If the polling routing is not running, start it running here
879 spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags);
881 if (!dgrp_poll_data.node_active_count) {
882 dgrp_poll_data.node_active_count = 2;
883 dgrp_poll_data.timer.expires = jiffies +
884 dgrp_poll_tick * HZ / 1000;
885 add_timer(&dgrp_poll_data.timer);
888 spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags);
890 dgrp_monitor_message(nd, "Net Open");
894 * Release the NET lock.
896 up(&nd->nd_net_semaphore);
900 module_put(THIS_MODULE);
905 /* dgrp_net_release() -- close the NET device for a particular PortServer */
906 static int dgrp_net_release(struct inode *inode, struct file *file)
908 struct nd_struct *nd;
911 nd = (struct nd_struct *)(file->private_data);
915 /* TODO : historical locking placeholder */
917 * In the HPUX version of the RealPort driver (which served as a basis
918 * for this driver) this locking code was used. Saved if ever we need
919 * to review the locking under Linux.
921 /* spinlock(&nd->nd_lock); */
927 down(&nd->nd_net_semaphore);
930 * Before "closing" the internal connection, make sure all
935 nd->nd_state = NS_CLOSED;
939 * TODO ... must the wait queue be reset on close?
940 * should any pending waiters be reset?
941 * Let's decide to assert that the waitq is empty... and see
944 if (waitqueue_active(&nd->nd_tx_waitq))
945 pr_info("%s - expected waitqueue_active to be false\n",
953 /* TODO : historical locking placeholder */
955 * In the HPUX version of the RealPort driver (which served as a basis
956 * for this driver) this locking code was used. Saved if ever we need
957 * to review the locking under Linux.
959 /* spinunlock( &nd->nd_lock ); */
962 kfree(nd->nd_writebuf);
963 nd->nd_writebuf = NULL;
965 kfree(nd->nd_inputbuf);
966 nd->nd_inputbuf = NULL;
968 kfree(nd->nd_inputflagbuf);
969 nd->nd_inputflagbuf = NULL;
971 /* TODO : historical locking placeholder */
973 * In the HPUX version of the RealPort driver (which served as a basis
974 * for this driver) this locking code was used. Saved if ever we need
975 * to review the locking under Linux.
977 /* spinlock(&nd->nd_lock); */
980 * Set the active port count to zero.
982 dgrp_chan_count(nd, 0);
984 /* TODO : historical locking placeholder */
986 * In the HPUX version of the RealPort driver (which served as a basis
987 * for this driver) this locking code was used. Saved if ever we need
988 * to review the locking under Linux.
990 /* spinunlock(&nd->nd_lock); */
993 * Release the NET lock.
995 up(&nd->nd_net_semaphore);
998 * Cause the poller to stop scheduling itself if this is
999 * the last active node.
1001 spin_lock_irqsave(&dgrp_poll_data.poll_lock, lock_flags);
1003 if (dgrp_poll_data.node_active_count == 2) {
1004 del_timer(&dgrp_poll_data.timer);
1005 dgrp_poll_data.node_active_count = 0;
1008 spin_unlock_irqrestore(&dgrp_poll_data.poll_lock, lock_flags);
1010 down(&nd->nd_net_semaphore);
1012 dgrp_monitor_message(nd, "Net Close");
1014 up(&nd->nd_net_semaphore);
1017 module_put(THIS_MODULE);
1018 file->private_data = NULL;
1022 /* used in dgrp_send to setup command header */
1023 static inline u8 *set_cmd_header(u8 *b, u8 port, u8 cmd)
1025 *b++ = 0xb0 + (port & 0x0f);
1031 * dgrp_send() -- build a packet for transmission to the server
1032 * @nd: pointer to a node structure
1033 * @tmax: maximum bytes to transmit
1035 * returns number of bytes sent
1037 static int dgrp_send(struct nd_struct *nd, long tmax)
1039 struct ch_struct *ch = nd->nd_chan;
1058 long wanted_sync_port = -1;
1059 ushort tdata[CHAN_MAX];
1062 mbuf = nd->nd_iobuf + UIO_BASE;
1065 send_sync = nd->nd_link.lk_slow_rate < UIO_MAX;
1070 memset(tdata, 0, sizeof(tdata));
1074 * If there are any outstanding requests to be serviced,
1075 * service them here.
1077 if (nd->nd_send & NR_PASSWORD) {
1080 * Send Password response.
1085 put_unaligned_be16(strlen(nd->password), b + 2);
1087 b += strlen(nd->password);
1088 nd->nd_send &= ~(NR_PASSWORD);
1093 * Loop over all modules to generate commands, and determine
1094 * the amount of data queued for transmit.
1097 for (mod = 0, port = 0; port < nd->nd_chan_count; mod++) {
1099 * If this is not the current module, enter a module select
1100 * code in the buffer.
1103 if (mod != nd->nd_tx_module)
1107 * Loop to process one module.
1110 maxport = port + 16;
1112 if (maxport > nd->nd_chan_count)
1113 maxport = nd->nd_chan_count;
1115 for (; port < maxport; port++, ch++) {
1117 * Switch based on channel state.
1120 switch (ch->ch_state) {
1122 * Send requests when the port is closed, and there
1123 * are no Open, Close or Cancel requests expected.
1128 * Wait until any open error code
1129 * has been delivered to all
1133 if (ch->ch_open_error) {
1134 if (ch->ch_wait_count[ch->ch_otype]) {
1139 ch->ch_open_error = 0;
1143 * Wait until the channel HANGUP flag is reset
1144 * before sending the first open. We can only
1145 * get to this state after a server disconnect.
1148 if ((ch->ch_flag & CH_HANGUP) != 0)
1152 * If recovering from a TCP disconnect, or if
1153 * there is an immediate open pending, send an
1154 * Immediate Open request.
1156 if ((ch->ch_flag & CH_PORT_GONE) ||
1157 ch->ch_wait_count[OTYPE_IMMEDIATE] != 0) {
1158 b = set_cmd_header(b, port, 10);
1161 ch->ch_state = CS_WAIT_OPEN;
1162 ch->ch_otype = OTYPE_IMMEDIATE;
1167 * If there is no Persistent or Incoming Open on the wait
1168 * list in the server, and a thread is waiting for a
1169 * Persistent or Incoming Open, send a Persistent or Incoming
1172 if (ch->ch_otype_waiting == 0) {
1173 if (ch->ch_wait_count[OTYPE_PERSISTENT] != 0) {
1174 b = set_cmd_header(b, port, 10);
1177 ch->ch_state = CS_WAIT_OPEN;
1178 ch->ch_otype = OTYPE_PERSISTENT;
1179 } else if (ch->ch_wait_count[OTYPE_INCOMING] != 0) {
1180 b = set_cmd_header(b, port, 10);
1183 ch->ch_state = CS_WAIT_OPEN;
1184 ch->ch_otype = OTYPE_INCOMING;
1190 * If a Persistent or Incoming Open is pending in
1191 * the server, but there is no longer an open
1192 * thread waiting for it, cancel the request.
1195 if (ch->ch_wait_count[ch->ch_otype_waiting] == 0) {
1196 b = set_cmd_header(b, port, 10);
1199 ch->ch_state = CS_WAIT_CANCEL;
1200 ch->ch_otype = ch->ch_otype_waiting;
1205 * Send port parameter queries.
1209 * Clear out all FEP state that might remain
1210 * from the last connection.
1213 ch->ch_flag |= CH_PARAM;
1215 ch->ch_flag &= ~CH_RX_FLUSH;
1251 /* Send Sequence Request */
1252 b = set_cmd_header(b, port, 14);
1254 /* Configure Event Conditions Packet */
1255 b = set_cmd_header(b, port, 42);
1256 put_unaligned_be16(0x02c0, b);
1258 *b++ = (DM_DTR | DM_RTS | DM_CTS |
1259 DM_DSR | DM_RI | DM_CD);
1261 /* Send Status Request */
1262 b = set_cmd_header(b, port, 16);
1264 /* Send Buffer Request */
1265 b = set_cmd_header(b, port, 20);
1267 /* Send Port Capability Request */
1268 b = set_cmd_header(b, port, 22);
1270 ch->ch_expect = (RR_SEQUENCE |
1275 ch->ch_state = CS_WAIT_QUERY;
1277 /* Raise modem signals */
1278 b = set_cmd_header(b, port, 44);
1280 if (ch->ch_flag & CH_PORT_GONE)
1281 ch->ch_s_mout = ch->ch_mout;
1283 ch->ch_s_mout = ch->ch_mout = DM_DTR | DM_RTS;
1286 *b++ = ch->ch_s_mflow = 0;
1287 *b++ = ch->ch_s_mctrl = ch->ch_mctrl = 0;
1289 if (ch->ch_flag & CH_PORT_GONE)
1290 ch->ch_flag &= ~CH_PORT_GONE;
1295 * Handle normal open and ready mode.
1301 * If the port is not open, and there are no
1302 * no longer any ports requesting an open,
1303 * then close the port.
1306 if (ch->ch_open_count == 0 &&
1307 ch->ch_wait_count[ch->ch_otype] == 0) {
1312 * Process waiting input.
1314 * If there is no one to read it, discard the data.
1316 * Otherwise if we are not in fastcook mode, or if there is a
1317 * fastcook thread waiting for data, send the data to the
1320 if (ch->ch_rin != ch->ch_rout) {
1321 if (ch->ch_tun.un_open_count == 0 ||
1322 (ch->ch_tun.un_flag & UN_CLOSING) ||
1323 (ch->ch_cflag & CF_CREAD) == 0) {
1324 ch->ch_rout = ch->ch_rin;
1325 } else if ((ch->ch_flag & CH_FAST_READ) == 0 ||
1326 ch->ch_inwait != 0) {
1329 if (ch->ch_rin != ch->ch_rout)
1335 * Handle receive flush, and changes to
1336 * server port parameters.
1339 if (ch->ch_flag & (CH_RX_FLUSH | CH_PARAM)) {
1341 * If we are in receive flush mode,
1342 * and enough data has gone by, reset
1343 * receive flush mode.
1345 if (ch->ch_flag & CH_RX_FLUSH) {
1346 if (((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >
1347 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK))
1348 ch->ch_flag &= ~CH_RX_FLUSH;
1357 if (ch->ch_s_tmax != ch->ch_tmax ||
1358 ch->ch_s_ttime != ch->ch_ttime) {
1359 b = set_cmd_header(b, port, 48);
1361 ch->ch_s_tmax = ch->ch_tmax;
1362 ch->ch_s_ttime = ch->ch_ttime;
1364 put_unaligned_be16(ch->ch_s_tmax,
1368 put_unaligned_be16(ch->ch_s_ttime,
1377 if (ch->ch_s_rlow != ch->ch_rlow ||
1378 ch->ch_s_rhigh != ch->ch_rhigh) {
1379 b = set_cmd_header(b, port, 45);
1381 ch->ch_s_rlow = ch->ch_rlow;
1382 ch->ch_s_rhigh = ch->ch_rhigh;
1384 put_unaligned_be16(ch->ch_s_rlow,
1388 put_unaligned_be16(ch->ch_s_rhigh,
1394 * Send BRATE, CFLAG, IFLAG,
1398 if (ch->ch_s_brate != ch->ch_brate ||
1399 ch->ch_s_cflag != ch->ch_cflag ||
1400 ch->ch_s_iflag != ch->ch_iflag ||
1401 ch->ch_s_oflag != ch->ch_oflag ||
1402 ch->ch_s_xflag != ch->ch_xflag) {
1403 b = set_cmd_header(b, port, 40);
1405 ch->ch_s_brate = ch->ch_brate;
1406 ch->ch_s_cflag = ch->ch_cflag;
1407 ch->ch_s_iflag = ch->ch_iflag;
1408 ch->ch_s_oflag = ch->ch_oflag;
1409 ch->ch_s_xflag = ch->ch_xflag;
1411 put_unaligned_be16(ch->ch_s_brate,
1415 put_unaligned_be16(ch->ch_s_cflag,
1419 put_unaligned_be16(ch->ch_s_iflag,
1423 put_unaligned_be16(ch->ch_s_oflag,
1427 put_unaligned_be16(ch->ch_s_xflag,
1433 * Send MOUT, MFLOW, MCTRL.
1436 if (ch->ch_s_mout != ch->ch_mout ||
1437 ch->ch_s_mflow != ch->ch_mflow ||
1438 ch->ch_s_mctrl != ch->ch_mctrl) {
1439 b = set_cmd_header(b, port, 44);
1441 *b++ = ch->ch_s_mout = ch->ch_mout;
1442 *b++ = ch->ch_s_mflow = ch->ch_mflow;
1443 *b++ = ch->ch_s_mctrl = ch->ch_mctrl;
1447 * Send Flow control characters.
1450 if (ch->ch_s_xon != ch->ch_xon ||
1451 ch->ch_s_xoff != ch->ch_xoff ||
1452 ch->ch_s_lnext != ch->ch_lnext ||
1453 ch->ch_s_xxon != ch->ch_xxon ||
1454 ch->ch_s_xxoff != ch->ch_xxoff) {
1455 b = set_cmd_header(b, port, 46);
1457 *b++ = ch->ch_s_xon = ch->ch_xon;
1458 *b++ = ch->ch_s_xoff = ch->ch_xoff;
1459 *b++ = ch->ch_s_lnext = ch->ch_lnext;
1460 *b++ = ch->ch_s_xxon = ch->ch_xxon;
1461 *b++ = ch->ch_s_xxoff = ch->ch_xxoff;
1468 if (ch->ch_s_rmax != ch->ch_rmax ||
1469 ch->ch_s_rtime != ch->ch_rtime) {
1470 b = set_cmd_header(b, port, 47);
1472 ch->ch_s_rmax = ch->ch_rmax;
1473 ch->ch_s_rtime = ch->ch_rtime;
1475 put_unaligned_be16(ch->ch_s_rmax,
1479 put_unaligned_be16(ch->ch_s_rtime,
1484 ch->ch_flag &= ~CH_PARAM;
1485 wake_up_interruptible(&ch->ch_flag_wait);
1490 * Handle action commands.
1493 if (ch->ch_send != 0) {
1494 /* int send = ch->ch_send & ~ch->ch_expect; */
1495 send = ch->ch_send & ~ch->ch_expect;
1497 /* Send character immediate */
1498 if ((send & RR_TX_ICHAR) != 0) {
1499 b = set_cmd_header(b, port, 60);
1502 ch->ch_expect |= RR_TX_ICHAR;
1506 if ((send & RR_TX_BREAK) != 0) {
1507 if (ch->ch_break_time != 0) {
1508 b = set_cmd_header(b, port, 61);
1509 put_unaligned_be16(ch->ch_break_time,
1513 ch->ch_expect |= RR_TX_BREAK;
1514 ch->ch_break_time = 0;
1516 ch->ch_send &= ~RR_TX_BREAK;
1517 ch->ch_flag &= ~CH_TX_BREAK;
1518 wake_up_interruptible(&ch->ch_flag_wait);
1523 * Flush input/output buffers.
1526 if ((send & (RR_RX_FLUSH | RR_TX_FLUSH)) != 0) {
1527 b = set_cmd_header(b, port, 62);
1529 *b++ = ((send & RR_TX_FLUSH) == 0 ? 1 :
1530 (send & RR_RX_FLUSH) == 0 ? 2 : 3);
1532 if (send & RR_RX_FLUSH) {
1533 ch->ch_flush_seq = nd->nd_seq_in;
1534 ch->ch_flag |= CH_RX_FLUSH;
1537 wanted_sync_port = port;
1540 ch->ch_send &= ~(RR_RX_FLUSH | RR_TX_FLUSH);
1543 /* Pause input/output */
1544 if ((send & (RR_RX_STOP | RR_TX_STOP)) != 0) {
1545 b = set_cmd_header(b, port, 63);
1548 if ((send & RR_TX_STOP) != 0)
1551 if ((send & RR_RX_STOP) != 0)
1556 ch->ch_send &= ~(RR_RX_STOP | RR_TX_STOP);
1559 /* Start input/output */
1560 if ((send & (RR_RX_START | RR_TX_START)) != 0) {
1561 b = set_cmd_header(b, port, 64);
1564 if ((send & RR_TX_START) != 0)
1565 *b |= EV_OPU | EV_OPS | EV_OPX;
1567 if ((send & RR_RX_START) != 0)
1568 *b |= EV_IPU | EV_IPS;
1572 ch->ch_send &= ~(RR_RX_START | RR_TX_START);
1578 * Send a window sequence to acknowledge received data.
1581 rwin = (ch->ch_s_rin +
1582 ((ch->ch_rout - ch->ch_rin - 1) & RBUF_MASK));
1584 n = (rwin - ch->ch_s_rwin) & 0xffff;
1586 if (n >= RBUF_MAX / 4) {
1587 b[0] = 0xa0 + (port & 0xf);
1588 ch->ch_s_rwin = rwin;
1589 put_unaligned_be16(rwin, b + 1);
1594 * If the terminal is waiting on LOW
1595 * water or EMPTY, and the condition
1596 * is now satisfied, call the line
1597 * discipline to put more data in the
1601 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1603 if ((ch->ch_tun.un_flag & (UN_EMPTY|UN_LOW)) != 0) {
1604 if ((ch->ch_tun.un_flag & UN_LOW) != 0 ?
1606 (n == 0 && ch->ch_s_tpos == ch->ch_s_tin)) {
1607 ch->ch_tun.un_flag &= ~(UN_EMPTY|UN_LOW);
1609 if (waitqueue_active(&((ch->ch_tun.un_tty)->write_wait)))
1610 wake_up_interruptible(&((ch->ch_tun.un_tty)->write_wait));
1611 tty_wakeup(ch->ch_tun.un_tty);
1612 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1617 * If the printer is waiting on LOW
1618 * water, TIME, EMPTY or PWAIT, and is
1619 * now ready to put more data in the
1620 * buffer, call the line discipline to
1624 /* FIXME: jiffies - ch->ch_waketime can never
1625 be < 0. Someone needs to work out what is
1626 actually intended here */
1627 if (ch->ch_pun.un_open_count &&
1628 (ch->ch_pun.un_flag &
1629 (UN_EMPTY|UN_TIME|UN_LOW|UN_PWAIT)) != 0) {
1631 if ((ch->ch_pun.un_flag & UN_LOW) != 0 ?
1633 (ch->ch_pun.un_flag & UN_TIME) != 0 ?
1634 ((jiffies - ch->ch_waketime) >= 0) :
1635 (n == 0 && ch->ch_s_tpos == ch->ch_s_tin) &&
1636 ((ch->ch_pun.un_flag & UN_EMPTY) != 0 ||
1637 ((ch->ch_tun.un_open_count &&
1638 ch->ch_tun.un_tty->ops->chars_in_buffer) ?
1639 (ch->ch_tun.un_tty->ops->chars_in_buffer)(ch->ch_tun.un_tty) == 0
1643 ch->ch_pun.un_flag &= ~(UN_EMPTY | UN_TIME | UN_LOW | UN_PWAIT);
1645 if (waitqueue_active(&((ch->ch_pun.un_tty)->write_wait)))
1646 wake_up_interruptible(&((ch->ch_pun.un_tty)->write_wait));
1647 tty_wakeup(ch->ch_pun.un_tty);
1648 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1650 } else if ((ch->ch_pun.un_flag & UN_TIME) != 0) {
1657 * Determine the max number of bytes
1658 * this port can send, including
1659 * packet header overhead.
1662 t = ((ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff);
1668 n += (n <= 8 ? 1 : n <= 255 ? 2 : 3);
1681 b = set_cmd_header(b, port, 10);
1682 if (ch->ch_otype == OTYPE_IMMEDIATE)
1687 ch->ch_state = CS_WAIT_CLOSE;
1691 * Wait for a previous server request.
1695 case CS_WAIT_CANCEL:
1702 pr_info("%s - unexpected channel state (%i)\n",
1703 __func__, ch->ch_state);
1708 * If a module select code is needed, drop one in. If space
1709 * was reserved for one, but none is needed, recover the space.
1712 if (mod != nd->nd_tx_module) {
1714 mbuf[-1] = 0xf0 | mod;
1715 nd->nd_tx_module = mod;
1723 * Adjust "tmax" so that under worst case conditions we do
1724 * not overflow either the daemon buffer or the internal
1725 * buffer in the loop that follows. Leave a safe area
1726 * of 64 bytes so we start getting asserts before we start
1727 * losing data or clobbering memory.
1730 n = UIO_MAX - UIO_BASE;
1740 * Allocate space for 5 Module Selects, 1 Sequence Request,
1741 * and 1 Set TREQ for each active channel.
1744 tmax -= 5 + 3 + 4 * nd->nd_chan_count;
1747 * Further reduce "tmax" to the available transmit credit.
1748 * Note that this is a soft constraint; The transmit credit
1749 * can go negative for a time and then recover.
1752 n = nd->nd_tx_deposit - nd->nd_tx_charge - nd->nd_link.lk_header_size;
1758 * Finally reduce tmax by the number of bytes already in
1765 * Suspend data transmit unless every ready channel can send
1766 * at least 1 character.
1768 if (tmax < 2 * nd->nd_chan_count) {
1771 } else if (tchan > 1 && ttotal > tmax) {
1774 * If transmit is limited by the credit budget, find the
1775 * largest number of characters we can send without driving
1776 * the credit negative.
1785 for (try = 0; try < 3; try++) {
1789 for (i = 0; i < tc; i++) {
1790 if (tsend < tdata[i])
1791 tdata[c++] = tdata[i];
1807 tsend = tm / nd->nd_chan_count;
1814 * If no budgetary constraints, or only one channel ready
1815 * to send, set the character limit to the remaining
1822 tsend -= (tsend <= 9) ? 1 : (tsend <= 257) ? 2 : 3;
1825 * Loop over all channels, sending queued data.
1832 for (mod = 0; port < nd->nd_chan_count; mod++) {
1834 * If this is not the current module, enter a module select
1835 * code in the buffer.
1838 if (mod != nd->nd_tx_module)
1842 * Loop to process one module.
1845 maxport = port + 16;
1847 if (maxport > nd->nd_chan_count)
1848 maxport = nd->nd_chan_count;
1850 for (; port < maxport; port++, ch++) {
1851 if (ch->ch_state != CS_READY)
1856 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1859 * If there is data that can be sent, send it.
1862 if (n != 0 && used_buffer > 0) {
1863 t = (ch->ch_s_tsize + ch->ch_s_tpos - ch->ch_s_tin) & 0xffff;
1873 if (n > used_buffer) {
1882 * Create the correct size transmit header,
1883 * depending on the amount of data to transmit.
1888 b[0] = ((n - 1) << 4) + (port & 0xf);
1891 } else if (n <= 255) {
1893 b[0] = 0x80 + (port & 0xf);
1899 b[0] = 0x90 + (port & 0xf);
1900 put_unaligned_be16(n, b + 1);
1904 ch->ch_s_tin = (ch->ch_s_tin + n) & 0xffff;
1907 * Copy transmit data to the packet.
1910 t = TBUF_MAX - ch->ch_tout;
1913 memcpy(b, ch->ch_tbuf + ch->ch_tout, t);
1920 memcpy(b, ch->ch_tbuf + ch->ch_tout, n);
1924 n = (ch->ch_tin - ch->ch_tout) & TBUF_MASK;
1928 * Wake any terminal unit process waiting in the
1929 * dgrp_write routine for low water.
1935 if ((ch->ch_flag & CH_LOW) != 0) {
1936 ch->ch_flag &= ~CH_LOW;
1937 wake_up_interruptible(&ch->ch_flag_wait);
1940 /* selwakeup tty_sel */
1941 if (ch->ch_tun.un_open_count) {
1942 struct tty_struct *tty = (ch->ch_tun.un_tty);
1944 if (waitqueue_active(&tty->write_wait))
1945 wake_up_interruptible(&tty->write_wait);
1950 if (ch->ch_pun.un_open_count) {
1951 struct tty_struct *tty = (ch->ch_pun.un_tty);
1953 if (waitqueue_active(&tty->write_wait))
1954 wake_up_interruptible(&tty->write_wait);
1960 * Do EMPTY processing.
1966 if ((ch->ch_flag & (CH_EMPTY | CH_DRAIN)) != 0 ||
1967 (ch->ch_pun.un_flag & UN_EMPTY) != 0) {
1969 * If there is still data in the server, ask the server
1970 * to notify us when its all gone.
1973 if (ch->ch_s_treq != ch->ch_s_tin) {
1974 b = set_cmd_header(b, port, 43);
1976 ch->ch_s_treq = ch->ch_s_tin;
1977 put_unaligned_be16(ch->ch_s_treq,
1983 * If there is a thread waiting for buffer empty,
1984 * and we are truly empty, wake the thread.
1987 else if ((ch->ch_flag & CH_EMPTY) != 0 &&
1988 (ch->ch_send & RR_TX_BREAK) == 0) {
1989 ch->ch_flag &= ~CH_EMPTY;
1991 wake_up_interruptible(&ch->ch_flag_wait);
1997 * If a module select code is needed, drop one in. If space
1998 * was reserved for one, but none is needed, recover the space.
2001 if (mod != nd->nd_tx_module) {
2003 mbuf[-1] = 0xf0 | mod;
2004 nd->nd_tx_module = mod;
2012 * Send a synchronization sequence associated with the last open
2013 * channel that sent data, and remember the time when the data was
2019 if ((send_sync || nd->nd_seq_wait[in] != 0) && lastport >= 0) {
2023 * Attempt the use the port that really wanted the sync.
2024 * This gets around a race condition where the "lastport" is in
2025 * the middle of the close() routine, and by the time we
2026 * send this command, it will have already acked the close, and
2027 * thus not send the sync response.
2029 if (wanted_sync_port >= 0)
2030 lastport = wanted_sync_port;
2032 * Set a flag just in case the port is in the middle of a close,
2033 * it will not be permitted to actually close until we get an
2034 * sync response, and clear the flag there.
2036 ch = nd->nd_chan + lastport;
2037 ch->ch_flag |= CH_WAITING_SYNC;
2039 mod = lastport >> 4;
2041 if (mod != nd->nd_tx_module) {
2045 nd->nd_tx_module = mod;
2048 bb = set_cmd_header(bb, lastport, 12);
2051 nd->nd_seq_size[in] = bb - buf;
2052 nd->nd_seq_time[in] = jiffies;
2054 if (++in >= SEQ_MAX)
2057 if (in != nd->nd_seq_out) {
2060 nd->nd_unack += b - buf;
2065 * If there are no open ports, a sync cannot be sent.
2066 * There is nothing left to wait for anyway, so wake any
2067 * thread waiting for an acknowledgement.
2070 else if (nd->nd_seq_wait[in] != 0) {
2071 nd->nd_seq_wait[in] = 0;
2073 wake_up_interruptible(&nd->nd_seq_wque[in]);
2077 * If there is no traffic for an interval of IDLE_MAX, then
2078 * send a single byte packet.
2082 nd->nd_tx_time = jiffies;
2083 } else if ((ulong)(jiffies - nd->nd_tx_time) >= IDLE_MAX) {
2084 *b++ = 0xf0 | nd->nd_tx_module;
2085 nd->nd_tx_time = jiffies;
2091 pr_info("%s - n(%i) >= tsafe(%i)\n",
2092 __func__, n, tsafe);
2097 nd->nd_tx_work = work;
2104 * Data to be sent TO the PortServer from the "async." half of the driver.
2106 static ssize_t dgrp_net_read(struct file *file, char __user *buf, size_t count,
2109 struct nd_struct *nd;
2116 * Get the node pointer, and quit if it doesn't exist.
2118 nd = (struct nd_struct *)(file->private_data);
2122 if (count < UIO_MIN)
2126 * Only one read/write operation may be in progress at
2131 * Grab the NET lock.
2133 down(&nd->nd_net_semaphore);
2135 nd->nd_read_count++;
2137 nd->nd_tx_ready = 0;
2140 * Determine the effective size of the buffer.
2143 if (nd->nd_remain > UIO_BASE)
2144 pr_info_ratelimited("%s - nd_remain(%i) > UIO_BASE\n",
2145 __func__, nd->nd_remain);
2147 b = local_buf = nd->nd_iobuf + UIO_BASE;
2150 * Generate data according to the node state.
2153 switch (nd->nd_state) {
2155 * Initialize the connection.
2160 dgrp_monitor_reset(nd);
2163 * Request a Product ID Packet.
2170 nd->nd_expect |= NR_IDENT;
2173 * Request a Server Capability ID Response.
2180 nd->nd_expect |= NR_CAPABILITY;
2183 * Request a Server VPD Response.
2190 nd->nd_expect |= NR_VPD;
2192 nd->nd_state = NS_WAIT_QUERY;
2196 * We do serious communication with the server only in
2201 b = dgrp_send(nd, count) + local_buf;
2205 * Send off an error after receiving a bogus message
2210 n = strlen(nd->nd_error);
2214 memcpy(b + 2, nd->nd_error, n);
2219 * Set the active port count to zero.
2221 dgrp_chan_count(nd, 0);
2231 nd->nd_send_count++;
2233 nd->nd_tx_byte += n + nd->nd_link.lk_header_size;
2234 nd->nd_tx_charge += n + nd->nd_link.lk_header_size;
2237 rtn = copy_to_user((void __user *)buf, local_buf, n);
2248 dgrp_monitor_data(nd, RPDUMP_CLIENT, local_buf, n);
2251 * Release the NET lock.
2254 up(&nd->nd_net_semaphore);
2260 * dgrp_receive() -- decode data packets received from the remote PortServer.
2261 * @nd: pointer to a node structure
2263 static void dgrp_receive(struct nd_struct *nd)
2265 struct ch_struct *ch;
2282 nd->nd_tx_time = jiffies;
2284 ID_TO_CHAR(nd->nd_ID, ID);
2286 b = buf = nd->nd_iobuf;
2287 remain = nd->nd_remain;
2290 * Loop to process Realport protocol packets.
2293 while (remain > 0) {
2295 int n1 = b[0] & 0x0f;
2298 port = (nd->nd_rx_module << 4) + n1;
2300 if (port >= nd->nd_chan_count) {
2301 error = "Improper Port Number";
2305 ch = nd->nd_chan + port;
2312 * Process by major packet type.
2318 * Process 1-byte header data packet.
2336 * Process 2-byte header data packet.
2350 * Process 3-byte header data packet.
2357 dlen = get_unaligned_be16(b + 1);
2363 * Common packet handling code.
2370 * Otherwise data should appear only when we are
2371 * in the CS_READY state.
2374 if (ch->ch_state < CS_READY) {
2375 error = "Data received before RWIN established";
2380 * Assure that the data received is within the
2384 n = (ch->ch_s_rwin - ch->ch_s_rin) & 0xffff;
2387 error = "Receive data overrun";
2392 * If we received 3 or less characters,
2393 * assume it is a human typing, and set RTIME
2394 * to 10 milliseconds.
2396 * If we receive 10 or more characters,
2397 * assume its not a human typing, and set RTIME
2398 * to 100 milliseconds.
2401 if (ch->ch_edelay != DGRP_RTIME) {
2402 if (ch->ch_rtime != ch->ch_edelay) {
2403 ch->ch_rtime = ch->ch_edelay;
2404 ch->ch_flag |= CH_PARAM;
2406 } else if (dlen <= 3) {
2407 if (ch->ch_rtime != 10) {
2409 ch->ch_flag |= CH_PARAM;
2412 if (ch->ch_rtime != DGRP_RTIME) {
2413 ch->ch_rtime = DGRP_RTIME;
2414 ch->ch_flag |= CH_PARAM;
2419 * If a portion of the packet is outside the
2420 * buffer, shorten the effective length of the
2421 * data packet to be the amount of data received.
2425 dlen -= plen - remain;
2428 * Detect if receive flush is now complete.
2431 if ((ch->ch_flag & CH_RX_FLUSH) != 0 &&
2432 ((ch->ch_flush_seq - nd->nd_seq_out) & SEQ_MASK) >=
2433 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2434 ch->ch_flag &= ~CH_RX_FLUSH;
2438 * If we are ready to receive, move the data into
2439 * the receive buffer.
2442 ch->ch_s_rin = (ch->ch_s_rin + dlen) & 0xffff;
2444 if (ch->ch_state == CS_READY &&
2445 (ch->ch_tun.un_open_count != 0) &&
2446 (ch->ch_tun.un_flag & UN_CLOSING) == 0 &&
2447 (ch->ch_cflag & CF_CREAD) != 0 &&
2448 (ch->ch_flag & (CH_BAUD0 | CH_RX_FLUSH)) == 0 &&
2449 (ch->ch_send & RR_RX_FLUSH) == 0) {
2451 if (ch->ch_rin + dlen >= RBUF_MAX) {
2452 n = RBUF_MAX - ch->ch_rin;
2454 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, n);
2461 memcpy(ch->ch_rbuf + ch->ch_rin, dbuf, dlen);
2467 * If we are not in fastcook mode, or
2468 * if there is a fastcook thread
2469 * waiting for data, send the data to
2470 * the line discipline.
2473 if ((ch->ch_flag & CH_FAST_READ) == 0 ||
2474 ch->ch_inwait != 0) {
2479 * If there is a read thread waiting
2480 * in select, and we are in fastcook
2481 * mode, wake him up.
2484 if (waitqueue_active(&ch->ch_tun.un_tty->read_wait) &&
2485 (ch->ch_flag & CH_FAST_READ) != 0)
2486 wake_up_interruptible(&ch->ch_tun.un_tty->read_wait);
2489 * Wake any thread waiting in the
2493 if ((ch->ch_flag & CH_INPUT) != 0) {
2494 ch->ch_flag &= ~CH_INPUT;
2496 wake_up_interruptible(&ch->ch_flag_wait);
2501 * Fabricate and insert a data packet header to
2502 * preced the remaining data when it comes in.
2505 if (remain < plen) {
2506 dlen = plen - remain;
2510 put_unaligned_be16(dlen, b + 1);
2518 * Handle Window Sequence packets.
2529 ushort tpos = get_unaligned_be16(b + 1);
2531 ushort ack = (tpos - ch->ch_s_tpos) & 0xffff;
2532 ushort unack = (ch->ch_s_tin - ch->ch_s_tpos) & 0xffff;
2533 ushort notify = (ch->ch_s_treq - ch->ch_s_tpos) & 0xffff;
2535 if (ch->ch_state < CS_READY || ack > unack) {
2536 error = "Improper Window Sequence";
2540 ch->ch_s_tpos = tpos;
2543 ch->ch_s_treq = tpos;
2548 * Handle Command response packets.
2554 * RealPort engine fix - 03/11/2004
2556 * This check did not used to be here.
2558 * We were using b[1] without verifying that the data
2559 * is actually there and valid. On a split packet, it
2562 * NOTE: I have never actually seen the failure happen
2563 * under Linux, but since I have seen it occur
2564 * under both Solaris and HP-UX, the assumption
2565 * is that it *could* happen here as well...
2574 * Handle Open Response.
2587 port = get_unaligned_be16(b + 4);
2589 if (port >= nd->nd_chan_count) {
2590 error = "Open channel number out of range";
2594 ch = nd->nd_chan + port;
2597 * How we handle an open response depends primarily
2598 * on our current channel state.
2601 switch (ch->ch_state) {
2605 * Handle a delayed open.
2608 if (ch->ch_otype_waiting != 0 &&
2609 req == ch->ch_otype_waiting &&
2612 ch->ch_otype_waiting = 0;
2613 ch->ch_state = CS_SEND_QUERY;
2621 * Handle the open response.
2624 if (req == ch->ch_otype) {
2628 * On successful response, open the
2629 * port and proceed normally.
2633 ch->ch_state = CS_SEND_QUERY;
2637 * On a busy response to a persistent open,
2638 * remember that the open is pending.
2643 if (req != OTYPE_IMMEDIATE) {
2644 ch->ch_otype_waiting = req;
2645 ch->ch_state = CS_IDLE;
2650 * Otherwise the server open failed. If
2651 * the Unix port is open, hang it up.
2655 if (ch->ch_open_count != 0) {
2656 ch->ch_flag |= CH_HANGUP;
2658 ch->ch_state = CS_IDLE;
2662 ch->ch_open_error = resp;
2663 ch->ch_state = CS_IDLE;
2665 wake_up_interruptible(&ch->ch_flag_wait);
2671 * Handle delayed response arrival preceding
2672 * the open response we are waiting for.
2675 if (ch->ch_otype_waiting != 0 &&
2676 req == ch->ch_otype_waiting &&
2678 ch->ch_otype = ch->ch_otype_waiting;
2679 ch->ch_otype_waiting = 0;
2680 ch->ch_state = CS_WAIT_FAIL;
2689 * Handle response to immediate open arriving
2690 * after a delayed open success.
2693 if (req == OTYPE_IMMEDIATE) {
2694 ch->ch_state = CS_SEND_QUERY;
2700 case CS_WAIT_CANCEL:
2702 * Handle delayed open response arriving before
2703 * the cancel response.
2706 if (req == ch->ch_otype_waiting &&
2708 ch->ch_otype_waiting = 0;
2713 * Handle cancel response.
2716 if (req == 4 && resp == 0) {
2717 ch->ch_otype_waiting = 0;
2718 ch->ch_state = CS_IDLE;
2726 * Handle a successful response to a port
2731 ch->ch_state = CS_IDLE;
2739 error = "Improper Open Response";
2747 * Handle Synchronize Response.
2759 * If channel was waiting for this sync response,
2760 * unset the flag, and wake up anyone waiting
2763 if (ch->ch_flag & CH_WAITING_SYNC) {
2764 ch->ch_flag &= ~(CH_WAITING_SYNC);
2765 wake_up_interruptible(&ch->ch_flag_wait);
2768 if (((seq - nd->nd_seq_out) & SEQ_MASK) >=
2769 ((nd->nd_seq_in - nd->nd_seq_out) & SEQ_MASK)) {
2773 for (s = nd->nd_seq_out;; s = (s + 1) & SEQ_MASK) {
2774 if (nd->nd_seq_wait[s] != 0) {
2775 nd->nd_seq_wait[s] = 0;
2777 wake_up_interruptible(&nd->nd_seq_wque[s]);
2780 nd->nd_unack -= nd->nd_seq_size[s];
2786 nd->nd_seq_out = (seq + 1) & SEQ_MASK;
2791 * Handle Sequence Response.
2800 /* Record that we have received the Sequence
2801 * Response, but we aren't interested in the
2802 * sequence numbers. We were using RIN like it
2803 * was ROUT and that was causing problems,
2804 * fixed 7-13-2001 David Fries. See comment in
2805 * drp.h for ch_s_rin variable.
2806 int rin = get_unaligned_be16(b + 2);
2807 int tpos = get_unaligned_be16(b + 4);
2810 ch->ch_send &= ~RR_SEQUENCE;
2811 ch->ch_expect &= ~RR_SEQUENCE;
2816 * Handle Status Response.
2825 ch->ch_s_elast = get_unaligned_be16(b + 2);
2826 ch->ch_s_mlast = b[4];
2828 ch->ch_expect &= ~RR_STATUS;
2829 ch->ch_send &= ~RR_STATUS;
2832 * CH_PHYS_CD is cleared because something _could_ be
2833 * waiting for the initial sense of carrier... and if
2834 * carrier is high immediately, we want to be sure to
2835 * wake them as soon as possible.
2837 ch->ch_flag &= ~CH_PHYS_CD;
2844 * Handle Line Error Response.
2855 * Handle Buffer Response.
2864 ch->ch_s_rsize = get_unaligned_be16(b + 2);
2865 ch->ch_s_tsize = get_unaligned_be16(b + 4);
2867 ch->ch_send &= ~RR_BUFFER;
2868 ch->ch_expect &= ~RR_BUFFER;
2873 * Handle Port Capability Response.
2882 ch->ch_send &= ~RR_CAPABILITY;
2883 ch->ch_expect &= ~RR_CAPABILITY;
2887 * When all queries are complete, set those parameters
2888 * derived from the query results, then transition
2889 * to the READY state.
2893 if (ch->ch_state == CS_WAIT_QUERY &&
2894 (ch->ch_expect & (RR_SEQUENCE |
2897 RR_CAPABILITY)) == 0) {
2898 ch->ch_tmax = ch->ch_s_tsize / 4;
2900 if (ch->ch_edelay == DGRP_TTIME)
2901 ch->ch_ttime = DGRP_TTIME;
2903 ch->ch_ttime = ch->ch_edelay;
2905 ch->ch_rmax = ch->ch_s_rsize / 4;
2907 if (ch->ch_edelay == DGRP_RTIME)
2908 ch->ch_rtime = DGRP_RTIME;
2910 ch->ch_rtime = ch->ch_edelay;
2912 ch->ch_rlow = 2 * ch->ch_s_rsize / 8;
2913 ch->ch_rhigh = 6 * ch->ch_s_rsize / 8;
2915 ch->ch_state = CS_READY;
2918 wake_up_interruptible(&ch->ch_flag_wait);
2937 mlast = ch->ch_s_mlast;
2938 elast = ch->ch_s_elast;
2940 mstat = ch->ch_s_mlast = b[1];
2941 estat = ch->ch_s_elast = get_unaligned_be16(b + 2);
2944 * Handle modem changes.
2947 if (((mstat ^ mlast) & DM_CD) != 0)
2952 * Handle received break.
2955 if ((estat & ~elast & EV_RXB) != 0 &&
2956 (ch->ch_tun.un_open_count != 0) &&
2957 I_BRKINT(ch->ch_tun.un_tty) &&
2958 !(I_IGNBRK(ch->ch_tun.un_tty))) {
2960 tty_buffer_request_room(&ch->port, 1);
2961 tty_insert_flip_char(&ch->port, 0, TTY_BREAK);
2962 tty_flip_buffer_push(&ch->port);
2967 * On transmit break complete, if more break traffic
2968 * is waiting then send it. Otherwise wake any threads
2969 * waiting for transmitter empty.
2972 if ((~estat & elast & EV_TXB) != 0 &&
2973 (ch->ch_expect & RR_TX_BREAK) != 0) {
2977 ch->ch_expect &= ~RR_TX_BREAK;
2979 if (ch->ch_break_time != 0) {
2980 ch->ch_send |= RR_TX_BREAK;
2982 ch->ch_send &= ~RR_TX_BREAK;
2983 ch->ch_flag &= ~CH_TX_BREAK;
2984 wake_up_interruptible(&ch->ch_flag_wait);
2991 error = "Unrecognized command";
2995 * Decode Special Codes.
3001 * One byte module select.
3013 nd->nd_rx_module = n1;
3017 * Two byte module select.
3025 nd->nd_rx_module = b[1];
3029 * ID Request packet.
3036 plen = get_unaligned_be16(b + 2);
3038 if (plen < 12 || plen > 1000) {
3039 error = "Response Packet length error";
3051 nd->nd_send |= NR_ECHO;
3055 * ID Response packet.
3059 nd->nd_send |= NR_IDENT;
3063 * ID Response packet.
3067 nd->nd_send |= NR_PASSWORD;
3074 * Various node-level response packets.
3081 plen = get_unaligned_be16(b + 2);
3083 if (plen < 4 || plen > 1000) {
3084 error = "Response Packet length error";
3096 nd->nd_expect &= ~NR_ECHO;
3100 * Product Response Packet.
3107 nd->nd_hw_ver = (b[8] << 8) | b[9];
3108 nd->nd_sw_ver = (b[10] << 8) | b[11];
3109 nd->nd_hw_id = b[6];
3110 desclen = ((plen - 12) > MAX_DESC_LEN) ? MAX_DESC_LEN :
3114 error = "Response Packet desclen error";
3118 strncpy(nd->nd_ps_desc, b + 12, desclen);
3119 nd->nd_ps_desc[desclen] = 0;
3122 nd->nd_expect &= ~NR_IDENT;
3126 * Capability Response Packet.
3131 int nn = get_unaligned_be16(b + 4);
3136 dgrp_chan_count(nd, nn);
3139 nd->nd_expect &= ~NR_CAPABILITY;
3143 * VPD Response Packet.
3148 * NOTE: case 15 is here ONLY because the EtherLite
3149 * is broken, and sends a response to 24 back as 15.
3150 * To resolve this, the EtherLite firmware is now
3151 * fixed to send back 24 correctly, but, for backwards
3152 * compatibility, we now have reserved 15 for the
3153 * bad EtherLite response to 24 as well.
3161 * If the product doesn't support VPD,
3162 * it will send back a null IDRESP,
3163 * which is a length of 4 bytes.
3166 memcpy(nd->nd_vpd, b + 4, min(plen - 4, (long) VPDSIZE));
3167 nd->nd_vpd_len = min(plen - 4, (long) VPDSIZE);
3170 nd->nd_expect &= ~NR_VPD;
3177 if (nd->nd_expect == 0 &&
3178 nd->nd_state == NS_WAIT_QUERY) {
3179 nd->nd_state = NS_READY;
3191 plen = get_unaligned_be16(b + 2) + 4;
3194 error = "Debug Packet too large";
3203 * Handle reset packet.
3222 error = "Client Reset Acknowledge";
3239 * When the buffer is exhausted, copy any data left at the
3240 * top of the buffer back down to the bottom for the next
3245 if (remain > 0 && b != buf)
3246 memcpy(buf, b, remain);
3248 nd->nd_remain = remain;
3252 * Handle a decode error.
3256 error = "Protocol decode error";
3259 * Handle a general protocol error.
3264 nd->nd_state = NS_SEND_ERROR;
3265 nd->nd_error = error;
3269 * dgrp_net_write() -- write data to the network device.
3271 * A zero byte write indicates that the connection to the RealPort
3272 * device has been broken.
3274 * A non-zero write indicates data from the RealPort device.
3276 static ssize_t dgrp_net_write(struct file *file, const char __user *buf,
3277 size_t count, loff_t *ppos)
3279 struct nd_struct *nd;
3285 * Get the node pointer, and quit if it doesn't exist.
3287 nd = (struct nd_struct *)(file->private_data);
3292 * Grab the NET lock.
3294 down(&nd->nd_net_semaphore);
3296 nd->nd_write_count++;
3299 * Handle disconnect.
3305 * Set the active port count to zero.
3307 dgrp_chan_count(nd, 0);
3312 * Loop to process entire receive packet.
3316 n = UIO_MAX - nd->nd_remain;
3321 nd->nd_rx_byte += n + nd->nd_link.lk_header_size;
3323 rtn = copy_from_user(nd->nd_iobuf + nd->nd_remain,
3324 (void __user *) buf + total, n);
3337 dgrp_monitor_data(nd, RPDUMP_SERVER,
3338 nd->nd_iobuf + nd->nd_remain, n);
3349 * Release the NET lock.
3351 up(&nd->nd_net_semaphore);
3359 * Determine whether a device is ready to be read or written to, and
3362 static unsigned int dgrp_net_select(struct file *file,
3363 struct poll_table_struct *table)
3365 unsigned int retval = 0;
3366 struct nd_struct *nd = file->private_data;
3368 poll_wait(file, &nd->nd_tx_waitq, table);
3370 if (nd->nd_tx_ready)
3371 retval |= POLLIN | POLLRDNORM; /* Conditionally readable */
3373 retval |= POLLOUT | POLLWRNORM; /* Always writeable */
3381 * Implement those functions which allow the network daemon to control
3382 * the network parameters in the driver. The ioctls include ones to
3383 * get and set the link speed parameters for the PortServer.
3385 static long dgrp_net_ioctl(struct file *file, unsigned int cmd,
3388 struct nd_struct *nd;
3390 long size = _IOC_SIZE(cmd);
3391 struct link_struct link;
3393 nd = file->private_data;
3395 if (_IOC_DIR(cmd) & _IOC_READ)
3396 rtn = access_ok(VERIFY_WRITE, (void __user *) arg, size);
3397 else if (_IOC_DIR(cmd) & _IOC_WRITE)
3398 rtn = access_ok(VERIFY_READ, (void __user *) arg, size);
3405 if (size != sizeof(struct link_struct))
3408 if (copy_from_user((void *)(&link), (void __user *) arg, size))
3411 if (link.lk_fast_rate < 9600)
3412 link.lk_fast_rate = 9600;
3414 if (link.lk_slow_rate < 2400)
3415 link.lk_slow_rate = 2400;
3417 if (link.lk_fast_rate > 10000000)
3418 link.lk_fast_rate = 10000000;
3420 if (link.lk_slow_rate > link.lk_fast_rate)
3421 link.lk_slow_rate = link.lk_fast_rate;
3423 if (link.lk_fast_delay > 2000)
3424 link.lk_fast_delay = 2000;
3426 if (link.lk_slow_delay > 10000)
3427 link.lk_slow_delay = 10000;
3429 if (link.lk_fast_delay < 60)
3430 link.lk_fast_delay = 60;
3432 if (link.lk_slow_delay < link.lk_fast_delay)
3433 link.lk_slow_delay = link.lk_fast_delay;
3435 if (link.lk_header_size < 2)
3436 link.lk_header_size = 2;
3438 if (link.lk_header_size > 128)
3439 link.lk_header_size = 128;
3441 link.lk_fast_rate /= 8 * 1000 / dgrp_poll_tick;
3442 link.lk_slow_rate /= 8 * 1000 / dgrp_poll_tick;
3444 link.lk_fast_delay /= dgrp_poll_tick;
3445 link.lk_slow_delay /= dgrp_poll_tick;
3452 if (size != sizeof(struct link_struct))
3455 if (copy_to_user((void __user *)arg, (void *)(&nd->nd_link),
3470 * dgrp_poll_handler() -- handler for poll timer
3472 * As each timer expires, it determines (a) whether the "transmit"
3473 * waiter needs to be woken up, and (b) whether the poller needs to
3476 void dgrp_poll_handler(unsigned long arg)
3478 struct dgrp_poll_data *poll_data;
3479 struct nd_struct *nd;
3480 struct link_struct *lk;
3486 poll_data = (struct dgrp_poll_data *) arg;
3487 freq = 1000 / poll_data->poll_tick;
3488 poll_data->poll_round += 17;
3490 if (poll_data->poll_round >= freq)
3491 poll_data->poll_round -= freq;
3494 * Loop to process all open nodes.
3496 * For each node, determine the rate at which it should
3497 * be transmitting data. Then if the node should wake up
3498 * and transmit data now, enable the net receive select
3499 * to get the transmit going.
3502 list_for_each_entry(nd, &nd_struct_list, list) {
3507 * Decrement statistics. These are only for use with
3508 * KME, so don't worry that the operations are done
3509 * unlocked, and so the results are occasionally wrong.
3512 nd->nd_read_count -= (nd->nd_read_count +
3513 poll_data->poll_round) / freq;
3514 nd->nd_write_count -= (nd->nd_write_count +
3515 poll_data->poll_round) / freq;
3516 nd->nd_send_count -= (nd->nd_send_count +
3517 poll_data->poll_round) / freq;
3518 nd->nd_tx_byte -= (nd->nd_tx_byte +
3519 poll_data->poll_round) / freq;
3520 nd->nd_rx_byte -= (nd->nd_rx_byte +
3521 poll_data->poll_round) / freq;
3524 * Wake the daemon to transmit data only when there is
3525 * enough byte credit to send data.
3527 * The results are approximate because the operations
3528 * are performed unlocked, and we are inspecting
3529 * data asynchronously updated elsewhere. The whole
3530 * thing is just approximation anyway, so that should
3534 if (lk->lk_slow_rate >= UIO_MAX) {
3537 nd->nd_rate = UIO_MAX;
3539 nd->nd_tx_deposit = nd->nd_tx_charge + 3 * UIO_MAX;
3540 nd->nd_tx_credit = 3 * UIO_MAX;
3551 long seq_in = nd->nd_seq_in;
3552 long seq_out = nd->nd_seq_out;
3555 * If there are no outstanding packets, run at the
3559 if (seq_in == seq_out) {
3561 rate = lk->lk_fast_rate;
3565 * Otherwise compute the transmit rate based on the
3566 * delay since the oldest packet.
3571 * The actual delay is computed as the
3572 * time since the oldest unacknowledged
3573 * packet was sent, minus the time it
3574 * took to send that packet to the server.
3577 delay = ((jiffies - nd->nd_seq_time[seq_out])
3578 - (nd->nd_seq_size[seq_out] /
3582 * If the delay is less than the "fast"
3583 * delay, transmit full speed. If greater
3584 * than the "slow" delay, transmit at the
3585 * "slow" speed. In between, interpolate
3586 * between the fast and slow speeds.
3590 (delay <= lk->lk_fast_delay ?
3592 delay >= lk->lk_slow_delay ?
3595 (lk->lk_slow_delay - delay) *
3596 (lk->lk_fast_rate - lk->lk_slow_rate) /
3597 (lk->lk_slow_delay - lk->lk_fast_delay)
3602 nd->nd_delay = delay;
3606 * Increase the transmit credit by depositing the
3607 * current transmit rate.
3610 deposit = nd->nd_tx_deposit;
3611 charge = nd->nd_tx_charge;
3616 * If the available transmit credit becomes too large,
3617 * reduce the deposit to correct the value.
3619 * Too large is the max of:
3620 * 6 times the header size
3621 * 3 times the current transmit rate.
3624 size = 2 * nd->nd_link.lk_header_size;
3631 excess = deposit - charge - size;
3636 nd->nd_tx_deposit = deposit;
3637 nd->nd_tx_credit = deposit - charge;
3640 * Wake the transmit task only if the transmit credit
3641 * is at least 3 times the transmit header size.
3644 size = 3 * lk->lk_header_size;
3646 if (nd->nd_tx_credit < size)
3652 * Enable the READ select to wake the daemon if there
3653 * is useful work for the drp_read routine to perform.
3656 if (waitqueue_active(&nd->nd_tx_waitq) &&
3657 (nd->nd_tx_work != 0 ||
3658 (ulong)(jiffies - nd->nd_tx_time) >= IDLE_MAX)) {
3659 nd->nd_tx_ready = 1;
3661 wake_up_interruptible(&nd->nd_tx_waitq);
3664 /* nd->nd_flag &= ~ND_SELECT; */
3670 * Schedule ourself back at the nominal wakeup interval.
3672 spin_lock_irqsave(&poll_data->poll_lock, lock_flags);
3674 poll_data->node_active_count--;
3675 if (poll_data->node_active_count > 0) {
3676 poll_data->node_active_count++;
3677 poll_time = poll_data->timer.expires +
3678 poll_data->poll_tick * HZ / 1000;
3680 time = poll_time - jiffies;
3682 if (time >= 2 * poll_data->poll_tick)
3683 poll_time = jiffies + dgrp_poll_tick * HZ / 1000;
3685 poll_data->timer.expires = poll_time;
3686 add_timer(&poll_data->timer);
3689 spin_unlock_irqrestore(&poll_data->poll_lock, lock_flags);