FreeBSD kernel usb device Code
usb_serial.h
Go to the documentation of this file.
1/* $NetBSD: ucomvar.h,v 1.9 2001/01/23 21:56:17 augustss Exp $ */
2/* $FreeBSD$ */
3
4/*-
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
6 *
7 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32/*-
33 * Copyright (c) 1999 The NetBSD Foundation, Inc.
34 * All rights reserved.
35 *
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Lennart Augustsson (lennart@augustsson.net) at
38 * Carlstedt Research & Technology.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE.
60 */
61
62#ifndef _USB_SERIAL_H_
63#define _USB_SERIAL_H_
64
65#include <sys/tty.h>
66#include <sys/serial.h>
67#include <sys/fcntl.h>
68#include <sys/sysctl.h>
69#include <sys/timepps.h>
70
71/* Module interface related macros */
72#define UCOM_MODVER 1
73
74#define UCOM_MINVER 1
75#define UCOM_PREFVER UCOM_MODVER
76#define UCOM_MAXVER 1
77#define UCOM_JITTERBUF_SIZE 128 /* bytes */
78
79struct usb_device;
80struct ucom_softc;
82struct thread;
83
84/*
85 * NOTE: There is no guarantee that "ucom_cfg_close()" will
86 * be called after "ucom_cfg_open()" if the device is detached
87 * while it is open!
88 */
90 void (*ucom_cfg_get_status) (struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr);
91 void (*ucom_cfg_set_dtr) (struct ucom_softc *, uint8_t);
92 void (*ucom_cfg_set_rts) (struct ucom_softc *, uint8_t);
93 void (*ucom_cfg_set_break) (struct ucom_softc *, uint8_t);
94 void (*ucom_cfg_set_ring) (struct ucom_softc *, uint8_t);
95 void (*ucom_cfg_param) (struct ucom_softc *, struct termios *);
96 void (*ucom_cfg_open) (struct ucom_softc *);
97 void (*ucom_cfg_close) (struct ucom_softc *);
98 int (*ucom_pre_open) (struct ucom_softc *);
99 int (*ucom_pre_param) (struct ucom_softc *, struct termios *);
100 int (*ucom_ioctl) (struct ucom_softc *, uint32_t, caddr_t, int, struct thread *);
101 void (*ucom_start_read) (struct ucom_softc *);
102 void (*ucom_stop_read) (struct ucom_softc *);
103 void (*ucom_start_write) (struct ucom_softc *);
104 void (*ucom_stop_write) (struct ucom_softc *);
105 void (*ucom_tty_name) (struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t unit, uint16_t subunit);
106 void (*ucom_poll) (struct ucom_softc *);
107 void (*ucom_free) (struct ucom_softc *);
108};
109
110/* Line status register */
111#define ULSR_RCV_FIFO 0x80
112#define ULSR_TSRE 0x40 /* Transmitter empty: byte sent */
113#define ULSR_TXRDY 0x20 /* Transmitter buffer empty */
114#define ULSR_BI 0x10 /* Break detected */
115#define ULSR_FE 0x08 /* Framing error: bad stop bit */
116#define ULSR_PE 0x04 /* Parity error */
117#define ULSR_OE 0x02 /* Overrun, lost incoming byte */
118#define ULSR_RXRDY 0x01 /* Byte ready in Receive Buffer */
119#define ULSR_RCV_MASK 0x1f /* Mask for incoming data or error */
120
123 struct ucom_softc *sc;
124};
125
128 struct ucom_softc *sc;
129 struct termios termios_copy;
130};
131
137 int sc_flag; /* see UCOM_FLAG_XXX */
138 struct sysctl_oid *sc_sysctl_ttyname;
139 struct sysctl_oid *sc_sysctl_ttyports;
140 char sc_ttyname[16];
141};
142
144 /*
145 * NOTE: To avoid losing level change information we use two
146 * tasks instead of one for all commands.
147 *
148 * Level changes are transitions like:
149 *
150 * ON->OFF
151 * OFF->ON
152 * OPEN->CLOSE
153 * CLOSE->OPEN
154 */
161 /* pulse capturing support, PPS */
162 struct pps_state sc_pps;
163 /* Used to set "UCOM_FLAG_GP_DATA" flag: */
167 struct tty *sc_tty;
168 struct consdev *sc_consdev;
169 struct mtx *sc_mtx;
174 uint16_t sc_portno;
175 uint16_t sc_flag;
176#define UCOM_FLAG_RTS_IFLOW 0x01 /* use RTS input flow control */
177#define UCOM_FLAG_GONE 0x02 /* the device is gone */
178#define UCOM_FLAG_ATTACHED 0x04 /* set if attached */
179#define UCOM_FLAG_GP_DATA 0x08 /* set if get and put data is possible */
180#define UCOM_FLAG_LL_READY 0x20 /* set if low layer is ready */
181#define UCOM_FLAG_HL_READY 0x40 /* set if high layer is ready */
182#define UCOM_FLAG_CONSOLE 0x80 /* set if device is a console */
183#define UCOM_FLAG_WAIT_REFS 0x0100 /* set if we must wait for refs */
184#define UCOM_FLAG_FREE_UNIT 0x0200 /* set if we must free the unit */
185#define UCOM_FLAG_INWAKEUP 0x0400 /* set if we are in the tsw_inwakeup callback */
186#define UCOM_FLAG_LSRTXIDLE 0x0800 /* set if sc_lsr bits ULSR_TSRE+TXRDY work */
187#define UCOM_FLAG_DEVICE_MODE 0x1000 /* set if we're an USB device, not a host */
188 uint8_t sc_lsr;
189 uint8_t sc_msr;
190 uint8_t sc_mcr;
191 /* programmed line state bits */
192 uint8_t sc_pls_set; /* set bits */
193 uint8_t sc_pls_clr; /* cleared bits */
194 uint8_t sc_pls_curr; /* last state */
195#define UCOM_LS_DTR 0x01
196#define UCOM_LS_RTS 0x02
197#define UCOM_LS_BREAK 0x04
198#define UCOM_LS_RING 0x08
200};
201
202#define UCOM_MTX_ASSERT(sc, what) USB_MTX_ASSERT((sc)->sc_mtx, what)
203#define UCOM_MTX_LOCK(sc) USB_MTX_LOCK((sc)->sc_mtx)
204#define UCOM_MTX_UNLOCK(sc) USB_MTX_UNLOCK((sc)->sc_mtx)
205#define UCOM_UNLOAD_DRAIN(x) \
206SYSUNINIT(var, SI_SUB_KLD - 2, SI_ORDER_ANY, ucom_drain_all, 0)
207
208#define ucom_cfg_do_request(udev,com,req,ptr,flags,timo) \
209 usbd_do_request_proc(udev,&(com)->sc_super->sc_tq,req,ptr,flags,NULL,timo)
210
211int ucom_attach(struct ucom_super_softc *,
212 struct ucom_softc *, int, void *,
213 const struct ucom_callback *callback, struct mtx *);
214void ucom_detach(struct ucom_super_softc *, struct ucom_softc *);
215void ucom_set_pnpinfo_usb(struct ucom_super_softc *, device_t);
217void ucom_status_change(struct ucom_softc *);
218uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *,
219 uint32_t, uint32_t, uint32_t *);
220void ucom_put_data(struct ucom_softc *, struct usb_page_cache *,
221 uint32_t, uint32_t);
222uint8_t ucom_cfg_is_gone(struct ucom_softc *);
223void ucom_drain(struct ucom_super_softc *);
224void ucom_drain_all(void *);
225void ucom_ref(struct ucom_super_softc *);
226int ucom_unref(struct ucom_super_softc *);
227
228static inline void
230{
231
233}
234
235#endif /* _USB_SERIAL_H_ */
void(* ucom_tty_name)(struct ucom_softc *, char *pbuf, uint16_t buflen, uint16_t unit, uint16_t subunit)
Definition: usb_serial.h:105
void(* ucom_cfg_set_dtr)(struct ucom_softc *, uint8_t)
Definition: usb_serial.h:91
void(* ucom_stop_read)(struct ucom_softc *)
Definition: usb_serial.h:102
int(* ucom_pre_open)(struct ucom_softc *)
Definition: usb_serial.h:98
int(* ucom_pre_param)(struct ucom_softc *, struct termios *)
Definition: usb_serial.h:99
void(* ucom_cfg_set_rts)(struct ucom_softc *, uint8_t)
Definition: usb_serial.h:92
void(* ucom_cfg_set_break)(struct ucom_softc *, uint8_t)
Definition: usb_serial.h:93
void(* ucom_start_write)(struct ucom_softc *)
Definition: usb_serial.h:103
void(* ucom_cfg_open)(struct ucom_softc *)
Definition: usb_serial.h:96
void(* ucom_stop_write)(struct ucom_softc *)
Definition: usb_serial.h:104
void(* ucom_poll)(struct ucom_softc *)
Definition: usb_serial.h:106
void(* ucom_free)(struct ucom_softc *)
Definition: usb_serial.h:107
int(* ucom_ioctl)(struct ucom_softc *, uint32_t, caddr_t, int, struct thread *)
Definition: usb_serial.h:100
void(* ucom_start_read)(struct ucom_softc *)
Definition: usb_serial.h:101
void(* ucom_cfg_param)(struct ucom_softc *, struct termios *)
Definition: usb_serial.h:95
void(* ucom_cfg_close)(struct ucom_softc *)
Definition: usb_serial.h:97
void(* ucom_cfg_get_status)(struct ucom_softc *, uint8_t *plsr, uint8_t *pmsr)
Definition: usb_serial.h:90
void(* ucom_cfg_set_ring)(struct ucom_softc *, uint8_t)
Definition: usb_serial.h:94
struct ucom_softc * sc
Definition: usb_serial.h:123
struct usb_proc_msg hdr
Definition: usb_serial.h:122
struct usb_proc_msg hdr
Definition: usb_serial.h:127
struct termios termios_copy
Definition: usb_serial.h:129
struct ucom_softc * sc
Definition: usb_serial.h:128
struct ucom_cfg_task sc_status_task[2]
Definition: usb_serial.h:159
uint16_t sc_portno
Definition: usb_serial.h:174
struct tty * sc_tty
Definition: usb_serial.h:167
uint8_t sc_mcr
Definition: usb_serial.h:190
struct ucom_param_task sc_param_task[2]
Definition: usb_serial.h:160
void * sc_parent
Definition: usb_serial.h:170
struct ucom_cfg_task sc_line_state_task[2]
Definition: usb_serial.h:158
uint16_t sc_jitterbuf_in
Definition: usb_serial.h:172
struct ucom_super_softc * sc_super
Definition: usb_serial.h:166
uint16_t sc_flag
Definition: usb_serial.h:175
struct mtx * sc_mtx
Definition: usb_serial.h:169
struct ucom_cfg_task sc_close_task[2]
Definition: usb_serial.h:157
uint8_t sc_pls_clr
Definition: usb_serial.h:193
uint16_t sc_jitterbuf_out
Definition: usb_serial.h:173
uint8_t sc_jitterbuf[UCOM_JITTERBUF_SIZE]
Definition: usb_serial.h:199
struct consdev * sc_consdev
Definition: usb_serial.h:168
uint8_t sc_lsr
Definition: usb_serial.h:188
uint8_t sc_pls_curr
Definition: usb_serial.h:194
struct usb_proc_msg * sc_last_start_xfer
Definition: usb_serial.h:164
const struct ucom_callback * sc_callback
Definition: usb_serial.h:165
uint8_t sc_pls_set
Definition: usb_serial.h:192
struct ucom_cfg_task sc_start_task[2]
Definition: usb_serial.h:155
uint8_t sc_msr
Definition: usb_serial.h:189
struct pps_state sc_pps
Definition: usb_serial.h:162
int sc_subunit
Definition: usb_serial.h:171
struct ucom_cfg_task sc_open_task[2]
Definition: usb_serial.h:156
char sc_ttyname[16]
Definition: usb_serial.h:140
struct sysctl_oid * sc_sysctl_ttyports
Definition: usb_serial.h:139
struct sysctl_oid * sc_sysctl_ttyname
Definition: usb_serial.h:138
struct usb_process sc_tq
Definition: usb_serial.h:133
usb_hc_mode
Definition: usb.h:777
static void ucom_use_lsr_txbits(struct ucom_softc *sc)
Definition: usb_serial.h:229
void ucom_put_data(struct ucom_softc *, struct usb_page_cache *, uint32_t, uint32_t)
Definition: usb_serial.c:1462
#define UCOM_FLAG_LSRTXIDLE
Definition: usb_serial.h:186
void ucom_drain(struct ucom_super_softc *)
Definition: usb_serial.c:375
#define UCOM_JITTERBUF_SIZE
Definition: usb_serial.h:77
void ucom_ref(struct ucom_super_softc *)
Definition: usb_serial.c:1695
void ucom_detach(struct ucom_super_softc *, struct ucom_softc *)
Definition: usb_serial.c:336
void ucom_set_usb_mode(struct ucom_super_softc *, enum usb_hc_mode)
Definition: usb_serial.c:584
void ucom_drain_all(void *)
Definition: usb_serial.c:386
uint8_t ucom_cfg_is_gone(struct ucom_softc *)
Definition: usb_serial.c:667
void ucom_status_change(struct ucom_softc *)
Definition: usb_serial.c:1229
uint8_t ucom_get_data(struct ucom_softc *, struct usb_page_cache *, uint32_t, uint32_t, uint32_t *)
Definition: usb_serial.c:1384
int ucom_attach(struct ucom_super_softc *, struct ucom_softc *, int, void *, const struct ucom_callback *callback, struct mtx *)
Definition: usb_serial.c:267
void ucom_set_pnpinfo_usb(struct ucom_super_softc *, device_t)
Definition: usb_serial.c:549
int ucom_unref(struct ucom_super_softc *)
Definition: usb_serial.c:1730