linux-stable/drivers/staging/fwserial/fwserial.h

360 lines
11 KiB
C
Raw Normal View History

License cleanup: add SPDX GPL-2.0 license identifier to files with no license Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _FIREWIRE_FWSERIAL_H
#define _FIREWIRE_FWSERIAL_H
#include <linux/kernel.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/list.h>
#include <linux/firewire.h>
#include <linux/firewire-constants.h>
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/mutex.h>
#include <linux/serial.h>
#include <linux/serial_reg.h>
#include <linux/module.h>
#include <linux/seq_file.h>
#include <linux/debugfs.h>
#include "dma_fifo.h"
#ifdef FWTTY_PROFILING
#define DISTRIBUTION_MAX_SIZE 8192
#define DISTRIBUTION_MAX_INDEX (ilog2(DISTRIBUTION_MAX_SIZE) + 1)
static inline void fwtty_profile_data(unsigned int stat[], unsigned int val)
{
int n = (val) ? min(ilog2(val) + 1, DISTRIBUTION_MAX_INDEX) : 0;
++stat[n];
}
#else
#define DISTRIBUTION_MAX_INDEX 0
#define fwtty_profile_data(st, n)
#endif
/* Parameters for both VIRT_CABLE_PLUG & VIRT_CABLE_PLUG_RSP mgmt codes */
struct virt_plug_params {
__be32 status_hi;
__be32 status_lo;
__be32 fifo_hi;
__be32 fifo_lo;
__be32 fifo_len;
};
struct peer_work_params {
union {
struct virt_plug_params plug_req;
};
};
/**
* fwtty_peer: structure representing local & remote unit devices
* @unit: unit child device of fw_device node
* @serial: back pointer to associated fw_serial aggregate
* @guid: unique 64-bit guid for this unit device
* @generation: most recent bus generation
* @node_id: most recent node_id
* @speed: link speed of peer (0 = S100, 2 = S400, ... 5 = S3200)
* @mgmt_addr: bus addr region to write mgmt packets to
* @status_addr: bus addr register to write line status to
* @fifo_addr: bus addr region to write serial output to
* @fifo_len: max length for single write to fifo_addr
* @list: link for insertion into fw_serial's peer_list
* @rcu: for deferring peer reclamation
* @lock: spinlock to synchonize changes to state & port fields
* @work: only one work item can be queued at any one time
* Note: pending work is canceled prior to removal, so this
* peer is valid for at least the lifetime of the work function
* @work_params: parameter block for work functions
* @timer: timer for resetting peer state if remote request times out
* @state: current state
* @connect: work item for auto-connecting
* @connect_retries: # of connections already attempted
* @port: associated tty_port (usable if state == FWSC_ATTACHED)
*/
struct fwtty_peer {
struct fw_unit *unit;
struct fw_serial *serial;
u64 guid;
int generation;
int node_id;
unsigned int speed;
int max_payload;
u64 mgmt_addr;
/* these are usable only if state == FWSC_ATTACHED */
u64 status_addr;
u64 fifo_addr;
int fifo_len;
struct list_head list;
struct rcu_head rcu;
spinlock_t lock;
work_func_t workfn;
struct work_struct work;
struct peer_work_params work_params;
struct timer_list timer;
int state;
struct delayed_work connect;
int connect_retries;
struct fwtty_port *port;
};
#define to_peer(ptr, field) (container_of(ptr, struct fwtty_peer, field))
/* state values for fwtty_peer.state field */
enum fwtty_peer_state {
FWPS_GONE,
FWPS_NOT_ATTACHED,
FWPS_ATTACHED,
FWPS_PLUG_PENDING,
FWPS_PLUG_RESPONDING,
FWPS_UNPLUG_PENDING,
FWPS_UNPLUG_RESPONDING,
FWPS_NO_MGMT_ADDR = -1,
};
#define CONNECT_RETRY_DELAY HZ
#define MAX_CONNECT_RETRIES 10
/* must be holding peer lock for these state funclets */
static inline void peer_set_state(struct fwtty_peer *peer, int new)
{
peer->state = new;
}
static inline struct fwtty_port *peer_revert_state(struct fwtty_peer *peer)
{
struct fwtty_port *port = peer->port;
peer->port = NULL;
peer_set_state(peer, FWPS_NOT_ATTACHED);
return port;
}
struct fwserial_mgmt_pkt {
struct {
__be16 len;
__be16 code;
} hdr;
union {
struct virt_plug_params plug_req;
struct virt_plug_params plug_rsp;
};
} __packed;
/* fwserial_mgmt_packet codes */
#define FWSC_RSP_OK 0x0000
#define FWSC_RSP_NACK 0x8000
#define FWSC_CODE_MASK 0x0fff
#define FWSC_VIRT_CABLE_PLUG 1
#define FWSC_VIRT_CABLE_UNPLUG 2
#define FWSC_VIRT_CABLE_PLUG_RSP 3
#define FWSC_VIRT_CABLE_UNPLUG_RSP 4
/* 1 min. plug timeout -- suitable for userland authorization */
#define VIRT_CABLE_PLUG_TIMEOUT (60 * HZ)
struct stats {
unsigned int xchars;
unsigned int dropped;
unsigned int tx_stall;
unsigned int fifo_errs;
unsigned int sent;
unsigned int lost;
unsigned int throttled;
unsigned int reads[DISTRIBUTION_MAX_INDEX + 1];
unsigned int writes[DISTRIBUTION_MAX_INDEX + 1];
unsigned int txns[DISTRIBUTION_MAX_INDEX + 1];
unsigned int unthrottle[DISTRIBUTION_MAX_INDEX + 1];
};
struct fwconsole_ops {
void (*notify)(int code, void *data);
void (*stats)(struct stats *stats, void *data);
void (*proc_show)(struct seq_file *m, void *data);
};
/* codes for console ops notify */
#define FWCON_NOTIFY_ATTACH 1
#define FWCON_NOTIFY_DETACH 2
/**
* fwtty_port: structure used to track/represent underlying tty_port
* @port: underlying tty_port
* @device: tty device
* @index: index into port_table for this particular port
* note: minor = index + minor_start assigned by tty_alloc_driver()
* @serial: back pointer to the containing fw_serial
* @rx_handler: bus address handler for unique addr region used by remotes
* to communicate with this port. Every port uses
* fwtty_port_handler() for per port transactions.
* @fwcon_ops: ops for attached fw_console (if any)
* @con_data: private data for fw_console
* @wait_tx: waitqueue for sleeping until writer/drain completes tx
* @emit_breaks: delayed work responsible for generating breaks when the
* break line status is active
* @cps : characters per second computed from the termios settings
* @break_last: timestamp in jiffies from last emit_breaks
* @hangup: work responsible for HUPing when carrier is dropped/lost
* @mstatus: loose virtualization of LSR/MSR
* bits 15..0 correspond to TIOCM_* bits
* bits 19..16 reserved for mctrl
* bit 20 OOB_TX_THROTTLE
* bits 23..21 reserved
* bits 31..24 correspond to UART_LSR_* bits
* @lock: spinlock for protecting concurrent access to fields below it
* @mctrl: loose virtualization of MCR
* bits 15..0 correspond to TIOCM_* bits
* bit 16 OOB_RX_THROTTLE
* bits 19..17 reserved
* bits 31..20 reserved for mstatus
* @drain: delayed work scheduled to ensure that writes are flushed.
* The work can race with the writer but concurrent sending is
* prevented with the IN_TX flag. Scheduled under lock to
* limit scheduling when fifo has just been drained.
* @tx_fifo: fifo used to store & block-up writes for dma to remote
* @max_payload: max bytes transmissible per dma (based on peer's max_payload)
* @status_mask: UART_LSR_* bitmask significant to rx (based on termios)
* @ignore_mask: UART_LSR_* bitmask of states to ignore (also based on termios)
* @break_ctl: if set, port is 'sending break' to remote
* @write_only: self-explanatory
* @overrun: previous rx was lost (partially or completely)
* @loopback: if set, port is in loopback mode
* @flags: atomic bit flags
* bit 0: IN_TX - gate to allow only one cpu to send from the dma fifo
* at a time.
* bit 1: STOP_TX - force tx to exit while sending
* @peer: rcu-pointer to associated fwtty_peer (if attached)
* NULL if no peer attached
* @icount: predefined statistics reported by the TIOCGICOUNT ioctl
* @stats: additional statistics reported in /proc/tty/driver/firewire_serial
*/
struct fwtty_port {
struct tty_port port;
struct device *device;
unsigned int index;
struct fw_serial *serial;
struct fw_address_handler rx_handler;
struct fwconsole_ops *fwcon_ops;
void *con_data;
wait_queue_head_t wait_tx;
struct delayed_work emit_breaks;
unsigned int cps;
unsigned long break_last;
struct work_struct hangup;
unsigned int mstatus;
spinlock_t lock;
unsigned int mctrl;
struct delayed_work drain;
struct dma_fifo tx_fifo;
int max_payload;
unsigned int status_mask;
unsigned int ignore_mask;
unsigned int break_ctl:1,
write_only:1,
overrun:1,
loopback:1;
unsigned long flags;
struct fwtty_peer __rcu *peer;
struct async_icount icount;
struct stats stats;
};
#define to_port(ptr, field) (container_of(ptr, struct fwtty_port, field))
/* bit #s for flags field */
#define IN_TX 0
#define STOP_TX 1
/* bitmasks for special mctrl/mstatus bits */
#define OOB_RX_THROTTLE 0x00010000
#define MCTRL_RSRVD 0x000e0000
#define OOB_TX_THROTTLE 0x00100000
#define MSTATUS_RSRVD 0x00e00000
#define MCTRL_MASK (TIOCM_DTR | TIOCM_RTS | TIOCM_OUT1 | TIOCM_OUT2 | \
TIOCM_LOOP | OOB_RX_THROTTLE | MCTRL_RSRVD)
/* XXX even every 1/50th secs. may be unnecessarily accurate */
/* delay in jiffies between brk emits */
#define FREQ_BREAKS (HZ / 50)
/* Ports are allocated in blocks of num_ports for each fw_card */
#define MAX_CARD_PORTS CONFIG_FWTTY_MAX_CARD_PORTS
#define MAX_TOTAL_PORTS CONFIG_FWTTY_MAX_TOTAL_PORTS
/* tuning parameters */
#define FWTTY_PORT_TXFIFO_LEN 4096
#define FWTTY_PORT_MAX_PEND_DMA 8 /* costs a cache line per pend */
#define DRAIN_THRESHOLD 1024
#define MAX_ASYNC_PAYLOAD 4096 /* ohci-defined limit */
#define WRITER_MINIMUM 128
/* TODO: how to set watermark to AR context size? see fwtty_rx() */
#define HIGH_WATERMARK 32768 /* AR context is 32K */
/*
* Size of bus addr region above 4GB used per port as the recv addr
* - must be at least as big as the MAX_ASYNC_PAYLOAD
*/
#define FWTTY_PORT_RXFIFO_LEN MAX_ASYNC_PAYLOAD
/**
* fw_serial: aggregate used to associate tty ports with specific fw_card
* @card: fw_card associated with this fw_serial device (1:1 association)
* @kref: reference-counted multi-port management allows delayed destroy
* @self: local unit device as 'peer'. Not valid until local unit device
* is enumerated.
* @list: link for insertion into fwserial_list
* @peer_list: list of local & remote unit devices attached to this card
* @ports: fixed array of tty_ports provided by this serial device
*/
struct fw_serial {
struct fw_card *card;
struct kref kref;
struct dentry *debugfs;
struct fwtty_peer *self;
struct list_head list;
struct list_head peer_list;
struct fwtty_port *ports[MAX_CARD_PORTS];
};
#define to_serial(ptr, field) (container_of(ptr, struct fw_serial, field))
#define TTY_DEV_NAME "fwtty" /* ttyFW was taken */
static const char tty_dev_name[] = TTY_DEV_NAME;
static const char loop_dev_name[] = "fwloop";
extern struct tty_driver *fwtty_driver;
/*
* Returns the max send async payload size in bytes based on the unit device
* link speed. Self-limiting asynchronous bandwidth (via reducing the payload)
* is not necessary and does not work, because
* 1) asynchronous traffic will absorb all available bandwidth (less that
* being used for isochronous traffic)
* 2) isochronous arbitration always wins.
*/
static inline int link_speed_to_max_payload(unsigned int speed)
{
/* Max async payload is 4096 - see IEEE 1394-2008 tables 6-4, 16-18 */
return min(512 << speed, 4096);
}
#endif /* _FIREWIRE_FWSERIAL_H */