Deleted Added
full compact
usb_dev.h (189906) usb_dev.h (190181)
1/* $FreeBSD: head/sys/dev/usb/usb_dev.h 189906 2009-03-17 01:46:40Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb/usb_dev.h 190181 2009-03-20 21:50:54Z thompsa $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef _USB2_DEV_H_
28#define _USB2_DEV_H_
29
30#include <sys/file.h>
31#include <sys/vnode.h>
32#include <sys/poll.h>
33#include <sys/signalvar.h>
34#include <sys/conf.h>
35#include <sys/fcntl.h>
36#include <sys/proc.h>
37
38#define USB_FIFO_TX 0
39#define USB_FIFO_RX 1
40
41struct usb2_fifo;
42struct usb2_mbuf;
43
44typedef int (usb2_fifo_open_t)(struct usb2_fifo *fifo, int fflags);
45typedef void (usb2_fifo_close_t)(struct usb2_fifo *fifo, int fflags);
46typedef int (usb2_fifo_ioctl_t)(struct usb2_fifo *fifo, u_long cmd, void *addr, int fflags);
47typedef void (usb2_fifo_cmd_t)(struct usb2_fifo *fifo);
48typedef void (usb2_fifo_filter_t)(struct usb2_fifo *fifo, struct usb2_mbuf *m);
49
50struct usb2_symlink {
51 TAILQ_ENTRY(usb2_symlink) sym_entry;
52 char src_path[32]; /* Source path - including terminating
53 * zero */
54 char dst_path[32]; /* Destination path - including
55 * terminating zero */
56 uint8_t src_len; /* String length */
57 uint8_t dst_len; /* String length */
58};
59
60/*
61 * Locking note for the following functions. All the
62 * "usb2_fifo_cmd_t" and "usb2_fifo_filter_t" functions are called
63 * locked. The others are called unlocked.
64 */
65struct usb2_fifo_methods {
66 usb2_fifo_open_t *f_open;
67 usb2_fifo_close_t *f_close;
68 usb2_fifo_ioctl_t *f_ioctl;
69 /*
70 * NOTE: The post-ioctl callback is called after the USB reference
71 * gets locked in the IOCTL handler:
72 */
73 usb2_fifo_ioctl_t *f_ioctl_post;
74 usb2_fifo_cmd_t *f_start_read;
75 usb2_fifo_cmd_t *f_stop_read;
76 usb2_fifo_cmd_t *f_start_write;
77 usb2_fifo_cmd_t *f_stop_write;
78 usb2_fifo_filter_t *f_filter_read;
79 usb2_fifo_filter_t *f_filter_write;
80 const char *basename[4];
81 const char *postfix[4];
82};
83
84/*
85 * Private per-device information.
86 */
87struct usb2_cdev_privdata {
88 struct usb2_bus *bus;
89 struct usb2_device *udev;
90 struct usb2_interface *iface;
91 struct usb2_fifo *rxfifo;
92 struct usb2_fifo *txfifo;
93 int bus_index; /* bus index */
94 int dev_index; /* device index */
95 int ep_addr; /* endpoint address */
96 int fflags;
97 uint8_t fifo_index; /* FIFO index */
98 uint8_t is_read; /* location has read access */
99 uint8_t is_write; /* location has write access */
100 uint8_t is_uref; /* USB refcount decr. needed */
101 uint8_t is_usbfs; /* USB-FS is active */
102};
103
104struct usb2_fs_privdata {
105 int bus_index;
106 int dev_index;
107 int ep_addr;
108 int mode;
109 int fifo_index;
110 struct cdev *cdev;
111
112 LIST_ENTRY(usb2_fs_privdata) pd_next;
113};
114
115/*
116 * Most of the fields in the "usb2_fifo" structure are used by the
117 * generic USB access layer.
118 */
119struct usb2_fifo {
120 struct usb2_ifqueue free_q;
121 struct usb2_ifqueue used_q;
122 struct selinfo selinfo;
123 struct cv cv_io;
124 struct cv cv_drain;
125 struct usb2_fifo_methods *methods;
126 struct usb2_symlink *symlink[2];/* our symlinks */
127 struct proc *async_p; /* process that wants SIGIO */
128 struct usb2_fs_endpoint *fs_ep_ptr;
129 struct usb2_device *udev;
130 struct usb2_xfer *xfer[2];
131 struct usb2_xfer **fs_xfer;
132 struct mtx *priv_mtx; /* client data */
133 /* set if FIFO is opened by a FILE: */
134 struct usb2_cdev_privdata *curr_cpd;
135 void *priv_sc0; /* client data */
136 void *priv_sc1; /* client data */
137 void *queue_data;
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef _USB2_DEV_H_
28#define _USB2_DEV_H_
29
30#include <sys/file.h>
31#include <sys/vnode.h>
32#include <sys/poll.h>
33#include <sys/signalvar.h>
34#include <sys/conf.h>
35#include <sys/fcntl.h>
36#include <sys/proc.h>
37
38#define USB_FIFO_TX 0
39#define USB_FIFO_RX 1
40
41struct usb2_fifo;
42struct usb2_mbuf;
43
44typedef int (usb2_fifo_open_t)(struct usb2_fifo *fifo, int fflags);
45typedef void (usb2_fifo_close_t)(struct usb2_fifo *fifo, int fflags);
46typedef int (usb2_fifo_ioctl_t)(struct usb2_fifo *fifo, u_long cmd, void *addr, int fflags);
47typedef void (usb2_fifo_cmd_t)(struct usb2_fifo *fifo);
48typedef void (usb2_fifo_filter_t)(struct usb2_fifo *fifo, struct usb2_mbuf *m);
49
50struct usb2_symlink {
51 TAILQ_ENTRY(usb2_symlink) sym_entry;
52 char src_path[32]; /* Source path - including terminating
53 * zero */
54 char dst_path[32]; /* Destination path - including
55 * terminating zero */
56 uint8_t src_len; /* String length */
57 uint8_t dst_len; /* String length */
58};
59
60/*
61 * Locking note for the following functions. All the
62 * "usb2_fifo_cmd_t" and "usb2_fifo_filter_t" functions are called
63 * locked. The others are called unlocked.
64 */
65struct usb2_fifo_methods {
66 usb2_fifo_open_t *f_open;
67 usb2_fifo_close_t *f_close;
68 usb2_fifo_ioctl_t *f_ioctl;
69 /*
70 * NOTE: The post-ioctl callback is called after the USB reference
71 * gets locked in the IOCTL handler:
72 */
73 usb2_fifo_ioctl_t *f_ioctl_post;
74 usb2_fifo_cmd_t *f_start_read;
75 usb2_fifo_cmd_t *f_stop_read;
76 usb2_fifo_cmd_t *f_start_write;
77 usb2_fifo_cmd_t *f_stop_write;
78 usb2_fifo_filter_t *f_filter_read;
79 usb2_fifo_filter_t *f_filter_write;
80 const char *basename[4];
81 const char *postfix[4];
82};
83
84/*
85 * Private per-device information.
86 */
87struct usb2_cdev_privdata {
88 struct usb2_bus *bus;
89 struct usb2_device *udev;
90 struct usb2_interface *iface;
91 struct usb2_fifo *rxfifo;
92 struct usb2_fifo *txfifo;
93 int bus_index; /* bus index */
94 int dev_index; /* device index */
95 int ep_addr; /* endpoint address */
96 int fflags;
97 uint8_t fifo_index; /* FIFO index */
98 uint8_t is_read; /* location has read access */
99 uint8_t is_write; /* location has write access */
100 uint8_t is_uref; /* USB refcount decr. needed */
101 uint8_t is_usbfs; /* USB-FS is active */
102};
103
104struct usb2_fs_privdata {
105 int bus_index;
106 int dev_index;
107 int ep_addr;
108 int mode;
109 int fifo_index;
110 struct cdev *cdev;
111
112 LIST_ENTRY(usb2_fs_privdata) pd_next;
113};
114
115/*
116 * Most of the fields in the "usb2_fifo" structure are used by the
117 * generic USB access layer.
118 */
119struct usb2_fifo {
120 struct usb2_ifqueue free_q;
121 struct usb2_ifqueue used_q;
122 struct selinfo selinfo;
123 struct cv cv_io;
124 struct cv cv_drain;
125 struct usb2_fifo_methods *methods;
126 struct usb2_symlink *symlink[2];/* our symlinks */
127 struct proc *async_p; /* process that wants SIGIO */
128 struct usb2_fs_endpoint *fs_ep_ptr;
129 struct usb2_device *udev;
130 struct usb2_xfer *xfer[2];
131 struct usb2_xfer **fs_xfer;
132 struct mtx *priv_mtx; /* client data */
133 /* set if FIFO is opened by a FILE: */
134 struct usb2_cdev_privdata *curr_cpd;
135 void *priv_sc0; /* client data */
136 void *priv_sc1; /* client data */
137 void *queue_data;
138 uint32_t timeout; /* timeout in milliseconds */
139 uint32_t bufsize; /* BULK and INTERRUPT buffer size */
140 uint16_t nframes; /* for isochronous mode */
138 usb2_timeout_t timeout; /* timeout in milliseconds */
139 usb2_frlength_t bufsize; /* BULK and INTERRUPT buffer size */
140 usb2_frcount_t nframes; /* for isochronous mode */
141 uint16_t dev_ep_index; /* our device endpoint index */
142 uint8_t flag_sleeping; /* set if FIFO is sleeping */
143 uint8_t flag_iscomplete; /* set if a USB transfer is complete */
144 uint8_t flag_iserror; /* set if FIFO error happened */
145 uint8_t flag_isselect; /* set if FIFO is selected */
146 uint8_t flag_flushing; /* set if FIFO is flushing data */
147 uint8_t flag_short; /* set if short_ok or force_short
148 * transfer flags should be set */
149 uint8_t flag_stall; /* set if clear stall should be run */
150 uint8_t iface_index; /* set to the interface we belong to */
151 uint8_t fifo_index; /* set to the FIFO index in "struct
152 * usb2_device" */
153 uint8_t fs_ep_max;
154 uint8_t fifo_zlp; /* zero length packet count */
155 uint8_t refcount;
156#define USB_FIFO_REF_MAX 0xFF
157};
158
159struct usb2_fifo_sc {
160 struct usb2_fifo *fp[2];
161 struct cdev* dev;
162};
163
164extern struct cdevsw usb2_devsw;
165
166int usb2_fifo_wait(struct usb2_fifo *fifo);
167void usb2_fifo_signal(struct usb2_fifo *fifo);
168int usb2_fifo_alloc_buffer(struct usb2_fifo *f, uint32_t bufsize,
169 uint16_t nbuf);
170void usb2_fifo_free_buffer(struct usb2_fifo *f);
171int usb2_fifo_attach(struct usb2_device *udev, void *priv_sc,
172 struct mtx *priv_mtx, struct usb2_fifo_methods *pm,
173 struct usb2_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
174 uint8_t iface_index, uid_t uid, gid_t gid, int mode);
175void usb2_fifo_detach(struct usb2_fifo_sc *f_sc);
176uint32_t usb2_fifo_put_bytes_max(struct usb2_fifo *fifo);
177void usb2_fifo_put_data(struct usb2_fifo *fifo, struct usb2_page_cache *pc,
141 uint16_t dev_ep_index; /* our device endpoint index */
142 uint8_t flag_sleeping; /* set if FIFO is sleeping */
143 uint8_t flag_iscomplete; /* set if a USB transfer is complete */
144 uint8_t flag_iserror; /* set if FIFO error happened */
145 uint8_t flag_isselect; /* set if FIFO is selected */
146 uint8_t flag_flushing; /* set if FIFO is flushing data */
147 uint8_t flag_short; /* set if short_ok or force_short
148 * transfer flags should be set */
149 uint8_t flag_stall; /* set if clear stall should be run */
150 uint8_t iface_index; /* set to the interface we belong to */
151 uint8_t fifo_index; /* set to the FIFO index in "struct
152 * usb2_device" */
153 uint8_t fs_ep_max;
154 uint8_t fifo_zlp; /* zero length packet count */
155 uint8_t refcount;
156#define USB_FIFO_REF_MAX 0xFF
157};
158
159struct usb2_fifo_sc {
160 struct usb2_fifo *fp[2];
161 struct cdev* dev;
162};
163
164extern struct cdevsw usb2_devsw;
165
166int usb2_fifo_wait(struct usb2_fifo *fifo);
167void usb2_fifo_signal(struct usb2_fifo *fifo);
168int usb2_fifo_alloc_buffer(struct usb2_fifo *f, uint32_t bufsize,
169 uint16_t nbuf);
170void usb2_fifo_free_buffer(struct usb2_fifo *f);
171int usb2_fifo_attach(struct usb2_device *udev, void *priv_sc,
172 struct mtx *priv_mtx, struct usb2_fifo_methods *pm,
173 struct usb2_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
174 uint8_t iface_index, uid_t uid, gid_t gid, int mode);
175void usb2_fifo_detach(struct usb2_fifo_sc *f_sc);
176uint32_t usb2_fifo_put_bytes_max(struct usb2_fifo *fifo);
177void usb2_fifo_put_data(struct usb2_fifo *fifo, struct usb2_page_cache *pc,
178 uint32_t offset, uint32_t len, uint8_t what);
178 usb2_frlength_t offset, usb2_frlength_t len, uint8_t what);
179void usb2_fifo_put_data_linear(struct usb2_fifo *fifo, void *ptr,
179void usb2_fifo_put_data_linear(struct usb2_fifo *fifo, void *ptr,
180 uint32_t len, uint8_t what);
181uint8_t usb2_fifo_put_data_buffer(struct usb2_fifo *f, void *ptr, uint32_t len);
180 usb2_size_t len, uint8_t what);
181uint8_t usb2_fifo_put_data_buffer(struct usb2_fifo *f, void *ptr, usb2_size_t len);
182void usb2_fifo_put_data_error(struct usb2_fifo *fifo);
183uint8_t usb2_fifo_get_data(struct usb2_fifo *fifo, struct usb2_page_cache *pc,
182void usb2_fifo_put_data_error(struct usb2_fifo *fifo);
183uint8_t usb2_fifo_get_data(struct usb2_fifo *fifo, struct usb2_page_cache *pc,
184 uint32_t offset, uint32_t len, uint32_t *actlen, uint8_t what);
184 usb2_frlength_t offset, usb2_frlength_t len, usb2_frlength_t *actlen,
185 uint8_t what);
185uint8_t usb2_fifo_get_data_linear(struct usb2_fifo *fifo, void *ptr,
186uint8_t usb2_fifo_get_data_linear(struct usb2_fifo *fifo, void *ptr,
186 uint32_t len, uint32_t *actlen, uint8_t what);
187 usb2_size_t len, usb2_size_t *actlen, uint8_t what);
187uint8_t usb2_fifo_get_data_buffer(struct usb2_fifo *f, void **pptr,
188uint8_t usb2_fifo_get_data_buffer(struct usb2_fifo *f, void **pptr,
188 uint32_t *plen);
189 usb2_size_t *plen);
189void usb2_fifo_get_data_error(struct usb2_fifo *fifo);
190uint8_t usb2_fifo_opened(struct usb2_fifo *fifo);
191void usb2_fifo_free(struct usb2_fifo *f);
192void usb2_fifo_reset(struct usb2_fifo *f);
193void usb2_fifo_wakeup(struct usb2_fifo *f);
194struct usb2_symlink *usb2_alloc_symlink(const char *target);
195void usb2_free_symlink(struct usb2_symlink *ps);
196int usb2_read_symlink(uint8_t *user_ptr, uint32_t startentry,
197 uint32_t user_len);
198void usb2_fifo_set_close_zlp(struct usb2_fifo *, uint8_t);
199
200#endif /* _USB2_DEV_H_ */
190void usb2_fifo_get_data_error(struct usb2_fifo *fifo);
191uint8_t usb2_fifo_opened(struct usb2_fifo *fifo);
192void usb2_fifo_free(struct usb2_fifo *f);
193void usb2_fifo_reset(struct usb2_fifo *f);
194void usb2_fifo_wakeup(struct usb2_fifo *f);
195struct usb2_symlink *usb2_alloc_symlink(const char *target);
196void usb2_free_symlink(struct usb2_symlink *ps);
197int usb2_read_symlink(uint8_t *user_ptr, uint32_t startentry,
198 uint32_t user_len);
199void usb2_fifo_set_close_zlp(struct usb2_fifo *, uint8_t);
200
201#endif /* _USB2_DEV_H_ */