* [PATCH] tty: n_tty: order lockless input availability checks
From: Cen Zhang @ 2026-05-04 7:23 UTC (permalink / raw)
To: gregkh, jirislaby
Cc: peter, linux-kernel, linux-serial, baijiaju1990, Cen Zhang
The N_TTY read buffer uses release/acquire ordering for its
lockless ring indices. Input producers release-publish canon_head and
commit_head after updating the buffer and delimiter flags, and readers
acquire those heads before copying data. Readers also release-publish
read_tail before producers use it to calculate room.
chars_in_buffer() and input_available_p() sample the same indices
for availability and flow-control decisions, but use plain loads. That
can miss the ordering used by the data-copy paths and can also let
poll() observe termios-synthesized availability with weaker ordering
than normal receive-side publication.
Use acquire loads for the lockless head/tail samples in those
helpers. When n_tty_set_termios() updates canonical/noncanonical
availability, publish the updated heads with release stores as well.
Keep the cached icanon bit as an intentionally lockless mode snapshot
and annotate that access.
Fixes: 70aca71f92ca ("n_tty: Fix unordered accesses to lockless read buffer")
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
drivers/tty/n_tty.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index e6a0f5b40d0a..56b0cd96a453 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -213,9 +213,17 @@ static void n_tty_kick_worker(const struct tty_struct *tty)
static ssize_t chars_in_buffer(const struct tty_struct *tty)
{
const struct n_tty_data *ldata = tty->disc_data;
- size_t head = ldata->icanon ? ldata->canon_head : ldata->commit_head;
+ bool icanon = data_race((int)ldata->icanon); /* lockless snapshot */
+ size_t head;
+ size_t tail;
- return head - ldata->read_tail;
+ if (icanon)
+ head = smp_load_acquire(&ldata->canon_head); /* producer publish */
+ else
+ head = smp_load_acquire(&ldata->commit_head); /* producer publish */
+ tail = smp_load_acquire(&ldata->read_tail); /* consumer publish */
+
+ return head - tail;
}
/**
@@ -1779,14 +1787,14 @@ static void n_tty_set_termios(struct tty_struct *tty, const struct ktermios *old
bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE);
ldata->line_start = ldata->read_tail;
if (!L_ICANON(tty) || !read_cnt(ldata)) {
- ldata->canon_head = ldata->read_tail;
+ smp_store_release(&ldata->canon_head, ldata->read_tail); /* publish */
ldata->push = 0;
} else {
set_bit(MASK(ldata->read_head - 1), ldata->read_flags);
- ldata->canon_head = ldata->read_head;
+ smp_store_release(&ldata->canon_head, ldata->read_head); /* publish */
ldata->push = 1;
}
- ldata->commit_head = ldata->read_head;
+ smp_store_release(&ldata->commit_head, ldata->read_head); /* publish */
ldata->erasing = 0;
ldata->lnext = 0;
}
@@ -1908,11 +1916,17 @@ static inline int input_available_p(const struct tty_struct *tty, int poll)
{
const struct n_tty_data *ldata = tty->disc_data;
int amt = poll && !TIME_CHAR(tty) && MIN_CHAR(tty) ? MIN_CHAR(tty) : 1;
+ bool icanon = data_race((int)ldata->icanon); /* lockless snapshot */
+ size_t tail = smp_load_acquire(&ldata->read_tail); /* consumer publish */
+ size_t head;
- if (ldata->icanon && !L_EXTPROC(tty))
- return ldata->canon_head != ldata->read_tail;
- else
- return ldata->commit_head - ldata->read_tail >= amt;
+ if (icanon && !L_EXTPROC(tty)) {
+ head = smp_load_acquire(&ldata->canon_head); /* producer publish */
+ return head != tail;
+ }
+
+ head = smp_load_acquire(&ldata->commit_head); /* producer publish */
+ return head - tail >= amt;
}
/**
--
2.43.0
^ permalink raw reply related
* Re: [PATCH] serial: fsl_lpuart: fix rx buffer and DMA map leaks in start_rx_dma
From: Shitalkumar Gandhi @ 2026-05-04 6:49 UTC (permalink / raw)
To: gregkh
Cc: Frank.Li, bhuvanchandra.dv, imx, jirislaby, linux-arm-kernel,
linux-kernel, linux-serial, peng.fan, sherry.sun, shital.gandhi45,
Shitalkumar Gandhi
In-Reply-To: <2026050410-frozen-fondue-5476@gregkh>
On Mon, May 04, 2026 at 08:24:20AM +0200, Greg Kroah-Hartman wrote:
> > Any update on this? It has Frank's Reviewed-by but I don't see
> > it queued in tty-next or tty-testing yet.
>
> What is "this"? I see no context here :(
Sorry for the missing context. The patch is:
serial: fsl_lpuart: fix rx buffer and DMA map leaks in start_rx_dma
Fixes three error paths in lpuart_start_rx_dma() that leak ring->buf
and the DMA mapping. Sent April 20, Frank Li gave Reviewed-by on
April 21.
Lore: https://lore.kernel.org/linux-serial/20260420135903.2062024-1-shitalkumar.gandhi@cambiumnetworks.com/
Happy to resend with Frank's Reviewed-by added if that helps.
Thanks,
Shital
^ permalink raw reply
* Re: [PATCH] serial: fsl_lpuart: fix rx buffer and DMA map leaks in start_rx_dma
From: Greg Kroah-Hartman @ 2026-05-04 6:24 UTC (permalink / raw)
To: Shitalkumar Gandhi
Cc: Jiri Slaby, Frank Li, Bhuvanchandra DV, Peng Fan, Sherry Sun,
linux-serial, imx, linux-arm-kernel, linux-kernel,
Shitalkumar Gandhi
In-Reply-To: <20260503194921.3449864-1-shitalkumar.gandhi@cambiumnetworks.com>
On Mon, May 04, 2026 at 01:19:21AM +0530, Shitalkumar Gandhi wrote:
> Hi Greg,
>
> Any update on this? It has Frank's Reviewed-by but I don't see
> it queued in tty-next or tty-testing yet.
What is "this"? I see no context here :(
^ permalink raw reply
* [PATCH v3] tty: synclink_gt: remove broken driver
From: Ethan Nelson-Moore @ 2026-05-04 3:14 UTC (permalink / raw)
To: linux-doc, netdev, linux-serial, rust-for-linux
Cc: Ethan Nelson-Moore, Jonathan Corbet, Shuah Khan,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Greg Kroah-Hartman,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Julian Braha, Qingfang Deng
The synclink_gt driver was marked as broken in commit 426263d5fb40
("tty: synclink_gt: mark as BROKEN") in July 2023 because it had severe
structural problems and there had been no evidence of users since 2016.
Since then, no meaningful improvements have been made to the driver,
and it is unlikely that will ever happen due to the lack of interest.
Drop the driver and references to it in comments and documentation.
include/uapi/linux/synclink.h is also removed. The only use of this
header I have found is the linux-raw-sys Rust crate. It generates
bindings for all UAPI headers, but has a hardcoded list of headers and
ioctls, including this one, so that does not indicate that anyone is
using it. I have sent a pull request to remove the include and ioctl
definitions for this header (see the link below).
Link: https://github.com/sunfishcode/linux-raw-sys/pull/185
Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
---
Changes from v2:
Remove UAPI header - I have sent a pull request to remove it from
linux-raw-sys
.../userspace-api/ioctl/ioctl-number.rst | 1 -
arch/powerpc/configs/ppc6xx_defconfig | 1 -
drivers/net/ppp/Kconfig | 4 +-
drivers/tty/Kconfig | 11 +-
drivers/tty/Makefile | 1 -
drivers/tty/n_hdlc.c | 7 -
drivers/tty/synclink_gt.c | 5038 -----------------
include/linux/synclink.h | 37 -
include/uapi/linux/synclink.h | 301 -
9 files changed, 3 insertions(+), 5398 deletions(-)
delete mode 100644 drivers/tty/synclink_gt.c
delete mode 100644 include/linux/synclink.h
delete mode 100644 include/uapi/linux/synclink.h
diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index 331223761fff..58716f4f4834 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -271,7 +271,6 @@ Code Seq# Include File Comments
'm' 00-09 linux/mmtimer.h conflict!
'm' all linux/mtio.h conflict!
'm' all linux/soundcard.h conflict!
-'m' all linux/synclink.h conflict!
'm' 00-19 drivers/message/fusion/mptctl.h conflict!
'm' 00 drivers/scsi/megaraid/megaraid_ioctl.h conflict!
'n' 00-7F linux/ncp_fs.h and fs/ncpfs/ioctl.c
diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
index ccabc6e17168..4ddd2c01b8b7 100644
--- a/arch/powerpc/configs/ppc6xx_defconfig
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -551,7 +551,6 @@ CONFIG_GAMEPORT_EMU10K1=m
CONFIG_GAMEPORT_FM801=m
# CONFIG_LEGACY_PTYS is not set
CONFIG_SERIAL_NONSTANDARD=y
-CONFIG_SYNCLINK_GT=m
CONFIG_NOZOMI=m
CONFIG_N_HDLC=m
CONFIG_SERIAL_8250=y
diff --git a/drivers/net/ppp/Kconfig b/drivers/net/ppp/Kconfig
index 753354b4e36c..5324e2102383 100644
--- a/drivers/net/ppp/Kconfig
+++ b/drivers/net/ppp/Kconfig
@@ -191,8 +191,8 @@ config PPP_SYNC_TTY
tristate "PPP support for sync tty ports"
help
Say Y (or M) here if you want to be able to use PPP over synchronous
- (HDLC) tty devices, such as the SyncLink adapter. These devices
- are often used for high-speed leased lines like T1/E1.
+ (HDLC) tty devices. These devices are often used for high-speed leased
+ lines like T1/E1.
To compile this driver as a module, choose M here.
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 149f3d53b760..df6832a4c237 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -231,21 +231,12 @@ config MOXA_SMARTIO
This driver can also be built as a module. The module will be called
mxser. If you want to do that, say M here.
-config SYNCLINK_GT
- tristate "SyncLink GT/AC support"
- depends on SERIAL_NONSTANDARD && PCI
- depends on BROKEN
- help
- Support for SyncLink GT and SyncLink AC families of
- synchronous and asynchronous serial adapters
- manufactured by Microgate Systems, Ltd. (www.microgate.com)
-
config N_HDLC
tristate "HDLC line discipline support"
depends on SERIAL_NONSTANDARD
help
Allows synchronous HDLC communications with tty device drivers that
- support synchronous HDLC such as the Microgate SyncLink adapter.
+ support synchronous HDLC.
This driver can be built as a module ( = code which can be
inserted in and removed from the running kernel whenever you want).
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 07aca5184a55..8ca1a0a2229f 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -21,7 +21,6 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
obj-$(CONFIG_NOZOMI) += nozomi.o
obj-$(CONFIG_NULL_TTY) += ttynull.o
-obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o
obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 98eefa2cede4..895b850a5950 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -4,8 +4,6 @@
* Written by Paul Fulghum paulkf@microgate.com
* for Microgate Corporation
*
- * Microgate and SyncLink are registered trademarks of Microgate Corporation
- *
* Adapted from ppp.c, written by Michael Callahan <callahan@maths.ox.ac.uk>,
* Al Longyear <longyear@netcom.com>,
* Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
@@ -54,11 +52,6 @@
* this line discipline (or another line discipline that is frame
* oriented such as N_PPP).
*
- * The SyncLink driver (synclink.c) implements both asynchronous
- * (using standard line discipline N_TTY) and synchronous HDLC
- * (using N_HDLC) communications, with the latter using the above
- * conventions.
- *
* This implementation is very basic and does not maintain
* any statistics. The main point is to enforce the raw data
* and frame orientation of HDLC communications.
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
deleted file mode 100644
index bf4f50e0ce94..000000000000
--- a/drivers/tty/synclink_gt.c
+++ /dev/null
@@ -1,5038 +0,0 @@
-// SPDX-License-Identifier: GPL-1.0+
-/*
- * Device driver for Microgate SyncLink GT serial adapters.
- *
- * written by Paul Fulghum for Microgate Corporation
- * paulkf@microgate.com
- *
- * Microgate and SyncLink are trademarks of Microgate Corporation
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DEBUG OUTPUT DEFINITIONS
- *
- * uncomment lines below to enable specific types of debug output
- *
- * DBGINFO information - most verbose output
- * DBGERR serious errors
- * DBGBH bottom half service routine debugging
- * DBGISR interrupt service routine debugging
- * DBGDATA output receive and transmit data
- * DBGTBUF output transmit DMA buffers and registers
- * DBGRBUF output receive DMA buffers and registers
- */
-
-#define DBGINFO(fmt) if (debug_level >= DEBUG_LEVEL_INFO) printk fmt
-#define DBGERR(fmt) if (debug_level >= DEBUG_LEVEL_ERROR) printk fmt
-#define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
-#define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
-#define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
-/*#define DBGTBUF(info) dump_tbufs(info)*/
-/*#define DBGRBUF(info) dump_rbufs(info)*/
-
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/interrupt.h>
-#include <linux/pci.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial.h>
-#include <linux/major.h>
-#include <linux/string.h>
-#include <linux/fcntl.h>
-#include <linux/ptrace.h>
-#include <linux/ioport.h>
-#include <linux/mm.h>
-#include <linux/seq_file.h>
-#include <linux/slab.h>
-#include <linux/netdevice.h>
-#include <linux/vmalloc.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/ioctl.h>
-#include <linux/termios.h>
-#include <linux/bitops.h>
-#include <linux/workqueue.h>
-#include <linux/hdlc.h>
-#include <linux/synclink.h>
-
-#include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/dma.h>
-#include <asm/types.h>
-#include <linux/uaccess.h>
-
-#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
-#define SYNCLINK_GENERIC_HDLC 1
-#else
-#define SYNCLINK_GENERIC_HDLC 0
-#endif
-
-/*
- * module identification
- */
-static const char driver_name[] = "SyncLink GT";
-static const char tty_dev_prefix[] = "ttySLG";
-MODULE_DESCRIPTION("Device driver for Microgate SyncLink GT serial adapters");
-MODULE_LICENSE("GPL");
-#define MAX_DEVICES 32
-
-static const struct pci_device_id pci_table[] = {
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT2_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT4_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_AC_DEVICE_ID) },
- { 0 }, /* terminate list */
-};
-MODULE_DEVICE_TABLE(pci, pci_table);
-
-static int init_one(struct pci_dev *dev,const struct pci_device_id *ent);
-static void remove_one(struct pci_dev *dev);
-static struct pci_driver pci_driver = {
- .name = "synclink_gt",
- .id_table = pci_table,
- .probe = init_one,
- .remove = remove_one,
-};
-
-static bool pci_registered;
-
-/*
- * module configuration and status
- */
-static struct slgt_info *slgt_device_list;
-static int slgt_device_count;
-
-static int ttymajor;
-static int debug_level;
-static int maxframe[MAX_DEVICES];
-
-module_param(ttymajor, int, 0);
-module_param(debug_level, int, 0);
-module_param_array(maxframe, int, NULL, 0);
-
-MODULE_PARM_DESC(ttymajor, "TTY major device number override: 0=auto assigned");
-MODULE_PARM_DESC(debug_level, "Debug syslog output: 0=disabled, 1 to 5=increasing detail");
-MODULE_PARM_DESC(maxframe, "Maximum frame size used by device (4096 to 65535)");
-
-/*
- * tty support and callbacks
- */
-static struct tty_driver *serial_driver;
-
-static void wait_until_sent(struct tty_struct *tty, int timeout);
-static void flush_buffer(struct tty_struct *tty);
-static void tx_release(struct tty_struct *tty);
-
-/*
- * generic HDLC support
- */
-#define dev_to_port(D) (dev_to_hdlc(D)->priv)
-
-
-/*
- * device specific structures, macros and functions
- */
-
-#define SLGT_MAX_PORTS 4
-#define SLGT_REG_SIZE 256
-
-/*
- * conditional wait facility
- */
-struct cond_wait {
- struct cond_wait *next;
- wait_queue_head_t q;
- wait_queue_entry_t wait;
- unsigned int data;
-};
-static void flush_cond_wait(struct cond_wait **head);
-
-/*
- * DMA buffer descriptor and access macros
- */
-struct slgt_desc
-{
- __le16 count;
- __le16 status;
- __le32 pbuf; /* physical address of data buffer */
- __le32 next; /* physical address of next descriptor */
-
- /* driver book keeping */
- char *buf; /* virtual address of data buffer */
- unsigned int pdesc; /* physical address of this descriptor */
- dma_addr_t buf_dma_addr;
- unsigned short buf_count;
-};
-
-#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
-#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
-#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
-#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
-#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
-#define desc_count(a) (le16_to_cpu((a).count))
-#define desc_status(a) (le16_to_cpu((a).status))
-#define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
-#define desc_eof(a) (le16_to_cpu((a).status) & BIT2)
-#define desc_crc_error(a) (le16_to_cpu((a).status) & BIT1)
-#define desc_abort(a) (le16_to_cpu((a).status) & BIT0)
-#define desc_residue(a) ((le16_to_cpu((a).status) & 0x38) >> 3)
-
-struct _input_signal_events {
- int ri_up;
- int ri_down;
- int dsr_up;
- int dsr_down;
- int dcd_up;
- int dcd_down;
- int cts_up;
- int cts_down;
-};
-
-/*
- * device instance data structure
- */
-struct slgt_info {
- void *if_ptr; /* General purpose pointer (used by SPPP) */
- struct tty_port port;
-
- struct slgt_info *next_device; /* device list link */
-
- char device_name[25];
- struct pci_dev *pdev;
-
- int port_count; /* count of ports on adapter */
- int adapter_num; /* adapter instance number */
- int port_num; /* port instance number */
-
- /* array of pointers to port contexts on this adapter */
- struct slgt_info *port_array[SLGT_MAX_PORTS];
-
- int line; /* tty line instance number */
-
- struct mgsl_icount icount;
-
- int timeout;
- int x_char; /* xon/xoff character */
- unsigned int read_status_mask;
- unsigned int ignore_status_mask;
-
- wait_queue_head_t status_event_wait_q;
- wait_queue_head_t event_wait_q;
- struct timer_list tx_timer;
- struct timer_list rx_timer;
-
- unsigned int gpio_present;
- struct cond_wait *gpio_wait_q;
-
- spinlock_t lock; /* spinlock for synchronizing with ISR */
-
- struct work_struct task;
- u32 pending_bh;
- bool bh_requested;
- bool bh_running;
-
- int isr_overflow;
- bool irq_requested; /* true if IRQ requested */
- bool irq_occurred; /* for diagnostics use */
-
- /* device configuration */
-
- unsigned int bus_type;
- unsigned int irq_level;
- unsigned long irq_flags;
-
- unsigned char __iomem * reg_addr; /* memory mapped registers address */
- u32 phys_reg_addr;
- bool reg_addr_requested;
-
- MGSL_PARAMS params; /* communications parameters */
- u32 idle_mode;
- u32 max_frame_size; /* as set by device config */
-
- unsigned int rbuf_fill_level;
- unsigned int rx_pio;
- unsigned int if_mode;
- unsigned int base_clock;
- unsigned int xsync;
- unsigned int xctrl;
-
- /* device status */
-
- bool rx_enabled;
- bool rx_restart;
-
- bool tx_enabled;
- bool tx_active;
-
- unsigned char signals; /* serial signal states */
- int init_error; /* initialization error */
-
- unsigned char *tx_buf;
- int tx_count;
-
- bool drop_rts_on_tx_done;
- struct _input_signal_events input_signal_events;
-
- int dcd_chkcount; /* check counts to prevent */
- int cts_chkcount; /* too many IRQs if a signal */
- int dsr_chkcount; /* is floating */
- int ri_chkcount;
-
- char *bufs; /* virtual address of DMA buffer lists */
- dma_addr_t bufs_dma_addr; /* physical address of buffer descriptors */
-
- unsigned int rbuf_count;
- struct slgt_desc *rbufs;
- unsigned int rbuf_current;
- unsigned int rbuf_index;
- unsigned int rbuf_fill_index;
- unsigned short rbuf_fill_count;
-
- unsigned int tbuf_count;
- struct slgt_desc *tbufs;
- unsigned int tbuf_current;
- unsigned int tbuf_start;
-
- unsigned char *tmp_rbuf;
- unsigned int tmp_rbuf_count;
-
- /* SPPP/Cisco HDLC device parts */
-
- int netcount;
- spinlock_t netlock;
-#if SYNCLINK_GENERIC_HDLC
- struct net_device *netdev;
-#endif
-
-};
-
-static const MGSL_PARAMS default_params = {
- .mode = MGSL_MODE_HDLC,
- .loopback = 0,
- .flags = HDLC_FLAG_UNDERRUN_ABORT15,
- .encoding = HDLC_ENCODING_NRZI_SPACE,
- .clock_speed = 0,
- .addr_filter = 0xff,
- .crc_type = HDLC_CRC_16_CCITT,
- .preamble_length = HDLC_PREAMBLE_LENGTH_8BITS,
- .preamble = HDLC_PREAMBLE_PATTERN_NONE,
- .data_rate = 9600,
- .data_bits = 8,
- .stop_bits = 1,
- .parity = ASYNC_PARITY_NONE
-};
-
-
-#define BH_RECEIVE 1
-#define BH_TRANSMIT 2
-#define BH_STATUS 4
-#define IO_PIN_SHUTDOWN_LIMIT 100
-
-#define DMABUFSIZE 256
-#define DESC_LIST_SIZE 4096
-
-#define MASK_PARITY BIT1
-#define MASK_FRAMING BIT0
-#define MASK_BREAK BIT14
-#define MASK_OVERRUN BIT4
-
-#define GSR 0x00 /* global status */
-#define JCR 0x04 /* JTAG control */
-#define IODR 0x08 /* GPIO direction */
-#define IOER 0x0c /* GPIO interrupt enable */
-#define IOVR 0x10 /* GPIO value */
-#define IOSR 0x14 /* GPIO interrupt status */
-#define TDR 0x80 /* tx data */
-#define RDR 0x80 /* rx data */
-#define TCR 0x82 /* tx control */
-#define TIR 0x84 /* tx idle */
-#define TPR 0x85 /* tx preamble */
-#define RCR 0x86 /* rx control */
-#define VCR 0x88 /* V.24 control */
-#define CCR 0x89 /* clock control */
-#define BDR 0x8a /* baud divisor */
-#define SCR 0x8c /* serial control */
-#define SSR 0x8e /* serial status */
-#define RDCSR 0x90 /* rx DMA control/status */
-#define TDCSR 0x94 /* tx DMA control/status */
-#define RDDAR 0x98 /* rx DMA descriptor address */
-#define TDDAR 0x9c /* tx DMA descriptor address */
-#define XSR 0x40 /* extended sync pattern */
-#define XCR 0x44 /* extended control */
-
-#define RXIDLE BIT14
-#define RXBREAK BIT14
-#define IRQ_TXDATA BIT13
-#define IRQ_TXIDLE BIT12
-#define IRQ_TXUNDER BIT11 /* HDLC */
-#define IRQ_RXDATA BIT10
-#define IRQ_RXIDLE BIT9 /* HDLC */
-#define IRQ_RXBREAK BIT9 /* async */
-#define IRQ_RXOVER BIT8
-#define IRQ_DSR BIT7
-#define IRQ_CTS BIT6
-#define IRQ_DCD BIT5
-#define IRQ_RI BIT4
-#define IRQ_ALL 0x3ff0
-#define IRQ_MASTER BIT0
-
-#define slgt_irq_on(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
-#define slgt_irq_off(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
-
-static void msc_set_vcr(struct slgt_info *info);
-
-static int startup_hw(struct slgt_info *info);
-static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
-static void shutdown_hw(struct slgt_info *info);
-static void program_hw(struct slgt_info *info);
-static void change_params(struct slgt_info *info);
-
-static int adapter_test(struct slgt_info *info);
-
-static void reset_port(struct slgt_info *info);
-static void async_mode(struct slgt_info *info);
-static void sync_mode(struct slgt_info *info);
-
-static void rx_stop(struct slgt_info *info);
-static void rx_start(struct slgt_info *info);
-static void reset_rbufs(struct slgt_info *info);
-static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
-static bool rx_get_frame(struct slgt_info *info);
-static bool rx_get_buf(struct slgt_info *info);
-
-static void tx_start(struct slgt_info *info);
-static void tx_stop(struct slgt_info *info);
-static void tx_set_idle(struct slgt_info *info);
-static unsigned int tbuf_bytes(struct slgt_info *info);
-static void reset_tbufs(struct slgt_info *info);
-static void tdma_reset(struct slgt_info *info);
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int count);
-
-static void get_gtsignals(struct slgt_info *info);
-static void set_gtsignals(struct slgt_info *info);
-static void set_rate(struct slgt_info *info, u32 data_rate);
-
-static void bh_transmit(struct slgt_info *info);
-static void isr_txeom(struct slgt_info *info, unsigned short status);
-
-static void tx_timeout(struct timer_list *t);
-static void rx_timeout(struct timer_list *t);
-
-/*
- * ioctl handlers
- */
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int get_txidle(struct slgt_info *info, int __user *idle_mode);
-static int set_txidle(struct slgt_info *info, int idle_mode);
-static int tx_enable(struct slgt_info *info, int enable);
-static int tx_abort(struct slgt_info *info);
-static int rx_enable(struct slgt_info *info, int enable);
-static int modem_input_wait(struct slgt_info *info,int arg);
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
-static int get_interface(struct slgt_info *info, int __user *if_mode);
-static int set_interface(struct slgt_info *info, int if_mode);
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_xsync(struct slgt_info *info, int __user *if_mode);
-static int set_xsync(struct slgt_info *info, int if_mode);
-static int get_xctrl(struct slgt_info *info, int __user *if_mode);
-static int set_xctrl(struct slgt_info *info, int if_mode);
-
-/*
- * driver functions
- */
-static void release_resources(struct slgt_info *info);
-
-/*
- * DEBUG OUTPUT CODE
- */
-#ifndef DBGINFO
-#define DBGINFO(fmt)
-#endif
-#ifndef DBGERR
-#define DBGERR(fmt)
-#endif
-#ifndef DBGBH
-#define DBGBH(fmt)
-#endif
-#ifndef DBGISR
-#define DBGISR(fmt)
-#endif
-
-#ifdef DBGDATA
-static void trace_block(struct slgt_info *info, const char *data, int count, const char *label)
-{
- int i;
- int linecount;
- printk("%s %s data:\n",info->device_name, label);
- while(count) {
- linecount = (count > 16) ? 16 : count;
- for(i=0; i < linecount; i++)
- printk("%02X ",(unsigned char)data[i]);
- for(;i<17;i++)
- printk(" ");
- for(i=0;i<linecount;i++) {
- if (data[i]>=040 && data[i]<=0176)
- printk("%c",data[i]);
- else
- printk(".");
- }
- printk("\n");
- data += linecount;
- count -= linecount;
- }
-}
-#else
-#define DBGDATA(info, buf, size, label)
-#endif
-
-#ifdef DBGTBUF
-static void dump_tbufs(struct slgt_info *info)
-{
- int i;
- printk("tbuf_current=%d\n", info->tbuf_current);
- for (i=0 ; i < info->tbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status));
- }
-}
-#else
-#define DBGTBUF(info)
-#endif
-
-#ifdef DBGRBUF
-static void dump_rbufs(struct slgt_info *info)
-{
- int i;
- printk("rbuf_current=%d\n", info->rbuf_current);
- for (i=0 ; i < info->rbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status));
- }
-}
-#else
-#define DBGRBUF(info)
-#endif
-
-static inline int sanity_check(struct slgt_info *info, char *devname, const char *name)
-{
-#ifdef SANITY_CHECK
- if (!info) {
- printk("null struct slgt_info for (%s) in %s\n", devname, name);
- return 1;
- }
-#else
- if (!info)
- return 1;
-#endif
- return 0;
-}
-
-/*
- * line discipline callback wrappers
- *
- * The wrappers maintain line discipline references
- * while calling into the line discipline.
- *
- * ldisc_receive_buf - pass receive data to line discipline
- */
-static void ldisc_receive_buf(struct tty_struct *tty,
- const __u8 *data, char *flags, int count)
-{
- struct tty_ldisc *ld;
- if (!tty)
- return;
- ld = tty_ldisc_ref(tty);
- if (ld) {
- if (ld->ops->receive_buf)
- ld->ops->receive_buf(tty, data, flags, count);
- tty_ldisc_deref(ld);
- }
-}
-
-/* tty callbacks */
-
-static int open(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info;
- int retval, line;
- unsigned long flags;
-
- line = tty->index;
- if (line >= slgt_device_count) {
- DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
- return -ENODEV;
- }
-
- info = slgt_device_list;
- while(info && info->line != line)
- info = info->next_device;
- if (sanity_check(info, tty->name, "open"))
- return -ENODEV;
- if (info->init_error) {
- DBGERR(("%s init error=%d\n", info->device_name, info->init_error));
- return -ENODEV;
- }
-
- tty->driver_data = info;
- info->port.tty = tty;
-
- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
-
- mutex_lock(&info->port.mutex);
-
- spin_lock_irqsave(&info->netlock, flags);
- if (info->netcount) {
- retval = -EBUSY;
- spin_unlock_irqrestore(&info->netlock, flags);
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- info->port.count++;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- if (info->port.count == 1) {
- /* 1st open on this device, init hardware */
- retval = startup_hw(info);
- if (retval < 0) {
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- }
- mutex_unlock(&info->port.mutex);
- retval = block_til_ready(tty, filp, info);
- if (retval) {
- DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval));
- goto cleanup;
- }
-
- retval = 0;
-
-cleanup:
- if (retval) {
- if (tty->count == 1)
- info->port.tty = NULL; /* tty layer will release tty struct */
- if(info->port.count)
- info->port.count--;
- }
-
- DBGINFO(("%s open rc=%d\n", info->device_name, retval));
- return retval;
-}
-
-static void close(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info = tty->driver_data;
-
- if (sanity_check(info, tty->name, "close"))
- return;
- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
-
- if (tty_port_close_start(&info->port, tty, filp) == 0)
- goto cleanup;
-
- mutex_lock(&info->port.mutex);
- if (tty_port_initialized(&info->port))
- wait_until_sent(tty, info->timeout);
- flush_buffer(tty);
- tty_ldisc_flush(tty);
-
- shutdown_hw(info);
- mutex_unlock(&info->port.mutex);
-
- tty_port_close_end(&info->port, tty);
- info->port.tty = NULL;
-cleanup:
- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
-}
-
-static void hangup(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "hangup"))
- return;
- DBGINFO(("%s hangup\n", info->device_name));
-
- flush_buffer(tty);
-
- mutex_lock(&info->port.mutex);
- shutdown_hw(info);
-
- spin_lock_irqsave(&info->port.lock, flags);
- info->port.count = 0;
- info->port.tty = NULL;
- spin_unlock_irqrestore(&info->port.lock, flags);
- tty_port_set_active(&info->port, false);
- mutex_unlock(&info->port.mutex);
-
- wake_up_interruptible(&info->port.open_wait);
-}
-
-static void set_termios(struct tty_struct *tty,
- const struct ktermios *old_termios)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s set_termios\n", tty->driver->name));
-
- change_params(info);
-
- /* Handle transition to B0 status */
- if ((old_termios->c_cflag & CBAUD) && !C_BAUD(tty)) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle transition away from B0 status */
- if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) {
- info->signals |= SerialSignal_DTR;
- if (!C_CRTSCTS(tty) || !tty_throttled(tty))
- info->signals |= SerialSignal_RTS;
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle turning off CRTSCTS */
- if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) {
- tty->hw_stopped = false;
- tx_release(tty);
- }
-}
-
-static void update_tx_timer(struct slgt_info *info)
-{
- /*
- * use worst case speed of 1200bps to calculate transmit timeout
- * based on data in buffers (tbuf_bytes) and FIFO (128 bytes)
- */
- if (info->params.mode == MGSL_MODE_HDLC) {
- int timeout = (tbuf_bytes(info) * 7) + 1000;
- mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout));
- }
-}
-
-static ssize_t write(struct tty_struct *tty, const u8 *buf, size_t count)
-{
- int ret = 0;
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "write"))
- return -EIO;
-
- DBGINFO(("%s write count=%zu\n", info->device_name, count));
-
- if (!info->tx_buf || (count > info->max_frame_size))
- return -EIO;
-
- if (!count || tty->flow.stopped || tty->hw_stopped)
- return 0;
-
- spin_lock_irqsave(&info->lock, flags);
-
- if (info->tx_count) {
- /* send accumulated data from send_char() */
- if (!tx_load(info, info->tx_buf, info->tx_count))
- goto cleanup;
- info->tx_count = 0;
- }
-
- if (tx_load(info, buf, count))
- ret = count;
-
-cleanup:
- spin_unlock_irqrestore(&info->lock, flags);
- DBGINFO(("%s write rc=%d\n", info->device_name, ret));
- return ret;
-}
-
-static int put_char(struct tty_struct *tty, u8 ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
- int ret = 0;
-
- if (sanity_check(info, tty->name, "put_char"))
- return 0;
- DBGINFO(("%s put_char(%u)\n", info->device_name, ch));
- if (!info->tx_buf)
- return 0;
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count < info->max_frame_size) {
- info->tx_buf[info->tx_count++] = ch;
- ret = 1;
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return ret;
-}
-
-static void send_xchar(struct tty_struct *tty, char ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "send_xchar"))
- return;
- DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch));
- info->x_char = ch;
- if (ch) {
- spin_lock_irqsave(&info->lock,flags);
- if (!info->tx_enabled)
- tx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-static void wait_until_sent(struct tty_struct *tty, int timeout)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long orig_jiffies, char_time;
-
- if (!info )
- return;
- if (sanity_check(info, tty->name, "wait_until_sent"))
- return;
- DBGINFO(("%s wait_until_sent entry\n", info->device_name));
- if (!tty_port_initialized(&info->port))
- goto exit;
-
- orig_jiffies = jiffies;
-
- /* Set check interval to 1/5 of estimated time to
- * send a character, and make it at least 1. The check
- * interval should also be less than the timeout.
- * Note: use tight timings here to satisfy the NIST-PCTS.
- */
-
- if (info->params.data_rate) {
- char_time = info->timeout/(32 * 5);
- if (!char_time)
- char_time++;
- } else
- char_time = 1;
-
- if (timeout)
- char_time = min_t(unsigned long, char_time, timeout);
-
- while (info->tx_active) {
- msleep_interruptible(jiffies_to_msecs(char_time));
- if (signal_pending(current))
- break;
- if (timeout && time_after(jiffies, orig_jiffies + timeout))
- break;
- }
-exit:
- DBGINFO(("%s wait_until_sent exit\n", info->device_name));
-}
-
-static unsigned int write_room(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int ret;
-
- if (sanity_check(info, tty->name, "write_room"))
- return 0;
- ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
- DBGINFO(("%s write_room=%u\n", info->device_name, ret));
- return ret;
-}
-
-static void flush_chars(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_chars"))
- return;
- DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count));
-
- if (info->tx_count <= 0 || tty->flow.stopped ||
- tty->hw_stopped || !info->tx_buf)
- return;
-
- DBGINFO(("%s flush_chars start transmit\n", info->device_name));
-
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-static void flush_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_buffer"))
- return;
- DBGINFO(("%s flush_buffer\n", info->device_name));
-
- spin_lock_irqsave(&info->lock, flags);
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-
- tty_wakeup(tty);
-}
-
-/*
- * throttle (stop) transmitter
- */
-static void tx_hold(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_hold"))
- return;
- DBGINFO(("%s tx_hold\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC)
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * release (start) transmitter
- */
-static void tx_release(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_release"))
- return;
- DBGINFO(("%s tx_release\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-}
-
-/*
- * Service an IOCTL request
- *
- * Arguments
- *
- * tty pointer to tty instance data
- * cmd IOCTL command code
- * arg command argument/context
- *
- * Return 0 if success, otherwise error code
- */
-static int ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- void __user *argp = (void __user *)arg;
- int ret;
-
- if (sanity_check(info, tty->name, "ioctl"))
- return -ENODEV;
- DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd));
-
- if (cmd != TIOCMIWAIT) {
- if (tty_io_error(tty))
- return -EIO;
- }
-
- switch (cmd) {
- case MGSL_IOCWAITEVENT:
- return wait_mgsl_event(info, argp);
- case TIOCMIWAIT:
- return modem_input_wait(info,(int)arg);
- case MGSL_IOCSGPIO:
- return set_gpio(info, argp);
- case MGSL_IOCGGPIO:
- return get_gpio(info, argp);
- case MGSL_IOCWAITGPIO:
- return wait_gpio(info, argp);
- case MGSL_IOCGXSYNC:
- return get_xsync(info, argp);
- case MGSL_IOCSXSYNC:
- return set_xsync(info, (int)arg);
- case MGSL_IOCGXCTRL:
- return get_xctrl(info, argp);
- case MGSL_IOCSXCTRL:
- return set_xctrl(info, (int)arg);
- }
- mutex_lock(&info->port.mutex);
- switch (cmd) {
- case MGSL_IOCGPARAMS:
- ret = get_params(info, argp);
- break;
- case MGSL_IOCSPARAMS:
- ret = set_params(info, argp);
- break;
- case MGSL_IOCGTXIDLE:
- ret = get_txidle(info, argp);
- break;
- case MGSL_IOCSTXIDLE:
- ret = set_txidle(info, (int)arg);
- break;
- case MGSL_IOCTXENABLE:
- ret = tx_enable(info, (int)arg);
- break;
- case MGSL_IOCRXENABLE:
- ret = rx_enable(info, (int)arg);
- break;
- case MGSL_IOCTXABORT:
- ret = tx_abort(info);
- break;
- case MGSL_IOCGSTATS:
- ret = get_stats(info, argp);
- break;
- case MGSL_IOCGIF:
- ret = get_interface(info, argp);
- break;
- case MGSL_IOCSIF:
- ret = set_interface(info,(int)arg);
- break;
- default:
- ret = -ENOIOCTLCMD;
- }
- mutex_unlock(&info->port.mutex);
- return ret;
-}
-
-static int get_icount(struct tty_struct *tty,
- struct serial_icounter_struct *icount)
-
-{
- struct slgt_info *info = tty->driver_data;
- struct mgsl_icount cnow; /* kernel counter temps */
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- spin_unlock_irqrestore(&info->lock,flags);
-
- icount->cts = cnow.cts;
- icount->dsr = cnow.dsr;
- icount->rng = cnow.rng;
- icount->dcd = cnow.dcd;
- icount->rx = cnow.rx;
- icount->tx = cnow.tx;
- icount->frame = cnow.frame;
- icount->overrun = cnow.overrun;
- icount->parity = cnow.parity;
- icount->brk = cnow.brk;
- icount->buf_overrun = cnow.buf_overrun;
-
- return 0;
-}
-
-/*
- * support for 32 bit ioctl calls on 64 bit systems
- */
-#ifdef CONFIG_COMPAT
-static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params)
-{
- struct MGSL_PARAMS32 tmp_params;
-
- DBGINFO(("%s get_params32\n", info->device_name));
- memset(&tmp_params, 0, sizeof(tmp_params));
- tmp_params.mode = (compat_ulong_t)info->params.mode;
- tmp_params.loopback = info->params.loopback;
- tmp_params.flags = info->params.flags;
- tmp_params.encoding = info->params.encoding;
- tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed;
- tmp_params.addr_filter = info->params.addr_filter;
- tmp_params.crc_type = info->params.crc_type;
- tmp_params.preamble_length = info->params.preamble_length;
- tmp_params.preamble = info->params.preamble;
- tmp_params.data_rate = (compat_ulong_t)info->params.data_rate;
- tmp_params.data_bits = info->params.data_bits;
- tmp_params.stop_bits = info->params.stop_bits;
- tmp_params.parity = info->params.parity;
- if (copy_to_user(user_params, &tmp_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
- return 0;
-}
-
-static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
-{
- struct MGSL_PARAMS32 tmp_params;
- unsigned long flags;
-
- DBGINFO(("%s set_params32\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK) {
- info->base_clock = tmp_params.clock_speed;
- } else {
- info->params.mode = tmp_params.mode;
- info->params.loopback = tmp_params.loopback;
- info->params.flags = tmp_params.flags;
- info->params.encoding = tmp_params.encoding;
- info->params.clock_speed = tmp_params.clock_speed;
- info->params.addr_filter = tmp_params.addr_filter;
- info->params.crc_type = tmp_params.crc_type;
- info->params.preamble_length = tmp_params.preamble_length;
- info->params.preamble = tmp_params.preamble;
- info->params.data_rate = tmp_params.data_rate;
- info->params.data_bits = tmp_params.data_bits;
- info->params.stop_bits = tmp_params.stop_bits;
- info->params.parity = tmp_params.parity;
- }
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static long slgt_compat_ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- int rc;
-
- if (sanity_check(info, tty->name, "compat_ioctl"))
- return -ENODEV;
- DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
-
- switch (cmd) {
- case MGSL_IOCSPARAMS32:
- rc = set_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS32:
- rc = get_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS:
- case MGSL_IOCSPARAMS:
- case MGSL_IOCGTXIDLE:
- case MGSL_IOCGSTATS:
- case MGSL_IOCWAITEVENT:
- case MGSL_IOCGIF:
- case MGSL_IOCSGPIO:
- case MGSL_IOCGGPIO:
- case MGSL_IOCWAITGPIO:
- case MGSL_IOCGXSYNC:
- case MGSL_IOCGXCTRL:
- rc = ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
- break;
- default:
- rc = ioctl(tty, cmd, arg);
- }
- DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
- return rc;
-}
-#else
-#define slgt_compat_ioctl NULL
-#endif /* ifdef CONFIG_COMPAT */
-
-/*
- * proc fs support
- */
-static inline void line_info(struct seq_file *m, struct slgt_info *info)
-{
- char stat_buf[30];
- unsigned long flags;
-
- seq_printf(m, "%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
- info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
- /* output current serial signal states */
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- stat_buf[0] = 0;
- stat_buf[1] = 0;
- if (info->signals & SerialSignal_RTS)
- strcat(stat_buf, "|RTS");
- if (info->signals & SerialSignal_CTS)
- strcat(stat_buf, "|CTS");
- if (info->signals & SerialSignal_DTR)
- strcat(stat_buf, "|DTR");
- if (info->signals & SerialSignal_DSR)
- strcat(stat_buf, "|DSR");
- if (info->signals & SerialSignal_DCD)
- strcat(stat_buf, "|CD");
- if (info->signals & SerialSignal_RI)
- strcat(stat_buf, "|RI");
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- seq_printf(m, "\tHDLC txok:%d rxok:%d",
- info->icount.txok, info->icount.rxok);
- if (info->icount.txunder)
- seq_printf(m, " txunder:%d", info->icount.txunder);
- if (info->icount.txabort)
- seq_printf(m, " txabort:%d", info->icount.txabort);
- if (info->icount.rxshort)
- seq_printf(m, " rxshort:%d", info->icount.rxshort);
- if (info->icount.rxlong)
- seq_printf(m, " rxlong:%d", info->icount.rxlong);
- if (info->icount.rxover)
- seq_printf(m, " rxover:%d", info->icount.rxover);
- if (info->icount.rxcrc)
- seq_printf(m, " rxcrc:%d", info->icount.rxcrc);
- } else {
- seq_printf(m, "\tASYNC tx:%d rx:%d",
- info->icount.tx, info->icount.rx);
- if (info->icount.frame)
- seq_printf(m, " fe:%d", info->icount.frame);
- if (info->icount.parity)
- seq_printf(m, " pe:%d", info->icount.parity);
- if (info->icount.brk)
- seq_printf(m, " brk:%d", info->icount.brk);
- if (info->icount.overrun)
- seq_printf(m, " oe:%d", info->icount.overrun);
- }
-
- /* Append serial signal status to end */
- seq_printf(m, " %s\n", stat_buf+1);
-
- seq_printf(m, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
- info->tx_active,info->bh_requested,info->bh_running,
- info->pending_bh);
-}
-
-/* Called to print information about devices
- */
-static int synclink_gt_proc_show(struct seq_file *m, void *v)
-{
- struct slgt_info *info;
-
- seq_puts(m, "synclink_gt driver\n");
-
- info = slgt_device_list;
- while( info ) {
- line_info(m, info);
- info = info->next_device;
- }
- return 0;
-}
-
-/*
- * return count of bytes in transmit buffer
- */
-static unsigned int chars_in_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int count;
- if (sanity_check(info, tty->name, "chars_in_buffer"))
- return 0;
- count = tbuf_bytes(info);
- DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count));
- return count;
-}
-
-/*
- * signal remote device to throttle send data (our receive data)
- */
-static void throttle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "throttle"))
- return;
- DBGINFO(("%s throttle\n", info->device_name));
- if (I_IXOFF(tty))
- send_xchar(tty, STOP_CHAR(tty));
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals &= ~SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * signal remote device to stop throttling send data (our receive data)
- */
-static void unthrottle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "unthrottle"))
- return;
- DBGINFO(("%s unthrottle\n", info->device_name));
- if (I_IXOFF(tty)) {
- if (info->x_char)
- info->x_char = 0;
- else
- send_xchar(tty, START_CHAR(tty));
- }
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * set or clear transmit break condition
- * break_state -1=set break condition, 0=clear
- */
-static int set_break(struct tty_struct *tty, int break_state)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned short value;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "set_break"))
- return -EINVAL;
- DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
-
- spin_lock_irqsave(&info->lock,flags);
- value = rd_reg16(info, TCR);
- if (break_state == -1)
- value |= BIT6;
- else
- value &= ~BIT6;
- wr_reg16(info, TCR, value);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-#if SYNCLINK_GENERIC_HDLC
-
-/**
- * hdlcdev_attach - called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
- * @dev: pointer to network device structure
- * @encoding: serial encoding setting
- * @parity: FCS setting
- *
- * Set encoding and frame check sequence (FCS) options.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
- unsigned short parity)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned char new_encoding;
- unsigned short new_crctype;
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- DBGINFO(("%s hdlcdev_attach\n", info->device_name));
-
- switch (encoding)
- {
- case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
- case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
- case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
- case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
- case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
- default: return -EINVAL;
- }
-
- switch (parity)
- {
- case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
- case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
- case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
- default: return -EINVAL;
- }
-
- info->params.encoding = new_encoding;
- info->params.crc_type = new_crctype;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
-
- return 0;
-}
-
-/**
- * hdlcdev_xmit - called by generic HDLC layer to send a frame
- * @skb: socket buffer containing HDLC frame
- * @dev: pointer to network device structure
- */
-static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
- struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlc_xmit\n", dev->name));
-
- if (!skb->len)
- return NETDEV_TX_OK;
-
- /* stop sending until this frame completes */
- netif_stop_queue(dev);
-
- /* update network statistics */
- dev->stats.tx_packets++;
- dev->stats.tx_bytes += skb->len;
-
- /* save start time for transmit timeout detection */
- netif_trans_update(dev);
-
- spin_lock_irqsave(&info->lock, flags);
- tx_load(info, skb->data, skb->len);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* done with socket buffer, so free it */
- dev_kfree_skb(skb);
-
- return NETDEV_TX_OK;
-}
-
-/**
- * hdlcdev_open - called by network layer when interface enabled
- * @dev: pointer to network device structure
- *
- * Claim resources and initialize hardware.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_open(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- int rc;
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_open\n", dev->name));
-
- /* arbitrate between network and tty opens */
- spin_lock_irqsave(&info->netlock, flags);
- if (info->port.count != 0 || info->netcount != 0) {
- DBGINFO(("%s hdlc_open busy\n", dev->name));
- spin_unlock_irqrestore(&info->netlock, flags);
- return -EBUSY;
- }
- info->netcount=1;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- /* claim resources and init adapter */
- if ((rc = startup_hw(info)) != 0) {
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* generic HDLC layer open processing */
- rc = hdlc_open(dev);
- if (rc) {
- shutdown_hw(info);
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount = 0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* assert RTS and DTR, apply hardware settings */
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- program_hw(info);
-
- /* enable network layer transmit */
- netif_trans_update(dev);
- netif_start_queue(dev);
-
- /* inform generic HDLC layer of current DCD status */
- spin_lock_irqsave(&info->lock, flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock, flags);
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(dev);
- else
- netif_carrier_off(dev);
- return 0;
-}
-
-/**
- * hdlcdev_close - called by network layer when interface is disabled
- * @dev: pointer to network device structure
- *
- * Shutdown hardware and release resources.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_close(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_close\n", dev->name));
-
- netif_stop_queue(dev);
-
- /* shutdown adapter and release resources */
- shutdown_hw(info);
-
- hdlc_close(dev);
-
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- return 0;
-}
-
-/**
- * hdlcdev_ioctl - called by network layer to process IOCTL call to network device
- * @dev: pointer to network device structure
- * @ifr: pointer to network interface request structure
- * @cmd: IOCTL command code
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_ioctl(struct net_device *dev, struct if_settings *ifs)
-{
- const size_t size = sizeof(sync_serial_settings);
- sync_serial_settings new_line;
- sync_serial_settings __user *line = ifs->ifs_ifsu.sync;
- struct slgt_info *info = dev_to_port(dev);
- unsigned int flags;
-
- DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- memset(&new_line, 0, sizeof(new_line));
-
- switch (ifs->type) {
- case IF_GET_IFACE: /* return current sync_serial_settings */
-
- ifs->type = IF_IFACE_SYNC_SERIAL;
- if (ifs->size < size) {
- ifs->size = size; /* data size wanted */
- return -ENOBUFS;
- }
-
- flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
-
- switch (flags){
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
- case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
- default: new_line.clock_type = CLOCK_DEFAULT;
- }
-
- new_line.clock_rate = info->params.clock_speed;
- new_line.loopback = info->params.loopback ? 1:0;
-
- if (copy_to_user(line, &new_line, size))
- return -EFAULT;
- return 0;
-
- case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
-
- if(!capable(CAP_NET_ADMIN))
- return -EPERM;
- if (copy_from_user(&new_line, line, size))
- return -EFAULT;
-
- switch (new_line.clock_type)
- {
- case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
- case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
- case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_DEFAULT: flags = info->params.flags &
- (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
- default: return -EINVAL;
- }
-
- if (new_line.loopback != 0 && new_line.loopback != 1)
- return -EINVAL;
-
- info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
- info->params.flags |= flags;
-
- info->params.loopback = new_line.loopback;
-
- if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
- info->params.clock_speed = new_line.clock_rate;
- else
- info->params.clock_speed = 0;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
- return 0;
-
- default:
- return hdlc_ioctl(dev, ifs);
- }
-}
-
-/**
- * hdlcdev_tx_timeout - called by network layer when transmit timeout is detected
- * @dev: pointer to network device structure
- * @txqueue: unused
- */
-static void hdlcdev_tx_timeout(struct net_device *dev, unsigned int txqueue)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_tx_timeout\n", dev->name));
-
- dev->stats.tx_errors++;
- dev->stats.tx_aborted_errors++;
-
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- netif_wake_queue(dev);
-}
-
-/**
- * hdlcdev_tx_done - called by device driver when transmit completes
- * @info: pointer to device instance information
- *
- * Reenable network layer transmit if stopped.
- */
-static void hdlcdev_tx_done(struct slgt_info *info)
-{
- if (netif_queue_stopped(info->netdev))
- netif_wake_queue(info->netdev);
-}
-
-/**
- * hdlcdev_rx - called by device driver when frame received
- * @info: pointer to device instance information
- * @buf: pointer to buffer contianing frame data
- * @size: count of data bytes in buf
- *
- * Pass frame to network layer.
- */
-static void hdlcdev_rx(struct slgt_info *info, char *buf, int size)
-{
- struct sk_buff *skb = dev_alloc_skb(size);
- struct net_device *dev = info->netdev;
-
- DBGINFO(("%s hdlcdev_rx\n", dev->name));
-
- if (skb == NULL) {
- DBGERR(("%s: can't alloc skb, drop packet\n", dev->name));
- dev->stats.rx_dropped++;
- return;
- }
-
- skb_put_data(skb, buf, size);
-
- skb->protocol = hdlc_type_trans(skb, dev);
-
- dev->stats.rx_packets++;
- dev->stats.rx_bytes += size;
-
- netif_rx(skb);
-}
-
-static const struct net_device_ops hdlcdev_ops = {
- .ndo_open = hdlcdev_open,
- .ndo_stop = hdlcdev_close,
- .ndo_start_xmit = hdlc_start_xmit,
- .ndo_siocwandev = hdlcdev_ioctl,
- .ndo_tx_timeout = hdlcdev_tx_timeout,
-};
-
-/**
- * hdlcdev_init - called by device driver when adding device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC initialization.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_init(struct slgt_info *info)
-{
- int rc;
- struct net_device *dev;
- hdlc_device *hdlc;
-
- /* allocate and initialize network and HDLC layer objects */
-
- dev = alloc_hdlcdev(info);
- if (!dev) {
- printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name);
- return -ENOMEM;
- }
-
- /* for network layer reporting purposes only */
- dev->mem_start = info->phys_reg_addr;
- dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1;
- dev->irq = info->irq_level;
-
- /* network layer callbacks and settings */
- dev->netdev_ops = &hdlcdev_ops;
- dev->watchdog_timeo = 10 * HZ;
- dev->tx_queue_len = 50;
-
- /* generic HDLC layer callbacks and settings */
- hdlc = dev_to_hdlc(dev);
- hdlc->attach = hdlcdev_attach;
- hdlc->xmit = hdlcdev_xmit;
-
- /* register objects with HDLC layer */
- rc = register_hdlc_device(dev);
- if (rc) {
- printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
- free_netdev(dev);
- return rc;
- }
-
- info->netdev = dev;
- return 0;
-}
-
-/**
- * hdlcdev_exit - called by device driver when removing device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC cleanup.
- */
-static void hdlcdev_exit(struct slgt_info *info)
-{
- if (!info->netdev)
- return;
- unregister_hdlc_device(info->netdev);
- free_netdev(info->netdev);
- info->netdev = NULL;
-}
-
-#endif /* ifdef CONFIG_HDLC */
-
-/*
- * get async data from rx DMA buffers
- */
-static void rx_async(struct slgt_info *info)
-{
- struct mgsl_icount *icount = &info->icount;
- unsigned int start, end;
- unsigned char *p;
- unsigned char status;
- struct slgt_desc *bufs = info->rbufs;
- int i, count;
- int chars = 0;
- int stat;
- unsigned char ch;
-
- start = end = info->rbuf_current;
-
- while(desc_complete(bufs[end])) {
- count = desc_count(bufs[end]) - info->rbuf_index;
- p = bufs[end].buf + info->rbuf_index;
-
- DBGISR(("%s rx_async count=%d\n", info->device_name, count));
- DBGDATA(info, p, count, "rx");
-
- for(i=0 ; i < count; i+=2, p+=2) {
- ch = *p;
- icount->rx++;
-
- stat = 0;
-
- status = *(p + 1) & (BIT1 + BIT0);
- if (status) {
- if (status & BIT1)
- icount->parity++;
- else if (status & BIT0)
- icount->frame++;
- /* discard char if tty control flags say so */
- if (status & info->ignore_status_mask)
- continue;
- if (status & BIT1)
- stat = TTY_PARITY;
- else if (status & BIT0)
- stat = TTY_FRAME;
- }
- tty_insert_flip_char(&info->port, ch, stat);
- chars++;
- }
-
- if (i < count) {
- /* receive buffer not completed */
- info->rbuf_index += i;
- mod_timer(&info->rx_timer, jiffies + 1);
- break;
- }
-
- info->rbuf_index = 0;
- free_rbufs(info, end, end);
-
- if (++end == info->rbuf_count)
- end = 0;
-
- /* if entire list searched then no frame available */
- if (end == start)
- break;
- }
-
- if (chars)
- tty_flip_buffer_push(&info->port);
-}
-
-/*
- * return next bottom half action to perform
- */
-static int bh_action(struct slgt_info *info)
-{
- unsigned long flags;
- int rc;
-
- spin_lock_irqsave(&info->lock,flags);
-
- if (info->pending_bh & BH_RECEIVE) {
- info->pending_bh &= ~BH_RECEIVE;
- rc = BH_RECEIVE;
- } else if (info->pending_bh & BH_TRANSMIT) {
- info->pending_bh &= ~BH_TRANSMIT;
- rc = BH_TRANSMIT;
- } else if (info->pending_bh & BH_STATUS) {
- info->pending_bh &= ~BH_STATUS;
- rc = BH_STATUS;
- } else {
- /* Mark BH routine as complete */
- info->bh_running = false;
- info->bh_requested = false;
- rc = 0;
- }
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- return rc;
-}
-
-/*
- * perform bottom half processing
- */
-static void bh_handler(struct work_struct *work)
-{
- struct slgt_info *info = container_of(work, struct slgt_info, task);
- int action;
-
- info->bh_running = true;
-
- while((action = bh_action(info))) {
- switch (action) {
- case BH_RECEIVE:
- DBGBH(("%s bh receive\n", info->device_name));
- switch(info->params.mode) {
- case MGSL_MODE_ASYNC:
- rx_async(info);
- break;
- case MGSL_MODE_HDLC:
- while(rx_get_frame(info));
- break;
- case MGSL_MODE_RAW:
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- while(rx_get_buf(info));
- break;
- }
- /* restart receiver if rx DMA buffers exhausted */
- if (info->rx_restart)
- rx_start(info);
- break;
- case BH_TRANSMIT:
- bh_transmit(info);
- break;
- case BH_STATUS:
- DBGBH(("%s bh status\n", info->device_name));
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- break;
- default:
- DBGBH(("%s unknown action\n", info->device_name));
- break;
- }
- }
- DBGBH(("%s bh_handler exit\n", info->device_name));
-}
-
-static void bh_transmit(struct slgt_info *info)
-{
- struct tty_struct *tty = info->port.tty;
-
- DBGBH(("%s bh_transmit\n", info->device_name));
- if (tty)
- tty_wakeup(tty);
-}
-
-static void dsr_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT3) {
- info->signals |= SerialSignal_DSR;
- info->input_signal_events.dsr_up++;
- } else {
- info->signals &= ~SerialSignal_DSR;
- info->input_signal_events.dsr_down++;
- }
- DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DSR);
- return;
- }
- info->icount.dsr++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void cts_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT2) {
- info->signals |= SerialSignal_CTS;
- info->input_signal_events.cts_up++;
- } else {
- info->signals &= ~SerialSignal_CTS;
- info->input_signal_events.cts_down++;
- }
- DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_CTS);
- return;
- }
- info->icount.cts++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_cts_enabled(&info->port)) {
- if (info->port.tty) {
- if (info->port.tty->hw_stopped) {
- if (info->signals & SerialSignal_CTS) {
- info->port.tty->hw_stopped = false;
- info->pending_bh |= BH_TRANSMIT;
- return;
- }
- } else {
- if (!(info->signals & SerialSignal_CTS))
- info->port.tty->hw_stopped = true;
- }
- }
- }
-}
-
-static void dcd_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT1) {
- info->signals |= SerialSignal_DCD;
- info->input_signal_events.dcd_up++;
- } else {
- info->signals &= ~SerialSignal_DCD;
- info->input_signal_events.dcd_down++;
- }
- DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DCD);
- return;
- }
- info->icount.dcd++;
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount) {
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(info->netdev);
- else
- netif_carrier_off(info->netdev);
- }
-#endif
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_check_carrier(&info->port)) {
- if (info->signals & SerialSignal_DCD)
- wake_up_interruptible(&info->port.open_wait);
- else {
- if (info->port.tty)
- tty_hangup(info->port.tty);
- }
- }
-}
-
-static void ri_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT0) {
- info->signals |= SerialSignal_RI;
- info->input_signal_events.ri_up++;
- } else {
- info->signals &= ~SerialSignal_RI;
- info->input_signal_events.ri_down++;
- }
- DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_RI);
- return;
- }
- info->icount.rng++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void isr_rxdata(struct slgt_info *info)
-{
- unsigned int count = info->rbuf_fill_count;
- unsigned int i = info->rbuf_fill_index;
- unsigned short reg;
-
- while (rd_reg16(info, SSR) & IRQ_RXDATA) {
- reg = rd_reg16(info, RDR);
- DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
- if (desc_complete(info->rbufs[i])) {
- /* all buffers full */
- rx_stop(info);
- info->rx_restart = true;
- continue;
- }
- info->rbufs[i].buf[count++] = (unsigned char)reg;
- /* async mode saves status byte to buffer for each data byte */
- if (info->params.mode == MGSL_MODE_ASYNC)
- info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
- if (count == info->rbuf_fill_level || (reg & BIT10)) {
- /* buffer full or end of frame */
- set_desc_count(info->rbufs[i], count);
- set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
- info->rbuf_fill_count = count = 0;
- if (++i == info->rbuf_count)
- i = 0;
- info->pending_bh |= BH_RECEIVE;
- }
- }
-
- info->rbuf_fill_index = i;
- info->rbuf_fill_count = count;
-}
-
-static void isr_serial(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- DBGISR(("%s isr_serial status=%04X\n", info->device_name, status));
-
- wr_reg16(info, SSR, status); /* clear pending */
-
- info->irq_occurred = true;
-
- if (info->params.mode == MGSL_MODE_ASYNC) {
- if (status & IRQ_TXIDLE) {
- if (info->tx_active)
- isr_txeom(info, status);
- }
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
- info->icount.brk++;
- /* process break detection if tty control allows */
- if (info->port.tty) {
- if (!(status & info->ignore_status_mask)) {
- if (info->read_status_mask & MASK_BREAK) {
- tty_insert_flip_char(&info->port, 0, TTY_BREAK);
- if (info->port.flags & ASYNC_SAK)
- do_SAK(info->port.tty);
- }
- }
- }
- }
- } else {
- if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
- isr_txeom(info, status);
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if (status & IRQ_RXIDLE) {
- if (status & RXIDLE)
- info->icount.rxidle++;
- else
- info->icount.exithunt++;
- wake_up_interruptible(&info->event_wait_q);
- }
-
- if (status & IRQ_RXOVER)
- rx_start(info);
- }
-
- if (status & IRQ_DSR)
- dsr_change(info, status);
- if (status & IRQ_CTS)
- cts_change(info, status);
- if (status & IRQ_DCD)
- dcd_change(info, status);
- if (status & IRQ_RI)
- ri_change(info, status);
-}
-
-static void isr_rdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, RDCSR);
-
- DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status));
-
- /* RDCSR (rx DMA control/status)
- *
- * 31..07 reserved
- * 06 save status byte to DMA buffer
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, RDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4)) {
- DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name));
- info->rx_restart = true;
- }
- info->pending_bh |= BH_RECEIVE;
-}
-
-static void isr_tdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, TDCSR);
-
- DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status));
-
- /* TDCSR (tx DMA control/status)
- *
- * 31..06 reserved
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, TDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4 + BIT3)) {
- // another transmit buffer has completed
- // run bottom half to get more send data from user
- info->pending_bh |= BH_TRANSMIT;
- }
-}
-
-/*
- * return true if there are unsent tx DMA buffers, otherwise false
- *
- * if there are unsent buffers then info->tbuf_start
- * is set to index of first unsent buffer
- */
-static bool unsent_tbufs(struct slgt_info *info)
-{
- unsigned int i = info->tbuf_current;
- bool rc = false;
-
- /*
- * search backwards from last loaded buffer (precedes tbuf_current)
- * for first unsent buffer (desc_count > 0)
- */
-
- do {
- if (i)
- i--;
- else
- i = info->tbuf_count - 1;
- if (!desc_count(info->tbufs[i]))
- break;
- info->tbuf_start = i;
- rc = true;
- } while (i != info->tbuf_current);
-
- return rc;
-}
-
-static void isr_txeom(struct slgt_info *info, unsigned short status)
-{
- DBGISR(("%s txeom status=%04x\n", info->device_name, status));
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
- tdma_reset(info);
- if (status & IRQ_TXUNDER) {
- unsigned short val = rd_reg16(info, TCR);
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, TCR, val); /* clear reset bit */
- }
-
- if (info->tx_active) {
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (status & IRQ_TXUNDER)
- info->icount.txunder++;
- else if (status & IRQ_TXIDLE)
- info->icount.txok++;
- }
-
- if (unsent_tbufs(info)) {
- tx_start(info);
- update_tx_timer(info);
- return;
- }
- info->tx_active = false;
-
- timer_delete(&info->tx_timer);
-
- if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) {
- info->signals &= ~SerialSignal_RTS;
- info->drop_rts_on_tx_done = false;
- set_gtsignals(info);
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- {
- if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) {
- tx_stop(info);
- return;
- }
- info->pending_bh |= BH_TRANSMIT;
- }
- }
-}
-
-static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state)
-{
- struct cond_wait *w, *prev;
-
- /* wake processes waiting for specific transitions */
- for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) {
- if (w->data & changed) {
- w->data = state;
- wake_up_interruptible(&w->q);
- if (prev != NULL)
- prev->next = w->next;
- else
- info->gpio_wait_q = w->next;
- } else
- prev = w;
- }
-}
-
-/* interrupt service routine
- *
- * irq interrupt number
- * dev_id device ID supplied during interrupt registration
- */
-static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
-{
- struct slgt_info *info = dev_id;
- unsigned int gsr;
- unsigned int i;
-
- DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level));
-
- while((gsr = rd_reg32(info, GSR) & 0xffffff00)) {
- DBGISR(("%s gsr=%08x\n", info->device_name, gsr));
- info->irq_occurred = true;
- for(i=0; i < info->port_count ; i++) {
- if (info->port_array[i] == NULL)
- continue;
- spin_lock(&info->port_array[i]->lock);
- if (gsr & (BIT8 << i))
- isr_serial(info->port_array[i]);
- if (gsr & (BIT16 << (i*2)))
- isr_rdma(info->port_array[i]);
- if (gsr & (BIT17 << (i*2)))
- isr_tdma(info->port_array[i]);
- spin_unlock(&info->port_array[i]->lock);
- }
- }
-
- if (info->gpio_present) {
- unsigned int state;
- unsigned int changed;
- spin_lock(&info->lock);
- while ((changed = rd_reg32(info, IOSR)) != 0) {
- DBGISR(("%s iosr=%08x\n", info->device_name, changed));
- /* read latched state of GPIO signals */
- state = rd_reg32(info, IOVR);
- /* clear pending GPIO interrupt bits */
- wr_reg32(info, IOSR, changed);
- for (i=0 ; i < info->port_count ; i++) {
- if (info->port_array[i] != NULL)
- isr_gpio(info->port_array[i], changed, state);
- }
- }
- spin_unlock(&info->lock);
- }
-
- for(i=0; i < info->port_count ; i++) {
- struct slgt_info *port = info->port_array[i];
- if (port == NULL)
- continue;
- spin_lock(&port->lock);
- if ((port->port.count || port->netcount) &&
- port->pending_bh && !port->bh_running &&
- !port->bh_requested) {
- DBGISR(("%s bh queued\n", port->device_name));
- schedule_work(&port->task);
- port->bh_requested = true;
- }
- spin_unlock(&port->lock);
- }
-
- DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level));
- return IRQ_HANDLED;
-}
-
-static int startup_hw(struct slgt_info *info)
-{
- DBGINFO(("%s startup\n", info->device_name));
-
- if (tty_port_initialized(&info->port))
- return 0;
-
- if (!info->tx_buf) {
- info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
- if (!info->tx_buf) {
- DBGERR(("%s can't allocate tx buffer\n", info->device_name));
- return -ENOMEM;
- }
- }
-
- info->pending_bh = 0;
-
- memset(&info->icount, 0, sizeof(info->icount));
-
- /* program hardware for current parameters */
- change_params(info);
-
- if (info->port.tty)
- clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, true);
-
- return 0;
-}
-
-/*
- * called by close() and hangup() to shutdown hardware
- */
-static void shutdown_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- if (!tty_port_initialized(&info->port))
- return;
-
- DBGINFO(("%s shutdown\n", info->device_name));
-
- /* clear status wait queue because status changes */
- /* can't happen after shutting down the hardware */
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
-
- timer_delete_sync(&info->tx_timer);
- timer_delete_sync(&info->rx_timer);
-
- kfree(info->tx_buf);
- info->tx_buf = NULL;
-
- spin_lock_irqsave(&info->lock,flags);
-
- tx_stop(info);
- rx_stop(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-
- if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- }
-
- flush_cond_wait(&info->gpio_wait_q);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- if (info->port.tty)
- set_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, false);
-}
-
-static void program_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
-
- rx_stop(info);
- tx_stop(info);
-
- if (info->params.mode != MGSL_MODE_ASYNC ||
- info->netcount)
- sync_mode(info);
- else
- async_mode(info);
-
- set_gtsignals(info);
-
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
-
- slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI);
- get_gtsignals(info);
-
- if (info->netcount ||
- (info->port.tty && info->port.tty->termios.c_cflag & CREAD))
- rx_start(info);
-
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * reconfigure adapter based on new parameters
- */
-static void change_params(struct slgt_info *info)
-{
- unsigned cflag;
- int bits_per_char;
-
- if (!info->port.tty)
- return;
- DBGINFO(("%s change_params\n", info->device_name));
-
- cflag = info->port.tty->termios.c_cflag;
-
- /* if B0 rate (hangup) specified then negate RTS and DTR */
- /* otherwise assert RTS and DTR */
- if (cflag & CBAUD)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
-
- /* byte size and parity */
-
- info->params.data_bits = tty_get_char_size(cflag);
- info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1;
-
- if (cflag & PARENB)
- info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN;
- else
- info->params.parity = ASYNC_PARITY_NONE;
-
- /* calculate number of jiffies to transmit a full
- * FIFO (32 bytes) at specified data rate
- */
- bits_per_char = info->params.data_bits +
- info->params.stop_bits + 1;
-
- info->params.data_rate = tty_get_baud_rate(info->port.tty);
-
- if (info->params.data_rate) {
- info->timeout = (32*HZ*bits_per_char) /
- info->params.data_rate;
- }
- info->timeout += HZ/50; /* Add .02 seconds of slop */
-
- tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
- tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL);
-
- /* process tty input control flags */
-
- info->read_status_mask = IRQ_RXOVER;
- if (I_INPCK(info->port.tty))
- info->read_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
- info->read_status_mask |= MASK_BREAK;
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_IGNBRK(info->port.tty)) {
- info->ignore_status_mask |= MASK_BREAK;
- /* If ignoring parity and break indicators, ignore
- * overruns too. (For real raw support).
- */
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_OVERRUN;
- }
-
- program_hw(info);
-}
-
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount)
-{
- DBGINFO(("%s get_stats\n", info->device_name));
- if (!user_icount) {
- memset(&info->icount, 0, sizeof(info->icount));
- } else {
- if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount)))
- return -EFAULT;
- }
- return 0;
-}
-
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params)
-{
- DBGINFO(("%s get_params\n", info->device_name));
- if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
- return 0;
-}
-
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params)
-{
- unsigned long flags;
- MGSL_PARAMS tmp_params;
-
- DBGINFO(("%s set_params\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK)
- info->base_clock = tmp_params.clock_speed;
- else
- memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS));
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static int get_txidle(struct slgt_info *info, int __user *idle_mode)
-{
- DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode));
- if (put_user(info->idle_mode, idle_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_txidle(struct slgt_info *info, int idle_mode)
-{
- unsigned long flags;
- DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->idle_mode = idle_mode;
- if (info->params.mode != MGSL_MODE_ASYNC)
- tx_set_idle(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int tx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- if (enable) {
- if (!info->tx_enabled)
- tx_start(info);
- } else {
- if (info->tx_enabled)
- tx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * abort transmit HDLC frame
- */
-static int tx_abort(struct slgt_info *info)
-{
- unsigned long flags;
- DBGINFO(("%s tx_abort\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- tdma_reset(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int rx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- unsigned int rbuf_fill_level;
- DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- /*
- * enable[31..16] = receive DMA buffer fill level
- * 0 = noop (leave fill level unchanged)
- * fill level must be multiple of 4 and <= buffer size
- */
- rbuf_fill_level = ((unsigned int)enable) >> 16;
- if (rbuf_fill_level) {
- if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
- spin_unlock_irqrestore(&info->lock, flags);
- return -EINVAL;
- }
- info->rbuf_fill_level = rbuf_fill_level;
- if (rbuf_fill_level < 128)
- info->rx_pio = 1; /* PIO mode */
- else
- info->rx_pio = 0; /* DMA mode */
- rx_stop(info); /* restart receiver to use new fill level */
- }
-
- /*
- * enable[1..0] = receiver enable command
- * 0 = disable
- * 1 = enable
- * 2 = enable or force hunt mode if already enabled
- */
- enable &= 3;
- if (enable) {
- if (!info->rx_enabled)
- rx_start(info);
- else if (enable == 2) {
- /* force hunt mode (write 1 to RCR[3]) */
- wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
- }
- } else {
- if (info->rx_enabled)
- rx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * wait for specified event to occur
- */
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr)
-{
- unsigned long flags;
- int s;
- int rc=0;
- struct mgsl_icount cprev, cnow;
- int events;
- int mask;
- struct _input_signal_events oldsigs, newsigs;
- DECLARE_WAITQUEUE(wait, current);
-
- if (get_user(mask, mask_ptr))
- return -EFAULT;
-
- DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask));
-
- spin_lock_irqsave(&info->lock,flags);
-
- /* return immediately if state matches requested events */
- get_gtsignals(info);
- s = info->signals;
-
- events = mask &
- ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
- ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
- ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
- ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
- if (events) {
- spin_unlock_irqrestore(&info->lock,flags);
- goto exit;
- }
-
- /* save current irq counts */
- cprev = info->icount;
- oldsigs = info->input_signal_events;
-
- /* enable hunt and idle irqs if needed */
- if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
- unsigned short val = rd_reg16(info, SCR);
- if (!(val & IRQ_RXIDLE))
- wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE));
- }
-
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&info->event_wait_q, &wait);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- newsigs = info->input_signal_events;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (newsigs.dsr_up == oldsigs.dsr_up &&
- newsigs.dsr_down == oldsigs.dsr_down &&
- newsigs.dcd_up == oldsigs.dcd_up &&
- newsigs.dcd_down == oldsigs.dcd_down &&
- newsigs.cts_up == oldsigs.cts_up &&
- newsigs.cts_down == oldsigs.cts_down &&
- newsigs.ri_up == oldsigs.ri_up &&
- newsigs.ri_down == oldsigs.ri_down &&
- cnow.exithunt == cprev.exithunt &&
- cnow.rxidle == cprev.rxidle) {
- rc = -EIO;
- break;
- }
-
- events = mask &
- ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
- (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
- (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
- (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
- (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
- (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
- (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
- (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
- (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
- (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
- if (events)
- break;
-
- cprev = cnow;
- oldsigs = newsigs;
- }
-
- remove_wait_queue(&info->event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
-
-
- if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
- spin_lock_irqsave(&info->lock,flags);
- if (!waitqueue_active(&info->event_wait_q)) {
- /* disable enable exit hunt mode/idle rcvd IRQs */
- wr_reg16(info, SCR,
- (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE));
- }
- spin_unlock_irqrestore(&info->lock,flags);
- }
-exit:
- if (rc == 0)
- rc = put_user(events, mask_ptr);
- return rc;
-}
-
-static int get_interface(struct slgt_info *info, int __user *if_mode)
-{
- DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode));
- if (put_user(info->if_mode, if_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_interface(struct slgt_info *info, int if_mode)
-{
- unsigned long flags;
- unsigned short val;
-
- DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->if_mode = if_mode;
-
- msc_set_vcr(info);
-
- /* TCR (tx control) 07 1=RTS driver control */
- val = rd_reg16(info, TCR);
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
- else
- val &= ~BIT7;
- wr_reg16(info, TCR, val);
-
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int get_xsync(struct slgt_info *info, int __user *xsync)
-{
- DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync));
- if (put_user(info->xsync, xsync))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended sync pattern (1 to 4 bytes) for extended sync mode
- *
- * sync pattern is contained in least significant bytes of value
- * most significant byte of sync pattern is oldest (1st sent/detected)
- */
-static int set_xsync(struct slgt_info *info, int xsync)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync));
- spin_lock_irqsave(&info->lock, flags);
- info->xsync = xsync;
- wr_reg32(info, XSR, xsync);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-static int get_xctrl(struct slgt_info *info, int __user *xctrl)
-{
- DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl));
- if (put_user(info->xctrl, xctrl))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended control options
- *
- * xctrl[31:19] reserved, must be zero
- * xctrl[18:17] extended sync pattern length in bytes
- * 00 = 1 byte in xsr[7:0]
- * 01 = 2 bytes in xsr[15:0]
- * 10 = 3 bytes in xsr[23:0]
- * 11 = 4 bytes in xsr[31:0]
- * xctrl[16] 1 = enable terminal count, 0=disabled
- * xctrl[15:0] receive terminal count for fixed length packets
- * value is count minus one (0 = 1 byte packet)
- * when terminal count is reached, receiver
- * automatically returns to hunt mode and receive
- * FIFO contents are flushed to DMA buffers with
- * end of frame (EOF) status
- */
-static int set_xctrl(struct slgt_info *info, int xctrl)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl));
- spin_lock_irqsave(&info->lock, flags);
- info->xctrl = xctrl;
- wr_reg32(info, XCR, xctrl);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-/*
- * set general purpose IO pin state and direction
- *
- * user_gpio fields:
- * state each bit indicates a pin state
- * smask set bit indicates pin state to set
- * dir each bit indicates a pin direction (0=input, 1=output)
- * dmask set bit indicates pin direction to set
- */
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- struct gpio_desc gpio;
- __u32 data;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
- info->device_name, gpio.state, gpio.smask,
- gpio.dir, gpio.dmask));
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- if (gpio.dmask) {
- data = rd_reg32(info, IODR);
- data |= gpio.dmask & gpio.dir;
- data &= ~(gpio.dmask & ~gpio.dir);
- wr_reg32(info, IODR, data);
- }
- if (gpio.smask) {
- data = rd_reg32(info, IOVR);
- data |= gpio.smask & gpio.state;
- data &= ~(gpio.smask & ~gpio.state);
- wr_reg32(info, IOVR, data);
- }
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- return 0;
-}
-
-/*
- * get general purpose IO pin state and direction
- */
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- struct gpio_desc gpio;
- if (!info->gpio_present)
- return -EINVAL;
- gpio.state = rd_reg32(info, IOVR);
- gpio.smask = 0xffffffff;
- gpio.dir = rd_reg32(info, IODR);
- gpio.dmask = 0xffffffff;
- if (copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s get_gpio state=%08x dir=%08x\n",
- info->device_name, gpio.state, gpio.dir));
- return 0;
-}
-
-/*
- * conditional wait facility
- */
-static void init_cond_wait(struct cond_wait *w, unsigned int data)
-{
- init_waitqueue_head(&w->q);
- init_waitqueue_entry(&w->wait, current);
- w->data = data;
-}
-
-static void add_cond_wait(struct cond_wait **head, struct cond_wait *w)
-{
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&w->q, &w->wait);
- w->next = *head;
- *head = w;
-}
-
-static void remove_cond_wait(struct cond_wait **head, struct cond_wait *cw)
-{
- struct cond_wait *w, *prev;
- remove_wait_queue(&cw->q, &cw->wait);
- set_current_state(TASK_RUNNING);
- for (w = *head, prev = NULL ; w != NULL ; prev = w, w = w->next) {
- if (w == cw) {
- if (prev != NULL)
- prev->next = w->next;
- else
- *head = w->next;
- break;
- }
- }
-}
-
-static void flush_cond_wait(struct cond_wait **head)
-{
- while (*head != NULL) {
- wake_up_interruptible(&(*head)->q);
- *head = (*head)->next;
- }
-}
-
-/*
- * wait for general purpose I/O pin(s) to enter specified state
- *
- * user_gpio fields:
- * state - bit indicates target pin state
- * smask - set bit indicates watched pin
- *
- * The wait ends when at least one watched pin enters the specified
- * state. When 0 (no error) is returned, user_gpio->state is set to the
- * state of all GPIO pins when the wait ends.
- *
- * Note: Each pin may be a dedicated input, dedicated output, or
- * configurable input/output. The number and configuration of pins
- * varies with the specific adapter model. Only input pins (dedicated
- * or configured) can be monitored with this function.
- */
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- int rc = 0;
- struct gpio_desc gpio;
- struct cond_wait wait;
- u32 state;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s wait_gpio() state=%08x smask=%08x\n",
- info->device_name, gpio.state, gpio.smask));
- /* ignore output pins identified by set IODR bit */
- if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0)
- return -EINVAL;
- init_cond_wait(&wait, gpio.smask);
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- /* enable interrupts for watched pins */
- wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
- /* get current pin states */
- state = rd_reg32(info, IOVR);
-
- if (gpio.smask & ~(state ^ gpio.state)) {
- /* already in target state */
- gpio.state = state;
- } else {
- /* wait for target state */
- add_cond_wait(&info->gpio_wait_q, &wait);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
- schedule();
- if (signal_pending(current))
- rc = -ERESTARTSYS;
- else
- gpio.state = wait.data;
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- remove_cond_wait(&info->gpio_wait_q, &wait);
- }
-
- /* disable all GPIO interrupts if no waiting processes */
- if (info->gpio_wait_q == NULL)
- wr_reg32(info, IOER, 0);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- rc = -EFAULT;
- return rc;
-}
-
-static int modem_input_wait(struct slgt_info *info,int arg)
-{
- unsigned long flags;
- int rc;
- struct mgsl_icount cprev, cnow;
- DECLARE_WAITQUEUE(wait, current);
-
- /* save current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cprev = info->icount;
- add_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get new irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
- cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
- rc = -EIO;
- break;
- }
-
- /* check for change in caller specified modem input */
- if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
- (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
- (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
- (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
- rc = 0;
- break;
- }
-
- cprev = cnow;
- }
- remove_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
- return rc;
-}
-
-/*
- * return state of serial control and status signals
- */
-static int tiocmget(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int result;
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
- ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
- ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
- ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) +
- ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
- ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0);
-
- DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result));
- return result;
-}
-
-/*
- * set modem control signals (DTR/RTS)
- *
- * cmd signal command: TIOCMBIS = set bit TIOCMBIC = clear bit
- * TIOCMSET = set/clear signal values
- * value bit mask for command
- */
-static int tiocmset(struct tty_struct *tty,
- unsigned int set, unsigned int clear)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear));
-
- if (set & TIOCM_RTS)
- info->signals |= SerialSignal_RTS;
- if (set & TIOCM_DTR)
- info->signals |= SerialSignal_DTR;
- if (clear & TIOCM_RTS)
- info->signals &= ~SerialSignal_RTS;
- if (clear & TIOCM_DTR)
- info->signals &= ~SerialSignal_DTR;
-
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static bool carrier_raised(struct tty_port *port)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- return info->signals & SerialSignal_DCD;
-}
-
-static void dtr_rts(struct tty_port *port, bool active)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- if (active)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-
-/*
- * block current process until the device is ready to open
- */
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
- struct slgt_info *info)
-{
- DECLARE_WAITQUEUE(wait, current);
- int retval;
- bool do_clocal = false;
- unsigned long flags;
- bool cd;
- struct tty_port *port = &info->port;
-
- DBGINFO(("%s block_til_ready\n", tty->driver->name));
-
- if (filp->f_flags & O_NONBLOCK || tty_io_error(tty)) {
- /* nonblock mode is set or port is not enabled */
- tty_port_set_active(port, true);
- return 0;
- }
-
- if (C_CLOCAL(tty))
- do_clocal = true;
-
- /* Wait for carrier detect and the line to become
- * free (i.e., not in use by the callout). While we are in
- * this loop, port->count is dropped by one, so that
- * close() knows when to free things. We restore it upon
- * exit, either normal or abnormal.
- */
-
- retval = 0;
- add_wait_queue(&port->open_wait, &wait);
-
- spin_lock_irqsave(&info->lock, flags);
- port->count--;
- spin_unlock_irqrestore(&info->lock, flags);
- port->blocked_open++;
-
- while (1) {
- if (C_BAUD(tty) && tty_port_initialized(port))
- tty_port_raise_dtr_rts(port);
-
- set_current_state(TASK_INTERRUPTIBLE);
-
- if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
- retval = (port->flags & ASYNC_HUP_NOTIFY) ?
- -EAGAIN : -ERESTARTSYS;
- break;
- }
-
- cd = tty_port_carrier_raised(port);
- if (do_clocal || cd)
- break;
-
- if (signal_pending(current)) {
- retval = -ERESTARTSYS;
- break;
- }
-
- DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
- tty_unlock(tty);
- schedule();
- tty_lock(tty);
- }
-
- set_current_state(TASK_RUNNING);
- remove_wait_queue(&port->open_wait, &wait);
-
- if (!tty_hung_up_p(filp))
- port->count++;
- port->blocked_open--;
-
- if (!retval)
- tty_port_set_active(port, true);
-
- DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
- return retval;
-}
-
-/*
- * allocate buffers used for calling line discipline receive_buf
- * directly in synchronous mode
- * note: add 5 bytes to max frame size to allow appending
- * 32-bit CRC and status byte when configured to do so
- */
-static int alloc_tmp_rbuf(struct slgt_info *info)
-{
- info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL);
- if (info->tmp_rbuf == NULL)
- return -ENOMEM;
-
- return 0;
-}
-
-static void free_tmp_rbuf(struct slgt_info *info)
-{
- kfree(info->tmp_rbuf);
- info->tmp_rbuf = NULL;
-}
-
-/*
- * allocate DMA descriptor lists.
- */
-static int alloc_desc(struct slgt_info *info)
-{
- unsigned int i;
- unsigned int pbufs;
-
- /* allocate memory to hold descriptor lists */
- info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- &info->bufs_dma_addr, GFP_KERNEL);
- if (info->bufs == NULL)
- return -ENOMEM;
-
- info->rbufs = (struct slgt_desc*)info->bufs;
- info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count;
-
- pbufs = (unsigned int)info->bufs_dma_addr;
-
- /*
- * Build circular lists of descriptors
- */
-
- for (i=0; i < info->rbuf_count; i++) {
- /* physical address of this descriptor */
- info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->rbuf_count - 1)
- info->rbufs[i].next = cpu_to_le32(pbufs);
- else
- info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc)));
- set_desc_count(info->rbufs[i], DMABUFSIZE);
- }
-
- for (i=0; i < info->tbuf_count; i++) {
- /* physical address of this descriptor */
- info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->tbuf_count - 1)
- info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc));
- else
- info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc)));
- }
-
- return 0;
-}
-
-static void free_desc(struct slgt_info *info)
-{
- if (info->bufs != NULL) {
- dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- info->bufs, info->bufs_dma_addr);
- info->bufs = NULL;
- info->rbufs = NULL;
- info->tbufs = NULL;
- }
-}
-
-static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE,
- &bufs[i].buf_dma_addr, GFP_KERNEL);
- if (!bufs[i].buf)
- return -ENOMEM;
- bufs[i].pbuf = cpu_to_le32((unsigned int)bufs[i].buf_dma_addr);
- }
- return 0;
-}
-
-static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- if (bufs[i].buf == NULL)
- continue;
- dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf,
- bufs[i].buf_dma_addr);
- bufs[i].buf = NULL;
- }
-}
-
-static int alloc_dma_bufs(struct slgt_info *info)
-{
- info->rbuf_count = 32;
- info->tbuf_count = 32;
-
- if (alloc_desc(info) < 0 ||
- alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 ||
- alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 ||
- alloc_tmp_rbuf(info) < 0) {
- DBGERR(("%s DMA buffer alloc fail\n", info->device_name));
- return -ENOMEM;
- }
- reset_rbufs(info);
- return 0;
-}
-
-static void free_dma_bufs(struct slgt_info *info)
-{
- if (info->bufs) {
- free_bufs(info, info->rbufs, info->rbuf_count);
- free_bufs(info, info->tbufs, info->tbuf_count);
- free_desc(info);
- }
- free_tmp_rbuf(info);
-}
-
-static int claim_resources(struct slgt_info *info)
-{
- if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) {
- DBGERR(("%s reg addr conflict, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_AddressConflict;
- goto errout;
- }
- else
- info->reg_addr_requested = true;
-
- info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE);
- if (!info->reg_addr) {
- DBGERR(("%s can't map device registers, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_CantAssignPciResources;
- goto errout;
- }
- return 0;
-
-errout:
- release_resources(info);
- return -ENODEV;
-}
-
-static void release_resources(struct slgt_info *info)
-{
- if (info->irq_requested) {
- free_irq(info->irq_level, info);
- info->irq_requested = false;
- }
-
- if (info->reg_addr_requested) {
- release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE);
- info->reg_addr_requested = false;
- }
-
- if (info->reg_addr) {
- iounmap(info->reg_addr);
- info->reg_addr = NULL;
- }
-}
-
-/* Add the specified device instance data structure to the
- * global linked list of devices and increment the device count.
- */
-static void add_device(struct slgt_info *info)
-{
- char *devstr;
-
- info->next_device = NULL;
- info->line = slgt_device_count;
- sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line);
-
- if (info->line < MAX_DEVICES) {
- if (maxframe[info->line])
- info->max_frame_size = maxframe[info->line];
- }
-
- slgt_device_count++;
-
- if (!slgt_device_list)
- slgt_device_list = info;
- else {
- struct slgt_info *current_dev = slgt_device_list;
- while(current_dev->next_device)
- current_dev = current_dev->next_device;
- current_dev->next_device = info;
- }
-
- if (info->max_frame_size < 4096)
- info->max_frame_size = 4096;
- else if (info->max_frame_size > 65535)
- info->max_frame_size = 65535;
-
- switch(info->pdev->device) {
- case SYNCLINK_GT_DEVICE_ID:
- devstr = "GT";
- break;
- case SYNCLINK_GT2_DEVICE_ID:
- devstr = "GT2";
- break;
- case SYNCLINK_GT4_DEVICE_ID:
- devstr = "GT4";
- break;
- case SYNCLINK_AC_DEVICE_ID:
- devstr = "AC";
- info->params.mode = MGSL_MODE_ASYNC;
- break;
- default:
- devstr = "(unknown model)";
- }
- printk("SyncLink %s %s IO=%08x IRQ=%d MaxFrameSize=%u\n",
- devstr, info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_init(info);
-#endif
-}
-
-static const struct tty_port_operations slgt_port_ops = {
- .carrier_raised = carrier_raised,
- .dtr_rts = dtr_rts,
-};
-
-/*
- * allocate device instance structure, return NULL on failure
- */
-static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
-{
- struct slgt_info *info;
-
- info = kzalloc_obj(struct slgt_info);
-
- if (!info) {
- DBGERR(("%s device alloc failed adapter=%d port=%d\n",
- driver_name, adapter_num, port_num));
- } else {
- tty_port_init(&info->port);
- info->port.ops = &slgt_port_ops;
- INIT_WORK(&info->task, bh_handler);
- info->max_frame_size = 4096;
- info->base_clock = 14745600;
- info->rbuf_fill_level = DMABUFSIZE;
- init_waitqueue_head(&info->status_event_wait_q);
- init_waitqueue_head(&info->event_wait_q);
- spin_lock_init(&info->netlock);
- memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
- info->idle_mode = HDLC_TXIDLE_FLAGS;
- info->adapter_num = adapter_num;
- info->port_num = port_num;
-
- timer_setup(&info->tx_timer, tx_timeout, 0);
- timer_setup(&info->rx_timer, rx_timeout, 0);
-
- /* Copy configuration info to device instance data */
- info->pdev = pdev;
- info->irq_level = pdev->irq;
- info->phys_reg_addr = pci_resource_start(pdev,0);
-
- info->bus_type = MGSL_BUS_TYPE_PCI;
- info->irq_flags = IRQF_SHARED;
-
- info->init_error = -1; /* assume error, set to 0 on successful init */
- }
-
- return info;
-}
-
-static void device_init(int adapter_num, struct pci_dev *pdev)
-{
- struct slgt_info *port_array[SLGT_MAX_PORTS];
- int i;
- int port_count = 1;
-
- if (pdev->device == SYNCLINK_GT2_DEVICE_ID)
- port_count = 2;
- else if (pdev->device == SYNCLINK_GT4_DEVICE_ID)
- port_count = 4;
-
- /* allocate device instances for all ports */
- for (i=0; i < port_count; ++i) {
- port_array[i] = alloc_dev(adapter_num, i, pdev);
- if (port_array[i] == NULL) {
- for (--i; i >= 0; --i) {
- tty_port_destroy(&port_array[i]->port);
- kfree(port_array[i]);
- }
- return;
- }
- }
-
- /* give copy of port_array to all ports and add to device list */
- for (i=0; i < port_count; ++i) {
- memcpy(port_array[i]->port_array, port_array, sizeof(port_array));
- add_device(port_array[i]);
- port_array[i]->port_count = port_count;
- spin_lock_init(&port_array[i]->lock);
- }
-
- /* Allocate and claim adapter resources */
- if (!claim_resources(port_array[0])) {
-
- alloc_dma_bufs(port_array[0]);
-
- /* copy resource information from first port to others */
- for (i = 1; i < port_count; ++i) {
- port_array[i]->irq_level = port_array[0]->irq_level;
- port_array[i]->reg_addr = port_array[0]->reg_addr;
- alloc_dma_bufs(port_array[i]);
- }
-
- if (request_irq(port_array[0]->irq_level,
- slgt_interrupt,
- port_array[0]->irq_flags,
- port_array[0]->device_name,
- port_array[0]) < 0) {
- DBGERR(("%s request_irq failed IRQ=%d\n",
- port_array[0]->device_name,
- port_array[0]->irq_level));
- } else {
- port_array[0]->irq_requested = true;
- adapter_test(port_array[0]);
- for (i=1 ; i < port_count ; i++) {
- port_array[i]->init_error = port_array[0]->init_error;
- port_array[i]->gpio_present = port_array[0]->gpio_present;
- }
- }
- }
-
- for (i = 0; i < port_count; ++i) {
- struct slgt_info *info = port_array[i];
- tty_port_register_device(&info->port, serial_driver, info->line,
- &info->pdev->dev);
- }
-}
-
-static int init_one(struct pci_dev *dev,
- const struct pci_device_id *ent)
-{
- if (pci_enable_device(dev)) {
- printk("error enabling pci device %p\n", dev);
- return -EIO;
- }
- pci_set_master(dev);
- device_init(slgt_device_count, dev);
- return 0;
-}
-
-static void remove_one(struct pci_dev *dev)
-{
-}
-
-static const struct tty_operations ops = {
- .open = open,
- .close = close,
- .write = write,
- .put_char = put_char,
- .flush_chars = flush_chars,
- .write_room = write_room,
- .chars_in_buffer = chars_in_buffer,
- .flush_buffer = flush_buffer,
- .ioctl = ioctl,
- .compat_ioctl = slgt_compat_ioctl,
- .throttle = throttle,
- .unthrottle = unthrottle,
- .send_xchar = send_xchar,
- .break_ctl = set_break,
- .wait_until_sent = wait_until_sent,
- .set_termios = set_termios,
- .stop = tx_hold,
- .start = tx_release,
- .hangup = hangup,
- .tiocmget = tiocmget,
- .tiocmset = tiocmset,
- .get_icount = get_icount,
- .proc_show = synclink_gt_proc_show,
-};
-
-static void slgt_cleanup(void)
-{
- struct slgt_info *info;
- struct slgt_info *tmp;
-
- if (serial_driver) {
- for (info=slgt_device_list ; info != NULL ; info=info->next_device)
- tty_unregister_device(serial_driver, info->line);
- tty_unregister_driver(serial_driver);
- tty_driver_kref_put(serial_driver);
- }
-
- /* reset devices */
- info = slgt_device_list;
- while(info) {
- reset_port(info);
- info = info->next_device;
- }
-
- /* release devices */
- info = slgt_device_list;
- while(info) {
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_exit(info);
-#endif
- free_dma_bufs(info);
- free_tmp_rbuf(info);
- if (info->port_num == 0)
- release_resources(info);
- tmp = info;
- info = info->next_device;
- tty_port_destroy(&tmp->port);
- kfree(tmp);
- }
-
- if (pci_registered)
- pci_unregister_driver(&pci_driver);
-}
-
-/*
- * Driver initialization entry point.
- */
-static int __init slgt_init(void)
-{
- int rc;
-
- serial_driver = tty_alloc_driver(MAX_DEVICES, TTY_DRIVER_REAL_RAW |
- TTY_DRIVER_DYNAMIC_DEV);
- if (IS_ERR(serial_driver)) {
- printk("%s can't allocate tty driver\n", driver_name);
- return PTR_ERR(serial_driver);
- }
-
- /* Initialize the tty_driver structure */
-
- serial_driver->driver_name = "synclink_gt";
- serial_driver->name = tty_dev_prefix;
- serial_driver->major = ttymajor;
- serial_driver->minor_start = 64;
- serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
- serial_driver->subtype = SERIAL_TYPE_NORMAL;
- serial_driver->init_termios = tty_std_termios;
- serial_driver->init_termios.c_cflag =
- B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- serial_driver->init_termios.c_ispeed = 9600;
- serial_driver->init_termios.c_ospeed = 9600;
- tty_set_operations(serial_driver, &ops);
- if ((rc = tty_register_driver(serial_driver)) < 0) {
- DBGERR(("%s can't register serial driver\n", driver_name));
- tty_driver_kref_put(serial_driver);
- serial_driver = NULL;
- goto error;
- }
-
- slgt_device_count = 0;
- if ((rc = pci_register_driver(&pci_driver)) < 0) {
- printk("%s pci_register_driver error=%d\n", driver_name, rc);
- goto error;
- }
- pci_registered = true;
-
- return 0;
-
-error:
- slgt_cleanup();
- return rc;
-}
-
-static void __exit slgt_exit(void)
-{
- slgt_cleanup();
-}
-
-module_init(slgt_init);
-module_exit(slgt_exit);
-
-/*
- * register access routines
- */
-
-static inline void __iomem *calc_regaddr(struct slgt_info *info,
- unsigned int addr)
-{
- void __iomem *reg_addr = info->reg_addr + addr;
-
- if (addr >= 0x80)
- reg_addr += info->port_num * 32;
- else if (addr >= 0x40)
- reg_addr += info->port_num * 16;
-
- return reg_addr;
-}
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr)
-{
- return readb(calc_regaddr(info, addr));
-}
-
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value)
-{
- writeb(value, calc_regaddr(info, addr));
-}
-
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr)
-{
- return readw(calc_regaddr(info, addr));
-}
-
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value)
-{
- writew(value, calc_regaddr(info, addr));
-}
-
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr)
-{
- return readl(calc_regaddr(info, addr));
-}
-
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value)
-{
- writel(value, calc_regaddr(info, addr));
-}
-
-static void rdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, RDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, RDCSR) & BIT0))
- break;
-}
-
-static void tdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, TDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, TDCSR) & BIT0))
- break;
-}
-
-/*
- * enable internal loopback
- * TxCLK and RxCLK are generated from BRG
- * and TxD is looped back to RxD internally.
- */
-static void enable_loopback(struct slgt_info *info)
-{
- /* SCR (serial control) BIT2=loopback enable */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2));
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* CCR (clock control)
- * 07..05 tx clock source (010 = BRG)
- * 04..02 rx clock source (010 = BRG)
- * 01 auxclk enable (0 = disable)
- * 00 BRG enable (1 = enable)
- *
- * 0100 1001
- */
- wr_reg8(info, CCR, 0x49);
-
- /* set speed if available, otherwise use default */
- if (info->params.clock_speed)
- set_rate(info, info->params.clock_speed);
- else
- set_rate(info, 3686400);
- }
-}
-
-/*
- * set baud rate generator to specified rate
- */
-static void set_rate(struct slgt_info *info, u32 rate)
-{
- unsigned int div;
- unsigned int osc = info->base_clock;
-
- /* div = osc/rate - 1
- *
- * Round div up if osc/rate is not integer to
- * force to next slowest rate.
- */
-
- if (rate) {
- div = osc/rate;
- if (!(osc % rate) && div)
- div--;
- wr_reg16(info, BDR, (unsigned short)div);
- }
-}
-
-static void rx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- /* disable and reset receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE);
-
- /* clear pending rx interrupts */
- wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER);
-
- rdma_reset(info);
-
- info->rx_enabled = false;
- info->rx_restart = false;
-}
-
-static void rx_start(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA);
-
- /* clear pending rx overrun IRQ */
- wr_reg16(info, SSR, IRQ_RXOVER);
-
- /* reset and disable receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- rdma_reset(info);
- reset_rbufs(info);
-
- if (info->rx_pio) {
- /* rx request when rx FIFO not empty */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
- slgt_irq_on(info, IRQ_RXDATA);
- if (info->params.mode == MGSL_MODE_ASYNC) {
- /* enable saving of rx status */
- wr_reg32(info, RDCSR, BIT6);
- }
- } else {
- /* rx request when rx FIFO half full */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
- /* set 1st descriptor address */
- wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* enable rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT2 + BIT0));
- } else {
- /* enable saving of rx status, rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
- }
- }
-
- slgt_irq_on(info, IRQ_RXOVER);
-
- /* enable receiver */
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1));
-
- info->rx_restart = false;
- info->rx_enabled = true;
-}
-
-static void tx_start(struct slgt_info *info)
-{
- if (!info->tx_enabled) {
- wr_reg16(info, TCR,
- (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
- info->tx_enabled = true;
- }
-
- if (desc_count(info->tbufs[info->tbuf_start])) {
- info->drop_rts_on_tx_done = false;
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
- get_gtsignals(info);
- if (!(info->signals & SerialSignal_RTS)) {
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- info->drop_rts_on_tx_done = true;
- }
- }
-
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE);
- /* clear tx idle and underrun status bits */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
- } else {
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXIDLE);
- /* clear tx idle status bit */
- wr_reg16(info, SSR, IRQ_TXIDLE);
- }
- /* set 1st descriptor address and start DMA */
- wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
- wr_reg32(info, TDCSR, BIT2 + BIT0);
- info->tx_active = true;
- }
-}
-
-static void tx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- timer_delete(&info->tx_timer);
-
- tdma_reset(info);
-
- /* reset and disable transmitter */
- val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
-
- /* clear tx idle and underrun status bit */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
-
- reset_tbufs(info);
-
- info->tx_enabled = false;
- info->tx_active = false;
-}
-
-static void reset_port(struct slgt_info *info)
-{
- if (!info->reg_addr)
- return;
-
- tx_stop(info);
- rx_stop(info);
-
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-}
-
-static void reset_adapter(struct slgt_info *info)
-{
- int i;
- for (i=0; i < info->port_count; ++i) {
- if (info->port_array[i])
- reset_port(info->port_array[i]);
- }
-}
-
-static void async_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07 1=RTS driver control
- * 06 1=break enable
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 0=1 stop bit, 1=2 stop bits
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = 0x4000;
-
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.stop_bits != 1)
- val |= BIT3;
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* RCR (rx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07..06 reserved, must be 0
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 reserved, must be zero
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0x4000;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 011 = tx clock source is BRG/16
- * 04..02 010 = rx clock source is BRG
- * 01 0 = auxclk disabled
- * 00 1 = BRG enabled
- *
- * 0110 1001
- */
- wr_reg8(info, CCR, 0x69);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 rx break on IRQ enable
- * 10 rx data IRQ enable
- * 09 rx break off IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 0=16x sampling, 1=8x sampling
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- val = BIT15 + BIT14 + BIT0;
- /* JCR[8] : 1 = x8 async mode feature available */
- if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate &&
- ((info->base_clock < (info->params.data_rate * 16)) ||
- (info->base_clock % (info->params.data_rate * 16)))) {
- /* use 8x sampling */
- val |= BIT3;
- set_rate(info, info->params.data_rate * 8);
- } else {
- /* use 16x sampling */
- set_rate(info, info->params.data_rate * 16);
- }
- wr_reg16(info, SCR, val);
-
- slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-static void sync_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07 1=RTS driver control
- * 06 preamble enable
- * 05..04 preamble length
- * 03 share open/close flag
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = BIT2;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE)
- val |= BIT6;
-
- switch (info->params.preamble_length)
- {
- case HDLC_PREAMBLE_LENGTH_16BITS: val |= BIT5; break;
- case HDLC_PREAMBLE_LENGTH_32BITS: val |= BIT4; break;
- case HDLC_PREAMBLE_LENGTH_64BITS: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* TPR (transmit preamble) */
-
- switch (info->params.preamble)
- {
- case HDLC_PREAMBLE_PATTERN_FLAGS: val = 0x7e; break;
- case HDLC_PREAMBLE_PATTERN_ONES: val = 0xff; break;
- case HDLC_PREAMBLE_PATTERN_ZEROS: val = 0x00; break;
- case HDLC_PREAMBLE_PATTERN_10: val = 0x55; break;
- case HDLC_PREAMBLE_PATTERN_01: val = 0xaa; break;
- default: val = 0x7e; break;
- }
- wr_reg8(info, TPR, (unsigned char)val);
-
- /* RCR (rx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07..03 reserved, must be 0
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 tx clock source
- * 04..02 rx clock source
- * 01 auxclk enable
- * 00 BRG enable
- */
- val = 0;
-
- if (info->params.flags & HDLC_FLAG_TXC_BRG)
- {
- // when RxC source is DPLL, BRG generates 16X DPLL
- // reference clock, so take TxC from BRG/16 to get
- // transmit clock at actual data rate
- if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT6 + BIT5; /* 011, txclk = BRG/16 */
- else
- val |= BIT6; /* 010, txclk = BRG */
- }
- else if (info->params.flags & HDLC_FLAG_TXC_DPLL)
- val |= BIT7; /* 100, txclk = DPLL Input */
- else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN)
- val |= BIT5; /* 001, txclk = RXC Input */
-
- if (info->params.flags & HDLC_FLAG_RXC_BRG)
- val |= BIT3; /* 010, rxclk = BRG */
- else if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT4; /* 100, rxclk = DPLL */
- else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN)
- val |= BIT2; /* 001, rxclk = TXC Input */
-
- if (info->params.clock_speed)
- val |= BIT1 + BIT0;
-
- wr_reg8(info, CCR, (unsigned char)val);
-
- if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL))
- {
- // program DPLL mode
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_BIPHASE_MARK:
- case HDLC_ENCODING_BIPHASE_SPACE:
- val = BIT7; break;
- case HDLC_ENCODING_BIPHASE_LEVEL:
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL:
- val = BIT7 + BIT6; break;
- default: val = BIT6; // NRZ encodings
- }
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val));
-
- // DPLL requires a 16X reference clock from BRG
- set_rate(info, info->params.clock_speed * 16);
- }
- else
- set_rate(info, info->params.clock_speed);
-
- tx_set_idle(info);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 underrun IRQ enable
- * 10 rx data IRQ enable
- * 09 rx idle IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 reserved, must be zero
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- wr_reg16(info, SCR, BIT15 + BIT14 + BIT0);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-/*
- * set transmit idle mode
- */
-static void tx_set_idle(struct slgt_info *info)
-{
- unsigned char val;
- unsigned short tcr;
-
- /* if preamble enabled (tcr[6] == 1) then tx idle size = 8 bits
- * else tcr[5:4] = tx idle size: 00 = 8 bits, 01 = 16 bits
- */
- tcr = rd_reg16(info, TCR);
- if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) {
- /* disable preamble, set idle size to 16 bits */
- tcr = (tcr & ~(BIT6 + BIT5)) | BIT4;
- /* MSB of 16 bit idle specified in tx preamble register (TPR) */
- wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff));
- } else if (!(tcr & BIT6)) {
- /* preamble is disabled, set idle size to 8 bits */
- tcr &= ~(BIT5 + BIT4);
- }
- wr_reg16(info, TCR, tcr);
-
- if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) {
- /* LSB of custom tx idle specified in tx idle register */
- val = (unsigned char)(info->idle_mode & 0xff);
- } else {
- /* standard 8 bit idle patterns */
- switch(info->idle_mode)
- {
- case HDLC_TXIDLE_FLAGS: val = 0x7e; break;
- case HDLC_TXIDLE_ALT_ZEROS_ONES:
- case HDLC_TXIDLE_ALT_MARK_SPACE: val = 0xaa; break;
- case HDLC_TXIDLE_ZEROS:
- case HDLC_TXIDLE_SPACE: val = 0x00; break;
- default: val = 0xff;
- }
- }
-
- wr_reg8(info, TIR, val);
-}
-
-/*
- * get state of V24 status (input) signals
- */
-static void get_gtsignals(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- /* clear all serial signals except RTS and DTR */
- info->signals &= SerialSignal_RTS | SerialSignal_DTR;
-
- if (status & BIT3)
- info->signals |= SerialSignal_DSR;
- if (status & BIT2)
- info->signals |= SerialSignal_CTS;
- if (status & BIT1)
- info->signals |= SerialSignal_DCD;
- if (status & BIT0)
- info->signals |= SerialSignal_RI;
-}
-
-/*
- * set V.24 Control Register based on current configuration
- */
-static void msc_set_vcr(struct slgt_info *info)
-{
- unsigned char val = 0;
-
- /* VCR (V.24 control)
- *
- * 07..04 serial IF select
- * 03 DTR
- * 02 RTS
- * 01 LL
- * 00 RL
- */
-
- switch(info->if_mode & MGSL_INTERFACE_MASK)
- {
- case MGSL_INTERFACE_RS232:
- val |= BIT5; /* 0010 */
- break;
- case MGSL_INTERFACE_V35:
- val |= BIT7 + BIT6 + BIT5; /* 1110 */
- break;
- case MGSL_INTERFACE_RS422:
- val |= BIT6; /* 0100 */
- break;
- }
-
- if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
- val |= BIT4;
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- if (info->if_mode & MGSL_INTERFACE_LL)
- val |= BIT1;
- if (info->if_mode & MGSL_INTERFACE_RL)
- val |= BIT0;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * set state of V24 control (output) signals
- */
-static void set_gtsignals(struct slgt_info *info)
-{
- unsigned char val = rd_reg8(info, VCR);
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- else
- val &= ~BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- else
- val &= ~BIT2;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * free range of receive DMA buffers (i to last)
- */
-static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last)
-{
- int done = 0;
-
- while(!done) {
- /* reset current buffer for reuse */
- info->rbufs[i].status = 0;
- set_desc_count(info->rbufs[i], info->rbuf_fill_level);
- if (i == last)
- done = 1;
- if (++i == info->rbuf_count)
- i = 0;
- }
- info->rbuf_current = i;
-}
-
-/*
- * mark all receive DMA buffers as free
- */
-static void reset_rbufs(struct slgt_info *info)
-{
- free_rbufs(info, 0, info->rbuf_count - 1);
- info->rbuf_fill_index = 0;
- info->rbuf_fill_count = 0;
-}
-
-/*
- * pass receive HDLC frame to upper layer
- *
- * return true if frame available, otherwise false
- */
-static bool rx_get_frame(struct slgt_info *info)
-{
- unsigned int start, end;
- unsigned short status;
- unsigned int framesize = 0;
- unsigned long flags;
- struct tty_struct *tty = info->port.tty;
- unsigned char addr_field = 0xff;
- unsigned int crc_size = 0;
-
- switch (info->params.crc_type & HDLC_CRC_MASK) {
- case HDLC_CRC_16_CCITT: crc_size = 2; break;
- case HDLC_CRC_32_CCITT: crc_size = 4; break;
- }
-
-check_again:
-
- framesize = 0;
- addr_field = 0xff;
- start = end = info->rbuf_current;
-
- for (;;) {
- if (!desc_complete(info->rbufs[end]))
- goto cleanup;
-
- if (framesize == 0 && info->params.addr_filter != 0xff)
- addr_field = info->rbufs[end].buf[0];
-
- framesize += desc_count(info->rbufs[end]);
-
- if (desc_eof(info->rbufs[end]))
- break;
-
- if (++end == info->rbuf_count)
- end = 0;
-
- if (end == info->rbuf_current) {
- if (info->rx_enabled){
- spin_lock_irqsave(&info->lock,flags);
- rx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
- goto cleanup;
- }
- }
-
- /* status
- *
- * 15 buffer complete
- * 14..06 reserved
- * 05..04 residue
- * 02 eof (end of frame)
- * 01 CRC error
- * 00 abort
- */
- status = desc_status(info->rbufs[end]);
-
- /* ignore CRC bit if not using CRC (bit is undefined) */
- if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE)
- status &= ~BIT1;
-
- if (framesize == 0 ||
- (addr_field != 0xff && addr_field != info->params.addr_filter)) {
- free_rbufs(info, start, end);
- goto check_again;
- }
-
- if (framesize < (2 + crc_size) || status & BIT0) {
- info->icount.rxshort++;
- framesize = 0;
- } else if (status & BIT1) {
- info->icount.rxcrc++;
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX))
- framesize = 0;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (framesize == 0) {
- info->netdev->stats.rx_errors++;
- info->netdev->stats.rx_frame_errors++;
- }
-#endif
-
- DBGBH(("%s rx frame status=%04X size=%d\n",
- info->device_name, status, framesize));
- DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
-
- if (framesize) {
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
- framesize -= crc_size;
- crc_size = 0;
- }
-
- if (framesize > info->max_frame_size + crc_size)
- info->icount.rxlong++;
- else {
- /* copy dma buffer(s) to contiguous temp buffer */
- int copy_count = framesize;
- int i = start;
- unsigned char *p = info->tmp_rbuf;
- info->tmp_rbuf_count = framesize;
-
- info->icount.rxok++;
-
- while(copy_count) {
- int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
- memcpy(p, info->rbufs[i].buf, partial_count);
- p += partial_count;
- copy_count -= partial_count;
- if (++i == info->rbuf_count)
- i = 0;
- }
-
- if (info->params.crc_type & HDLC_CRC_RETURN_EX) {
- *p = (status & BIT1) ? RX_CRC_ERROR : RX_OK;
- framesize++;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_rx(info,info->tmp_rbuf, framesize);
- else
-#endif
- ldisc_receive_buf(tty, info->tmp_rbuf, NULL,
- framesize);
- }
- }
- free_rbufs(info, start, end);
- return true;
-
-cleanup:
- return false;
-}
-
-/*
- * pass receive buffer (RAW synchronous mode) to tty layer
- * return true if buffer available, otherwise false
- */
-static bool rx_get_buf(struct slgt_info *info)
-{
- unsigned int i = info->rbuf_current;
- unsigned int count;
-
- if (!desc_complete(info->rbufs[i]))
- return false;
- count = desc_count(info->rbufs[i]);
- switch(info->params.mode) {
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- /* ignore residue in byte synchronous modes */
- if (desc_residue(info->rbufs[i]))
- count--;
- break;
- }
- DBGDATA(info, info->rbufs[i].buf, count, "rx");
- DBGINFO(("rx_get_buf size=%d\n", count));
- if (count)
- ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, NULL,
- count);
- free_rbufs(info, i, i);
- return true;
-}
-
-static void reset_tbufs(struct slgt_info *info)
-{
- unsigned int i;
- info->tbuf_current = 0;
- for (i=0 ; i < info->tbuf_count ; i++) {
- info->tbufs[i].status = 0;
- info->tbufs[i].count = 0;
- }
-}
-
-/*
- * return number of free transmit DMA buffers
- */
-static unsigned int free_tbuf_count(struct slgt_info *info)
-{
- unsigned int count = 0;
- unsigned int i = info->tbuf_current;
-
- do
- {
- if (desc_count(info->tbufs[i]))
- break; /* buffer in use */
- ++count;
- if (++i == info->tbuf_count)
- i=0;
- } while (i != info->tbuf_current);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (count && (rd_reg32(info, TDCSR) & BIT0))
- --count;
-
- return count;
-}
-
-/*
- * return number of bytes in unsent transmit DMA buffers
- * and the serial controller tx FIFO
- */
-static unsigned int tbuf_bytes(struct slgt_info *info)
-{
- unsigned int total_count = 0;
- unsigned int i = info->tbuf_current;
- unsigned int reg_value;
- unsigned int count;
- unsigned int active_buf_count = 0;
-
- /*
- * Add descriptor counts for all tx DMA buffers.
- * If count is zero (cleared by DMA controller after read),
- * the buffer is complete or is actively being read from.
- *
- * Record buf_count of last buffer with zero count starting
- * from current ring position. buf_count is mirror
- * copy of count and is not cleared by serial controller.
- * If DMA controller is active, that buffer is actively
- * being read so add to total.
- */
- do {
- count = desc_count(info->tbufs[i]);
- if (count)
- total_count += count;
- else if (!total_count)
- active_buf_count = info->tbufs[i].buf_count;
- if (++i == info->tbuf_count)
- i = 0;
- } while (i != info->tbuf_current);
-
- /* read tx DMA status register */
- reg_value = rd_reg32(info, TDCSR);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (reg_value & BIT0)
- total_count += active_buf_count;
-
- /* add tx FIFO count = reg_value[15..8] */
- total_count += (reg_value >> 8) & 0xff;
-
- /* if transmitter active add one byte for shift register */
- if (info->tx_active)
- total_count++;
-
- return total_count;
-}
-
-/*
- * load data into transmit DMA buffer ring and start transmitter if needed
- * return true if data accepted, otherwise false (buffers full)
- */
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int size)
-{
- unsigned short count;
- unsigned int i;
- struct slgt_desc *d;
-
- /* check required buffer space */
- if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info))
- return false;
-
- DBGDATA(info, buf, size, "tx");
-
- /*
- * copy data to one or more DMA buffers in circular ring
- * tbuf_start = first buffer for this data
- * tbuf_current = next free buffer
- *
- * Copy all data before making data visible to DMA controller by
- * setting descriptor count of the first buffer.
- * This prevents an active DMA controller from reading the first DMA
- * buffers of a frame and stopping before the final buffers are filled.
- */
-
- info->tbuf_start = i = info->tbuf_current;
-
- while (size) {
- d = &info->tbufs[i];
-
- count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size);
- memcpy(d->buf, buf, count);
-
- size -= count;
- buf += count;
-
- /*
- * set EOF bit for last buffer of HDLC frame or
- * for every buffer in raw mode
- */
- if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
- info->params.mode == MGSL_MODE_RAW)
- set_desc_eof(*d, 1);
- else
- set_desc_eof(*d, 0);
-
- /* set descriptor count for all but first buffer */
- if (i != info->tbuf_start)
- set_desc_count(*d, count);
- d->buf_count = count;
-
- if (++i == info->tbuf_count)
- i = 0;
- }
-
- info->tbuf_current = i;
-
- /* set first buffer count to make new data visible to DMA controller */
- d = &info->tbufs[info->tbuf_start];
- set_desc_count(*d, d->buf_count);
-
- /* start transmitter if needed and update transmit timeout */
- if (!info->tx_active)
- tx_start(info);
- update_tx_timer(info);
-
- return true;
-}
-
-static int register_test(struct slgt_info *info)
-{
- static unsigned short patterns[] =
- {0x0000, 0xffff, 0xaaaa, 0x5555, 0x6969, 0x9696};
- static unsigned int count = ARRAY_SIZE(patterns);
- unsigned int i;
- int rc = 0;
-
- for (i=0 ; i < count ; i++) {
- wr_reg16(info, TIR, patterns[i]);
- wr_reg16(info, BDR, patterns[(i+1)%count]);
- if ((rd_reg16(info, TIR) != patterns[i]) ||
- (rd_reg16(info, BDR) != patterns[(i+1)%count])) {
- rc = -ENODEV;
- break;
- }
- }
- info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0;
- info->init_error = rc ? 0 : DiagStatus_AddressFailure;
- return rc;
-}
-
-static int irq_test(struct slgt_info *info)
-{
- unsigned long timeout;
- unsigned long flags;
- struct tty_struct *oldtty = info->port.tty;
- u32 speed = info->params.data_rate;
-
- info->params.data_rate = 921600;
- info->port.tty = NULL;
-
- spin_lock_irqsave(&info->lock, flags);
- async_mode(info);
- slgt_irq_on(info, IRQ_TXIDLE);
-
- /* enable transmitter */
- wr_reg16(info, TCR,
- (unsigned short)(rd_reg16(info, TCR) | BIT1));
-
- /* write one byte and wait for tx idle */
- wr_reg16(info, TDR, 0);
-
- /* assume failure */
- info->init_error = DiagStatus_IrqFailure;
- info->irq_occurred = false;
-
- spin_unlock_irqrestore(&info->lock, flags);
-
- timeout=100;
- while(timeout-- && !info->irq_occurred)
- msleep_interruptible(10);
-
- spin_lock_irqsave(&info->lock,flags);
- reset_port(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- info->params.data_rate = speed;
- info->port.tty = oldtty;
-
- info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure;
- return info->irq_occurred ? 0 : -ENODEV;
-}
-
-static int loopback_test_rx(struct slgt_info *info)
-{
- unsigned char *src, *dest;
- int count;
-
- if (desc_complete(info->rbufs[0])) {
- count = desc_count(info->rbufs[0]);
- src = info->rbufs[0].buf;
- dest = info->tmp_rbuf;
-
- for( ; count ; count-=2, src+=2) {
- /* src=data byte (src+1)=status byte */
- if (!(*(src+1) & (BIT9 + BIT8))) {
- *dest = *src;
- dest++;
- info->tmp_rbuf_count++;
- }
- }
- DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx");
- return 1;
- }
- return 0;
-}
-
-static int loopback_test(struct slgt_info *info)
-{
-#define TESTFRAMESIZE 20
-
- unsigned long timeout;
- u16 count;
- unsigned char buf[TESTFRAMESIZE];
- int rc = -ENODEV;
- unsigned long flags;
-
- struct tty_struct *oldtty = info->port.tty;
- MGSL_PARAMS params;
-
- memcpy(¶ms, &info->params, sizeof(params));
-
- info->params.mode = MGSL_MODE_ASYNC;
- info->params.data_rate = 921600;
- info->params.loopback = 1;
- info->port.tty = NULL;
-
- /* build and send transmit frame */
- for (count = 0; count < TESTFRAMESIZE; ++count)
- buf[count] = (unsigned char)count;
-
- info->tmp_rbuf_count = 0;
- memset(info->tmp_rbuf, 0, TESTFRAMESIZE);
-
- /* program hardware for HDLC and enabled receiver */
- spin_lock_irqsave(&info->lock,flags);
- async_mode(info);
- rx_start(info);
- tx_load(info, buf, count);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* wait for receive complete */
- for (timeout = 100; timeout; --timeout) {
- msleep_interruptible(10);
- if (loopback_test_rx(info)) {
- rc = 0;
- break;
- }
- }
-
- /* verify received frame length and contents */
- if (!rc && (info->tmp_rbuf_count != count ||
- memcmp(buf, info->tmp_rbuf, count))) {
- rc = -ENODEV;
- }
-
- spin_lock_irqsave(&info->lock,flags);
- reset_adapter(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- memcpy(&info->params, ¶ms, sizeof(info->params));
- info->port.tty = oldtty;
-
- info->init_error = rc ? DiagStatus_DmaFailure : 0;
- return rc;
-}
-
-static int adapter_test(struct slgt_info *info)
-{
- DBGINFO(("testing %s\n", info->device_name));
- if (register_test(info) < 0) {
- printk("register test failure %s addr=%08X\n",
- info->device_name, info->phys_reg_addr);
- } else if (irq_test(info) < 0) {
- printk("IRQ test failure %s IRQ=%d\n",
- info->device_name, info->irq_level);
- } else if (loopback_test(info) < 0) {
- printk("loopback test failure %s\n", info->device_name);
- }
- return info->init_error;
-}
-
-/*
- * transmit timeout handler
- */
-static void tx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, tx_timer);
- unsigned long flags;
-
- DBGINFO(("%s tx_timeout\n", info->device_name));
- if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
- info->icount.txtimeout++;
- }
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- bh_transmit(info);
-}
-
-/*
- * receive buffer polling timer
- */
-static void rx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, rx_timer);
- unsigned long flags;
-
- DBGINFO(("%s rx_timeout\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- info->pending_bh |= BH_RECEIVE;
- spin_unlock_irqrestore(&info->lock, flags);
- bh_handler(&info->task);
-}
-
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
deleted file mode 100644
index f1405b1c71ba..000000000000
--- a/include/linux/synclink.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SyncLink Multiprotocol Serial Adapter Driver
- *
- * $Id: synclink.h,v 3.14 2006/07/17 20:15:43 paulkf Exp $
- *
- * Copyright (C) 1998-2000 by Microgate Corporation
- *
- * Redistribution of this file is permitted under
- * the terms of the GNU Public License (GPL)
- */
-#ifndef _SYNCLINK_H_
-#define _SYNCLINK_H_
-
-#include <uapi/linux/synclink.h>
-
-/* provide 32 bit ioctl compatibility on 64 bit systems */
-#ifdef CONFIG_COMPAT
-#include <linux/compat.h>
-struct MGSL_PARAMS32 {
- compat_ulong_t mode;
- unsigned char loopback;
- unsigned short flags;
- unsigned char encoding;
- compat_ulong_t clock_speed;
- unsigned char addr_filter;
- unsigned short crc_type;
- unsigned char preamble_length;
- unsigned char preamble;
- compat_ulong_t data_rate;
- unsigned char data_bits;
- unsigned char stop_bits;
- unsigned char parity;
-};
-#define MGSL_IOCSPARAMS32 _IOW(MGSL_MAGIC_IOC,0,struct MGSL_PARAMS32)
-#define MGSL_IOCGPARAMS32 _IOR(MGSL_MAGIC_IOC,1,struct MGSL_PARAMS32)
-#endif
-#endif /* _SYNCLINK_H_ */
diff --git a/include/uapi/linux/synclink.h b/include/uapi/linux/synclink.h
deleted file mode 100644
index 62f32d4e1021..000000000000
--- a/include/uapi/linux/synclink.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */
-/*
- * SyncLink Multiprotocol Serial Adapter Driver
- *
- * $Id: synclink.h,v 3.14 2006/07/17 20:15:43 paulkf Exp $
- *
- * Copyright (C) 1998-2000 by Microgate Corporation
- *
- * Redistribution of this file is permitted under
- * the terms of the GNU Public License (GPL)
- */
-
-#ifndef _UAPI_SYNCLINK_H_
-#define _UAPI_SYNCLINK_H_
-#define SYNCLINK_H_VERSION 3.6
-
-#include <linux/types.h>
-
-#define BIT0 0x0001
-#define BIT1 0x0002
-#define BIT2 0x0004
-#define BIT3 0x0008
-#define BIT4 0x0010
-#define BIT5 0x0020
-#define BIT6 0x0040
-#define BIT7 0x0080
-#define BIT8 0x0100
-#define BIT9 0x0200
-#define BIT10 0x0400
-#define BIT11 0x0800
-#define BIT12 0x1000
-#define BIT13 0x2000
-#define BIT14 0x4000
-#define BIT15 0x8000
-#define BIT16 0x00010000
-#define BIT17 0x00020000
-#define BIT18 0x00040000
-#define BIT19 0x00080000
-#define BIT20 0x00100000
-#define BIT21 0x00200000
-#define BIT22 0x00400000
-#define BIT23 0x00800000
-#define BIT24 0x01000000
-#define BIT25 0x02000000
-#define BIT26 0x04000000
-#define BIT27 0x08000000
-#define BIT28 0x10000000
-#define BIT29 0x20000000
-#define BIT30 0x40000000
-#define BIT31 0x80000000
-
-
-#define HDLC_MAX_FRAME_SIZE 65535
-#define MAX_ASYNC_TRANSMIT 4096
-#define MAX_ASYNC_BUFFER_SIZE 4096
-
-#define ASYNC_PARITY_NONE 0
-#define ASYNC_PARITY_EVEN 1
-#define ASYNC_PARITY_ODD 2
-#define ASYNC_PARITY_SPACE 3
-
-#define HDLC_FLAG_UNDERRUN_ABORT7 0x0000
-#define HDLC_FLAG_UNDERRUN_ABORT15 0x0001
-#define HDLC_FLAG_UNDERRUN_FLAG 0x0002
-#define HDLC_FLAG_UNDERRUN_CRC 0x0004
-#define HDLC_FLAG_SHARE_ZERO 0x0010
-#define HDLC_FLAG_AUTO_CTS 0x0020
-#define HDLC_FLAG_AUTO_DCD 0x0040
-#define HDLC_FLAG_AUTO_RTS 0x0080
-#define HDLC_FLAG_RXC_DPLL 0x0100
-#define HDLC_FLAG_RXC_BRG 0x0200
-#define HDLC_FLAG_RXC_TXCPIN 0x8000
-#define HDLC_FLAG_RXC_RXCPIN 0x0000
-#define HDLC_FLAG_TXC_DPLL 0x0400
-#define HDLC_FLAG_TXC_BRG 0x0800
-#define HDLC_FLAG_TXC_TXCPIN 0x0000
-#define HDLC_FLAG_TXC_RXCPIN 0x0008
-#define HDLC_FLAG_DPLL_DIV8 0x1000
-#define HDLC_FLAG_DPLL_DIV16 0x2000
-#define HDLC_FLAG_DPLL_DIV32 0x0000
-#define HDLC_FLAG_HDLC_LOOPMODE 0x4000
-
-#define HDLC_CRC_NONE 0
-#define HDLC_CRC_16_CCITT 1
-#define HDLC_CRC_32_CCITT 2
-#define HDLC_CRC_MASK 0x00ff
-#define HDLC_CRC_RETURN_EX 0x8000
-
-#define RX_OK 0
-#define RX_CRC_ERROR 1
-
-#define HDLC_TXIDLE_FLAGS 0
-#define HDLC_TXIDLE_ALT_ZEROS_ONES 1
-#define HDLC_TXIDLE_ZEROS 2
-#define HDLC_TXIDLE_ONES 3
-#define HDLC_TXIDLE_ALT_MARK_SPACE 4
-#define HDLC_TXIDLE_SPACE 5
-#define HDLC_TXIDLE_MARK 6
-#define HDLC_TXIDLE_CUSTOM_8 0x10000000
-#define HDLC_TXIDLE_CUSTOM_16 0x20000000
-
-#define HDLC_ENCODING_NRZ 0
-#define HDLC_ENCODING_NRZB 1
-#define HDLC_ENCODING_NRZI_MARK 2
-#define HDLC_ENCODING_NRZI_SPACE 3
-#define HDLC_ENCODING_NRZI HDLC_ENCODING_NRZI_SPACE
-#define HDLC_ENCODING_BIPHASE_MARK 4
-#define HDLC_ENCODING_BIPHASE_SPACE 5
-#define HDLC_ENCODING_BIPHASE_LEVEL 6
-#define HDLC_ENCODING_DIFF_BIPHASE_LEVEL 7
-
-#define HDLC_PREAMBLE_LENGTH_8BITS 0
-#define HDLC_PREAMBLE_LENGTH_16BITS 1
-#define HDLC_PREAMBLE_LENGTH_32BITS 2
-#define HDLC_PREAMBLE_LENGTH_64BITS 3
-
-#define HDLC_PREAMBLE_PATTERN_NONE 0
-#define HDLC_PREAMBLE_PATTERN_ZEROS 1
-#define HDLC_PREAMBLE_PATTERN_FLAGS 2
-#define HDLC_PREAMBLE_PATTERN_10 3
-#define HDLC_PREAMBLE_PATTERN_01 4
-#define HDLC_PREAMBLE_PATTERN_ONES 5
-
-#define MGSL_MODE_ASYNC 1
-#define MGSL_MODE_HDLC 2
-#define MGSL_MODE_MONOSYNC 3
-#define MGSL_MODE_BISYNC 4
-#define MGSL_MODE_RAW 6
-#define MGSL_MODE_BASE_CLOCK 7
-#define MGSL_MODE_XSYNC 8
-
-#define MGSL_BUS_TYPE_ISA 1
-#define MGSL_BUS_TYPE_EISA 2
-#define MGSL_BUS_TYPE_PCI 5
-
-#define MGSL_INTERFACE_MASK 0xf
-#define MGSL_INTERFACE_DISABLE 0
-#define MGSL_INTERFACE_RS232 1
-#define MGSL_INTERFACE_V35 2
-#define MGSL_INTERFACE_RS422 3
-#define MGSL_INTERFACE_RTS_EN 0x10
-#define MGSL_INTERFACE_LL 0x20
-#define MGSL_INTERFACE_RL 0x40
-#define MGSL_INTERFACE_MSB_FIRST 0x80
-
-typedef struct _MGSL_PARAMS
-{
- /* Common */
-
- unsigned long mode; /* Asynchronous or HDLC */
- unsigned char loopback; /* internal loopback mode */
-
- /* HDLC Only */
-
- unsigned short flags;
- unsigned char encoding; /* NRZ, NRZI, etc. */
- unsigned long clock_speed; /* external clock speed in bits per second */
- unsigned char addr_filter; /* receive HDLC address filter, 0xFF = disable */
- unsigned short crc_type; /* None, CRC16-CCITT, or CRC32-CCITT */
- unsigned char preamble_length;
- unsigned char preamble;
-
- /* Async Only */
-
- unsigned long data_rate; /* bits per second */
- unsigned char data_bits; /* 7 or 8 data bits */
- unsigned char stop_bits; /* 1 or 2 stop bits */
- unsigned char parity; /* none, even, or odd */
-
-} MGSL_PARAMS, *PMGSL_PARAMS;
-
-#define MICROGATE_VENDOR_ID 0x13c0
-#define SYNCLINK_DEVICE_ID 0x0010
-#define MGSCC_DEVICE_ID 0x0020
-#define SYNCLINK_SCA_DEVICE_ID 0x0030
-#define SYNCLINK_GT_DEVICE_ID 0x0070
-#define SYNCLINK_GT4_DEVICE_ID 0x0080
-#define SYNCLINK_AC_DEVICE_ID 0x0090
-#define SYNCLINK_GT2_DEVICE_ID 0x00A0
-#define MGSL_MAX_SERIAL_NUMBER 30
-
-/*
-** device diagnostics status
-*/
-
-#define DiagStatus_OK 0
-#define DiagStatus_AddressFailure 1
-#define DiagStatus_AddressConflict 2
-#define DiagStatus_IrqFailure 3
-#define DiagStatus_IrqConflict 4
-#define DiagStatus_DmaFailure 5
-#define DiagStatus_DmaConflict 6
-#define DiagStatus_PciAdapterNotFound 7
-#define DiagStatus_CantAssignPciResources 8
-#define DiagStatus_CantAssignPciMemAddr 9
-#define DiagStatus_CantAssignPciIoAddr 10
-#define DiagStatus_CantAssignPciIrq 11
-#define DiagStatus_MemoryError 12
-
-#define SerialSignal_DCD 0x01 /* Data Carrier Detect */
-#define SerialSignal_TXD 0x02 /* Transmit Data */
-#define SerialSignal_RI 0x04 /* Ring Indicator */
-#define SerialSignal_RXD 0x08 /* Receive Data */
-#define SerialSignal_CTS 0x10 /* Clear to Send */
-#define SerialSignal_RTS 0x20 /* Request to Send */
-#define SerialSignal_DSR 0x40 /* Data Set Ready */
-#define SerialSignal_DTR 0x80 /* Data Terminal Ready */
-
-
-/*
- * Counters of the input lines (CTS, DSR, RI, CD) interrupts
- */
-struct mgsl_icount {
- __u32 cts, dsr, rng, dcd, tx, rx;
- __u32 frame, parity, overrun, brk;
- __u32 buf_overrun;
- __u32 txok;
- __u32 txunder;
- __u32 txabort;
- __u32 txtimeout;
- __u32 rxshort;
- __u32 rxlong;
- __u32 rxabort;
- __u32 rxover;
- __u32 rxcrc;
- __u32 rxok;
- __u32 exithunt;
- __u32 rxidle;
-};
-
-struct gpio_desc {
- __u32 state;
- __u32 smask;
- __u32 dir;
- __u32 dmask;
-};
-
-#define DEBUG_LEVEL_DATA 1
-#define DEBUG_LEVEL_ERROR 2
-#define DEBUG_LEVEL_INFO 3
-#define DEBUG_LEVEL_BH 4
-#define DEBUG_LEVEL_ISR 5
-
-/*
-** Event bit flags for use with MgslWaitEvent
-*/
-
-#define MgslEvent_DsrActive 0x0001
-#define MgslEvent_DsrInactive 0x0002
-#define MgslEvent_Dsr 0x0003
-#define MgslEvent_CtsActive 0x0004
-#define MgslEvent_CtsInactive 0x0008
-#define MgslEvent_Cts 0x000c
-#define MgslEvent_DcdActive 0x0010
-#define MgslEvent_DcdInactive 0x0020
-#define MgslEvent_Dcd 0x0030
-#define MgslEvent_RiActive 0x0040
-#define MgslEvent_RiInactive 0x0080
-#define MgslEvent_Ri 0x00c0
-#define MgslEvent_ExitHuntMode 0x0100
-#define MgslEvent_IdleReceived 0x0200
-
-/* Private IOCTL codes:
- *
- * MGSL_IOCSPARAMS set MGSL_PARAMS structure values
- * MGSL_IOCGPARAMS get current MGSL_PARAMS structure values
- * MGSL_IOCSTXIDLE set current transmit idle mode
- * MGSL_IOCGTXIDLE get current transmit idle mode
- * MGSL_IOCTXENABLE enable or disable transmitter
- * MGSL_IOCRXENABLE enable or disable receiver
- * MGSL_IOCTXABORT abort transmitting frame (HDLC)
- * MGSL_IOCGSTATS return current statistics
- * MGSL_IOCWAITEVENT wait for specified event to occur
- * MGSL_LOOPTXDONE transmit in HDLC LoopMode done
- * MGSL_IOCSIF set the serial interface type
- * MGSL_IOCGIF get the serial interface type
- */
-#define MGSL_MAGIC_IOC 'm'
-#define MGSL_IOCSPARAMS _IOW(MGSL_MAGIC_IOC,0,struct _MGSL_PARAMS)
-#define MGSL_IOCGPARAMS _IOR(MGSL_MAGIC_IOC,1,struct _MGSL_PARAMS)
-#define MGSL_IOCSTXIDLE _IO(MGSL_MAGIC_IOC,2)
-#define MGSL_IOCGTXIDLE _IO(MGSL_MAGIC_IOC,3)
-#define MGSL_IOCTXENABLE _IO(MGSL_MAGIC_IOC,4)
-#define MGSL_IOCRXENABLE _IO(MGSL_MAGIC_IOC,5)
-#define MGSL_IOCTXABORT _IO(MGSL_MAGIC_IOC,6)
-#define MGSL_IOCGSTATS _IO(MGSL_MAGIC_IOC,7)
-#define MGSL_IOCWAITEVENT _IOWR(MGSL_MAGIC_IOC,8,int)
-#define MGSL_IOCCLRMODCOUNT _IO(MGSL_MAGIC_IOC,15)
-#define MGSL_IOCLOOPTXDONE _IO(MGSL_MAGIC_IOC,9)
-#define MGSL_IOCSIF _IO(MGSL_MAGIC_IOC,10)
-#define MGSL_IOCGIF _IO(MGSL_MAGIC_IOC,11)
-#define MGSL_IOCSGPIO _IOW(MGSL_MAGIC_IOC,16,struct gpio_desc)
-#define MGSL_IOCGGPIO _IOR(MGSL_MAGIC_IOC,17,struct gpio_desc)
-#define MGSL_IOCWAITGPIO _IOWR(MGSL_MAGIC_IOC,18,struct gpio_desc)
-#define MGSL_IOCSXSYNC _IO(MGSL_MAGIC_IOC, 19)
-#define MGSL_IOCGXSYNC _IO(MGSL_MAGIC_IOC, 20)
-#define MGSL_IOCSXCTRL _IO(MGSL_MAGIC_IOC, 21)
-#define MGSL_IOCGXCTRL _IO(MGSL_MAGIC_IOC, 22)
-
-
-#endif /* _UAPI_SYNCLINK_H_ */
--
2.43.0
^ permalink raw reply related
* Re: [PATCH] serial: fsl_lpuart: fix rx buffer and DMA map leaks in start_rx_dma
From: Shitalkumar Gandhi @ 2026-05-03 19:49 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Frank Li, Bhuvanchandra DV, Peng Fan, Sherry Sun, linux-serial,
imx, linux-arm-kernel, linux-kernel, Shitalkumar Gandhi
In-Reply-To: <20260420135903.2062024-1-shitalkumar.gandhi@cambiumnetworks.com>
Hi Greg,
Any update on this? It has Frank's Reviewed-by but I don't see
it queued in tty-next or tty-testing yet.
Thanks,
Shital
^ permalink raw reply
* Re: [PATCH v2] tty: synclink_gt: remove broken driver
From: Ethan Nelson-Moore @ 2026-05-03 19:25 UTC (permalink / raw)
To: Andrew Lunn
Cc: Greg Kroah-Hartman, linux-doc, netdev, linux-serial,
rust-for-linux, Jonathan Corbet, Shuah Khan, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
In-Reply-To: <e12da6e2-5e50-4819-a5a8-2bc675da4c14@lunn.ch>
Hi, Andrew,
On Sun, May 3, 2026 at 7:23 AM Andrew Lunn <andrew@lunn.ch> wrote:
> Sounds like a whack a mole problem. I assume the recent removal of ATM
> broke it as well? Maybe __has_include() could be used?
That's a great idea. I will investigate that.
Ethan
^ permalink raw reply
* Re: [PATCH v2] tty: synclink_gt: remove broken driver
From: Andrew Lunn @ 2026-05-03 14:23 UTC (permalink / raw)
To: Ethan Nelson-Moore
Cc: Greg Kroah-Hartman, linux-doc, netdev, linux-serial,
rust-for-linux, Jonathan Corbet, Shuah Khan, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
In-Reply-To: <CADkSEUgPtjkKC684O3qB=koKDPwJoUj-qU_4Z_18NAU_+bBqkw@mail.gmail.com>
On Sat, May 02, 2026 at 11:00:53PM -0700, Ethan Nelson-Moore wrote:
> Hi, Greg,
>
> On Sat, May 2, 2026 at 10:44 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > Then that means someone uses it somewhere. Don't generate bindings for
> > something that will break because it is no longer in the tree :(
> That project generates bindings for every UAPI header automatically,
> but has a hardcoded list of them, so its presence there doesn't mean
> anyone is using it.
>
> > If no one does use it, then please get that project to fix their code so
> > that we don't break their build.
> They have had to remove headers from their list that got removed from
> the kernel before. I will send them a pull request to remove this
> header and then resend this patch with the UAPI header removal
> restored. Does that sound good to you?
Sounds like a whack a mole problem. I assume the recent removal of ATM
broke it as well? Maybe __has_include() could be used?
Andrew
^ permalink raw reply
* Re: [PATCH v2] tty: synclink_gt: remove broken driver
From: Greg Kroah-Hartman @ 2026-05-03 6:08 UTC (permalink / raw)
To: Ethan Nelson-Moore
Cc: linux-doc, netdev, linux-serial, rust-for-linux, Jonathan Corbet,
Shuah Khan, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP), Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
In-Reply-To: <CADkSEUgPtjkKC684O3qB=koKDPwJoUj-qU_4Z_18NAU_+bBqkw@mail.gmail.com>
On Sat, May 02, 2026 at 11:00:53PM -0700, Ethan Nelson-Moore wrote:
> Hi, Greg,
>
> On Sat, May 2, 2026 at 10:44 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > Then that means someone uses it somewhere. Don't generate bindings for
> > something that will break because it is no longer in the tree :(
> That project generates bindings for every UAPI header automatically,
> but has a hardcoded lost of them, so its presence there doesn't mean
> anyone is using it.
>
> > If no one does use it, then please get that project to fix their code so
> > that we don't break their build.
> They have had to remove headers from their list that got removed from
> the kernel before. I will send them a pull request to remove this
> header and then resend this patch with the UAPI header removal
> restored. Does that sound good to you?
Yes, thanks.
^ permalink raw reply
* Re: [PATCH v2] tty: synclink_gt: remove broken driver
From: Ethan Nelson-Moore @ 2026-05-03 6:00 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: linux-doc, netdev, linux-serial, rust-for-linux, Jonathan Corbet,
Shuah Khan, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP), Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
In-Reply-To: <2026050340-kilogram-prissy-a833@gregkh>
Hi, Greg,
On Sat, May 2, 2026 at 10:44 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
> Then that means someone uses it somewhere. Don't generate bindings for
> something that will break because it is no longer in the tree :(
That project generates bindings for every UAPI header automatically,
but has a hardcoded lost of them, so its presence there doesn't mean
anyone is using it.
> If no one does use it, then please get that project to fix their code so
> that we don't break their build.
They have had to remove headers from their list that got removed from
the kernel before. I will send them a pull request to remove this
header and then resend this patch with the UAPI header removal
restored. Does that sound good to you?
Ethan
^ permalink raw reply
* Re: [PATCH v2] tty: synclink_gt: remove broken driver
From: Greg Kroah-Hartman @ 2026-05-03 5:43 UTC (permalink / raw)
To: Ethan Nelson-Moore
Cc: linux-doc, netdev, linux-serial, rust-for-linux, Jonathan Corbet,
Shuah Khan, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP), Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
In-Reply-To: <20260503030801.14080-1-enelsonmoore@gmail.com>
On Sat, May 02, 2026 at 08:07:38PM -0700, Ethan Nelson-Moore wrote:
> The synclink_gt driver was marked as broken in commit 426263d5fb40
> ("tty: synclink_gt: mark as BROKEN") in July 2023 because it had severe
> structural problems and there had been no evidence of users since 2016.
> Since then, no meaningful improvements have been made to the driver,
> and it is unlikely that will ever happen due to the lack of interest.
> Drop the driver and references to it in comments and documentation.
> Retain include/uapi/linux/synclink.h to avoid breaking userspace
> software.
>
> Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
> ---
> Changes from v1:
> - Retain UAPI header - the linux-raw-sys Rust crate generates bindings
> for it [1]
Then that means someone uses it somewhere. Don't generate bindings for
something that will break because it is no longer in the tree :(
If no one does use it, then please get that project to fix their code so
that we don't break their build.
thanks,
greg k-h
^ permalink raw reply
* [PATCH v2] tty: synclink_gt: remove broken driver
From: Ethan Nelson-Moore @ 2026-05-03 3:07 UTC (permalink / raw)
To: linux-doc, netdev, linux-serial, rust-for-linux
Cc: Ethan Nelson-Moore, Jonathan Corbet, Shuah Khan,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Greg Kroah-Hartman,
Jiri Slaby, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Bagas Sanjaya, Haren Myneni,
Eric Biggers, Qingfang Deng, Julian Braha
The synclink_gt driver was marked as broken in commit 426263d5fb40
("tty: synclink_gt: mark as BROKEN") in July 2023 because it had severe
structural problems and there had been no evidence of users since 2016.
Since then, no meaningful improvements have been made to the driver,
and it is unlikely that will ever happen due to the lack of interest.
Drop the driver and references to it in comments and documentation.
Retain include/uapi/linux/synclink.h to avoid breaking userspace
software.
Signed-off-by: Ethan Nelson-Moore <enelsonmoore@gmail.com>
---
Changes from v1:
- Retain UAPI header - the linux-raw-sys Rust crate generates bindings
for it [1]
- Remove Documentation/userspace-api/ioctl/ioctl-number.rst entry
instead of marking it as dead; other recent driver removals have simply
removed entries
[1] https://github.com/sunfishcode/linux-raw-sys/blob/3b15c17f2688445cd3e9ef2907113829837773dd/gen/ioctl/list.c#L151
.../userspace-api/ioctl/ioctl-number.rst | 1 -
arch/powerpc/configs/ppc6xx_defconfig | 1 -
drivers/net/ppp/Kconfig | 4 +-
drivers/tty/Kconfig | 11 +-
drivers/tty/Makefile | 1 -
drivers/tty/n_hdlc.c | 7 -
drivers/tty/synclink_gt.c | 5038 -----------------
include/linux/synclink.h | 37 -
8 files changed, 3 insertions(+), 5097 deletions(-)
delete mode 100644 drivers/tty/synclink_gt.c
delete mode 100644 include/linux/synclink.h
diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst
index 331223761fff..58716f4f4834 100644
--- a/Documentation/userspace-api/ioctl/ioctl-number.rst
+++ b/Documentation/userspace-api/ioctl/ioctl-number.rst
@@ -271,7 +271,6 @@ Code Seq# Include File Comments
'm' 00-09 linux/mmtimer.h conflict!
'm' all linux/mtio.h conflict!
'm' all linux/soundcard.h conflict!
-'m' all linux/synclink.h conflict!
'm' 00-19 drivers/message/fusion/mptctl.h conflict!
'm' 00 drivers/scsi/megaraid/megaraid_ioctl.h conflict!
'n' 00-7F linux/ncp_fs.h and fs/ncpfs/ioctl.c
diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
index ccabc6e17168..4ddd2c01b8b7 100644
--- a/arch/powerpc/configs/ppc6xx_defconfig
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -551,7 +551,6 @@ CONFIG_GAMEPORT_EMU10K1=m
CONFIG_GAMEPORT_FM801=m
# CONFIG_LEGACY_PTYS is not set
CONFIG_SERIAL_NONSTANDARD=y
-CONFIG_SYNCLINK_GT=m
CONFIG_NOZOMI=m
CONFIG_N_HDLC=m
CONFIG_SERIAL_8250=y
diff --git a/drivers/net/ppp/Kconfig b/drivers/net/ppp/Kconfig
index 753354b4e36c..5324e2102383 100644
--- a/drivers/net/ppp/Kconfig
+++ b/drivers/net/ppp/Kconfig
@@ -191,8 +191,8 @@ config PPP_SYNC_TTY
tristate "PPP support for sync tty ports"
help
Say Y (or M) here if you want to be able to use PPP over synchronous
- (HDLC) tty devices, such as the SyncLink adapter. These devices
- are often used for high-speed leased lines like T1/E1.
+ (HDLC) tty devices. These devices are often used for high-speed leased
+ lines like T1/E1.
To compile this driver as a module, choose M here.
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 149f3d53b760..df6832a4c237 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -231,21 +231,12 @@ config MOXA_SMARTIO
This driver can also be built as a module. The module will be called
mxser. If you want to do that, say M here.
-config SYNCLINK_GT
- tristate "SyncLink GT/AC support"
- depends on SERIAL_NONSTANDARD && PCI
- depends on BROKEN
- help
- Support for SyncLink GT and SyncLink AC families of
- synchronous and asynchronous serial adapters
- manufactured by Microgate Systems, Ltd. (www.microgate.com)
-
config N_HDLC
tristate "HDLC line discipline support"
depends on SERIAL_NONSTANDARD
help
Allows synchronous HDLC communications with tty device drivers that
- support synchronous HDLC such as the Microgate SyncLink adapter.
+ support synchronous HDLC.
This driver can be built as a module ( = code which can be
inserted in and removed from the running kernel whenever you want).
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 07aca5184a55..8ca1a0a2229f 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -21,7 +21,6 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
obj-$(CONFIG_NOZOMI) += nozomi.o
obj-$(CONFIG_NULL_TTY) += ttynull.o
-obj-$(CONFIG_SYNCLINK_GT) += synclink_gt.o
obj-$(CONFIG_PPC_EPAPR_HV_BYTECHAN) += ehv_bytechan.o
obj-$(CONFIG_GOLDFISH_TTY) += goldfish.o
obj-$(CONFIG_MIPS_EJTAG_FDC_TTY) += mips_ejtag_fdc.o
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 98eefa2cede4..895b850a5950 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -4,8 +4,6 @@
* Written by Paul Fulghum paulkf@microgate.com
* for Microgate Corporation
*
- * Microgate and SyncLink are registered trademarks of Microgate Corporation
- *
* Adapted from ppp.c, written by Michael Callahan <callahan@maths.ox.ac.uk>,
* Al Longyear <longyear@netcom.com>,
* Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
@@ -54,11 +52,6 @@
* this line discipline (or another line discipline that is frame
* oriented such as N_PPP).
*
- * The SyncLink driver (synclink.c) implements both asynchronous
- * (using standard line discipline N_TTY) and synchronous HDLC
- * (using N_HDLC) communications, with the latter using the above
- * conventions.
- *
* This implementation is very basic and does not maintain
* any statistics. The main point is to enforce the raw data
* and frame orientation of HDLC communications.
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
deleted file mode 100644
index bf4f50e0ce94..000000000000
--- a/drivers/tty/synclink_gt.c
+++ /dev/null
@@ -1,5038 +0,0 @@
-// SPDX-License-Identifier: GPL-1.0+
-/*
- * Device driver for Microgate SyncLink GT serial adapters.
- *
- * written by Paul Fulghum for Microgate Corporation
- * paulkf@microgate.com
- *
- * Microgate and SyncLink are trademarks of Microgate Corporation
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * DEBUG OUTPUT DEFINITIONS
- *
- * uncomment lines below to enable specific types of debug output
- *
- * DBGINFO information - most verbose output
- * DBGERR serious errors
- * DBGBH bottom half service routine debugging
- * DBGISR interrupt service routine debugging
- * DBGDATA output receive and transmit data
- * DBGTBUF output transmit DMA buffers and registers
- * DBGRBUF output receive DMA buffers and registers
- */
-
-#define DBGINFO(fmt) if (debug_level >= DEBUG_LEVEL_INFO) printk fmt
-#define DBGERR(fmt) if (debug_level >= DEBUG_LEVEL_ERROR) printk fmt
-#define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
-#define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
-#define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
-/*#define DBGTBUF(info) dump_tbufs(info)*/
-/*#define DBGRBUF(info) dump_rbufs(info)*/
-
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/signal.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/interrupt.h>
-#include <linux/pci.h>
-#include <linux/tty.h>
-#include <linux/tty_flip.h>
-#include <linux/serial.h>
-#include <linux/major.h>
-#include <linux/string.h>
-#include <linux/fcntl.h>
-#include <linux/ptrace.h>
-#include <linux/ioport.h>
-#include <linux/mm.h>
-#include <linux/seq_file.h>
-#include <linux/slab.h>
-#include <linux/netdevice.h>
-#include <linux/vmalloc.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/ioctl.h>
-#include <linux/termios.h>
-#include <linux/bitops.h>
-#include <linux/workqueue.h>
-#include <linux/hdlc.h>
-#include <linux/synclink.h>
-
-#include <asm/io.h>
-#include <asm/irq.h>
-#include <asm/dma.h>
-#include <asm/types.h>
-#include <linux/uaccess.h>
-
-#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
-#define SYNCLINK_GENERIC_HDLC 1
-#else
-#define SYNCLINK_GENERIC_HDLC 0
-#endif
-
-/*
- * module identification
- */
-static const char driver_name[] = "SyncLink GT";
-static const char tty_dev_prefix[] = "ttySLG";
-MODULE_DESCRIPTION("Device driver for Microgate SyncLink GT serial adapters");
-MODULE_LICENSE("GPL");
-#define MAX_DEVICES 32
-
-static const struct pci_device_id pci_table[] = {
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT2_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_GT4_DEVICE_ID) },
- { PCI_VDEVICE(MICROGATE, SYNCLINK_AC_DEVICE_ID) },
- { 0 }, /* terminate list */
-};
-MODULE_DEVICE_TABLE(pci, pci_table);
-
-static int init_one(struct pci_dev *dev,const struct pci_device_id *ent);
-static void remove_one(struct pci_dev *dev);
-static struct pci_driver pci_driver = {
- .name = "synclink_gt",
- .id_table = pci_table,
- .probe = init_one,
- .remove = remove_one,
-};
-
-static bool pci_registered;
-
-/*
- * module configuration and status
- */
-static struct slgt_info *slgt_device_list;
-static int slgt_device_count;
-
-static int ttymajor;
-static int debug_level;
-static int maxframe[MAX_DEVICES];
-
-module_param(ttymajor, int, 0);
-module_param(debug_level, int, 0);
-module_param_array(maxframe, int, NULL, 0);
-
-MODULE_PARM_DESC(ttymajor, "TTY major device number override: 0=auto assigned");
-MODULE_PARM_DESC(debug_level, "Debug syslog output: 0=disabled, 1 to 5=increasing detail");
-MODULE_PARM_DESC(maxframe, "Maximum frame size used by device (4096 to 65535)");
-
-/*
- * tty support and callbacks
- */
-static struct tty_driver *serial_driver;
-
-static void wait_until_sent(struct tty_struct *tty, int timeout);
-static void flush_buffer(struct tty_struct *tty);
-static void tx_release(struct tty_struct *tty);
-
-/*
- * generic HDLC support
- */
-#define dev_to_port(D) (dev_to_hdlc(D)->priv)
-
-
-/*
- * device specific structures, macros and functions
- */
-
-#define SLGT_MAX_PORTS 4
-#define SLGT_REG_SIZE 256
-
-/*
- * conditional wait facility
- */
-struct cond_wait {
- struct cond_wait *next;
- wait_queue_head_t q;
- wait_queue_entry_t wait;
- unsigned int data;
-};
-static void flush_cond_wait(struct cond_wait **head);
-
-/*
- * DMA buffer descriptor and access macros
- */
-struct slgt_desc
-{
- __le16 count;
- __le16 status;
- __le32 pbuf; /* physical address of data buffer */
- __le32 next; /* physical address of next descriptor */
-
- /* driver book keeping */
- char *buf; /* virtual address of data buffer */
- unsigned int pdesc; /* physical address of this descriptor */
- dma_addr_t buf_dma_addr;
- unsigned short buf_count;
-};
-
-#define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
-#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
-#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
-#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
-#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
-#define desc_count(a) (le16_to_cpu((a).count))
-#define desc_status(a) (le16_to_cpu((a).status))
-#define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
-#define desc_eof(a) (le16_to_cpu((a).status) & BIT2)
-#define desc_crc_error(a) (le16_to_cpu((a).status) & BIT1)
-#define desc_abort(a) (le16_to_cpu((a).status) & BIT0)
-#define desc_residue(a) ((le16_to_cpu((a).status) & 0x38) >> 3)
-
-struct _input_signal_events {
- int ri_up;
- int ri_down;
- int dsr_up;
- int dsr_down;
- int dcd_up;
- int dcd_down;
- int cts_up;
- int cts_down;
-};
-
-/*
- * device instance data structure
- */
-struct slgt_info {
- void *if_ptr; /* General purpose pointer (used by SPPP) */
- struct tty_port port;
-
- struct slgt_info *next_device; /* device list link */
-
- char device_name[25];
- struct pci_dev *pdev;
-
- int port_count; /* count of ports on adapter */
- int adapter_num; /* adapter instance number */
- int port_num; /* port instance number */
-
- /* array of pointers to port contexts on this adapter */
- struct slgt_info *port_array[SLGT_MAX_PORTS];
-
- int line; /* tty line instance number */
-
- struct mgsl_icount icount;
-
- int timeout;
- int x_char; /* xon/xoff character */
- unsigned int read_status_mask;
- unsigned int ignore_status_mask;
-
- wait_queue_head_t status_event_wait_q;
- wait_queue_head_t event_wait_q;
- struct timer_list tx_timer;
- struct timer_list rx_timer;
-
- unsigned int gpio_present;
- struct cond_wait *gpio_wait_q;
-
- spinlock_t lock; /* spinlock for synchronizing with ISR */
-
- struct work_struct task;
- u32 pending_bh;
- bool bh_requested;
- bool bh_running;
-
- int isr_overflow;
- bool irq_requested; /* true if IRQ requested */
- bool irq_occurred; /* for diagnostics use */
-
- /* device configuration */
-
- unsigned int bus_type;
- unsigned int irq_level;
- unsigned long irq_flags;
-
- unsigned char __iomem * reg_addr; /* memory mapped registers address */
- u32 phys_reg_addr;
- bool reg_addr_requested;
-
- MGSL_PARAMS params; /* communications parameters */
- u32 idle_mode;
- u32 max_frame_size; /* as set by device config */
-
- unsigned int rbuf_fill_level;
- unsigned int rx_pio;
- unsigned int if_mode;
- unsigned int base_clock;
- unsigned int xsync;
- unsigned int xctrl;
-
- /* device status */
-
- bool rx_enabled;
- bool rx_restart;
-
- bool tx_enabled;
- bool tx_active;
-
- unsigned char signals; /* serial signal states */
- int init_error; /* initialization error */
-
- unsigned char *tx_buf;
- int tx_count;
-
- bool drop_rts_on_tx_done;
- struct _input_signal_events input_signal_events;
-
- int dcd_chkcount; /* check counts to prevent */
- int cts_chkcount; /* too many IRQs if a signal */
- int dsr_chkcount; /* is floating */
- int ri_chkcount;
-
- char *bufs; /* virtual address of DMA buffer lists */
- dma_addr_t bufs_dma_addr; /* physical address of buffer descriptors */
-
- unsigned int rbuf_count;
- struct slgt_desc *rbufs;
- unsigned int rbuf_current;
- unsigned int rbuf_index;
- unsigned int rbuf_fill_index;
- unsigned short rbuf_fill_count;
-
- unsigned int tbuf_count;
- struct slgt_desc *tbufs;
- unsigned int tbuf_current;
- unsigned int tbuf_start;
-
- unsigned char *tmp_rbuf;
- unsigned int tmp_rbuf_count;
-
- /* SPPP/Cisco HDLC device parts */
-
- int netcount;
- spinlock_t netlock;
-#if SYNCLINK_GENERIC_HDLC
- struct net_device *netdev;
-#endif
-
-};
-
-static const MGSL_PARAMS default_params = {
- .mode = MGSL_MODE_HDLC,
- .loopback = 0,
- .flags = HDLC_FLAG_UNDERRUN_ABORT15,
- .encoding = HDLC_ENCODING_NRZI_SPACE,
- .clock_speed = 0,
- .addr_filter = 0xff,
- .crc_type = HDLC_CRC_16_CCITT,
- .preamble_length = HDLC_PREAMBLE_LENGTH_8BITS,
- .preamble = HDLC_PREAMBLE_PATTERN_NONE,
- .data_rate = 9600,
- .data_bits = 8,
- .stop_bits = 1,
- .parity = ASYNC_PARITY_NONE
-};
-
-
-#define BH_RECEIVE 1
-#define BH_TRANSMIT 2
-#define BH_STATUS 4
-#define IO_PIN_SHUTDOWN_LIMIT 100
-
-#define DMABUFSIZE 256
-#define DESC_LIST_SIZE 4096
-
-#define MASK_PARITY BIT1
-#define MASK_FRAMING BIT0
-#define MASK_BREAK BIT14
-#define MASK_OVERRUN BIT4
-
-#define GSR 0x00 /* global status */
-#define JCR 0x04 /* JTAG control */
-#define IODR 0x08 /* GPIO direction */
-#define IOER 0x0c /* GPIO interrupt enable */
-#define IOVR 0x10 /* GPIO value */
-#define IOSR 0x14 /* GPIO interrupt status */
-#define TDR 0x80 /* tx data */
-#define RDR 0x80 /* rx data */
-#define TCR 0x82 /* tx control */
-#define TIR 0x84 /* tx idle */
-#define TPR 0x85 /* tx preamble */
-#define RCR 0x86 /* rx control */
-#define VCR 0x88 /* V.24 control */
-#define CCR 0x89 /* clock control */
-#define BDR 0x8a /* baud divisor */
-#define SCR 0x8c /* serial control */
-#define SSR 0x8e /* serial status */
-#define RDCSR 0x90 /* rx DMA control/status */
-#define TDCSR 0x94 /* tx DMA control/status */
-#define RDDAR 0x98 /* rx DMA descriptor address */
-#define TDDAR 0x9c /* tx DMA descriptor address */
-#define XSR 0x40 /* extended sync pattern */
-#define XCR 0x44 /* extended control */
-
-#define RXIDLE BIT14
-#define RXBREAK BIT14
-#define IRQ_TXDATA BIT13
-#define IRQ_TXIDLE BIT12
-#define IRQ_TXUNDER BIT11 /* HDLC */
-#define IRQ_RXDATA BIT10
-#define IRQ_RXIDLE BIT9 /* HDLC */
-#define IRQ_RXBREAK BIT9 /* async */
-#define IRQ_RXOVER BIT8
-#define IRQ_DSR BIT7
-#define IRQ_CTS BIT6
-#define IRQ_DCD BIT5
-#define IRQ_RI BIT4
-#define IRQ_ALL 0x3ff0
-#define IRQ_MASTER BIT0
-
-#define slgt_irq_on(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
-#define slgt_irq_off(info, mask) \
- wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr);
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value);
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr);
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value);
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr);
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value);
-
-static void msc_set_vcr(struct slgt_info *info);
-
-static int startup_hw(struct slgt_info *info);
-static int block_til_ready(struct tty_struct *tty, struct file * filp,struct slgt_info *info);
-static void shutdown_hw(struct slgt_info *info);
-static void program_hw(struct slgt_info *info);
-static void change_params(struct slgt_info *info);
-
-static int adapter_test(struct slgt_info *info);
-
-static void reset_port(struct slgt_info *info);
-static void async_mode(struct slgt_info *info);
-static void sync_mode(struct slgt_info *info);
-
-static void rx_stop(struct slgt_info *info);
-static void rx_start(struct slgt_info *info);
-static void reset_rbufs(struct slgt_info *info);
-static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last);
-static bool rx_get_frame(struct slgt_info *info);
-static bool rx_get_buf(struct slgt_info *info);
-
-static void tx_start(struct slgt_info *info);
-static void tx_stop(struct slgt_info *info);
-static void tx_set_idle(struct slgt_info *info);
-static unsigned int tbuf_bytes(struct slgt_info *info);
-static void reset_tbufs(struct slgt_info *info);
-static void tdma_reset(struct slgt_info *info);
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int count);
-
-static void get_gtsignals(struct slgt_info *info);
-static void set_gtsignals(struct slgt_info *info);
-static void set_rate(struct slgt_info *info, u32 data_rate);
-
-static void bh_transmit(struct slgt_info *info);
-static void isr_txeom(struct slgt_info *info, unsigned short status);
-
-static void tx_timeout(struct timer_list *t);
-static void rx_timeout(struct timer_list *t);
-
-/*
- * ioctl handlers
- */
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount);
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *params);
-static int get_txidle(struct slgt_info *info, int __user *idle_mode);
-static int set_txidle(struct slgt_info *info, int idle_mode);
-static int tx_enable(struct slgt_info *info, int enable);
-static int tx_abort(struct slgt_info *info);
-static int rx_enable(struct slgt_info *info, int enable);
-static int modem_input_wait(struct slgt_info *info,int arg);
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr);
-static int get_interface(struct slgt_info *info, int __user *if_mode);
-static int set_interface(struct slgt_info *info, int if_mode);
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
-static int get_xsync(struct slgt_info *info, int __user *if_mode);
-static int set_xsync(struct slgt_info *info, int if_mode);
-static int get_xctrl(struct slgt_info *info, int __user *if_mode);
-static int set_xctrl(struct slgt_info *info, int if_mode);
-
-/*
- * driver functions
- */
-static void release_resources(struct slgt_info *info);
-
-/*
- * DEBUG OUTPUT CODE
- */
-#ifndef DBGINFO
-#define DBGINFO(fmt)
-#endif
-#ifndef DBGERR
-#define DBGERR(fmt)
-#endif
-#ifndef DBGBH
-#define DBGBH(fmt)
-#endif
-#ifndef DBGISR
-#define DBGISR(fmt)
-#endif
-
-#ifdef DBGDATA
-static void trace_block(struct slgt_info *info, const char *data, int count, const char *label)
-{
- int i;
- int linecount;
- printk("%s %s data:\n",info->device_name, label);
- while(count) {
- linecount = (count > 16) ? 16 : count;
- for(i=0; i < linecount; i++)
- printk("%02X ",(unsigned char)data[i]);
- for(;i<17;i++)
- printk(" ");
- for(i=0;i<linecount;i++) {
- if (data[i]>=040 && data[i]<=0176)
- printk("%c",data[i]);
- else
- printk(".");
- }
- printk("\n");
- data += linecount;
- count -= linecount;
- }
-}
-#else
-#define DBGDATA(info, buf, size, label)
-#endif
-
-#ifdef DBGTBUF
-static void dump_tbufs(struct slgt_info *info)
-{
- int i;
- printk("tbuf_current=%d\n", info->tbuf_current);
- for (i=0 ; i < info->tbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->tbufs[i].count), le16_to_cpu(info->tbufs[i].status));
- }
-}
-#else
-#define DBGTBUF(info)
-#endif
-
-#ifdef DBGRBUF
-static void dump_rbufs(struct slgt_info *info)
-{
- int i;
- printk("rbuf_current=%d\n", info->rbuf_current);
- for (i=0 ; i < info->rbuf_count ; i++) {
- printk("%d: count=%04X status=%04X\n",
- i, le16_to_cpu(info->rbufs[i].count), le16_to_cpu(info->rbufs[i].status));
- }
-}
-#else
-#define DBGRBUF(info)
-#endif
-
-static inline int sanity_check(struct slgt_info *info, char *devname, const char *name)
-{
-#ifdef SANITY_CHECK
- if (!info) {
- printk("null struct slgt_info for (%s) in %s\n", devname, name);
- return 1;
- }
-#else
- if (!info)
- return 1;
-#endif
- return 0;
-}
-
-/*
- * line discipline callback wrappers
- *
- * The wrappers maintain line discipline references
- * while calling into the line discipline.
- *
- * ldisc_receive_buf - pass receive data to line discipline
- */
-static void ldisc_receive_buf(struct tty_struct *tty,
- const __u8 *data, char *flags, int count)
-{
- struct tty_ldisc *ld;
- if (!tty)
- return;
- ld = tty_ldisc_ref(tty);
- if (ld) {
- if (ld->ops->receive_buf)
- ld->ops->receive_buf(tty, data, flags, count);
- tty_ldisc_deref(ld);
- }
-}
-
-/* tty callbacks */
-
-static int open(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info;
- int retval, line;
- unsigned long flags;
-
- line = tty->index;
- if (line >= slgt_device_count) {
- DBGERR(("%s: open with invalid line #%d.\n", driver_name, line));
- return -ENODEV;
- }
-
- info = slgt_device_list;
- while(info && info->line != line)
- info = info->next_device;
- if (sanity_check(info, tty->name, "open"))
- return -ENODEV;
- if (info->init_error) {
- DBGERR(("%s init error=%d\n", info->device_name, info->init_error));
- return -ENODEV;
- }
-
- tty->driver_data = info;
- info->port.tty = tty;
-
- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
-
- mutex_lock(&info->port.mutex);
-
- spin_lock_irqsave(&info->netlock, flags);
- if (info->netcount) {
- retval = -EBUSY;
- spin_unlock_irqrestore(&info->netlock, flags);
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- info->port.count++;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- if (info->port.count == 1) {
- /* 1st open on this device, init hardware */
- retval = startup_hw(info);
- if (retval < 0) {
- mutex_unlock(&info->port.mutex);
- goto cleanup;
- }
- }
- mutex_unlock(&info->port.mutex);
- retval = block_til_ready(tty, filp, info);
- if (retval) {
- DBGINFO(("%s block_til_ready rc=%d\n", info->device_name, retval));
- goto cleanup;
- }
-
- retval = 0;
-
-cleanup:
- if (retval) {
- if (tty->count == 1)
- info->port.tty = NULL; /* tty layer will release tty struct */
- if(info->port.count)
- info->port.count--;
- }
-
- DBGINFO(("%s open rc=%d\n", info->device_name, retval));
- return retval;
-}
-
-static void close(struct tty_struct *tty, struct file *filp)
-{
- struct slgt_info *info = tty->driver_data;
-
- if (sanity_check(info, tty->name, "close"))
- return;
- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
-
- if (tty_port_close_start(&info->port, tty, filp) == 0)
- goto cleanup;
-
- mutex_lock(&info->port.mutex);
- if (tty_port_initialized(&info->port))
- wait_until_sent(tty, info->timeout);
- flush_buffer(tty);
- tty_ldisc_flush(tty);
-
- shutdown_hw(info);
- mutex_unlock(&info->port.mutex);
-
- tty_port_close_end(&info->port, tty);
- info->port.tty = NULL;
-cleanup:
- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
-}
-
-static void hangup(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "hangup"))
- return;
- DBGINFO(("%s hangup\n", info->device_name));
-
- flush_buffer(tty);
-
- mutex_lock(&info->port.mutex);
- shutdown_hw(info);
-
- spin_lock_irqsave(&info->port.lock, flags);
- info->port.count = 0;
- info->port.tty = NULL;
- spin_unlock_irqrestore(&info->port.lock, flags);
- tty_port_set_active(&info->port, false);
- mutex_unlock(&info->port.mutex);
-
- wake_up_interruptible(&info->port.open_wait);
-}
-
-static void set_termios(struct tty_struct *tty,
- const struct ktermios *old_termios)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s set_termios\n", tty->driver->name));
-
- change_params(info);
-
- /* Handle transition to B0 status */
- if ((old_termios->c_cflag & CBAUD) && !C_BAUD(tty)) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle transition away from B0 status */
- if (!(old_termios->c_cflag & CBAUD) && C_BAUD(tty)) {
- info->signals |= SerialSignal_DTR;
- if (!C_CRTSCTS(tty) || !tty_throttled(tty))
- info->signals |= SerialSignal_RTS;
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-
- /* Handle turning off CRTSCTS */
- if ((old_termios->c_cflag & CRTSCTS) && !C_CRTSCTS(tty)) {
- tty->hw_stopped = false;
- tx_release(tty);
- }
-}
-
-static void update_tx_timer(struct slgt_info *info)
-{
- /*
- * use worst case speed of 1200bps to calculate transmit timeout
- * based on data in buffers (tbuf_bytes) and FIFO (128 bytes)
- */
- if (info->params.mode == MGSL_MODE_HDLC) {
- int timeout = (tbuf_bytes(info) * 7) + 1000;
- mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout));
- }
-}
-
-static ssize_t write(struct tty_struct *tty, const u8 *buf, size_t count)
-{
- int ret = 0;
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "write"))
- return -EIO;
-
- DBGINFO(("%s write count=%zu\n", info->device_name, count));
-
- if (!info->tx_buf || (count > info->max_frame_size))
- return -EIO;
-
- if (!count || tty->flow.stopped || tty->hw_stopped)
- return 0;
-
- spin_lock_irqsave(&info->lock, flags);
-
- if (info->tx_count) {
- /* send accumulated data from send_char() */
- if (!tx_load(info, info->tx_buf, info->tx_count))
- goto cleanup;
- info->tx_count = 0;
- }
-
- if (tx_load(info, buf, count))
- ret = count;
-
-cleanup:
- spin_unlock_irqrestore(&info->lock, flags);
- DBGINFO(("%s write rc=%d\n", info->device_name, ret));
- return ret;
-}
-
-static int put_char(struct tty_struct *tty, u8 ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
- int ret = 0;
-
- if (sanity_check(info, tty->name, "put_char"))
- return 0;
- DBGINFO(("%s put_char(%u)\n", info->device_name, ch));
- if (!info->tx_buf)
- return 0;
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count < info->max_frame_size) {
- info->tx_buf[info->tx_count++] = ch;
- ret = 1;
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return ret;
-}
-
-static void send_xchar(struct tty_struct *tty, char ch)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "send_xchar"))
- return;
- DBGINFO(("%s send_xchar(%d)\n", info->device_name, ch));
- info->x_char = ch;
- if (ch) {
- spin_lock_irqsave(&info->lock,flags);
- if (!info->tx_enabled)
- tx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-static void wait_until_sent(struct tty_struct *tty, int timeout)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long orig_jiffies, char_time;
-
- if (!info )
- return;
- if (sanity_check(info, tty->name, "wait_until_sent"))
- return;
- DBGINFO(("%s wait_until_sent entry\n", info->device_name));
- if (!tty_port_initialized(&info->port))
- goto exit;
-
- orig_jiffies = jiffies;
-
- /* Set check interval to 1/5 of estimated time to
- * send a character, and make it at least 1. The check
- * interval should also be less than the timeout.
- * Note: use tight timings here to satisfy the NIST-PCTS.
- */
-
- if (info->params.data_rate) {
- char_time = info->timeout/(32 * 5);
- if (!char_time)
- char_time++;
- } else
- char_time = 1;
-
- if (timeout)
- char_time = min_t(unsigned long, char_time, timeout);
-
- while (info->tx_active) {
- msleep_interruptible(jiffies_to_msecs(char_time));
- if (signal_pending(current))
- break;
- if (timeout && time_after(jiffies, orig_jiffies + timeout))
- break;
- }
-exit:
- DBGINFO(("%s wait_until_sent exit\n", info->device_name));
-}
-
-static unsigned int write_room(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int ret;
-
- if (sanity_check(info, tty->name, "write_room"))
- return 0;
- ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
- DBGINFO(("%s write_room=%u\n", info->device_name, ret));
- return ret;
-}
-
-static void flush_chars(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_chars"))
- return;
- DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count));
-
- if (info->tx_count <= 0 || tty->flow.stopped ||
- tty->hw_stopped || !info->tx_buf)
- return;
-
- DBGINFO(("%s flush_chars start transmit\n", info->device_name));
-
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-static void flush_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "flush_buffer"))
- return;
- DBGINFO(("%s flush_buffer\n", info->device_name));
-
- spin_lock_irqsave(&info->lock, flags);
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-
- tty_wakeup(tty);
-}
-
-/*
- * throttle (stop) transmitter
- */
-static void tx_hold(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_hold"))
- return;
- DBGINFO(("%s tx_hold\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- if (info->tx_enabled && info->params.mode == MGSL_MODE_ASYNC)
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * release (start) transmitter
- */
-static void tx_release(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "tx_release"))
- return;
- DBGINFO(("%s tx_release\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- if (info->tx_count && tx_load(info, info->tx_buf, info->tx_count))
- info->tx_count = 0;
- spin_unlock_irqrestore(&info->lock, flags);
-}
-
-/*
- * Service an IOCTL request
- *
- * Arguments
- *
- * tty pointer to tty instance data
- * cmd IOCTL command code
- * arg command argument/context
- *
- * Return 0 if success, otherwise error code
- */
-static int ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- void __user *argp = (void __user *)arg;
- int ret;
-
- if (sanity_check(info, tty->name, "ioctl"))
- return -ENODEV;
- DBGINFO(("%s ioctl() cmd=%08X\n", info->device_name, cmd));
-
- if (cmd != TIOCMIWAIT) {
- if (tty_io_error(tty))
- return -EIO;
- }
-
- switch (cmd) {
- case MGSL_IOCWAITEVENT:
- return wait_mgsl_event(info, argp);
- case TIOCMIWAIT:
- return modem_input_wait(info,(int)arg);
- case MGSL_IOCSGPIO:
- return set_gpio(info, argp);
- case MGSL_IOCGGPIO:
- return get_gpio(info, argp);
- case MGSL_IOCWAITGPIO:
- return wait_gpio(info, argp);
- case MGSL_IOCGXSYNC:
- return get_xsync(info, argp);
- case MGSL_IOCSXSYNC:
- return set_xsync(info, (int)arg);
- case MGSL_IOCGXCTRL:
- return get_xctrl(info, argp);
- case MGSL_IOCSXCTRL:
- return set_xctrl(info, (int)arg);
- }
- mutex_lock(&info->port.mutex);
- switch (cmd) {
- case MGSL_IOCGPARAMS:
- ret = get_params(info, argp);
- break;
- case MGSL_IOCSPARAMS:
- ret = set_params(info, argp);
- break;
- case MGSL_IOCGTXIDLE:
- ret = get_txidle(info, argp);
- break;
- case MGSL_IOCSTXIDLE:
- ret = set_txidle(info, (int)arg);
- break;
- case MGSL_IOCTXENABLE:
- ret = tx_enable(info, (int)arg);
- break;
- case MGSL_IOCRXENABLE:
- ret = rx_enable(info, (int)arg);
- break;
- case MGSL_IOCTXABORT:
- ret = tx_abort(info);
- break;
- case MGSL_IOCGSTATS:
- ret = get_stats(info, argp);
- break;
- case MGSL_IOCGIF:
- ret = get_interface(info, argp);
- break;
- case MGSL_IOCSIF:
- ret = set_interface(info,(int)arg);
- break;
- default:
- ret = -ENOIOCTLCMD;
- }
- mutex_unlock(&info->port.mutex);
- return ret;
-}
-
-static int get_icount(struct tty_struct *tty,
- struct serial_icounter_struct *icount)
-
-{
- struct slgt_info *info = tty->driver_data;
- struct mgsl_icount cnow; /* kernel counter temps */
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- spin_unlock_irqrestore(&info->lock,flags);
-
- icount->cts = cnow.cts;
- icount->dsr = cnow.dsr;
- icount->rng = cnow.rng;
- icount->dcd = cnow.dcd;
- icount->rx = cnow.rx;
- icount->tx = cnow.tx;
- icount->frame = cnow.frame;
- icount->overrun = cnow.overrun;
- icount->parity = cnow.parity;
- icount->brk = cnow.brk;
- icount->buf_overrun = cnow.buf_overrun;
-
- return 0;
-}
-
-/*
- * support for 32 bit ioctl calls on 64 bit systems
- */
-#ifdef CONFIG_COMPAT
-static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params)
-{
- struct MGSL_PARAMS32 tmp_params;
-
- DBGINFO(("%s get_params32\n", info->device_name));
- memset(&tmp_params, 0, sizeof(tmp_params));
- tmp_params.mode = (compat_ulong_t)info->params.mode;
- tmp_params.loopback = info->params.loopback;
- tmp_params.flags = info->params.flags;
- tmp_params.encoding = info->params.encoding;
- tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed;
- tmp_params.addr_filter = info->params.addr_filter;
- tmp_params.crc_type = info->params.crc_type;
- tmp_params.preamble_length = info->params.preamble_length;
- tmp_params.preamble = info->params.preamble;
- tmp_params.data_rate = (compat_ulong_t)info->params.data_rate;
- tmp_params.data_bits = info->params.data_bits;
- tmp_params.stop_bits = info->params.stop_bits;
- tmp_params.parity = info->params.parity;
- if (copy_to_user(user_params, &tmp_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
- return 0;
-}
-
-static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
-{
- struct MGSL_PARAMS32 tmp_params;
- unsigned long flags;
-
- DBGINFO(("%s set_params32\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK) {
- info->base_clock = tmp_params.clock_speed;
- } else {
- info->params.mode = tmp_params.mode;
- info->params.loopback = tmp_params.loopback;
- info->params.flags = tmp_params.flags;
- info->params.encoding = tmp_params.encoding;
- info->params.clock_speed = tmp_params.clock_speed;
- info->params.addr_filter = tmp_params.addr_filter;
- info->params.crc_type = tmp_params.crc_type;
- info->params.preamble_length = tmp_params.preamble_length;
- info->params.preamble = tmp_params.preamble;
- info->params.data_rate = tmp_params.data_rate;
- info->params.data_bits = tmp_params.data_bits;
- info->params.stop_bits = tmp_params.stop_bits;
- info->params.parity = tmp_params.parity;
- }
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static long slgt_compat_ioctl(struct tty_struct *tty,
- unsigned int cmd, unsigned long arg)
-{
- struct slgt_info *info = tty->driver_data;
- int rc;
-
- if (sanity_check(info, tty->name, "compat_ioctl"))
- return -ENODEV;
- DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
-
- switch (cmd) {
- case MGSL_IOCSPARAMS32:
- rc = set_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS32:
- rc = get_params32(info, compat_ptr(arg));
- break;
-
- case MGSL_IOCGPARAMS:
- case MGSL_IOCSPARAMS:
- case MGSL_IOCGTXIDLE:
- case MGSL_IOCGSTATS:
- case MGSL_IOCWAITEVENT:
- case MGSL_IOCGIF:
- case MGSL_IOCSGPIO:
- case MGSL_IOCGGPIO:
- case MGSL_IOCWAITGPIO:
- case MGSL_IOCGXSYNC:
- case MGSL_IOCGXCTRL:
- rc = ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
- break;
- default:
- rc = ioctl(tty, cmd, arg);
- }
- DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
- return rc;
-}
-#else
-#define slgt_compat_ioctl NULL
-#endif /* ifdef CONFIG_COMPAT */
-
-/*
- * proc fs support
- */
-static inline void line_info(struct seq_file *m, struct slgt_info *info)
-{
- char stat_buf[30];
- unsigned long flags;
-
- seq_printf(m, "%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
- info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
- /* output current serial signal states */
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- stat_buf[0] = 0;
- stat_buf[1] = 0;
- if (info->signals & SerialSignal_RTS)
- strcat(stat_buf, "|RTS");
- if (info->signals & SerialSignal_CTS)
- strcat(stat_buf, "|CTS");
- if (info->signals & SerialSignal_DTR)
- strcat(stat_buf, "|DTR");
- if (info->signals & SerialSignal_DSR)
- strcat(stat_buf, "|DSR");
- if (info->signals & SerialSignal_DCD)
- strcat(stat_buf, "|CD");
- if (info->signals & SerialSignal_RI)
- strcat(stat_buf, "|RI");
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- seq_printf(m, "\tHDLC txok:%d rxok:%d",
- info->icount.txok, info->icount.rxok);
- if (info->icount.txunder)
- seq_printf(m, " txunder:%d", info->icount.txunder);
- if (info->icount.txabort)
- seq_printf(m, " txabort:%d", info->icount.txabort);
- if (info->icount.rxshort)
- seq_printf(m, " rxshort:%d", info->icount.rxshort);
- if (info->icount.rxlong)
- seq_printf(m, " rxlong:%d", info->icount.rxlong);
- if (info->icount.rxover)
- seq_printf(m, " rxover:%d", info->icount.rxover);
- if (info->icount.rxcrc)
- seq_printf(m, " rxcrc:%d", info->icount.rxcrc);
- } else {
- seq_printf(m, "\tASYNC tx:%d rx:%d",
- info->icount.tx, info->icount.rx);
- if (info->icount.frame)
- seq_printf(m, " fe:%d", info->icount.frame);
- if (info->icount.parity)
- seq_printf(m, " pe:%d", info->icount.parity);
- if (info->icount.brk)
- seq_printf(m, " brk:%d", info->icount.brk);
- if (info->icount.overrun)
- seq_printf(m, " oe:%d", info->icount.overrun);
- }
-
- /* Append serial signal status to end */
- seq_printf(m, " %s\n", stat_buf+1);
-
- seq_printf(m, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
- info->tx_active,info->bh_requested,info->bh_running,
- info->pending_bh);
-}
-
-/* Called to print information about devices
- */
-static int synclink_gt_proc_show(struct seq_file *m, void *v)
-{
- struct slgt_info *info;
-
- seq_puts(m, "synclink_gt driver\n");
-
- info = slgt_device_list;
- while( info ) {
- line_info(m, info);
- info = info->next_device;
- }
- return 0;
-}
-
-/*
- * return count of bytes in transmit buffer
- */
-static unsigned int chars_in_buffer(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int count;
- if (sanity_check(info, tty->name, "chars_in_buffer"))
- return 0;
- count = tbuf_bytes(info);
- DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count));
- return count;
-}
-
-/*
- * signal remote device to throttle send data (our receive data)
- */
-static void throttle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "throttle"))
- return;
- DBGINFO(("%s throttle\n", info->device_name));
- if (I_IXOFF(tty))
- send_xchar(tty, STOP_CHAR(tty));
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals &= ~SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * signal remote device to stop throttling send data (our receive data)
- */
-static void unthrottle(struct tty_struct * tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "unthrottle"))
- return;
- DBGINFO(("%s unthrottle\n", info->device_name));
- if (I_IXOFF(tty)) {
- if (info->x_char)
- info->x_char = 0;
- else
- send_xchar(tty, START_CHAR(tty));
- }
- if (C_CRTSCTS(tty)) {
- spin_lock_irqsave(&info->lock,flags);
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
-}
-
-/*
- * set or clear transmit break condition
- * break_state -1=set break condition, 0=clear
- */
-static int set_break(struct tty_struct *tty, int break_state)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned short value;
- unsigned long flags;
-
- if (sanity_check(info, tty->name, "set_break"))
- return -EINVAL;
- DBGINFO(("%s set_break(%d)\n", info->device_name, break_state));
-
- spin_lock_irqsave(&info->lock,flags);
- value = rd_reg16(info, TCR);
- if (break_state == -1)
- value |= BIT6;
- else
- value &= ~BIT6;
- wr_reg16(info, TCR, value);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-#if SYNCLINK_GENERIC_HDLC
-
-/**
- * hdlcdev_attach - called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
- * @dev: pointer to network device structure
- * @encoding: serial encoding setting
- * @parity: FCS setting
- *
- * Set encoding and frame check sequence (FCS) options.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
- unsigned short parity)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned char new_encoding;
- unsigned short new_crctype;
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- DBGINFO(("%s hdlcdev_attach\n", info->device_name));
-
- switch (encoding)
- {
- case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
- case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
- case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
- case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
- case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
- default: return -EINVAL;
- }
-
- switch (parity)
- {
- case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
- case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
- case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
- default: return -EINVAL;
- }
-
- info->params.encoding = new_encoding;
- info->params.crc_type = new_crctype;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
-
- return 0;
-}
-
-/**
- * hdlcdev_xmit - called by generic HDLC layer to send a frame
- * @skb: socket buffer containing HDLC frame
- * @dev: pointer to network device structure
- */
-static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
- struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlc_xmit\n", dev->name));
-
- if (!skb->len)
- return NETDEV_TX_OK;
-
- /* stop sending until this frame completes */
- netif_stop_queue(dev);
-
- /* update network statistics */
- dev->stats.tx_packets++;
- dev->stats.tx_bytes += skb->len;
-
- /* save start time for transmit timeout detection */
- netif_trans_update(dev);
-
- spin_lock_irqsave(&info->lock, flags);
- tx_load(info, skb->data, skb->len);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* done with socket buffer, so free it */
- dev_kfree_skb(skb);
-
- return NETDEV_TX_OK;
-}
-
-/**
- * hdlcdev_open - called by network layer when interface enabled
- * @dev: pointer to network device structure
- *
- * Claim resources and initialize hardware.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_open(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- int rc;
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_open\n", dev->name));
-
- /* arbitrate between network and tty opens */
- spin_lock_irqsave(&info->netlock, flags);
- if (info->port.count != 0 || info->netcount != 0) {
- DBGINFO(("%s hdlc_open busy\n", dev->name));
- spin_unlock_irqrestore(&info->netlock, flags);
- return -EBUSY;
- }
- info->netcount=1;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- /* claim resources and init adapter */
- if ((rc = startup_hw(info)) != 0) {
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* generic HDLC layer open processing */
- rc = hdlc_open(dev);
- if (rc) {
- shutdown_hw(info);
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount = 0;
- spin_unlock_irqrestore(&info->netlock, flags);
- return rc;
- }
-
- /* assert RTS and DTR, apply hardware settings */
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- program_hw(info);
-
- /* enable network layer transmit */
- netif_trans_update(dev);
- netif_start_queue(dev);
-
- /* inform generic HDLC layer of current DCD status */
- spin_lock_irqsave(&info->lock, flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock, flags);
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(dev);
- else
- netif_carrier_off(dev);
- return 0;
-}
-
-/**
- * hdlcdev_close - called by network layer when interface is disabled
- * @dev: pointer to network device structure
- *
- * Shutdown hardware and release resources.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_close(struct net_device *dev)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_close\n", dev->name));
-
- netif_stop_queue(dev);
-
- /* shutdown adapter and release resources */
- shutdown_hw(info);
-
- hdlc_close(dev);
-
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- spin_unlock_irqrestore(&info->netlock, flags);
-
- return 0;
-}
-
-/**
- * hdlcdev_ioctl - called by network layer to process IOCTL call to network device
- * @dev: pointer to network device structure
- * @ifr: pointer to network interface request structure
- * @cmd: IOCTL command code
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_ioctl(struct net_device *dev, struct if_settings *ifs)
-{
- const size_t size = sizeof(sync_serial_settings);
- sync_serial_settings new_line;
- sync_serial_settings __user *line = ifs->ifs_ifsu.sync;
- struct slgt_info *info = dev_to_port(dev);
- unsigned int flags;
-
- DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
-
- /* return error if TTY interface open */
- if (info->port.count)
- return -EBUSY;
-
- memset(&new_line, 0, sizeof(new_line));
-
- switch (ifs->type) {
- case IF_GET_IFACE: /* return current sync_serial_settings */
-
- ifs->type = IF_IFACE_SYNC_SERIAL;
- if (ifs->size < size) {
- ifs->size = size; /* data size wanted */
- return -ENOBUFS;
- }
-
- flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
-
- switch (flags){
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
- case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
- case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
- default: new_line.clock_type = CLOCK_DEFAULT;
- }
-
- new_line.clock_rate = info->params.clock_speed;
- new_line.loopback = info->params.loopback ? 1:0;
-
- if (copy_to_user(line, &new_line, size))
- return -EFAULT;
- return 0;
-
- case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
-
- if(!capable(CAP_NET_ADMIN))
- return -EPERM;
- if (copy_from_user(&new_line, line, size))
- return -EFAULT;
-
- switch (new_line.clock_type)
- {
- case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
- case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
- case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
- case CLOCK_DEFAULT: flags = info->params.flags &
- (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
- default: return -EINVAL;
- }
-
- if (new_line.loopback != 0 && new_line.loopback != 1)
- return -EINVAL;
-
- info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
- HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
- HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
- HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
- info->params.flags |= flags;
-
- info->params.loopback = new_line.loopback;
-
- if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
- info->params.clock_speed = new_line.clock_rate;
- else
- info->params.clock_speed = 0;
-
- /* if network interface up, reprogram hardware */
- if (info->netcount)
- program_hw(info);
- return 0;
-
- default:
- return hdlc_ioctl(dev, ifs);
- }
-}
-
-/**
- * hdlcdev_tx_timeout - called by network layer when transmit timeout is detected
- * @dev: pointer to network device structure
- * @txqueue: unused
- */
-static void hdlcdev_tx_timeout(struct net_device *dev, unsigned int txqueue)
-{
- struct slgt_info *info = dev_to_port(dev);
- unsigned long flags;
-
- DBGINFO(("%s hdlcdev_tx_timeout\n", dev->name));
-
- dev->stats.tx_errors++;
- dev->stats.tx_aborted_errors++;
-
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- netif_wake_queue(dev);
-}
-
-/**
- * hdlcdev_tx_done - called by device driver when transmit completes
- * @info: pointer to device instance information
- *
- * Reenable network layer transmit if stopped.
- */
-static void hdlcdev_tx_done(struct slgt_info *info)
-{
- if (netif_queue_stopped(info->netdev))
- netif_wake_queue(info->netdev);
-}
-
-/**
- * hdlcdev_rx - called by device driver when frame received
- * @info: pointer to device instance information
- * @buf: pointer to buffer contianing frame data
- * @size: count of data bytes in buf
- *
- * Pass frame to network layer.
- */
-static void hdlcdev_rx(struct slgt_info *info, char *buf, int size)
-{
- struct sk_buff *skb = dev_alloc_skb(size);
- struct net_device *dev = info->netdev;
-
- DBGINFO(("%s hdlcdev_rx\n", dev->name));
-
- if (skb == NULL) {
- DBGERR(("%s: can't alloc skb, drop packet\n", dev->name));
- dev->stats.rx_dropped++;
- return;
- }
-
- skb_put_data(skb, buf, size);
-
- skb->protocol = hdlc_type_trans(skb, dev);
-
- dev->stats.rx_packets++;
- dev->stats.rx_bytes += size;
-
- netif_rx(skb);
-}
-
-static const struct net_device_ops hdlcdev_ops = {
- .ndo_open = hdlcdev_open,
- .ndo_stop = hdlcdev_close,
- .ndo_start_xmit = hdlc_start_xmit,
- .ndo_siocwandev = hdlcdev_ioctl,
- .ndo_tx_timeout = hdlcdev_tx_timeout,
-};
-
-/**
- * hdlcdev_init - called by device driver when adding device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC initialization.
- *
- * Return: 0 if success, otherwise error code
- */
-static int hdlcdev_init(struct slgt_info *info)
-{
- int rc;
- struct net_device *dev;
- hdlc_device *hdlc;
-
- /* allocate and initialize network and HDLC layer objects */
-
- dev = alloc_hdlcdev(info);
- if (!dev) {
- printk(KERN_ERR "%s hdlc device alloc failure\n", info->device_name);
- return -ENOMEM;
- }
-
- /* for network layer reporting purposes only */
- dev->mem_start = info->phys_reg_addr;
- dev->mem_end = info->phys_reg_addr + SLGT_REG_SIZE - 1;
- dev->irq = info->irq_level;
-
- /* network layer callbacks and settings */
- dev->netdev_ops = &hdlcdev_ops;
- dev->watchdog_timeo = 10 * HZ;
- dev->tx_queue_len = 50;
-
- /* generic HDLC layer callbacks and settings */
- hdlc = dev_to_hdlc(dev);
- hdlc->attach = hdlcdev_attach;
- hdlc->xmit = hdlcdev_xmit;
-
- /* register objects with HDLC layer */
- rc = register_hdlc_device(dev);
- if (rc) {
- printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
- free_netdev(dev);
- return rc;
- }
-
- info->netdev = dev;
- return 0;
-}
-
-/**
- * hdlcdev_exit - called by device driver when removing device instance
- * @info: pointer to device instance information
- *
- * Do generic HDLC cleanup.
- */
-static void hdlcdev_exit(struct slgt_info *info)
-{
- if (!info->netdev)
- return;
- unregister_hdlc_device(info->netdev);
- free_netdev(info->netdev);
- info->netdev = NULL;
-}
-
-#endif /* ifdef CONFIG_HDLC */
-
-/*
- * get async data from rx DMA buffers
- */
-static void rx_async(struct slgt_info *info)
-{
- struct mgsl_icount *icount = &info->icount;
- unsigned int start, end;
- unsigned char *p;
- unsigned char status;
- struct slgt_desc *bufs = info->rbufs;
- int i, count;
- int chars = 0;
- int stat;
- unsigned char ch;
-
- start = end = info->rbuf_current;
-
- while(desc_complete(bufs[end])) {
- count = desc_count(bufs[end]) - info->rbuf_index;
- p = bufs[end].buf + info->rbuf_index;
-
- DBGISR(("%s rx_async count=%d\n", info->device_name, count));
- DBGDATA(info, p, count, "rx");
-
- for(i=0 ; i < count; i+=2, p+=2) {
- ch = *p;
- icount->rx++;
-
- stat = 0;
-
- status = *(p + 1) & (BIT1 + BIT0);
- if (status) {
- if (status & BIT1)
- icount->parity++;
- else if (status & BIT0)
- icount->frame++;
- /* discard char if tty control flags say so */
- if (status & info->ignore_status_mask)
- continue;
- if (status & BIT1)
- stat = TTY_PARITY;
- else if (status & BIT0)
- stat = TTY_FRAME;
- }
- tty_insert_flip_char(&info->port, ch, stat);
- chars++;
- }
-
- if (i < count) {
- /* receive buffer not completed */
- info->rbuf_index += i;
- mod_timer(&info->rx_timer, jiffies + 1);
- break;
- }
-
- info->rbuf_index = 0;
- free_rbufs(info, end, end);
-
- if (++end == info->rbuf_count)
- end = 0;
-
- /* if entire list searched then no frame available */
- if (end == start)
- break;
- }
-
- if (chars)
- tty_flip_buffer_push(&info->port);
-}
-
-/*
- * return next bottom half action to perform
- */
-static int bh_action(struct slgt_info *info)
-{
- unsigned long flags;
- int rc;
-
- spin_lock_irqsave(&info->lock,flags);
-
- if (info->pending_bh & BH_RECEIVE) {
- info->pending_bh &= ~BH_RECEIVE;
- rc = BH_RECEIVE;
- } else if (info->pending_bh & BH_TRANSMIT) {
- info->pending_bh &= ~BH_TRANSMIT;
- rc = BH_TRANSMIT;
- } else if (info->pending_bh & BH_STATUS) {
- info->pending_bh &= ~BH_STATUS;
- rc = BH_STATUS;
- } else {
- /* Mark BH routine as complete */
- info->bh_running = false;
- info->bh_requested = false;
- rc = 0;
- }
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- return rc;
-}
-
-/*
- * perform bottom half processing
- */
-static void bh_handler(struct work_struct *work)
-{
- struct slgt_info *info = container_of(work, struct slgt_info, task);
- int action;
-
- info->bh_running = true;
-
- while((action = bh_action(info))) {
- switch (action) {
- case BH_RECEIVE:
- DBGBH(("%s bh receive\n", info->device_name));
- switch(info->params.mode) {
- case MGSL_MODE_ASYNC:
- rx_async(info);
- break;
- case MGSL_MODE_HDLC:
- while(rx_get_frame(info));
- break;
- case MGSL_MODE_RAW:
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- while(rx_get_buf(info));
- break;
- }
- /* restart receiver if rx DMA buffers exhausted */
- if (info->rx_restart)
- rx_start(info);
- break;
- case BH_TRANSMIT:
- bh_transmit(info);
- break;
- case BH_STATUS:
- DBGBH(("%s bh status\n", info->device_name));
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- break;
- default:
- DBGBH(("%s unknown action\n", info->device_name));
- break;
- }
- }
- DBGBH(("%s bh_handler exit\n", info->device_name));
-}
-
-static void bh_transmit(struct slgt_info *info)
-{
- struct tty_struct *tty = info->port.tty;
-
- DBGBH(("%s bh_transmit\n", info->device_name));
- if (tty)
- tty_wakeup(tty);
-}
-
-static void dsr_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT3) {
- info->signals |= SerialSignal_DSR;
- info->input_signal_events.dsr_up++;
- } else {
- info->signals &= ~SerialSignal_DSR;
- info->input_signal_events.dsr_down++;
- }
- DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DSR);
- return;
- }
- info->icount.dsr++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void cts_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT2) {
- info->signals |= SerialSignal_CTS;
- info->input_signal_events.cts_up++;
- } else {
- info->signals &= ~SerialSignal_CTS;
- info->input_signal_events.cts_down++;
- }
- DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_CTS);
- return;
- }
- info->icount.cts++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_cts_enabled(&info->port)) {
- if (info->port.tty) {
- if (info->port.tty->hw_stopped) {
- if (info->signals & SerialSignal_CTS) {
- info->port.tty->hw_stopped = false;
- info->pending_bh |= BH_TRANSMIT;
- return;
- }
- } else {
- if (!(info->signals & SerialSignal_CTS))
- info->port.tty->hw_stopped = true;
- }
- }
- }
-}
-
-static void dcd_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT1) {
- info->signals |= SerialSignal_DCD;
- info->input_signal_events.dcd_up++;
- } else {
- info->signals &= ~SerialSignal_DCD;
- info->input_signal_events.dcd_down++;
- }
- DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_DCD);
- return;
- }
- info->icount.dcd++;
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount) {
- if (info->signals & SerialSignal_DCD)
- netif_carrier_on(info->netdev);
- else
- netif_carrier_off(info->netdev);
- }
-#endif
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-
- if (tty_port_check_carrier(&info->port)) {
- if (info->signals & SerialSignal_DCD)
- wake_up_interruptible(&info->port.open_wait);
- else {
- if (info->port.tty)
- tty_hangup(info->port.tty);
- }
- }
-}
-
-static void ri_change(struct slgt_info *info, unsigned short status)
-{
- if (status & BIT0) {
- info->signals |= SerialSignal_RI;
- info->input_signal_events.ri_up++;
- } else {
- info->signals &= ~SerialSignal_RI;
- info->input_signal_events.ri_down++;
- }
- DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals));
- if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) {
- slgt_irq_off(info, IRQ_RI);
- return;
- }
- info->icount.rng++;
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
- info->pending_bh |= BH_STATUS;
-}
-
-static void isr_rxdata(struct slgt_info *info)
-{
- unsigned int count = info->rbuf_fill_count;
- unsigned int i = info->rbuf_fill_index;
- unsigned short reg;
-
- while (rd_reg16(info, SSR) & IRQ_RXDATA) {
- reg = rd_reg16(info, RDR);
- DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
- if (desc_complete(info->rbufs[i])) {
- /* all buffers full */
- rx_stop(info);
- info->rx_restart = true;
- continue;
- }
- info->rbufs[i].buf[count++] = (unsigned char)reg;
- /* async mode saves status byte to buffer for each data byte */
- if (info->params.mode == MGSL_MODE_ASYNC)
- info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
- if (count == info->rbuf_fill_level || (reg & BIT10)) {
- /* buffer full or end of frame */
- set_desc_count(info->rbufs[i], count);
- set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
- info->rbuf_fill_count = count = 0;
- if (++i == info->rbuf_count)
- i = 0;
- info->pending_bh |= BH_RECEIVE;
- }
- }
-
- info->rbuf_fill_index = i;
- info->rbuf_fill_count = count;
-}
-
-static void isr_serial(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- DBGISR(("%s isr_serial status=%04X\n", info->device_name, status));
-
- wr_reg16(info, SSR, status); /* clear pending */
-
- info->irq_occurred = true;
-
- if (info->params.mode == MGSL_MODE_ASYNC) {
- if (status & IRQ_TXIDLE) {
- if (info->tx_active)
- isr_txeom(info, status);
- }
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
- info->icount.brk++;
- /* process break detection if tty control allows */
- if (info->port.tty) {
- if (!(status & info->ignore_status_mask)) {
- if (info->read_status_mask & MASK_BREAK) {
- tty_insert_flip_char(&info->port, 0, TTY_BREAK);
- if (info->port.flags & ASYNC_SAK)
- do_SAK(info->port.tty);
- }
- }
- }
- }
- } else {
- if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
- isr_txeom(info, status);
- if (info->rx_pio && (status & IRQ_RXDATA))
- isr_rxdata(info);
- if (status & IRQ_RXIDLE) {
- if (status & RXIDLE)
- info->icount.rxidle++;
- else
- info->icount.exithunt++;
- wake_up_interruptible(&info->event_wait_q);
- }
-
- if (status & IRQ_RXOVER)
- rx_start(info);
- }
-
- if (status & IRQ_DSR)
- dsr_change(info, status);
- if (status & IRQ_CTS)
- cts_change(info, status);
- if (status & IRQ_DCD)
- dcd_change(info, status);
- if (status & IRQ_RI)
- ri_change(info, status);
-}
-
-static void isr_rdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, RDCSR);
-
- DBGISR(("%s isr_rdma status=%08x\n", info->device_name, status));
-
- /* RDCSR (rx DMA control/status)
- *
- * 31..07 reserved
- * 06 save status byte to DMA buffer
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, RDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4)) {
- DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name));
- info->rx_restart = true;
- }
- info->pending_bh |= BH_RECEIVE;
-}
-
-static void isr_tdma(struct slgt_info *info)
-{
- unsigned int status = rd_reg32(info, TDCSR);
-
- DBGISR(("%s isr_tdma status=%08x\n", info->device_name, status));
-
- /* TDCSR (tx DMA control/status)
- *
- * 31..06 reserved
- * 05 error
- * 04 eol (end of list)
- * 03 eob (end of buffer)
- * 02 IRQ enable
- * 01 reset
- * 00 enable
- */
- wr_reg32(info, TDCSR, status); /* clear pending */
-
- if (status & (BIT5 + BIT4 + BIT3)) {
- // another transmit buffer has completed
- // run bottom half to get more send data from user
- info->pending_bh |= BH_TRANSMIT;
- }
-}
-
-/*
- * return true if there are unsent tx DMA buffers, otherwise false
- *
- * if there are unsent buffers then info->tbuf_start
- * is set to index of first unsent buffer
- */
-static bool unsent_tbufs(struct slgt_info *info)
-{
- unsigned int i = info->tbuf_current;
- bool rc = false;
-
- /*
- * search backwards from last loaded buffer (precedes tbuf_current)
- * for first unsent buffer (desc_count > 0)
- */
-
- do {
- if (i)
- i--;
- else
- i = info->tbuf_count - 1;
- if (!desc_count(info->tbufs[i]))
- break;
- info->tbuf_start = i;
- rc = true;
- } while (i != info->tbuf_current);
-
- return rc;
-}
-
-static void isr_txeom(struct slgt_info *info, unsigned short status)
-{
- DBGISR(("%s txeom status=%04x\n", info->device_name, status));
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
- tdma_reset(info);
- if (status & IRQ_TXUNDER) {
- unsigned short val = rd_reg16(info, TCR);
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, TCR, val); /* clear reset bit */
- }
-
- if (info->tx_active) {
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (status & IRQ_TXUNDER)
- info->icount.txunder++;
- else if (status & IRQ_TXIDLE)
- info->icount.txok++;
- }
-
- if (unsent_tbufs(info)) {
- tx_start(info);
- update_tx_timer(info);
- return;
- }
- info->tx_active = false;
-
- timer_delete(&info->tx_timer);
-
- if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) {
- info->signals &= ~SerialSignal_RTS;
- info->drop_rts_on_tx_done = false;
- set_gtsignals(info);
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- {
- if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) {
- tx_stop(info);
- return;
- }
- info->pending_bh |= BH_TRANSMIT;
- }
- }
-}
-
-static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state)
-{
- struct cond_wait *w, *prev;
-
- /* wake processes waiting for specific transitions */
- for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) {
- if (w->data & changed) {
- w->data = state;
- wake_up_interruptible(&w->q);
- if (prev != NULL)
- prev->next = w->next;
- else
- info->gpio_wait_q = w->next;
- } else
- prev = w;
- }
-}
-
-/* interrupt service routine
- *
- * irq interrupt number
- * dev_id device ID supplied during interrupt registration
- */
-static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
-{
- struct slgt_info *info = dev_id;
- unsigned int gsr;
- unsigned int i;
-
- DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level));
-
- while((gsr = rd_reg32(info, GSR) & 0xffffff00)) {
- DBGISR(("%s gsr=%08x\n", info->device_name, gsr));
- info->irq_occurred = true;
- for(i=0; i < info->port_count ; i++) {
- if (info->port_array[i] == NULL)
- continue;
- spin_lock(&info->port_array[i]->lock);
- if (gsr & (BIT8 << i))
- isr_serial(info->port_array[i]);
- if (gsr & (BIT16 << (i*2)))
- isr_rdma(info->port_array[i]);
- if (gsr & (BIT17 << (i*2)))
- isr_tdma(info->port_array[i]);
- spin_unlock(&info->port_array[i]->lock);
- }
- }
-
- if (info->gpio_present) {
- unsigned int state;
- unsigned int changed;
- spin_lock(&info->lock);
- while ((changed = rd_reg32(info, IOSR)) != 0) {
- DBGISR(("%s iosr=%08x\n", info->device_name, changed));
- /* read latched state of GPIO signals */
- state = rd_reg32(info, IOVR);
- /* clear pending GPIO interrupt bits */
- wr_reg32(info, IOSR, changed);
- for (i=0 ; i < info->port_count ; i++) {
- if (info->port_array[i] != NULL)
- isr_gpio(info->port_array[i], changed, state);
- }
- }
- spin_unlock(&info->lock);
- }
-
- for(i=0; i < info->port_count ; i++) {
- struct slgt_info *port = info->port_array[i];
- if (port == NULL)
- continue;
- spin_lock(&port->lock);
- if ((port->port.count || port->netcount) &&
- port->pending_bh && !port->bh_running &&
- !port->bh_requested) {
- DBGISR(("%s bh queued\n", port->device_name));
- schedule_work(&port->task);
- port->bh_requested = true;
- }
- spin_unlock(&port->lock);
- }
-
- DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level));
- return IRQ_HANDLED;
-}
-
-static int startup_hw(struct slgt_info *info)
-{
- DBGINFO(("%s startup\n", info->device_name));
-
- if (tty_port_initialized(&info->port))
- return 0;
-
- if (!info->tx_buf) {
- info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
- if (!info->tx_buf) {
- DBGERR(("%s can't allocate tx buffer\n", info->device_name));
- return -ENOMEM;
- }
- }
-
- info->pending_bh = 0;
-
- memset(&info->icount, 0, sizeof(info->icount));
-
- /* program hardware for current parameters */
- change_params(info);
-
- if (info->port.tty)
- clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, true);
-
- return 0;
-}
-
-/*
- * called by close() and hangup() to shutdown hardware
- */
-static void shutdown_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- if (!tty_port_initialized(&info->port))
- return;
-
- DBGINFO(("%s shutdown\n", info->device_name));
-
- /* clear status wait queue because status changes */
- /* can't happen after shutting down the hardware */
- wake_up_interruptible(&info->status_event_wait_q);
- wake_up_interruptible(&info->event_wait_q);
-
- timer_delete_sync(&info->tx_timer);
- timer_delete_sync(&info->rx_timer);
-
- kfree(info->tx_buf);
- info->tx_buf = NULL;
-
- spin_lock_irqsave(&info->lock,flags);
-
- tx_stop(info);
- rx_stop(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-
- if (!info->port.tty || info->port.tty->termios.c_cflag & HUPCL) {
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- }
-
- flush_cond_wait(&info->gpio_wait_q);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- if (info->port.tty)
- set_bit(TTY_IO_ERROR, &info->port.tty->flags);
-
- tty_port_set_initialized(&info->port, false);
-}
-
-static void program_hw(struct slgt_info *info)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
-
- rx_stop(info);
- tx_stop(info);
-
- if (info->params.mode != MGSL_MODE_ASYNC ||
- info->netcount)
- sync_mode(info);
- else
- async_mode(info);
-
- set_gtsignals(info);
-
- info->dcd_chkcount = 0;
- info->cts_chkcount = 0;
- info->ri_chkcount = 0;
- info->dsr_chkcount = 0;
-
- slgt_irq_on(info, IRQ_DCD | IRQ_CTS | IRQ_DSR | IRQ_RI);
- get_gtsignals(info);
-
- if (info->netcount ||
- (info->port.tty && info->port.tty->termios.c_cflag & CREAD))
- rx_start(info);
-
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-/*
- * reconfigure adapter based on new parameters
- */
-static void change_params(struct slgt_info *info)
-{
- unsigned cflag;
- int bits_per_char;
-
- if (!info->port.tty)
- return;
- DBGINFO(("%s change_params\n", info->device_name));
-
- cflag = info->port.tty->termios.c_cflag;
-
- /* if B0 rate (hangup) specified then negate RTS and DTR */
- /* otherwise assert RTS and DTR */
- if (cflag & CBAUD)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
-
- /* byte size and parity */
-
- info->params.data_bits = tty_get_char_size(cflag);
- info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1;
-
- if (cflag & PARENB)
- info->params.parity = (cflag & PARODD) ? ASYNC_PARITY_ODD : ASYNC_PARITY_EVEN;
- else
- info->params.parity = ASYNC_PARITY_NONE;
-
- /* calculate number of jiffies to transmit a full
- * FIFO (32 bytes) at specified data rate
- */
- bits_per_char = info->params.data_bits +
- info->params.stop_bits + 1;
-
- info->params.data_rate = tty_get_baud_rate(info->port.tty);
-
- if (info->params.data_rate) {
- info->timeout = (32*HZ*bits_per_char) /
- info->params.data_rate;
- }
- info->timeout += HZ/50; /* Add .02 seconds of slop */
-
- tty_port_set_cts_flow(&info->port, cflag & CRTSCTS);
- tty_port_set_check_carrier(&info->port, ~cflag & CLOCAL);
-
- /* process tty input control flags */
-
- info->read_status_mask = IRQ_RXOVER;
- if (I_INPCK(info->port.tty))
- info->read_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty))
- info->read_status_mask |= MASK_BREAK;
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_PARITY | MASK_FRAMING;
- if (I_IGNBRK(info->port.tty)) {
- info->ignore_status_mask |= MASK_BREAK;
- /* If ignoring parity and break indicators, ignore
- * overruns too. (For real raw support).
- */
- if (I_IGNPAR(info->port.tty))
- info->ignore_status_mask |= MASK_OVERRUN;
- }
-
- program_hw(info);
-}
-
-static int get_stats(struct slgt_info *info, struct mgsl_icount __user *user_icount)
-{
- DBGINFO(("%s get_stats\n", info->device_name));
- if (!user_icount) {
- memset(&info->icount, 0, sizeof(info->icount));
- } else {
- if (copy_to_user(user_icount, &info->icount, sizeof(struct mgsl_icount)))
- return -EFAULT;
- }
- return 0;
-}
-
-static int get_params(struct slgt_info *info, MGSL_PARAMS __user *user_params)
-{
- DBGINFO(("%s get_params\n", info->device_name));
- if (copy_to_user(user_params, &info->params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
- return 0;
-}
-
-static int set_params(struct slgt_info *info, MGSL_PARAMS __user *new_params)
-{
- unsigned long flags;
- MGSL_PARAMS tmp_params;
-
- DBGINFO(("%s set_params\n", info->device_name));
- if (copy_from_user(&tmp_params, new_params, sizeof(MGSL_PARAMS)))
- return -EFAULT;
-
- spin_lock_irqsave(&info->lock, flags);
- if (tmp_params.mode == MGSL_MODE_BASE_CLOCK)
- info->base_clock = tmp_params.clock_speed;
- else
- memcpy(&info->params, &tmp_params, sizeof(MGSL_PARAMS));
- spin_unlock_irqrestore(&info->lock, flags);
-
- program_hw(info);
-
- return 0;
-}
-
-static int get_txidle(struct slgt_info *info, int __user *idle_mode)
-{
- DBGINFO(("%s get_txidle=%d\n", info->device_name, info->idle_mode));
- if (put_user(info->idle_mode, idle_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_txidle(struct slgt_info *info, int idle_mode)
-{
- unsigned long flags;
- DBGINFO(("%s set_txidle(%d)\n", info->device_name, idle_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->idle_mode = idle_mode;
- if (info->params.mode != MGSL_MODE_ASYNC)
- tx_set_idle(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int tx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- DBGINFO(("%s tx_enable(%d)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- if (enable) {
- if (!info->tx_enabled)
- tx_start(info);
- } else {
- if (info->tx_enabled)
- tx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * abort transmit HDLC frame
- */
-static int tx_abort(struct slgt_info *info)
-{
- unsigned long flags;
- DBGINFO(("%s tx_abort\n", info->device_name));
- spin_lock_irqsave(&info->lock,flags);
- tdma_reset(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int rx_enable(struct slgt_info *info, int enable)
-{
- unsigned long flags;
- unsigned int rbuf_fill_level;
- DBGINFO(("%s rx_enable(%08x)\n", info->device_name, enable));
- spin_lock_irqsave(&info->lock,flags);
- /*
- * enable[31..16] = receive DMA buffer fill level
- * 0 = noop (leave fill level unchanged)
- * fill level must be multiple of 4 and <= buffer size
- */
- rbuf_fill_level = ((unsigned int)enable) >> 16;
- if (rbuf_fill_level) {
- if ((rbuf_fill_level > DMABUFSIZE) || (rbuf_fill_level % 4)) {
- spin_unlock_irqrestore(&info->lock, flags);
- return -EINVAL;
- }
- info->rbuf_fill_level = rbuf_fill_level;
- if (rbuf_fill_level < 128)
- info->rx_pio = 1; /* PIO mode */
- else
- info->rx_pio = 0; /* DMA mode */
- rx_stop(info); /* restart receiver to use new fill level */
- }
-
- /*
- * enable[1..0] = receiver enable command
- * 0 = disable
- * 1 = enable
- * 2 = enable or force hunt mode if already enabled
- */
- enable &= 3;
- if (enable) {
- if (!info->rx_enabled)
- rx_start(info);
- else if (enable == 2) {
- /* force hunt mode (write 1 to RCR[3]) */
- wr_reg16(info, RCR, rd_reg16(info, RCR) | BIT3);
- }
- } else {
- if (info->rx_enabled)
- rx_stop(info);
- }
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-/*
- * wait for specified event to occur
- */
-static int wait_mgsl_event(struct slgt_info *info, int __user *mask_ptr)
-{
- unsigned long flags;
- int s;
- int rc=0;
- struct mgsl_icount cprev, cnow;
- int events;
- int mask;
- struct _input_signal_events oldsigs, newsigs;
- DECLARE_WAITQUEUE(wait, current);
-
- if (get_user(mask, mask_ptr))
- return -EFAULT;
-
- DBGINFO(("%s wait_mgsl_event(%d)\n", info->device_name, mask));
-
- spin_lock_irqsave(&info->lock,flags);
-
- /* return immediately if state matches requested events */
- get_gtsignals(info);
- s = info->signals;
-
- events = mask &
- ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
- ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
- ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
- ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
- if (events) {
- spin_unlock_irqrestore(&info->lock,flags);
- goto exit;
- }
-
- /* save current irq counts */
- cprev = info->icount;
- oldsigs = info->input_signal_events;
-
- /* enable hunt and idle irqs if needed */
- if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
- unsigned short val = rd_reg16(info, SCR);
- if (!(val & IRQ_RXIDLE))
- wr_reg16(info, SCR, (unsigned short)(val | IRQ_RXIDLE));
- }
-
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&info->event_wait_q, &wait);
-
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- newsigs = info->input_signal_events;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (newsigs.dsr_up == oldsigs.dsr_up &&
- newsigs.dsr_down == oldsigs.dsr_down &&
- newsigs.dcd_up == oldsigs.dcd_up &&
- newsigs.dcd_down == oldsigs.dcd_down &&
- newsigs.cts_up == oldsigs.cts_up &&
- newsigs.cts_down == oldsigs.cts_down &&
- newsigs.ri_up == oldsigs.ri_up &&
- newsigs.ri_down == oldsigs.ri_down &&
- cnow.exithunt == cprev.exithunt &&
- cnow.rxidle == cprev.rxidle) {
- rc = -EIO;
- break;
- }
-
- events = mask &
- ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
- (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
- (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
- (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
- (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
- (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
- (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
- (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
- (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
- (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
- if (events)
- break;
-
- cprev = cnow;
- oldsigs = newsigs;
- }
-
- remove_wait_queue(&info->event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
-
-
- if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
- spin_lock_irqsave(&info->lock,flags);
- if (!waitqueue_active(&info->event_wait_q)) {
- /* disable enable exit hunt mode/idle rcvd IRQs */
- wr_reg16(info, SCR,
- (unsigned short)(rd_reg16(info, SCR) & ~IRQ_RXIDLE));
- }
- spin_unlock_irqrestore(&info->lock,flags);
- }
-exit:
- if (rc == 0)
- rc = put_user(events, mask_ptr);
- return rc;
-}
-
-static int get_interface(struct slgt_info *info, int __user *if_mode)
-{
- DBGINFO(("%s get_interface=%x\n", info->device_name, info->if_mode));
- if (put_user(info->if_mode, if_mode))
- return -EFAULT;
- return 0;
-}
-
-static int set_interface(struct slgt_info *info, int if_mode)
-{
- unsigned long flags;
- unsigned short val;
-
- DBGINFO(("%s set_interface=%x)\n", info->device_name, if_mode));
- spin_lock_irqsave(&info->lock,flags);
- info->if_mode = if_mode;
-
- msc_set_vcr(info);
-
- /* TCR (tx control) 07 1=RTS driver control */
- val = rd_reg16(info, TCR);
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
- else
- val &= ~BIT7;
- wr_reg16(info, TCR, val);
-
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static int get_xsync(struct slgt_info *info, int __user *xsync)
-{
- DBGINFO(("%s get_xsync=%x\n", info->device_name, info->xsync));
- if (put_user(info->xsync, xsync))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended sync pattern (1 to 4 bytes) for extended sync mode
- *
- * sync pattern is contained in least significant bytes of value
- * most significant byte of sync pattern is oldest (1st sent/detected)
- */
-static int set_xsync(struct slgt_info *info, int xsync)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xsync=%x)\n", info->device_name, xsync));
- spin_lock_irqsave(&info->lock, flags);
- info->xsync = xsync;
- wr_reg32(info, XSR, xsync);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-static int get_xctrl(struct slgt_info *info, int __user *xctrl)
-{
- DBGINFO(("%s get_xctrl=%x\n", info->device_name, info->xctrl));
- if (put_user(info->xctrl, xctrl))
- return -EFAULT;
- return 0;
-}
-
-/*
- * set extended control options
- *
- * xctrl[31:19] reserved, must be zero
- * xctrl[18:17] extended sync pattern length in bytes
- * 00 = 1 byte in xsr[7:0]
- * 01 = 2 bytes in xsr[15:0]
- * 10 = 3 bytes in xsr[23:0]
- * 11 = 4 bytes in xsr[31:0]
- * xctrl[16] 1 = enable terminal count, 0=disabled
- * xctrl[15:0] receive terminal count for fixed length packets
- * value is count minus one (0 = 1 byte packet)
- * when terminal count is reached, receiver
- * automatically returns to hunt mode and receive
- * FIFO contents are flushed to DMA buffers with
- * end of frame (EOF) status
- */
-static int set_xctrl(struct slgt_info *info, int xctrl)
-{
- unsigned long flags;
-
- DBGINFO(("%s set_xctrl=%x)\n", info->device_name, xctrl));
- spin_lock_irqsave(&info->lock, flags);
- info->xctrl = xctrl;
- wr_reg32(info, XCR, xctrl);
- spin_unlock_irqrestore(&info->lock, flags);
- return 0;
-}
-
-/*
- * set general purpose IO pin state and direction
- *
- * user_gpio fields:
- * state each bit indicates a pin state
- * smask set bit indicates pin state to set
- * dir each bit indicates a pin direction (0=input, 1=output)
- * dmask set bit indicates pin direction to set
- */
-static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- struct gpio_desc gpio;
- __u32 data;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
- info->device_name, gpio.state, gpio.smask,
- gpio.dir, gpio.dmask));
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- if (gpio.dmask) {
- data = rd_reg32(info, IODR);
- data |= gpio.dmask & gpio.dir;
- data &= ~(gpio.dmask & ~gpio.dir);
- wr_reg32(info, IODR, data);
- }
- if (gpio.smask) {
- data = rd_reg32(info, IOVR);
- data |= gpio.smask & gpio.state;
- data &= ~(gpio.smask & ~gpio.state);
- wr_reg32(info, IOVR, data);
- }
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- return 0;
-}
-
-/*
- * get general purpose IO pin state and direction
- */
-static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- struct gpio_desc gpio;
- if (!info->gpio_present)
- return -EINVAL;
- gpio.state = rd_reg32(info, IOVR);
- gpio.smask = 0xffffffff;
- gpio.dir = rd_reg32(info, IODR);
- gpio.dmask = 0xffffffff;
- if (copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s get_gpio state=%08x dir=%08x\n",
- info->device_name, gpio.state, gpio.dir));
- return 0;
-}
-
-/*
- * conditional wait facility
- */
-static void init_cond_wait(struct cond_wait *w, unsigned int data)
-{
- init_waitqueue_head(&w->q);
- init_waitqueue_entry(&w->wait, current);
- w->data = data;
-}
-
-static void add_cond_wait(struct cond_wait **head, struct cond_wait *w)
-{
- set_current_state(TASK_INTERRUPTIBLE);
- add_wait_queue(&w->q, &w->wait);
- w->next = *head;
- *head = w;
-}
-
-static void remove_cond_wait(struct cond_wait **head, struct cond_wait *cw)
-{
- struct cond_wait *w, *prev;
- remove_wait_queue(&cw->q, &cw->wait);
- set_current_state(TASK_RUNNING);
- for (w = *head, prev = NULL ; w != NULL ; prev = w, w = w->next) {
- if (w == cw) {
- if (prev != NULL)
- prev->next = w->next;
- else
- *head = w->next;
- break;
- }
- }
-}
-
-static void flush_cond_wait(struct cond_wait **head)
-{
- while (*head != NULL) {
- wake_up_interruptible(&(*head)->q);
- *head = (*head)->next;
- }
-}
-
-/*
- * wait for general purpose I/O pin(s) to enter specified state
- *
- * user_gpio fields:
- * state - bit indicates target pin state
- * smask - set bit indicates watched pin
- *
- * The wait ends when at least one watched pin enters the specified
- * state. When 0 (no error) is returned, user_gpio->state is set to the
- * state of all GPIO pins when the wait ends.
- *
- * Note: Each pin may be a dedicated input, dedicated output, or
- * configurable input/output. The number and configuration of pins
- * varies with the specific adapter model. Only input pins (dedicated
- * or configured) can be monitored with this function.
- */
-static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
-{
- unsigned long flags;
- int rc = 0;
- struct gpio_desc gpio;
- struct cond_wait wait;
- u32 state;
-
- if (!info->gpio_present)
- return -EINVAL;
- if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
- return -EFAULT;
- DBGINFO(("%s wait_gpio() state=%08x smask=%08x\n",
- info->device_name, gpio.state, gpio.smask));
- /* ignore output pins identified by set IODR bit */
- if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0)
- return -EINVAL;
- init_cond_wait(&wait, gpio.smask);
-
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- /* enable interrupts for watched pins */
- wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
- /* get current pin states */
- state = rd_reg32(info, IOVR);
-
- if (gpio.smask & ~(state ^ gpio.state)) {
- /* already in target state */
- gpio.state = state;
- } else {
- /* wait for target state */
- add_cond_wait(&info->gpio_wait_q, &wait);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
- schedule();
- if (signal_pending(current))
- rc = -ERESTARTSYS;
- else
- gpio.state = wait.data;
- spin_lock_irqsave(&info->port_array[0]->lock, flags);
- remove_cond_wait(&info->gpio_wait_q, &wait);
- }
-
- /* disable all GPIO interrupts if no waiting processes */
- if (info->gpio_wait_q == NULL)
- wr_reg32(info, IOER, 0);
- spin_unlock_irqrestore(&info->port_array[0]->lock, flags);
-
- if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
- rc = -EFAULT;
- return rc;
-}
-
-static int modem_input_wait(struct slgt_info *info,int arg)
-{
- unsigned long flags;
- int rc;
- struct mgsl_icount cprev, cnow;
- DECLARE_WAITQUEUE(wait, current);
-
- /* save current irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cprev = info->icount;
- add_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- for(;;) {
- schedule();
- if (signal_pending(current)) {
- rc = -ERESTARTSYS;
- break;
- }
-
- /* get new irq counts */
- spin_lock_irqsave(&info->lock,flags);
- cnow = info->icount;
- set_current_state(TASK_INTERRUPTIBLE);
- spin_unlock_irqrestore(&info->lock,flags);
-
- /* if no change, wait aborted for some reason */
- if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
- cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
- rc = -EIO;
- break;
- }
-
- /* check for change in caller specified modem input */
- if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
- (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
- (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
- (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
- rc = 0;
- break;
- }
-
- cprev = cnow;
- }
- remove_wait_queue(&info->status_event_wait_q, &wait);
- set_current_state(TASK_RUNNING);
- return rc;
-}
-
-/*
- * return state of serial control and status signals
- */
-static int tiocmget(struct tty_struct *tty)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned int result;
- unsigned long flags;
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- result = ((info->signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
- ((info->signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
- ((info->signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
- ((info->signals & SerialSignal_RI) ? TIOCM_RNG:0) +
- ((info->signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
- ((info->signals & SerialSignal_CTS) ? TIOCM_CTS:0);
-
- DBGINFO(("%s tiocmget value=%08X\n", info->device_name, result));
- return result;
-}
-
-/*
- * set modem control signals (DTR/RTS)
- *
- * cmd signal command: TIOCMBIS = set bit TIOCMBIC = clear bit
- * TIOCMSET = set/clear signal values
- * value bit mask for command
- */
-static int tiocmset(struct tty_struct *tty,
- unsigned int set, unsigned int clear)
-{
- struct slgt_info *info = tty->driver_data;
- unsigned long flags;
-
- DBGINFO(("%s tiocmset(%x,%x)\n", info->device_name, set, clear));
-
- if (set & TIOCM_RTS)
- info->signals |= SerialSignal_RTS;
- if (set & TIOCM_DTR)
- info->signals |= SerialSignal_DTR;
- if (clear & TIOCM_RTS)
- info->signals &= ~SerialSignal_RTS;
- if (clear & TIOCM_DTR)
- info->signals &= ~SerialSignal_DTR;
-
- spin_lock_irqsave(&info->lock,flags);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
- return 0;
-}
-
-static bool carrier_raised(struct tty_port *port)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- get_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- return info->signals & SerialSignal_DCD;
-}
-
-static void dtr_rts(struct tty_port *port, bool active)
-{
- unsigned long flags;
- struct slgt_info *info = container_of(port, struct slgt_info, port);
-
- spin_lock_irqsave(&info->lock,flags);
- if (active)
- info->signals |= SerialSignal_RTS | SerialSignal_DTR;
- else
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
- spin_unlock_irqrestore(&info->lock,flags);
-}
-
-
-/*
- * block current process until the device is ready to open
- */
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
- struct slgt_info *info)
-{
- DECLARE_WAITQUEUE(wait, current);
- int retval;
- bool do_clocal = false;
- unsigned long flags;
- bool cd;
- struct tty_port *port = &info->port;
-
- DBGINFO(("%s block_til_ready\n", tty->driver->name));
-
- if (filp->f_flags & O_NONBLOCK || tty_io_error(tty)) {
- /* nonblock mode is set or port is not enabled */
- tty_port_set_active(port, true);
- return 0;
- }
-
- if (C_CLOCAL(tty))
- do_clocal = true;
-
- /* Wait for carrier detect and the line to become
- * free (i.e., not in use by the callout). While we are in
- * this loop, port->count is dropped by one, so that
- * close() knows when to free things. We restore it upon
- * exit, either normal or abnormal.
- */
-
- retval = 0;
- add_wait_queue(&port->open_wait, &wait);
-
- spin_lock_irqsave(&info->lock, flags);
- port->count--;
- spin_unlock_irqrestore(&info->lock, flags);
- port->blocked_open++;
-
- while (1) {
- if (C_BAUD(tty) && tty_port_initialized(port))
- tty_port_raise_dtr_rts(port);
-
- set_current_state(TASK_INTERRUPTIBLE);
-
- if (tty_hung_up_p(filp) || !tty_port_initialized(port)) {
- retval = (port->flags & ASYNC_HUP_NOTIFY) ?
- -EAGAIN : -ERESTARTSYS;
- break;
- }
-
- cd = tty_port_carrier_raised(port);
- if (do_clocal || cd)
- break;
-
- if (signal_pending(current)) {
- retval = -ERESTARTSYS;
- break;
- }
-
- DBGINFO(("%s block_til_ready wait\n", tty->driver->name));
- tty_unlock(tty);
- schedule();
- tty_lock(tty);
- }
-
- set_current_state(TASK_RUNNING);
- remove_wait_queue(&port->open_wait, &wait);
-
- if (!tty_hung_up_p(filp))
- port->count++;
- port->blocked_open--;
-
- if (!retval)
- tty_port_set_active(port, true);
-
- DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
- return retval;
-}
-
-/*
- * allocate buffers used for calling line discipline receive_buf
- * directly in synchronous mode
- * note: add 5 bytes to max frame size to allow appending
- * 32-bit CRC and status byte when configured to do so
- */
-static int alloc_tmp_rbuf(struct slgt_info *info)
-{
- info->tmp_rbuf = kmalloc(info->max_frame_size + 5, GFP_KERNEL);
- if (info->tmp_rbuf == NULL)
- return -ENOMEM;
-
- return 0;
-}
-
-static void free_tmp_rbuf(struct slgt_info *info)
-{
- kfree(info->tmp_rbuf);
- info->tmp_rbuf = NULL;
-}
-
-/*
- * allocate DMA descriptor lists.
- */
-static int alloc_desc(struct slgt_info *info)
-{
- unsigned int i;
- unsigned int pbufs;
-
- /* allocate memory to hold descriptor lists */
- info->bufs = dma_alloc_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- &info->bufs_dma_addr, GFP_KERNEL);
- if (info->bufs == NULL)
- return -ENOMEM;
-
- info->rbufs = (struct slgt_desc*)info->bufs;
- info->tbufs = ((struct slgt_desc*)info->bufs) + info->rbuf_count;
-
- pbufs = (unsigned int)info->bufs_dma_addr;
-
- /*
- * Build circular lists of descriptors
- */
-
- for (i=0; i < info->rbuf_count; i++) {
- /* physical address of this descriptor */
- info->rbufs[i].pdesc = pbufs + (i * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->rbuf_count - 1)
- info->rbufs[i].next = cpu_to_le32(pbufs);
- else
- info->rbufs[i].next = cpu_to_le32(pbufs + ((i+1) * sizeof(struct slgt_desc)));
- set_desc_count(info->rbufs[i], DMABUFSIZE);
- }
-
- for (i=0; i < info->tbuf_count; i++) {
- /* physical address of this descriptor */
- info->tbufs[i].pdesc = pbufs + ((info->rbuf_count + i) * sizeof(struct slgt_desc));
-
- /* physical address of next descriptor */
- if (i == info->tbuf_count - 1)
- info->tbufs[i].next = cpu_to_le32(pbufs + info->rbuf_count * sizeof(struct slgt_desc));
- else
- info->tbufs[i].next = cpu_to_le32(pbufs + ((info->rbuf_count + i + 1) * sizeof(struct slgt_desc)));
- }
-
- return 0;
-}
-
-static void free_desc(struct slgt_info *info)
-{
- if (info->bufs != NULL) {
- dma_free_coherent(&info->pdev->dev, DESC_LIST_SIZE,
- info->bufs, info->bufs_dma_addr);
- info->bufs = NULL;
- info->rbufs = NULL;
- info->tbufs = NULL;
- }
-}
-
-static int alloc_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- bufs[i].buf = dma_alloc_coherent(&info->pdev->dev, DMABUFSIZE,
- &bufs[i].buf_dma_addr, GFP_KERNEL);
- if (!bufs[i].buf)
- return -ENOMEM;
- bufs[i].pbuf = cpu_to_le32((unsigned int)bufs[i].buf_dma_addr);
- }
- return 0;
-}
-
-static void free_bufs(struct slgt_info *info, struct slgt_desc *bufs, int count)
-{
- int i;
- for (i=0; i < count; i++) {
- if (bufs[i].buf == NULL)
- continue;
- dma_free_coherent(&info->pdev->dev, DMABUFSIZE, bufs[i].buf,
- bufs[i].buf_dma_addr);
- bufs[i].buf = NULL;
- }
-}
-
-static int alloc_dma_bufs(struct slgt_info *info)
-{
- info->rbuf_count = 32;
- info->tbuf_count = 32;
-
- if (alloc_desc(info) < 0 ||
- alloc_bufs(info, info->rbufs, info->rbuf_count) < 0 ||
- alloc_bufs(info, info->tbufs, info->tbuf_count) < 0 ||
- alloc_tmp_rbuf(info) < 0) {
- DBGERR(("%s DMA buffer alloc fail\n", info->device_name));
- return -ENOMEM;
- }
- reset_rbufs(info);
- return 0;
-}
-
-static void free_dma_bufs(struct slgt_info *info)
-{
- if (info->bufs) {
- free_bufs(info, info->rbufs, info->rbuf_count);
- free_bufs(info, info->tbufs, info->tbuf_count);
- free_desc(info);
- }
- free_tmp_rbuf(info);
-}
-
-static int claim_resources(struct slgt_info *info)
-{
- if (request_mem_region(info->phys_reg_addr, SLGT_REG_SIZE, "synclink_gt") == NULL) {
- DBGERR(("%s reg addr conflict, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_AddressConflict;
- goto errout;
- }
- else
- info->reg_addr_requested = true;
-
- info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE);
- if (!info->reg_addr) {
- DBGERR(("%s can't map device registers, addr=%08X\n",
- info->device_name, info->phys_reg_addr));
- info->init_error = DiagStatus_CantAssignPciResources;
- goto errout;
- }
- return 0;
-
-errout:
- release_resources(info);
- return -ENODEV;
-}
-
-static void release_resources(struct slgt_info *info)
-{
- if (info->irq_requested) {
- free_irq(info->irq_level, info);
- info->irq_requested = false;
- }
-
- if (info->reg_addr_requested) {
- release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE);
- info->reg_addr_requested = false;
- }
-
- if (info->reg_addr) {
- iounmap(info->reg_addr);
- info->reg_addr = NULL;
- }
-}
-
-/* Add the specified device instance data structure to the
- * global linked list of devices and increment the device count.
- */
-static void add_device(struct slgt_info *info)
-{
- char *devstr;
-
- info->next_device = NULL;
- info->line = slgt_device_count;
- sprintf(info->device_name, "%s%d", tty_dev_prefix, info->line);
-
- if (info->line < MAX_DEVICES) {
- if (maxframe[info->line])
- info->max_frame_size = maxframe[info->line];
- }
-
- slgt_device_count++;
-
- if (!slgt_device_list)
- slgt_device_list = info;
- else {
- struct slgt_info *current_dev = slgt_device_list;
- while(current_dev->next_device)
- current_dev = current_dev->next_device;
- current_dev->next_device = info;
- }
-
- if (info->max_frame_size < 4096)
- info->max_frame_size = 4096;
- else if (info->max_frame_size > 65535)
- info->max_frame_size = 65535;
-
- switch(info->pdev->device) {
- case SYNCLINK_GT_DEVICE_ID:
- devstr = "GT";
- break;
- case SYNCLINK_GT2_DEVICE_ID:
- devstr = "GT2";
- break;
- case SYNCLINK_GT4_DEVICE_ID:
- devstr = "GT4";
- break;
- case SYNCLINK_AC_DEVICE_ID:
- devstr = "AC";
- info->params.mode = MGSL_MODE_ASYNC;
- break;
- default:
- devstr = "(unknown model)";
- }
- printk("SyncLink %s %s IO=%08x IRQ=%d MaxFrameSize=%u\n",
- devstr, info->device_name, info->phys_reg_addr,
- info->irq_level, info->max_frame_size);
-
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_init(info);
-#endif
-}
-
-static const struct tty_port_operations slgt_port_ops = {
- .carrier_raised = carrier_raised,
- .dtr_rts = dtr_rts,
-};
-
-/*
- * allocate device instance structure, return NULL on failure
- */
-static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
-{
- struct slgt_info *info;
-
- info = kzalloc_obj(struct slgt_info);
-
- if (!info) {
- DBGERR(("%s device alloc failed adapter=%d port=%d\n",
- driver_name, adapter_num, port_num));
- } else {
- tty_port_init(&info->port);
- info->port.ops = &slgt_port_ops;
- INIT_WORK(&info->task, bh_handler);
- info->max_frame_size = 4096;
- info->base_clock = 14745600;
- info->rbuf_fill_level = DMABUFSIZE;
- init_waitqueue_head(&info->status_event_wait_q);
- init_waitqueue_head(&info->event_wait_q);
- spin_lock_init(&info->netlock);
- memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
- info->idle_mode = HDLC_TXIDLE_FLAGS;
- info->adapter_num = adapter_num;
- info->port_num = port_num;
-
- timer_setup(&info->tx_timer, tx_timeout, 0);
- timer_setup(&info->rx_timer, rx_timeout, 0);
-
- /* Copy configuration info to device instance data */
- info->pdev = pdev;
- info->irq_level = pdev->irq;
- info->phys_reg_addr = pci_resource_start(pdev,0);
-
- info->bus_type = MGSL_BUS_TYPE_PCI;
- info->irq_flags = IRQF_SHARED;
-
- info->init_error = -1; /* assume error, set to 0 on successful init */
- }
-
- return info;
-}
-
-static void device_init(int adapter_num, struct pci_dev *pdev)
-{
- struct slgt_info *port_array[SLGT_MAX_PORTS];
- int i;
- int port_count = 1;
-
- if (pdev->device == SYNCLINK_GT2_DEVICE_ID)
- port_count = 2;
- else if (pdev->device == SYNCLINK_GT4_DEVICE_ID)
- port_count = 4;
-
- /* allocate device instances for all ports */
- for (i=0; i < port_count; ++i) {
- port_array[i] = alloc_dev(adapter_num, i, pdev);
- if (port_array[i] == NULL) {
- for (--i; i >= 0; --i) {
- tty_port_destroy(&port_array[i]->port);
- kfree(port_array[i]);
- }
- return;
- }
- }
-
- /* give copy of port_array to all ports and add to device list */
- for (i=0; i < port_count; ++i) {
- memcpy(port_array[i]->port_array, port_array, sizeof(port_array));
- add_device(port_array[i]);
- port_array[i]->port_count = port_count;
- spin_lock_init(&port_array[i]->lock);
- }
-
- /* Allocate and claim adapter resources */
- if (!claim_resources(port_array[0])) {
-
- alloc_dma_bufs(port_array[0]);
-
- /* copy resource information from first port to others */
- for (i = 1; i < port_count; ++i) {
- port_array[i]->irq_level = port_array[0]->irq_level;
- port_array[i]->reg_addr = port_array[0]->reg_addr;
- alloc_dma_bufs(port_array[i]);
- }
-
- if (request_irq(port_array[0]->irq_level,
- slgt_interrupt,
- port_array[0]->irq_flags,
- port_array[0]->device_name,
- port_array[0]) < 0) {
- DBGERR(("%s request_irq failed IRQ=%d\n",
- port_array[0]->device_name,
- port_array[0]->irq_level));
- } else {
- port_array[0]->irq_requested = true;
- adapter_test(port_array[0]);
- for (i=1 ; i < port_count ; i++) {
- port_array[i]->init_error = port_array[0]->init_error;
- port_array[i]->gpio_present = port_array[0]->gpio_present;
- }
- }
- }
-
- for (i = 0; i < port_count; ++i) {
- struct slgt_info *info = port_array[i];
- tty_port_register_device(&info->port, serial_driver, info->line,
- &info->pdev->dev);
- }
-}
-
-static int init_one(struct pci_dev *dev,
- const struct pci_device_id *ent)
-{
- if (pci_enable_device(dev)) {
- printk("error enabling pci device %p\n", dev);
- return -EIO;
- }
- pci_set_master(dev);
- device_init(slgt_device_count, dev);
- return 0;
-}
-
-static void remove_one(struct pci_dev *dev)
-{
-}
-
-static const struct tty_operations ops = {
- .open = open,
- .close = close,
- .write = write,
- .put_char = put_char,
- .flush_chars = flush_chars,
- .write_room = write_room,
- .chars_in_buffer = chars_in_buffer,
- .flush_buffer = flush_buffer,
- .ioctl = ioctl,
- .compat_ioctl = slgt_compat_ioctl,
- .throttle = throttle,
- .unthrottle = unthrottle,
- .send_xchar = send_xchar,
- .break_ctl = set_break,
- .wait_until_sent = wait_until_sent,
- .set_termios = set_termios,
- .stop = tx_hold,
- .start = tx_release,
- .hangup = hangup,
- .tiocmget = tiocmget,
- .tiocmset = tiocmset,
- .get_icount = get_icount,
- .proc_show = synclink_gt_proc_show,
-};
-
-static void slgt_cleanup(void)
-{
- struct slgt_info *info;
- struct slgt_info *tmp;
-
- if (serial_driver) {
- for (info=slgt_device_list ; info != NULL ; info=info->next_device)
- tty_unregister_device(serial_driver, info->line);
- tty_unregister_driver(serial_driver);
- tty_driver_kref_put(serial_driver);
- }
-
- /* reset devices */
- info = slgt_device_list;
- while(info) {
- reset_port(info);
- info = info->next_device;
- }
-
- /* release devices */
- info = slgt_device_list;
- while(info) {
-#if SYNCLINK_GENERIC_HDLC
- hdlcdev_exit(info);
-#endif
- free_dma_bufs(info);
- free_tmp_rbuf(info);
- if (info->port_num == 0)
- release_resources(info);
- tmp = info;
- info = info->next_device;
- tty_port_destroy(&tmp->port);
- kfree(tmp);
- }
-
- if (pci_registered)
- pci_unregister_driver(&pci_driver);
-}
-
-/*
- * Driver initialization entry point.
- */
-static int __init slgt_init(void)
-{
- int rc;
-
- serial_driver = tty_alloc_driver(MAX_DEVICES, TTY_DRIVER_REAL_RAW |
- TTY_DRIVER_DYNAMIC_DEV);
- if (IS_ERR(serial_driver)) {
- printk("%s can't allocate tty driver\n", driver_name);
- return PTR_ERR(serial_driver);
- }
-
- /* Initialize the tty_driver structure */
-
- serial_driver->driver_name = "synclink_gt";
- serial_driver->name = tty_dev_prefix;
- serial_driver->major = ttymajor;
- serial_driver->minor_start = 64;
- serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
- serial_driver->subtype = SERIAL_TYPE_NORMAL;
- serial_driver->init_termios = tty_std_termios;
- serial_driver->init_termios.c_cflag =
- B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- serial_driver->init_termios.c_ispeed = 9600;
- serial_driver->init_termios.c_ospeed = 9600;
- tty_set_operations(serial_driver, &ops);
- if ((rc = tty_register_driver(serial_driver)) < 0) {
- DBGERR(("%s can't register serial driver\n", driver_name));
- tty_driver_kref_put(serial_driver);
- serial_driver = NULL;
- goto error;
- }
-
- slgt_device_count = 0;
- if ((rc = pci_register_driver(&pci_driver)) < 0) {
- printk("%s pci_register_driver error=%d\n", driver_name, rc);
- goto error;
- }
- pci_registered = true;
-
- return 0;
-
-error:
- slgt_cleanup();
- return rc;
-}
-
-static void __exit slgt_exit(void)
-{
- slgt_cleanup();
-}
-
-module_init(slgt_init);
-module_exit(slgt_exit);
-
-/*
- * register access routines
- */
-
-static inline void __iomem *calc_regaddr(struct slgt_info *info,
- unsigned int addr)
-{
- void __iomem *reg_addr = info->reg_addr + addr;
-
- if (addr >= 0x80)
- reg_addr += info->port_num * 32;
- else if (addr >= 0x40)
- reg_addr += info->port_num * 16;
-
- return reg_addr;
-}
-
-static __u8 rd_reg8(struct slgt_info *info, unsigned int addr)
-{
- return readb(calc_regaddr(info, addr));
-}
-
-static void wr_reg8(struct slgt_info *info, unsigned int addr, __u8 value)
-{
- writeb(value, calc_regaddr(info, addr));
-}
-
-static __u16 rd_reg16(struct slgt_info *info, unsigned int addr)
-{
- return readw(calc_regaddr(info, addr));
-}
-
-static void wr_reg16(struct slgt_info *info, unsigned int addr, __u16 value)
-{
- writew(value, calc_regaddr(info, addr));
-}
-
-static __u32 rd_reg32(struct slgt_info *info, unsigned int addr)
-{
- return readl(calc_regaddr(info, addr));
-}
-
-static void wr_reg32(struct slgt_info *info, unsigned int addr, __u32 value)
-{
- writel(value, calc_regaddr(info, addr));
-}
-
-static void rdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, RDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, RDCSR) & BIT0))
- break;
-}
-
-static void tdma_reset(struct slgt_info *info)
-{
- unsigned int i;
-
- /* set reset bit */
- wr_reg32(info, TDCSR, BIT1);
-
- /* wait for enable bit cleared */
- for(i=0 ; i < 1000 ; i++)
- if (!(rd_reg32(info, TDCSR) & BIT0))
- break;
-}
-
-/*
- * enable internal loopback
- * TxCLK and RxCLK are generated from BRG
- * and TxD is looped back to RxD internally.
- */
-static void enable_loopback(struct slgt_info *info)
-{
- /* SCR (serial control) BIT2=loopback enable */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT2));
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* CCR (clock control)
- * 07..05 tx clock source (010 = BRG)
- * 04..02 rx clock source (010 = BRG)
- * 01 auxclk enable (0 = disable)
- * 00 BRG enable (1 = enable)
- *
- * 0100 1001
- */
- wr_reg8(info, CCR, 0x49);
-
- /* set speed if available, otherwise use default */
- if (info->params.clock_speed)
- set_rate(info, info->params.clock_speed);
- else
- set_rate(info, 3686400);
- }
-}
-
-/*
- * set baud rate generator to specified rate
- */
-static void set_rate(struct slgt_info *info, u32 rate)
-{
- unsigned int div;
- unsigned int osc = info->base_clock;
-
- /* div = osc/rate - 1
- *
- * Round div up if osc/rate is not integer to
- * force to next slowest rate.
- */
-
- if (rate) {
- div = osc/rate;
- if (!(osc % rate) && div)
- div--;
- wr_reg16(info, BDR, (unsigned short)div);
- }
-}
-
-static void rx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- /* disable and reset receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA + IRQ_RXIDLE);
-
- /* clear pending rx interrupts */
- wr_reg16(info, SSR, IRQ_RXIDLE + IRQ_RXOVER);
-
- rdma_reset(info);
-
- info->rx_enabled = false;
- info->rx_restart = false;
-}
-
-static void rx_start(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_RXOVER + IRQ_RXDATA);
-
- /* clear pending rx overrun IRQ */
- wr_reg16(info, SSR, IRQ_RXOVER);
-
- /* reset and disable receiver */
- val = rd_reg16(info, RCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, RCR, (unsigned short)(val | BIT2)); /* set reset bit */
- wr_reg16(info, RCR, val); /* clear reset bit */
-
- rdma_reset(info);
- reset_rbufs(info);
-
- if (info->rx_pio) {
- /* rx request when rx FIFO not empty */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
- slgt_irq_on(info, IRQ_RXDATA);
- if (info->params.mode == MGSL_MODE_ASYNC) {
- /* enable saving of rx status */
- wr_reg32(info, RDCSR, BIT6);
- }
- } else {
- /* rx request when rx FIFO half full */
- wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
- /* set 1st descriptor address */
- wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- /* enable rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT2 + BIT0));
- } else {
- /* enable saving of rx status, rx DMA and DMA interrupt */
- wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
- }
- }
-
- slgt_irq_on(info, IRQ_RXOVER);
-
- /* enable receiver */
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1));
-
- info->rx_restart = false;
- info->rx_enabled = true;
-}
-
-static void tx_start(struct slgt_info *info)
-{
- if (!info->tx_enabled) {
- wr_reg16(info, TCR,
- (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2));
- info->tx_enabled = true;
- }
-
- if (desc_count(info->tbufs[info->tbuf_start])) {
- info->drop_rts_on_tx_done = false;
-
- if (info->params.mode != MGSL_MODE_ASYNC) {
- if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
- get_gtsignals(info);
- if (!(info->signals & SerialSignal_RTS)) {
- info->signals |= SerialSignal_RTS;
- set_gtsignals(info);
- info->drop_rts_on_tx_done = true;
- }
- }
-
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE);
- /* clear tx idle and underrun status bits */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
- } else {
- slgt_irq_off(info, IRQ_TXDATA);
- slgt_irq_on(info, IRQ_TXIDLE);
- /* clear tx idle status bit */
- wr_reg16(info, SSR, IRQ_TXIDLE);
- }
- /* set 1st descriptor address and start DMA */
- wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
- wr_reg32(info, TDCSR, BIT2 + BIT0);
- info->tx_active = true;
- }
-}
-
-static void tx_stop(struct slgt_info *info)
-{
- unsigned short val;
-
- timer_delete(&info->tx_timer);
-
- tdma_reset(info);
-
- /* reset and disable transmitter */
- val = rd_reg16(info, TCR) & ~BIT1; /* clear enable bit */
- wr_reg16(info, TCR, (unsigned short)(val | BIT2)); /* set reset bit */
-
- slgt_irq_off(info, IRQ_TXDATA + IRQ_TXIDLE + IRQ_TXUNDER);
-
- /* clear tx idle and underrun status bit */
- wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
-
- reset_tbufs(info);
-
- info->tx_enabled = false;
- info->tx_active = false;
-}
-
-static void reset_port(struct slgt_info *info)
-{
- if (!info->reg_addr)
- return;
-
- tx_stop(info);
- rx_stop(info);
-
- info->signals &= ~(SerialSignal_RTS | SerialSignal_DTR);
- set_gtsignals(info);
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
-}
-
-static void reset_adapter(struct slgt_info *info)
-{
- int i;
- for (i=0; i < info->port_count; ++i) {
- if (info->port_array[i])
- reset_port(info->port_array[i]);
- }
-}
-
-static void async_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07 1=RTS driver control
- * 06 1=break enable
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 0=1 stop bit, 1=2 stop bits
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = 0x4000;
-
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.stop_bits != 1)
- val |= BIT3;
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* RCR (rx control)
- *
- * 15..13 mode, 010=async
- * 12..10 encoding, 000=NRZ
- * 09 parity enable
- * 08 1=odd parity, 0=even parity
- * 07..06 reserved, must be 0
- * 05..04 character length
- * 00=5 bits
- * 01=6 bits
- * 10=7 bits
- * 11=8 bits
- * 03 reserved, must be zero
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0x4000;
-
- if (info->params.parity != ASYNC_PARITY_NONE) {
- val |= BIT9;
- if (info->params.parity == ASYNC_PARITY_ODD)
- val |= BIT8;
- }
-
- switch (info->params.data_bits)
- {
- case 6: val |= BIT4; break;
- case 7: val |= BIT5; break;
- case 8: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 011 = tx clock source is BRG/16
- * 04..02 010 = rx clock source is BRG
- * 01 0 = auxclk disabled
- * 00 1 = BRG enabled
- *
- * 0110 1001
- */
- wr_reg8(info, CCR, 0x69);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 rx break on IRQ enable
- * 10 rx data IRQ enable
- * 09 rx break off IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 0=16x sampling, 1=8x sampling
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- val = BIT15 + BIT14 + BIT0;
- /* JCR[8] : 1 = x8 async mode feature available */
- if ((rd_reg32(info, JCR) & BIT8) && info->params.data_rate &&
- ((info->base_clock < (info->params.data_rate * 16)) ||
- (info->base_clock % (info->params.data_rate * 16)))) {
- /* use 8x sampling */
- val |= BIT3;
- set_rate(info, info->params.data_rate * 8);
- } else {
- /* use 16x sampling */
- set_rate(info, info->params.data_rate * 16);
- }
- wr_reg16(info, SCR, val);
-
- slgt_irq_on(info, IRQ_RXBREAK | IRQ_RXOVER);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-static void sync_mode(struct slgt_info *info)
-{
- unsigned short val;
-
- slgt_irq_off(info, IRQ_ALL | IRQ_MASTER);
- tx_stop(info);
- rx_stop(info);
-
- /* TCR (tx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07 1=RTS driver control
- * 06 preamble enable
- * 05..04 preamble length
- * 03 share open/close flag
- * 02 reset
- * 01 enable
- * 00 auto-CTS enable
- */
- val = BIT2;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
- if (info->if_mode & MGSL_INTERFACE_RTS_EN)
- val |= BIT7;
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE)
- val |= BIT6;
-
- switch (info->params.preamble_length)
- {
- case HDLC_PREAMBLE_LENGTH_16BITS: val |= BIT5; break;
- case HDLC_PREAMBLE_LENGTH_32BITS: val |= BIT4; break;
- case HDLC_PREAMBLE_LENGTH_64BITS: val |= BIT5 + BIT4; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_CTS)
- val |= BIT0;
-
- wr_reg16(info, TCR, val);
-
- /* TPR (transmit preamble) */
-
- switch (info->params.preamble)
- {
- case HDLC_PREAMBLE_PATTERN_FLAGS: val = 0x7e; break;
- case HDLC_PREAMBLE_PATTERN_ONES: val = 0xff; break;
- case HDLC_PREAMBLE_PATTERN_ZEROS: val = 0x00; break;
- case HDLC_PREAMBLE_PATTERN_10: val = 0x55; break;
- case HDLC_PREAMBLE_PATTERN_01: val = 0xaa; break;
- default: val = 0x7e; break;
- }
- wr_reg8(info, TPR, (unsigned char)val);
-
- /* RCR (rx control)
- *
- * 15..13 mode
- * 000=HDLC/SDLC
- * 001=raw bit synchronous
- * 010=asynchronous/isochronous
- * 011=monosync byte synchronous
- * 100=bisync byte synchronous
- * 101=xsync byte synchronous
- * 12..10 encoding
- * 09 CRC enable
- * 08 CRC32
- * 07..03 reserved, must be 0
- * 02 reset
- * 01 enable
- * 00 auto-DCD enable
- */
- val = 0;
-
- switch(info->params.mode) {
- case MGSL_MODE_XSYNC:
- val |= BIT15 + BIT13;
- break;
- case MGSL_MODE_MONOSYNC: val |= BIT14 + BIT13; break;
- case MGSL_MODE_BISYNC: val |= BIT15; break;
- case MGSL_MODE_RAW: val |= BIT13; break;
- }
-
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_NRZB: val |= BIT10; break;
- case HDLC_ENCODING_NRZI_MARK: val |= BIT11; break;
- case HDLC_ENCODING_NRZI: val |= BIT11 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_MARK: val |= BIT12; break;
- case HDLC_ENCODING_BIPHASE_SPACE: val |= BIT12 + BIT10; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: val |= BIT12 + BIT11; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: val |= BIT12 + BIT11 + BIT10; break;
- }
-
- switch (info->params.crc_type & HDLC_CRC_MASK)
- {
- case HDLC_CRC_16_CCITT: val |= BIT9; break;
- case HDLC_CRC_32_CCITT: val |= BIT9 + BIT8; break;
- }
-
- if (info->params.flags & HDLC_FLAG_AUTO_DCD)
- val |= BIT0;
-
- wr_reg16(info, RCR, val);
-
- /* CCR (clock control)
- *
- * 07..05 tx clock source
- * 04..02 rx clock source
- * 01 auxclk enable
- * 00 BRG enable
- */
- val = 0;
-
- if (info->params.flags & HDLC_FLAG_TXC_BRG)
- {
- // when RxC source is DPLL, BRG generates 16X DPLL
- // reference clock, so take TxC from BRG/16 to get
- // transmit clock at actual data rate
- if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT6 + BIT5; /* 011, txclk = BRG/16 */
- else
- val |= BIT6; /* 010, txclk = BRG */
- }
- else if (info->params.flags & HDLC_FLAG_TXC_DPLL)
- val |= BIT7; /* 100, txclk = DPLL Input */
- else if (info->params.flags & HDLC_FLAG_TXC_RXCPIN)
- val |= BIT5; /* 001, txclk = RXC Input */
-
- if (info->params.flags & HDLC_FLAG_RXC_BRG)
- val |= BIT3; /* 010, rxclk = BRG */
- else if (info->params.flags & HDLC_FLAG_RXC_DPLL)
- val |= BIT4; /* 100, rxclk = DPLL */
- else if (info->params.flags & HDLC_FLAG_RXC_TXCPIN)
- val |= BIT2; /* 001, rxclk = TXC Input */
-
- if (info->params.clock_speed)
- val |= BIT1 + BIT0;
-
- wr_reg8(info, CCR, (unsigned char)val);
-
- if (info->params.flags & (HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL))
- {
- // program DPLL mode
- switch(info->params.encoding)
- {
- case HDLC_ENCODING_BIPHASE_MARK:
- case HDLC_ENCODING_BIPHASE_SPACE:
- val = BIT7; break;
- case HDLC_ENCODING_BIPHASE_LEVEL:
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL:
- val = BIT7 + BIT6; break;
- default: val = BIT6; // NRZ encodings
- }
- wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | val));
-
- // DPLL requires a 16X reference clock from BRG
- set_rate(info, info->params.clock_speed * 16);
- }
- else
- set_rate(info, info->params.clock_speed);
-
- tx_set_idle(info);
-
- msc_set_vcr(info);
-
- /* SCR (serial control)
- *
- * 15 1=tx req on FIFO half empty
- * 14 1=rx req on FIFO half full
- * 13 tx data IRQ enable
- * 12 tx idle IRQ enable
- * 11 underrun IRQ enable
- * 10 rx data IRQ enable
- * 09 rx idle IRQ enable
- * 08 overrun IRQ enable
- * 07 DSR IRQ enable
- * 06 CTS IRQ enable
- * 05 DCD IRQ enable
- * 04 RI IRQ enable
- * 03 reserved, must be zero
- * 02 1=txd->rxd internal loopback enable
- * 01 reserved, must be zero
- * 00 1=master IRQ enable
- */
- wr_reg16(info, SCR, BIT15 + BIT14 + BIT0);
-
- if (info->params.loopback)
- enable_loopback(info);
-}
-
-/*
- * set transmit idle mode
- */
-static void tx_set_idle(struct slgt_info *info)
-{
- unsigned char val;
- unsigned short tcr;
-
- /* if preamble enabled (tcr[6] == 1) then tx idle size = 8 bits
- * else tcr[5:4] = tx idle size: 00 = 8 bits, 01 = 16 bits
- */
- tcr = rd_reg16(info, TCR);
- if (info->idle_mode & HDLC_TXIDLE_CUSTOM_16) {
- /* disable preamble, set idle size to 16 bits */
- tcr = (tcr & ~(BIT6 + BIT5)) | BIT4;
- /* MSB of 16 bit idle specified in tx preamble register (TPR) */
- wr_reg8(info, TPR, (unsigned char)((info->idle_mode >> 8) & 0xff));
- } else if (!(tcr & BIT6)) {
- /* preamble is disabled, set idle size to 8 bits */
- tcr &= ~(BIT5 + BIT4);
- }
- wr_reg16(info, TCR, tcr);
-
- if (info->idle_mode & (HDLC_TXIDLE_CUSTOM_8 | HDLC_TXIDLE_CUSTOM_16)) {
- /* LSB of custom tx idle specified in tx idle register */
- val = (unsigned char)(info->idle_mode & 0xff);
- } else {
- /* standard 8 bit idle patterns */
- switch(info->idle_mode)
- {
- case HDLC_TXIDLE_FLAGS: val = 0x7e; break;
- case HDLC_TXIDLE_ALT_ZEROS_ONES:
- case HDLC_TXIDLE_ALT_MARK_SPACE: val = 0xaa; break;
- case HDLC_TXIDLE_ZEROS:
- case HDLC_TXIDLE_SPACE: val = 0x00; break;
- default: val = 0xff;
- }
- }
-
- wr_reg8(info, TIR, val);
-}
-
-/*
- * get state of V24 status (input) signals
- */
-static void get_gtsignals(struct slgt_info *info)
-{
- unsigned short status = rd_reg16(info, SSR);
-
- /* clear all serial signals except RTS and DTR */
- info->signals &= SerialSignal_RTS | SerialSignal_DTR;
-
- if (status & BIT3)
- info->signals |= SerialSignal_DSR;
- if (status & BIT2)
- info->signals |= SerialSignal_CTS;
- if (status & BIT1)
- info->signals |= SerialSignal_DCD;
- if (status & BIT0)
- info->signals |= SerialSignal_RI;
-}
-
-/*
- * set V.24 Control Register based on current configuration
- */
-static void msc_set_vcr(struct slgt_info *info)
-{
- unsigned char val = 0;
-
- /* VCR (V.24 control)
- *
- * 07..04 serial IF select
- * 03 DTR
- * 02 RTS
- * 01 LL
- * 00 RL
- */
-
- switch(info->if_mode & MGSL_INTERFACE_MASK)
- {
- case MGSL_INTERFACE_RS232:
- val |= BIT5; /* 0010 */
- break;
- case MGSL_INTERFACE_V35:
- val |= BIT7 + BIT6 + BIT5; /* 1110 */
- break;
- case MGSL_INTERFACE_RS422:
- val |= BIT6; /* 0100 */
- break;
- }
-
- if (info->if_mode & MGSL_INTERFACE_MSB_FIRST)
- val |= BIT4;
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- if (info->if_mode & MGSL_INTERFACE_LL)
- val |= BIT1;
- if (info->if_mode & MGSL_INTERFACE_RL)
- val |= BIT0;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * set state of V24 control (output) signals
- */
-static void set_gtsignals(struct slgt_info *info)
-{
- unsigned char val = rd_reg8(info, VCR);
- if (info->signals & SerialSignal_DTR)
- val |= BIT3;
- else
- val &= ~BIT3;
- if (info->signals & SerialSignal_RTS)
- val |= BIT2;
- else
- val &= ~BIT2;
- wr_reg8(info, VCR, val);
-}
-
-/*
- * free range of receive DMA buffers (i to last)
- */
-static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last)
-{
- int done = 0;
-
- while(!done) {
- /* reset current buffer for reuse */
- info->rbufs[i].status = 0;
- set_desc_count(info->rbufs[i], info->rbuf_fill_level);
- if (i == last)
- done = 1;
- if (++i == info->rbuf_count)
- i = 0;
- }
- info->rbuf_current = i;
-}
-
-/*
- * mark all receive DMA buffers as free
- */
-static void reset_rbufs(struct slgt_info *info)
-{
- free_rbufs(info, 0, info->rbuf_count - 1);
- info->rbuf_fill_index = 0;
- info->rbuf_fill_count = 0;
-}
-
-/*
- * pass receive HDLC frame to upper layer
- *
- * return true if frame available, otherwise false
- */
-static bool rx_get_frame(struct slgt_info *info)
-{
- unsigned int start, end;
- unsigned short status;
- unsigned int framesize = 0;
- unsigned long flags;
- struct tty_struct *tty = info->port.tty;
- unsigned char addr_field = 0xff;
- unsigned int crc_size = 0;
-
- switch (info->params.crc_type & HDLC_CRC_MASK) {
- case HDLC_CRC_16_CCITT: crc_size = 2; break;
- case HDLC_CRC_32_CCITT: crc_size = 4; break;
- }
-
-check_again:
-
- framesize = 0;
- addr_field = 0xff;
- start = end = info->rbuf_current;
-
- for (;;) {
- if (!desc_complete(info->rbufs[end]))
- goto cleanup;
-
- if (framesize == 0 && info->params.addr_filter != 0xff)
- addr_field = info->rbufs[end].buf[0];
-
- framesize += desc_count(info->rbufs[end]);
-
- if (desc_eof(info->rbufs[end]))
- break;
-
- if (++end == info->rbuf_count)
- end = 0;
-
- if (end == info->rbuf_current) {
- if (info->rx_enabled){
- spin_lock_irqsave(&info->lock,flags);
- rx_start(info);
- spin_unlock_irqrestore(&info->lock,flags);
- }
- goto cleanup;
- }
- }
-
- /* status
- *
- * 15 buffer complete
- * 14..06 reserved
- * 05..04 residue
- * 02 eof (end of frame)
- * 01 CRC error
- * 00 abort
- */
- status = desc_status(info->rbufs[end]);
-
- /* ignore CRC bit if not using CRC (bit is undefined) */
- if ((info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_NONE)
- status &= ~BIT1;
-
- if (framesize == 0 ||
- (addr_field != 0xff && addr_field != info->params.addr_filter)) {
- free_rbufs(info, start, end);
- goto check_again;
- }
-
- if (framesize < (2 + crc_size) || status & BIT0) {
- info->icount.rxshort++;
- framesize = 0;
- } else if (status & BIT1) {
- info->icount.rxcrc++;
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX))
- framesize = 0;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (framesize == 0) {
- info->netdev->stats.rx_errors++;
- info->netdev->stats.rx_frame_errors++;
- }
-#endif
-
- DBGBH(("%s rx frame status=%04X size=%d\n",
- info->device_name, status, framesize));
- DBGDATA(info, info->rbufs[start].buf, min_t(int, framesize, info->rbuf_fill_level), "rx");
-
- if (framesize) {
- if (!(info->params.crc_type & HDLC_CRC_RETURN_EX)) {
- framesize -= crc_size;
- crc_size = 0;
- }
-
- if (framesize > info->max_frame_size + crc_size)
- info->icount.rxlong++;
- else {
- /* copy dma buffer(s) to contiguous temp buffer */
- int copy_count = framesize;
- int i = start;
- unsigned char *p = info->tmp_rbuf;
- info->tmp_rbuf_count = framesize;
-
- info->icount.rxok++;
-
- while(copy_count) {
- int partial_count = min_t(int, copy_count, info->rbuf_fill_level);
- memcpy(p, info->rbufs[i].buf, partial_count);
- p += partial_count;
- copy_count -= partial_count;
- if (++i == info->rbuf_count)
- i = 0;
- }
-
- if (info->params.crc_type & HDLC_CRC_RETURN_EX) {
- *p = (status & BIT1) ? RX_CRC_ERROR : RX_OK;
- framesize++;
- }
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_rx(info,info->tmp_rbuf, framesize);
- else
-#endif
- ldisc_receive_buf(tty, info->tmp_rbuf, NULL,
- framesize);
- }
- }
- free_rbufs(info, start, end);
- return true;
-
-cleanup:
- return false;
-}
-
-/*
- * pass receive buffer (RAW synchronous mode) to tty layer
- * return true if buffer available, otherwise false
- */
-static bool rx_get_buf(struct slgt_info *info)
-{
- unsigned int i = info->rbuf_current;
- unsigned int count;
-
- if (!desc_complete(info->rbufs[i]))
- return false;
- count = desc_count(info->rbufs[i]);
- switch(info->params.mode) {
- case MGSL_MODE_MONOSYNC:
- case MGSL_MODE_BISYNC:
- case MGSL_MODE_XSYNC:
- /* ignore residue in byte synchronous modes */
- if (desc_residue(info->rbufs[i]))
- count--;
- break;
- }
- DBGDATA(info, info->rbufs[i].buf, count, "rx");
- DBGINFO(("rx_get_buf size=%d\n", count));
- if (count)
- ldisc_receive_buf(info->port.tty, info->rbufs[i].buf, NULL,
- count);
- free_rbufs(info, i, i);
- return true;
-}
-
-static void reset_tbufs(struct slgt_info *info)
-{
- unsigned int i;
- info->tbuf_current = 0;
- for (i=0 ; i < info->tbuf_count ; i++) {
- info->tbufs[i].status = 0;
- info->tbufs[i].count = 0;
- }
-}
-
-/*
- * return number of free transmit DMA buffers
- */
-static unsigned int free_tbuf_count(struct slgt_info *info)
-{
- unsigned int count = 0;
- unsigned int i = info->tbuf_current;
-
- do
- {
- if (desc_count(info->tbufs[i]))
- break; /* buffer in use */
- ++count;
- if (++i == info->tbuf_count)
- i=0;
- } while (i != info->tbuf_current);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (count && (rd_reg32(info, TDCSR) & BIT0))
- --count;
-
- return count;
-}
-
-/*
- * return number of bytes in unsent transmit DMA buffers
- * and the serial controller tx FIFO
- */
-static unsigned int tbuf_bytes(struct slgt_info *info)
-{
- unsigned int total_count = 0;
- unsigned int i = info->tbuf_current;
- unsigned int reg_value;
- unsigned int count;
- unsigned int active_buf_count = 0;
-
- /*
- * Add descriptor counts for all tx DMA buffers.
- * If count is zero (cleared by DMA controller after read),
- * the buffer is complete or is actively being read from.
- *
- * Record buf_count of last buffer with zero count starting
- * from current ring position. buf_count is mirror
- * copy of count and is not cleared by serial controller.
- * If DMA controller is active, that buffer is actively
- * being read so add to total.
- */
- do {
- count = desc_count(info->tbufs[i]);
- if (count)
- total_count += count;
- else if (!total_count)
- active_buf_count = info->tbufs[i].buf_count;
- if (++i == info->tbuf_count)
- i = 0;
- } while (i != info->tbuf_current);
-
- /* read tx DMA status register */
- reg_value = rd_reg32(info, TDCSR);
-
- /* if tx DMA active, last zero count buffer is in use */
- if (reg_value & BIT0)
- total_count += active_buf_count;
-
- /* add tx FIFO count = reg_value[15..8] */
- total_count += (reg_value >> 8) & 0xff;
-
- /* if transmitter active add one byte for shift register */
- if (info->tx_active)
- total_count++;
-
- return total_count;
-}
-
-/*
- * load data into transmit DMA buffer ring and start transmitter if needed
- * return true if data accepted, otherwise false (buffers full)
- */
-static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int size)
-{
- unsigned short count;
- unsigned int i;
- struct slgt_desc *d;
-
- /* check required buffer space */
- if (DIV_ROUND_UP(size, DMABUFSIZE) > free_tbuf_count(info))
- return false;
-
- DBGDATA(info, buf, size, "tx");
-
- /*
- * copy data to one or more DMA buffers in circular ring
- * tbuf_start = first buffer for this data
- * tbuf_current = next free buffer
- *
- * Copy all data before making data visible to DMA controller by
- * setting descriptor count of the first buffer.
- * This prevents an active DMA controller from reading the first DMA
- * buffers of a frame and stopping before the final buffers are filled.
- */
-
- info->tbuf_start = i = info->tbuf_current;
-
- while (size) {
- d = &info->tbufs[i];
-
- count = (unsigned short)((size > DMABUFSIZE) ? DMABUFSIZE : size);
- memcpy(d->buf, buf, count);
-
- size -= count;
- buf += count;
-
- /*
- * set EOF bit for last buffer of HDLC frame or
- * for every buffer in raw mode
- */
- if ((!size && info->params.mode == MGSL_MODE_HDLC) ||
- info->params.mode == MGSL_MODE_RAW)
- set_desc_eof(*d, 1);
- else
- set_desc_eof(*d, 0);
-
- /* set descriptor count for all but first buffer */
- if (i != info->tbuf_start)
- set_desc_count(*d, count);
- d->buf_count = count;
-
- if (++i == info->tbuf_count)
- i = 0;
- }
-
- info->tbuf_current = i;
-
- /* set first buffer count to make new data visible to DMA controller */
- d = &info->tbufs[info->tbuf_start];
- set_desc_count(*d, d->buf_count);
-
- /* start transmitter if needed and update transmit timeout */
- if (!info->tx_active)
- tx_start(info);
- update_tx_timer(info);
-
- return true;
-}
-
-static int register_test(struct slgt_info *info)
-{
- static unsigned short patterns[] =
- {0x0000, 0xffff, 0xaaaa, 0x5555, 0x6969, 0x9696};
- static unsigned int count = ARRAY_SIZE(patterns);
- unsigned int i;
- int rc = 0;
-
- for (i=0 ; i < count ; i++) {
- wr_reg16(info, TIR, patterns[i]);
- wr_reg16(info, BDR, patterns[(i+1)%count]);
- if ((rd_reg16(info, TIR) != patterns[i]) ||
- (rd_reg16(info, BDR) != patterns[(i+1)%count])) {
- rc = -ENODEV;
- break;
- }
- }
- info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0;
- info->init_error = rc ? 0 : DiagStatus_AddressFailure;
- return rc;
-}
-
-static int irq_test(struct slgt_info *info)
-{
- unsigned long timeout;
- unsigned long flags;
- struct tty_struct *oldtty = info->port.tty;
- u32 speed = info->params.data_rate;
-
- info->params.data_rate = 921600;
- info->port.tty = NULL;
-
- spin_lock_irqsave(&info->lock, flags);
- async_mode(info);
- slgt_irq_on(info, IRQ_TXIDLE);
-
- /* enable transmitter */
- wr_reg16(info, TCR,
- (unsigned short)(rd_reg16(info, TCR) | BIT1));
-
- /* write one byte and wait for tx idle */
- wr_reg16(info, TDR, 0);
-
- /* assume failure */
- info->init_error = DiagStatus_IrqFailure;
- info->irq_occurred = false;
-
- spin_unlock_irqrestore(&info->lock, flags);
-
- timeout=100;
- while(timeout-- && !info->irq_occurred)
- msleep_interruptible(10);
-
- spin_lock_irqsave(&info->lock,flags);
- reset_port(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- info->params.data_rate = speed;
- info->port.tty = oldtty;
-
- info->init_error = info->irq_occurred ? 0 : DiagStatus_IrqFailure;
- return info->irq_occurred ? 0 : -ENODEV;
-}
-
-static int loopback_test_rx(struct slgt_info *info)
-{
- unsigned char *src, *dest;
- int count;
-
- if (desc_complete(info->rbufs[0])) {
- count = desc_count(info->rbufs[0]);
- src = info->rbufs[0].buf;
- dest = info->tmp_rbuf;
-
- for( ; count ; count-=2, src+=2) {
- /* src=data byte (src+1)=status byte */
- if (!(*(src+1) & (BIT9 + BIT8))) {
- *dest = *src;
- dest++;
- info->tmp_rbuf_count++;
- }
- }
- DBGDATA(info, info->tmp_rbuf, info->tmp_rbuf_count, "rx");
- return 1;
- }
- return 0;
-}
-
-static int loopback_test(struct slgt_info *info)
-{
-#define TESTFRAMESIZE 20
-
- unsigned long timeout;
- u16 count;
- unsigned char buf[TESTFRAMESIZE];
- int rc = -ENODEV;
- unsigned long flags;
-
- struct tty_struct *oldtty = info->port.tty;
- MGSL_PARAMS params;
-
- memcpy(¶ms, &info->params, sizeof(params));
-
- info->params.mode = MGSL_MODE_ASYNC;
- info->params.data_rate = 921600;
- info->params.loopback = 1;
- info->port.tty = NULL;
-
- /* build and send transmit frame */
- for (count = 0; count < TESTFRAMESIZE; ++count)
- buf[count] = (unsigned char)count;
-
- info->tmp_rbuf_count = 0;
- memset(info->tmp_rbuf, 0, TESTFRAMESIZE);
-
- /* program hardware for HDLC and enabled receiver */
- spin_lock_irqsave(&info->lock,flags);
- async_mode(info);
- rx_start(info);
- tx_load(info, buf, count);
- spin_unlock_irqrestore(&info->lock, flags);
-
- /* wait for receive complete */
- for (timeout = 100; timeout; --timeout) {
- msleep_interruptible(10);
- if (loopback_test_rx(info)) {
- rc = 0;
- break;
- }
- }
-
- /* verify received frame length and contents */
- if (!rc && (info->tmp_rbuf_count != count ||
- memcmp(buf, info->tmp_rbuf, count))) {
- rc = -ENODEV;
- }
-
- spin_lock_irqsave(&info->lock,flags);
- reset_adapter(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
- memcpy(&info->params, ¶ms, sizeof(info->params));
- info->port.tty = oldtty;
-
- info->init_error = rc ? DiagStatus_DmaFailure : 0;
- return rc;
-}
-
-static int adapter_test(struct slgt_info *info)
-{
- DBGINFO(("testing %s\n", info->device_name));
- if (register_test(info) < 0) {
- printk("register test failure %s addr=%08X\n",
- info->device_name, info->phys_reg_addr);
- } else if (irq_test(info) < 0) {
- printk("IRQ test failure %s IRQ=%d\n",
- info->device_name, info->irq_level);
- } else if (loopback_test(info) < 0) {
- printk("loopback test failure %s\n", info->device_name);
- }
- return info->init_error;
-}
-
-/*
- * transmit timeout handler
- */
-static void tx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, tx_timer);
- unsigned long flags;
-
- DBGINFO(("%s tx_timeout\n", info->device_name));
- if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
- info->icount.txtimeout++;
- }
- spin_lock_irqsave(&info->lock,flags);
- tx_stop(info);
- spin_unlock_irqrestore(&info->lock,flags);
-
-#if SYNCLINK_GENERIC_HDLC
- if (info->netcount)
- hdlcdev_tx_done(info);
- else
-#endif
- bh_transmit(info);
-}
-
-/*
- * receive buffer polling timer
- */
-static void rx_timeout(struct timer_list *t)
-{
- struct slgt_info *info = timer_container_of(info, t, rx_timer);
- unsigned long flags;
-
- DBGINFO(("%s rx_timeout\n", info->device_name));
- spin_lock_irqsave(&info->lock, flags);
- info->pending_bh |= BH_RECEIVE;
- spin_unlock_irqrestore(&info->lock, flags);
- bh_handler(&info->task);
-}
-
diff --git a/include/linux/synclink.h b/include/linux/synclink.h
deleted file mode 100644
index f1405b1c71ba..000000000000
--- a/include/linux/synclink.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SyncLink Multiprotocol Serial Adapter Driver
- *
- * $Id: synclink.h,v 3.14 2006/07/17 20:15:43 paulkf Exp $
- *
- * Copyright (C) 1998-2000 by Microgate Corporation
- *
- * Redistribution of this file is permitted under
- * the terms of the GNU Public License (GPL)
- */
-#ifndef _SYNCLINK_H_
-#define _SYNCLINK_H_
-
-#include <uapi/linux/synclink.h>
-
-/* provide 32 bit ioctl compatibility on 64 bit systems */
-#ifdef CONFIG_COMPAT
-#include <linux/compat.h>
-struct MGSL_PARAMS32 {
- compat_ulong_t mode;
- unsigned char loopback;
- unsigned short flags;
- unsigned char encoding;
- compat_ulong_t clock_speed;
- unsigned char addr_filter;
- unsigned short crc_type;
- unsigned char preamble_length;
- unsigned char preamble;
- compat_ulong_t data_rate;
- unsigned char data_bits;
- unsigned char stop_bits;
- unsigned char parity;
-};
-#define MGSL_IOCSPARAMS32 _IOW(MGSL_MAGIC_IOC,0,struct MGSL_PARAMS32)
-#define MGSL_IOCGPARAMS32 _IOR(MGSL_MAGIC_IOC,1,struct MGSL_PARAMS32)
-#endif
-#endif /* _SYNCLINK_H_ */
--
2.43.0
^ permalink raw reply related
* Re: [PATCH v2 02/15] serial: core: add uart_iotype_mmio/legacy_io helper functions
From: Maciej W. Rozycki @ 2026-05-02 23:25 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Hugo Villeneuve, Greg Kroah-Hartman, Jiri Slaby,
Ilpo Järvinen, linux-kernel, linux-serial, Hugo Villeneuve
In-Reply-To: <afNwaUf8esqaqxUe@black.igk.intel.com>
On Thu, 30 Apr 2026, Andy Shevchenko wrote:
> > +bool uart_iotype_legacy_io(enum uart_iotype iotype)
>
> Why do we use 'legacy'? Still in use in modern CPUs...
Deprecated in PCIe and not available in numerous systems. Also actually
called "legacy" in some serial port datasheets aged ~20 years now. While
some contemporary CPUs indeed retain the port I/O address space, it's for
legacy use anyway, you don't want to rely on it in new designs.
Maciej
^ permalink raw reply
* [syzbot] Monthly serial report (May 2026)
From: syzbot @ 2026-05-02 20:32 UTC (permalink / raw)
To: gregkh, linux-kernel, linux-serial, syzkaller-bugs
Hello serial maintainers/developers,
This is a 31-day syzbot report for the serial subsystem.
All related reports/information can be found at:
https://syzkaller.appspot.com/upstream/s/serial
During the period, 2 new issues were detected and 0 were fixed.
In total, 18 issues are still open and 48 have already been fixed.
Some of the still happening issues:
Ref Crashes Repro Title
<1> 3947 Yes possible deadlock in console_lock_spinning_enable (5)
https://syzkaller.appspot.com/bug?extid=622acb507894a48b2ce9
<2> 3513 Yes KMSAN: uninit-value in n_tty_receive_buf_standard
https://syzkaller.appspot.com/bug?extid=559c7fe4b8bac56d38c2
<3> 1194 Yes BUG: soft lockup in tx
https://syzkaller.appspot.com/bug?extid=5e87db90e68fbc4707c6
<4> 255 Yes INFO: task can't die in show_free_areas
https://syzkaller.appspot.com/bug?extid=8f41dccfb6c03cc36fd6
<5> 177 No possible deadlock in kbd_event
https://syzkaller.appspot.com/bug?extid=781c8bb5e4d62cc883d3
<6> 131 Yes possible deadlock in tty_buffer_flush (3)
https://syzkaller.appspot.com/bug?extid=52cf91760dcb1dac6376
<7> 61 No KMSAN: uninit-value in n_tty_lookahead_flow_ctrl (2)
https://syzkaller.appspot.com/bug?extid=290abdcd4f509377a0eb
<8> 10 No KASAN: slab-out-of-bounds Write in do_con_write (3)
https://syzkaller.appspot.com/bug?extid=8e9c1abac3ceb45abffe
---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
To disable reminders for individual bugs, reply with the following command:
#syz set <Ref> no-reminders
To change bug's subsystems, reply with:
#syz set <Ref> subsystems: new-subsystem
You may send multiple commands in a single email message.
^ permalink raw reply
* [PATCH v2 10/10] MIPS: DEC: Ensure RTC platform device deregistration upon failure
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Switch RTC platform device registration from platform_device_register()
to platform_add_devices() so as to make sure any failure will result in
automatic device deregistration.
Fixes: fae67ad43114 ("arch/mips/dec: switch DECstation systems to rtc-cmos")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
---
No change from v1 (8/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604110042130.29980@angie.orcam.me.uk/>.
---
arch/mips/dec/platform.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
linux-mips-dec-platform-rtc-unregister.diff
Index: linux-macro/arch/mips/dec/platform.c
===================================================================
--- linux-macro.orig/arch/mips/dec/platform.c
+++ linux-macro/arch/mips/dec/platform.c
@@ -38,6 +38,10 @@ static struct platform_device dec_rtc_de
.num_resources = ARRAY_SIZE(dec_rtc_resources),
};
+static struct platform_device *dec_rtc_devices[] __initdata = {
+ &dec_rtc_device,
+};
+
static struct resource dec_dz_resources[] = {
{ .name = "dz", .flags = IORESOURCE_MEM, },
{ .name = "dz", .flags = IORESOURCE_IRQ, },
@@ -137,7 +141,7 @@ static int __init dec_add_devices(void)
}
num_zs = i;
- ret1 = platform_device_register(&dec_rtc_device);
+ ret1 = platform_add_devices(dec_rtc_devices, 1);
ret2 = IS_ENABLED(CONFIG_32BIT) ?
platform_add_devices(dec_dz_devices, num_dz) : 0;
ret3 = platform_add_devices(dec_zs_devices, num_zs);
^ permalink raw reply
* [PATCH v2 09/10] serial: dz: Enable modular build
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Enable modular build since the driver now has a proper module_exit()
handler. There's nothing specific to DZ hardware to prevent driver
unloading and reloading from working.
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
---
No change from v1 (7/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604130133470.29980@angie.orcam.me.uk/>.
---
drivers/tty/serial/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
linux-serial-dz-module.diff
Index: linux-macro/drivers/tty/serial/Kconfig
===================================================================
--- linux-macro.orig/drivers/tty/serial/Kconfig
+++ linux-macro/drivers/tty/serial/Kconfig
@@ -335,7 +335,7 @@ config SERIAL_MAX310X
Say Y here if you want to support this ICs.
config SERIAL_DZ
- bool "DECstation DZ serial driver"
+ tristate "DECstation DZ serial driver"
depends on MACH_DECSTATION && 32BIT
select SERIAL_CORE
default y
^ permalink raw reply
* [PATCH v2 08/10] serial: zs: Convert to use a platform device
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Prevent a crash from happening as the first serial port is initialised:
Console: switching to mono frame buffer device 160x64
fb0: PMAG-AA frame buffer device at tc0
DECstation Z85C30 serial driver version 0.10
CPU 0 Unable to handle kernel paging request at virtual address 0000002c, epc == 803ab00c, ra == 803aafe0
Oops[#1]:
CPU: 0 PID: 1 Comm: swapper Not tainted 6.4.0-rc3-00031-g84a9582fd203-dirty #57
$ 0 : 00000000 10012c00 803aaeb0 00000000
$ 4 : 80e12f60 80e12f50 80e12f58 81000030
$ 8 : 00000000 805ff37c 00000000 33433538
$12 : 65732030 00000006 80c2915d 6c616972
$16 : 80e12f00 807b7630 00000000 00000000
$20 : 00000004 00000348 000001a0 807623b8
$24 : 00000018 00000000
$28 : 80c24000 80c25d60 8078b148 803aafe0
Hi : 00000000
Lo : 00000000
epc : 803ab00c serial_base_ctrl_add+0x78/0xf4
ra : 803aafe0 serial_base_ctrl_add+0x4c/0xf4
Status: 10012c03 KERNEL EXL IE
Cause : 00000008 (ExcCode 02)
BadVA : 0000002c
PrId : 00000440 (R4400SC)
Modules linked in:
Process swapper (pid: 1, threadinfo=(ptrval), task=(ptrval), tls=00000000)
Stack : 80760000 00000cc0 00400044 00400040 803aa02c 80d61ab8 00000000 807b7630
80760000 807623b8 807b7628 803aa644 80386998 00000000 80e17780 80220f68
80e17780 80d61ab8 80c17d80 80e17780 80e17780 8063c798 80e17780 80383fa0
00000010 80e17780 00000000 80386998 807a0000 00000000 00400040 8038f848
807623b8 80d61ab8 00000004 80e17780 00000000 803a68e4 80c25e2c 803bb884
...
Call Trace:
[<803ab00c>] serial_base_ctrl_add+0x78/0xf4
[<803aa644>] serial_core_register_port+0x174/0x69c
[<8077e9ac>] zs_init+0xc8/0xfc
[<800404d4>] do_one_initcall+0x40/0x2ac
[<8076cecc>] kernel_init_freeable+0x1e4/0x270
[<80605bec>] kernel_init+0x20/0x108
[<800431e8>] ret_from_kernel_thread+0x14/0x1c
Code: 2442aeb0 ae120024 ae0200d0 <8c67002c> 50e00001 8c670000 3c06806e 3c05806e afb30010
---[ end trace 0000000000000000 ]---
(report at the offending commit) -- where a pointer is dereferenced that
has been derived from a null pointer to the port's parent device.
Since no device is available with legacy probing and it's not anymore a
preferable way to discover devices anyway, switch the driver to using a
platform device and use it as the port's parent device. Update resource
handling accordingly and only request the actual span of addresses used
within the slot, which will have had its resource already requested by
generic platform device code.
Use platform_driver_probe() not just because SCC devices are fixed with
solder on board and not straightforward to remove, but foremost because
the associated TTY's major device number is the same as used by the dz
driver and the first driver to claim it will prevent the other one from
using it. Either one DZ device or some SCC devices will be present in a
given system but never both at a time, and therefore we want the major
device number to be claimed by the first driver to actually successfully
bind to its device and platform_driver_probe() is a way to fulfil that.
An unfortunate consequence of the switch to a platform device is we now
hand the console over from the bootconsole much later in the bootstrap.
The firmware console handler appears good enough though to work so late
and in particular with interrupts enabled.
Since there is one way only remaining to reach zs_reset() now, remove
the port initialisation marker as no longer needed and go through the
channel reset unconditionally.
Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # needs to use .remove_new for <= 6.10
---
No change from v1 (6/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604110034160.29980@angie.orcam.me.uk/>.
---
arch/mips/dec/platform.c | 60 ++++++++++++++-
drivers/tty/serial/zs.c | 184 +++++++++++++++++------------------------------
drivers/tty/serial/zs.h | 1
3 files changed, 125 insertions(+), 120 deletions(-)
linux-serial-zs-platform.diff
Index: linux-macro/arch/mips/dec/platform.c
===================================================================
--- linux-macro.orig/arch/mips/dec/platform.c
+++ linux-macro/arch/mips/dec/platform.c
@@ -13,6 +13,7 @@
#include <asm/bootinfo.h>
#include <asm/dec/interrupts.h>
+#include <asm/dec/ioasic_addrs.h>
#include <asm/dec/kn01.h>
#include <asm/dec/kn02.h>
#include <asm/dec/system.h>
@@ -53,10 +54,37 @@ static struct platform_device *dec_dz_de
&dec_dz_device,
};
+static struct resource dec_zs_resources[][2] = {
+ {
+ { .name = "scc0", .flags = IORESOURCE_MEM, },
+ { .name = "scc0", .flags = IORESOURCE_IRQ, },
+ },
+ {
+ { .name = "scc1", .flags = IORESOURCE_MEM, },
+ { .name = "scc1", .flags = IORESOURCE_IRQ, },
+ },
+};
+
+static struct platform_device dec_zs_device[] = {
+ {
+ .name = "zs",
+ .id = 0,
+ .resource = dec_zs_resources[0],
+ .num_resources = ARRAY_SIZE(dec_zs_resources[0]),
+ },
+ {
+ .name = "zs",
+ .id = 1,
+ .resource = dec_zs_resources[1],
+ .num_resources = ARRAY_SIZE(dec_zs_resources[1]),
+ },
+};
+
static int __init dec_add_devices(void)
{
- int ret1, ret2;
- int num_dz;
+ struct platform_device *dec_zs_devices[ARRAY_SIZE(dec_zs_device)];
+ int ret1, ret2, ret3;
+ int num_dz, num_zs;
int irq, i;
dec_rtc_resources[0].start = RTC_PORT(0);
@@ -84,10 +112,36 @@ static int __init dec_add_devices(void)
}
num_dz = i;
+ i = 0;
+ irq = dec_interrupt[DEC_IRQ_SCC0];
+ if (irq >= 0) {
+ resource_size_t base = dec_kn_slot_base + IOASIC_SCC0;
+
+ dec_zs_device[i].resource[0].start = base;
+ dec_zs_device[i].resource[0].end = base + dec_kn_slot_size - 1;
+ dec_zs_device[i].resource[1].start = irq;
+ dec_zs_device[i].resource[1].end = irq;
+ dec_zs_devices[i] = &dec_zs_device[i];
+ i++;
+ }
+ irq = dec_interrupt[DEC_IRQ_SCC1];
+ if (irq >= 0) {
+ resource_size_t base = dec_kn_slot_base + IOASIC_SCC1;
+
+ dec_zs_device[i].resource[0].start = base;
+ dec_zs_device[i].resource[0].end = base + dec_kn_slot_size - 1;
+ dec_zs_device[i].resource[1].start = irq;
+ dec_zs_device[i].resource[1].end = irq;
+ dec_zs_devices[i] = &dec_zs_device[i];
+ i++;
+ }
+ num_zs = i;
+
ret1 = platform_device_register(&dec_rtc_device);
ret2 = IS_ENABLED(CONFIG_32BIT) ?
platform_add_devices(dec_dz_devices, num_dz) : 0;
- return ret1 ? ret1 : ret2;
+ ret3 = platform_add_devices(dec_zs_devices, num_zs);
+ return ret1 ? ret1 : ret2 ? ret2 : ret3;
}
device_initcall(dec_add_devices);
Index: linux-macro/drivers/tty/serial/zs.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/zs.c
+++ linux-macro/drivers/tty/serial/zs.c
@@ -56,6 +56,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/major.h>
+#include <linux/platform_device.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
#include <linux/spinlock.h>
@@ -66,10 +67,6 @@
#include <linux/atomic.h>
-#include <asm/dec/interrupts.h>
-#include <asm/dec/ioasic_addrs.h>
-#include <asm/dec/system.h>
-
#include "zs.h"
@@ -79,7 +76,7 @@ MODULE_LICENSE("GPL");
static char zs_name[] __initdata = "DECstation Z85C30 serial driver version ";
-static char zs_version[] __initdata = "0.10";
+static char zs_version[] __initdata = "0.11";
/*
* It would be nice to dynamically allocate everything that
@@ -98,12 +95,8 @@ static char zs_version[] __initdata = "0
#define to_zport(uport) container_of(uport, struct zs_port, port)
-struct zs_parms {
- resource_size_t scc[ZS_NUM_SCCS];
- int irq[ZS_NUM_SCCS];
-};
-
static struct zs_scc zs_sccs[ZS_NUM_SCCS];
+static struct uart_driver zs_reg;
/*
* Set parameters in WR5, WR12, WR13 such as not to interfere
@@ -839,16 +832,15 @@ static void zs_reset(struct zs_port *zpo
spin_lock_irqsave(&scc->zlock, flags);
irq = !irqs_disabled_flags(flags);
- if (!zport->initialised) {
- /* Reset the pointer first, just in case... */
- read_zsreg(zport, R0);
- /* And let the current transmission finish. */
- zs_line_drain(zport, irq);
- write_zsreg(zport, R9, zport == zport_a ? CHRA : CHRB);
- udelay(10);
- write_zsreg(zport, R9, 0);
- zport->initialised = 1;
- }
+
+ /* Reset the pointer first, just in case... */
+ read_zsreg(zport, R0);
+ /* And let the current transmission finish. */
+ zs_line_drain(zport, irq);
+ write_zsreg(zport, R9, zport == zport_a ? CHRA : CHRB);
+ udelay(10);
+ write_zsreg(zport, R9, 0);
+
load_zsregs(zport, zport->regs, irq);
spin_unlock_irqrestore(&scc->zlock, flags);
}
@@ -1055,63 +1047,62 @@ static const struct uart_ops zs_ops = {
/*
* Initialize Z85C30 port structures.
*/
-static int __init zs_probe_sccs(void)
+static int __init zs_probe(struct platform_device *pdev)
{
- static int probed;
- struct zs_parms zs_parms;
- int chip, side, irq;
- int n_chips = 0;
+ struct resource *mem_resource, *irq_resource;
+ int chip, side;
int i;
- if (probed)
- return 0;
-
- irq = dec_interrupt[DEC_IRQ_SCC0];
- if (irq >= 0) {
- zs_parms.scc[n_chips] = IOASIC_SCC0;
- zs_parms.irq[n_chips] = dec_interrupt[DEC_IRQ_SCC0];
- n_chips++;
- }
- irq = dec_interrupt[DEC_IRQ_SCC1];
- if (irq >= 0) {
- zs_parms.scc[n_chips] = IOASIC_SCC1;
- zs_parms.irq[n_chips] = dec_interrupt[DEC_IRQ_SCC1];
- n_chips++;
- }
- if (!n_chips)
- return -ENXIO;
+ mem_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ irq_resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+ if (!mem_resource || !irq_resource)
+ return -ENODEV;
- probed = 1;
+ chip = pdev->id;
+ spin_lock_init(&zs_sccs[chip].zlock);
+ for (side = 0; side < ZS_NUM_CHAN; side++) {
+ struct zs_port *zport = &zs_sccs[chip].zport[side];
+ struct uart_port *uport = &zport->port;
- for (chip = 0; chip < n_chips; chip++) {
- spin_lock_init(&zs_sccs[chip].zlock);
- for (side = 0; side < ZS_NUM_CHAN; side++) {
- struct zs_port *zport = &zs_sccs[chip].zport[side];
- struct uart_port *uport = &zport->port;
+ zport->scc = &zs_sccs[chip];
+ zport->clk_mode = 16;
- zport->scc = &zs_sccs[chip];
- zport->clk_mode = 16;
+ uport->dev = &pdev->dev;
+ uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ZS_CONSOLE);
+ uport->irq = irq_resource->start;
+ uport->uartclk = ZS_CLOCK;
+ uport->fifosize = 1;
+ uport->iotype = UPIO_MEM;
+ uport->flags = UPF_BOOT_AUTOCONF;
+ uport->ops = &zs_ops;
+ uport->line = chip * ZS_NUM_CHAN + side;
+ uport->mapbase = mem_resource->start +
+ (side ^ ZS_CHAN_B) * ZS_CHAN_IO_SIZE;
- uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ZS_CONSOLE);
- uport->irq = zs_parms.irq[chip];
- uport->uartclk = ZS_CLOCK;
- uport->fifosize = 1;
- uport->iotype = UPIO_MEM;
- uport->flags = UPF_BOOT_AUTOCONF;
- uport->ops = &zs_ops;
- uport->line = chip * ZS_NUM_CHAN + side;
- uport->mapbase = dec_kn_slot_base +
- zs_parms.scc[chip] +
- (side ^ ZS_CHAN_B) * ZS_CHAN_IO_SIZE;
+ for (i = 0; i < ZS_NUM_REGS; i++)
+ zport->regs[i] = zs_init_regs[i];
- for (i = 0; i < ZS_NUM_REGS; i++)
- zport->regs[i] = zs_init_regs[i];
- }
+ if (uart_add_one_port(&zs_reg, uport))
+ uport->dev = NULL;
}
return 0;
}
+static void __exit zs_remove(struct platform_device *pdev)
+{
+ int chip, side;
+
+ chip = pdev->id;
+ for (side = ZS_NUM_CHAN - 1; side >= 0; side--) {
+ struct zs_port *zport = &zs_sccs[chip].zport[side];
+ struct uart_port *uport = &zport->port;
+
+ if (uport->dev)
+ uart_remove_one_port(&zs_reg, uport);
+ }
+}
+
#ifdef CONFIG_SERIAL_ZS_CONSOLE
static void zs_console_putchar(struct uart_port *uport, unsigned char ch)
@@ -1192,20 +1183,14 @@ static int __init zs_console_setup(struc
int bits = 8;
int parity = 'n';
int flow = 'n';
- int ret;
-
- ret = zs_map_port(uport);
- if (ret)
- return ret;
-
- zs_reset(zport);
+ if (!zport->scc)
+ return -ENODEV;
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
return uart_set_options(uport, co, baud, parity, bits, flow);
}
-static struct uart_driver zs_reg;
static struct console zs_console = {
.name = "ttyS",
.write = zs_console_write,
@@ -1216,23 +1201,6 @@ static struct console zs_console = {
.data = &zs_reg,
};
-/*
- * Register console.
- */
-static int __init zs_serial_console_init(void)
-{
- int ret;
-
- ret = zs_probe_sccs();
- if (ret)
- return ret;
- register_console(&zs_console);
-
- return 0;
-}
-
-console_initcall(zs_serial_console_init);
-
#define SERIAL_ZS_CONSOLE &zs_console
#else
#define SERIAL_ZS_CONSOLE NULL
@@ -1248,47 +1216,31 @@ static struct uart_driver zs_reg = {
.cons = SERIAL_ZS_CONSOLE,
};
+static struct platform_driver zs_driver = {
+ .remove = __exit_p(zs_remove),
+ .driver = { .name = "zs" },
+};
+
/* zs_init inits the driver. */
static int __init zs_init(void)
{
- int i, ret;
+ int ret;
pr_info("%s%s\n", zs_name, zs_version);
- /* Find out how many Z85C30 SCCs we have. */
- ret = zs_probe_sccs();
- if (ret)
- return ret;
-
ret = uart_register_driver(&zs_reg);
if (ret)
return ret;
+ ret = platform_driver_probe(&zs_driver, zs_probe);
+ if (ret)
+ uart_unregister_driver(&zs_reg);
- for (i = 0; i < ZS_NUM_SCCS * ZS_NUM_CHAN; i++) {
- struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
- struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
- struct uart_port *uport = &zport->port;
-
- if (zport->scc)
- uart_add_one_port(&zs_reg, uport);
- }
-
- return 0;
+ return ret;
}
static void __exit zs_exit(void)
{
- int i;
-
- for (i = ZS_NUM_SCCS * ZS_NUM_CHAN - 1; i >= 0; i--) {
- struct zs_scc *scc = &zs_sccs[i / ZS_NUM_CHAN];
- struct zs_port *zport = &scc->zport[i % ZS_NUM_CHAN];
- struct uart_port *uport = &zport->port;
-
- if (zport->scc)
- uart_remove_one_port(&zs_reg, uport);
- }
-
+ platform_driver_unregister(&zs_driver);
uart_unregister_driver(&zs_reg);
}
Index: linux-macro/drivers/tty/serial/zs.h
===================================================================
--- linux-macro.orig/drivers/tty/serial/zs.h
+++ linux-macro/drivers/tty/serial/zs.h
@@ -22,7 +22,6 @@
struct zs_port {
struct zs_scc *scc; /* Containing SCC. */
struct uart_port port; /* Underlying UART. */
- int initialised; /* For the console port. */
int clk_mode; /* May be 1, 16, 32, or 64. */
^ permalink raw reply
* [PATCH v2 07/10] serial: dz: Convert to use a platform device
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Prevent a crash from happening as the first serial port is initialised:
Console: switching to colour frame buffer device 160x64
tgafb: SFB+ detected, rev=0x02
fb0: Digital ZLX-E1 frame buffer device at 0x1e000000
DECstation DZ serial driver version 1.04
CPU 0 Unable to handle kernel paging request at virtual address 000000bc, epc == 8048b3a4, ra == 80470a78
Oops[#1]:
CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.19.0-dirty #35 NONE
$ 0 : 00000000 1000ac00 00000004 804707ac
$ 4 : 00000000 80e20850 80e20858 81000030
$ 8 : 00000000 8072c81c 00000008 fefefeff
$12 : 6c616972 00000006 80c5917f 69726420
$16 : 80e20800 00000000 808f8968 80e20800
$20 : 00000000 807f5a90 808b0094 808d3bc8
$24 : 00000018 80479030
$28 : 80c2e000 80c2fd70 00000069 80470a78
Hi : 00000004
Lo : 00000000
epc : 8048b3a4 __dev_fwnode+0x0/0xc
ra : 80470a78 serial_base_ctrl_add+0xa0/0x168
Status: 1000ac04 IEp
Cause : 30000008 (ExcCode 02)
BadVA : 000000bc
PrId : 00000220 (R3000)
Modules linked in:
Process swapper/0 (pid: 1, threadinfo=(ptrval), task=(ptrval), tls=00000000)
Stack : 00400044 00400040 8046f4cc 00000000 808a6148 808a0000 808f8968 8086983c
808e0000 8046fc84 1000ac01 00000028 80e20700 802ba3f8 80e20700 80d34a94
80c1b900 80e20700 80e20700 80e20700 80e20700 80444650 00000000 00000000
00000000 807f5a90 808b0094 80447080 00400040 808e0000 80d34a94 808a6148
80d34a94 00000004 80e20700 00000000 8076974c 80469810 80c2fe3c 1000ac01
...
Call Trace:
[<8048b3a4>] __dev_fwnode+0x0/0xc
[<80470a78>] serial_base_ctrl_add+0xa0/0x168
[<8046fc84>] serial_core_register_port+0x1c8/0x974
[<808c6af0>] dz_init+0x74/0xc8
[<800470e0>] do_one_initcall+0x44/0x2d4
[<808b111c>] kernel_init_freeable+0x258/0x308
[<8072e434>] kernel_init+0x20/0x114
[<80049cd0>] ret_from_kernel_thread+0x14/0x1c
Code: 27bd0018 03e00008 2402ffea <8c8200bc> 03e00008 00000000 27bdffc0 afbe0038 afb30024
---[ end trace 0000000000000000 ]---
-- where a pointer is dereferenced that has been derived from a null
pointer to the port's parent device.
Since no device is available with legacy probing and it's not anymore a
preferable way to discover devices anyway, switch the driver to using a
platform device and use it as the port's parent device. Update resource
handling accordingly and only request the actual span of addresses used
within the slot, which will have had its resource already requested by
generic platform device code.
Use platform_driver_probe() not just because the DZ device is fixed with
solder on board and not straightforward to remove, but foremost because
the associated TTY's major device number is the same as used by the zs
driver and the first driver to claim it will prevent the other one from
using it. Either one DZ device or some SCC devices will be present in a
given system but never both at a time, and therefore we want the major
device number to be claimed by the first driver to actually successfully
bind to its device and platform_driver_probe() is a way to fulfil that.
An unfortunate consequence of the switch to a platform device is we now
hand the console over from the bootconsole much later in the bootstrap.
The firmware console handler appears good enough though to work so late
and in particular with interrupts enabled.
Conversely only starting the console port so late lets the reset code
fully utilise our delay handlers, so switch from udelay() to fsleep()
for transmitter draining so as to avoid busy-waiting for an excessive
amount of time.
Fixes: 84a9582fd203 ("serial: core: Start managing serial controllers to enable runtime PM")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # needs to use .remove_new for <= 6.10
---
No change from v1 (5/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604102351280.29980@angie.orcam.me.uk/>.
---
arch/mips/dec/platform.c | 55 +++++++++++++++++++++-
drivers/tty/serial/dz.c | 116 ++++++++++++++++++++++-------------------------
2 files changed, 110 insertions(+), 61 deletions(-)
linux-serial-dz-platform.diff
Index: linux-macro/arch/mips/dec/platform.c
===================================================================
--- linux-macro.orig/arch/mips/dec/platform.c
+++ linux-macro/arch/mips/dec/platform.c
@@ -10,6 +10,13 @@
#include <linux/mc146818rtc.h>
#include <linux/platform_device.h>
+#include <asm/bootinfo.h>
+
+#include <asm/dec/interrupts.h>
+#include <asm/dec/kn01.h>
+#include <asm/dec/kn02.h>
+#include <asm/dec/system.h>
+
static struct resource dec_rtc_resources[] = {
{
.name = "rtc",
@@ -30,11 +37,57 @@ static struct platform_device dec_rtc_de
.num_resources = ARRAY_SIZE(dec_rtc_resources),
};
+static struct resource dec_dz_resources[] = {
+ { .name = "dz", .flags = IORESOURCE_MEM, },
+ { .name = "dz", .flags = IORESOURCE_IRQ, },
+};
+
+static struct platform_device dec_dz_device = {
+ .name = "dz",
+ .id = PLATFORM_DEVID_NONE,
+ .resource = dec_dz_resources,
+ .num_resources = ARRAY_SIZE(dec_dz_resources),
+};
+
+static struct platform_device *dec_dz_devices[] __initdata = {
+ &dec_dz_device,
+};
+
static int __init dec_add_devices(void)
{
+ int ret1, ret2;
+ int num_dz;
+ int irq, i;
+
dec_rtc_resources[0].start = RTC_PORT(0);
dec_rtc_resources[0].end = RTC_PORT(0) + dec_kn_slot_size - 1;
- return platform_device_register(&dec_rtc_device);
+
+ i = 0;
+ irq = dec_interrupt[DEC_IRQ_DZ11];
+ if (IS_ENABLED(CONFIG_32BIT) && irq >= 0) {
+ resource_size_t base;
+
+ switch (mips_machtype) {
+ case MACH_DS23100:
+ case MACH_DS5100:
+ base = dec_kn_slot_base + KN01_DZ11;
+ break;
+ default:
+ base = dec_kn_slot_base + KN02_DZ11;
+ break;
+ }
+ dec_dz_device.resource[0].start = base;
+ dec_dz_device.resource[0].end = base + dec_kn_slot_size - 1;
+ dec_dz_device.resource[1].start = irq;
+ dec_dz_device.resource[1].end = irq;
+ i++;
+ }
+ num_dz = i;
+
+ ret1 = platform_device_register(&dec_rtc_device);
+ ret2 = IS_ENABLED(CONFIG_32BIT) ?
+ platform_add_devices(dec_dz_devices, num_dz) : 0;
+ return ret1 ? ret1 : ret2;
}
device_initcall(dec_add_devices);
Index: linux-macro/drivers/tty/serial/dz.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/dz.c
+++ linux-macro/drivers/tty/serial/dz.c
@@ -40,6 +40,7 @@
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/module.h>
+#include <linux/platform_device.h>
#include <linux/serial.h>
#include <linux/serial_core.h>
#include <linux/sysrq.h>
@@ -48,14 +49,6 @@
#include <linux/atomic.h>
#include <linux/io.h>
-#include <asm/bootinfo.h>
-
-#include <asm/dec/interrupts.h>
-#include <asm/dec/kn01.h>
-#include <asm/dec/kn02.h>
-#include <asm/dec/machtype.h>
-#include <asm/dec/prom.h>
-#include <asm/dec/system.h>
#include "dz.h"
@@ -65,7 +58,9 @@ MODULE_LICENSE("GPL");
static char dz_name[] __initdata = "DECstation DZ serial driver version ";
-static char dz_version[] __initdata = "1.04";
+static char dz_version[] __initdata = "1.05";
+
+#define DZ_IO_SIZE 0x20 /* IOMEM space size. */
struct dz_port {
struct dz_mux *mux;
@@ -81,6 +76,7 @@ struct dz_mux {
};
static struct dz_mux dz_mux;
+static struct uart_driver dz_reg;
static inline struct dz_port *to_dport(struct uart_port *uport)
{
@@ -564,7 +560,7 @@ static void dz_reset(struct dz_port *dpo
iob();
udelay(2); /* 1.4us TRDY recovery. */
}
- udelay(1200); /* Transmitter drain. */
+ fsleep(1200); /* Transmitter drain. */
}
dz_out(dport, DZ_CSR, DZ_CLR);
@@ -681,14 +677,13 @@ static void dz_release_port(struct uart_
map_guard = atomic_add_return(-1, &mux->map_guard);
if (!map_guard)
- release_mem_region(uport->mapbase, dec_kn_slot_size);
+ release_mem_region(uport->mapbase, DZ_IO_SIZE);
}
static int dz_map_port(struct uart_port *uport)
{
if (!uport->membase)
- uport->membase = ioremap(uport->mapbase,
- dec_kn_slot_size);
+ uport->membase = ioremap(uport->mapbase, DZ_IO_SIZE);
if (!uport->membase) {
printk(KERN_ERR "dz: Cannot map MMIO\n");
return -ENOMEM;
@@ -704,8 +699,7 @@ static int dz_request_port(struct uart_p
map_guard = atomic_add_return(1, &mux->map_guard);
if (map_guard == 1) {
- if (!request_mem_region(uport->mapbase, dec_kn_slot_size,
- "dz")) {
+ if (!request_mem_region(uport->mapbase, DZ_IO_SIZE, "dz")) {
atomic_add(-1, &mux->map_guard);
printk(KERN_ERR
"dz: Unable to reserve MMIO resource\n");
@@ -716,7 +710,7 @@ static int dz_request_port(struct uart_p
if (ret) {
map_guard = atomic_add_return(-1, &mux->map_guard);
if (!map_guard)
- release_mem_region(uport->mapbase, dec_kn_slot_size);
+ release_mem_region(uport->mapbase, DZ_IO_SIZE);
return ret;
}
return 0;
@@ -768,20 +762,15 @@ static const struct uart_ops dz_ops = {
.verify_port = dz_verify_port,
};
-static void __init dz_init_ports(void)
+static int __init dz_probe(struct platform_device *pdev)
{
- static int first = 1;
- unsigned long base;
+ struct resource *mem_resource, *irq_resource;
int line;
- if (!first)
- return;
- first = 0;
-
- if (mips_machtype == MACH_DS23100 || mips_machtype == MACH_DS5100)
- base = dec_kn_slot_base + KN01_DZ11;
- else
- base = dec_kn_slot_base + KN02_DZ11;
+ mem_resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ irq_resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+ if (!mem_resource || !irq_resource)
+ return -ENODEV;
for (line = 0; line < DZ_NB_PORT; line++) {
struct dz_port *dport = &dz_mux.dport[line];
@@ -789,14 +778,33 @@ static void __init dz_init_ports(void)
dport->mux = &dz_mux;
- uport->irq = dec_interrupt[DEC_IRQ_DZ11];
+ uport->dev = &pdev->dev;
+ uport->irq = irq_resource->start;
uport->fifosize = 1;
uport->iotype = UPIO_MEM;
uport->flags = UPF_BOOT_AUTOCONF;
uport->ops = &dz_ops;
uport->line = line;
- uport->mapbase = base;
+ uport->mapbase = mem_resource->start;
uport->has_sysrq = IS_ENABLED(CONFIG_SERIAL_DZ_CONSOLE);
+
+ if (uart_add_one_port(&dz_reg, uport))
+ uport->dev = NULL;
+ }
+
+ return 0;
+}
+
+static void __exit dz_remove(struct platform_device *pdev)
+{
+ int line;
+
+ for (line = DZ_NB_PORT - 1; line >= 0; line--) {
+ struct dz_port *dport = &dz_mux.dport[line];
+ struct uart_port *uport = &dport->port;
+
+ if (uport->dev)
+ uart_remove_one_port(&dz_reg, uport);
}
}
@@ -879,21 +887,14 @@ static int __init dz_console_setup(struc
int bits = 8;
int parity = 'n';
int flow = 'n';
- int ret;
-
- ret = dz_map_port(uport);
- if (ret)
- return ret;
-
- dz_reset(dport);
+ if (!dport->mux)
+ return -ENODEV;
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
-
- return uart_set_options(&dport->port, co, baud, parity, bits, flow);
+ return uart_set_options(uport, co, baud, parity, bits, flow);
}
-static struct uart_driver dz_reg;
static struct console dz_console = {
.name = "ttyS",
.write = dz_console_print,
@@ -904,18 +905,6 @@ static struct console dz_console = {
.data = &dz_reg,
};
-static int __init dz_serial_console_init(void)
-{
- if (!IOASIC) {
- dz_init_ports();
- register_console(&dz_console);
- return 0;
- } else
- return -ENXIO;
-}
-
-console_initcall(dz_serial_console_init);
-
#define SERIAL_DZ_CONSOLE &dz_console
#else
#define SERIAL_DZ_CONSOLE NULL
@@ -931,25 +920,32 @@ static struct uart_driver dz_reg = {
.cons = SERIAL_DZ_CONSOLE,
};
+static struct platform_driver dz_driver = {
+ .remove = __exit_p(dz_remove),
+ .driver = { .name = "dz" },
+};
+
static int __init dz_init(void)
{
- int ret, i;
-
- if (IOASIC)
- return -ENXIO;
+ int ret;
printk("%s%s\n", dz_name, dz_version);
- dz_init_ports();
-
ret = uart_register_driver(&dz_reg);
if (ret)
return ret;
+ ret = platform_driver_probe(&dz_driver, dz_probe);
+ if (ret)
+ uart_unregister_driver(&dz_reg);
- for (i = 0; i < DZ_NB_PORT; i++)
- uart_add_one_port(&dz_reg, &dz_mux.dport[i].port);
+ return ret;
+}
- return 0;
+static void __exit dz_exit(void)
+{
+ platform_driver_unregister(&dz_driver);
+ uart_unregister_driver(&dz_reg);
}
module_init(dz_init);
+module_exit(dz_exit);
^ permalink raw reply
* [PATCH v2 06/10] serial: zs: Switch to using channel reset
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Switch the driver to using the channel reset rather than hardware reset,
simplifying handling by removing an interference between channels that
causes the other channel to become uninitialised afterwards.
There is little difference between the two kinds of reset in terms of
register settings that result, and we initialise the whole register set
right away anyway. However this prevents a hang from happening should
the console output handler in the firmware try to access the other port
whose transmitter has been disabled and line parameters messed up.
For example this will happen if the keyboard port (port A) is chosen for
the system console, unusually but not insanely for a headless system, as
the port is wired to a standard DA-15 connector and an adapter can be
easily made. Or with the next change in place this would happen for the
regular console port (port B), since the keyboard port (port A) will be
initialised first.
Just remove the unnecessary complication then, a channel reset is good
enough. We still need the initialisation marker, now per channel rather
than per SCC, as for the console port zs_reset() will be called twice:
once early on via zs_serial_console_init() for the console setup only,
and then again via zs_config_port() as the port is associated with a TTY
device.
Fixes: 8b4a40809e53 ("zs: move to the serial subsystem")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.23+
---
No change from v1 (4/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604122134330.29980@angie.orcam.me.uk/>.
---
drivers/tty/serial/zs.c | 7 ++++---
drivers/tty/serial/zs.h | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
linux-serial-zs-reset-channel.diff
Index: linux-macro/drivers/tty/serial/zs.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/zs.c
+++ linux-macro/drivers/tty/serial/zs.c
@@ -832,21 +832,22 @@ static void zs_shutdown(struct uart_port
static void zs_reset(struct zs_port *zport)
{
+ struct zs_port *zport_a = &zport->scc->zport[ZS_CHAN_A];
struct zs_scc *scc = zport->scc;
int irq;
unsigned long flags;
spin_lock_irqsave(&scc->zlock, flags);
irq = !irqs_disabled_flags(flags);
- if (!scc->initialised) {
+ if (!zport->initialised) {
/* Reset the pointer first, just in case... */
read_zsreg(zport, R0);
/* And let the current transmission finish. */
zs_line_drain(zport, irq);
- write_zsreg(zport, R9, FHWRES);
+ write_zsreg(zport, R9, zport == zport_a ? CHRA : CHRB);
udelay(10);
write_zsreg(zport, R9, 0);
- scc->initialised = 1;
+ zport->initialised = 1;
}
load_zsregs(zport, zport->regs, irq);
spin_unlock_irqrestore(&scc->zlock, flags);
Index: linux-macro/drivers/tty/serial/zs.h
===================================================================
--- linux-macro.orig/drivers/tty/serial/zs.h
+++ linux-macro/drivers/tty/serial/zs.h
@@ -22,6 +22,7 @@
struct zs_port {
struct zs_scc *scc; /* Containing SCC. */
struct uart_port port; /* Underlying UART. */
+ int initialised; /* For the console port. */
int clk_mode; /* May be 1, 16, 32, or 64. */
@@ -41,7 +42,6 @@ struct zs_scc {
struct zs_port zport[2];
spinlock_t zlock;
atomic_t irq_guard;
- int initialised;
};
#endif /* __KERNEL__ */
^ permalink raw reply
* [PATCH v2 05/10] serial: zs: Fix bootconsole handover lockup
From: Maciej W. Rozycki @ 2026-05-01 23:15 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Calling zs_reset() in the course of setting up the serial device causes
line parameters to be reset and the transmitter disabled. We've been
lucky in that no message is usually produced to the kernel log between
this call and the later call to uart_set_options() in the course of
console setup done by zs_serial_console_init(), or the system would hang
as the console output handler in the firmware tried to access a port
whose transmitter has been disabled and line parameters messed up.
This will change with the next change to the driver, so fix zs_reset()
such that line parameters are set for 9600n8 console operation as with
the system firmware and the transmitter re-enabled after reset. This
also means zs_pm() serves no purpose anymore, so drop it.
Switch to using the channel reset rather than the hardware reset, since
this simplifies handling by removing the interfere
Fixes: 8b4a40809e53 ("zs: move to the serial subsystem")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.23+
---
No change from v1 (3/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604102346290.29980@angie.orcam.me.uk/>.
---
drivers/tty/serial/zs.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
linux-serial-zs-prom-console.diff
Index: linux-macro/drivers/tty/serial/zs.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/zs.c
+++ linux-macro/drivers/tty/serial/zs.c
@@ -105,18 +105,24 @@ struct zs_parms {
static struct zs_scc zs_sccs[ZS_NUM_SCCS];
+/*
+ * Set parameters in WR5, WR12, WR13 such as not to interfere
+ * with the initial PROM-based console. Otherwise any output
+ * produced before the console handover would cause the system
+ * firmware to hang (TxENAB) or produce rubbish (Tx8, B9600).
+ */
static u8 zs_init_regs[ZS_NUM_REGS] __initdata = {
0, /* write 0 */
PAR_SPEC, /* write 1 */
0, /* write 2 */
0, /* write 3 */
X16CLK | SB1, /* write 4 */
- 0, /* write 5 */
+ Tx8 | TxENAB, /* write 5 */
0, 0, 0, /* write 6, 7, 8 */
MIE | DLC | NV, /* write 9 */
NRZ, /* write 10 */
TCBR | RCBR, /* write 11 */
- 0, 0, /* BRG time constant, write 12 + 13 */
+ 0x16, 0x00, /* BRG time constant, write 12 + 13 */
BRSRC | BRENABL, /* write 14 */
0, /* write 15 */
};
@@ -956,23 +962,6 @@ static void zs_set_termios(struct uart_p
spin_unlock_irqrestore(&scc->zlock, flags);
}
-/*
- * Hack alert!
- * Required solely so that the initial PROM-based console
- * works undisturbed in parallel with this one.
- */
-static void zs_pm(struct uart_port *uport, unsigned int state,
- unsigned int oldstate)
-{
- struct zs_port *zport = to_zport(uport);
-
- if (state < 3)
- zport->regs[5] |= TxENAB;
- else
- zport->regs[5] &= ~TxENAB;
- write_zsreg(zport, R5, zport->regs[5]);
-}
-
static const char *zs_type(struct uart_port *uport)
{
@@ -1055,7 +1044,6 @@ static const struct uart_ops zs_ops = {
.startup = zs_startup,
.shutdown = zs_shutdown,
.set_termios = zs_set_termios,
- .pm = zs_pm,
.type = zs_type,
.release_port = zs_release_port,
.request_port = zs_request_port,
@@ -1210,7 +1198,6 @@ static int __init zs_console_setup(struc
return ret;
zs_reset(zport);
- zs_pm(uport, 0, -1);
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
^ permalink raw reply
* [PATCH v2 04/10] serial: dz: Fix bootconsole handover lockup
From: Maciej W. Rozycki @ 2026-05-01 23:14 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
Calling dz_reset() in the course of setting up the serial device causes
line parameters to be reset and the transmitter disabled. We've been
lucky in that no message is usually produced to the kernel log between
this call and the later call to uart_set_options() in the course of
console setup done by dz_serial_console_init(), or the system would hang
as the console output handler in the firmware tried to access a port
whose transmitter has been disabled and line parameters messed up.
This will change with the next change to the driver, so fix dz_reset()
such that line parameters are set for 9600n8 console operation as with
the system firmware and the transmitter re-enabled after reset. This
also means dz_pm() serves no purpose anymore, so drop it.
Fixes: e6ee512f5a77 ("dz.c: Resource management")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.25+
---
No change from v1 (2/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604102338300.29980@angie.orcam.me.uk/>.
---
drivers/tty/serial/dz.c | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
linux-serial-dz-prom-console.diff
Index: linux-macro/drivers/tty/serial/dz.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/dz.c
+++ linux-macro/drivers/tty/serial/dz.c
@@ -571,6 +571,18 @@ static void dz_reset(struct dz_port *dpo
while (dz_in(dport, DZ_CSR) & DZ_CLR);
iob();
+ /*
+ * Set parameters across all lines such as not to interfere
+ * with the initial PROM-based console. Otherwise any output
+ * produced before the console handover would cause the system
+ * firmware to produce rubbish.
+ */
+ for (int line = 0; line < DZ_NB_PORT; line++)
+ dz_out(dport, DZ_LPR, DZ_B9600 | DZ_CS8 | line);
+
+ /* Re-enable transmission for the initial PROM-based console. */
+ dz_out(dport, DZ_TCR, tcr);
+
/* Enable scanning. */
dz_out(dport, DZ_CSR, DZ_MSE);
@@ -654,26 +666,6 @@ static void dz_set_termios(struct uart_p
uart_port_unlock_irqrestore(&dport->port, flags);
}
-/*
- * Hack alert!
- * Required solely so that the initial PROM-based console
- * works undisturbed in parallel with this one.
- */
-static void dz_pm(struct uart_port *uport, unsigned int state,
- unsigned int oldstate)
-{
- struct dz_port *dport = to_dport(uport);
- unsigned long flags;
-
- uart_port_lock_irqsave(&dport->port, &flags);
- if (state < 3)
- dz_start_tx(&dport->port);
- else
- dz_stop_tx(&dport->port);
- uart_port_unlock_irqrestore(&dport->port, flags);
-}
-
-
static const char *dz_type(struct uart_port *uport)
{
return "DZ";
@@ -769,7 +761,6 @@ static const struct uart_ops dz_ops = {
.startup = dz_startup,
.shutdown = dz_shutdown,
.set_termios = dz_set_termios,
- .pm = dz_pm,
.type = dz_type,
.release_port = dz_release_port,
.request_port = dz_request_port,
@@ -894,10 +885,7 @@ static int __init dz_console_setup(struc
if (ret)
return ret;
- spin_lock_init(&dport->port.lock); /* For dz_pm(). */
-
dz_reset(dport);
- dz_pm(uport, 0, -1);
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);
^ permalink raw reply
* [PATCH v2 03/10] serial: dz: Fix bootconsole message clobbering at chip reset
From: Maciej W. Rozycki @ 2026-05-01 23:14 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
In the DZ interface as implemented by the DC7085 gate array the serial
transmitters are double buffered, meaning that at the time a transmitter
is ready to accept the next character there is one in the transmit shift
register still being sent to the line. Issuing a master clear at this
time causes this character to be lost, so wait an extra amount of time
sufficient for the transmit shift register to drain at 9600bps, which is
the baud rate setting used by the firmware console.
Mind the specified 1.4us TRDY recovery time in the course and continue
using iob() as the completion barrier, since the platforms involved use
a write buffer that can delay and combine writes, and reorder them with
respect to reads regardless of the MMIO locations accessed and we still
lack a platform-independent handler for that.
When called from dz_serial_console_init() this is too early for fsleep()
to work and even before lpj has been calculated and therefore the delay
is actually not sufficient for the transmitter to drain and is merely a
placeholder now. This will be addressed in a follow-up change.
Fixes: e6ee512f5a77 ("dz.c: Resource management")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.25+
---
No change from v1 (1/8),
<https://lore.kernel.org/r/alpine.DEB.2.21.2604121508060.29980@angie.orcam.me.uk/>.
---
drivers/tty/serial/dz.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
linux-serial-dz-reset-drain.diff
Index: linux-macro/drivers/tty/serial/dz.c
===================================================================
--- linux-macro.orig/drivers/tty/serial/dz.c
+++ linux-macro/drivers/tty/serial/dz.c
@@ -542,10 +542,31 @@ static int dz_encode_baud_rate(unsigned
static void dz_reset(struct dz_port *dport)
{
struct dz_mux *mux = dport->mux;
+ unsigned short tcr;
+ int loops = 10000;
if (mux->initialised)
return;
+ tcr = dz_in(dport, DZ_TCR);
+
+ /* Do not disturb any ongoing transmissions. */
+ if (dz_in(dport, DZ_CSR) & DZ_MSE) {
+ unsigned short csr, mask;
+
+ mask = tcr;
+ while ((mask & DZ_LNENB) && loops--) {
+ csr = dz_in(dport, DZ_CSR);
+ if (!(csr & DZ_TRDY))
+ continue;
+ mask &= ~(1 << ((csr & DZ_TLINE) >> 8));
+ dz_out(dport, DZ_TCR, mask);
+ iob();
+ udelay(2); /* 1.4us TRDY recovery. */
+ }
+ udelay(1200); /* Transmitter drain. */
+ }
+
dz_out(dport, DZ_CSR, DZ_CLR);
while (dz_in(dport, DZ_CSR) & DZ_CLR);
iob();
^ permalink raw reply
* [PATCH v2 02/10] MIPS: DEC: Prevent initial console buffer from landing in XKPHYS
From: Maciej W. Rozycki @ 2026-05-01 23:14 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
In 64-bit configurations calling the initial console output handler from
a kernel thread other than the initial one will result in a situation
where the stack has been placed in the XKPHYS 64-bit memory segment and
consequently so has been the buffer allocated there that is used as the
argument corresponding to the `%s' output conversion specifier for the
firmware's printf() entry point.
This 64-bit address will then be truncated by 32-bit firmware, resulting
in an attempt to access the wrong memory location, which in turn will
cause all kinds of unpredictable behaviour, such as a kernel crash:
Console: colour dummy device 160x64
Calibrating delay loop... 49.36 BogoMIPS (lpj=192512)
pid_max: default: 32768 minimum: 301
CPU 0 Unable to handle kernel paging request at virtual address 000000000203bd00, epc == ffffffffbfc08364, ra == ffffffffbfc08800
Oops[#1]:
CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-rc2-00254-gfb649bda6f56-dirty #121
$ 0 : 0000000000000000 0000000000000001 0000000000000023 ffffffff80684ba0
$ 4 : 000000000203bd00 ffffffffbfc0f3b4 ffffffffffffffff 0000000000000073
$ 8 : 0a303d7469000000 0000000000000000 0000000000000073 ffffffffbfc0f473
$12 : 0000000000000002 0000000000000000 ffffffff80684c1c 0000000000000000
$16 : 0000000000000000 ffffffff80596dc9 0000000000000000 ffffffffbfc09240
$20 : ffffffff80684c40 ffffffffbfc0f400 000000000000002d 000000000000002b
$24 : ffffffffffffffbf 000000000203bd00
$28 : ffffffff805f0000 ffffffff80684b58 0000000000000030 ffffffffbfc08800
Hi : 0000000000000000
Lo : 0000000000000aa8
epc : ffffffffbfc08364 0xffffffffbfc08364
ra : ffffffffbfc08800 0xffffffffbfc08800
Status: 140120e2 KX SX UX KERNEL EXL
Cause : 00000008 (ExcCode 02)
BadVA : 000000000203bd00
PrId : 00000430 (R4000SC)
Modules linked in:
Process swapper (pid: 0, threadinfo=(____ptrval____), task=(____ptrval____), tls=0000000000000000)
Stack : 0000000000000000 0000000000000000 0000000000000000 0000004d0000004d
80684cc0806a2a40 80596dc80000004d 8061000000000000 bfc0850c80684c38
0000000000000000 000000000203bd00 0000000000000000 0000000000000000
0000000000000000 00000000bfc0f3b4 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000002500000000 0000000000000000 0000000000000000 802c1a7400000000
0203bd0080596dc8 0203bd4d69000000 6c61632000000018 5f746567646e6172
6c616320625f6d6f 5f736e5f6d6f7266 206361323778302b 303d74696e726320
806a0a38806b0000 806a0a38806b0000 00000000806b0000 80683c58806b0000
...
Call Trace:
Code: a082ffff 03e00008 00601021 <80820000> 00001821 10400005 24840001 80820000 24630001
---[ end trace 0000000000000000 ]---
Kernel panic - not syncing: Fatal exception in interrupt
KN04 V2.1k (PC: 0xa0026768, SP: 0x806848e8)
>>
In this case the pointer in $4 was truncated from 0x980000000203bd00 to
0x000000000203bd00.
This may happen when no final console driver has been enabled in the
configuration and consequently the initial console continues being used
late into bootstrap or with an upcoming change that will switch the zs
driver to use a platform device, which in turn will make the console
handover happen only after other kernel threads have already been
started.
Fix the issue by making the buffer static and initdata, and therefore
placed in the CKSEG0 32-bit compatibility segment, observing that the
console output handler is called with the console lock held, implying
no need for this code to be reentrant. Add an assertion to verify the
buffer actually has been placed in a compatibility segment.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.12+
---
New change in v2.
---
arch/mips/dec/prom/console.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
linux-mips-dec-prom-console-xkphys.diff
Index: linux-macro/arch/mips/dec/prom/console.c
===================================================================
--- linux-macro.orig/arch/mips/dec/prom/console.c
+++ linux-macro/arch/mips/dec/prom/console.c
@@ -2,8 +2,9 @@
/*
* DECstation PROM-based early console support.
*
- * Copyright (C) 2004, 2007 Maciej W. Rozycki
+ * Copyright (C) 2004, 2007, 2026 Maciej W. Rozycki
*/
+#include <linux/bug.h>
#include <linux/console.h>
#include <linux/init.h>
#include <linux/kernel.h>
@@ -14,9 +15,11 @@
static void __init prom_console_write(struct console *con, const char *s,
unsigned int c)
{
- char buf[81];
+ static char buf[81] __initdata = { 0 };
unsigned int chunk = sizeof(buf) - 1;
+ BUG_ON((long)buf != (int)buf);
+
while (c > 0) {
if (chunk > c)
chunk = c;
^ permalink raw reply
* [PATCH v2 01/10] MIPS: DEC: Ensure 32-bit stack location for o32 prom_printf()
From: Maciej W. Rozycki @ 2026-05-01 23:14 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
In-Reply-To: <alpine.DEB.2.21.2604302336260.38805@angie.orcam.me.uk>
In 64-bit configurations calling any firmware entry points from a kernel
thread other than the initial one will result in a situation where the
stack has been placed in the XKPHYS 64-bit memory segment.
Consequently the stack pointer is no longer a 32-bit value and when the
32-bit firmware code called uses 32-bit ALU operations to manipulate the
stack pointer, the calculated result is incorrect (in fact in the 64-bit
MIPS ISA almost all 32-bit ALU operations will produce an unpredictable
result when executed on 64-bit data) and control goes astray.
This may happen when no final console driver has been enabled in the
configuration and consequently the initial console continues being used
late into bootstrap, or with an upcoming change that will switch the zs
driver to use a platform device, which in turn will make the console
handover happen only after other kernel threads have already been
started, and the kernel will hang at:
pid_max: default: 32768 minimum: 301
or somewhat later, but always before:
cblist_init_generic: Setting adjustable number of callback queues.
has been printed.
It seems that only the prom_printf() entry point is affected. Of all
the other entry points wired only rex_slot_address() and rex_gettcinfo()
are called from a kernel thread other than the initial one, specifically
kernel_init(), and they are leaf functions that do no business with the
stack, having worked with no issue ever since 64-bit support was added
for the platform back in 2002.
To address this issue then, arrange for the stack to be switched in the
o32 wrapper as required for prom_printf() only, by supplying call_o32()
with a pointer to a chunk of initdata space, which is placed in the
CKSEG0 32-bit compatibility segment, observing that prom_printf() is
only called from console output handler and therefore with the console
lock held, implying no need for this code to be reentrant.
Other firmware entry points may be called with interrupts enabled and no
lock held, and may therefore require that call_o32() be reentrant. They
trigger no issue at this point and "if it ain't broke, don't fix it," so
just leave them alone.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v2.6.12+
---
New change in v2.
---
arch/mips/dec/prom/init.c | 6 +++++-
arch/mips/include/asm/dec/prom.h | 15 +++++++++++++--
2 files changed, 18 insertions(+), 3 deletions(-)
linux-mips-dec-call-o32-stack.diff
Index: linux-macro/arch/mips/dec/prom/init.c
===================================================================
--- linux-macro.orig/arch/mips/dec/prom/init.c
+++ linux-macro/arch/mips/dec/prom/init.c
@@ -3,7 +3,7 @@
* init.c: PROM library initialisation code.
*
* Copyright (C) 1998 Harald Koerfgen
- * Copyright (C) 2002, 2004 Maciej W. Rozycki
+ * Copyright (C) 2002, 2004, 2026 Maciej W. Rozycki
*/
#include <linux/init.h>
#include <linux/kernel.h>
@@ -20,6 +20,10 @@
#include <asm/dec/prom.h>
+#ifdef CONFIG_64BIT
+unsigned long o32_stk[O32_STK_SIZE] __initdata = { 0 };
+#endif
+
int (*__rex_bootinit)(void);
int (*__rex_bootread)(void);
int (*__rex_getbitmap)(memmap *);
Index: linux-macro/arch/mips/include/asm/dec/prom.h
===================================================================
--- linux-macro.orig/arch/mips/include/asm/dec/prom.h
+++ linux-macro/arch/mips/include/asm/dec/prom.h
@@ -4,7 +4,7 @@
*
* DECstation PROM interface.
*
- * Copyright (C) 2002 Maciej W. Rozycki
+ * Copyright (C) 2002, 2026 Maciej W. Rozycki
*
* Based on arch/mips/dec/prom/prom.h by the Anonymous.
*/
@@ -97,6 +97,17 @@ extern int (*__pmax_close)(int);
#ifdef CONFIG_64BIT
+#define O32_STK_SIZE 512
+extern unsigned long o32_stk[];
+
+/* Switch the stack if outside the 32-bit address space. */
+static inline unsigned long *o32_get_stk(void)
+{
+ long fp = (long)__builtin_frame_address(0);
+
+ return fp != (int)fp ? o32_stk + O32_STK_SIZE : NULL;
+}
+
/*
* On MIPS64 we have to call PROM functions via a helper
* dispatcher to accommodate ABI incompatibilities.
@@ -128,7 +139,7 @@ int __DEC_PROM_O32(_prom_printf, (int (*
#define prom_getchar() _prom_getchar(__prom_getchar, NULL)
#define prom_getenv(x) _prom_getenv(__prom_getenv, NULL, x)
-#define prom_printf(x...) _prom_printf(__prom_printf, NULL, x)
+#define prom_printf(x...) _prom_printf(__prom_printf, o32_get_stk(), x)
#else /* !CONFIG_64BIT */
^ permalink raw reply
* [PATCH v2 00/10] MIPS: DEC: Fix serial device regressions + RTC cleanup
From: Maciej W. Rozycki @ 2026-05-01 23:14 UTC (permalink / raw)
To: Thomas Bogendoerfer, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-mips, linux-serial, linux-serial
Hi,
This is v2 of the series, addressing fallout for 64-bit configurations
where the initial console ouutput handler that uses calls into 32-bit
firmware has to ensure no register input including the stack pointer is
outside the 32-bit range, now that the handler is now also called from
kernel threads other beyond the initial one.
Two extra introductory changes, 01/10 and 02/10 have now been added to
platform code. No modification has been made to original changes. The
original description follows, updated for patch renumbering.
Starting from commit 84a9582fd203 ("serial: core: Start managing serial
controllers to enable runtime PM") drivers for serial devices used with
the DEC platform have stopped working due to a null pointer dereference in
the serial core, which means a kernel crash at bootstrap if the relevant
driver has been enabled, as is usually the case for the system console.
This patch series addresses the issue by switching the drivers away from
legacy probing to using platform devices. A notable consequence of this
is the serial console is only switched from the bootconsole handler that
uses firmware calls over to our serial driver at the time the driver is
being properly brought up. This causes messages to be produced to the
console between the device reset and console setup, which in turn causes
the firmware still being called via the bootconsole handler to loop
forever owing to the transmitter having been disabled.
Both drivers are affected and therefore introductory changes 04/10 and
05/10 are included to fix the issue by doing a rudimentary device setup
right after reset, using parameters compatible with those used by the
firmware (9600n8). There are auxiliary changes 03/10 and 06/10 included
as well, that respectively prevent a message corruption regression from
happening at reset due to the change in timing of messages produced to the
console with the dz driver switch to the platform device, and simplify
reset handling in the zs driver by issuing a channel rather hardware
reset. Then 07/10 and 08/10 actually switch the respective drivers to use
platform devices.
A tiny update follows, 09/10, that enables modular build for the dz
driver, not to be backported as not a bug fix.
Finally 10/10 is a small cleanup for the existing RTC device, included in
the series and then last only, due to a mechanical dependency and neither
for backporting, as it only addresses a code quality issue for a failure
scenario that is not expected to trigger in reality.
See individual change descriptions for details. Verified with a 5000/200
machine for the dz driver, and with 5000/150 and 5000/260 systems for the
zs driver.
Please apply.
Previous iterations:
- v1 at: <https://lore.kernel.org/r/alpine.DEB.2.21.2604102250060.29980@angie.orcam.me.uk/>.
Maciej
^ permalink raw reply
* Re: [PATCH v2 02/15] serial: core: add uart_iotype_mmio/legacy_io helper functions
From: Andy Shevchenko @ 2026-05-01 11:48 UTC (permalink / raw)
To: Hugo Villeneuve
Cc: Greg Kroah-Hartman, Jiri Slaby, ilpo.jarvinen, linux-kernel,
linux-serial, Hugo Villeneuve
In-Reply-To: <20260430113011.fea8a6edca8d864429a63fd5@hugovil.com>
On Thu, Apr 30, 2026 at 11:30:11AM -0400, Hugo Villeneuve wrote:
> On Thu, 30 Apr 2026 17:08:25 +0200
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Tue, Apr 28, 2026 at 01:53:48PM -0400, Hugo Villeneuve wrote:
...
> > > +bool uart_iotype_legacy_io(enum uart_iotype iotype)
> >
> > Why do we use 'legacy'? Still in use in modern CPUs...
>
> TBH I do not remember exactly where i got this, but what would you
> suggest?
>
> Maybe:
> uart_iotype_io()
Yep!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox