Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-08-07 Thread Greg Kroah-Hartman
On Fri, Aug 07, 2020 at 09:18:57AM +, Johnson CH Chen (陳昭勳) wrote:
> > > + if (info->modem_control & UART_MCR_RTS)
> > > + nd->cmd_buffer[6] = 1;
> > > + else
> > > + nd->cmd_buffer[6] = 0;
> > > +
> > > + if (termio->c_cflag & CRTSCTS) {
> > > + nd->cmd_buffer[7] = 1;
> > > + nd->cmd_buffer[8] = 1;
> > > + } else {
> > > + nd->cmd_buffer[7] = 0;
> > > + nd->cmd_buffer[8] = 0;
> > > + }
> > > +
> > > + if (termio->c_iflag & IXON)
> > > + nd->cmd_buffer[9] = 1;
> > > + else
> > > + nd->cmd_buffer[9] = 0;
> > > +
> > > + if (termio->c_iflag & IXOFF)
> > > + nd->cmd_buffer[10] = 1;
> > > + else
> > > + nd->cmd_buffer[10] = 0;
> > 
> > What is this cmd_buffer good for actually? Only to let the user know?
> > Then -- drop it.
> 
> Because detailed iterations for cmd_buffer and cmd_rsp with Nport
> server device are regarded proprietary for our company, is it good to
> reveal value of cmd_buffer[] with macros only for upstream this
> driver?

There is nothing "proprietary" for Linux kernel code, sorry.  Please
document this properly so we can understand, review, and maintain it
over time correctly.

thanks,

greg k-h


RE: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-08-07 Thread 陳昭勳
Hi Jiri,

Thanks for your good coding review for this patch, it helps us a lot!

> From: Jiri Slaby 
> Sent: Tuesday, July 14, 2020 5:34 PM
> To: Johnson CH Chen (陳昭勳) ; Greg
> Kroah-Hartman 
> Cc: linux-kernel@vger.kernel.org; linux-ser...@vger.kernel.org
> Subject: Re: [PATCH] tty: Add MOXA NPort Real TTY Driver
> 
> On 14. 07. 20, 8:24, Johnson CH Chen (陳昭勳) wrote:
> > This driver supports tty functions for all of MOXA's NPort series with
> > v5.0. Using this driver, host part can use tty to connect NPort device
> > server by ethernet.
> ...
> > Signed-off-by: Johnson Chen 
> > Signed-off-by: Jason Chen 
> > Signed-off-by: Danny Lin 
> > Signed-off-by: Victor Yu 
> > ---
> ...
> > --- a/drivers/tty/Kconfig
> > +++ b/drivers/tty/Kconfig
> > @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> > +   tristate "Moxa NPort Real TTY support v5.0"
> 
> MOXA_SMARTIO is lexicographically after MOXA_NPORT_REAL_TTY. So move
> this before MOXA_SMARTIO.
> 
> > +   help
> > + Say Y here if you have a Moxa NPort serial device server.
> > +
> > + The purpose of this driver is to map NPort serial port to host tty
> > + port. Using this driver, you can use NPort serial port as local tty 
> > port.
> > +
> > + This driver can also be built as a module. The module will be called
> > + npreal2 by setting M.
> > +
> >  config SYNCLINK
> > tristate "Microgate SyncLink card support"
> > depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API diff --git
> > a/drivers/tty/Makefile b/drivers/tty/Makefile index
> > 020b1cd9294f..6d07985d6962 100644
> > --- a/drivers/tty/Makefile
> > +++ b/drivers/tty/Makefile
> > @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
> 
> The same.
> 
> >  obj-$(CONFIG_NOZOMI)   += nozomi.o
> >  obj-$(CONFIG_NULL_TTY) += ttynull.o
> >  obj-$(CONFIG_ROCKETPORT)   += rocket.o
> > diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c new file
> > mode 100644 index ..65c773420755
> > --- /dev/null
> > +++ b/drivers/tty/npreal2.c
> > @@ -0,0 +1,3042 @@
> ...
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> What do you need version.h for? Are you sure, you need all these headers?
> 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include "npreal2.h"
> > +
> > +static int ttymajor = NPREALMAJOR;
> 
> You want dynamic major anyway. So kill this all.
> 
> > +static int verbose = 1;
> > +
> > +MODULE_AUTHOR("");
> > +MODULE_DESCRIPTION("MOXA Async/NPort Server Family Real TTY
> Driver");
> > +module_param(ttymajor, int, 0); module_param(verbose, int, 0644);
> > +MODULE_VERSION(NPREAL_VERSION); MODULE_LICENSE("GPL");
> > +
> > +struct server_setting_struct {
> > +   int32_t server_type;
> > +   int32_t disable_fifo;
> > +};
> > +
> > +struct npreal_struct {
> > +   struct tty_port ttyPort;
> > +   struct work_struct tqueue;
> > +   struct work_struct process_flip_tqueue;
> > +   struct ktermios normal_termios;
> > +   struct ktermios callout_termios;
> 
> callout in 2020?
> 
> > +   /* kernel counters for the 4 input interrupts */
> > +   struct async_icount icount;
> > +   struct semaphore rx_semaphore;
> 
> semaphores in new code? You have to explain why are you not using simpler
> and faset mutexes.
> 
> > +   struct nd_struct *net_node;
> > +   struct tty_struct *tty;
> > +   struct pid *session;
> > +   struct pid *pgrp;
> 
> Why does a driver need to care about pgrp? And session? You should kill all
> these set, but unused fields. Note that you should also use fields from struct
> tty_port instead of the duplicates here.
> 
> > +   wait_queue_head_t open_wait;
> > + 

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-28 Thread Pavel Machek
Hi!

> +   This driver can also be built as a module. The module will be called
> +   npreal2 by setting M.

Odd wording...
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-23 Thread kernel test robot
Hi "Johnson,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tty/tty-testing]
[also build test WARNING on v5.8-rc6 next-20200723]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Johnson-CH-Chen/tty-Add-MOXA-NPort-Real-TTY-Driver/20200714-142712
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git 
tty-testing
config: mips-randconfig-s032-20200723 (attached as .config)
compiler: mipsel-linux-gcc (GCC) 9.3.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-93-g4c6cbe55-dirty
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 
CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 


sparse warnings: (new ones prefixed by >>)

   drivers/tty/npreal2.c:1107:26: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void [noderef] __user *to @@ got 
struct serial_struct *retinfo @@
   drivers/tty/npreal2.c:1107:26: sparse: expected void [noderef] __user *to
   drivers/tty/npreal2.c:1107:26: sparse: got struct serial_struct *retinfo
   drivers/tty/npreal2.c:1122:56: sparse: sparse: incorrect type in argument 2 
(different address spaces) @@ expected void const [noderef] __user *from @@ 
got struct serial_struct *new_info @@
   drivers/tty/npreal2.c:1122:56: sparse: expected void const [noderef] 
__user *from
   drivers/tty/npreal2.c:1122:56: sparse: got struct serial_struct *new_info
   drivers/tty/npreal2.c:1149:57: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1186:9: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected unsigned int [noderef] __user 
*__pu_addr @@ got unsigned int *value @@
   drivers/tty/npreal2.c:1186:9: sparse: expected unsigned int [noderef] 
__user *__pu_addr
   drivers/tty/npreal2.c:1186:9: sparse: got unsigned int *value
   drivers/tty/npreal2.c:1624:38: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1897:34: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1914:21: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1984:46: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:2261:17: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected unsigned long [noderef] __user 
*__pu_addr @@ got unsigned long * @@
   drivers/tty/npreal2.c:2261:17: sparse: expected unsigned long [noderef] 
__user *__pu_addr
   drivers/tty/npreal2.c:2261:17: sparse: got unsigned long *
>> drivers/tty/npreal2.c:2265:17: sparse: sparse: incorrect type in initializer 
>> (different address spaces) @@ expected unsigned long const [noderef] 
>> __user *__gu_ptr @@ got unsigned long * @@
>> drivers/tty/npreal2.c:2265:17: sparse: expected unsigned long const 
>> [noderef] __user *__gu_ptr
   drivers/tty/npreal2.c:2265:17: sparse: got unsigned long *
   drivers/tty/npreal2.c:2319:21: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected int [noderef] __user *__pu_addr @@   
  got int * @@
   drivers/tty/npreal2.c:2319:21: sparse: expected int [noderef] __user 
*__pu_addr
   drivers/tty/npreal2.c:2319:21: sparse: got int *
   drivers/tty/npreal2.c:2319:62: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected int [noderef] __user *__pu_addr @@   
  got int * @@
   drivers/tty/npreal2.c:2319:62: sparse: expected int [noderef] __user 
*__pu_addr
   drivers/tty/npreal2.c:2319:62: sparse: got int *
   drivers/tty/npreal2.c:2320:25: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected int [noderef] __user *__pu_addr @@   
  got int * @@
   drivers/tty/npreal2.c:2320:25: sparse: expected int [noderef] __user 
*__pu_addr
   drivers/tty/npreal2.c:2320:25: sparse: got int *
   drivers/tty/npreal2.c:2321:25: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected int [noderef] __user *__pu_addr @@   
  got int * @@
   drivers/tty/npreal2.c:2321:25: sparse: expected int [noderef] __user 
*__pu_addr
   drivers/tty/npreal2.c:2321:25: sparse: got int *
   drivers/tty/npreal2.c:2322:25: sparse: sparse: incorrect type in initializer 
(different address spaces) @@ expected int [noderef] __user *__pu_addr @@   
  got int * @@
   drivers/tty/npreal2.c:2322:25: sparse: 

RE: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-23 Thread 陳昭勳
Hi Greg,

Thanks for your detailed good review!

> From: Greg Kroah-Hartman 
> Sent: Tuesday, July 14, 2020 3:12 PM
> To: Johnson CH Chen (陳昭勳) 
> Cc: Jiri Slaby ; linux-kernel@vger.kernel.org;
> linux-ser...@vger.kernel.org
> Subject: Re: [PATCH] tty: Add MOXA NPort Real TTY Driver
> 
> On Tue, Jul 14, 2020 at 06:24:42AM +, Johnson CH Chen (陳昭勳) wrote:
> > This driver supports tty functions for all of MOXA's NPort series with
> > v5.0. Using this driver, host part can use tty to connect NPort device
> > server by ethernet.
> 
> A new serial driver, nice!
> 
> >
> > The following Moxa products are supported:
> > * CN2600 Series
> > * CN2500 Series
> > * NPort DE Series
> > * NPort 5000A-M12 Series
> > * NPort 5100 Series
> > * NPort 5200 Series
> > * NPort 5400 Series
> > * NPort 5600 Desktop Series
> > * NPort 5600 Rackmount Series
> > * NPort Wireless Series
> > * NPort IA5000 Series
> > * NPort 6000 Series
> > * NPort S8000 Series
> > * NPort S8455I Series
> > * NPort S9000 Series
> > * NE-4100 Series
> > * MiiNePort Series
> >
> > Signed-off-by: Johnson Chen 
> > Signed-off-by: Jason Chen 
> > Signed-off-by: Danny Lin 
> > Signed-off-by: Victor Yu 
> > ---
> >  drivers/tty/Kconfig   |   11 +
> >  drivers/tty/Makefile  |1 +
> >  drivers/tty/npreal2.c | 3042
> > +
> >  drivers/tty/npreal2.h |  140 ++
> >  4 files changed, 3194 insertions(+)
> >  create mode 100644 drivers/tty/npreal2.c  create mode 100644
> > drivers/tty/npreal2.h
> >
> > diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index
> > 93fd984eb2f5..79b545269b71 100644
> > --- a/drivers/tty/Kconfig
> > +++ b/drivers/tty/Kconfig
> > @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> > +   tristate "Moxa NPort Real TTY support v5.0"
> > +   help
> > + Say Y here if you have a Moxa NPort serial device server.
> > +
> > + The purpose of this driver is to map NPort serial port to host tty
> > + port. Using this driver, you can use NPort serial port as local tty 
> > port.
> > +
> > + This driver can also be built as a module. The module will be called
> > + npreal2 by setting M.
> > +
> >  config SYNCLINK
> > tristate "Microgate SyncLink card support"
> > depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API diff --git
> > a/drivers/tty/Makefile b/drivers/tty/Makefile index
> > 020b1cd9294f..6d07985d6962 100644
> > --- a/drivers/tty/Makefile
> > +++ b/drivers/tty/Makefile
> > @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
> >  obj-$(CONFIG_NOZOMI)   += nozomi.o
> >  obj-$(CONFIG_NULL_TTY) += ttynull.o
> >  obj-$(CONFIG_ROCKETPORT)   += rocket.o
> > diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c new file
> > mode 100644 index ..65c773420755
> > --- /dev/null
> > +++ b/drivers/tty/npreal2.c
> > @@ -0,0 +1,3042 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * npreal2.c  -- MOXA NPort Server family Real TTY driver.
> > + *
> > + * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
> > + *
> > + * Supports the following Moxa Product:
> > + * CN2600 Series
> > + * CN2500 Series
> > + * NPort DE Series
> > + * NPort 5000A-M12 Series
> > + * NPort 5100 Series
> > + * NPort 5200 Series
> > + * NPort 5400 Series
> > + * NPort 5600 Desktop Series
> > + * NPort 5600 Rackmount Series
> > + * NPort Wireless Series
> > + * NPort IA5000 Series
> > + * NPort 6000 Series
> > + * NPort S8000 Series
> > + * NPort S8455I Series
> > + * NPort S9000 Series
> > + * NE-4100 Series
> > + * MiiNePort Series
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> &g

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-22 Thread Greg Kroah-Hartman
On Wed, Jul 22, 2020 at 07:04:00AM +, Johnson CH Chen (陳昭勳) wrote:
> Hi Greg,
> 
> Thanks for your response!
> 
> > > > > + unsigned long flag;
> > > > > + unsigned char cmd_buffer[84];
> > > > > + unsigned char rsp_buffer[84];
> > > >
> > > > You seem to have two "static" buffers here, for your device, that 
> > > > you semi-randomly write to all over the place, but I can't find 
> > > > any locking or coordination between things that prevents multiple 
> > > > commands from not just overwritting each other.
> > > >
> > > For cmd_buffer[], we use npreal_wait_and_set_command() to make sure 
> > > cmd_buffer[] is safe to be written by checking "cmd_buffer[0] == 0".
> > 
> > And what locks are protecting you there?
> > 
> > > For rsp_buffer[], we use npreal_wait_command_completed() to make 
> > > sure rsp_buffer[] is desired by checking rsp_buffer[0] and rsp_buffer[1].
> > > Command_set and command should be checked. Besides, rsp_buffer[] is 
> > > got from user space by "NPREAL_NET_CMD_RESPONSE" in 
> > > npreal_net_ioctl().
> > 
> > Again, what locking is really handling this?
> > 
> 
> It's better to protect cmd_buffer[84] and rsp_buffer[84] by locking 
> completely. They are safe because NPort driver should be worked with NPort 
> daemon before, and NPort daemon is designed to be simple.

I'm sorry, but I do not understand this answer at all.  Something can be
"simple" and still be totally wrong :)

Without locking, this code is broken.

thanks,

greg k-h


RE: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-22 Thread 陳昭勳
Hi Greg,

Thanks for your response!

> > > > +   unsigned long flag;
> > > > +   unsigned char cmd_buffer[84];
> > > > +   unsigned char rsp_buffer[84];
> > >
> > > You seem to have two "static" buffers here, for your device, that 
> > > you semi-randomly write to all over the place, but I can't find 
> > > any locking or coordination between things that prevents multiple 
> > > commands from not just overwritting each other.
> > >
> > For cmd_buffer[], we use npreal_wait_and_set_command() to make sure 
> > cmd_buffer[] is safe to be written by checking "cmd_buffer[0] == 0".
> 
> And what locks are protecting you there?
> 
> > For rsp_buffer[], we use npreal_wait_command_completed() to make 
> > sure rsp_buffer[] is desired by checking rsp_buffer[0] and rsp_buffer[1].
> > Command_set and command should be checked. Besides, rsp_buffer[] is 
> > got from user space by "NPREAL_NET_CMD_RESPONSE" in 
> > npreal_net_ioctl().
> 
> Again, what locking is really handling this?
> 

It's better to protect cmd_buffer[84] and rsp_buffer[84] by locking completely. 
They are safe because NPort driver should be worked with NPort daemon before, 
and NPort daemon is designed to be simple.

> > > Also, how does the data get sent to the hardware at all?  I see 
> > > cmd_buffer[] being written to, but what reads from it and how does 
> > > the hardware get the data?
> >
> > Actually we need to both NPort driver (this driver) and Npreal 
> > daemon
> > (userspace) to let HW work. Npreal daemon can communicate with HW by 
> > socket, and Npreal deamon communicates with Nport driver by 
> > "npreal_net_fops". When commands are ready for driver part, it will 
> > wake up poll event to let Nport daemon know.
> 
> That is not obvious at all, and needs to be really really really documented 
> here.
> Why not put the userspace chunk in the tree too?  At the least, you 
> need to point at it.
> 
> And why is a userspace part needed?  We have tty-over-ethernet drivers 
> that do not require such a thing in the tree somewhere...
>

Because we need hardware serial to Ethernet converter (NPort device server) to 
manage some serial devices, so we still need to use MOXA Nport's commands and 
responses between host computer and converter. We will have an internal 
discussion about release of Nport daemon and related document, or using free 
tty to Ethernet daemon such as (ser2net/ socat/ remtty) and improved nport 
driver later. Thanks a lot!

Best regards,
Johnson


Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-16 Thread Greg Kroah-Hartman
On Thu, Jul 16, 2020 at 07:19:02AM +, Johnson CH Chen (陳昭勳) wrote:
> Hi Greg,
> 
> Thanks for detailed and good suggestions!
> 
> > From: linux-serial-ow...@vger.kernel.org
> >  On Behalf Of Greg Kroah-Hartman
> > Sent: Tuesday, July 14, 2020 3:36 PM
> > To: Johnson CH Chen (陳昭勳) 
> > Cc: Jiri Slaby ; linux-kernel@vger.kernel.org;
> > linux-ser...@vger.kernel.org
> > Subject: Re: [PATCH] tty: Add MOXA NPort Real TTY Driver
> > 
> > On Tue, Jul 14, 2020 at 06:24:42AM +, Johnson CH Chen (陳昭勳) wrote:
> > > This driver supports tty functions for all of MOXA's NPort series with
> > > v5.0. Using this driver, host part can use tty to connect NPort device
> > > server by ethernet.
> > >
> > > The following Moxa products are supported:
> > > * CN2600 Series
> > > * CN2500 Series
> > > * NPort DE Series
> > > * NPort 5000A-M12 Series
> > > * NPort 5100 Series
> > > * NPort 5200 Series
> > > * NPort 5400 Series
> > > * NPort 5600 Desktop Series
> > > * NPort 5600 Rackmount Series
> > > * NPort Wireless Series
> > > * NPort IA5000 Series
> > > * NPort 6000 Series
> > > * NPort S8000 Series
> > > * NPort S8455I Series
> > > * NPort S9000 Series
> > > * NE-4100 Series
> > > * MiiNePort Series
> > >
> > > Signed-off-by: Johnson Chen 
> > > Signed-off-by: Jason Chen 
> > > Signed-off-by: Danny Lin 
> > > Signed-off-by: Victor Yu 
> > > ---
> > >  drivers/tty/Kconfig   |   11 +
> > >  drivers/tty/Makefile  |1 +
> > >  drivers/tty/npreal2.c | 3042
> > > +
> > >  drivers/tty/npreal2.h |  140 ++
> > >  4 files changed, 3194 insertions(+)
> > >  create mode 100644 drivers/tty/npreal2.c  create mode 100644
> > > drivers/tty/npreal2.h
> > >
> > > diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index
> > > 93fd984eb2f5..79b545269b71 100644
> > > --- a/drivers/tty/Kconfig
> > > +++ b/drivers/tty/Kconfig
> > > @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> > > + tristate "Moxa NPort Real TTY support v5.0"
> > > + help
> > > +   Say Y here if you have a Moxa NPort serial device server.
> > > +
> > > +   The purpose of this driver is to map NPort serial port to host tty
> > > +   port. Using this driver, you can use NPort serial port as local tty 
> > > port.
> > > +
> > > +   This driver can also be built as a module. The module will be called
> > > +   npreal2 by setting M.
> > > +
> > >  config SYNCLINK
> > >   tristate "Microgate SyncLink card support"
> > >   depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API diff --git
> > > a/drivers/tty/Makefile b/drivers/tty/Makefile index
> > > 020b1cd9294f..6d07985d6962 100644
> > > --- a/drivers/tty/Makefile
> > > +++ b/drivers/tty/Makefile
> > > @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
> > >  obj-$(CONFIG_NOZOMI) += nozomi.o
> > >  obj-$(CONFIG_NULL_TTY)   += ttynull.o
> > >  obj-$(CONFIG_ROCKETPORT) += rocket.o
> > > diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c new file
> > > mode 100644 index ..65c773420755
> > > --- /dev/null
> > > +++ b/drivers/tty/npreal2.c
> > > @@ -0,0 +1,3042 @@
> > > +// SPDX-License-Identifier: GPL-2.0+
> > > +/*
> > > + * npreal2.c  -- MOXA NPort Server family Real TTY driver.
> > > + *
> > > + * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
> > > + *
> > > + * Supports the following Moxa Product:
> > > + * CN2600 Series
> > > + * CN2500 Series
> > > + * NPort DE Series
> > > + * NPort 5000A-M12 Series
> > > + * NPort 5100 Series
> > > + * NPort 5200 Series
> > > + * NPort 5400 Series
> > > + * NPort 5600 Desktop Series
> > > + * NPort 5600 Rackmount Series
> > > + * NPort Wireless Series
> > > 

RE: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-16 Thread 陳昭勳
Hi Greg,

Thanks for detailed and good suggestions!

> From: linux-serial-ow...@vger.kernel.org
>  On Behalf Of Greg Kroah-Hartman
> Sent: Tuesday, July 14, 2020 3:36 PM
> To: Johnson CH Chen (陳昭勳) 
> Cc: Jiri Slaby ; linux-kernel@vger.kernel.org;
> linux-ser...@vger.kernel.org
> Subject: Re: [PATCH] tty: Add MOXA NPort Real TTY Driver
> 
> On Tue, Jul 14, 2020 at 06:24:42AM +, Johnson CH Chen (陳昭勳) wrote:
> > This driver supports tty functions for all of MOXA's NPort series with
> > v5.0. Using this driver, host part can use tty to connect NPort device
> > server by ethernet.
> >
> > The following Moxa products are supported:
> > * CN2600 Series
> > * CN2500 Series
> > * NPort DE Series
> > * NPort 5000A-M12 Series
> > * NPort 5100 Series
> > * NPort 5200 Series
> > * NPort 5400 Series
> > * NPort 5600 Desktop Series
> > * NPort 5600 Rackmount Series
> > * NPort Wireless Series
> > * NPort IA5000 Series
> > * NPort 6000 Series
> > * NPort S8000 Series
> > * NPort S8455I Series
> > * NPort S9000 Series
> > * NE-4100 Series
> > * MiiNePort Series
> >
> > Signed-off-by: Johnson Chen 
> > Signed-off-by: Jason Chen 
> > Signed-off-by: Danny Lin 
> > Signed-off-by: Victor Yu 
> > ---
> >  drivers/tty/Kconfig   |   11 +
> >  drivers/tty/Makefile  |1 +
> >  drivers/tty/npreal2.c | 3042
> > +
> >  drivers/tty/npreal2.h |  140 ++
> >  4 files changed, 3194 insertions(+)
> >  create mode 100644 drivers/tty/npreal2.c  create mode 100644
> > drivers/tty/npreal2.h
> >
> > diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig index
> > 93fd984eb2f5..79b545269b71 100644
> > --- a/drivers/tty/Kconfig
> > +++ b/drivers/tty/Kconfig
> > @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> > +   tristate "Moxa NPort Real TTY support v5.0"
> > +   help
> > + Say Y here if you have a Moxa NPort serial device server.
> > +
> > + The purpose of this driver is to map NPort serial port to host tty
> > + port. Using this driver, you can use NPort serial port as local tty 
> > port.
> > +
> > + This driver can also be built as a module. The module will be called
> > + npreal2 by setting M.
> > +
> >  config SYNCLINK
> > tristate "Microgate SyncLink card support"
> > depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API diff --git
> > a/drivers/tty/Makefile b/drivers/tty/Makefile index
> > 020b1cd9294f..6d07985d6962 100644
> > --- a/drivers/tty/Makefile
> > +++ b/drivers/tty/Makefile
> > @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
> >  obj-$(CONFIG_NOZOMI)   += nozomi.o
> >  obj-$(CONFIG_NULL_TTY) += ttynull.o
> >  obj-$(CONFIG_ROCKETPORT)   += rocket.o
> > diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c new file
> > mode 100644 index ..65c773420755
> > --- /dev/null
> > +++ b/drivers/tty/npreal2.c
> > @@ -0,0 +1,3042 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * npreal2.c  -- MOXA NPort Server family Real TTY driver.
> > + *
> > + * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
> > + *
> > + * Supports the following Moxa Product:
> > + * CN2600 Series
> > + * CN2500 Series
> > + * NPort DE Series
> > + * NPort 5000A-M12 Series
> > + * NPort 5100 Series
> > + * NPort 5200 Series
> > + * NPort 5400 Series
> > + * NPort 5600 Desktop Series
> > + * NPort 5600 Rackmount Series
> > + * NPort Wireless Series
> > + * NPort IA5000 Series
> > + * NPort 6000 Series
> > + * NPort S8000 Series
> > + * NPort S8455I Series
> > + * NPort S9000 Series
> > + * NE-4100 Series
> > + * MiiNePort Series
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
>

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-15 Thread kernel test robot
Hi "Johnson,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on tty/tty-testing]
[also build test WARNING on v5.8-rc5 next-20200714]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Johnson-CH-Chen/tty-Add-MOXA-NPort-Real-TTY-Driver/20200714-142712
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git 
tty-testing
config: sparc64-randconfig-s032-20200715 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-49-g707c5017-dirty
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 
CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 


sparse warnings: (new ones prefixed by >>)

>> drivers/tty/npreal2.c:1107:26: sparse: sparse: incorrect type in argument 1 
>> (different address spaces) @@ expected void [noderef] __user *to @@ 
>> got struct serial_struct *retinfo @@
>> drivers/tty/npreal2.c:1107:26: sparse: expected void [noderef] __user *to
>> drivers/tty/npreal2.c:1107:26: sparse: got struct serial_struct *retinfo
>> drivers/tty/npreal2.c:1122:56: sparse: sparse: incorrect type in argument 2 
>> (different address spaces) @@ expected void const [noderef] __user *from 
>> @@ got struct serial_struct *new_info @@
>> drivers/tty/npreal2.c:1122:56: sparse: expected void const [noderef] 
>> __user *from
>> drivers/tty/npreal2.c:1122:56: sparse: got struct serial_struct *new_info
>> drivers/tty/npreal2.c:1149:57: sparse: sparse: Using plain integer as NULL 
>> pointer
>> drivers/tty/npreal2.c:1186:9: sparse: sparse: incorrect type in argument 1 
>> (different address spaces) @@ expected void const volatile [noderef] 
>> __user * @@ got unsigned int *value @@
>> drivers/tty/npreal2.c:1186:9: sparse: expected void const volatile 
>> [noderef] __user *
>> drivers/tty/npreal2.c:1186:9: sparse: got unsigned int *value
   drivers/tty/npreal2.c:1624:38: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1897:34: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1914:21: sparse: sparse: Using plain integer as NULL 
pointer
   drivers/tty/npreal2.c:1984:46: sparse: sparse: Using plain integer as NULL 
pointer
>> drivers/tty/npreal2.c:2261:17: sparse: sparse: incorrect type in argument 1 
>> (different address spaces) @@ expected void const volatile [noderef] 
>> __user * @@ got unsigned long * @@
   drivers/tty/npreal2.c:2261:17: sparse: expected void const volatile 
[noderef] __user *
>> drivers/tty/npreal2.c:2261:17: sparse: got unsigned long *
   drivers/tty/npreal2.c:2265:17: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void const volatile [noderef] __user 
* @@ got unsigned long * @@
   drivers/tty/npreal2.c:2265:17: sparse: expected void const volatile 
[noderef] __user *
   drivers/tty/npreal2.c:2265:17: sparse: got unsigned long *
>> drivers/tty/npreal2.c:2319:21: sparse: sparse: incorrect type in argument 1 
>> (different address spaces) @@ expected void const volatile [noderef] 
>> __user * @@ got int * @@
   drivers/tty/npreal2.c:2319:21: sparse: expected void const volatile 
[noderef] __user *
>> drivers/tty/npreal2.c:2319:21: sparse: got int *
   drivers/tty/npreal2.c:2319:62: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void const volatile [noderef] __user 
* @@ got int * @@
   drivers/tty/npreal2.c:2319:62: sparse: expected void const volatile 
[noderef] __user *
   drivers/tty/npreal2.c:2319:62: sparse: got int *
   drivers/tty/npreal2.c:2320:25: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void const volatile [noderef] __user 
* @@ got int * @@
   drivers/tty/npreal2.c:2320:25: sparse: expected void const volatile 
[noderef] __user *
   drivers/tty/npreal2.c:2320:25: sparse: got int *
   drivers/tty/npreal2.c:2321:25: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void const volatile [noderef] __user 
* @@ got int * @@
   drivers/tty/npreal2.c:2321:25: sparse: expected void const volatile 
[noderef] __user *
   drivers/tty/npreal2.c:2321:25: sparse: got int *
   drivers/tty/npreal2.c:2322:25: sparse: sparse: incorrect type in argument 1 
(different address spaces) @@ expected void const volatile [noderef] __user 
* @@ 

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-14 Thread Jiri Slaby
On 14. 07. 20, 8:24, Johnson CH Chen (陳昭勳) wrote:
> This driver supports tty functions for all of MOXA's NPort series
> with v5.0. Using this driver, host part can use tty to connect NPort
> device server by ethernet.
...
> Signed-off-by: Johnson Chen 
> Signed-off-by: Jason Chen 
> Signed-off-by: Danny Lin 
> Signed-off-by: Victor Yu 
> ---
...
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> + tristate "Moxa NPort Real TTY support v5.0"

MOXA_SMARTIO is lexicographically after MOXA_NPORT_REAL_TTY. So move
this before MOXA_SMARTIO.

> + help
> +   Say Y here if you have a Moxa NPort serial device server.
> +
> +   The purpose of this driver is to map NPort serial port to host tty
> +   port. Using this driver, you can use NPort serial port as local tty 
> port.
> +
> +   This driver can also be built as a module. The module will be called
> +   npreal2 by setting M.
> +
>  config SYNCLINK
>   tristate "Microgate SyncLink card support"
>   depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index 020b1cd9294f..6d07985d6962 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o

The same.

>  obj-$(CONFIG_NOZOMI) += nozomi.o
>  obj-$(CONFIG_NULL_TTY)   += ttynull.o
>  obj-$(CONFIG_ROCKETPORT) += rocket.o
> diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c
> new file mode 100644
> index ..65c773420755
> --- /dev/null
> +++ b/drivers/tty/npreal2.c
> @@ -0,0 +1,3042 @@
...
> +#include 
> +#include 
> +#include 
> +#include 

What do you need version.h for? Are you sure, you need all these headers?

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "npreal2.h"
> +
> +static int ttymajor = NPREALMAJOR;

You want dynamic major anyway. So kill this all.

> +static int verbose = 1;
> +
> +MODULE_AUTHOR("");
> +MODULE_DESCRIPTION("MOXA Async/NPort Server Family Real TTY Driver");
> +module_param(ttymajor, int, 0);
> +module_param(verbose, int, 0644);
> +MODULE_VERSION(NPREAL_VERSION);
> +MODULE_LICENSE("GPL");
> +
> +struct server_setting_struct {
> + int32_t server_type;
> + int32_t disable_fifo;
> +};
> +
> +struct npreal_struct {
> + struct tty_port ttyPort;
> + struct work_struct tqueue;
> + struct work_struct process_flip_tqueue;
> + struct ktermios normal_termios;
> + struct ktermios callout_termios;

callout in 2020?

> + /* kernel counters for the 4 input interrupts */
> + struct async_icount icount;
> + struct semaphore rx_semaphore;

semaphores in new code? You have to explain why are you not using
simpler and faset mutexes.

> + struct nd_struct *net_node;
> + struct tty_struct *tty;
> + struct pid *session;
> + struct pid *pgrp;

Why does a driver need to care about pgrp? And session? You should kill
all these set, but unused fields. Note that you should also use fields
from struct tty_port instead of the duplicates here.

> + wait_queue_head_t open_wait;
> + wait_queue_head_t close_wait;
> + wait_queue_head_t delta_msr_wait;
> + unsigned long baud_base;
> + unsigned long event;
> + unsigned short closing_wait;
> + int port;
> + int flags;
> + int type;  /* UART type */
> + int xmit_fifo_size;
> + int custom_divisor;
> + int x_char; /* xon/xoff character */
> + int close_delay;
> + int modem_control; /* Modem control register */
> + int modem_status;  /* Line status */
> + int count; /* # of fd on device */
> + int xmit_head;
> + int xmit_tail;
> + int xmit_cnt;
> + unsigned char *xmit_buf;

ringbuf (as Greg suggests) or kfifo.

> + /*
> +  * We use spin_lock_irqsave instead of semaphonre here.

"semaphonre"?

> +  * Reason: When we use pppd to dialout via Real TTY driver,
> +  * some driver functions, such as npreal_write(), would be
> +  * invoked under interrpute mode which causes warning in

"interrpute"?

> +  * down/up tx_semaphore.
> +  */
> + spinlock_t tx_lock;
> +};
> +
> +struct nd_struct {
> + struct semaphore cmd_semaphore;
> + struct proc_dir_entry *node_entry;
> + struct npreal_struct *tty_node;
> + struct semaphore semaphore;
> + wait_queue_head_t initialize_wait;
> + wait_queue_head_t 

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-14 Thread Greg Kroah-Hartman
On Tue, Jul 14, 2020 at 06:24:42AM +, Johnson CH Chen (陳昭勳) wrote:
> This driver supports tty functions for all of MOXA's NPort series
> with v5.0. Using this driver, host part can use tty to connect NPort
> device server by ethernet.
> 
> The following Moxa products are supported:
> * CN2600 Series
> * CN2500 Series
> * NPort DE Series
> * NPort 5000A-M12 Series
> * NPort 5100 Series
> * NPort 5200 Series
> * NPort 5400 Series
> * NPort 5600 Desktop Series
> * NPort 5600 Rackmount Series
> * NPort Wireless Series
> * NPort IA5000 Series
> * NPort 6000 Series
> * NPort S8000 Series
> * NPort S8455I Series
> * NPort S9000 Series
> * NE-4100 Series
> * MiiNePort Series
> 
> Signed-off-by: Johnson Chen 
> Signed-off-by: Jason Chen 
> Signed-off-by: Danny Lin 
> Signed-off-by: Victor Yu 
> ---
>  drivers/tty/Kconfig   |   11 +
>  drivers/tty/Makefile  |1 +
>  drivers/tty/npreal2.c | 3042 +
>  drivers/tty/npreal2.h |  140 ++
>  4 files changed, 3194 insertions(+)
>  create mode 100644 drivers/tty/npreal2.c
>  create mode 100644 drivers/tty/npreal2.h
> 
> diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> index 93fd984eb2f5..79b545269b71 100644
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> + tristate "Moxa NPort Real TTY support v5.0"
> + help
> +   Say Y here if you have a Moxa NPort serial device server.
> +
> +   The purpose of this driver is to map NPort serial port to host tty
> +   port. Using this driver, you can use NPort serial port as local tty 
> port.
> +
> +   This driver can also be built as a module. The module will be called
> +   npreal2 by setting M.
> +
>  config SYNCLINK
>   tristate "Microgate SyncLink card support"
>   depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index 020b1cd9294f..6d07985d6962 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
>  obj-$(CONFIG_NOZOMI) += nozomi.o
>  obj-$(CONFIG_NULL_TTY)   += ttynull.o
>  obj-$(CONFIG_ROCKETPORT) += rocket.o
> diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c
> new file mode 100644
> index ..65c773420755
> --- /dev/null
> +++ b/drivers/tty/npreal2.c
> @@ -0,0 +1,3042 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * npreal2.c  -- MOXA NPort Server family Real TTY driver.
> + *
> + * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
> + *
> + * Supports the following Moxa Product:
> + * CN2600 Series
> + * CN2500 Series
> + * NPort DE Series
> + * NPort 5000A-M12 Series
> + * NPort 5100 Series
> + * NPort 5200 Series
> + * NPort 5400 Series
> + * NPort 5600 Desktop Series
> + * NPort 5600 Rackmount Series
> + * NPort Wireless Series
> + * NPort IA5000 Series
> + * NPort 6000 Series
> + * NPort S8000 Series
> + * NPort S8455I Series
> + * NPort S9000 Series
> + * NE-4100 Series
> + * MiiNePort Series
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "npreal2.h"
> +
> +static int ttymajor = NPREALMAJOR;
> +static int verbose = 1;
> +
> +MODULE_AUTHOR("");
> +MODULE_DESCRIPTION("MOXA Async/NPort Server Family Real TTY Driver");
> +module_param(ttymajor, int, 0);
> +module_param(verbose, int, 0644);
> +MODULE_VERSION(NPREAL_VERSION);
> +MODULE_LICENSE("GPL");
> +
> +struct server_setting_struct {
> + int32_t server_type;
> + int32_t disable_fifo;
> +};
> +
> +struct npreal_struct {
> + struct tty_port ttyPort;
> + struct work_struct tqueue;
> + struct work_struct process_flip_tqueue;
> + struct ktermios normal_termios;
> + struct ktermios callout_termios;
> + /* kernel counters for the 4 input interrupts */
> + struct async_icount icount;
> + struct semaphore rx_semaphore;
> + struct nd_struct *net_node;
> + struct tty_struct *tty;
> + struct pid *session;
> + struct pid *pgrp;
> + wait_queue_head_t open_wait;
> + wait_queue_head_t close_wait;
> + wait_queue_head_t delta_msr_wait;
> + unsigned long baud_base;
> + unsigned long event;
> + unsigned short closing_wait;
> + int port;
> + int flags;
> + int type;  /* UART type */
> + int xmit_fifo_size;
> + int custom_divisor;
> + int 

Re: [PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-14 Thread Greg Kroah-Hartman
On Tue, Jul 14, 2020 at 06:24:42AM +, Johnson CH Chen (陳昭勳) wrote:
> This driver supports tty functions for all of MOXA's NPort series
> with v5.0. Using this driver, host part can use tty to connect NPort
> device server by ethernet.

A new serial driver, nice!

> 
> The following Moxa products are supported:
> * CN2600 Series
> * CN2500 Series
> * NPort DE Series
> * NPort 5000A-M12 Series
> * NPort 5100 Series
> * NPort 5200 Series
> * NPort 5400 Series
> * NPort 5600 Desktop Series
> * NPort 5600 Rackmount Series
> * NPort Wireless Series
> * NPort IA5000 Series
> * NPort 6000 Series
> * NPort S8000 Series
> * NPort S8455I Series
> * NPort S9000 Series
> * NE-4100 Series
> * MiiNePort Series
> 
> Signed-off-by: Johnson Chen 
> Signed-off-by: Jason Chen 
> Signed-off-by: Danny Lin 
> Signed-off-by: Victor Yu 
> ---
>  drivers/tty/Kconfig   |   11 +
>  drivers/tty/Makefile  |1 +
>  drivers/tty/npreal2.c | 3042 +
>  drivers/tty/npreal2.h |  140 ++
>  4 files changed, 3194 insertions(+)
>  create mode 100644 drivers/tty/npreal2.c
>  create mode 100644 drivers/tty/npreal2.h
> 
> diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
> index 93fd984eb2f5..79b545269b71 100644
> --- a/drivers/tty/Kconfig
> +++ b/drivers/tty/Kconfig
> @@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
> + tristate "Moxa NPort Real TTY support v5.0"
> + help
> +   Say Y here if you have a Moxa NPort serial device server.
> +
> +   The purpose of this driver is to map NPort serial port to host tty
> +   port. Using this driver, you can use NPort serial port as local tty 
> port.
> +
> +   This driver can also be built as a module. The module will be called
> +   npreal2 by setting M.
> +
>  config SYNCLINK
>   tristate "Microgate SyncLink card support"
>   depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API
> diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
> index 020b1cd9294f..6d07985d6962 100644
> --- a/drivers/tty/Makefile
> +++ b/drivers/tty/Makefile
> @@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
>  obj-$(CONFIG_NOZOMI) += nozomi.o
>  obj-$(CONFIG_NULL_TTY)   += ttynull.o
>  obj-$(CONFIG_ROCKETPORT) += rocket.o
> diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c
> new file mode 100644
> index ..65c773420755
> --- /dev/null
> +++ b/drivers/tty/npreal2.c
> @@ -0,0 +1,3042 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * npreal2.c  -- MOXA NPort Server family Real TTY driver.
> + *
> + * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
> + *
> + * Supports the following Moxa Product:
> + * CN2600 Series
> + * CN2500 Series
> + * NPort DE Series
> + * NPort 5000A-M12 Series
> + * NPort 5100 Series
> + * NPort 5200 Series
> + * NPort 5400 Series
> + * NPort 5600 Desktop Series
> + * NPort 5600 Rackmount Series
> + * NPort Wireless Series
> + * NPort IA5000 Series
> + * NPort 6000 Series
> + * NPort S8000 Series
> + * NPort S8455I Series
> + * NPort S9000 Series
> + * NE-4100 Series
> + * MiiNePort Series
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "npreal2.h"
> +
> +static int ttymajor = NPREALMAJOR;
> +static int verbose = 1;

Please do not do that, just use the normal dynamic debug logic that the
kernel has and that everyone uses.  No per-driver type of debugging
functionality, as obviously that does not scale at all.

> +
> +MODULE_AUTHOR("");

We need a real author name here if you want to be the maintainer.
Otherwise a support address can't be an author :)

> +MODULE_DESCRIPTION("MOXA Async/NPort Server Family Real TTY Driver");
> +module_param(ttymajor, int, 0);
> +module_param(verbose, int, 0644);

No module parameters please, they should not be needed at all.

> +MODULE_VERSION(NPREAL_VERSION);

No need for a driver version once the code is in the kernel tree, as the
kernel version is what matters.

> +MODULE_LICENSE("GPL");
> +
> +struct server_setting_struct {
> + int32_t server_type;
> + int32_t disable_fifo;

Please use kernel types, like u32, instead of userspace types like
these.

> +};
> +
> +struct npreal_struct {
> + struct tty_port ttyPort;
> + struct work_struct tqueue;
> + struct work_struct process_flip_tqueue;

None of these should be pointers?

> + struct ktermios normal_termios;
> + struct ktermios 

[PATCH] tty: Add MOXA NPort Real TTY Driver

2020-07-14 Thread 陳昭勳
This driver supports tty functions for all of MOXA's NPort series
with v5.0. Using this driver, host part can use tty to connect NPort
device server by ethernet.

The following Moxa products are supported:
* CN2600 Series
* CN2500 Series
* NPort DE Series
* NPort 5000A-M12 Series
* NPort 5100 Series
* NPort 5200 Series
* NPort 5400 Series
* NPort 5600 Desktop Series
* NPort 5600 Rackmount Series
* NPort Wireless Series
* NPort IA5000 Series
* NPort 6000 Series
* NPort S8000 Series
* NPort S8455I Series
* NPort S9000 Series
* NE-4100 Series
* MiiNePort Series

Signed-off-by: Johnson Chen 
Signed-off-by: Jason Chen 
Signed-off-by: Danny Lin 
Signed-off-by: Victor Yu 
---
 drivers/tty/Kconfig   |   11 +
 drivers/tty/Makefile  |1 +
 drivers/tty/npreal2.c | 3042 +
 drivers/tty/npreal2.h |  140 ++
 4 files changed, 3194 insertions(+)
 create mode 100644 drivers/tty/npreal2.c
 create mode 100644 drivers/tty/npreal2.h

diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 93fd984eb2f5..79b545269b71 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -259,6 +259,17 @@ 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_NPORT_REAL_TTY
+   tristate "Moxa NPort Real TTY support v5.0"
+   help
+ Say Y here if you have a Moxa NPort serial device server.
+
+ The purpose of this driver is to map NPort serial port to host tty
+ port. Using this driver, you can use NPort serial port as local tty 
port.
+
+ This driver can also be built as a module. The module will be called
+ npreal2 by setting M.
+
 config SYNCLINK
tristate "Microgate SyncLink card support"
depends on SERIAL_NONSTANDARD && PCI && ISA_DMA_API
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index 020b1cd9294f..6d07985d6962 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -24,6 +24,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_NPORT_REAL_TTY) += npreal2.o
 obj-$(CONFIG_NOZOMI)   += nozomi.o
 obj-$(CONFIG_NULL_TTY) += ttynull.o
 obj-$(CONFIG_ROCKETPORT)   += rocket.o
diff --git a/drivers/tty/npreal2.c b/drivers/tty/npreal2.c
new file mode 100644
index ..65c773420755
--- /dev/null
+++ b/drivers/tty/npreal2.c
@@ -0,0 +1,3042 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * npreal2.c  -- MOXA NPort Server family Real TTY driver.
+ *
+ * Copyright (c) 1999-2020  Moxa Technologies (supp...@moxa.com)
+ *
+ * Supports the following Moxa Product:
+ * CN2600 Series
+ * CN2500 Series
+ * NPort DE Series
+ * NPort 5000A-M12 Series
+ * NPort 5100 Series
+ * NPort 5200 Series
+ * NPort 5400 Series
+ * NPort 5600 Desktop Series
+ * NPort 5600 Rackmount Series
+ * NPort Wireless Series
+ * NPort IA5000 Series
+ * NPort 6000 Series
+ * NPort S8000 Series
+ * NPort S8455I Series
+ * NPort S9000 Series
+ * NE-4100 Series
+ * MiiNePort Series
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "npreal2.h"
+
+static int ttymajor = NPREALMAJOR;
+static int verbose = 1;
+
+MODULE_AUTHOR("");
+MODULE_DESCRIPTION("MOXA Async/NPort Server Family Real TTY Driver");
+module_param(ttymajor, int, 0);
+module_param(verbose, int, 0644);
+MODULE_VERSION(NPREAL_VERSION);
+MODULE_LICENSE("GPL");
+
+struct server_setting_struct {
+   int32_t server_type;
+   int32_t disable_fifo;
+};
+
+struct npreal_struct {
+   struct tty_port ttyPort;
+   struct work_struct tqueue;
+   struct work_struct process_flip_tqueue;
+   struct ktermios normal_termios;
+   struct ktermios callout_termios;
+   /* kernel counters for the 4 input interrupts */
+   struct async_icount icount;
+   struct semaphore rx_semaphore;
+   struct nd_struct *net_node;
+   struct tty_struct *tty;
+   struct pid *session;
+   struct pid *pgrp;
+   wait_queue_head_t open_wait;
+   wait_queue_head_t close_wait;
+   wait_queue_head_t delta_msr_wait;
+   unsigned long baud_base;
+   unsigned long event;
+   unsigned short closing_wait;
+   int port;
+   int flags;
+   int type;  /* UART type */
+   int xmit_fifo_size;
+   int custom_divisor;
+   int x_char; /* xon/xoff character */
+   int close_delay;
+   int modem_control; /* Modem control register */
+   int modem_status;  /* Line status */
+   int count; /* # of fd on device */
+   int xmit_head;
+   int xmit_tail;
+   int xmit_cnt;
+   unsigned char *xmit_buf;
+
+   /*
+* We