Re: [Patch] Driver for Keyspan USA-19HS

2019-06-24 Thread Jonathan Gray
On Fri, Jun 07, 2019 at 11:08:24AM -0500, joshua stein wrote:
> On Mon, 03 Jun 2019 at 23:44:37 -0400, Cody Cutler wrote:
> > Hi jcs and tech, the following is a patch which implements jcs's feedback 
> > and
> > adds a man page.
> 
> Thanks Cody, I've imported your driver.
> 

/sys/dev/usb/ukspan.c:510:7: warning: variable 'cflag' is uninitialized when 
used here [-Wuninitialized]
if ((cflag & CIGNORE) == 0) {
 ^

Index: ukspan.c
===
RCS file: /cvs/src/sys/dev/usb/ukspan.c,v
retrieving revision 1.1
diff -u -p -r1.1 ukspan.c
--- ukspan.c7 Jun 2019 16:06:59 -   1.1
+++ ukspan.c24 Jun 2019 14:25:06 -
@@ -507,8 +507,8 @@ ukspan_param(void *addr, int portno, str
cmsg->rxmode = cmsg->txmode = 0;
 
/* Set parity, data, and stop bits */
+   cflag = ti->c_cflag;
if ((cflag & CIGNORE) == 0) {
-   cflag = ti->c_cflag;
if (cflag & PARENB)
lcr = (cflag & PARODD) ? UKSPAN_PARITY_ODD :
UKSPAN_PARITY_EVEN;



Re: [Patch] Driver for Keyspan USA-19HS

2019-06-07 Thread joshua stein
On Mon, 03 Jun 2019 at 23:44:37 -0400, Cody Cutler wrote:
> Hi jcs and tech, the following is a patch which implements jcs's feedback and
> adds a man page.

Thanks Cody, I've imported your driver.



Re: [Patch] Driver for Keyspan USA-19HS

2019-06-04 Thread Tracey Emery
On Mon, Jun 03, 2019 at 11:44:37PM -0400, Cody Cutler wrote:
> Hi jcs and tech, the following is a patch which implements jcs's feedback and
> adds a man page.
> 
> Note that one must execute `make -C sys/dev/usb' after applying to build.
> 
> Thanks!
> 
> diff --git share/man/man4/Makefile share/man/man4/Makefile
> index 7d470b6ca47..999621c7889 100644
> --- share/man/man4/Makefile
> +++ share/man/man4/Makefile
> @@ -71,7 +71,7 @@ MAN=aac.4 abcrtc.4 ac97.4 acphy.4 acrtc.4 \
>   tlphy.4 thmc.4 tpm.4 tqphy.4 trm.4 trunk.4 tsl.4 tty.4 tun.4 tap.4 \
>   twe.4 \
>   txp.4 txphy.4 uaudio.4 uark.4 uath.4 ubcmtp.4 uberry.4 ubsa.4 \
> - ubsec.4 ucom.4 uchcom.4 ucrcom.4 ucycom.4 uslhcom.4 \
> + ubsec.4 ucom.4 uchcom.4 ucrcom.4 ucycom.4 ukspan.4 uslhcom.4 \
>   udav.4 udcf.4 udl.4 udp.4 udsbr.4 \
>   uftdi.4 ugen.4 ugl.4 ugold.4 uguru.4 uhci.4 uhid.4 uhidev.4 uipaq.4 \
>   uk.4 ukbd.4 \
> diff --git share/man/man4/ucom.4 share/man/man4/ucom.4
> index e14df75675b..bde53a2c5e1 100644
> --- share/man/man4/ucom.4
> +++ share/man/man4/ucom.4
> @@ -42,6 +42,7 @@
>  .Cd "ucom* at ucycom?"   # Cypress
>  .Cd "ucom* at uftdi?"# FTDI
>  .Cd "ucom* at uipaq?"# iPAQ
> +.Cd "ucom* at ukspan?"   # Keyspan
>  .Cd "ucom* at umcs?" # MosChip Semiconductor multiport
>  .Cd "ucom* at umct?" # MCT
>  .Cd "ucom* at umodem?"   # Standardized umodem
> diff --git share/man/man4/ukspan.4 share/man/man4/ukspan.4
> new file mode 100644
> index 000..2b98f1efcb5
> --- /dev/null
> +++ share/man/man4/ukspan.4
> @@ -0,0 +1,39 @@
> +.\" Copyright (c) 2019 Cody Cutler 
> +.\"
> +.\" Permission to use, copy, modify, and distribute this software for any
> +.\" purpose with or without fee is hereby granted, provided that the above
> +.\" copyright notice and this permission notice appear in all copies.
> +.\"
> +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> +.\"
> +.Dd $Mdocdate$
> +.Dt UKSPAN 4
> +.Os
> +.Sh NAME
> +.Nm ukspan
> +.Nd Keyspan USB serial adapter
> +.Sh SYNOPSIS
> +.Cd "ukspan* at uhub?"
> +.Cd "ucom*   at ukspan?"
> +.Sh DESCRIPTION
> +The
> +.Nm
> +driver supports the TrippLite Keyspan USA-19HS serial adapter, which is made
> +accessible through
> +.Xr ucom 4 .
> +.Sh SEE ALSO
> +.Xr tty 4 ,
> +.Xr ucom 4 ,
> +.Xr uhub 4 ,
> +.Xr usb 4
> +.Sh AUTHORS
> +The
> +.Nm
> +driver was written by
> +.An Cody Cutler Aq Mt ccut...@csail.mit.edu .
> diff --git share/man/man4/usb.4 share/man/man4/usb.4
> index 520d513f5b1..81a4abd8c70 100644
> --- share/man/man4/usb.4
> +++ share/man/man4/usb.4
> @@ -188,6 +188,8 @@ FTDI USB serial adapter
>  iPAQ USB units
>  .It Xr ulpt 4
>  USB printer support
> +.It Xr ukspan 4
> +Keyspan serial adapter
>  .It Xr umcs 4
>  MosChip Semiconductor based USB multiport serial adapter
>  .It Xr umct 4
> diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
> index ad192f4ea1d..5b5d37c24e2 100644
> --- sys/arch/amd64/conf/GENERIC
> +++ sys/arch/amd64/conf/GENERIC
> @@ -224,6 +224,8 @@ uvscom*   at uhub?# SUNTAC Slipper U 
> VS-10U serial
>  ucom*at uvscom?
>  ubsa*at uhub?# Belkin serial adapter
>  ucom*at ubsa?
> +ukspan* at uhub? # Keyspan USA19HS serial adapter
> +ucom*at ukspan?
>  uftdi*   at uhub?# FTDI FT8U100AX serial adapter
>  ucom*at uftdi?
>  uplcom* at uhub? # I/O DATA USB-RSAQ2 serial adapter
> diff --git sys/dev/usb/files.usb sys/dev/usb/files.usb
> index 1036cf36232..29bc1205540 100644
> --- sys/dev/usb/files.usb
> +++ sys/dev/usb/files.usb
> @@ -317,6 +317,11 @@ device   ubsa: ucombus
>  attach   ubsa at uhub
>  file dev/usb/ubsa.c  ubsa
>  
> +# Keyspan USA19HS serial
> +device   ukspan: ucombus
> +attach   ukspan at uhub
> +file dev/usb/ukspan.cukspan
> +
>  # Silicon Laboratories CP210x serial
>  device   uslcom: ucombus
>  attach   uslcom at uhub
> diff --git sys/dev/usb/ukspan.c sys/dev/usb/ukspan.c
> new file mode 100644
> index 000..5f5e9583641
> --- /dev/null
> +++ sys/dev/usb/ukspan.c
> @@ -0,0 +1,594 @@
> +/*
> + * Copyright (c) 2019 Cody Cutler 
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 

Re: [Patch] Driver for Keyspan USA-19HS

2019-06-03 Thread Cody Cutler
Hi jcs and tech, the following is a patch which implements jcs's feedback and
adds a man page.

Note that one must execute `make -C sys/dev/usb' after applying to build.

Thanks!

diff --git share/man/man4/Makefile share/man/man4/Makefile
index 7d470b6ca47..999621c7889 100644
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -71,7 +71,7 @@ MAN=  aac.4 abcrtc.4 ac97.4 acphy.4 acrtc.4 \
tlphy.4 thmc.4 tpm.4 tqphy.4 trm.4 trunk.4 tsl.4 tty.4 tun.4 tap.4 \
twe.4 \
txp.4 txphy.4 uaudio.4 uark.4 uath.4 ubcmtp.4 uberry.4 ubsa.4 \
-   ubsec.4 ucom.4 uchcom.4 ucrcom.4 ucycom.4 uslhcom.4 \
+   ubsec.4 ucom.4 uchcom.4 ucrcom.4 ucycom.4 ukspan.4 uslhcom.4 \
udav.4 udcf.4 udl.4 udp.4 udsbr.4 \
uftdi.4 ugen.4 ugl.4 ugold.4 uguru.4 uhci.4 uhid.4 uhidev.4 uipaq.4 \
uk.4 ukbd.4 \
diff --git share/man/man4/ucom.4 share/man/man4/ucom.4
index e14df75675b..bde53a2c5e1 100644
--- share/man/man4/ucom.4
+++ share/man/man4/ucom.4
@@ -42,6 +42,7 @@
 .Cd "ucom* at ucycom?" # Cypress
 .Cd "ucom* at uftdi?"  # FTDI
 .Cd "ucom* at uipaq?"  # iPAQ
+.Cd "ucom* at ukspan?" # Keyspan
 .Cd "ucom* at umcs?"   # MosChip Semiconductor multiport
 .Cd "ucom* at umct?"   # MCT
 .Cd "ucom* at umodem?" # Standardized umodem
diff --git share/man/man4/ukspan.4 share/man/man4/ukspan.4
new file mode 100644
index 000..2b98f1efcb5
--- /dev/null
+++ share/man/man4/ukspan.4
@@ -0,0 +1,39 @@
+.\" Copyright (c) 2019 Cody Cutler 
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate$
+.Dt UKSPAN 4
+.Os
+.Sh NAME
+.Nm ukspan
+.Nd Keyspan USB serial adapter
+.Sh SYNOPSIS
+.Cd "ukspan* at uhub?"
+.Cd "ucom*   at ukspan?"
+.Sh DESCRIPTION
+The
+.Nm
+driver supports the TrippLite Keyspan USA-19HS serial adapter, which is made
+accessible through
+.Xr ucom 4 .
+.Sh SEE ALSO
+.Xr tty 4 ,
+.Xr ucom 4 ,
+.Xr uhub 4 ,
+.Xr usb 4
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Cody Cutler Aq Mt ccut...@csail.mit.edu .
diff --git share/man/man4/usb.4 share/man/man4/usb.4
index 520d513f5b1..81a4abd8c70 100644
--- share/man/man4/usb.4
+++ share/man/man4/usb.4
@@ -188,6 +188,8 @@ FTDI USB serial adapter
 iPAQ USB units
 .It Xr ulpt 4
 USB printer support
+.It Xr ukspan 4
+Keyspan serial adapter
 .It Xr umcs 4
 MosChip Semiconductor based USB multiport serial adapter
 .It Xr umct 4
diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
index ad192f4ea1d..5b5d37c24e2 100644
--- sys/arch/amd64/conf/GENERIC
+++ sys/arch/amd64/conf/GENERIC
@@ -224,6 +224,8 @@ uvscom* at uhub?# SUNTAC Slipper U 
VS-10U serial
 ucom*  at uvscom?
 ubsa*  at uhub?# Belkin serial adapter
 ucom*  at ubsa?
+ukspan* at uhub?   # Keyspan USA19HS serial adapter
+ucom*  at ukspan?
 uftdi* at uhub?# FTDI FT8U100AX serial adapter
 ucom*  at uftdi?
 uplcom* at uhub?   # I/O DATA USB-RSAQ2 serial adapter
diff --git sys/dev/usb/files.usb sys/dev/usb/files.usb
index 1036cf36232..29bc1205540 100644
--- sys/dev/usb/files.usb
+++ sys/dev/usb/files.usb
@@ -317,6 +317,11 @@ device ubsa: ucombus
 attach ubsa at uhub
 file   dev/usb/ubsa.c  ubsa
 
+# Keyspan USA19HS serial
+device ukspan: ucombus
+attach ukspan at uhub
+file   dev/usb/ukspan.cukspan
+
 # Silicon Laboratories CP210x serial
 device uslcom: ucombus
 attach uslcom at uhub
diff --git sys/dev/usb/ukspan.c sys/dev/usb/ukspan.c
new file mode 100644
index 000..5f5e9583641
--- /dev/null
+++ sys/dev/usb/ukspan.c
@@ -0,0 +1,594 @@
+/*
+ * Copyright (c) 2019 Cody Cutler 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION 

Re: [Patch] Driver for Keyspan USA-19HS

2019-05-29 Thread Cody Cutler
Thank you for your comments, Joshua. I'll send an updated patch shortly.

j...@openbsd.org (joshua stein) - Tue, May 28, 2019 at 07:51:08PM -0500
> Hi,
> 
> Some feedback inline:
> 
> On Tue, 28 May 2019 at 18:42:51 -0400, Cody Cutler wrote:
> > Hello tech, I'm submitting the following patch for inclusion. The patch
> > implements a driver for the Keyspan USA-19HS USB-to-serial dongle.
> > 
> > I've used it for a few months now without any problems. Please let me know 
> > if
> > you spot any problems.
> > 
> > Thanks!
> > 
> > diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
> > index ad192f4ea1d..052915d10e0 100644
> > --- sys/arch/amd64/conf/GENERIC
> > +++ sys/arch/amd64/conf/GENERIC
> > @@ -224,6 +224,8 @@ uvscom* at uhub?# SUNTAC Slipper U 
> > VS-10U serial
> >  ucom*  at uvscom?
> >  ubsa*  at uhub?# Belkin serial adapter
> >  ucom*  at ubsa?
> > +ukspan* at uhub?   # Keyspan USA19HS
> 
> Nit: maybe add "serial adapter" at the end
> 
> > +ucom*  at ukspan?
> >  uftdi* at uhub?# FTDI FT8U100AX serial adapter
> >  ucom*  at uftdi?
> >  uplcom* at uhub?   # I/O DATA USB-RSAQ2 serial adapter
> > diff --git sys/dev/usb/files.usb sys/dev/usb/files.usb
> > index 1036cf36232..29bc1205540 100644
> > --- sys/dev/usb/files.usb
> > +++ sys/dev/usb/files.usb
> > @@ -317,6 +317,11 @@ device ubsa: ucombus
> >  attach ubsa at uhub
> >  file   dev/usb/ubsa.c  ubsa
> >  
> > +# Keyspan USA19HS serial
> > +device ukspan: ucombus
> > +attach ukspan at uhub
> > +file   dev/usb/ukspan.cukspan
> > +
> >  # Silicon Laboratories CP210x serial
> >  device uslcom: ucombus
> >  attach uslcom at uhub
> > diff --git sys/dev/usb/ukspan.c sys/dev/usb/ukspan.c
> > new file mode 100644
> > index 000..749144058a0
> > --- /dev/null
> > +++ sys/dev/usb/ukspan.c
> > @@ -0,0 +1,567 @@
> > +#include 
> 
> Please add a copyright and license at the top of the file.  
> /usr/share/misc/license.template is a good one to use.
> 
> Also, is there any documentation for the device that you used?  A 
> URL to it is always useful to include in the header.
> 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +
> > +#if 0
> > +   #define DBG(...) do { printf("ukspan " __VA_ARGS__); } while (0)
> > +#else
> > +   #define DBG(...)
> > +#endif
> 
> Can you put that behind an ifdef UKSPAN_DEBUG and leave a commented 
> out example?  That is usually how drivers do it.
> 
> /* #define UKSPAN_DEBUG */
> 
> #ifdef UKSPAN_DEBUG
> #define DPRINTF(x...)   do { printf(x); } while (0);
> #else
> #define DPRINTF(x...)
> #endif
> 
> > +#define UKSPAN_PARITY_NONE 0x0
> > +#define UKSPAN_PARITY_ODD  0x08
> > +#define UKSPAN_PARITY_EVEN 0x18
> > +
> > +#define UKSPAN_DATA_5  0x0
> > +#define UKSPAN_DATA_6  0x1
> > +#define UKSPAN_DATA_7  0x2
> > +#define UKSPAN_DATA_8  0x3
> > +
> > +#define UKSPAN_STOP_1  0x0
> > +#define UKSPAN_STOP_2  0x4
> > +
> > +#define UKSPAN_MAGIC   0x2
> > +
> > +#define UKSPAN_CLOCK   14769231
> > +
> > +/*
> > + * The following USB endpoint addresses may be specific to the Keyspan 
> > USA19HS
> > + * device
> > + */
> > +#define UKSPAN_CONFIG_IDX  1
> > +#define UKSPAN_IFACE_IDX   0
> > +
> > +#define UKSPAN_EA_BULKIN   (UE_DIR_IN  | 1)
> > +#define UKSPAN_EA_BULKOUT  (UE_DIR_OUT | 1)
> > +#define UKSPAN_EA_CONFIGIN (UE_DIR_IN  | 2)
> > +#define UKSPAN_EA_CONFIGOUT(UE_DIR_OUT | 2)
> > +
> > +/* Sent to device on control out endpoint */
> > +struct ukspan_cmsg {
> > +   uint8_t setclock;
> > +   uint8_t baudlo;
> > +   uint8_t baudhi;
> > +   uint8_t setlcr;
> > +   uint8_t lcr;
> > +   uint8_t setrxmode;
> > +   uint8_t rxmode;
> > +   uint8_t settxmode;
> > +   uint8_t txmode;
> > +   uint8_t settxflowcontrol;
> > +   uint8_t txflowcontrol;
> > +   uint8_t setrxflowcontrol;
> > +   uint8_t rxflowcontrol;
> > +   uint8_t sendxoff;
> > +   uint8_t sendxon;
> > +   uint8_t xonchar;
> > +   uint8_t xoffchar;
> > +   uint8_t sendchar;
> > +   uint8_t txchar;
> > +   uint8_t setrts;
> > +   uint8_t rts;
> > +   uint8_t setdtr;
> > +   uint8_t dtr;
> > +
> > +   uint8_t rxforwardingchars;
> > +   uint8_t rxforwardingtimeoutms;
> > +   uint8_t txacksetting;
> > +
> > +   uint8_t portenabled;
> > +   uint8_t txflush;
> > +   uint8_t txbreak;
> > +   uint8_t loopbackmode;
> > +
> > +   uint8_t rxflush;
> > +   uint8_t rxforward;
> > +   uint8_t cancelrxoff;
> > +   uint8_t returnstatus;
> > +};
> > +
> > +/* Received from device on control in endpoint */
> > +struct ukspan_smsg {
> > +   uint8_t msr;
> > +   uint8_t cts;
> > +   uint8_t dcd;
> > +   uint8_t dsr;
> > +   uint8_t ri;
> > +   uint8_t txxoff;
> > +   uint8_t rxbreak;
> > +   uint8_t rxoverrun;
> > +   uint8_t 

Re: [Patch] Driver for Keyspan USA-19HS

2019-05-29 Thread Tracey Emery
> 
> The routine for adding USB devices is to just add them to 
> /usr/src/sys/dev/usb/usbdevs, then run 'make' in 
> /usr/src/sys/dev/usb/.  That will automatically regenerate usbdevs.h 
> and usbdevs_data.h.

I'm happy to test when the new diff is submitted. I have a USA19HS
sitting in my desk.

Tracey



Re: [Patch] Driver for Keyspan USA-19HS

2019-05-28 Thread joshua stein
Hi,

Some feedback inline:

On Tue, 28 May 2019 at 18:42:51 -0400, Cody Cutler wrote:
> Hello tech, I'm submitting the following patch for inclusion. The patch
> implements a driver for the Keyspan USA-19HS USB-to-serial dongle.
> 
> I've used it for a few months now without any problems. Please let me know if
> you spot any problems.
> 
> Thanks!
> 
> diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
> index ad192f4ea1d..052915d10e0 100644
> --- sys/arch/amd64/conf/GENERIC
> +++ sys/arch/amd64/conf/GENERIC
> @@ -224,6 +224,8 @@ uvscom*   at uhub?# SUNTAC Slipper U 
> VS-10U serial
>  ucom*at uvscom?
>  ubsa*at uhub?# Belkin serial adapter
>  ucom*at ubsa?
> +ukspan* at uhub? # Keyspan USA19HS

Nit: maybe add "serial adapter" at the end

> +ucom*at ukspan?
>  uftdi*   at uhub?# FTDI FT8U100AX serial adapter
>  ucom*at uftdi?
>  uplcom* at uhub? # I/O DATA USB-RSAQ2 serial adapter
> diff --git sys/dev/usb/files.usb sys/dev/usb/files.usb
> index 1036cf36232..29bc1205540 100644
> --- sys/dev/usb/files.usb
> +++ sys/dev/usb/files.usb
> @@ -317,6 +317,11 @@ device   ubsa: ucombus
>  attach   ubsa at uhub
>  file dev/usb/ubsa.c  ubsa
>  
> +# Keyspan USA19HS serial
> +device   ukspan: ucombus
> +attach   ukspan at uhub
> +file dev/usb/ukspan.cukspan
> +
>  # Silicon Laboratories CP210x serial
>  device   uslcom: ucombus
>  attach   uslcom at uhub
> diff --git sys/dev/usb/ukspan.c sys/dev/usb/ukspan.c
> new file mode 100644
> index 000..749144058a0
> --- /dev/null
> +++ sys/dev/usb/ukspan.c
> @@ -0,0 +1,567 @@
> +#include 

Please add a copyright and license at the top of the file.  
/usr/share/misc/license.template is a good one to use.

Also, is there any documentation for the device that you used?  A 
URL to it is always useful to include in the header.

> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#if 0
> + #define DBG(...) do { printf("ukspan " __VA_ARGS__); } while (0)
> +#else
> + #define DBG(...)
> +#endif

Can you put that behind an ifdef UKSPAN_DEBUG and leave a commented 
out example?  That is usually how drivers do it.

/* #define UKSPAN_DEBUG */

#ifdef UKSPAN_DEBUG
#define DPRINTF(x...)   do { printf(x); } while (0);
#else
#define DPRINTF(x...)
#endif

> +#define UKSPAN_PARITY_NONE   0x0
> +#define UKSPAN_PARITY_ODD0x08
> +#define UKSPAN_PARITY_EVEN   0x18
> +
> +#define UKSPAN_DATA_50x0
> +#define UKSPAN_DATA_60x1
> +#define UKSPAN_DATA_70x2
> +#define UKSPAN_DATA_80x3
> +
> +#define UKSPAN_STOP_10x0
> +#define UKSPAN_STOP_20x4
> +
> +#define UKSPAN_MAGIC 0x2
> +
> +#define UKSPAN_CLOCK 14769231
> +
> +/*
> + * The following USB endpoint addresses may be specific to the Keyspan 
> USA19HS
> + * device
> + */
> +#define UKSPAN_CONFIG_IDX1
> +#define UKSPAN_IFACE_IDX 0
> +
> +#define UKSPAN_EA_BULKIN (UE_DIR_IN  | 1)
> +#define UKSPAN_EA_BULKOUT(UE_DIR_OUT | 1)
> +#define UKSPAN_EA_CONFIGIN   (UE_DIR_IN  | 2)
> +#define UKSPAN_EA_CONFIGOUT  (UE_DIR_OUT | 2)
> +
> +/* Sent to device on control out endpoint */
> +struct ukspan_cmsg {
> + uint8_t setclock;
> + uint8_t baudlo;
> + uint8_t baudhi;
> + uint8_t setlcr;
> + uint8_t lcr;
> + uint8_t setrxmode;
> + uint8_t rxmode;
> + uint8_t settxmode;
> + uint8_t txmode;
> + uint8_t settxflowcontrol;
> + uint8_t txflowcontrol;
> + uint8_t setrxflowcontrol;
> + uint8_t rxflowcontrol;
> + uint8_t sendxoff;
> + uint8_t sendxon;
> + uint8_t xonchar;
> + uint8_t xoffchar;
> + uint8_t sendchar;
> + uint8_t txchar;
> + uint8_t setrts;
> + uint8_t rts;
> + uint8_t setdtr;
> + uint8_t dtr;
> +
> + uint8_t rxforwardingchars;
> + uint8_t rxforwardingtimeoutms;
> + uint8_t txacksetting;
> +
> + uint8_t portenabled;
> + uint8_t txflush;
> + uint8_t txbreak;
> + uint8_t loopbackmode;
> +
> + uint8_t rxflush;
> + uint8_t rxforward;
> + uint8_t cancelrxoff;
> + uint8_t returnstatus;
> +};
> +
> +/* Received from device on control in endpoint */
> +struct ukspan_smsg {
> + uint8_t msr;
> + uint8_t cts;
> + uint8_t dcd;
> + uint8_t dsr;
> + uint8_t ri;
> + uint8_t txxoff;
> + uint8_t rxbreak;
> + uint8_t rxoverrun;
> + uint8_t rxparity;
> + uint8_t rxframe;
> + uint8_t portstate;
> + uint8_t messageack;
> + uint8_t charack;
> + uint8_t controlresp;
> +};

If these structures are communicated directly with the device, it's 
a good idea to make the structs have the __packed attribute.

struct ukspan_smsg {
...
} __packed;

> +
> +struct ukspan_softc {
> + 

[Patch] Driver for Keyspan USA-19HS

2019-05-28 Thread Cody Cutler
Hello tech, I'm submitting the following patch for inclusion. The patch
implements a driver for the Keyspan USA-19HS USB-to-serial dongle.

I've used it for a few months now without any problems. Please let me know if
you spot any problems.

Thanks!

diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
index ad192f4ea1d..052915d10e0 100644
--- sys/arch/amd64/conf/GENERIC
+++ sys/arch/amd64/conf/GENERIC
@@ -224,6 +224,8 @@ uvscom* at uhub?# SUNTAC Slipper U 
VS-10U serial
 ucom*  at uvscom?
 ubsa*  at uhub?# Belkin serial adapter
 ucom*  at ubsa?
+ukspan* at uhub?   # Keyspan USA19HS
+ucom*  at ukspan?
 uftdi* at uhub?# FTDI FT8U100AX serial adapter
 ucom*  at uftdi?
 uplcom* at uhub?   # I/O DATA USB-RSAQ2 serial adapter
diff --git sys/dev/usb/files.usb sys/dev/usb/files.usb
index 1036cf36232..29bc1205540 100644
--- sys/dev/usb/files.usb
+++ sys/dev/usb/files.usb
@@ -317,6 +317,11 @@ device ubsa: ucombus
 attach ubsa at uhub
 file   dev/usb/ubsa.c  ubsa
 
+# Keyspan USA19HS serial
+device ukspan: ucombus
+attach ukspan at uhub
+file   dev/usb/ukspan.cukspan
+
 # Silicon Laboratories CP210x serial
 device uslcom: ucombus
 attach uslcom at uhub
diff --git sys/dev/usb/ukspan.c sys/dev/usb/ukspan.c
new file mode 100644
index 000..749144058a0
--- /dev/null
+++ sys/dev/usb/ukspan.c
@@ -0,0 +1,567 @@
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#if 0
+   #define DBG(...) do { printf("ukspan " __VA_ARGS__); } while (0)
+#else
+   #define DBG(...)
+#endif
+
+#define UKSPAN_PARITY_NONE 0x0
+#define UKSPAN_PARITY_ODD  0x08
+#define UKSPAN_PARITY_EVEN 0x18
+
+#define UKSPAN_DATA_5  0x0
+#define UKSPAN_DATA_6  0x1
+#define UKSPAN_DATA_7  0x2
+#define UKSPAN_DATA_8  0x3
+
+#define UKSPAN_STOP_1  0x0
+#define UKSPAN_STOP_2  0x4
+
+#define UKSPAN_MAGIC   0x2
+
+#define UKSPAN_CLOCK   14769231
+
+/*
+ * The following USB endpoint addresses may be specific to the Keyspan USA19HS
+ * device
+ */
+#define UKSPAN_CONFIG_IDX  1
+#define UKSPAN_IFACE_IDX   0
+
+#define UKSPAN_EA_BULKIN   (UE_DIR_IN  | 1)
+#define UKSPAN_EA_BULKOUT  (UE_DIR_OUT | 1)
+#define UKSPAN_EA_CONFIGIN (UE_DIR_IN  | 2)
+#define UKSPAN_EA_CONFIGOUT(UE_DIR_OUT | 2)
+
+/* Sent to device on control out endpoint */
+struct ukspan_cmsg {
+   uint8_t setclock;
+   uint8_t baudlo;
+   uint8_t baudhi;
+   uint8_t setlcr;
+   uint8_t lcr;
+   uint8_t setrxmode;
+   uint8_t rxmode;
+   uint8_t settxmode;
+   uint8_t txmode;
+   uint8_t settxflowcontrol;
+   uint8_t txflowcontrol;
+   uint8_t setrxflowcontrol;
+   uint8_t rxflowcontrol;
+   uint8_t sendxoff;
+   uint8_t sendxon;
+   uint8_t xonchar;
+   uint8_t xoffchar;
+   uint8_t sendchar;
+   uint8_t txchar;
+   uint8_t setrts;
+   uint8_t rts;
+   uint8_t setdtr;
+   uint8_t dtr;
+
+   uint8_t rxforwardingchars;
+   uint8_t rxforwardingtimeoutms;
+   uint8_t txacksetting;
+
+   uint8_t portenabled;
+   uint8_t txflush;
+   uint8_t txbreak;
+   uint8_t loopbackmode;
+
+   uint8_t rxflush;
+   uint8_t rxforward;
+   uint8_t cancelrxoff;
+   uint8_t returnstatus;
+};
+
+/* Received from device on control in endpoint */
+struct ukspan_smsg {
+   uint8_t msr;
+   uint8_t cts;
+   uint8_t dcd;
+   uint8_t dsr;
+   uint8_t ri;
+   uint8_t txxoff;
+   uint8_t rxbreak;
+   uint8_t rxoverrun;
+   uint8_t rxparity;
+   uint8_t rxframe;
+   uint8_t portstate;
+   uint8_t messageack;
+   uint8_t charack;
+   uint8_t controlresp;
+};
+
+struct ukspan_softc {
+   struct device sc_dev;
+   struct usbd_device *udev;
+   struct usbd_interface *iface;
+   struct usbd_pipe *cout_pipe;
+   struct usbd_pipe *cin_pipe;
+   struct usbd_xfer *ixfer;
+   struct usbd_xfer *oxfer;
+   struct device *ucom_dev;
+   struct ukspan_smsg smsg;
+   struct ukspan_cmsg cmsg;
+   u_char lsr;
+   u_char msr;
+};
+
+int  ukspan_match(struct device *, void *, void *);
+void ukspan_attach(struct device *, struct device *, void *);
+int  ukspan_detach(struct device *, int);
+
+void ukspan_close(void *, int);
+int  ukspan_open(void *, int);
+int  ukspan_param(void *, int, struct termios *);
+void ukspan_set(void *, int, int, int);
+void ukspan_get_status(void *, int, u_char *, u_char *);
+
+void kmsg_init(bool, struct ukspan_cmsg *);
+int  send_cmsg(struct ukspan_softc *);
+void ukspan_incb(struct usbd_xfer *, void *, usbd_status);
+void ukspan_outcb(struct usbd_xfer *, void *, usbd_status);
+void ukspan_destroy(struct ukspan_softc *);
+
+struct cfdriver ukspan_cd = {
+   NULL, "ukspan", DV_DULL
+};
+
+const struct cfattach