All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Subject: [PATCH v2 20/31] tty: moxa: carve out special ioctls and extra tty_port
Date: Mon, 17 Mar 2025 08:00:35 +0100	[thread overview]
Message-ID: <20250317070046.24386-21-jirislaby@kernel.org> (raw)
In-Reply-To: <20250317070046.24386-1-jirislaby@kernel.org>

These ioctls are undocumented and not exposed -- they are defined
locally. Given they need a special tty_port just for them, this is very
ugly. So drop this whole functionality. It is barely used for something
real. (And if it is, we'd need a common functionality to all drivers.)

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/moxa.c | 146 +--------------------------------------------
 1 file changed, 1 insertion(+), 145 deletions(-)

diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index a753afcb53b5..1348e2214b81 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -43,15 +43,6 @@
 #include <linux/ratelimit.h>
 
 #include <asm/io.h>
-#include <linux/uaccess.h>
-
-#define	MOXA			0x400
-#define MOXA_GET_IQUEUE		(MOXA + 1)	/* get input buffered count */
-#define MOXA_GET_OQUEUE		(MOXA + 2)	/* get output buffered count */
-#define MOXA_GETDATACOUNT       (MOXA + 23)
-#define MOXA_GET_IOQUEUE	(MOXA + 27)
-#define MOXA_FLUSH_QUEUE	(MOXA + 28)
-#define MOXA_GETMSTATUS         (MOXA + 65)
 
 /*
  *    System Configuration
@@ -397,19 +388,6 @@ static struct moxa_board_conf {
 	void __iomem *intTable;
 } moxa_boards[MAX_BOARDS];
 
-struct mxser_mstatus {
-	tcflag_t cflag;
-	int cts;
-	int dsr;
-	int ri;
-	int dcd;
-};
-
-struct moxaq_str {
-	int inq;
-	int outq;
-};
-
 struct moxa_port {
 	struct tty_port port;
 	struct moxa_board_conf *board;
@@ -424,12 +402,6 @@ struct moxa_port {
 	u8 lowChkFlag;
 };
 
-struct mon_str {
-	int tick;
-	int rxcnt[MAX_PORTS];
-	int txcnt[MAX_PORTS];
-};
-
 /* statusflags */
 #define TXSTOPPED	1
 #define LOWWAIT 	2
@@ -439,14 +411,11 @@ struct mon_str {
 #define WAKEUP_CHARS		256
 
 static int ttymajor = MOXAMAJOR;
-static struct mon_str moxaLog;
 static unsigned int moxaFuncTout = HZ / 2;
 static unsigned int moxaLowWaterChk;
 static DEFINE_MUTEX(moxa_openlock);
 static DEFINE_SPINLOCK(moxa_lock);
 
-static struct tty_port moxa_service_port;
-
 MODULE_AUTHOR("William Chen");
 MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
 MODULE_LICENSE("GPL");
@@ -557,104 +526,6 @@ static void moxa_low_water_check(void __iomem *ofsAddr)
  * TTY operations
  */
 
-static int moxa_ioctl(struct tty_struct *tty,
-		      unsigned int cmd, unsigned long arg)
-{
-	struct moxa_port *ch = tty->driver_data;
-	void __user *argp = (void __user *)arg;
-	int status, ret = 0;
-
-	if (tty->index == MAX_PORTS) {
-		if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
-				cmd != MOXA_GETMSTATUS)
-			return -EINVAL;
-	} else if (!ch)
-		return -ENODEV;
-
-	switch (cmd) {
-	case MOXA_GETDATACOUNT:
-		moxaLog.tick = jiffies;
-		if (copy_to_user(argp, &moxaLog, sizeof(moxaLog)))
-			ret = -EFAULT;
-		break;
-	case MOXA_FLUSH_QUEUE:
-		MoxaPortFlushData(ch, arg);
-		break;
-	case MOXA_GET_IOQUEUE: {
-		struct moxaq_str __user *argm = argp;
-		struct moxaq_str tmp;
-		struct moxa_port *p;
-		unsigned int i, j;
-
-		for (i = 0; i < MAX_BOARDS; i++) {
-			p = moxa_boards[i].ports;
-			for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
-				memset(&tmp, 0, sizeof(tmp));
-				spin_lock_bh(&moxa_lock);
-				if (moxa_boards[i].ready) {
-					tmp.inq = MoxaPortRxQueue(p);
-					tmp.outq = MoxaPortTxQueue(p);
-				}
-				spin_unlock_bh(&moxa_lock);
-				if (copy_to_user(argm, &tmp, sizeof(tmp)))
-					return -EFAULT;
-			}
-		}
-		break;
-	} case MOXA_GET_OQUEUE:
-		status = MoxaPortTxQueue(ch);
-		ret = put_user(status, (unsigned long __user *)argp);
-		break;
-	case MOXA_GET_IQUEUE:
-		status = MoxaPortRxQueue(ch);
-		ret = put_user(status, (unsigned long __user *)argp);
-		break;
-	case MOXA_GETMSTATUS: {
-		struct mxser_mstatus __user *argm = argp;
-		struct mxser_mstatus tmp;
-		struct moxa_port *p;
-		unsigned int i, j;
-
-		for (i = 0; i < MAX_BOARDS; i++) {
-			p = moxa_boards[i].ports;
-			for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
-				struct tty_struct *ttyp;
-				memset(&tmp, 0, sizeof(tmp));
-				spin_lock_bh(&moxa_lock);
-				if (!moxa_boards[i].ready) {
-				        spin_unlock_bh(&moxa_lock);
-					goto copy;
-                                }
-
-				status = MoxaPortLineStatus(p);
-				spin_unlock_bh(&moxa_lock);
-
-				if (status & 1)
-					tmp.cts = 1;
-				if (status & 2)
-					tmp.dsr = 1;
-				if (status & 4)
-					tmp.dcd = 1;
-
-				ttyp = tty_port_tty_get(&p->port);
-				if (!ttyp)
-					tmp.cflag = p->cflag;
-				else
-					tmp.cflag = ttyp->termios.c_cflag;
-				tty_kref_put(ttyp);
-copy:
-				if (copy_to_user(argm, &tmp, sizeof(tmp)))
-					return -EFAULT;
-			}
-		}
-		break;
-	}
-	default:
-		ret = -ENOIOCTLCMD;
-	}
-	return ret;
-}
-
 static int moxa_break_ctl(struct tty_struct *tty, int state)
 {
 	struct moxa_port *port = tty->driver_data;
@@ -671,7 +542,6 @@ static const struct tty_operations moxa_ops = {
 	.write_room = moxa_write_room,
 	.flush_buffer = moxa_flush_buffer,
 	.chars_in_buffer = moxa_chars_in_buffer,
-	.ioctl = moxa_ioctl,
 	.set_termios = moxa_set_termios,
 	.stop = moxa_stop,
 	.start = moxa_start,
@@ -1283,9 +1153,7 @@ static int __init moxa_init(void)
 {
 	int retval = 0;
 
-	tty_port_init(&moxa_service_port);
-
-	moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
+	moxaDriver = tty_alloc_driver(MAX_PORTS,
 			TTY_DRIVER_REAL_RAW |
 			TTY_DRIVER_DYNAMIC_DEV);
 	if (IS_ERR(moxaDriver))
@@ -1301,8 +1169,6 @@ static int __init moxa_init(void)
 	moxaDriver->init_termios.c_ispeed = 9600;
 	moxaDriver->init_termios.c_ospeed = 9600;
 	tty_set_operations(moxaDriver, &moxa_ops);
-	/* Having one more port only for ioctls is ugly */
-	tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
 
 	if (tty_register_driver(moxaDriver)) {
 		printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
@@ -1362,9 +1228,6 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
 	int port;
 
 	port = tty->index;
-	if (port == MAX_PORTS) {
-		return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
-	}
 	if (mutex_lock_interruptible(&moxa_openlock))
 		return -ERESTARTSYS;
 	brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
@@ -2087,7 +1950,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
 	c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
 	if (c > len)
 		c = len;
-	moxaLog.txcnt[port->port.tty->index] += c;
 	total = c;
 	if (spage == epage) {
 		bufhead = readw(ofsAddr + Ofs_txb);
@@ -2129,7 +1991,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
 
 static int MoxaPortReadData(struct moxa_port *port)
 {
-	struct tty_struct *tty = port->port.tty;
 	void __iomem *baseAddr, *ofsAddr, *ofs;
 	u8 *dst;
 	unsigned int count, len, total;
@@ -2148,7 +2009,6 @@ static int MoxaPortReadData(struct moxa_port *port)
 		return 0;
 
 	total = count;
-	moxaLog.rxcnt[tty->index] += total;
 	if (spage == epage) {
 		bufhead = readw(ofsAddr + Ofs_rxb);
 		writew(spage, baseAddr + Control_reg);
@@ -2236,8 +2096,6 @@ static int moxa_get_serial_info(struct tty_struct *tty,
 {
 	struct moxa_port *info = tty->driver_data;
 
-	if (tty->index == MAX_PORTS)
-		return -EINVAL;
 	if (!info)
 		return -ENODEV;
 	mutex_lock(&info->port.mutex);
@@ -2257,8 +2115,6 @@ static int moxa_set_serial_info(struct tty_struct *tty,
 	struct moxa_port *info = tty->driver_data;
 	unsigned int close_delay;
 
-	if (tty->index == MAX_PORTS)
-		return -EINVAL;
 	if (!info)
 		return -ENODEV;
 
-- 
2.49.0


  parent reply	other threads:[~2025-03-17  7:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-17  7:00 [PATCH v2 00/31] tty: cleanup no. 99 Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 01/31] tty: convert "TTY Struct Flags" to an enum Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 02/31] tty: audit: do not use N_TTY_BUF_SIZE Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 03/31] tty: caif: " Jiri Slaby (SUSE)
2025-03-20 11:17   ` Simon Horman
2025-03-17  7:00 ` [PATCH v2 04/31] tty: move N_TTY_BUF_SIZE to n_tty Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 05/31] tty: n_tty: use uint for space returned by tty_write_room() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 06/31] tty: n_tty: simplify process_output() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 07/31] tty: n_tty: clean up process_output_block() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 08/31] tty: n_tty: drop n_tty_trace() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 09/31] tty: n_tty: extract n_tty_continue_cookie() from n_tty_read() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 10/31] tty: n_tty: extract n_tty_wait_for_input() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 11/31] tty: n_tty: move more_to_be_read to the end of n_tty_read() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 12/31] tty: tty_driver: move TTY macros to the top Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 13/31] tty: tty_driver: convert "TTY Driver Flags" to an enum Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 14/31] tty: tty_driver: document both {,__}tty_alloc_driver() properly Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 15/31] tty: tty_driver: introduce TTY driver sub/types enums Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 16/31] tty: serdev: drop serdev_controller_ops::write_room() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 17/31] tty: mmc: sdio: use bool for cts and remove parentheses Jiri Slaby (SUSE)
2025-03-17 10:50   ` Ulf Hansson
2025-03-17  7:00 ` [PATCH v2 18/31] tty: moxa: drop version dump to logs Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 19/31] tty: moxa: drop ISA support Jiri Slaby (SUSE)
2025-03-17  7:00 ` Jiri Slaby (SUSE) [this message]
2025-03-17  7:00 ` [PATCH v2 21/31] tty: srmcons: fix retval from srmcons_init() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 22/31] tty: staging/greybus: pass tty_driver flags to tty_alloc_driver() Jiri Slaby (SUSE)
2025-03-17 12:35   ` Alex Elder
2025-03-17  7:00 ` [PATCH v2 23/31] tty: sunsu: drop serial_{in,out}p() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 24/31] tty: sunsu: remove unused serial_icr_read() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 25/31] serial: remove redundant tty_port_link_device() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 26/31] serial: pass struct uart_state to uart_line_info() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 27/31] serial: 8250: use serial_port_in/out() helpers Jiri Slaby (SUSE)
2025-03-17  7:25   ` Andy Shevchenko
2025-03-17  7:42     ` Jiri Slaby
2025-03-17  7:00 ` [PATCH v2 28/31] serial: 8250_rsa: simplify rsa8250_{request/release}_resource() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 29/31] serial: 8250_port: do not use goto for UPQ_NO_TXEN_TEST code flow Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 30/31] serial: 8250_port: simplify serial8250_request_std_resource() Jiri Slaby (SUSE)
2025-03-17  7:00 ` [PATCH v2 31/31] serial: switch change_irq and change_port to bool in uart_set_info() Jiri Slaby (SUSE)
2025-03-17  7:03 ` [PATCH v2 00/31] tty: cleanup no. 99 Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250317070046.24386-21-jirislaby@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.