Skip to contentSkip to conversation

tty: add Moxa Smartio MUE serial driver

PATCH In review Mathieu OTHACEHE 5 participants 8 messages Feb 1, 2016 – Feb 10, 2016 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tty: add Moxa Smartio MUE serial driver

Add a driver which supports:

- CP-102E: 2 ports RS232 PCIE card
- CP-102EL: 2 ports RS232 PCIE card
- CP-132EL: 2 ports RS422/485 PCIE card
- CP-114EL: 4 ports RS232/422/485 PCIE card
- CP-104EL-A: 4 ports RS232 PCIE card
- CP-168EL-A: 8 ports RS232 PCIE card
- CP-118EL-A: 8 ports RS232/422/485 PCIE card
- CP-118E-A: 8 ports RS422/485 PCIE card
- CP-138E-A: 8 ports RS422/485 PCIE card
- CP-134EL-A: 4 ports RS422/485 PCIE card
- CP-116E-A (A): 8 ports RS232/422/485 PCIE card
- CP-116E-A (B): 8 ports RS232/422/485 PCIE card

This driver is based on 1.16.7 GPL MOXA driver written by Eric Lo and available on MOXA website. The original driver was based on Linux serial driver.

---

Hi,

Here is a new driver for MOXA Smartio MUE cards. It is based on the vendor driver available on MOXA website and on the mainline mxser driver.

I was able to test it on a CP-168EL-A card on PC. Some of the cards (118E-A, 138E-A, 134EL-A, 116E-A-A et 116E-A-B) have a CPLD module programmable via GPIO.
For now, I dropped all the code related to CPLD/GPIO because I can't test it on my card.

Mathieu

 MAINTAINERS           |    5 +
 drivers/tty/Kconfig   |   10 +
 drivers/tty/Makefile  |    1 +
 drivers/tty/mxupcie.c | 1874 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/mxupcie.h |  129 ++++
 5 files changed, 2019 insertions(+)
 create mode 100644 drivers/tty/mxupcie.c
 create mode 100644 drivers/tty/mxupcie.h
MAINTAINERS +5 -0
index 2b4eb31..3e6c950 100644
@@ -7274,6 +7274,11 @@ S:	Maintained
 F:	Documentation/serial/moxa-smartio
 F:	drivers/tty/mxser.*
 
+MOXA SMARTIO/INDUSTIO MUE SERIAL CARD
+M:	Mathieu Othacehe <[email protected]>
+S:	Maintained
+F:	drivers/tty/mxupcie.*
+
 MR800 AVERMEDIA USB FM RADIO DRIVER
 M:	Alexey Klimov <[email protected]>
 L:	[email protected]
drivers/tty/Kconfig +10 -0
index c01f450..8a14bd075 100644
@@ -259,6 +259,16 @@ 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 MOXA_SMARTIO_MUE
+	tristate "Moxa SmartIO MUE support"
+	depends on SERIAL_NONSTANDARD && PCI
+	help
+	  Say Y here if you have a Moxa SmartIO MUE multiport serial card
+	  and/or want to help develop a new version of this driver.
+
+	  This driver can also be built as a module. The module will be called
+	  mxupcie. If you want to do that, say M here.
+
 config SYNCLINK
 	tristate "Microgate SyncLink card support"
 	depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API
drivers/tty/Makefile +1 -0
index 5817e23..0e37ff2 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_CYCLADES)		+= cyclades.o
 obj-$(CONFIG_ISI)		+= isicom.o
 obj-$(CONFIG_MOXA_INTELLIO)	+= moxa.o
 obj-$(CONFIG_MOXA_SMARTIO)	+= mxser.o
+obj-$(CONFIG_MOXA_SMARTIO_MUE)  += mxupcie.o
 obj-$(CONFIG_NOZOMI)		+= nozomi.o
 obj-$(CONFIG_ROCKETPORT)	+= rocket.o
 obj-$(CONFIG_SYNCLINK_GT)	+= synclink_gt.o
drivers/tty/mxupcie.c new file +1874 -0

1,874 lines not on this page · raw message

drivers/tty/mxupcie.h new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.6.4
maintainer
#1 lore raw
Quoted 34 lines · Mathieu OTHACEHE

Add a driver which supports:

- CP-102E: 2 ports RS232 PCIE card
- CP-102EL: 2 ports RS232 PCIE card
- CP-132EL: 2 ports RS422/485 PCIE card
- CP-114EL: 4 ports RS232/422/485 PCIE card
- CP-104EL-A: 4 ports RS232 PCIE card
- CP-168EL-A: 8 ports RS232 PCIE card
- CP-118EL-A: 8 ports RS232/422/485 PCIE card
- CP-118E-A: 8 ports RS422/485 PCIE card
- CP-138E-A: 8 ports RS422/485 PCIE card
- CP-134EL-A: 4 ports RS422/485 PCIE card
- CP-116E-A (A): 8 ports RS232/422/485 PCIE card
- CP-116E-A (B): 8 ports RS232/422/485 PCIE card

This driver is based on 1.16.7 GPL MOXA driver written by Eric Lo and available on MOXA website. The original driver was based on Linux serial driver.

---

Hi,

Here is a new driver for MOXA Smartio MUE cards. It is based on the vendor driver available on MOXA website and on the mainline mxser driver.

I was able to test it on a CP-168EL-A card on PC. Some of the cards (118E-A, 138E-A, 134EL-A, 116E-A-A et 116E-A-B) have a CPLD module programmable via GPIO.
For now, I dropped all the code related to CPLD/GPIO because I can't test it on my card.

Quoted 7 lines

Mathieu

 MAINTAINERS           |    5 +
 drivers/tty/Kconfig   |   10 +
 drivers/tty/Makefile  |    1 +
 drivers/tty/mxupcie.c | 1874 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/tty/mxupcie.h |  129 ++++

Minor nit, but why do you need a .h file here when no one else includes it? Why not just put it into the .c file to keep things nice and self-contained?

thanks,

greg k-h

#2 lore raw
In reply to Mathieu OTHACEHE
Quoted 9 lines

Here is a new driver for MOXA Smartio MUE cards. It is based on the vendor driver available on MOXA website and on the mainline mxser driver.

I was able to test it on a CP-168EL-A card on PC. Some of the cards (118E-A, 138E-A, 134EL-A, 116E-A-A et 116E-A-B) have a CPLD module programmable via GPIO.
For now, I dropped all the code related to CPLD/GPIO because I can't test it on my card.

Thanks

Some comments (and I realise these are probably not bugs you added!)

drivers/tty/mxupcie.c line 304

Quoted 9 lines
drivers/tty/mxupcie.c new file +9 -0
+static int mxupcie_set_baud(struct tty_struct *tty, long newspd)
+{
+	int quot = 0;
+	unsigned char cval;
+	int custom = 0;
+	struct mxupcie_port *info = tty->driver_data;
+
+	if (newspd > info->max_baud)
+		return 0;

This doesn't look quite the behavioru you want.

drivers/tty/mxupcie.c line 315

Quoted 11 lines
drivers/tty/mxupcie.c new file +11 -0
+
+	if (newspd == 38400 &&
+		(info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) {
+		info->speed = info->custom_baud_rate;
+		custom = 1;
+
+		quot = info->baud_base / info->speed;
+		if (info->speed <= 0 || info->speed > info->max_baud)
+			quot = 0;
+		else
+			set_linear_baud(info->ioaddr, info->speed);

The custom speed stuff can go really - it's handled by termios directly these days.

drivers/tty/mxupcie.c line 361

Quoted 4 lines
drivers/tty/mxupcie.c new file +3 -0
+static int mxupcie_change_speed(struct tty_struct *tty,
+				struct ktermios *old_termios)
+{

Be careful with this - if CMSPAR is set the these indicate mark or space (and if you don't support that then clear the CMSPAR bit in tty->termios)

Likewise you should write the actual baud rate into the tty->termios using the helper functions (see how 8250.c does it - it's a nice example)

Quoted 36 lines
drivers/tty/mxupcie.c new file +36 -0
+static void mxupcie_shutdown(struct tty_port *port)
+{
+	struct mxupcie_port *info;
+	unsigned char reg_flag;
+	int i;
+	unsigned long sp_flags;
+
+	info = container_of(port, struct mxupcie_port, port);
+
+	spin_lock_irqsave(&info->slock, sp_flags);
+
+	wake_up_interruptible(&info->port.delta_msr_wait);
+
+	if (info->port.xmit_buf) {
+		free_page((unsigned long)info->port.xmit_buf);
+		info->port.xmit_buf = NULL;
+	}
+
+	reg_flag = 0;
+	iowrite8(reg_flag, info->ioaddr + MOXA_PUART_EFR);
+	iowrite8(reg_flag, info->ioaddr + MOXA_PUART_SFR);
+
+	info->ier = 0;
+	iowrite8(0x00, info->ioaddr + UART_IER);
+
+	if (info->speed < 9600) {
+		int sleep_interval = 0;
+		int reset_cnt = 0;
+
+		if (info->speed <= 600) {
+			sleep_interval = 10;
+			reset_cnt = MX_FIFO_RESET_CNT;
+		} else {
+			sleep_interval = 1;
+			reset_cnt = MX_FIFO_RESET_CNT / 10;
+		}

drivers/tty/mxupcie.c line 587

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+
+		/* Workaround for clear FIFO in low baudrate */
+		iowrite8(0x0f, info->ioaddr + MOXA_PUART_ADJ_CLK);
+		iowrite8(0x03, info->ioaddr + MOXA_PUART_ADJ_ENABLE);
+
+		/* clear Rx/Tx FIFO's */
+		for (i = 0; i < reset_cnt; i++) {
+			iowrite8((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
+				 info->ioaddr + UART_FCR);
+			msleep(sleep_interval);

No can do - you have a spinlock held while you are tring to sleep. I'm not btw clear that you actually need the lock. The tty_port layer ensures activate/shutdown don't cross or get duplicated. The only protection you might need is versus interrupts, and in that case you could free the IRQ up and claim it in activate/shutdown.

drivers/tty/mxupcie.c line 612

Quoted 9 lines
drivers/tty/mxupcie.c new file +9 -0
+static int mxupcie_open(struct tty_struct *tty, struct file *filp)
+{
+	struct mxupcie_port *info;
+	struct mxupcie_board *board;
+	int line;
+
+	line = tty->index;
+	if (line == MXUPCIE_PORTS)
+		return 0;

What is this for ?

drivers/tty/mxupcie.c line 615

Quoted 3 lines
drivers/tty/mxupcie.c new file +3 -0
+
+	if ((line < 0) || (line > MXUPCIE_PORTS))
+		return -ENODEV;

How can this happen ?

drivers/tty/mxupcie.c line 657

Quoted 8 lines
drivers/tty/mxupcie.c new file +8 -0
+	/*
+	 * Before we drop DTR, make sure the UART transmitter
+	 * has completely drained; this is especially
+	 * important if there is a transmit FIFO!
+	 */
+	timeout = jiffies + HZ;
+	while (!(ioread8(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
+		schedule_timeout_interruptible(5);

Always 5 - doesn't it depend on HZ ?

drivers/tty/mxupcie.c line 669

Quoted 12 lines
drivers/tty/mxupcie.c new file +12 -0
+		if (time_after(jiffies, timeout))
+			break;
+	}
+}
+
+static void mxupcie_close(struct tty_struct *tty, struct file *filp)
+{
+	struct mxupcie_port *info = tty->driver_data;
+	struct tty_port *port = &info->port;
+
+	if (tty->index == MXUPCIE_PORTS || info == NULL)
+		return;

Can info be null, given the tty_port code does it matter ?

drivers/tty/mxupcie.c line 682

Quoted 13 lines
drivers/tty/mxupcie.c new file +13 -0
+	if (tty_port_close_start(port, tty, filp) == 0)
+		return;
+
+	mutex_lock(&port->mutex);
+	mxupcie_close_port(port);
+	mxupcie_flush_buffer(tty);
+	if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
+		if (tty->termios.c_cflag & HUPCL)
+			tty_port_lower_dtr_rts(port);
+	}
+	mxupcie_shutdown(port);
+	set_bit(TTY_IO_ERROR, &tty->flags);
+	mutex_unlock(&port->mutex);

This looks confused - the tty_port_close method calls the shutdown method of the tty port so this should probably just be using tty_port_close and the rest in the port method ?

Quoted 19 lines
drivers/tty/mxupcie.c new file +18 -0
+static int mxupcie_ioctl(struct tty_struct *tty, unsigned int cmd,
+			 unsigned long arg)
+{
+	struct mxupcie_port *info = tty->driver_data;
+	int retval;
+	struct async_icount cnow;
+	int ret = 0;
+	unsigned long sp_flags;
+
+	switch (cmd) {
+	case TCSBRK:
+		retval = tty_check_change(tty);
+		if (retval)
+			return retval;
+
+		tty_wait_until_sent(tty, 0);
+
+		if (!arg)

drivers/tty/mxupcie.c line 1073

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+			mxupcie_send_break(tty, HZ / 4);
+
+		break;
+	case TCSBRKP:
+		retval = tty_check_change(tty);
+		if (retval)
+			return retval;
+
+		tty_wait_until_sent(tty, 0);
+		mxupcie_send_break(tty, arg ? arg * (HZ / 10) : HZ / 4);

These won't work. You need to supply a tty->ops->break_ctl method (which you seem to have later on)

Quoted 6 lines
drivers/tty/mxupcie.c new file +6 -0
+static void mxupcie_set_termios(struct tty_struct *tty,
+				struct ktermios *old_termios)
+{
+	struct mxupcie_port *info = tty->driver_data;
+	unsigned long sp_flags;
+

drivers/tty/mxupcie.c line 1166

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+	spin_lock_irqsave(&info->slock, sp_flags);
+	mxupcie_change_speed(tty, old_termios);
+	spin_unlock_irqrestore(&info->slock, sp_flags);
+
+	if (old_termios &&
+	    !tty_termios_hw_change(&tty->termios, old_termios) &&
+	    tty->termios.c_iflag == old_termios->c_iflag) {
+		dev_dbg(tty->dev, "%s - nothing to change\n", __func__);
+		return;
+	}

This debug can probably go away

Quoted 20 lines
drivers/tty/mxupcie.c new file +20 -0
+static void mxupcie_rx_chars(struct tty_struct *tty,
+			     int *status)
+{
+	struct mxupcie_port *info = tty->driver_data;
+	unsigned char ch, gdl = 0;
+	int cnt = 0;
+	int recv_room;
+	int max = 256;
+	unsigned long flags;
+
+	if (*status & UART_LSR_SPECIAL)
+		goto intr_old;
+
+	recv_room = tty_buffer_request_room(&info->port, MX_RX_FIFO_SIZE);
+	if (recv_room) {
+		gdl = ioread8(info->ioaddr + MOXA_PUART_RCNT);
+
+		if (gdl > recv_room)
+			gdl = recv_room;
+

drivers/tty/mxupcie.c line 1394

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+		if (gdl) {
+			tty_insert_flip_string(
+				&info->port,
+				info->ioaddr + MOXA_PUART_MEMRBR, gdl);
+
+			cnt = gdl;
+		}
+	} else {
+		set_bit(TTY_THROTTLED, &tty->flags);
+	}

The above is almost certainly not worth the effort. If we fill up space we are very congested already and you'll almost certainly drop bytes anyway. In fact because you preallocate the full size it's probably more likely to drop bytes than doign it the simple way and letting the tty layer manage things.

drivers/tty/mxupcie.c line 1465

Quoted 3 lines
drivers/tty/mxupcie.c new file +3 -0
+	if (cnt) {
+		memcpy(info->ioaddr + MOXA_PUART_MEMTHR,
+		       info->port.xmit_buf + info->xmit_tail, cnt);

This appears to be memcpy into the mmio space. In which case memcpy is probably not what you want here as memcpy won't work for mmio space on all platforms and may do very weird things on some !

Quoted 9 lines
drivers/tty/mxupcie.c new file +9 -0
+static irqreturn_t mxupcie_interrupt(int irq, void *dev_id)
+{
+	int lsr, iir, i;
+	struct mxupcie_board *board;
+	struct mxupcie_port *info;
+	int max, msr;
+	int pass_counter = 0;
+	int int_cnt;
+	int handled = 0;

drivers/tty/mxupcie.c line 1529

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+	int vect_flag;
+	struct tty_struct *tty;
+
+	board = NULL;
+	for (i = 0; i < MXUPCIE_BOARDS; i++) {
+		if (dev_id == &mxupcie_boards[i]) {
+			board = dev_id;
+			break;
+		}
+	}

This code makes no sense. Surely it's just

	board = dev_id;

drivers/tty/mxupcie.c line 1535

Quoted 6 lines
drivers/tty/mxupcie.c new file +6 -0
+
+	if (i == MXUPCIE_BOARDS)
+		goto irq_stop;
+
+	if (board == NULL)
+		goto irq_stop;

Not needed

Quoted 13 lines
drivers/tty/mxupcie.c new file +13 -0
+
+	max = board->cinfo->nports;
+	pass_counter = 0;
+
+	do {
+		vect_flag = 0;
+
+		for (i = 0; i < max; i++) {
+			info = &board->ports[i];
+			int_cnt = 0;
+
+			do {
+				iir = ioread8(info->ioaddr + UART_IIR);

drivers/tty/mxupcie.c line 1558

Quoted 10 lines
drivers/tty/mxupcie.c new file +10 -0
+				if (iir == MOXA_IIR_NO_INT) {
+					vect_flag++;
+					break;
+				}
+
+				tty = tty_port_tty_get(&info->port);
+				if (!tty) {
+					lsr = ioread8(info->ioaddr + UART_LSR);
+					iowrite8(0x27, info->ioaddr + UART_FCR);
+					ioread8(info->ioaddr + UART_MSR);

Should this not also set handled ?

drivers/tty/mxupcie.c line 1754

Quoted 3 lines
drivers/tty/mxupcie.c new file +3 -0
+	err = mxupcie_initbrd(board, pdev);
+	if (err)
+		goto err_zero;

This seems to have cases it can leave tty resources partially allocated ?

drivers/tty/mxupcie.c line 1804

Quoted 11 lines
drivers/tty/mxupcie.c new file +11 -0
+static void mxupcie_pci_remove(struct pci_dev *pdev)
+{
+	struct mxupcie_board *board = pci_get_drvdata(pdev);
+	int i;
+
+	for (i = 0; i < board->cinfo->nports; i++) {
+		tty_unregister_device(mx_drv, board->index + i);
+		tty_port_destroy(&board->ports[i].port);
+	}
+
+	free_irq(board->irq, board);

I think you need to free the IRQ first so an IRQ can't crash if it occurs between the port destroy and the free_irq

Alan

#3 lore raw

Thank you for your comments. I'll come up with v2 soon but, I have a question about this point :

Quoted 11 lines

drivers/tty/mxupcie.c line 587

Quoted 5 lines
drivers/tty/mxupcie.c new file +5 -0
+		/* clear Rx/Tx FIFO's */
+		for (i = 0; i < reset_cnt; i++) {
+			iowrite8((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
+				 info->ioaddr + UART_FCR);
+			msleep(sleep_interval);

No can do - you have a spinlock held while you are tring to sleep. I'm not btw clear that you actually need the lock. The tty_port layer ensures activate/shutdown don't cross or get duplicated. The only protection you might need is versus interrupts, and in that case you could free the IRQ up and claim it in activate/shutdown.

So is it possible to replace spin_lock_irqsave/restore by local_irq_save/restore in activate/shutdown to protect versus interrupts ?

And is it allowed to call msleep while holding local_irq_save ?

Thank you,

Mathieu

#4 lore raw
In reply to Mathieu OTHACEHE
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Mathieu,

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on v4.5-rc2 next-20160205]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]

url:    https://github.com/0day-ci/linux/commits/Mathieu-OTHACEHE/tty-add-Moxa-Smartio-MUE-serial-driver/20160202-043752
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
config: ia64-allmodconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64

All errors (new ones prefixed by >>):

drivers/tty/mxupcie.c: In function 'mxupcie_get_serial_info':

>> drivers/tty/mxupcie.c:803:2: error: implicit declaration of function 'copy_to_user' [-Werror=implicit-function-declaration]
     if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
     ^
   drivers/tty/mxupcie.c: In function 'mxupcie_set_serial_info':
>> drivers/tty/mxupcie.c:822:2: error: implicit declaration of function 'copy_from_user' [-Werror=implicit-function-declaration]
     if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
     ^
   drivers/tty/mxupcie.c: In function 'mxupcie_get_lsr_info':
>> drivers/tty/mxupcie.c:897:2: error: implicit declaration of function 'put_user' [-Werror=implicit-function-declaration]
     put_user(result, value);
     ^

cc1: some warnings being treated as errors

vim +/copy_to_user +803 drivers/tty/mxupcie.c

797 tmp.baud_base = info->baud_base;
798 tmp.close_delay = info->close_delay;
799 tmp.closing_wait = info->closing_wait;
800 tmp.custom_divisor = info->custom_divisor;
801 tmp.hub6 = 0;
802

 > 803		if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
   804			return -EFAULT;
   805	
   806		return 0;
   807	}
   808	
   809	static int mxupcie_set_serial_info(struct tty_struct *tty,
   810					   struct serial_struct *new_info)
   811	{
   812		struct mxupcie_port *info = tty->driver_data;
   813		struct tty_port *port = &info->port;
   814		struct serial_struct new_serial;
   815		unsigned int flags;
   816		int retval = 0;
   817		unsigned long sp_flags;
   818	
   819		if (!new_info)
   820			return -EFAULT;
   821	
 > 822		if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
   823			return -EFAULT;
   824	
   825		if ((new_serial.irq != info->board->irq) ||
   826		    (new_serial.port != *info->ioaddr))
   827			return -EINVAL;
   828	
   829		flags = port->flags & ASYNC_SPD_MASK;
   830	
   831		if (!capable(CAP_SYS_ADMIN)) {
   832			if ((new_serial.baud_base != info->baud_base) ||
   833			    (new_serial.close_delay != info->close_delay) ||
   834			    ((new_serial.flags & ~ASYNC_USR_MASK) !=
   835			     (port->flags & ~ASYNC_USR_MASK)))
   836				return -EPERM;
   837	
   838			port->flags = ((port->flags & ~ASYNC_USR_MASK) |
   839					    (new_serial.flags & ASYNC_USR_MASK));
   840		} else {
   841			/*
   842			 * OK, past this point, all the error checking has been done.
   843			 * At this point, we start making changes.....
   844			 */
   845			port->flags = ((port->flags & ~ASYNC_FLAGS) |
   846				       (new_serial.flags & ASYNC_FLAGS));
   847			info->close_delay = new_serial.close_delay * HZ / 100;
   848			info->closing_wait = new_serial.closing_wait * HZ / 100;
   849	
   850			if ((new_serial.baud_base != info->baud_base) ||
   851			    (new_serial.custom_divisor != info->custom_divisor)) {
   852	
   853				if (new_serial.custom_divisor == 0)
   854					return -EINVAL;
   855	
   856				info->custom_baud_rate = new_serial.baud_base /
   857					new_serial.custom_divisor;
   858			}
   859		}
   860	
   861		if (test_bit(ASYNCB_INITIALIZED, &port->flags)) {
   862			if (flags != (port->flags & ASYNC_SPD_MASK)) {
   863				spin_lock_irqsave(&info->slock, sp_flags);
   864				mxupcie_change_speed(tty, NULL);
   865				spin_unlock_irqrestore(&info->slock, sp_flags);
   866			}
   867		} else {
   868			retval = mxupcie_activate(port, tty);
   869			if (retval == 0)
   870				set_bit(ASYNCB_INITIALIZED, &port->flags);
   871		}
   872	
   873		return retval;
   874	}
   875	
   876	/*
   877	 * mx_get_lsr_info - get line status register info
   878	 *
   879	 * Purpose: Let user call ioctl() to get info when the UART physically
   880	 *	    is emptied.  On bus types like RS485, the transmitter must
   881	 *	    release the bus after transmitting. This must be done when
   882	 *	    the transmit shift register is empty, not be done when the
   883	 *	    transmit holding register is empty.  This functionality
   884	 *	    allows an RS485 driver to be written in user space.
   885	 */
   886	static int mxupcie_get_lsr_info(struct tty_struct *tty, unsigned int *value)
   887	{
   888		struct mxupcie_port *info = tty->driver_data;
   889		unsigned char status;
   890		unsigned int result;
   891		unsigned long sp_flags;
   892	
   893		spin_lock_irqsave(&info->slock, sp_flags);
   894		status = ioread8(info->ioaddr + UART_LSR);
   895		spin_unlock_irqrestore(&info->slock, sp_flags);
   896		result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
 > 897		put_user(result, value);

898
899 return 0;
900 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw
In reply to Mathieu OTHACEHE
Quoted 28 lines · Mathieu OTHACEHE

Add a driver which supports:

- CP-102E: 2 ports RS232 PCIE card
- CP-102EL: 2 ports RS232 PCIE card
- CP-132EL: 2 ports RS422/485 PCIE card
- CP-114EL: 4 ports RS232/422/485 PCIE card
- CP-104EL-A: 4 ports RS232 PCIE card
- CP-168EL-A: 8 ports RS232 PCIE card
- CP-118EL-A: 8 ports RS232/422/485 PCIE card
- CP-118E-A: 8 ports RS422/485 PCIE card
- CP-138E-A: 8 ports RS422/485 PCIE card
- CP-134EL-A: 4 ports RS422/485 PCIE card
- CP-116E-A (A): 8 ports RS232/422/485 PCIE card
- CP-116E-A (B): 8 ports RS232/422/485 PCIE card

This driver is based on 1.16.7 GPL MOXA driver written by Eric Lo and available on MOXA website. The original driver was based on Linux serial driver.

---

Hi,

Here is a new driver for MOXA Smartio MUE cards. It is based on the vendor driver available on MOXA website and on the mainline mxser driver.

Quoted 7 lines

I was able to test it on a CP-168EL-A card on PC. Some of the cards (118E-A, 138E-A, 134EL-A, 116E-A-A et 116E-A-B) have a CPLD module programmable via GPIO.
For now, I dropped all the code related to CPLD/GPIO because I can't test it on my card.

Mathieu

I'm sorry, but it looks like 8250 based driver if I'm not mistaken. In which case why not to use 8250_core.c / 8250_port.c and entire 8250/ infrastructure?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 3 lines

I'm sorry, but it looks like 8250 based driver if I'm not mistaken. In which case why not to use 8250_core.c / 8250_port.c and entire 8250/ infrastructure?

Well, the vendor is providing two drivers for his serial pci cards : mxser and mxupcie. The mxser driver has been cleaned up and integrated to mainline a long time ago (drivers/tty/mxser.c). I'm trying to do the same thing with the mxupcie driver.

mxser and mxupcie are quite similar, maybe both should use 8250 infrastructure and not have independant drivers ?

Mathieu

#7 lore raw
Quoted 10 lines · Mathieu OTHACEHE
Quoted 3 lines

I'm sorry, but it looks like 8250 based driver if I'm not mistaken. In which case why not to use 8250_core.c / 8250_port.c and entire 8250/ infrastructure?

Well, the vendor is providing two drivers for his serial pci cards : mxser and mxupcie. The mxser driver has been cleaned up and integrated to mainline a long time ago (drivers/tty/mxser.c). I'm trying to do the same thing with the mxupcie driver.

mxser and mxupcie are quite similar, maybe both should use 8250 infrastructure and not have independant drivers ?

Might be. Though for new driver it would be much easier to do. After that someone might move the existing driver.

Signature · 2 lines
With Best Regards,
Andy Shevchenko