diff options
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/Kconfig | 2 | ||||
-rw-r--r-- | drivers/staging/Makefile | 1 | ||||
-rw-r--r-- | drivers/staging/dgrp/Kconfig | 9 | ||||
-rw-r--r-- | drivers/staging/dgrp/Makefile | 12 | ||||
-rw-r--r-- | drivers/staging/dgrp/README | 2 | ||||
-rw-r--r-- | drivers/staging/dgrp/TODO | 13 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_common.c | 200 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_common.h | 208 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_dpa_ops.c | 556 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_driver.c | 110 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_mon_ops.c | 346 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_net_ops.c | 3737 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_ports_ops.c | 170 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_specproc.c | 822 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_sysfs.c | 555 | ||||
-rw-r--r-- | drivers/staging/dgrp/dgrp_tty.c | 3331 | ||||
-rw-r--r-- | drivers/staging/dgrp/digirp.h | 129 | ||||
-rw-r--r-- | drivers/staging/dgrp/drp.h | 693 | ||||
-rw-r--r-- | drivers/staging/ipack/devices/ipoctal.c | 14 | ||||
-rw-r--r-- | drivers/staging/serqt_usb2/serqt_usb2.c | 18 | ||||
-rw-r--r-- | drivers/staging/speakup/serialio.h | 3 |
21 files changed, 10912 insertions, 19 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 0f51a158ef7..d805eef1191 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -142,4 +142,6 @@ source "drivers/staging/ced1401/Kconfig" source "drivers/staging/imx-drm/Kconfig" +source "drivers/staging/dgrp/Kconfig" + endif # STAGING diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index f4b2bc41f1d..76e2ebd596f 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -63,3 +63,4 @@ obj-$(CONFIG_ZCACHE2) += ramster/ obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/ obj-$(CONFIG_CED1401) += ced1401/ obj-$(CONFIG_DRM_IMX) += imx-drm/ +obj-$(CONFIG_DGRP) += dgrp/ diff --git a/drivers/staging/dgrp/Kconfig b/drivers/staging/dgrp/Kconfig new file mode 100644 index 00000000000..39f4bb65ec8 --- /dev/null +++ b/drivers/staging/dgrp/Kconfig @@ -0,0 +1,9 @@ +config DGRP + tristate "Digi Realport driver" + default n + depends on SYSFS + ---help--- + Support for Digi Realport devices. These devices allow you to + access remote serial ports as if they are local tty devices. This + will build the kernel driver, you will still need the userspace + component to make your Realport device work. diff --git a/drivers/staging/dgrp/Makefile b/drivers/staging/dgrp/Makefile new file mode 100644 index 00000000000..d9c3b88d716 --- /dev/null +++ b/drivers/staging/dgrp/Makefile @@ -0,0 +1,12 @@ +obj-$(CONFIG_DGRP) += dgrp.o + +dgrp-y := \ + dgrp_common.o \ + dgrp_dpa_ops.o \ + dgrp_driver.o \ + dgrp_mon_ops.o \ + dgrp_net_ops.o \ + dgrp_ports_ops.o \ + dgrp_specproc.o \ + dgrp_tty.o \ + dgrp_sysfs.o diff --git a/drivers/staging/dgrp/README b/drivers/staging/dgrp/README new file mode 100644 index 00000000000..1d8aaee270e --- /dev/null +++ b/drivers/staging/dgrp/README @@ -0,0 +1,2 @@ +The user space code to work with this driver is located at +https://github.com/wfp5p/dgrp-utils diff --git a/drivers/staging/dgrp/TODO b/drivers/staging/dgrp/TODO new file mode 100644 index 00000000000..3ef2611bc6d --- /dev/null +++ b/drivers/staging/dgrp/TODO @@ -0,0 +1,13 @@ +- Use configfs for config stuff. This will require changes to the + user space code. + +- dgrp_send() and dgrp_receive() could use some refactoring + +- Don't automatically create CHAN_MAX (64) channel array entries for + every device as many devices are going to have much less than 64 + channels. + +- The locking needs to be checked. It seems haphazardly done in most + places. + +- Check Kconfig dependencies diff --git a/drivers/staging/dgrp/dgrp_common.c b/drivers/staging/dgrp/dgrp_common.c new file mode 100644 index 00000000000..fce74e7fb83 --- /dev/null +++ b/drivers/staging/dgrp/dgrp_common.c @@ -0,0 +1,200 @@ +/* + * + * Copyright 1999 Digi International (www.digi.com) + * James Puzzo <jamesp at digi dot com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + */ + +/* + * + * Filename: + * + * dgrp_common.c + * + * Description: + * + * Definitions of global variables and functions which are either + * shared by the tty, mon, and net drivers; or which cross them + * functionally (like the poller). + * + * Author: + * + * James A. Puzzo + * + */ + +#include <linux/errno.h> +#include <linux/tty.h> +#include <linux/sched.h> +#include <linux/cred.h> + +#include "dgrp_common.h" + +/** + * dgrp_carrier -- check for carrier change state and act + * @ch: struct ch_struct * + */ +void dgrp_carrier(struct ch_struct *ch) +{ + struct nd_struct *nd; + + int virt_carrier = 0; + int phys_carrier = 0; + + /* fix case when the tty has already closed. */ + + if (!ch) + return; + nd = ch->ch_nd; + if (!nd) + return; + + /* + * If we are currently waiting to determine the status of the port, + * we don't yet know the state of the modem lines. As a result, + * we ignore state changes when we are waiting for the modem lines + * to be established. We know, as a result of code in dgrp_net_ops, + * that we will be called again immediately following the reception + * of the status message with the true modem status flags in it. + */ + if (ch->ch_expect & RR_STATUS) + return; + + /* + * If CH_HANGUP is set, we gotta keep trying to get all the processes + * that have the port open to close the port. + * So lets just keep sending a hangup every time we get here. + */ + if ((ch->ch_flag & CH_HANGUP) && + (ch->ch_tun.un_open_count > 0)) + tty_hangup(ch->ch_tun.un_tty); + + /* + * Compute the effective state of both the physical and virtual + * senses of carrier. + */ + + if (ch->ch_s_mlast & DM_CD) + phys_carrier = 1; + + if ((ch->ch_s_mlast & DM_CD) || + (ch->ch_digi.digi_flags & DIGI_FORCEDCD) || + (ch->ch_flag & CH_CLOCAL)) + virt_carrier = 1; + + /* + * Test for a VIRTUAL carrier transition to HIGH. + * + * The CH_HANGUP condition is intended to prevent any action + * except for close. As a result, we ignore positive carrier + * transitions during CH_HANGUP. + */ + if (((ch->ch_flag & CH_HANGUP) == 0) && + ((ch->ch_flag & CH_VIRT_CD) == 0) && + (virt_carrier == 1)) { + /* + * When carrier rises, wake any threads waiting + * for carrier in the open routine. + */ + nd->nd_tx_work = 1; + + if (waitqueue_active(&ch->ch_flag_wait)) + wake_up_interruptible(&ch->ch_flag_wait); + } + + /* + * Test for a PHYSICAL transition to low, so long as we aren't + * currently ignoring physical transitions (which is what "virtual + * carrier" indicates). + * + * The transition of the virtual carrier to low really doesn't + * matter... it really only means "ignore carrier state", not + * "make pretend that carrier is there". + */ + if ((virt_carrier == 0) && + ((ch->ch_flag & CH_PHYS_CD) != 0) && + (phys_carrier == 0)) { + /* + * When carrier drops: + * + * Do a Hard Hangup if that is called for. + * + * Drop carrier on all open units. + * + * Flush queues, waking up any task waiting in the + * line discipline. + * + * Send a hangup to the control terminal. + * + * Enable all select calls. + */ + + nd->nd_tx_work = 1; + + ch->ch_flag &= ~(CH_LOW | CH_EMPTY | CH_DRAIN | CH_INPUT); + + if (waitqueue_active(&ch->ch_flag_wait)) + wake_up_interruptible(&ch->ch_flag_wait); + + if (ch->ch_tun.un_open_count > 0) + tty_hangup(ch->ch_tun.un_tty); + + if (ch->ch_pun.un_open_count > 0) + tty_hangup(ch->ch_pun.un_tty); + } + + /* + * Make sure that our cached values reflect the current reality. + */ + if (virt_carrier == 1) + ch->ch_flag |= CH_VIRT_CD; + else + ch->ch_flag &= ~CH_VIRT_CD; + + if (phys_carrier == 1) + ch->ch_flag |= CH_PHYS_CD; + else + ch->ch_flag &= ~CH_PHYS_CD; + +} + +/** + * dgrp_chk_perm() -- check permissions for net device + * @inode: pointer to inode structure for the net communication device + * @op: operation to be tested + * + * The file permissions and ownerships are tested to determine whether + * the operation "op" is permitted on the file pointed to by the inode. + * Returns 0 if the operation is permitted, -EACCESS otherwise + */ +int dgrp_chk_perm(int mode, int op) +{ + if (!current_euid()) + mode >>= 6; + else if (in_egroup_p(0)) + mode >>= 3; + + if ((mode & op & 0007) == op) + return 0; + + if (capable(CAP_SYS_ADMIN)) + return 0; + + return -EACCES; +} + +/* dgrp_chk_perm wrapper for permission call in struct inode_operations */ +int dgrp_inode_permission(struct inode *inode, int op) +{ + return dgrp_chk_perm(inode->i_mode, op); +} diff --git a/drivers/staging/dgrp/dgrp_common.h b/drivers/staging/dgrp/dgrp_common.h new file mode 100644 index 00000000000..05ff338471a --- /dev/null +++ b/drivers/staging/dgrp/dgrp_common.h @@ -0,0 +1,208 @@ +/* + * + * Copyright 1999 Digi International (www.digi.com) + * James Puzzo <jamesp at digi dot com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + */ + +#ifndef __DGRP_COMMON_H +#define __DGRP_COMMON_H + +#define DIGI_VERSION "1.9-29" + +#include <linux/fs.h> +#include <linux/timer.h> +#include "drp.h" + +#define DGRP_TTIME 100 +#define DGRP_RTIME 100 + +/************************************************************************ + * All global storage allocation. + ************************************************************************/ + +extern int dgrp_rawreadok; /* Allow raw writing of input */ +extern int dgrp_register_cudevices; /* enable legacy cu devices */ +extern int dgrp_register_prdevices; /* enable transparent print devices */ +extern int dgrp_poll_tick; /* Poll interval - in ms */ + +extern struct list_head nd_struct_list; + +struct dgrp_poll_data { + spinlock_t poll_lock; + struct timer_list timer; + int poll_tick; + ulong poll_round; /* Timer rouding factor */ + long node_active_count; +}; + +extern struct dgrp_poll_data dgrp_poll_data; +extern void dgrp_poll_handler(unsigned long arg); + +/* from dgrp_mon_ops.c */ +extern void dgrp_register_mon_hook(struct proc_dir_entry *de); + +/* from dgrp_tty.c */ +extern int dgrp_tty_init(struct nd_struct *nd); +extern void dgrp_tty_uninit(struct nd_struct *nd); + +/* from dgrp_ports_ops.c */ +extern void dgrp_register_ports_hook(struct proc_dir_entry *de); + +/* from dgrp_net_ops.c */ +extern void dgrp_register_net_hook(struct proc_dir_entry *de); + +/* from dgrp_dpa_ops.c */ +extern void dgrp_register_dpa_hook(struct proc_dir_entry *de); +extern void dgrp_dpa_data(struct nd_struct *, int, u8 *, int); + +/* from dgrp_sysfs.c */ +extern void dgrp_create_class_sysfs_files(void); +extern void dgrp_remove_class_sysfs_files(void); + +extern void dgrp_create_node_class_sysfs_files(struct nd_struct *nd); +extern void dgrp_remove_node_class_sysfs_files(struct nd_struct *nd); + +extern void dgrp_create_tty_sysfs(struct un_struct *un, struct device *c); +extern void dgrp_remove_tty_sysfs(struct device *c); + +/* from dgrp_specproc.c */ +/* + * The list of DGRP entries with r/w capabilities. These + * magic numbers are used for identification purposes. + */ +enum { + DGRP_CONFIG = 1, /* Configure portservers */ + DGRP_NETDIR = 2, /* Directory for "net" devices */ + DGRP_MONDIR = 3, /* Directory for "mon" devices */ + DGRP_PORTSDIR = 4, /* Directory for "ports" devices */ + DGRP_INFO = 5, /* Get info. about the running module */ + DGRP_NODEINFO = 6, /* Get info. about the configured nodes */ + DGRP_DPADIR = 7, /* Directory for the "dpa" devices */ +}; + +/* + * Directions for proc handlers + */ +enum { + INBOUND = 1, /* Data being written to kernel */ + OUTBOUND = 2, /* Data being read from the kernel */ +}; + +/** + * dgrp_proc_entry: structure for dgrp proc dirs + * @id: ID number associated with this particular entry. Should be + * unique across all of DGRP. + * @name: text name associated with the /proc entry + * @mode: file access permisssions for the /proc entry + * @child: pointer to table describing a subdirectory for this entry + * @de: pointer to directory entry for this object once registered. Used + * to grab the handle of the object for unregistration + * @excl_sem: semaphore to provide exclusive to struct + * @excl_cnt: counter of current accesses + * + * Each entry in a DGRP proc directory is described with a + * dgrp_proc_entry structure. A collection of these + * entries (in an array) represents the members associated + * with a particular /proc directory, and is referred to + * as a table. All tables are terminated by an entry with + * zeros for every member. + */ +struct dgrp_proc_entry { + int id; /* Integer identifier */ + const char *name; /* ASCII identifier */ + mode_t mode; /* File access permissions */ + struct dgrp_proc_entry *child; /* Child pointer */ + + /* file ops to use, pass NULL to use default */ + struct file_operations *proc_file_ops; + + struct proc_dir_entry *de; /* proc entry pointer */ + struct semaphore excl_sem; /* Protects exclusive access var */ + int excl_cnt; /* Counts number of curr accesses */ +}; + +extern void dgrp_unregister_proc(void); +extern void dgrp_register_proc(void); + +/*-----------------------------------------------------------------------* + * + * Declarations for common operations: + * + * (either used by more than one of net, mon, or tty, + * or in interrupt context (i.e. the poller)) + * + *-----------------------------------------------------------------------*/ + +void dgrp_carrier(struct ch_struct *ch); +extern int dgrp_inode_permission(struct inode *inode, int op); +extern int dgrp_chk_perm(int mode, int op); + + +/* + * ID manipulation macros (where c1 & c2 are characters, i is + * a long integer, and s is a character array of at least three members + */ + +static inline void ID_TO_CHAR(long i, char *s) +{ + s[0] = ((i & 0xff00)>>8); + s[1] = (i & 0xff); + s[2] = 0; +} + +static inline long CHAR_TO_ID(char *s) +{ + return ((s[0] & 0xff) << 8) | (s[1] & 0xff); +} + +static inline struct nd_struct *nd_struct_get(long major) +{ + struct nd_struct *nd; + + list_for_each_entry(nd, &nd_struct_list, list) { + if (major == nd->nd_major) + return nd; + } + + return NULL; +} + +static inline int nd_struct_add(struct nd_struct *entry) +{ + struct nd_struct *ptr; + + ptr = nd_struct_get(entry->nd_major); + + if (ptr) + return -EBUSY; + + list_add_tail(&entry->list, &nd_struct_list); + + return 0; +} + +static inline int nd_struct_del(struct nd_struct *entry) +{ + struct nd_struct *nd; + + nd = nd_struct_get(entry->nd_major); + + if (!nd) + return -ENODEV; + + list_del(&nd->list); + return 0; +} + +#endif /* __DGRP_COMMON_H */ diff --git a/drivers/staging/dgrp/dgrp_dpa_ops.c b/drivers/staging/dgrp/dgrp_dpa_ops.c new file mode 100644 index 00000000000..49e670915e5 --- /dev/null +++ b/drivers/staging/dgrp/dgrp_dpa_ops.c @@ -0,0 +1,556 @@ +/* + * + * Copyright 1999 Digi International (www.digi.com) + * James Puzzo <jamesp at digi dot com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the + * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + */ + +/* + * + * Filename: + * + * dgrp_dpa_ops.c + * + * Description: + * + * Handle the file operations required for the "dpa" devices. + * Includes those functions required to register the "dpa" devices + * in "/proc". + * + * Author: + * + * James A. Puzzo + * + */ + +#include <linux/module.h> +#include <linux/proc_fs.h> +#include <linux/tty.h> +#include <linux/poll.h> +#include <linux/cred.h> +#include <linux/sched.h> +#include <linux/ratelimit.h> +#include <asm/unaligned.h> + +#include "dgrp_common.h" + +/* File operation declarations */ +static int dgrp_dpa_open(struct inode *, struct file *); +static int dgrp_dpa_release(struct inode *, struct file *); +static ssize_t dgrp_dpa_read(struct file *, char __user *, size_t, loff_t *); +static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd, + unsigned long arg); +static unsigned int dgrp_dpa_select(struct file *, struct poll_table_struct *); + +static const struct file_operations dpa_ops = { + .owner = THIS_MODULE, + .read = dgrp_dpa_read, + .poll = dgrp_dpa_select, + .unlocked_ioctl = dgrp_dpa_ioctl, + .open = dgrp_dpa_open, + .release = dgrp_dpa_release, +}; + +static struct inode_operations dpa_inode_ops = { + .permission = dgrp_inode_permission +}; + + + +struct digi_node { + uint nd_state; /* Node state: 1 = up, 0 = down. */ + uint nd_chan_count; /* Number of channels found */ + uint nd_tx_byte; /* Tx data count */ + uint nd_rx_byte; /* RX data count */ + u8 nd_ps_desc[MAX_DESC_LEN]; /* Description from PS */ +}; + +#define DIGI_GETNODE (('d'<<8) | 249) /* get board info */ + + +struct digi_chan { + uint ch_port; /* Port number to get info on */ + uint ch_open; /* 1 if open, 0 if not */ + uint ch_txcount; /* TX data count */ + uint ch_rxcount; /* RX data count */ + uint ch_s_brate; /* Realport BRATE */ + uint ch_s_estat; /* Realport ELAST */ + uint ch_s_cflag; /* Realport CFLAG */ + uint ch_s_iflag; /* Realport IFLAG */ + uint ch_s_oflag; /* Realport OFLAG */ + uint ch_s_xflag; /* Realport XFLAG */ + uint ch_s_mstat; /* Realport MLAST */ +}; + +#define DIGI_GETCHAN (('d'<<8) | 248) /* get channel info */ + + +struct digi_vpd { + int vpd_len; + char vpd_data[VPDSIZE]; +}; + +#define DIGI_GETVPD (('d'<<8) | 246) /* get VPD info */ + + +struct digi_debug { + int onoff; + int port; +}; + +#define DIGI_SETDEBUG (('d'<<8) | 247) /* set debug info */ + + +void dgrp_register_dpa_hook(struct proc_dir_entry *de) +{ + struct nd_struct *node = de->data; + + de->proc_iops = &dpa_inode_ops; + de->proc_fops = &dpa_ops; + + node->nd_dpa_de = de; + spin_lock_init(&node->nd_dpa_lock); +} + +/* + * dgrp_dpa_open -- open the DPA device for a particular PortServer + */ +static int dgrp_dpa_open(struct inode *inode, struct file *file) +{ + struct nd_struct *nd; + int rtn = 0; + + struct proc_dir_entry *de; + + rtn = try_module_get(THIS_MODULE); + if (!rtn) + return -ENXIO; + + rtn = 0; + + if (!capable(CAP_SYS_ADMIN)) { + rtn = -EPERM; + goto done; + } + + /* + * Make sure that the "private_data" field hasn't already been used. + */ + if (file->private_data) { + rtn = -EINVAL; + goto done; + } + + /* + * Get the node pointer, and fail if it doesn't exist. + */ + de = PDE(inode); + if (!de) { + rtn = -ENXIO; + goto done; + } + nd = (struct nd_struct *)de->data; + if (!nd) { + rtn = -ENXIO; + goto done; + } + + file->private_data = (void *) nd; + + /* + * Allocate the DPA buffer. + */ + + if (nd->nd_dpa_buf) { + rtn = -EBUSY; + } else { + nd->nd_dpa_buf = kmalloc(DPA_MAX, GFP_KERNEL); + + if (!nd->nd_dpa_buf) { + rtn = -ENOMEM; + } else { + nd->nd_dpa_out = 0; + nd->nd_dpa_in = 0; + nd->nd_dpa_lbolt = jiffies; + } + } + +done: + + if (rtn) + module_put(THIS_MODULE); + return rtn; +} + +/* + * dgrp_dpa_release -- close the DPA device for a particular PortServer + */ +static int dgrp_dpa_release(struct inode *inode, struct file *file) +{ + struct nd_struct *nd; + u8 *buf; + unsigned long lock_flags; + + /* + * Get the node pointer, and quit if it doesn't exist. + */ + nd = (struct nd_struct *)(file->private_data); + if (!nd) + goto done; + + /* + * Free the dpa buffer. + */ + + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + + buf = nd->nd_dpa_buf; + + nd->nd_dpa_buf = NULL; + nd->nd_dpa_out = nd->nd_dpa_in; + + /* + * Wakeup any thread waiting for buffer space. + */ + + if (nd->nd_dpa_flag & DPA_WAIT_SPACE) { + nd->nd_dpa_flag &= ~DPA_WAIT_SPACE; + wake_up_interruptible(&nd->nd_dpa_wqueue); + } + + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + + kfree(buf); + +done: + module_put(THIS_MODULE); + file->private_data = NULL; + return 0; +} + +/* + * dgrp_dpa_read + * + * Copy data from the monitoring buffer to the user, freeing space + * in the monitoring buffer for more messages + */ +static ssize_t dgrp_dpa_read(struct file *file, char __user *buf, size_t count, + loff_t *ppos) +{ + struct nd_struct *nd; + int n; + int r; + int offset = 0; + int res = 0; + ssize_t rtn; + unsigned long lock_flags; + + /* + * Get the node pointer, and quit if it doesn't exist. + */ + nd = (struct nd_struct *)(file->private_data); + if (!nd) + return -ENXIO; + + /* + * Wait for some data to appear in the buffer. + */ + + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + + for (;;) { + n = (nd->nd_dpa_in - nd->nd_dpa_out) & DPA_MASK; + + if (n != 0) + break; + + nd->nd_dpa_flag |= DPA_WAIT_DATA; + + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + + /* + * Go to sleep waiting until the condition becomes true. + */ + rtn = wait_event_interruptible(nd->nd_dpa_wqueue, + ((nd->nd_dpa_flag & DPA_WAIT_DATA) == 0)); + + if (rtn) + return rtn; + + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + } + + /* + * Read whatever is there. + */ + + if (n > count) + n = count; + + res = n; + + r = DPA_MAX - nd->nd_dpa_out; + + if (r <= n) { + + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + rtn = copy_to_user((void __user *)buf, + nd->nd_dpa_buf + nd->nd_dpa_out, r); + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + + if (rtn) { + rtn = -EFAULT; + goto done; + } + + nd->nd_dpa_out = 0; + n -= r; + offset = r; + } + + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + rtn = copy_to_user((void __user *)buf + offset, + nd->nd_dpa_buf + nd->nd_dpa_out, n); + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + + if (rtn) { + rtn = -EFAULT; + goto done; + } + + nd->nd_dpa_out += n; + + *ppos += res; + + rtn = res; + + /* + * Wakeup any thread waiting for buffer space. + */ + + n = (nd->nd_dpa_in - nd->nd_dpa_out) & DPA_MASK; + + if (nd->nd_dpa_flag & DPA_WAIT_SPACE && + (DPA_MAX - n) > DPA_HIGH_WATER) { + nd->nd_dpa_flag &= ~DPA_WAIT_SPACE; + wake_up_interruptible(&nd->nd_dpa_wqueue); + } + + done: + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + return rtn; +} + +static unsigned int dgrp_dpa_select(struct file *file, + struct poll_table_struct *table) +{ + unsigned int retval = 0; + struct nd_struct *nd = file->private_data; + + if (nd->nd_dpa_out != nd->nd_dpa_in) + retval |= POLLIN | POLLRDNORM; /* Conditionally readable */ + + retval |= POLLOUT | POLLWRNORM; /* Always writeable */ + + return retval; +} + +static long dgrp_dpa_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + + struct nd_struct *nd; + struct digi_chan getchan; + struct digi_node getnode; + struct ch_struct *ch; + struct digi_debug setdebug; + struct digi_vpd vpd; + unsigned int port; + void __user *uarg = (void __user *) arg; + + nd = file->private_data; + + switch (cmd) { + case DIGI_GETCHAN: + if (copy_from_user(&getchan, uarg, sizeof(struct digi_chan))) + return -EFAULT; + + port = getchan.ch_port; + + if (port < 0 || port > nd->nd_chan_count) + return -EINVAL; + + ch = nd->nd_chan + port; + + getchan.ch_open = (ch->ch_open_count > 0) ? 1 : 0; + getchan.ch_txcount = ch->ch_txcount; + getchan.ch_rxcount = ch->ch_rxcount; + getchan.ch_s_brate = ch->ch_s_brate; + getchan.ch_s_estat = ch->ch_s_elast; + getchan.ch_s_cflag = ch->ch_s_cflag; + getchan.ch_s_iflag = ch->ch_s_iflag; + getchan.ch_s_oflag = ch->ch_s_oflag; + getchan.ch_s_xflag = ch->ch_s_xflag; + getchan.ch_s_mstat = ch->ch_s_mlast; + + if (copy_to_user(uarg, &getchan, sizeof(struct digi_chan))) + return -EFAULT; + break; + + + case DIGI_GETNODE: + getnode.nd_state = (nd->nd_state & NS_READY) ? 1 : 0; + getnode.nd_chan_count = nd->nd_chan_count; + getnode.nd_tx_byte = nd->nd_tx_byte; + getnode.nd_rx_byte = nd->nd_rx_byte; + + memset(&getnode.nd_ps_desc, 0, MAX_DESC_LEN); + strncpy(getnode.nd_ps_desc, nd->nd_ps_desc, MAX_DESC_LEN); + + if (copy_to_user(uarg, &getnode, sizeof(struct digi_node))) + return -EFAULT; + break; + + + case DIGI_SETDEBUG: + if (copy_from_user(&setdebug, uarg, sizeof(struct digi_debug))) + return -EFAULT; + + nd->nd_dpa_debug = setdebug.onoff; + nd->nd_dpa_port = setdebug.port; + break; + + + case DIGI_GETVPD: + if (nd->nd_vpd_len > 0) { + vpd.vpd_len = nd->nd_vpd_len; + memcpy(&vpd.vpd_data, &nd->nd_vpd, nd->nd_vpd_len); + } else { + vpd.vpd_len = 0; + } + + if (copy_to_user(uarg, &vpd, sizeof(struct digi_vpd))) + return -EFAULT; + break; + } + + return 0; +} + +/** + * dgrp_dpa() -- send data to the device monitor queue + * @nd: pointer to a node structure + * @buf: buffer of data to copy to the monitoring buffer + * @len: number of bytes to transfer to the buffer + * + * Called by the net device routines to send data to the device + * monitor queue. If the device monitor buffer is too full to + * accept the data, it waits until the buffer is ready. + */ +static void dgrp_dpa(struct nd_struct *nd, u8 *buf, int nbuf) +{ + int n; + int r; + unsigned long lock_flags; + + /* + * Grab DPA lock. + */ + spin_lock_irqsave(&nd->nd_dpa_lock, lock_flags); + + /* + * Loop while data remains. + */ + while (nbuf > 0 && nd->nd_dpa_buf != NULL) { + + n = (nd->nd_dpa_out - nd->nd_dpa_in - 1) & DPA_MASK; + + /* + * Enforce flow control on the DPA device. + */ + if (n < (DPA_MAX - DPA_HIGH_WATER)) + nd->nd_dpa_flag |= DPA_WAIT_SPACE; + + /* + * This should never happen, as the flow control above + * should have stopped things before they got to this point. + */ + if (n == 0) { + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); + return; + } + + /* + * Copy as much data as will fit. + */ + + if (n > nbuf) + n = nbuf; + + r = DPA_MAX - nd->nd_dpa_in; + + if (r <= n) { + memcpy(nd->nd_dpa_buf + nd->nd_dpa_in, buf, r); + + n -= r; + + nd->nd_dpa_in = 0; + + buf += r; + nbuf -= r; + } + + memcpy(nd->nd_dpa_buf + nd->nd_dpa_in, buf, n); + + nd->nd_dpa_in += n; + + buf += n; + nbuf -= n; + + if (nd->nd_dpa_in >= DPA_MAX) + pr_info_ratelimited("%s - nd->nd_dpa_in (%i) >= DPA_MAX\n", + __func__, nd->nd_dpa_in); + + /* + * Wakeup any thread waiting for data + */ + if (nd->nd_dpa_flag & DPA_WAIT_DATA) { + nd->nd_dpa_flag &= ~DPA_WAIT_DATA; + wake_up_interruptible(&nd->nd_dpa_wqueue); + } + } + + /* + * Release the DPA lock. + */ + spin_unlock_irqrestore(&nd->nd_dpa_lock, lock_flags); +} + +/** + * dgrp_monitor_data() -- builds a DPA data packet + * @nd: pointer to a node structure + * @type: type of message to be logged in the DPA buffer + * @buf: buffer of data to be logged in the DPA buffer + * @size -- number of bytes in the "buf" buffer + */ +void dgrp_dpa_data(struct nd_struct *nd, int type, u8 *buf, int size) +{ + u8 header[5]; + + header[0] = type; +< |