Commit e136e3036bf27569dbfeae245cc09c7167cdc749
Committed by
Linus Torvalds
1 parent
33dd474ae7
Exists in
master
and in
4 other branches
hso: net driver using tty without locking
Checking tty == NULL doesn't help us unless we have a clear semantic for the locking of the tty object in the driver. Use the tty kref objects so that we can take references to the tty in the USB event handling paths. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 42 additions and 12 deletions Inline Diff
drivers/net/usb/hso.c
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | * |
3 | * Driver for Option High Speed Mobile Devices. | 3 | * Driver for Option High Speed Mobile Devices. |
4 | * | 4 | * |
5 | * Copyright (C) 2008 Option International | 5 | * Copyright (C) 2008 Option International |
6 | * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd) | 6 | * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd) |
7 | * <ajb@spheresystems.co.uk> | 7 | * <ajb@spheresystems.co.uk> |
8 | * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> | 8 | * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> |
9 | * Copyright (C) 2008 Novell, Inc. | 9 | * Copyright (C) 2008 Novell, Inc. |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License version 2 as | 12 | * it under the terms of the GNU General Public License version 2 as |
13 | * published by the Free Software Foundation. | 13 | * published by the Free Software Foundation. |
14 | * | 14 | * |
15 | * This program is distributed in the hope that it will be useful, | 15 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. | 18 | * GNU General Public License for more details. |
19 | * | 19 | * |
20 | * You should have received a copy of the GNU General Public License | 20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software | 21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
23 | * USA | 23 | * USA |
24 | * | 24 | * |
25 | * | 25 | * |
26 | *****************************************************************************/ | 26 | *****************************************************************************/ |
27 | 27 | ||
28 | /****************************************************************************** | 28 | /****************************************************************************** |
29 | * | 29 | * |
30 | * Description of the device: | 30 | * Description of the device: |
31 | * | 31 | * |
32 | * Interface 0: Contains the IP network interface on the bulk end points. | 32 | * Interface 0: Contains the IP network interface on the bulk end points. |
33 | * The multiplexed serial ports are using the interrupt and | 33 | * The multiplexed serial ports are using the interrupt and |
34 | * control endpoints. | 34 | * control endpoints. |
35 | * Interrupt contains a bitmap telling which multiplexed | 35 | * Interrupt contains a bitmap telling which multiplexed |
36 | * serialport needs servicing. | 36 | * serialport needs servicing. |
37 | * | 37 | * |
38 | * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the | 38 | * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the |
39 | * port is opened, as this have a huge impact on the network port | 39 | * port is opened, as this have a huge impact on the network port |
40 | * throughput. | 40 | * throughput. |
41 | * | 41 | * |
42 | * Interface 2: Standard modem interface - circuit switched interface, should | 42 | * Interface 2: Standard modem interface - circuit switched interface, should |
43 | * not be used. | 43 | * not be used. |
44 | * | 44 | * |
45 | *****************************************************************************/ | 45 | *****************************************************************************/ |
46 | 46 | ||
47 | #include <linux/sched.h> | 47 | #include <linux/sched.h> |
48 | #include <linux/slab.h> | 48 | #include <linux/slab.h> |
49 | #include <linux/init.h> | 49 | #include <linux/init.h> |
50 | #include <linux/delay.h> | 50 | #include <linux/delay.h> |
51 | #include <linux/netdevice.h> | 51 | #include <linux/netdevice.h> |
52 | #include <linux/module.h> | 52 | #include <linux/module.h> |
53 | #include <linux/ethtool.h> | 53 | #include <linux/ethtool.h> |
54 | #include <linux/usb.h> | 54 | #include <linux/usb.h> |
55 | #include <linux/timer.h> | 55 | #include <linux/timer.h> |
56 | #include <linux/tty.h> | 56 | #include <linux/tty.h> |
57 | #include <linux/tty_driver.h> | 57 | #include <linux/tty_driver.h> |
58 | #include <linux/tty_flip.h> | 58 | #include <linux/tty_flip.h> |
59 | #include <linux/kmod.h> | 59 | #include <linux/kmod.h> |
60 | #include <linux/rfkill.h> | 60 | #include <linux/rfkill.h> |
61 | #include <linux/ip.h> | 61 | #include <linux/ip.h> |
62 | #include <linux/uaccess.h> | 62 | #include <linux/uaccess.h> |
63 | #include <linux/usb/cdc.h> | 63 | #include <linux/usb/cdc.h> |
64 | #include <net/arp.h> | 64 | #include <net/arp.h> |
65 | #include <asm/byteorder.h> | 65 | #include <asm/byteorder.h> |
66 | 66 | ||
67 | 67 | ||
68 | #define DRIVER_VERSION "1.2" | 68 | #define DRIVER_VERSION "1.2" |
69 | #define MOD_AUTHOR "Option Wireless" | 69 | #define MOD_AUTHOR "Option Wireless" |
70 | #define MOD_DESCRIPTION "USB High Speed Option driver" | 70 | #define MOD_DESCRIPTION "USB High Speed Option driver" |
71 | #define MOD_LICENSE "GPL" | 71 | #define MOD_LICENSE "GPL" |
72 | 72 | ||
73 | #define HSO_MAX_NET_DEVICES 10 | 73 | #define HSO_MAX_NET_DEVICES 10 |
74 | #define HSO__MAX_MTU 2048 | 74 | #define HSO__MAX_MTU 2048 |
75 | #define DEFAULT_MTU 1500 | 75 | #define DEFAULT_MTU 1500 |
76 | #define DEFAULT_MRU 1500 | 76 | #define DEFAULT_MRU 1500 |
77 | 77 | ||
78 | #define CTRL_URB_RX_SIZE 1024 | 78 | #define CTRL_URB_RX_SIZE 1024 |
79 | #define CTRL_URB_TX_SIZE 64 | 79 | #define CTRL_URB_TX_SIZE 64 |
80 | 80 | ||
81 | #define BULK_URB_RX_SIZE 4096 | 81 | #define BULK_URB_RX_SIZE 4096 |
82 | #define BULK_URB_TX_SIZE 8192 | 82 | #define BULK_URB_TX_SIZE 8192 |
83 | 83 | ||
84 | #define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU | 84 | #define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU |
85 | #define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU | 85 | #define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU |
86 | #define MUX_BULK_RX_BUF_COUNT 4 | 86 | #define MUX_BULK_RX_BUF_COUNT 4 |
87 | #define USB_TYPE_OPTION_VENDOR 0x20 | 87 | #define USB_TYPE_OPTION_VENDOR 0x20 |
88 | 88 | ||
89 | /* These definitions are used with the struct hso_net flags element */ | 89 | /* These definitions are used with the struct hso_net flags element */ |
90 | /* - use *_bit operations on it. (bit indices not values.) */ | 90 | /* - use *_bit operations on it. (bit indices not values.) */ |
91 | #define HSO_NET_RUNNING 0 | 91 | #define HSO_NET_RUNNING 0 |
92 | 92 | ||
93 | #define HSO_NET_TX_TIMEOUT (HZ*10) | 93 | #define HSO_NET_TX_TIMEOUT (HZ*10) |
94 | 94 | ||
95 | #define HSO_SERIAL_MAGIC 0x48534f31 | 95 | #define HSO_SERIAL_MAGIC 0x48534f31 |
96 | 96 | ||
97 | /* Number of ttys to handle */ | 97 | /* Number of ttys to handle */ |
98 | #define HSO_SERIAL_TTY_MINORS 256 | 98 | #define HSO_SERIAL_TTY_MINORS 256 |
99 | 99 | ||
100 | #define MAX_RX_URBS 2 | 100 | #define MAX_RX_URBS 2 |
101 | 101 | ||
102 | static inline struct hso_serial *get_serial_by_tty(struct tty_struct *tty) | 102 | static inline struct hso_serial *get_serial_by_tty(struct tty_struct *tty) |
103 | { | 103 | { |
104 | if (tty) | 104 | if (tty) |
105 | return tty->driver_data; | 105 | return tty->driver_data; |
106 | return NULL; | 106 | return NULL; |
107 | } | 107 | } |
108 | 108 | ||
109 | /*****************************************************************************/ | 109 | /*****************************************************************************/ |
110 | /* Debugging functions */ | 110 | /* Debugging functions */ |
111 | /*****************************************************************************/ | 111 | /*****************************************************************************/ |
112 | #define D__(lvl_, fmt, arg...) \ | 112 | #define D__(lvl_, fmt, arg...) \ |
113 | do { \ | 113 | do { \ |
114 | printk(lvl_ "[%d:%s]: " fmt "\n", \ | 114 | printk(lvl_ "[%d:%s]: " fmt "\n", \ |
115 | __LINE__, __func__, ## arg); \ | 115 | __LINE__, __func__, ## arg); \ |
116 | } while (0) | 116 | } while (0) |
117 | 117 | ||
118 | #define D_(lvl, args...) \ | 118 | #define D_(lvl, args...) \ |
119 | do { \ | 119 | do { \ |
120 | if (lvl & debug) \ | 120 | if (lvl & debug) \ |
121 | D__(KERN_INFO, args); \ | 121 | D__(KERN_INFO, args); \ |
122 | } while (0) | 122 | } while (0) |
123 | 123 | ||
124 | #define D1(args...) D_(0x01, ##args) | 124 | #define D1(args...) D_(0x01, ##args) |
125 | #define D2(args...) D_(0x02, ##args) | 125 | #define D2(args...) D_(0x02, ##args) |
126 | #define D3(args...) D_(0x04, ##args) | 126 | #define D3(args...) D_(0x04, ##args) |
127 | #define D4(args...) D_(0x08, ##args) | 127 | #define D4(args...) D_(0x08, ##args) |
128 | #define D5(args...) D_(0x10, ##args) | 128 | #define D5(args...) D_(0x10, ##args) |
129 | 129 | ||
130 | /*****************************************************************************/ | 130 | /*****************************************************************************/ |
131 | /* Enumerators */ | 131 | /* Enumerators */ |
132 | /*****************************************************************************/ | 132 | /*****************************************************************************/ |
133 | enum pkt_parse_state { | 133 | enum pkt_parse_state { |
134 | WAIT_IP, | 134 | WAIT_IP, |
135 | WAIT_DATA, | 135 | WAIT_DATA, |
136 | WAIT_SYNC | 136 | WAIT_SYNC |
137 | }; | 137 | }; |
138 | 138 | ||
139 | /*****************************************************************************/ | 139 | /*****************************************************************************/ |
140 | /* Structs */ | 140 | /* Structs */ |
141 | /*****************************************************************************/ | 141 | /*****************************************************************************/ |
142 | 142 | ||
143 | struct hso_shared_int { | 143 | struct hso_shared_int { |
144 | struct usb_endpoint_descriptor *intr_endp; | 144 | struct usb_endpoint_descriptor *intr_endp; |
145 | void *shared_intr_buf; | 145 | void *shared_intr_buf; |
146 | struct urb *shared_intr_urb; | 146 | struct urb *shared_intr_urb; |
147 | struct usb_device *usb; | 147 | struct usb_device *usb; |
148 | int use_count; | 148 | int use_count; |
149 | int ref_count; | 149 | int ref_count; |
150 | struct mutex shared_int_lock; | 150 | struct mutex shared_int_lock; |
151 | }; | 151 | }; |
152 | 152 | ||
153 | struct hso_net { | 153 | struct hso_net { |
154 | struct hso_device *parent; | 154 | struct hso_device *parent; |
155 | struct net_device *net; | 155 | struct net_device *net; |
156 | struct rfkill *rfkill; | 156 | struct rfkill *rfkill; |
157 | 157 | ||
158 | struct usb_endpoint_descriptor *in_endp; | 158 | struct usb_endpoint_descriptor *in_endp; |
159 | struct usb_endpoint_descriptor *out_endp; | 159 | struct usb_endpoint_descriptor *out_endp; |
160 | 160 | ||
161 | struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT]; | 161 | struct urb *mux_bulk_rx_urb_pool[MUX_BULK_RX_BUF_COUNT]; |
162 | struct urb *mux_bulk_tx_urb; | 162 | struct urb *mux_bulk_tx_urb; |
163 | void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT]; | 163 | void *mux_bulk_rx_buf_pool[MUX_BULK_RX_BUF_COUNT]; |
164 | void *mux_bulk_tx_buf; | 164 | void *mux_bulk_tx_buf; |
165 | 165 | ||
166 | struct sk_buff *skb_rx_buf; | 166 | struct sk_buff *skb_rx_buf; |
167 | struct sk_buff *skb_tx_buf; | 167 | struct sk_buff *skb_tx_buf; |
168 | 168 | ||
169 | enum pkt_parse_state rx_parse_state; | 169 | enum pkt_parse_state rx_parse_state; |
170 | spinlock_t net_lock; | 170 | spinlock_t net_lock; |
171 | 171 | ||
172 | unsigned short rx_buf_size; | 172 | unsigned short rx_buf_size; |
173 | unsigned short rx_buf_missing; | 173 | unsigned short rx_buf_missing; |
174 | struct iphdr rx_ip_hdr; | 174 | struct iphdr rx_ip_hdr; |
175 | 175 | ||
176 | unsigned long flags; | 176 | unsigned long flags; |
177 | }; | 177 | }; |
178 | 178 | ||
179 | enum rx_ctrl_state{ | 179 | enum rx_ctrl_state{ |
180 | RX_IDLE, | 180 | RX_IDLE, |
181 | RX_SENT, | 181 | RX_SENT, |
182 | RX_PENDING | 182 | RX_PENDING |
183 | }; | 183 | }; |
184 | 184 | ||
185 | struct hso_serial { | 185 | struct hso_serial { |
186 | struct hso_device *parent; | 186 | struct hso_device *parent; |
187 | int magic; | 187 | int magic; |
188 | u8 minor; | 188 | u8 minor; |
189 | 189 | ||
190 | struct hso_shared_int *shared_int; | 190 | struct hso_shared_int *shared_int; |
191 | 191 | ||
192 | /* rx/tx urb could be either a bulk urb or a control urb depending | 192 | /* rx/tx urb could be either a bulk urb or a control urb depending |
193 | on which serial port it is used on. */ | 193 | on which serial port it is used on. */ |
194 | struct urb *rx_urb[MAX_RX_URBS]; | 194 | struct urb *rx_urb[MAX_RX_URBS]; |
195 | u8 num_rx_urbs; | 195 | u8 num_rx_urbs; |
196 | u8 *rx_data[MAX_RX_URBS]; | 196 | u8 *rx_data[MAX_RX_URBS]; |
197 | u16 rx_data_length; /* should contain allocated length */ | 197 | u16 rx_data_length; /* should contain allocated length */ |
198 | 198 | ||
199 | struct urb *tx_urb; | 199 | struct urb *tx_urb; |
200 | u8 *tx_data; | 200 | u8 *tx_data; |
201 | u8 *tx_buffer; | 201 | u8 *tx_buffer; |
202 | u16 tx_data_length; /* should contain allocated length */ | 202 | u16 tx_data_length; /* should contain allocated length */ |
203 | u16 tx_data_count; | 203 | u16 tx_data_count; |
204 | u16 tx_buffer_count; | 204 | u16 tx_buffer_count; |
205 | struct usb_ctrlrequest ctrl_req_tx; | 205 | struct usb_ctrlrequest ctrl_req_tx; |
206 | struct usb_ctrlrequest ctrl_req_rx; | 206 | struct usb_ctrlrequest ctrl_req_rx; |
207 | 207 | ||
208 | struct usb_endpoint_descriptor *in_endp; | 208 | struct usb_endpoint_descriptor *in_endp; |
209 | struct usb_endpoint_descriptor *out_endp; | 209 | struct usb_endpoint_descriptor *out_endp; |
210 | 210 | ||
211 | enum rx_ctrl_state rx_state; | 211 | enum rx_ctrl_state rx_state; |
212 | u8 rts_state; | 212 | u8 rts_state; |
213 | u8 dtr_state; | 213 | u8 dtr_state; |
214 | unsigned tx_urb_used:1; | 214 | unsigned tx_urb_used:1; |
215 | 215 | ||
216 | /* from usb_serial_port */ | 216 | /* from usb_serial_port */ |
217 | struct tty_struct *tty; | 217 | struct tty_struct *tty; |
218 | int open_count; | 218 | int open_count; |
219 | spinlock_t serial_lock; | 219 | spinlock_t serial_lock; |
220 | 220 | ||
221 | int (*write_data) (struct hso_serial *serial); | 221 | int (*write_data) (struct hso_serial *serial); |
222 | /* Hacks required to get flow control | 222 | /* Hacks required to get flow control |
223 | * working on the serial receive buffers | 223 | * working on the serial receive buffers |
224 | * so as not to drop characters on the floor. | 224 | * so as not to drop characters on the floor. |
225 | */ | 225 | */ |
226 | int curr_rx_urb_idx; | 226 | int curr_rx_urb_idx; |
227 | u16 curr_rx_urb_offset; | 227 | u16 curr_rx_urb_offset; |
228 | u8 rx_urb_filled[MAX_RX_URBS]; | 228 | u8 rx_urb_filled[MAX_RX_URBS]; |
229 | struct tasklet_struct unthrottle_tasklet; | 229 | struct tasklet_struct unthrottle_tasklet; |
230 | struct work_struct retry_unthrottle_workqueue; | 230 | struct work_struct retry_unthrottle_workqueue; |
231 | }; | 231 | }; |
232 | 232 | ||
233 | struct hso_device { | 233 | struct hso_device { |
234 | union { | 234 | union { |
235 | struct hso_serial *dev_serial; | 235 | struct hso_serial *dev_serial; |
236 | struct hso_net *dev_net; | 236 | struct hso_net *dev_net; |
237 | } port_data; | 237 | } port_data; |
238 | 238 | ||
239 | u32 port_spec; | 239 | u32 port_spec; |
240 | 240 | ||
241 | u8 is_active; | 241 | u8 is_active; |
242 | u8 usb_gone; | 242 | u8 usb_gone; |
243 | struct work_struct async_get_intf; | 243 | struct work_struct async_get_intf; |
244 | struct work_struct async_put_intf; | 244 | struct work_struct async_put_intf; |
245 | 245 | ||
246 | struct usb_device *usb; | 246 | struct usb_device *usb; |
247 | struct usb_interface *interface; | 247 | struct usb_interface *interface; |
248 | 248 | ||
249 | struct device *dev; | 249 | struct device *dev; |
250 | struct kref ref; | 250 | struct kref ref; |
251 | struct mutex mutex; | 251 | struct mutex mutex; |
252 | }; | 252 | }; |
253 | 253 | ||
254 | /* Type of interface */ | 254 | /* Type of interface */ |
255 | #define HSO_INTF_MASK 0xFF00 | 255 | #define HSO_INTF_MASK 0xFF00 |
256 | #define HSO_INTF_MUX 0x0100 | 256 | #define HSO_INTF_MUX 0x0100 |
257 | #define HSO_INTF_BULK 0x0200 | 257 | #define HSO_INTF_BULK 0x0200 |
258 | 258 | ||
259 | /* Type of port */ | 259 | /* Type of port */ |
260 | #define HSO_PORT_MASK 0xFF | 260 | #define HSO_PORT_MASK 0xFF |
261 | #define HSO_PORT_NO_PORT 0x0 | 261 | #define HSO_PORT_NO_PORT 0x0 |
262 | #define HSO_PORT_CONTROL 0x1 | 262 | #define HSO_PORT_CONTROL 0x1 |
263 | #define HSO_PORT_APP 0x2 | 263 | #define HSO_PORT_APP 0x2 |
264 | #define HSO_PORT_GPS 0x3 | 264 | #define HSO_PORT_GPS 0x3 |
265 | #define HSO_PORT_PCSC 0x4 | 265 | #define HSO_PORT_PCSC 0x4 |
266 | #define HSO_PORT_APP2 0x5 | 266 | #define HSO_PORT_APP2 0x5 |
267 | #define HSO_PORT_GPS_CONTROL 0x6 | 267 | #define HSO_PORT_GPS_CONTROL 0x6 |
268 | #define HSO_PORT_MSD 0x7 | 268 | #define HSO_PORT_MSD 0x7 |
269 | #define HSO_PORT_VOICE 0x8 | 269 | #define HSO_PORT_VOICE 0x8 |
270 | #define HSO_PORT_DIAG2 0x9 | 270 | #define HSO_PORT_DIAG2 0x9 |
271 | #define HSO_PORT_DIAG 0x10 | 271 | #define HSO_PORT_DIAG 0x10 |
272 | #define HSO_PORT_MODEM 0x11 | 272 | #define HSO_PORT_MODEM 0x11 |
273 | #define HSO_PORT_NETWORK 0x12 | 273 | #define HSO_PORT_NETWORK 0x12 |
274 | 274 | ||
275 | /* Additional device info */ | 275 | /* Additional device info */ |
276 | #define HSO_INFO_MASK 0xFF000000 | 276 | #define HSO_INFO_MASK 0xFF000000 |
277 | #define HSO_INFO_CRC_BUG 0x01000000 | 277 | #define HSO_INFO_CRC_BUG 0x01000000 |
278 | 278 | ||
279 | /*****************************************************************************/ | 279 | /*****************************************************************************/ |
280 | /* Prototypes */ | 280 | /* Prototypes */ |
281 | /*****************************************************************************/ | 281 | /*****************************************************************************/ |
282 | /* Serial driver functions */ | 282 | /* Serial driver functions */ |
283 | static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file, | 283 | static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file, |
284 | unsigned int set, unsigned int clear); | 284 | unsigned int set, unsigned int clear); |
285 | static void ctrl_callback(struct urb *urb); | 285 | static void ctrl_callback(struct urb *urb); |
286 | static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial); | 286 | static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial); |
287 | static void hso_kick_transmit(struct hso_serial *serial); | 287 | static void hso_kick_transmit(struct hso_serial *serial); |
288 | /* Helper functions */ | 288 | /* Helper functions */ |
289 | static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int, | 289 | static int hso_mux_submit_intr_urb(struct hso_shared_int *mux_int, |
290 | struct usb_device *usb, gfp_t gfp); | 290 | struct usb_device *usb, gfp_t gfp); |
291 | static void log_usb_status(int status, const char *function); | 291 | static void log_usb_status(int status, const char *function); |
292 | static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, | 292 | static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, |
293 | int type, int dir); | 293 | int type, int dir); |
294 | static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports); | 294 | static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports); |
295 | static void hso_free_interface(struct usb_interface *intf); | 295 | static void hso_free_interface(struct usb_interface *intf); |
296 | static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags); | 296 | static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags); |
297 | static int hso_stop_serial_device(struct hso_device *hso_dev); | 297 | static int hso_stop_serial_device(struct hso_device *hso_dev); |
298 | static int hso_start_net_device(struct hso_device *hso_dev); | 298 | static int hso_start_net_device(struct hso_device *hso_dev); |
299 | static void hso_free_shared_int(struct hso_shared_int *shared_int); | 299 | static void hso_free_shared_int(struct hso_shared_int *shared_int); |
300 | static int hso_stop_net_device(struct hso_device *hso_dev); | 300 | static int hso_stop_net_device(struct hso_device *hso_dev); |
301 | static void hso_serial_ref_free(struct kref *ref); | 301 | static void hso_serial_ref_free(struct kref *ref); |
302 | static void hso_std_serial_read_bulk_callback(struct urb *urb); | 302 | static void hso_std_serial_read_bulk_callback(struct urb *urb); |
303 | static int hso_mux_serial_read(struct hso_serial *serial); | 303 | static int hso_mux_serial_read(struct hso_serial *serial); |
304 | static void async_get_intf(struct work_struct *data); | 304 | static void async_get_intf(struct work_struct *data); |
305 | static void async_put_intf(struct work_struct *data); | 305 | static void async_put_intf(struct work_struct *data); |
306 | static int hso_put_activity(struct hso_device *hso_dev); | 306 | static int hso_put_activity(struct hso_device *hso_dev); |
307 | static int hso_get_activity(struct hso_device *hso_dev); | 307 | static int hso_get_activity(struct hso_device *hso_dev); |
308 | 308 | ||
309 | /*****************************************************************************/ | 309 | /*****************************************************************************/ |
310 | /* Helping functions */ | 310 | /* Helping functions */ |
311 | /*****************************************************************************/ | 311 | /*****************************************************************************/ |
312 | 312 | ||
313 | /* #define DEBUG */ | 313 | /* #define DEBUG */ |
314 | 314 | ||
315 | static inline struct hso_net *dev2net(struct hso_device *hso_dev) | 315 | static inline struct hso_net *dev2net(struct hso_device *hso_dev) |
316 | { | 316 | { |
317 | return hso_dev->port_data.dev_net; | 317 | return hso_dev->port_data.dev_net; |
318 | } | 318 | } |
319 | 319 | ||
320 | static inline struct hso_serial *dev2ser(struct hso_device *hso_dev) | 320 | static inline struct hso_serial *dev2ser(struct hso_device *hso_dev) |
321 | { | 321 | { |
322 | return hso_dev->port_data.dev_serial; | 322 | return hso_dev->port_data.dev_serial; |
323 | } | 323 | } |
324 | 324 | ||
325 | /* Debugging functions */ | 325 | /* Debugging functions */ |
326 | #ifdef DEBUG | 326 | #ifdef DEBUG |
327 | static void dbg_dump(int line_count, const char *func_name, unsigned char *buf, | 327 | static void dbg_dump(int line_count, const char *func_name, unsigned char *buf, |
328 | unsigned int len) | 328 | unsigned int len) |
329 | { | 329 | { |
330 | static char name[255]; | 330 | static char name[255]; |
331 | 331 | ||
332 | sprintf(name, "hso[%d:%s]", line_count, func_name); | 332 | sprintf(name, "hso[%d:%s]", line_count, func_name); |
333 | print_hex_dump_bytes(name, DUMP_PREFIX_NONE, buf, len); | 333 | print_hex_dump_bytes(name, DUMP_PREFIX_NONE, buf, len); |
334 | } | 334 | } |
335 | 335 | ||
336 | #define DUMP(buf_, len_) \ | 336 | #define DUMP(buf_, len_) \ |
337 | dbg_dump(__LINE__, __func__, buf_, len_) | 337 | dbg_dump(__LINE__, __func__, buf_, len_) |
338 | 338 | ||
339 | #define DUMP1(buf_, len_) \ | 339 | #define DUMP1(buf_, len_) \ |
340 | do { \ | 340 | do { \ |
341 | if (0x01 & debug) \ | 341 | if (0x01 & debug) \ |
342 | DUMP(buf_, len_); \ | 342 | DUMP(buf_, len_); \ |
343 | } while (0) | 343 | } while (0) |
344 | #else | 344 | #else |
345 | #define DUMP(buf_, len_) | 345 | #define DUMP(buf_, len_) |
346 | #define DUMP1(buf_, len_) | 346 | #define DUMP1(buf_, len_) |
347 | #endif | 347 | #endif |
348 | 348 | ||
349 | /* module parameters */ | 349 | /* module parameters */ |
350 | static int debug; | 350 | static int debug; |
351 | static int tty_major; | 351 | static int tty_major; |
352 | static int disable_net; | 352 | static int disable_net; |
353 | 353 | ||
354 | /* driver info */ | 354 | /* driver info */ |
355 | static const char driver_name[] = "hso"; | 355 | static const char driver_name[] = "hso"; |
356 | static const char tty_filename[] = "ttyHS"; | 356 | static const char tty_filename[] = "ttyHS"; |
357 | static const char *version = __FILE__ ": " DRIVER_VERSION " " MOD_AUTHOR; | 357 | static const char *version = __FILE__ ": " DRIVER_VERSION " " MOD_AUTHOR; |
358 | /* the usb driver itself (registered in hso_init) */ | 358 | /* the usb driver itself (registered in hso_init) */ |
359 | static struct usb_driver hso_driver; | 359 | static struct usb_driver hso_driver; |
360 | /* serial structures */ | 360 | /* serial structures */ |
361 | static struct tty_driver *tty_drv; | 361 | static struct tty_driver *tty_drv; |
362 | static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS]; | 362 | static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS]; |
363 | static struct hso_device *network_table[HSO_MAX_NET_DEVICES]; | 363 | static struct hso_device *network_table[HSO_MAX_NET_DEVICES]; |
364 | static spinlock_t serial_table_lock; | 364 | static spinlock_t serial_table_lock; |
365 | static struct ktermios *hso_serial_termios[HSO_SERIAL_TTY_MINORS]; | 365 | static struct ktermios *hso_serial_termios[HSO_SERIAL_TTY_MINORS]; |
366 | static struct ktermios *hso_serial_termios_locked[HSO_SERIAL_TTY_MINORS]; | 366 | static struct ktermios *hso_serial_termios_locked[HSO_SERIAL_TTY_MINORS]; |
367 | 367 | ||
368 | static const s32 default_port_spec[] = { | 368 | static const s32 default_port_spec[] = { |
369 | HSO_INTF_MUX | HSO_PORT_NETWORK, | 369 | HSO_INTF_MUX | HSO_PORT_NETWORK, |
370 | HSO_INTF_BULK | HSO_PORT_DIAG, | 370 | HSO_INTF_BULK | HSO_PORT_DIAG, |
371 | HSO_INTF_BULK | HSO_PORT_MODEM, | 371 | HSO_INTF_BULK | HSO_PORT_MODEM, |
372 | 0 | 372 | 0 |
373 | }; | 373 | }; |
374 | 374 | ||
375 | static const s32 icon321_port_spec[] = { | 375 | static const s32 icon321_port_spec[] = { |
376 | HSO_INTF_MUX | HSO_PORT_NETWORK, | 376 | HSO_INTF_MUX | HSO_PORT_NETWORK, |
377 | HSO_INTF_BULK | HSO_PORT_DIAG2, | 377 | HSO_INTF_BULK | HSO_PORT_DIAG2, |
378 | HSO_INTF_BULK | HSO_PORT_MODEM, | 378 | HSO_INTF_BULK | HSO_PORT_MODEM, |
379 | HSO_INTF_BULK | HSO_PORT_DIAG, | 379 | HSO_INTF_BULK | HSO_PORT_DIAG, |
380 | 0 | 380 | 0 |
381 | }; | 381 | }; |
382 | 382 | ||
383 | #define default_port_device(vendor, product) \ | 383 | #define default_port_device(vendor, product) \ |
384 | USB_DEVICE(vendor, product), \ | 384 | USB_DEVICE(vendor, product), \ |
385 | .driver_info = (kernel_ulong_t)default_port_spec | 385 | .driver_info = (kernel_ulong_t)default_port_spec |
386 | 386 | ||
387 | #define icon321_port_device(vendor, product) \ | 387 | #define icon321_port_device(vendor, product) \ |
388 | USB_DEVICE(vendor, product), \ | 388 | USB_DEVICE(vendor, product), \ |
389 | .driver_info = (kernel_ulong_t)icon321_port_spec | 389 | .driver_info = (kernel_ulong_t)icon321_port_spec |
390 | 390 | ||
391 | /* list of devices we support */ | 391 | /* list of devices we support */ |
392 | static const struct usb_device_id hso_ids[] = { | 392 | static const struct usb_device_id hso_ids[] = { |
393 | {default_port_device(0x0af0, 0x6711)}, | 393 | {default_port_device(0x0af0, 0x6711)}, |
394 | {default_port_device(0x0af0, 0x6731)}, | 394 | {default_port_device(0x0af0, 0x6731)}, |
395 | {default_port_device(0x0af0, 0x6751)}, | 395 | {default_port_device(0x0af0, 0x6751)}, |
396 | {default_port_device(0x0af0, 0x6771)}, | 396 | {default_port_device(0x0af0, 0x6771)}, |
397 | {default_port_device(0x0af0, 0x6791)}, | 397 | {default_port_device(0x0af0, 0x6791)}, |
398 | {default_port_device(0x0af0, 0x6811)}, | 398 | {default_port_device(0x0af0, 0x6811)}, |
399 | {default_port_device(0x0af0, 0x6911)}, | 399 | {default_port_device(0x0af0, 0x6911)}, |
400 | {default_port_device(0x0af0, 0x6951)}, | 400 | {default_port_device(0x0af0, 0x6951)}, |
401 | {default_port_device(0x0af0, 0x6971)}, | 401 | {default_port_device(0x0af0, 0x6971)}, |
402 | {default_port_device(0x0af0, 0x7011)}, | 402 | {default_port_device(0x0af0, 0x7011)}, |
403 | {default_port_device(0x0af0, 0x7031)}, | 403 | {default_port_device(0x0af0, 0x7031)}, |
404 | {default_port_device(0x0af0, 0x7051)}, | 404 | {default_port_device(0x0af0, 0x7051)}, |
405 | {default_port_device(0x0af0, 0x7071)}, | 405 | {default_port_device(0x0af0, 0x7071)}, |
406 | {default_port_device(0x0af0, 0x7111)}, | 406 | {default_port_device(0x0af0, 0x7111)}, |
407 | {default_port_device(0x0af0, 0x7211)}, | 407 | {default_port_device(0x0af0, 0x7211)}, |
408 | {default_port_device(0x0af0, 0x7251)}, | 408 | {default_port_device(0x0af0, 0x7251)}, |
409 | {default_port_device(0x0af0, 0x7271)}, | 409 | {default_port_device(0x0af0, 0x7271)}, |
410 | {default_port_device(0x0af0, 0x7311)}, | 410 | {default_port_device(0x0af0, 0x7311)}, |
411 | {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */ | 411 | {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */ |
412 | {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */ | 412 | {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */ |
413 | {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */ | 413 | {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */ |
414 | {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */ | 414 | {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */ |
415 | {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */ | 415 | {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */ |
416 | {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */ | 416 | {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */ |
417 | {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */ | 417 | {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */ |
418 | {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */ | 418 | {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */ |
419 | {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */ | 419 | {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */ |
420 | {USB_DEVICE(0x0af0, 0x7701)}, | 420 | {USB_DEVICE(0x0af0, 0x7701)}, |
421 | {USB_DEVICE(0x0af0, 0x7801)}, | 421 | {USB_DEVICE(0x0af0, 0x7801)}, |
422 | {USB_DEVICE(0x0af0, 0x7901)}, | 422 | {USB_DEVICE(0x0af0, 0x7901)}, |
423 | {USB_DEVICE(0x0af0, 0x7361)}, | 423 | {USB_DEVICE(0x0af0, 0x7361)}, |
424 | {icon321_port_device(0x0af0, 0xd051)}, | 424 | {icon321_port_device(0x0af0, 0xd051)}, |
425 | {} | 425 | {} |
426 | }; | 426 | }; |
427 | MODULE_DEVICE_TABLE(usb, hso_ids); | 427 | MODULE_DEVICE_TABLE(usb, hso_ids); |
428 | 428 | ||
429 | /* Sysfs attribute */ | 429 | /* Sysfs attribute */ |
430 | static ssize_t hso_sysfs_show_porttype(struct device *dev, | 430 | static ssize_t hso_sysfs_show_porttype(struct device *dev, |
431 | struct device_attribute *attr, | 431 | struct device_attribute *attr, |
432 | char *buf) | 432 | char *buf) |
433 | { | 433 | { |
434 | struct hso_device *hso_dev = dev->driver_data; | 434 | struct hso_device *hso_dev = dev->driver_data; |
435 | char *port_name; | 435 | char *port_name; |
436 | 436 | ||
437 | if (!hso_dev) | 437 | if (!hso_dev) |
438 | return 0; | 438 | return 0; |
439 | 439 | ||
440 | switch (hso_dev->port_spec & HSO_PORT_MASK) { | 440 | switch (hso_dev->port_spec & HSO_PORT_MASK) { |
441 | case HSO_PORT_CONTROL: | 441 | case HSO_PORT_CONTROL: |
442 | port_name = "Control"; | 442 | port_name = "Control"; |
443 | break; | 443 | break; |
444 | case HSO_PORT_APP: | 444 | case HSO_PORT_APP: |
445 | port_name = "Application"; | 445 | port_name = "Application"; |
446 | break; | 446 | break; |
447 | case HSO_PORT_APP2: | 447 | case HSO_PORT_APP2: |
448 | port_name = "Application2"; | 448 | port_name = "Application2"; |
449 | break; | 449 | break; |
450 | case HSO_PORT_GPS: | 450 | case HSO_PORT_GPS: |
451 | port_name = "GPS"; | 451 | port_name = "GPS"; |
452 | break; | 452 | break; |
453 | case HSO_PORT_GPS_CONTROL: | 453 | case HSO_PORT_GPS_CONTROL: |
454 | port_name = "GPS Control"; | 454 | port_name = "GPS Control"; |
455 | break; | 455 | break; |
456 | case HSO_PORT_PCSC: | 456 | case HSO_PORT_PCSC: |
457 | port_name = "PCSC"; | 457 | port_name = "PCSC"; |
458 | break; | 458 | break; |
459 | case HSO_PORT_DIAG: | 459 | case HSO_PORT_DIAG: |
460 | port_name = "Diagnostic"; | 460 | port_name = "Diagnostic"; |
461 | break; | 461 | break; |
462 | case HSO_PORT_DIAG2: | 462 | case HSO_PORT_DIAG2: |
463 | port_name = "Diagnostic2"; | 463 | port_name = "Diagnostic2"; |
464 | break; | 464 | break; |
465 | case HSO_PORT_MODEM: | 465 | case HSO_PORT_MODEM: |
466 | port_name = "Modem"; | 466 | port_name = "Modem"; |
467 | break; | 467 | break; |
468 | case HSO_PORT_NETWORK: | 468 | case HSO_PORT_NETWORK: |
469 | port_name = "Network"; | 469 | port_name = "Network"; |
470 | break; | 470 | break; |
471 | default: | 471 | default: |
472 | port_name = "Unknown"; | 472 | port_name = "Unknown"; |
473 | break; | 473 | break; |
474 | } | 474 | } |
475 | 475 | ||
476 | return sprintf(buf, "%s\n", port_name); | 476 | return sprintf(buf, "%s\n", port_name); |
477 | } | 477 | } |
478 | static DEVICE_ATTR(hsotype, S_IRUGO, hso_sysfs_show_porttype, NULL); | 478 | static DEVICE_ATTR(hsotype, S_IRUGO, hso_sysfs_show_porttype, NULL); |
479 | 479 | ||
480 | static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb) | 480 | static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb) |
481 | { | 481 | { |
482 | int idx; | 482 | int idx; |
483 | 483 | ||
484 | for (idx = 0; idx < serial->num_rx_urbs; idx++) | 484 | for (idx = 0; idx < serial->num_rx_urbs; idx++) |
485 | if (serial->rx_urb[idx] == urb) | 485 | if (serial->rx_urb[idx] == urb) |
486 | return idx; | 486 | return idx; |
487 | dev_err(serial->parent->dev, "hso_urb_to_index failed\n"); | 487 | dev_err(serial->parent->dev, "hso_urb_to_index failed\n"); |
488 | return -1; | 488 | return -1; |
489 | } | 489 | } |
490 | 490 | ||
491 | /* converts mux value to a port spec value */ | 491 | /* converts mux value to a port spec value */ |
492 | static u32 hso_mux_to_port(int mux) | 492 | static u32 hso_mux_to_port(int mux) |
493 | { | 493 | { |
494 | u32 result; | 494 | u32 result; |
495 | 495 | ||
496 | switch (mux) { | 496 | switch (mux) { |
497 | case 0x1: | 497 | case 0x1: |
498 | result = HSO_PORT_CONTROL; | 498 | result = HSO_PORT_CONTROL; |
499 | break; | 499 | break; |
500 | case 0x2: | 500 | case 0x2: |
501 | result = HSO_PORT_APP; | 501 | result = HSO_PORT_APP; |
502 | break; | 502 | break; |
503 | case 0x4: | 503 | case 0x4: |
504 | result = HSO_PORT_PCSC; | 504 | result = HSO_PORT_PCSC; |
505 | break; | 505 | break; |
506 | case 0x8: | 506 | case 0x8: |
507 | result = HSO_PORT_GPS; | 507 | result = HSO_PORT_GPS; |
508 | break; | 508 | break; |
509 | case 0x10: | 509 | case 0x10: |
510 | result = HSO_PORT_APP2; | 510 | result = HSO_PORT_APP2; |
511 | break; | 511 | break; |
512 | default: | 512 | default: |
513 | result = HSO_PORT_NO_PORT; | 513 | result = HSO_PORT_NO_PORT; |
514 | } | 514 | } |
515 | return result; | 515 | return result; |
516 | } | 516 | } |
517 | 517 | ||
518 | /* converts port spec value to a mux value */ | 518 | /* converts port spec value to a mux value */ |
519 | static u32 hso_port_to_mux(int port) | 519 | static u32 hso_port_to_mux(int port) |
520 | { | 520 | { |
521 | u32 result; | 521 | u32 result; |
522 | 522 | ||
523 | switch (port & HSO_PORT_MASK) { | 523 | switch (port & HSO_PORT_MASK) { |
524 | case HSO_PORT_CONTROL: | 524 | case HSO_PORT_CONTROL: |
525 | result = 0x0; | 525 | result = 0x0; |
526 | break; | 526 | break; |
527 | case HSO_PORT_APP: | 527 | case HSO_PORT_APP: |
528 | result = 0x1; | 528 | result = 0x1; |
529 | break; | 529 | break; |
530 | case HSO_PORT_PCSC: | 530 | case HSO_PORT_PCSC: |
531 | result = 0x2; | 531 | result = 0x2; |
532 | break; | 532 | break; |
533 | case HSO_PORT_GPS: | 533 | case HSO_PORT_GPS: |
534 | result = 0x3; | 534 | result = 0x3; |
535 | break; | 535 | break; |
536 | case HSO_PORT_APP2: | 536 | case HSO_PORT_APP2: |
537 | result = 0x4; | 537 | result = 0x4; |
538 | break; | 538 | break; |
539 | default: | 539 | default: |
540 | result = 0x0; | 540 | result = 0x0; |
541 | } | 541 | } |
542 | return result; | 542 | return result; |
543 | } | 543 | } |
544 | 544 | ||
545 | static struct hso_serial *get_serial_by_shared_int_and_type( | 545 | static struct hso_serial *get_serial_by_shared_int_and_type( |
546 | struct hso_shared_int *shared_int, | 546 | struct hso_shared_int *shared_int, |
547 | int mux) | 547 | int mux) |
548 | { | 548 | { |
549 | int i, port; | 549 | int i, port; |
550 | 550 | ||
551 | port = hso_mux_to_port(mux); | 551 | port = hso_mux_to_port(mux); |
552 | 552 | ||
553 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { | 553 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { |
554 | if (serial_table[i] | 554 | if (serial_table[i] |
555 | && (dev2ser(serial_table[i])->shared_int == shared_int) | 555 | && (dev2ser(serial_table[i])->shared_int == shared_int) |
556 | && ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) { | 556 | && ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) { |
557 | return dev2ser(serial_table[i]); | 557 | return dev2ser(serial_table[i]); |
558 | } | 558 | } |
559 | } | 559 | } |
560 | 560 | ||
561 | return NULL; | 561 | return NULL; |
562 | } | 562 | } |
563 | 563 | ||
564 | static struct hso_serial *get_serial_by_index(unsigned index) | 564 | static struct hso_serial *get_serial_by_index(unsigned index) |
565 | { | 565 | { |
566 | struct hso_serial *serial = NULL; | 566 | struct hso_serial *serial = NULL; |
567 | unsigned long flags; | 567 | unsigned long flags; |
568 | 568 | ||
569 | spin_lock_irqsave(&serial_table_lock, flags); | 569 | spin_lock_irqsave(&serial_table_lock, flags); |
570 | if (serial_table[index]) | 570 | if (serial_table[index]) |
571 | serial = dev2ser(serial_table[index]); | 571 | serial = dev2ser(serial_table[index]); |
572 | spin_unlock_irqrestore(&serial_table_lock, flags); | 572 | spin_unlock_irqrestore(&serial_table_lock, flags); |
573 | 573 | ||
574 | return serial; | 574 | return serial; |
575 | } | 575 | } |
576 | 576 | ||
577 | static int get_free_serial_index(void) | 577 | static int get_free_serial_index(void) |
578 | { | 578 | { |
579 | int index; | 579 | int index; |
580 | unsigned long flags; | 580 | unsigned long flags; |
581 | 581 | ||
582 | spin_lock_irqsave(&serial_table_lock, flags); | 582 | spin_lock_irqsave(&serial_table_lock, flags); |
583 | for (index = 0; index < HSO_SERIAL_TTY_MINORS; index++) { | 583 | for (index = 0; index < HSO_SERIAL_TTY_MINORS; index++) { |
584 | if (serial_table[index] == NULL) { | 584 | if (serial_table[index] == NULL) { |
585 | spin_unlock_irqrestore(&serial_table_lock, flags); | 585 | spin_unlock_irqrestore(&serial_table_lock, flags); |
586 | return index; | 586 | return index; |
587 | } | 587 | } |
588 | } | 588 | } |
589 | spin_unlock_irqrestore(&serial_table_lock, flags); | 589 | spin_unlock_irqrestore(&serial_table_lock, flags); |
590 | 590 | ||
591 | printk(KERN_ERR "%s: no free serial devices in table\n", __func__); | 591 | printk(KERN_ERR "%s: no free serial devices in table\n", __func__); |
592 | return -1; | 592 | return -1; |
593 | } | 593 | } |
594 | 594 | ||
595 | static void set_serial_by_index(unsigned index, struct hso_serial *serial) | 595 | static void set_serial_by_index(unsigned index, struct hso_serial *serial) |
596 | { | 596 | { |
597 | unsigned long flags; | 597 | unsigned long flags; |
598 | 598 | ||
599 | spin_lock_irqsave(&serial_table_lock, flags); | 599 | spin_lock_irqsave(&serial_table_lock, flags); |
600 | if (serial) | 600 | if (serial) |
601 | serial_table[index] = serial->parent; | 601 | serial_table[index] = serial->parent; |
602 | else | 602 | else |
603 | serial_table[index] = NULL; | 603 | serial_table[index] = NULL; |
604 | spin_unlock_irqrestore(&serial_table_lock, flags); | 604 | spin_unlock_irqrestore(&serial_table_lock, flags); |
605 | } | 605 | } |
606 | 606 | ||
607 | /* log a meaningful explanation of an USB status */ | 607 | /* log a meaningful explanation of an USB status */ |
608 | static void log_usb_status(int status, const char *function) | 608 | static void log_usb_status(int status, const char *function) |
609 | { | 609 | { |
610 | char *explanation; | 610 | char *explanation; |
611 | 611 | ||
612 | switch (status) { | 612 | switch (status) { |
613 | case -ENODEV: | 613 | case -ENODEV: |
614 | explanation = "no device"; | 614 | explanation = "no device"; |
615 | break; | 615 | break; |
616 | case -ENOENT: | 616 | case -ENOENT: |
617 | explanation = "endpoint not enabled"; | 617 | explanation = "endpoint not enabled"; |
618 | break; | 618 | break; |
619 | case -EPIPE: | 619 | case -EPIPE: |
620 | explanation = "endpoint stalled"; | 620 | explanation = "endpoint stalled"; |
621 | break; | 621 | break; |
622 | case -ENOSPC: | 622 | case -ENOSPC: |
623 | explanation = "not enough bandwidth"; | 623 | explanation = "not enough bandwidth"; |
624 | break; | 624 | break; |
625 | case -ESHUTDOWN: | 625 | case -ESHUTDOWN: |
626 | explanation = "device disabled"; | 626 | explanation = "device disabled"; |
627 | break; | 627 | break; |
628 | case -EHOSTUNREACH: | 628 | case -EHOSTUNREACH: |
629 | explanation = "device suspended"; | 629 | explanation = "device suspended"; |
630 | break; | 630 | break; |
631 | case -EINVAL: | 631 | case -EINVAL: |
632 | case -EAGAIN: | 632 | case -EAGAIN: |
633 | case -EFBIG: | 633 | case -EFBIG: |
634 | case -EMSGSIZE: | 634 | case -EMSGSIZE: |
635 | explanation = "internal error"; | 635 | explanation = "internal error"; |
636 | break; | 636 | break; |
637 | default: | 637 | default: |
638 | explanation = "unknown status"; | 638 | explanation = "unknown status"; |
639 | break; | 639 | break; |
640 | } | 640 | } |
641 | D1("%s: received USB status - %s (%d)", function, explanation, status); | 641 | D1("%s: received USB status - %s (%d)", function, explanation, status); |
642 | } | 642 | } |
643 | 643 | ||
644 | /* Network interface functions */ | 644 | /* Network interface functions */ |
645 | 645 | ||
646 | /* called when net interface is brought up by ifconfig */ | 646 | /* called when net interface is brought up by ifconfig */ |
647 | static int hso_net_open(struct net_device *net) | 647 | static int hso_net_open(struct net_device *net) |
648 | { | 648 | { |
649 | struct hso_net *odev = netdev_priv(net); | 649 | struct hso_net *odev = netdev_priv(net); |
650 | unsigned long flags = 0; | 650 | unsigned long flags = 0; |
651 | 651 | ||
652 | if (!odev) { | 652 | if (!odev) { |
653 | dev_err(&net->dev, "No net device !\n"); | 653 | dev_err(&net->dev, "No net device !\n"); |
654 | return -ENODEV; | 654 | return -ENODEV; |
655 | } | 655 | } |
656 | 656 | ||
657 | odev->skb_tx_buf = NULL; | 657 | odev->skb_tx_buf = NULL; |
658 | 658 | ||
659 | /* setup environment */ | 659 | /* setup environment */ |
660 | spin_lock_irqsave(&odev->net_lock, flags); | 660 | spin_lock_irqsave(&odev->net_lock, flags); |
661 | odev->rx_parse_state = WAIT_IP; | 661 | odev->rx_parse_state = WAIT_IP; |
662 | odev->rx_buf_size = 0; | 662 | odev->rx_buf_size = 0; |
663 | odev->rx_buf_missing = sizeof(struct iphdr); | 663 | odev->rx_buf_missing = sizeof(struct iphdr); |
664 | spin_unlock_irqrestore(&odev->net_lock, flags); | 664 | spin_unlock_irqrestore(&odev->net_lock, flags); |
665 | 665 | ||
666 | /* We are up and running. */ | 666 | /* We are up and running. */ |
667 | set_bit(HSO_NET_RUNNING, &odev->flags); | 667 | set_bit(HSO_NET_RUNNING, &odev->flags); |
668 | hso_start_net_device(odev->parent); | 668 | hso_start_net_device(odev->parent); |
669 | 669 | ||
670 | /* Tell the kernel we are ready to start receiving from it */ | 670 | /* Tell the kernel we are ready to start receiving from it */ |
671 | netif_start_queue(net); | 671 | netif_start_queue(net); |
672 | 672 | ||
673 | return 0; | 673 | return 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | /* called when interface is brought down by ifconfig */ | 676 | /* called when interface is brought down by ifconfig */ |
677 | static int hso_net_close(struct net_device *net) | 677 | static int hso_net_close(struct net_device *net) |
678 | { | 678 | { |
679 | struct hso_net *odev = netdev_priv(net); | 679 | struct hso_net *odev = netdev_priv(net); |
680 | 680 | ||
681 | /* we don't need the queue anymore */ | 681 | /* we don't need the queue anymore */ |
682 | netif_stop_queue(net); | 682 | netif_stop_queue(net); |
683 | /* no longer running */ | 683 | /* no longer running */ |
684 | clear_bit(HSO_NET_RUNNING, &odev->flags); | 684 | clear_bit(HSO_NET_RUNNING, &odev->flags); |
685 | 685 | ||
686 | hso_stop_net_device(odev->parent); | 686 | hso_stop_net_device(odev->parent); |
687 | 687 | ||
688 | /* done */ | 688 | /* done */ |
689 | return 0; | 689 | return 0; |
690 | } | 690 | } |
691 | 691 | ||
692 | /* USB tells is xmit done, we should start the netqueue again */ | 692 | /* USB tells is xmit done, we should start the netqueue again */ |
693 | static void write_bulk_callback(struct urb *urb) | 693 | static void write_bulk_callback(struct urb *urb) |
694 | { | 694 | { |
695 | struct hso_net *odev = urb->context; | 695 | struct hso_net *odev = urb->context; |
696 | int status = urb->status; | 696 | int status = urb->status; |
697 | 697 | ||
698 | /* Sanity check */ | 698 | /* Sanity check */ |
699 | if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { | 699 | if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { |
700 | dev_err(&urb->dev->dev, "%s: device not running\n", __func__); | 700 | dev_err(&urb->dev->dev, "%s: device not running\n", __func__); |
701 | return; | 701 | return; |
702 | } | 702 | } |
703 | 703 | ||
704 | /* Do we still have a valid kernel network device? */ | 704 | /* Do we still have a valid kernel network device? */ |
705 | if (!netif_device_present(odev->net)) { | 705 | if (!netif_device_present(odev->net)) { |
706 | dev_err(&urb->dev->dev, "%s: net device not present\n", | 706 | dev_err(&urb->dev->dev, "%s: net device not present\n", |
707 | __func__); | 707 | __func__); |
708 | return; | 708 | return; |
709 | } | 709 | } |
710 | 710 | ||
711 | /* log status, but don't act on it, we don't need to resubmit anything | 711 | /* log status, but don't act on it, we don't need to resubmit anything |
712 | * anyhow */ | 712 | * anyhow */ |
713 | if (status) | 713 | if (status) |
714 | log_usb_status(status, __func__); | 714 | log_usb_status(status, __func__); |
715 | 715 | ||
716 | hso_put_activity(odev->parent); | 716 | hso_put_activity(odev->parent); |
717 | 717 | ||
718 | /* Tell the network interface we are ready for another frame */ | 718 | /* Tell the network interface we are ready for another frame */ |
719 | netif_wake_queue(odev->net); | 719 | netif_wake_queue(odev->net); |
720 | } | 720 | } |
721 | 721 | ||
722 | /* called by kernel when we need to transmit a packet */ | 722 | /* called by kernel when we need to transmit a packet */ |
723 | static int hso_net_start_xmit(struct sk_buff *skb, struct net_device *net) | 723 | static int hso_net_start_xmit(struct sk_buff *skb, struct net_device *net) |
724 | { | 724 | { |
725 | struct hso_net *odev = netdev_priv(net); | 725 | struct hso_net *odev = netdev_priv(net); |
726 | int result; | 726 | int result; |
727 | 727 | ||
728 | /* Tell the kernel, "No more frames 'til we are done with this one." */ | 728 | /* Tell the kernel, "No more frames 'til we are done with this one." */ |
729 | netif_stop_queue(net); | 729 | netif_stop_queue(net); |
730 | if (hso_get_activity(odev->parent) == -EAGAIN) { | 730 | if (hso_get_activity(odev->parent) == -EAGAIN) { |
731 | odev->skb_tx_buf = skb; | 731 | odev->skb_tx_buf = skb; |
732 | return 0; | 732 | return 0; |
733 | } | 733 | } |
734 | 734 | ||
735 | /* log if asked */ | 735 | /* log if asked */ |
736 | DUMP1(skb->data, skb->len); | 736 | DUMP1(skb->data, skb->len); |
737 | /* Copy it from kernel memory to OUR memory */ | 737 | /* Copy it from kernel memory to OUR memory */ |
738 | memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len); | 738 | memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len); |
739 | D1("len: %d/%d", skb->len, MUX_BULK_TX_BUF_SIZE); | 739 | D1("len: %d/%d", skb->len, MUX_BULK_TX_BUF_SIZE); |
740 | 740 | ||
741 | /* Fill in the URB for shipping it out. */ | 741 | /* Fill in the URB for shipping it out. */ |
742 | usb_fill_bulk_urb(odev->mux_bulk_tx_urb, | 742 | usb_fill_bulk_urb(odev->mux_bulk_tx_urb, |
743 | odev->parent->usb, | 743 | odev->parent->usb, |
744 | usb_sndbulkpipe(odev->parent->usb, | 744 | usb_sndbulkpipe(odev->parent->usb, |
745 | odev->out_endp-> | 745 | odev->out_endp-> |
746 | bEndpointAddress & 0x7F), | 746 | bEndpointAddress & 0x7F), |
747 | odev->mux_bulk_tx_buf, skb->len, write_bulk_callback, | 747 | odev->mux_bulk_tx_buf, skb->len, write_bulk_callback, |
748 | odev); | 748 | odev); |
749 | 749 | ||
750 | /* Deal with the Zero Length packet problem, I hope */ | 750 | /* Deal with the Zero Length packet problem, I hope */ |
751 | odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET; | 751 | odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET; |
752 | 752 | ||
753 | /* Send the URB on its merry way. */ | 753 | /* Send the URB on its merry way. */ |
754 | result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC); | 754 | result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC); |
755 | if (result) { | 755 | if (result) { |
756 | dev_warn(&odev->parent->interface->dev, | 756 | dev_warn(&odev->parent->interface->dev, |
757 | "failed mux_bulk_tx_urb %d", result); | 757 | "failed mux_bulk_tx_urb %d", result); |
758 | net->stats.tx_errors++; | 758 | net->stats.tx_errors++; |
759 | netif_start_queue(net); | 759 | netif_start_queue(net); |
760 | } else { | 760 | } else { |
761 | net->stats.tx_packets++; | 761 | net->stats.tx_packets++; |
762 | net->stats.tx_bytes += skb->len; | 762 | net->stats.tx_bytes += skb->len; |
763 | /* And tell the kernel when the last transmit started. */ | 763 | /* And tell the kernel when the last transmit started. */ |
764 | net->trans_start = jiffies; | 764 | net->trans_start = jiffies; |
765 | } | 765 | } |
766 | dev_kfree_skb(skb); | 766 | dev_kfree_skb(skb); |
767 | /* we're done */ | 767 | /* we're done */ |
768 | return result; | 768 | return result; |
769 | } | 769 | } |
770 | 770 | ||
771 | static void hso_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) | 771 | static void hso_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) |
772 | { | 772 | { |
773 | struct hso_net *odev = netdev_priv(net); | 773 | struct hso_net *odev = netdev_priv(net); |
774 | 774 | ||
775 | strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN); | 775 | strncpy(info->driver, driver_name, ETHTOOL_BUSINFO_LEN); |
776 | strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN); | 776 | strncpy(info->version, DRIVER_VERSION, ETHTOOL_BUSINFO_LEN); |
777 | usb_make_path(odev->parent->usb, info->bus_info, sizeof info->bus_info); | 777 | usb_make_path(odev->parent->usb, info->bus_info, sizeof info->bus_info); |
778 | } | 778 | } |
779 | 779 | ||
780 | static struct ethtool_ops ops = { | 780 | static struct ethtool_ops ops = { |
781 | .get_drvinfo = hso_get_drvinfo, | 781 | .get_drvinfo = hso_get_drvinfo, |
782 | .get_link = ethtool_op_get_link | 782 | .get_link = ethtool_op_get_link |
783 | }; | 783 | }; |
784 | 784 | ||
785 | /* called when a packet did not ack after watchdogtimeout */ | 785 | /* called when a packet did not ack after watchdogtimeout */ |
786 | static void hso_net_tx_timeout(struct net_device *net) | 786 | static void hso_net_tx_timeout(struct net_device *net) |
787 | { | 787 | { |
788 | struct hso_net *odev = netdev_priv(net); | 788 | struct hso_net *odev = netdev_priv(net); |
789 | 789 | ||
790 | if (!odev) | 790 | if (!odev) |
791 | return; | 791 | return; |
792 | 792 | ||
793 | /* Tell syslog we are hosed. */ | 793 | /* Tell syslog we are hosed. */ |
794 | dev_warn(&net->dev, "Tx timed out.\n"); | 794 | dev_warn(&net->dev, "Tx timed out.\n"); |
795 | 795 | ||
796 | /* Tear the waiting frame off the list */ | 796 | /* Tear the waiting frame off the list */ |
797 | if (odev->mux_bulk_tx_urb | 797 | if (odev->mux_bulk_tx_urb |
798 | && (odev->mux_bulk_tx_urb->status == -EINPROGRESS)) | 798 | && (odev->mux_bulk_tx_urb->status == -EINPROGRESS)) |
799 | usb_unlink_urb(odev->mux_bulk_tx_urb); | 799 | usb_unlink_urb(odev->mux_bulk_tx_urb); |
800 | 800 | ||
801 | /* Update statistics */ | 801 | /* Update statistics */ |
802 | net->stats.tx_errors++; | 802 | net->stats.tx_errors++; |
803 | } | 803 | } |
804 | 804 | ||
805 | /* make a real packet from the received USB buffer */ | 805 | /* make a real packet from the received USB buffer */ |
806 | static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt, | 806 | static void packetizeRx(struct hso_net *odev, unsigned char *ip_pkt, |
807 | unsigned int count, unsigned char is_eop) | 807 | unsigned int count, unsigned char is_eop) |
808 | { | 808 | { |
809 | unsigned short temp_bytes; | 809 | unsigned short temp_bytes; |
810 | unsigned short buffer_offset = 0; | 810 | unsigned short buffer_offset = 0; |
811 | unsigned short frame_len; | 811 | unsigned short frame_len; |
812 | unsigned char *tmp_rx_buf; | 812 | unsigned char *tmp_rx_buf; |
813 | 813 | ||
814 | /* log if needed */ | 814 | /* log if needed */ |
815 | D1("Rx %d bytes", count); | 815 | D1("Rx %d bytes", count); |
816 | DUMP(ip_pkt, min(128, (int)count)); | 816 | DUMP(ip_pkt, min(128, (int)count)); |
817 | 817 | ||
818 | while (count) { | 818 | while (count) { |
819 | switch (odev->rx_parse_state) { | 819 | switch (odev->rx_parse_state) { |
820 | case WAIT_IP: | 820 | case WAIT_IP: |
821 | /* waiting for IP header. */ | 821 | /* waiting for IP header. */ |
822 | /* wanted bytes - size of ip header */ | 822 | /* wanted bytes - size of ip header */ |
823 | temp_bytes = | 823 | temp_bytes = |
824 | (count < | 824 | (count < |
825 | odev->rx_buf_missing) ? count : odev-> | 825 | odev->rx_buf_missing) ? count : odev-> |
826 | rx_buf_missing; | 826 | rx_buf_missing; |
827 | 827 | ||
828 | memcpy(((unsigned char *)(&odev->rx_ip_hdr)) + | 828 | memcpy(((unsigned char *)(&odev->rx_ip_hdr)) + |
829 | odev->rx_buf_size, ip_pkt + buffer_offset, | 829 | odev->rx_buf_size, ip_pkt + buffer_offset, |
830 | temp_bytes); | 830 | temp_bytes); |
831 | 831 | ||
832 | odev->rx_buf_size += temp_bytes; | 832 | odev->rx_buf_size += temp_bytes; |
833 | buffer_offset += temp_bytes; | 833 | buffer_offset += temp_bytes; |
834 | odev->rx_buf_missing -= temp_bytes; | 834 | odev->rx_buf_missing -= temp_bytes; |
835 | count -= temp_bytes; | 835 | count -= temp_bytes; |
836 | 836 | ||
837 | if (!odev->rx_buf_missing) { | 837 | if (!odev->rx_buf_missing) { |
838 | /* header is complete allocate an sk_buffer and | 838 | /* header is complete allocate an sk_buffer and |
839 | * continue to WAIT_DATA */ | 839 | * continue to WAIT_DATA */ |
840 | frame_len = ntohs(odev->rx_ip_hdr.tot_len); | 840 | frame_len = ntohs(odev->rx_ip_hdr.tot_len); |
841 | 841 | ||
842 | if ((frame_len > DEFAULT_MRU) || | 842 | if ((frame_len > DEFAULT_MRU) || |
843 | (frame_len < sizeof(struct iphdr))) { | 843 | (frame_len < sizeof(struct iphdr))) { |
844 | dev_err(&odev->net->dev, | 844 | dev_err(&odev->net->dev, |
845 | "Invalid frame (%d) length\n", | 845 | "Invalid frame (%d) length\n", |
846 | frame_len); | 846 | frame_len); |
847 | odev->rx_parse_state = WAIT_SYNC; | 847 | odev->rx_parse_state = WAIT_SYNC; |
848 | continue; | 848 | continue; |
849 | } | 849 | } |
850 | /* Allocate an sk_buff */ | 850 | /* Allocate an sk_buff */ |
851 | odev->skb_rx_buf = dev_alloc_skb(frame_len); | 851 | odev->skb_rx_buf = dev_alloc_skb(frame_len); |
852 | if (!odev->skb_rx_buf) { | 852 | if (!odev->skb_rx_buf) { |
853 | /* We got no receive buffer. */ | 853 | /* We got no receive buffer. */ |
854 | D1("could not allocate memory"); | 854 | D1("could not allocate memory"); |
855 | odev->rx_parse_state = WAIT_SYNC; | 855 | odev->rx_parse_state = WAIT_SYNC; |
856 | return; | 856 | return; |
857 | } | 857 | } |
858 | /* Here's where it came from */ | 858 | /* Here's where it came from */ |
859 | odev->skb_rx_buf->dev = odev->net; | 859 | odev->skb_rx_buf->dev = odev->net; |
860 | 860 | ||
861 | /* Copy what we got so far. make room for iphdr | 861 | /* Copy what we got so far. make room for iphdr |
862 | * after tail. */ | 862 | * after tail. */ |
863 | tmp_rx_buf = | 863 | tmp_rx_buf = |
864 | skb_put(odev->skb_rx_buf, | 864 | skb_put(odev->skb_rx_buf, |
865 | sizeof(struct iphdr)); | 865 | sizeof(struct iphdr)); |
866 | memcpy(tmp_rx_buf, (char *)&(odev->rx_ip_hdr), | 866 | memcpy(tmp_rx_buf, (char *)&(odev->rx_ip_hdr), |
867 | sizeof(struct iphdr)); | 867 | sizeof(struct iphdr)); |
868 | 868 | ||
869 | /* ETH_HLEN */ | 869 | /* ETH_HLEN */ |
870 | odev->rx_buf_size = sizeof(struct iphdr); | 870 | odev->rx_buf_size = sizeof(struct iphdr); |
871 | 871 | ||
872 | /* Filip actually use .tot_len */ | 872 | /* Filip actually use .tot_len */ |
873 | odev->rx_buf_missing = | 873 | odev->rx_buf_missing = |
874 | frame_len - sizeof(struct iphdr); | 874 | frame_len - sizeof(struct iphdr); |
875 | odev->rx_parse_state = WAIT_DATA; | 875 | odev->rx_parse_state = WAIT_DATA; |
876 | } | 876 | } |
877 | break; | 877 | break; |
878 | 878 | ||
879 | case WAIT_DATA: | 879 | case WAIT_DATA: |
880 | temp_bytes = (count < odev->rx_buf_missing) | 880 | temp_bytes = (count < odev->rx_buf_missing) |
881 | ? count : odev->rx_buf_missing; | 881 | ? count : odev->rx_buf_missing; |
882 | 882 | ||
883 | /* Copy the rest of the bytes that are left in the | 883 | /* Copy the rest of the bytes that are left in the |
884 | * buffer into the waiting sk_buf. */ | 884 | * buffer into the waiting sk_buf. */ |
885 | /* Make room for temp_bytes after tail. */ | 885 | /* Make room for temp_bytes after tail. */ |
886 | tmp_rx_buf = skb_put(odev->skb_rx_buf, temp_bytes); | 886 | tmp_rx_buf = skb_put(odev->skb_rx_buf, temp_bytes); |
887 | memcpy(tmp_rx_buf, ip_pkt + buffer_offset, temp_bytes); | 887 | memcpy(tmp_rx_buf, ip_pkt + buffer_offset, temp_bytes); |
888 | 888 | ||
889 | odev->rx_buf_missing -= temp_bytes; | 889 | odev->rx_buf_missing -= temp_bytes; |
890 | count -= temp_bytes; | 890 | count -= temp_bytes; |
891 | buffer_offset += temp_bytes; | 891 | buffer_offset += temp_bytes; |
892 | odev->rx_buf_size += temp_bytes; | 892 | odev->rx_buf_size += temp_bytes; |
893 | if (!odev->rx_buf_missing) { | 893 | if (!odev->rx_buf_missing) { |
894 | /* Packet is complete. Inject into stack. */ | 894 | /* Packet is complete. Inject into stack. */ |
895 | /* We have IP packet here */ | 895 | /* We have IP packet here */ |
896 | odev->skb_rx_buf->protocol = | 896 | odev->skb_rx_buf->protocol = |
897 | __constant_htons(ETH_P_IP); | 897 | __constant_htons(ETH_P_IP); |
898 | /* don't check it */ | 898 | /* don't check it */ |
899 | odev->skb_rx_buf->ip_summed = | 899 | odev->skb_rx_buf->ip_summed = |
900 | CHECKSUM_UNNECESSARY; | 900 | CHECKSUM_UNNECESSARY; |
901 | 901 | ||
902 | skb_reset_mac_header(odev->skb_rx_buf); | 902 | skb_reset_mac_header(odev->skb_rx_buf); |
903 | 903 | ||
904 | /* Ship it off to the kernel */ | 904 | /* Ship it off to the kernel */ |
905 | netif_rx(odev->skb_rx_buf); | 905 | netif_rx(odev->skb_rx_buf); |
906 | /* No longer our buffer. */ | 906 | /* No longer our buffer. */ |
907 | odev->skb_rx_buf = NULL; | 907 | odev->skb_rx_buf = NULL; |
908 | 908 | ||
909 | /* update out statistics */ | 909 | /* update out statistics */ |
910 | odev->net->stats.rx_packets++; | 910 | odev->net->stats.rx_packets++; |
911 | 911 | ||
912 | odev->net->stats.rx_bytes += odev->rx_buf_size; | 912 | odev->net->stats.rx_bytes += odev->rx_buf_size; |
913 | 913 | ||
914 | odev->rx_buf_size = 0; | 914 | odev->rx_buf_size = 0; |
915 | odev->rx_buf_missing = sizeof(struct iphdr); | 915 | odev->rx_buf_missing = sizeof(struct iphdr); |
916 | odev->rx_parse_state = WAIT_IP; | 916 | odev->rx_parse_state = WAIT_IP; |
917 | } | 917 | } |
918 | break; | 918 | break; |
919 | 919 | ||
920 | case WAIT_SYNC: | 920 | case WAIT_SYNC: |
921 | D1(" W_S"); | 921 | D1(" W_S"); |
922 | count = 0; | 922 | count = 0; |
923 | break; | 923 | break; |
924 | default: | 924 | default: |
925 | D1(" "); | 925 | D1(" "); |
926 | count--; | 926 | count--; |
927 | break; | 927 | break; |
928 | } | 928 | } |
929 | } | 929 | } |
930 | 930 | ||
931 | /* Recovery mechanism for WAIT_SYNC state. */ | 931 | /* Recovery mechanism for WAIT_SYNC state. */ |
932 | if (is_eop) { | 932 | if (is_eop) { |
933 | if (odev->rx_parse_state == WAIT_SYNC) { | 933 | if (odev->rx_parse_state == WAIT_SYNC) { |
934 | odev->rx_parse_state = WAIT_IP; | 934 | odev->rx_parse_state = WAIT_IP; |
935 | odev->rx_buf_size = 0; | 935 | odev->rx_buf_size = 0; |
936 | odev->rx_buf_missing = sizeof(struct iphdr); | 936 | odev->rx_buf_missing = sizeof(struct iphdr); |
937 | } | 937 | } |
938 | } | 938 | } |
939 | } | 939 | } |
940 | 940 | ||
941 | /* Moving data from usb to kernel (in interrupt state) */ | 941 | /* Moving data from usb to kernel (in interrupt state) */ |
942 | static void read_bulk_callback(struct urb *urb) | 942 | static void read_bulk_callback(struct urb *urb) |
943 | { | 943 | { |
944 | struct hso_net *odev = urb->context; | 944 | struct hso_net *odev = urb->context; |
945 | struct net_device *net; | 945 | struct net_device *net; |
946 | int result; | 946 | int result; |
947 | int status = urb->status; | 947 | int status = urb->status; |
948 | 948 | ||
949 | /* is al ok? (Filip: Who's Al ?) */ | 949 | /* is al ok? (Filip: Who's Al ?) */ |
950 | if (status) { | 950 | if (status) { |
951 | log_usb_status(status, __func__); | 951 | log_usb_status(status, __func__); |
952 | return; | 952 | return; |
953 | } | 953 | } |
954 | 954 | ||
955 | /* Sanity check */ | 955 | /* Sanity check */ |
956 | if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { | 956 | if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { |
957 | D1("BULK IN callback but driver is not active!"); | 957 | D1("BULK IN callback but driver is not active!"); |
958 | return; | 958 | return; |
959 | } | 959 | } |
960 | usb_mark_last_busy(urb->dev); | 960 | usb_mark_last_busy(urb->dev); |
961 | 961 | ||
962 | net = odev->net; | 962 | net = odev->net; |
963 | 963 | ||
964 | if (!netif_device_present(net)) { | 964 | if (!netif_device_present(net)) { |
965 | /* Somebody killed our network interface... */ | 965 | /* Somebody killed our network interface... */ |
966 | return; | 966 | return; |
967 | } | 967 | } |
968 | 968 | ||
969 | if (odev->parent->port_spec & HSO_INFO_CRC_BUG) { | 969 | if (odev->parent->port_spec & HSO_INFO_CRC_BUG) { |
970 | u32 rest; | 970 | u32 rest; |
971 | u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; | 971 | u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; |
972 | rest = urb->actual_length % odev->in_endp->wMaxPacketSize; | 972 | rest = urb->actual_length % odev->in_endp->wMaxPacketSize; |
973 | if (((rest == 5) || (rest == 6)) | 973 | if (((rest == 5) || (rest == 6)) |
974 | && !memcmp(((u8 *) urb->transfer_buffer) + | 974 | && !memcmp(((u8 *) urb->transfer_buffer) + |
975 | urb->actual_length - 4, crc_check, 4)) { | 975 | urb->actual_length - 4, crc_check, 4)) { |
976 | urb->actual_length -= 4; | 976 | urb->actual_length -= 4; |
977 | } | 977 | } |
978 | } | 978 | } |
979 | 979 | ||
980 | /* do we even have a packet? */ | 980 | /* do we even have a packet? */ |
981 | if (urb->actual_length) { | 981 | if (urb->actual_length) { |
982 | /* Handle the IP stream, add header and push it onto network | 982 | /* Handle the IP stream, add header and push it onto network |
983 | * stack if the packet is complete. */ | 983 | * stack if the packet is complete. */ |
984 | spin_lock(&odev->net_lock); | 984 | spin_lock(&odev->net_lock); |
985 | packetizeRx(odev, urb->transfer_buffer, urb->actual_length, | 985 | packetizeRx(odev, urb->transfer_buffer, urb->actual_length, |
986 | (urb->transfer_buffer_length > | 986 | (urb->transfer_buffer_length > |
987 | urb->actual_length) ? 1 : 0); | 987 | urb->actual_length) ? 1 : 0); |
988 | spin_unlock(&odev->net_lock); | 988 | spin_unlock(&odev->net_lock); |
989 | } | 989 | } |
990 | 990 | ||
991 | /* We are done with this URB, resubmit it. Prep the USB to wait for | 991 | /* We are done with this URB, resubmit it. Prep the USB to wait for |
992 | * another frame. Reuse same as received. */ | 992 | * another frame. Reuse same as received. */ |
993 | usb_fill_bulk_urb(urb, | 993 | usb_fill_bulk_urb(urb, |
994 | odev->parent->usb, | 994 | odev->parent->usb, |
995 | usb_rcvbulkpipe(odev->parent->usb, | 995 | usb_rcvbulkpipe(odev->parent->usb, |
996 | odev->in_endp-> | 996 | odev->in_endp-> |
997 | bEndpointAddress & 0x7F), | 997 | bEndpointAddress & 0x7F), |
998 | urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE, | 998 | urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE, |
999 | read_bulk_callback, odev); | 999 | read_bulk_callback, odev); |
1000 | 1000 | ||
1001 | /* Give this to the USB subsystem so it can tell us when more data | 1001 | /* Give this to the USB subsystem so it can tell us when more data |
1002 | * arrives. */ | 1002 | * arrives. */ |
1003 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1003 | result = usb_submit_urb(urb, GFP_ATOMIC); |
1004 | if (result) | 1004 | if (result) |
1005 | dev_warn(&odev->parent->interface->dev, | 1005 | dev_warn(&odev->parent->interface->dev, |
1006 | "%s failed submit mux_bulk_rx_urb %d", __func__, | 1006 | "%s failed submit mux_bulk_rx_urb %d", __func__, |
1007 | result); | 1007 | result); |
1008 | } | 1008 | } |
1009 | 1009 | ||
1010 | /* Serial driver functions */ | 1010 | /* Serial driver functions */ |
1011 | 1011 | ||
1012 | static void _hso_serial_set_termios(struct tty_struct *tty, | 1012 | static void _hso_serial_set_termios(struct tty_struct *tty, |
1013 | struct ktermios *old) | 1013 | struct ktermios *old) |
1014 | { | 1014 | { |
1015 | struct hso_serial *serial = get_serial_by_tty(tty); | 1015 | struct hso_serial *serial = get_serial_by_tty(tty); |
1016 | struct ktermios *termios; | 1016 | struct ktermios *termios; |
1017 | 1017 | ||
1018 | if ((!tty) || (!tty->termios) || (!serial)) { | 1018 | if (!serial) { |
1019 | printk(KERN_ERR "%s: no tty structures", __func__); | 1019 | printk(KERN_ERR "%s: no tty structures", __func__); |
1020 | return; | 1020 | return; |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | D4("port %d", serial->minor); | 1023 | D4("port %d", serial->minor); |
1024 | 1024 | ||
1025 | /* | 1025 | /* |
1026 | * The default requirements for this device are: | 1026 | * The default requirements for this device are: |
1027 | */ | 1027 | */ |
1028 | termios = tty->termios; | 1028 | termios = tty->termios; |
1029 | termios->c_iflag &= | 1029 | termios->c_iflag &= |
1030 | ~(IGNBRK /* disable ignore break */ | 1030 | ~(IGNBRK /* disable ignore break */ |
1031 | | BRKINT /* disable break causes interrupt */ | 1031 | | BRKINT /* disable break causes interrupt */ |
1032 | | PARMRK /* disable mark parity errors */ | 1032 | | PARMRK /* disable mark parity errors */ |
1033 | | ISTRIP /* disable clear high bit of input characters */ | 1033 | | ISTRIP /* disable clear high bit of input characters */ |
1034 | | INLCR /* disable translate NL to CR */ | 1034 | | INLCR /* disable translate NL to CR */ |
1035 | | IGNCR /* disable ignore CR */ | 1035 | | IGNCR /* disable ignore CR */ |
1036 | | ICRNL /* disable translate CR to NL */ | 1036 | | ICRNL /* disable translate CR to NL */ |
1037 | | IXON); /* disable enable XON/XOFF flow control */ | 1037 | | IXON); /* disable enable XON/XOFF flow control */ |
1038 | 1038 | ||
1039 | /* disable postprocess output characters */ | 1039 | /* disable postprocess output characters */ |
1040 | termios->c_oflag &= ~OPOST; | 1040 | termios->c_oflag &= ~OPOST; |
1041 | 1041 | ||
1042 | termios->c_lflag &= | 1042 | termios->c_lflag &= |
1043 | ~(ECHO /* disable echo input characters */ | 1043 | ~(ECHO /* disable echo input characters */ |
1044 | | ECHONL /* disable echo new line */ | 1044 | | ECHONL /* disable echo new line */ |
1045 | | ICANON /* disable erase, kill, werase, and rprnt | 1045 | | ICANON /* disable erase, kill, werase, and rprnt |
1046 | special characters */ | 1046 | special characters */ |
1047 | | ISIG /* disable interrupt, quit, and suspend special | 1047 | | ISIG /* disable interrupt, quit, and suspend special |
1048 | characters */ | 1048 | characters */ |
1049 | | IEXTEN); /* disable non-POSIX special characters */ | 1049 | | IEXTEN); /* disable non-POSIX special characters */ |
1050 | 1050 | ||
1051 | termios->c_cflag &= | 1051 | termios->c_cflag &= |
1052 | ~(CSIZE /* no size */ | 1052 | ~(CSIZE /* no size */ |
1053 | | PARENB /* disable parity bit */ | 1053 | | PARENB /* disable parity bit */ |
1054 | | CBAUD /* clear current baud rate */ | 1054 | | CBAUD /* clear current baud rate */ |
1055 | | CBAUDEX); /* clear current buad rate */ | 1055 | | CBAUDEX); /* clear current buad rate */ |
1056 | 1056 | ||
1057 | termios->c_cflag |= CS8; /* character size 8 bits */ | 1057 | termios->c_cflag |= CS8; /* character size 8 bits */ |
1058 | 1058 | ||
1059 | /* baud rate 115200 */ | 1059 | /* baud rate 115200 */ |
1060 | tty_encode_baud_rate(serial->tty, 115200, 115200); | 1060 | tty_encode_baud_rate(tty, 115200, 115200); |
1061 | 1061 | ||
1062 | /* | 1062 | /* |
1063 | * Force low_latency on; otherwise the pushes are scheduled; | 1063 | * Force low_latency on; otherwise the pushes are scheduled; |
1064 | * this is bad as it opens up the possibility of dropping bytes | 1064 | * this is bad as it opens up the possibility of dropping bytes |
1065 | * on the floor. We don't want to drop bytes on the floor. :) | 1065 | * on the floor. We don't want to drop bytes on the floor. :) |
1066 | */ | 1066 | */ |
1067 | serial->tty->low_latency = 1; | 1067 | tty->low_latency = 1; |
1068 | return; | 1068 | return; |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) | 1071 | static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) |
1072 | { | 1072 | { |
1073 | int result; | 1073 | int result; |
1074 | #ifdef CONFIG_HSO_AUTOPM | 1074 | #ifdef CONFIG_HSO_AUTOPM |
1075 | usb_mark_last_busy(urb->dev); | 1075 | usb_mark_last_busy(urb->dev); |
1076 | #endif | 1076 | #endif |
1077 | /* We are done with this URB, resubmit it. Prep the USB to wait for | 1077 | /* We are done with this URB, resubmit it. Prep the USB to wait for |
1078 | * another frame */ | 1078 | * another frame */ |
1079 | usb_fill_bulk_urb(urb, serial->parent->usb, | 1079 | usb_fill_bulk_urb(urb, serial->parent->usb, |
1080 | usb_rcvbulkpipe(serial->parent->usb, | 1080 | usb_rcvbulkpipe(serial->parent->usb, |
1081 | serial->in_endp-> | 1081 | serial->in_endp-> |
1082 | bEndpointAddress & 0x7F), | 1082 | bEndpointAddress & 0x7F), |
1083 | urb->transfer_buffer, serial->rx_data_length, | 1083 | urb->transfer_buffer, serial->rx_data_length, |
1084 | hso_std_serial_read_bulk_callback, serial); | 1084 | hso_std_serial_read_bulk_callback, serial); |
1085 | /* Give this to the USB subsystem so it can tell us when more data | 1085 | /* Give this to the USB subsystem so it can tell us when more data |
1086 | * arrives. */ | 1086 | * arrives. */ |
1087 | result = usb_submit_urb(urb, GFP_ATOMIC); | 1087 | result = usb_submit_urb(urb, GFP_ATOMIC); |
1088 | if (result) { | 1088 | if (result) { |
1089 | dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n", | 1089 | dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n", |
1090 | __func__, result); | 1090 | __func__, result); |
1091 | } | 1091 | } |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | 1094 | ||
1095 | 1095 | ||
1096 | 1096 | ||
1097 | static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial) | 1097 | static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial) |
1098 | { | 1098 | { |
1099 | int count; | 1099 | int count; |
1100 | struct urb *curr_urb; | 1100 | struct urb *curr_urb; |
1101 | 1101 | ||
1102 | while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) { | 1102 | while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) { |
1103 | curr_urb = serial->rx_urb[serial->curr_rx_urb_idx]; | 1103 | curr_urb = serial->rx_urb[serial->curr_rx_urb_idx]; |
1104 | count = put_rxbuf_data(curr_urb, serial); | 1104 | count = put_rxbuf_data(curr_urb, serial); |
1105 | if (count == -1) | 1105 | if (count == -1) |
1106 | return; | 1106 | return; |
1107 | if (count == 0) { | 1107 | if (count == 0) { |
1108 | serial->curr_rx_urb_idx++; | 1108 | serial->curr_rx_urb_idx++; |
1109 | if (serial->curr_rx_urb_idx >= serial->num_rx_urbs) | 1109 | if (serial->curr_rx_urb_idx >= serial->num_rx_urbs) |
1110 | serial->curr_rx_urb_idx = 0; | 1110 | serial->curr_rx_urb_idx = 0; |
1111 | hso_resubmit_rx_bulk_urb(serial, curr_urb); | 1111 | hso_resubmit_rx_bulk_urb(serial, curr_urb); |
1112 | } | 1112 | } |
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) | 1116 | static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) |
1117 | { | 1117 | { |
1118 | int count = 0; | 1118 | int count = 0; |
1119 | struct urb *urb; | 1119 | struct urb *urb; |
1120 | 1120 | ||
1121 | urb = serial->rx_urb[0]; | 1121 | urb = serial->rx_urb[0]; |
1122 | if (serial->open_count > 0) { | 1122 | if (serial->open_count > 0) { |
1123 | count = put_rxbuf_data(urb, serial); | 1123 | count = put_rxbuf_data(urb, serial); |
1124 | if (count == -1) | 1124 | if (count == -1) |
1125 | return; | 1125 | return; |
1126 | } | 1126 | } |
1127 | /* Re issue a read as long as we receive data. */ | 1127 | /* Re issue a read as long as we receive data. */ |
1128 | 1128 | ||
1129 | if (count == 0 && ((urb->actual_length != 0) || | 1129 | if (count == 0 && ((urb->actual_length != 0) || |
1130 | (serial->rx_state == RX_PENDING))) { | 1130 | (serial->rx_state == RX_PENDING))) { |
1131 | serial->rx_state = RX_SENT; | 1131 | serial->rx_state = RX_SENT; |
1132 | hso_mux_serial_read(serial); | 1132 | hso_mux_serial_read(serial); |
1133 | } else | 1133 | } else |
1134 | serial->rx_state = RX_IDLE; | 1134 | serial->rx_state = RX_IDLE; |
1135 | } | 1135 | } |
1136 | 1136 | ||
1137 | 1137 | ||
1138 | /* read callback for Diag and CS port */ | 1138 | /* read callback for Diag and CS port */ |
1139 | static void hso_std_serial_read_bulk_callback(struct urb *urb) | 1139 | static void hso_std_serial_read_bulk_callback(struct urb *urb) |
1140 | { | 1140 | { |
1141 | struct hso_serial *serial = urb->context; | 1141 | struct hso_serial *serial = urb->context; |
1142 | int status = urb->status; | 1142 | int status = urb->status; |
1143 | 1143 | ||
1144 | /* sanity check */ | 1144 | /* sanity check */ |
1145 | if (!serial) { | 1145 | if (!serial) { |
1146 | D1("serial == NULL"); | 1146 | D1("serial == NULL"); |
1147 | return; | 1147 | return; |
1148 | } else if (status) { | 1148 | } else if (status) { |
1149 | log_usb_status(status, __func__); | 1149 | log_usb_status(status, __func__); |
1150 | return; | 1150 | return; |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | D4("\n--- Got serial_read_bulk callback %02x ---", status); | 1153 | D4("\n--- Got serial_read_bulk callback %02x ---", status); |
1154 | D1("Actual length = %d\n", urb->actual_length); | 1154 | D1("Actual length = %d\n", urb->actual_length); |
1155 | DUMP1(urb->transfer_buffer, urb->actual_length); | 1155 | DUMP1(urb->transfer_buffer, urb->actual_length); |
1156 | 1156 | ||
1157 | /* Anyone listening? */ | 1157 | /* Anyone listening? */ |
1158 | if (serial->open_count == 0) | 1158 | if (serial->open_count == 0) |
1159 | return; | 1159 | return; |
1160 | 1160 | ||
1161 | if (status == 0) { | 1161 | if (status == 0) { |
1162 | if (serial->parent->port_spec & HSO_INFO_CRC_BUG) { | 1162 | if (serial->parent->port_spec & HSO_INFO_CRC_BUG) { |
1163 | u32 rest; | 1163 | u32 rest; |
1164 | u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; | 1164 | u8 crc_check[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; |
1165 | rest = | 1165 | rest = |
1166 | urb->actual_length % | 1166 | urb->actual_length % |
1167 | serial->in_endp->wMaxPacketSize; | 1167 | serial->in_endp->wMaxPacketSize; |
1168 | if (((rest == 5) || (rest == 6)) | 1168 | if (((rest == 5) || (rest == 6)) |
1169 | && !memcmp(((u8 *) urb->transfer_buffer) + | 1169 | && !memcmp(((u8 *) urb->transfer_buffer) + |
1170 | urb->actual_length - 4, crc_check, 4)) { | 1170 | urb->actual_length - 4, crc_check, 4)) { |
1171 | urb->actual_length -= 4; | 1171 | urb->actual_length -= 4; |
1172 | } | 1172 | } |
1173 | } | 1173 | } |
1174 | /* Valid data, handle RX data */ | 1174 | /* Valid data, handle RX data */ |
1175 | spin_lock(&serial->serial_lock); | 1175 | spin_lock(&serial->serial_lock); |
1176 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; | 1176 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; |
1177 | put_rxbuf_data_and_resubmit_bulk_urb(serial); | 1177 | put_rxbuf_data_and_resubmit_bulk_urb(serial); |
1178 | spin_unlock(&serial->serial_lock); | 1178 | spin_unlock(&serial->serial_lock); |
1179 | } else if (status == -ENOENT || status == -ECONNRESET) { | 1179 | } else if (status == -ENOENT || status == -ECONNRESET) { |
1180 | /* Unlinked - check for throttled port. */ | 1180 | /* Unlinked - check for throttled port. */ |
1181 | D2("Port %d, successfully unlinked urb", serial->minor); | 1181 | D2("Port %d, successfully unlinked urb", serial->minor); |
1182 | spin_lock(&serial->serial_lock); | 1182 | spin_lock(&serial->serial_lock); |
1183 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; | 1183 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; |
1184 | hso_resubmit_rx_bulk_urb(serial, urb); | 1184 | hso_resubmit_rx_bulk_urb(serial, urb); |
1185 | spin_unlock(&serial->serial_lock); | 1185 | spin_unlock(&serial->serial_lock); |
1186 | } else { | 1186 | } else { |
1187 | D2("Port %d, status = %d for read urb", serial->minor, status); | 1187 | D2("Port %d, status = %d for read urb", serial->minor, status); |
1188 | return; | 1188 | return; |
1189 | } | 1189 | } |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | /* | 1192 | /* |
1193 | * This needs to be a tasklet otherwise we will | 1193 | * This needs to be a tasklet otherwise we will |
1194 | * end up recursively calling this function. | 1194 | * end up recursively calling this function. |
1195 | */ | 1195 | */ |
1196 | void hso_unthrottle_tasklet(struct hso_serial *serial) | 1196 | void hso_unthrottle_tasklet(struct hso_serial *serial) |
1197 | { | 1197 | { |
1198 | unsigned long flags; | 1198 | unsigned long flags; |
1199 | 1199 | ||
1200 | spin_lock_irqsave(&serial->serial_lock, flags); | 1200 | spin_lock_irqsave(&serial->serial_lock, flags); |
1201 | if ((serial->parent->port_spec & HSO_INTF_MUX)) | 1201 | if ((serial->parent->port_spec & HSO_INTF_MUX)) |
1202 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); | 1202 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); |
1203 | else | 1203 | else |
1204 | put_rxbuf_data_and_resubmit_bulk_urb(serial); | 1204 | put_rxbuf_data_and_resubmit_bulk_urb(serial); |
1205 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1205 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | static void hso_unthrottle(struct tty_struct *tty) | 1208 | static void hso_unthrottle(struct tty_struct *tty) |
1209 | { | 1209 | { |
1210 | struct hso_serial *serial = get_serial_by_tty(tty); | 1210 | struct hso_serial *serial = get_serial_by_tty(tty); |
1211 | 1211 | ||
1212 | tasklet_hi_schedule(&serial->unthrottle_tasklet); | 1212 | tasklet_hi_schedule(&serial->unthrottle_tasklet); |
1213 | } | 1213 | } |
1214 | 1214 | ||
1215 | void hso_unthrottle_workfunc(struct work_struct *work) | 1215 | void hso_unthrottle_workfunc(struct work_struct *work) |
1216 | { | 1216 | { |
1217 | struct hso_serial *serial = | 1217 | struct hso_serial *serial = |
1218 | container_of(work, struct hso_serial, | 1218 | container_of(work, struct hso_serial, |
1219 | retry_unthrottle_workqueue); | 1219 | retry_unthrottle_workqueue); |
1220 | hso_unthrottle_tasklet(serial); | 1220 | hso_unthrottle_tasklet(serial); |
1221 | } | 1221 | } |
1222 | 1222 | ||
1223 | /* open the requested serial port */ | 1223 | /* open the requested serial port */ |
1224 | static int hso_serial_open(struct tty_struct *tty, struct file *filp) | 1224 | static int hso_serial_open(struct tty_struct *tty, struct file *filp) |
1225 | { | 1225 | { |
1226 | struct hso_serial *serial = get_serial_by_index(tty->index); | 1226 | struct hso_serial *serial = get_serial_by_index(tty->index); |
1227 | int result; | 1227 | int result; |
1228 | 1228 | ||
1229 | /* sanity check */ | 1229 | /* sanity check */ |
1230 | if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { | 1230 | if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { |
1231 | WARN_ON(1); | ||
1231 | tty->driver_data = NULL; | 1232 | tty->driver_data = NULL; |
1232 | D1("Failed to open port"); | 1233 | D1("Failed to open port"); |
1233 | return -ENODEV; | 1234 | return -ENODEV; |
1234 | } | 1235 | } |
1235 | 1236 | ||
1236 | mutex_lock(&serial->parent->mutex); | 1237 | mutex_lock(&serial->parent->mutex); |
1237 | result = usb_autopm_get_interface(serial->parent->interface); | 1238 | result = usb_autopm_get_interface(serial->parent->interface); |
1238 | if (result < 0) | 1239 | if (result < 0) |
1239 | goto err_out; | 1240 | goto err_out; |
1240 | 1241 | ||
1241 | D1("Opening %d", serial->minor); | 1242 | D1("Opening %d", serial->minor); |
1242 | kref_get(&serial->parent->ref); | 1243 | kref_get(&serial->parent->ref); |
1243 | 1244 | ||
1244 | /* setup */ | 1245 | /* setup */ |
1246 | spin_lock_irq(&serial->serial_lock); | ||
1245 | tty->driver_data = serial; | 1247 | tty->driver_data = serial; |
1246 | serial->tty = tty; | 1248 | serial->tty = tty_kref_get(tty); |
1249 | spin_unlock_irq(&serial->serial_lock); | ||
1247 | 1250 | ||
1248 | /* check for port already opened, if not set the termios */ | 1251 | /* check for port already opened, if not set the termios */ |
1249 | serial->open_count++; | 1252 | serial->open_count++; |
1250 | if (serial->open_count == 1) { | 1253 | if (serial->open_count == 1) { |
1251 | tty->low_latency = 1; | 1254 | tty->low_latency = 1; |
1252 | serial->rx_state = RX_IDLE; | 1255 | serial->rx_state = RX_IDLE; |
1253 | /* Force default termio settings */ | 1256 | /* Force default termio settings */ |
1254 | _hso_serial_set_termios(tty, NULL); | 1257 | _hso_serial_set_termios(tty, NULL); |
1255 | tasklet_init(&serial->unthrottle_tasklet, | 1258 | tasklet_init(&serial->unthrottle_tasklet, |
1256 | (void (*)(unsigned long))hso_unthrottle_tasklet, | 1259 | (void (*)(unsigned long))hso_unthrottle_tasklet, |
1257 | (unsigned long)serial); | 1260 | (unsigned long)serial); |
1258 | INIT_WORK(&serial->retry_unthrottle_workqueue, | 1261 | INIT_WORK(&serial->retry_unthrottle_workqueue, |
1259 | hso_unthrottle_workfunc); | 1262 | hso_unthrottle_workfunc); |
1260 | result = hso_start_serial_device(serial->parent, GFP_KERNEL); | 1263 | result = hso_start_serial_device(serial->parent, GFP_KERNEL); |
1261 | if (result) { | 1264 | if (result) { |
1262 | hso_stop_serial_device(serial->parent); | 1265 | hso_stop_serial_device(serial->parent); |
1263 | serial->open_count--; | 1266 | serial->open_count--; |
1264 | kref_put(&serial->parent->ref, hso_serial_ref_free); | 1267 | kref_put(&serial->parent->ref, hso_serial_ref_free); |
1265 | } | 1268 | } |
1266 | } else { | 1269 | } else { |
1267 | D1("Port was already open"); | 1270 | D1("Port was already open"); |
1268 | } | 1271 | } |
1269 | 1272 | ||
1270 | usb_autopm_put_interface(serial->parent->interface); | 1273 | usb_autopm_put_interface(serial->parent->interface); |
1271 | 1274 | ||
1272 | /* done */ | 1275 | /* done */ |
1273 | if (result) | 1276 | if (result) |
1274 | hso_serial_tiocmset(tty, NULL, TIOCM_RTS | TIOCM_DTR, 0); | 1277 | hso_serial_tiocmset(tty, NULL, TIOCM_RTS | TIOCM_DTR, 0); |
1275 | err_out: | 1278 | err_out: |
1276 | mutex_unlock(&serial->parent->mutex); | 1279 | mutex_unlock(&serial->parent->mutex); |
1277 | return result; | 1280 | return result; |
1278 | } | 1281 | } |
1279 | 1282 | ||
1280 | /* close the requested serial port */ | 1283 | /* close the requested serial port */ |
1281 | static void hso_serial_close(struct tty_struct *tty, struct file *filp) | 1284 | static void hso_serial_close(struct tty_struct *tty, struct file *filp) |
1282 | { | 1285 | { |
1283 | struct hso_serial *serial = tty->driver_data; | 1286 | struct hso_serial *serial = tty->driver_data; |
1284 | u8 usb_gone; | 1287 | u8 usb_gone; |
1285 | 1288 | ||
1286 | D1("Closing serial port"); | 1289 | D1("Closing serial port"); |
1287 | 1290 | ||
1291 | /* Open failed, no close cleanup required */ | ||
1292 | if (serial == NULL) | ||
1293 | return; | ||
1294 | |||
1288 | mutex_lock(&serial->parent->mutex); | 1295 | mutex_lock(&serial->parent->mutex); |
1289 | usb_gone = serial->parent->usb_gone; | 1296 | usb_gone = serial->parent->usb_gone; |
1290 | 1297 | ||
1291 | if (!usb_gone) | 1298 | if (!usb_gone) |
1292 | usb_autopm_get_interface(serial->parent->interface); | 1299 | usb_autopm_get_interface(serial->parent->interface); |
1293 | 1300 | ||
1294 | /* reset the rts and dtr */ | 1301 | /* reset the rts and dtr */ |
1295 | /* do the actual close */ | 1302 | /* do the actual close */ |
1296 | serial->open_count--; | 1303 | serial->open_count--; |
1297 | kref_put(&serial->parent->ref, hso_serial_ref_free); | 1304 | kref_put(&serial->parent->ref, hso_serial_ref_free); |
1298 | if (serial->open_count <= 0) { | 1305 | if (serial->open_count <= 0) { |
1299 | serial->open_count = 0; | 1306 | serial->open_count = 0; |
1300 | if (serial->tty) { | 1307 | spin_lock_irq(&serial->serial_lock); |
1308 | if (serial->tty == tty) { | ||
1301 | serial->tty->driver_data = NULL; | 1309 | serial->tty->driver_data = NULL; |
1302 | serial->tty = NULL; | 1310 | serial->tty = NULL; |
1311 | tty_kref_put(tty); | ||
1303 | } | 1312 | } |
1313 | spin_unlock_irq(&serial->serial_lock); | ||
1304 | if (!usb_gone) | 1314 | if (!usb_gone) |
1305 | hso_stop_serial_device(serial->parent); | 1315 | hso_stop_serial_device(serial->parent); |
1306 | tasklet_kill(&serial->unthrottle_tasklet); | 1316 | tasklet_kill(&serial->unthrottle_tasklet); |
1307 | cancel_work_sync(&serial->retry_unthrottle_workqueue); | 1317 | cancel_work_sync(&serial->retry_unthrottle_workqueue); |
1308 | } | 1318 | } |
1309 | 1319 | ||
1310 | if (!usb_gone) | 1320 | if (!usb_gone) |
1311 | usb_autopm_put_interface(serial->parent->interface); | 1321 | usb_autopm_put_interface(serial->parent->interface); |
1312 | 1322 | ||
1313 | mutex_unlock(&serial->parent->mutex); | 1323 | mutex_unlock(&serial->parent->mutex); |
1314 | } | 1324 | } |
1315 | 1325 | ||
1316 | /* close the requested serial port */ | 1326 | /* close the requested serial port */ |
1317 | static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, | 1327 | static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, |
1318 | int count) | 1328 | int count) |
1319 | { | 1329 | { |
1320 | struct hso_serial *serial = get_serial_by_tty(tty); | 1330 | struct hso_serial *serial = get_serial_by_tty(tty); |
1321 | int space, tx_bytes; | 1331 | int space, tx_bytes; |
1322 | unsigned long flags; | 1332 | unsigned long flags; |
1323 | 1333 | ||
1324 | /* sanity check */ | 1334 | /* sanity check */ |
1325 | if (serial == NULL) { | 1335 | if (serial == NULL) { |
1326 | printk(KERN_ERR "%s: serial is NULL\n", __func__); | 1336 | printk(KERN_ERR "%s: serial is NULL\n", __func__); |
1327 | return -ENODEV; | 1337 | return -ENODEV; |
1328 | } | 1338 | } |
1329 | 1339 | ||
1330 | spin_lock_irqsave(&serial->serial_lock, flags); | 1340 | spin_lock_irqsave(&serial->serial_lock, flags); |
1331 | 1341 | ||
1332 | space = serial->tx_data_length - serial->tx_buffer_count; | 1342 | space = serial->tx_data_length - serial->tx_buffer_count; |
1333 | tx_bytes = (count < space) ? count : space; | 1343 | tx_bytes = (count < space) ? count : space; |
1334 | 1344 | ||
1335 | if (!tx_bytes) | 1345 | if (!tx_bytes) |
1336 | goto out; | 1346 | goto out; |
1337 | 1347 | ||
1338 | memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes); | 1348 | memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, tx_bytes); |
1339 | serial->tx_buffer_count += tx_bytes; | 1349 | serial->tx_buffer_count += tx_bytes; |
1340 | 1350 | ||
1341 | out: | 1351 | out: |
1342 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1352 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1343 | 1353 | ||
1344 | hso_kick_transmit(serial); | 1354 | hso_kick_transmit(serial); |
1345 | /* done */ | 1355 | /* done */ |
1346 | return tx_bytes; | 1356 | return tx_bytes; |
1347 | } | 1357 | } |
1348 | 1358 | ||
1349 | /* how much room is there for writing */ | 1359 | /* how much room is there for writing */ |
1350 | static int hso_serial_write_room(struct tty_struct *tty) | 1360 | static int hso_serial_write_room(struct tty_struct *tty) |
1351 | { | 1361 | { |
1352 | struct hso_serial *serial = get_serial_by_tty(tty); | 1362 | struct hso_serial *serial = get_serial_by_tty(tty); |
1353 | int room; | 1363 | int room; |
1354 | unsigned long flags; | 1364 | unsigned long flags; |
1355 | 1365 | ||
1356 | spin_lock_irqsave(&serial->serial_lock, flags); | 1366 | spin_lock_irqsave(&serial->serial_lock, flags); |
1357 | room = serial->tx_data_length - serial->tx_buffer_count; | 1367 | room = serial->tx_data_length - serial->tx_buffer_count; |
1358 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1368 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1359 | 1369 | ||
1360 | /* return free room */ | 1370 | /* return free room */ |
1361 | return room; | 1371 | return room; |
1362 | } | 1372 | } |
1363 | 1373 | ||
1364 | /* setup the term */ | 1374 | /* setup the term */ |
1365 | static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) | 1375 | static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) |
1366 | { | 1376 | { |
1367 | struct hso_serial *serial = get_serial_by_tty(tty); | 1377 | struct hso_serial *serial = get_serial_by_tty(tty); |
1368 | unsigned long flags; | 1378 | unsigned long flags; |
1369 | 1379 | ||
1370 | if (old) | 1380 | if (old) |
1371 | D5("Termios called with: cflags new[%d] - old[%d]", | 1381 | D5("Termios called with: cflags new[%d] - old[%d]", |
1372 | tty->termios->c_cflag, old->c_cflag); | 1382 | tty->termios->c_cflag, old->c_cflag); |
1373 | 1383 | ||
1374 | /* the actual setup */ | 1384 | /* the actual setup */ |
1375 | spin_lock_irqsave(&serial->serial_lock, flags); | 1385 | spin_lock_irqsave(&serial->serial_lock, flags); |
1376 | if (serial->open_count) | 1386 | if (serial->open_count) |
1377 | _hso_serial_set_termios(tty, old); | 1387 | _hso_serial_set_termios(tty, old); |
1378 | else | 1388 | else |
1379 | tty->termios = old; | 1389 | tty->termios = old; |
1380 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1390 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1381 | 1391 | ||
1382 | /* done */ | 1392 | /* done */ |
1383 | return; | 1393 | return; |
1384 | } | 1394 | } |
1385 | 1395 | ||
1386 | /* how many characters in the buffer */ | 1396 | /* how many characters in the buffer */ |
1387 | static int hso_serial_chars_in_buffer(struct tty_struct *tty) | 1397 | static int hso_serial_chars_in_buffer(struct tty_struct *tty) |
1388 | { | 1398 | { |
1389 | struct hso_serial *serial = get_serial_by_tty(tty); | 1399 | struct hso_serial *serial = get_serial_by_tty(tty); |
1390 | int chars; | 1400 | int chars; |
1391 | unsigned long flags; | 1401 | unsigned long flags; |
1392 | 1402 | ||
1393 | /* sanity check */ | 1403 | /* sanity check */ |
1394 | if (serial == NULL) | 1404 | if (serial == NULL) |
1395 | return 0; | 1405 | return 0; |
1396 | 1406 | ||
1397 | spin_lock_irqsave(&serial->serial_lock, flags); | 1407 | spin_lock_irqsave(&serial->serial_lock, flags); |
1398 | chars = serial->tx_buffer_count; | 1408 | chars = serial->tx_buffer_count; |
1399 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1409 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1400 | 1410 | ||
1401 | return chars; | 1411 | return chars; |
1402 | } | 1412 | } |
1403 | 1413 | ||
1404 | static int hso_serial_tiocmget(struct tty_struct *tty, struct file *file) | 1414 | static int hso_serial_tiocmget(struct tty_struct *tty, struct file *file) |
1405 | { | 1415 | { |
1406 | unsigned int value; | 1416 | unsigned int value; |
1407 | struct hso_serial *serial = get_serial_by_tty(tty); | 1417 | struct hso_serial *serial = get_serial_by_tty(tty); |
1408 | unsigned long flags; | 1418 | unsigned long flags; |
1409 | 1419 | ||
1410 | /* sanity check */ | 1420 | /* sanity check */ |
1411 | if (!serial) { | 1421 | if (!serial) { |
1412 | D1("no tty structures"); | 1422 | D1("no tty structures"); |
1413 | return -EINVAL; | 1423 | return -EINVAL; |
1414 | } | 1424 | } |
1415 | 1425 | ||
1416 | spin_lock_irqsave(&serial->serial_lock, flags); | 1426 | spin_lock_irqsave(&serial->serial_lock, flags); |
1417 | value = ((serial->rts_state) ? TIOCM_RTS : 0) | | 1427 | value = ((serial->rts_state) ? TIOCM_RTS : 0) | |
1418 | ((serial->dtr_state) ? TIOCM_DTR : 0); | 1428 | ((serial->dtr_state) ? TIOCM_DTR : 0); |
1419 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1429 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1420 | 1430 | ||
1421 | return value; | 1431 | return value; |
1422 | } | 1432 | } |
1423 | 1433 | ||
1424 | static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file, | 1434 | static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file, |
1425 | unsigned int set, unsigned int clear) | 1435 | unsigned int set, unsigned int clear) |
1426 | { | 1436 | { |
1427 | int val = 0; | 1437 | int val = 0; |
1428 | unsigned long flags; | 1438 | unsigned long flags; |
1429 | int if_num; | 1439 | int if_num; |
1430 | struct hso_serial *serial = get_serial_by_tty(tty); | 1440 | struct hso_serial *serial = get_serial_by_tty(tty); |
1431 | 1441 | ||
1432 | /* sanity check */ | 1442 | /* sanity check */ |
1433 | if (!serial) { | 1443 | if (!serial) { |
1434 | D1("no tty structures"); | 1444 | D1("no tty structures"); |
1435 | return -EINVAL; | 1445 | return -EINVAL; |
1436 | } | 1446 | } |
1437 | if_num = serial->parent->interface->altsetting->desc.bInterfaceNumber; | 1447 | if_num = serial->parent->interface->altsetting->desc.bInterfaceNumber; |
1438 | 1448 | ||
1439 | spin_lock_irqsave(&serial->serial_lock, flags); | 1449 | spin_lock_irqsave(&serial->serial_lock, flags); |
1440 | if (set & TIOCM_RTS) | 1450 | if (set & TIOCM_RTS) |
1441 | serial->rts_state = 1; | 1451 | serial->rts_state = 1; |
1442 | if (set & TIOCM_DTR) | 1452 | if (set & TIOCM_DTR) |
1443 | serial->dtr_state = 1; | 1453 | serial->dtr_state = 1; |
1444 | 1454 | ||
1445 | if (clear & TIOCM_RTS) | 1455 | if (clear & TIOCM_RTS) |
1446 | serial->rts_state = 0; | 1456 | serial->rts_state = 0; |
1447 | if (clear & TIOCM_DTR) | 1457 | if (clear & TIOCM_DTR) |
1448 | serial->dtr_state = 0; | 1458 | serial->dtr_state = 0; |
1449 | 1459 | ||
1450 | if (serial->dtr_state) | 1460 | if (serial->dtr_state) |
1451 | val |= 0x01; | 1461 | val |= 0x01; |
1452 | if (serial->rts_state) | 1462 | if (serial->rts_state) |
1453 | val |= 0x02; | 1463 | val |= 0x02; |
1454 | 1464 | ||
1455 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1465 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1456 | 1466 | ||
1457 | return usb_control_msg(serial->parent->usb, | 1467 | return usb_control_msg(serial->parent->usb, |
1458 | usb_rcvctrlpipe(serial->parent->usb, 0), 0x22, | 1468 | usb_rcvctrlpipe(serial->parent->usb, 0), 0x22, |
1459 | 0x21, val, if_num, NULL, 0, | 1469 | 0x21, val, if_num, NULL, 0, |
1460 | USB_CTRL_SET_TIMEOUT); | 1470 | USB_CTRL_SET_TIMEOUT); |
1461 | } | 1471 | } |
1462 | 1472 | ||
1463 | /* starts a transmit */ | 1473 | /* starts a transmit */ |
1464 | static void hso_kick_transmit(struct hso_serial *serial) | 1474 | static void hso_kick_transmit(struct hso_serial *serial) |
1465 | { | 1475 | { |
1466 | u8 *temp; | 1476 | u8 *temp; |
1467 | unsigned long flags; | 1477 | unsigned long flags; |
1468 | int res; | 1478 | int res; |
1469 | 1479 | ||
1470 | spin_lock_irqsave(&serial->serial_lock, flags); | 1480 | spin_lock_irqsave(&serial->serial_lock, flags); |
1471 | if (!serial->tx_buffer_count) | 1481 | if (!serial->tx_buffer_count) |
1472 | goto out; | 1482 | goto out; |
1473 | 1483 | ||
1474 | if (serial->tx_urb_used) | 1484 | if (serial->tx_urb_used) |
1475 | goto out; | 1485 | goto out; |
1476 | 1486 | ||
1477 | /* Wakeup USB interface if necessary */ | 1487 | /* Wakeup USB interface if necessary */ |
1478 | if (hso_get_activity(serial->parent) == -EAGAIN) | 1488 | if (hso_get_activity(serial->parent) == -EAGAIN) |
1479 | goto out; | 1489 | goto out; |
1480 | 1490 | ||
1481 | /* Switch pointers around to avoid memcpy */ | 1491 | /* Switch pointers around to avoid memcpy */ |
1482 | temp = serial->tx_buffer; | 1492 | temp = serial->tx_buffer; |
1483 | serial->tx_buffer = serial->tx_data; | 1493 | serial->tx_buffer = serial->tx_data; |
1484 | serial->tx_data = temp; | 1494 | serial->tx_data = temp; |
1485 | serial->tx_data_count = serial->tx_buffer_count; | 1495 | serial->tx_data_count = serial->tx_buffer_count; |
1486 | serial->tx_buffer_count = 0; | 1496 | serial->tx_buffer_count = 0; |
1487 | 1497 | ||
1488 | /* If temp is set, it means we switched buffers */ | 1498 | /* If temp is set, it means we switched buffers */ |
1489 | if (temp && serial->write_data) { | 1499 | if (temp && serial->write_data) { |
1490 | res = serial->write_data(serial); | 1500 | res = serial->write_data(serial); |
1491 | if (res >= 0) | 1501 | if (res >= 0) |
1492 | serial->tx_urb_used = 1; | 1502 | serial->tx_urb_used = 1; |
1493 | } | 1503 | } |
1494 | out: | 1504 | out: |
1495 | spin_unlock_irqrestore(&serial->serial_lock, flags); | 1505 | spin_unlock_irqrestore(&serial->serial_lock, flags); |
1496 | } | 1506 | } |
1497 | 1507 | ||
1498 | /* make a request (for reading and writing data to muxed serial port) */ | 1508 | /* make a request (for reading and writing data to muxed serial port) */ |
1499 | static int mux_device_request(struct hso_serial *serial, u8 type, u16 port, | 1509 | static int mux_device_request(struct hso_serial *serial, u8 type, u16 port, |
1500 | struct urb *ctrl_urb, | 1510 | struct urb *ctrl_urb, |
1501 | struct usb_ctrlrequest *ctrl_req, | 1511 | struct usb_ctrlrequest *ctrl_req, |
1502 | u8 *ctrl_urb_data, u32 size) | 1512 | u8 *ctrl_urb_data, u32 size) |
1503 | { | 1513 | { |
1504 | int result; | 1514 | int result; |
1505 | int pipe; | 1515 | int pipe; |
1506 | 1516 | ||
1507 | /* Sanity check */ | 1517 | /* Sanity check */ |
1508 | if (!serial || !ctrl_urb || !ctrl_req) { | 1518 | if (!serial || !ctrl_urb || !ctrl_req) { |
1509 | printk(KERN_ERR "%s: Wrong arguments\n", __func__); | 1519 | printk(KERN_ERR "%s: Wrong arguments\n", __func__); |
1510 | return -EINVAL; | 1520 | return -EINVAL; |
1511 | } | 1521 | } |
1512 | 1522 | ||
1513 | /* initialize */ | 1523 | /* initialize */ |
1514 | ctrl_req->wValue = 0; | 1524 | ctrl_req->wValue = 0; |
1515 | ctrl_req->wIndex = hso_port_to_mux(port); | 1525 | ctrl_req->wIndex = hso_port_to_mux(port); |
1516 | ctrl_req->wLength = size; | 1526 | ctrl_req->wLength = size; |
1517 | 1527 | ||
1518 | if (type == USB_CDC_GET_ENCAPSULATED_RESPONSE) { | 1528 | if (type == USB_CDC_GET_ENCAPSULATED_RESPONSE) { |
1519 | /* Reading command */ | 1529 | /* Reading command */ |
1520 | ctrl_req->bRequestType = USB_DIR_IN | | 1530 | ctrl_req->bRequestType = USB_DIR_IN | |
1521 | USB_TYPE_OPTION_VENDOR | | 1531 | USB_TYPE_OPTION_VENDOR | |
1522 | USB_RECIP_INTERFACE; | 1532 | USB_RECIP_INTERFACE; |
1523 | ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; | 1533 | ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; |
1524 | pipe = usb_rcvctrlpipe(serial->parent->usb, 0); | 1534 | pipe = usb_rcvctrlpipe(serial->parent->usb, 0); |
1525 | } else { | 1535 | } else { |
1526 | /* Writing command */ | 1536 | /* Writing command */ |
1527 | ctrl_req->bRequestType = USB_DIR_OUT | | 1537 | ctrl_req->bRequestType = USB_DIR_OUT | |
1528 | USB_TYPE_OPTION_VENDOR | | 1538 | USB_TYPE_OPTION_VENDOR | |
1529 | USB_RECIP_INTERFACE; | 1539 | USB_RECIP_INTERFACE; |
1530 | ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; | 1540 | ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; |
1531 | pipe = usb_sndctrlpipe(serial->parent->usb, 0); | 1541 | pipe = usb_sndctrlpipe(serial->parent->usb, 0); |
1532 | } | 1542 | } |
1533 | /* syslog */ | 1543 | /* syslog */ |
1534 | D2("%s command (%02x) len: %d, port: %d", | 1544 | D2("%s command (%02x) len: %d, port: %d", |
1535 | type == USB_CDC_GET_ENCAPSULATED_RESPONSE ? "Read" : "Write", | 1545 | type == USB_CDC_GET_ENCAPSULATED_RESPONSE ? "Read" : "Write", |
1536 | ctrl_req->bRequestType, ctrl_req->wLength, port); | 1546 | ctrl_req->bRequestType, ctrl_req->wLength, port); |
1537 | 1547 | ||
1538 | /* Load ctrl urb */ | 1548 | /* Load ctrl urb */ |
1539 | ctrl_urb->transfer_flags = 0; | 1549 | ctrl_urb->transfer_flags = 0; |
1540 | usb_fill_control_urb(ctrl_urb, | 1550 | usb_fill_control_urb(ctrl_urb, |
1541 | serial->parent->usb, | 1551 | serial->parent->usb, |
1542 | pipe, | 1552 | pipe, |
1543 | (u8 *) ctrl_req, | 1553 | (u8 *) ctrl_req, |
1544 | ctrl_urb_data, size, ctrl_callback, serial); | 1554 | ctrl_urb_data, size, ctrl_callback, serial); |
1545 | /* Send it on merry way */ | 1555 | /* Send it on merry way */ |
1546 | result = usb_submit_urb(ctrl_urb, GFP_ATOMIC); | 1556 | result = usb_submit_urb(ctrl_urb, GFP_ATOMIC); |
1547 | if (result) { | 1557 | if (result) { |
1548 | dev_err(&ctrl_urb->dev->dev, | 1558 | dev_err(&ctrl_urb->dev->dev, |
1549 | "%s failed submit ctrl_urb %d type %d", __func__, | 1559 | "%s failed submit ctrl_urb %d type %d", __func__, |
1550 | result, type); | 1560 | result, type); |
1551 | return result; | 1561 | return result; |
1552 | } | 1562 | } |
1553 | 1563 | ||
1554 | /* done */ | 1564 | /* done */ |
1555 | return size; | 1565 | return size; |
1556 | } | 1566 | } |
1557 | 1567 | ||
1558 | /* called by intr_callback when read occurs */ | 1568 | /* called by intr_callback when read occurs */ |
1559 | static int hso_mux_serial_read(struct hso_serial *serial) | 1569 | static int hso_mux_serial_read(struct hso_serial *serial) |
1560 | { | 1570 | { |
1561 | if (!serial) | 1571 | if (!serial) |
1562 | return -EINVAL; | 1572 | return -EINVAL; |
1563 | 1573 | ||
1564 | /* clean data */ | 1574 | /* clean data */ |
1565 | memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE); | 1575 | memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE); |
1566 | /* make the request */ | 1576 | /* make the request */ |
1567 | 1577 | ||
1568 | if (serial->num_rx_urbs != 1) { | 1578 | if (serial->num_rx_urbs != 1) { |
1569 | dev_err(&serial->parent->interface->dev, | 1579 | dev_err(&serial->parent->interface->dev, |
1570 | "ERROR: mux'd reads with multiple buffers " | 1580 | "ERROR: mux'd reads with multiple buffers " |
1571 | "not possible\n"); | 1581 | "not possible\n"); |
1572 | return 0; | 1582 | return 0; |
1573 | } | 1583 | } |
1574 | return mux_device_request(serial, | 1584 | return mux_device_request(serial, |
1575 | USB_CDC_GET_ENCAPSULATED_RESPONSE, | 1585 | USB_CDC_GET_ENCAPSULATED_RESPONSE, |
1576 | serial->parent->port_spec & HSO_PORT_MASK, | 1586 | serial->parent->port_spec & HSO_PORT_MASK, |
1577 | serial->rx_urb[0], | 1587 | serial->rx_urb[0], |
1578 | &serial->ctrl_req_rx, | 1588 | &serial->ctrl_req_rx, |
1579 | serial->rx_data[0], serial->rx_data_length); | 1589 | serial->rx_data[0], serial->rx_data_length); |
1580 | } | 1590 | } |
1581 | 1591 | ||
1582 | /* used for muxed serial port callback (muxed serial read) */ | 1592 | /* used for muxed serial port callback (muxed serial read) */ |
1583 | static void intr_callback(struct urb *urb) | 1593 | static void intr_callback(struct urb *urb) |
1584 | { | 1594 | { |
1585 | struct hso_shared_int *shared_int = urb->context; | 1595 | struct hso_shared_int *shared_int = urb->context; |
1586 | struct hso_serial *serial; | 1596 | struct hso_serial *serial; |
1587 | unsigned char *port_req; | 1597 | unsigned char *port_req; |
1588 | int status = urb->status; | 1598 | int status = urb->status; |
1589 | int i; | 1599 | int i; |
1590 | 1600 | ||
1591 | usb_mark_last_busy(urb->dev); | 1601 | usb_mark_last_busy(urb->dev); |
1592 | 1602 | ||
1593 | /* sanity check */ | 1603 | /* sanity check */ |
1594 | if (!shared_int) | 1604 | if (!shared_int) |
1595 | return; | 1605 | return; |
1596 | 1606 | ||
1597 | /* status check */ | 1607 | /* status check */ |
1598 | if (status) { | 1608 | if (status) { |
1599 | log_usb_status(status, __func__); | 1609 | log_usb_status(status, __func__); |
1600 | return; | 1610 | return; |
1601 | } | 1611 | } |
1602 | D4("\n--- Got intr callback 0x%02X ---", status); | 1612 | D4("\n--- Got intr callback 0x%02X ---", status); |
1603 | 1613 | ||
1604 | /* what request? */ | 1614 | /* what request? */ |
1605 | port_req = urb->transfer_buffer; | 1615 | port_req = urb->transfer_buffer; |
1606 | D4(" port_req = 0x%.2X\n", *port_req); | 1616 | D4(" port_req = 0x%.2X\n", *port_req); |
1607 | /* loop over all muxed ports to find the one sending this */ | 1617 | /* loop over all muxed ports to find the one sending this */ |
1608 | for (i = 0; i < 8; i++) { | 1618 | for (i = 0; i < 8; i++) { |
1609 | /* max 8 channels on MUX */ | 1619 | /* max 8 channels on MUX */ |
1610 | if (*port_req & (1 << i)) { | 1620 | if (*port_req & (1 << i)) { |
1611 | serial = get_serial_by_shared_int_and_type(shared_int, | 1621 | serial = get_serial_by_shared_int_and_type(shared_int, |
1612 | (1 << i)); | 1622 | (1 << i)); |
1613 | if (serial != NULL) { | 1623 | if (serial != NULL) { |
1614 | D1("Pending read interrupt on port %d\n", i); | 1624 | D1("Pending read interrupt on port %d\n", i); |
1615 | spin_lock(&serial->serial_lock); | 1625 | spin_lock(&serial->serial_lock); |
1616 | if (serial->rx_state == RX_IDLE) { | 1626 | if (serial->rx_state == RX_IDLE) { |
1617 | /* Setup and send a ctrl req read on | 1627 | /* Setup and send a ctrl req read on |
1618 | * port i */ | 1628 | * port i */ |
1619 | if (!serial->rx_urb_filled[0]) { | 1629 | if (!serial->rx_urb_filled[0]) { |
1620 | serial->rx_state = RX_SENT; | 1630 | serial->rx_state = RX_SENT; |
1621 | hso_mux_serial_read(serial); | 1631 | hso_mux_serial_read(serial); |
1622 | } else | 1632 | } else |
1623 | serial->rx_state = RX_PENDING; | 1633 | serial->rx_state = RX_PENDING; |
1624 | 1634 | ||
1625 | } else { | 1635 | } else { |
1626 | D1("Already pending a read on " | 1636 | D1("Already pending a read on " |
1627 | "port %d\n", i); | 1637 | "port %d\n", i); |
1628 | } | 1638 | } |
1629 | spin_unlock(&serial->serial_lock); | 1639 | spin_unlock(&serial->serial_lock); |
1630 | } | 1640 | } |
1631 | } | 1641 | } |
1632 | } | 1642 | } |
1633 | /* Resubmit interrupt urb */ | 1643 | /* Resubmit interrupt urb */ |
1634 | hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC); | 1644 | hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC); |
1635 | } | 1645 | } |
1636 | 1646 | ||
1637 | /* called for writing to muxed serial port */ | 1647 | /* called for writing to muxed serial port */ |
1638 | static int hso_mux_serial_write_data(struct hso_serial *serial) | 1648 | static int hso_mux_serial_write_data(struct hso_serial *serial) |
1639 | { | 1649 | { |
1640 | if (NULL == serial) | 1650 | if (NULL == serial) |
1641 | return -EINVAL; | 1651 | return -EINVAL; |
1642 | 1652 | ||
1643 | return mux_device_request(serial, | 1653 | return mux_device_request(serial, |
1644 | USB_CDC_SEND_ENCAPSULATED_COMMAND, | 1654 | USB_CDC_SEND_ENCAPSULATED_COMMAND, |
1645 | serial->parent->port_spec & HSO_PORT_MASK, | 1655 | serial->parent->port_spec & HSO_PORT_MASK, |
1646 | serial->tx_urb, | 1656 | serial->tx_urb, |
1647 | &serial->ctrl_req_tx, | 1657 | &serial->ctrl_req_tx, |
1648 | serial->tx_data, serial->tx_data_count); | 1658 | serial->tx_data, serial->tx_data_count); |
1649 | } | 1659 | } |
1650 | 1660 | ||
1651 | /* write callback for Diag and CS port */ | 1661 | /* write callback for Diag and CS port */ |
1652 | static void hso_std_serial_write_bulk_callback(struct urb *urb) | 1662 | static void hso_std_serial_write_bulk_callback(struct urb *urb) |
1653 | { | 1663 | { |
1654 | struct hso_serial *serial = urb->context; | 1664 | struct hso_serial *serial = urb->context; |
1655 | int status = urb->status; | 1665 | int status = urb->status; |
1666 | struct tty_struct *tty; | ||
1656 | 1667 | ||
1657 | /* sanity check */ | 1668 | /* sanity check */ |
1658 | if (!serial) { | 1669 | if (!serial) { |
1659 | D1("serial == NULL"); | 1670 | D1("serial == NULL"); |
1660 | return; | 1671 | return; |
1661 | } | 1672 | } |
1662 | 1673 | ||
1663 | spin_lock(&serial->serial_lock); | 1674 | spin_lock(&serial->serial_lock); |
1664 | serial->tx_urb_used = 0; | 1675 | serial->tx_urb_used = 0; |
1676 | tty = tty_kref_get(serial->tty); | ||
1665 | spin_unlock(&serial->serial_lock); | 1677 | spin_unlock(&serial->serial_lock); |
1666 | if (status) { | 1678 | if (status) { |
1667 | log_usb_status(status, __func__); | 1679 | log_usb_status(status, __func__); |
1680 | tty_kref_put(tty); | ||
1668 | return; | 1681 | return; |
1669 | } | 1682 | } |
1670 | hso_put_activity(serial->parent); | 1683 | hso_put_activity(serial->parent); |
1671 | if (serial->tty) | 1684 | if (tty) { |
1672 | tty_wakeup(serial->tty); | 1685 | tty_wakeup(tty); |
1686 | tty_kref_put(tty); | ||
1687 | } | ||
1673 | hso_kick_transmit(serial); | 1688 | hso_kick_transmit(serial); |
1674 | 1689 | ||
1675 | D1(" "); | 1690 | D1(" "); |
1676 | return; | 1691 | return; |
1677 | } | 1692 | } |
1678 | 1693 | ||
1679 | /* called for writing diag or CS serial port */ | 1694 | /* called for writing diag or CS serial port */ |
1680 | static int hso_std_serial_write_data(struct hso_serial *serial) | 1695 | static int hso_std_serial_write_data(struct hso_serial *serial) |
1681 | { | 1696 | { |
1682 | int count = serial->tx_data_count; | 1697 | int count = serial->tx_data_count; |
1683 | int result; | 1698 | int result; |
1684 | 1699 | ||
1685 | usb_fill_bulk_urb(serial->tx_urb, | 1700 | usb_fill_bulk_urb(serial->tx_urb, |
1686 | serial->parent->usb, | 1701 | serial->parent->usb, |
1687 | usb_sndbulkpipe(serial->parent->usb, | 1702 | usb_sndbulkpipe(serial->parent->usb, |
1688 | serial->out_endp-> | 1703 | serial->out_endp-> |
1689 | bEndpointAddress & 0x7F), | 1704 | bEndpointAddress & 0x7F), |
1690 | serial->tx_data, serial->tx_data_count, | 1705 | serial->tx_data, serial->tx_data_count, |
1691 | hso_std_serial_write_bulk_callback, serial); | 1706 | hso_std_serial_write_bulk_callback, serial); |
1692 | 1707 | ||
1693 | result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC); | 1708 | result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC); |
1694 | if (result) { | 1709 | if (result) { |
1695 | dev_warn(&serial->parent->usb->dev, | 1710 | dev_warn(&serial->parent->usb->dev, |
1696 | "Failed to submit urb - res %d\n", result); | 1711 | "Failed to submit urb - res %d\n", result); |
1697 | return result; | 1712 | return result; |
1698 | } | 1713 | } |
1699 | 1714 | ||
1700 | return count; | 1715 | return count; |
1701 | } | 1716 | } |
1702 | 1717 | ||
1703 | /* callback after read or write on muxed serial port */ | 1718 | /* callback after read or write on muxed serial port */ |
1704 | static void ctrl_callback(struct urb *urb) | 1719 | static void ctrl_callback(struct urb *urb) |
1705 | { | 1720 | { |
1706 | struct hso_serial *serial = urb->context; | 1721 | struct hso_serial *serial = urb->context; |
1707 | struct usb_ctrlrequest *req; | 1722 | struct usb_ctrlrequest *req; |
1708 | int status = urb->status; | 1723 | int status = urb->status; |
1724 | struct tty_struct *tty; | ||
1709 | 1725 | ||
1710 | /* sanity check */ | 1726 | /* sanity check */ |
1711 | if (!serial) | 1727 | if (!serial) |
1712 | return; | 1728 | return; |
1713 | 1729 | ||
1714 | spin_lock(&serial->serial_lock); | 1730 | spin_lock(&serial->serial_lock); |
1715 | serial->tx_urb_used = 0; | 1731 | serial->tx_urb_used = 0; |
1732 | tty = tty_kref_get(serial->tty); | ||
1716 | spin_unlock(&serial->serial_lock); | 1733 | spin_unlock(&serial->serial_lock); |
1717 | if (status) { | 1734 | if (status) { |
1718 | log_usb_status(status, __func__); | 1735 | log_usb_status(status, __func__); |
1736 | tty_kref_put(tty); | ||
1719 | return; | 1737 | return; |
1720 | } | 1738 | } |
1721 | 1739 | ||
1722 | /* what request? */ | 1740 | /* what request? */ |
1723 | req = (struct usb_ctrlrequest *)(urb->setup_packet); | 1741 | req = (struct usb_ctrlrequest *)(urb->setup_packet); |
1724 | D4("\n--- Got muxed ctrl callback 0x%02X ---", status); | 1742 | D4("\n--- Got muxed ctrl callback 0x%02X ---", status); |
1725 | D4("Actual length of urb = %d\n", urb->actual_length); | 1743 | D4("Actual length of urb = %d\n", urb->actual_length); |
1726 | DUMP1(urb->transfer_buffer, urb->actual_length); | 1744 | DUMP1(urb->transfer_buffer, urb->actual_length); |
1727 | 1745 | ||
1728 | if (req->bRequestType == | 1746 | if (req->bRequestType == |
1729 | (USB_DIR_IN | USB_TYPE_OPTION_VENDOR | USB_RECIP_INTERFACE)) { | 1747 | (USB_DIR_IN | USB_TYPE_OPTION_VENDOR | USB_RECIP_INTERFACE)) { |
1730 | /* response to a read command */ | 1748 | /* response to a read command */ |
1731 | serial->rx_urb_filled[0] = 1; | 1749 | serial->rx_urb_filled[0] = 1; |
1732 | spin_lock(&serial->serial_lock); | 1750 | spin_lock(&serial->serial_lock); |
1733 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); | 1751 | put_rxbuf_data_and_resubmit_ctrl_urb(serial); |
1734 | spin_unlock(&serial->serial_lock); | 1752 | spin_unlock(&serial->serial_lock); |
1735 | } else { | 1753 | } else { |
1736 | hso_put_activity(serial->parent); | 1754 | hso_put_activity(serial->parent); |
1737 | if (serial->tty) | 1755 | if (tty) |
1738 | tty_wakeup(serial->tty); | 1756 | tty_wakeup(tty); |
1739 | /* response to a write command */ | 1757 | /* response to a write command */ |
1740 | hso_kick_transmit(serial); | 1758 | hso_kick_transmit(serial); |
1741 | } | 1759 | } |
1760 | tty_kref_put(tty); | ||
1742 | } | 1761 | } |
1743 | 1762 | ||
1744 | /* handle RX data for serial port */ | 1763 | /* handle RX data for serial port */ |
1745 | static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) | 1764 | static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) |
1746 | { | 1765 | { |
1747 | struct tty_struct *tty = serial->tty; | 1766 | struct tty_struct *tty; |
1748 | int write_length_remaining = 0; | 1767 | int write_length_remaining = 0; |
1749 | int curr_write_len; | 1768 | int curr_write_len; |
1769 | |||
1750 | /* Sanity check */ | 1770 | /* Sanity check */ |
1751 | if (urb == NULL || serial == NULL) { | 1771 | if (urb == NULL || serial == NULL) { |
1752 | D1("serial = NULL"); | 1772 | D1("serial = NULL"); |
1753 | return -2; | 1773 | return -2; |
1754 | } | 1774 | } |
1755 | 1775 | ||
1776 | spin_lock(&serial->serial_lock); | ||
1777 | tty = tty_kref_get(serial->tty); | ||
1778 | spin_unlock(&serial->serial_lock); | ||
1779 | |||
1756 | /* Push data to tty */ | 1780 | /* Push data to tty */ |
1757 | if (tty) { | 1781 | if (tty) { |
1758 | write_length_remaining = urb->actual_length - | 1782 | write_length_remaining = urb->actual_length - |
1759 | serial->curr_rx_urb_offset; | 1783 | serial->curr_rx_urb_offset; |
1760 | D1("data to push to tty"); | 1784 | D1("data to push to tty"); |
1761 | while (write_length_remaining) { | 1785 | while (write_length_remaining) { |
1762 | if (test_bit(TTY_THROTTLED, &tty->flags)) | 1786 | if (test_bit(TTY_THROTTLED, &tty->flags)) |
1763 | return -1; | 1787 | return -1; |
1764 | curr_write_len = tty_insert_flip_string | 1788 | curr_write_len = tty_insert_flip_string |
1765 | (tty, urb->transfer_buffer + | 1789 | (tty, urb->transfer_buffer + |
1766 | serial->curr_rx_urb_offset, | 1790 | serial->curr_rx_urb_offset, |
1767 | write_length_remaining); | 1791 | write_length_remaining); |
1768 | serial->curr_rx_urb_offset += curr_write_len; | 1792 | serial->curr_rx_urb_offset += curr_write_len; |
1769 | write_length_remaining -= curr_write_len; | 1793 | write_length_remaining -= curr_write_len; |
1770 | tty_flip_buffer_push(tty); | 1794 | tty_flip_buffer_push(tty); |
1771 | } | 1795 | } |
1772 | } | 1796 | } |
1773 | if (write_length_remaining == 0) { | 1797 | if (write_length_remaining == 0) { |
1774 | serial->curr_rx_urb_offset = 0; | 1798 | serial->curr_rx_urb_offset = 0; |
1775 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; | 1799 | serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; |
1776 | } | 1800 | } |
1801 | tty_kref_put(tty); | ||
1777 | return write_length_remaining; | 1802 | return write_length_remaining; |
1778 | } | 1803 | } |
1779 | 1804 | ||
1780 | 1805 | ||
1781 | /* Base driver functions */ | 1806 | /* Base driver functions */ |
1782 | 1807 | ||
1783 | static void hso_log_port(struct hso_device *hso_dev) | 1808 | static void hso_log_port(struct hso_device *hso_dev) |
1784 | { | 1809 | { |
1785 | char *port_type; | 1810 | char *port_type; |
1786 | char port_dev[20]; | 1811 | char port_dev[20]; |
1787 | 1812 | ||
1788 | switch (hso_dev->port_spec & HSO_PORT_MASK) { | 1813 | switch (hso_dev->port_spec & HSO_PORT_MASK) { |
1789 | case HSO_PORT_CONTROL: | 1814 | case HSO_PORT_CONTROL: |
1790 | port_type = "Control"; | 1815 | port_type = "Control"; |
1791 | break; | 1816 | break; |
1792 | case HSO_PORT_APP: | 1817 | case HSO_PORT_APP: |
1793 | port_type = "Application"; | 1818 | port_type = "Application"; |
1794 | break; | 1819 | break; |
1795 | case HSO_PORT_GPS: | 1820 | case HSO_PORT_GPS: |
1796 | port_type = "GPS"; | 1821 | port_type = "GPS"; |
1797 | break; | 1822 | break; |
1798 | case HSO_PORT_GPS_CONTROL: | 1823 | case HSO_PORT_GPS_CONTROL: |
1799 | port_type = "GPS control"; | 1824 | port_type = "GPS control"; |
1800 | break; | 1825 | break; |
1801 | case HSO_PORT_APP2: | 1826 | case HSO_PORT_APP2: |
1802 | port_type = "Application2"; | 1827 | port_type = "Application2"; |
1803 | break; | 1828 | break; |
1804 | case HSO_PORT_PCSC: | 1829 | case HSO_PORT_PCSC: |
1805 | port_type = "PCSC"; | 1830 | port_type = "PCSC"; |
1806 | break; | 1831 | break; |
1807 | case HSO_PORT_DIAG: | 1832 | case HSO_PORT_DIAG: |
1808 | port_type = "Diagnostic"; | 1833 | port_type = "Diagnostic"; |
1809 | break; | 1834 | break; |
1810 | case HSO_PORT_DIAG2: | 1835 | case HSO_PORT_DIAG2: |
1811 | port_type = "Diagnostic2"; | 1836 | port_type = "Diagnostic2"; |
1812 | break; | 1837 | break; |
1813 | case HSO_PORT_MODEM: | 1838 | case HSO_PORT_MODEM: |
1814 | port_type = "Modem"; | 1839 | port_type = "Modem"; |
1815 | break; | 1840 | break; |
1816 | case HSO_PORT_NETWORK: | 1841 | case HSO_PORT_NETWORK: |
1817 | port_type = "Network"; | 1842 | port_type = "Network"; |
1818 | break; | 1843 | break; |
1819 | default: | 1844 | default: |
1820 | port_type = "Unknown"; | 1845 | port_type = "Unknown"; |
1821 | break; | 1846 | break; |
1822 | } | 1847 | } |
1823 | if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) { | 1848 | if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) { |
1824 | sprintf(port_dev, "%s", dev2net(hso_dev)->net->name); | 1849 | sprintf(port_dev, "%s", dev2net(hso_dev)->net->name); |
1825 | } else | 1850 | } else |
1826 | sprintf(port_dev, "/dev/%s%d", tty_filename, | 1851 | sprintf(port_dev, "/dev/%s%d", tty_filename, |
1827 | dev2ser(hso_dev)->minor); | 1852 | dev2ser(hso_dev)->minor); |
1828 | 1853 | ||
1829 | dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n", | 1854 | dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n", |
1830 | port_type, port_dev); | 1855 | port_type, port_dev); |
1831 | } | 1856 | } |
1832 | 1857 | ||
1833 | static int hso_start_net_device(struct hso_device *hso_dev) | 1858 | static int hso_start_net_device(struct hso_device *hso_dev) |
1834 | { | 1859 | { |
1835 | int i, result = 0; | 1860 | int i, result = 0; |
1836 | struct hso_net *hso_net = dev2net(hso_dev); | 1861 | struct hso_net *hso_net = dev2net(hso_dev); |
1837 | 1862 | ||
1838 | if (!hso_net) | 1863 | if (!hso_net) |
1839 | return -ENODEV; | 1864 | return -ENODEV; |
1840 | 1865 | ||
1841 | /* send URBs for all read buffers */ | 1866 | /* send URBs for all read buffers */ |
1842 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { | 1867 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { |
1843 | 1868 | ||
1844 | /* Prep a receive URB */ | 1869 | /* Prep a receive URB */ |
1845 | usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i], | 1870 | usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i], |
1846 | hso_dev->usb, | 1871 | hso_dev->usb, |
1847 | usb_rcvbulkpipe(hso_dev->usb, | 1872 | usb_rcvbulkpipe(hso_dev->usb, |
1848 | hso_net->in_endp-> | 1873 | hso_net->in_endp-> |
1849 | bEndpointAddress & 0x7F), | 1874 | bEndpointAddress & 0x7F), |
1850 | hso_net->mux_bulk_rx_buf_pool[i], | 1875 | hso_net->mux_bulk_rx_buf_pool[i], |
1851 | MUX_BULK_RX_BUF_SIZE, read_bulk_callback, | 1876 | MUX_BULK_RX_BUF_SIZE, read_bulk_callback, |
1852 | hso_net); | 1877 | hso_net); |
1853 | 1878 | ||
1854 | /* Put it out there so the device can send us stuff */ | 1879 | /* Put it out there so the device can send us stuff */ |
1855 | result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i], | 1880 | result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i], |
1856 | GFP_NOIO); | 1881 | GFP_NOIO); |
1857 | if (result) | 1882 | if (result) |
1858 | dev_warn(&hso_dev->usb->dev, | 1883 | dev_warn(&hso_dev->usb->dev, |
1859 | "%s failed mux_bulk_rx_urb[%d] %d\n", __func__, | 1884 | "%s failed mux_bulk_rx_urb[%d] %d\n", __func__, |
1860 | i, result); | 1885 | i, result); |
1861 | } | 1886 | } |
1862 | 1887 | ||
1863 | return result; | 1888 | return result; |
1864 | } | 1889 | } |
1865 | 1890 | ||
1866 | static int hso_stop_net_device(struct hso_device *hso_dev) | 1891 | static int hso_stop_net_device(struct hso_device *hso_dev) |
1867 | { | 1892 | { |
1868 | int i; | 1893 | int i; |
1869 | struct hso_net *hso_net = dev2net(hso_dev); | 1894 | struct hso_net *hso_net = dev2net(hso_dev); |
1870 | 1895 | ||
1871 | if (!hso_net) | 1896 | if (!hso_net) |
1872 | return -ENODEV; | 1897 | return -ENODEV; |
1873 | 1898 | ||
1874 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { | 1899 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { |
1875 | if (hso_net->mux_bulk_rx_urb_pool[i]) | 1900 | if (hso_net->mux_bulk_rx_urb_pool[i]) |
1876 | usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]); | 1901 | usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]); |
1877 | 1902 | ||
1878 | } | 1903 | } |
1879 | if (hso_net->mux_bulk_tx_urb) | 1904 | if (hso_net->mux_bulk_tx_urb) |
1880 | usb_kill_urb(hso_net->mux_bulk_tx_urb); | 1905 | usb_kill_urb(hso_net->mux_bulk_tx_urb); |
1881 | 1906 | ||
1882 | return 0; | 1907 | return 0; |
1883 | } | 1908 | } |
1884 | 1909 | ||
1885 | static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags) | 1910 | static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags) |
1886 | { | 1911 | { |
1887 | int i, result = 0; | 1912 | int i, result = 0; |
1888 | struct hso_serial *serial = dev2ser(hso_dev); | 1913 | struct hso_serial *serial = dev2ser(hso_dev); |
1889 | 1914 | ||
1890 | if (!serial) | 1915 | if (!serial) |
1891 | return -ENODEV; | 1916 | return -ENODEV; |
1892 | 1917 | ||
1893 | /* If it is not the MUX port fill in and submit a bulk urb (already | 1918 | /* If it is not the MUX port fill in and submit a bulk urb (already |
1894 | * allocated in hso_serial_start) */ | 1919 | * allocated in hso_serial_start) */ |
1895 | if (!(serial->parent->port_spec & HSO_INTF_MUX)) { | 1920 | if (!(serial->parent->port_spec & HSO_INTF_MUX)) { |
1896 | for (i = 0; i < serial->num_rx_urbs; i++) { | 1921 | for (i = 0; i < serial->num_rx_urbs; i++) { |
1897 | usb_fill_bulk_urb(serial->rx_urb[i], | 1922 | usb_fill_bulk_urb(serial->rx_urb[i], |
1898 | serial->parent->usb, | 1923 | serial->parent->usb, |
1899 | usb_rcvbulkpipe(serial->parent->usb, | 1924 | usb_rcvbulkpipe(serial->parent->usb, |
1900 | serial->in_endp-> | 1925 | serial->in_endp-> |
1901 | bEndpointAddress & | 1926 | bEndpointAddress & |
1902 | 0x7F), | 1927 | 0x7F), |
1903 | serial->rx_data[i], | 1928 | serial->rx_data[i], |
1904 | serial->rx_data_length, | 1929 | serial->rx_data_length, |
1905 | hso_std_serial_read_bulk_callback, | 1930 | hso_std_serial_read_bulk_callback, |
1906 | serial); | 1931 | serial); |
1907 | result = usb_submit_urb(serial->rx_urb[i], flags); | 1932 | result = usb_submit_urb(serial->rx_urb[i], flags); |
1908 | if (result) { | 1933 | if (result) { |
1909 | dev_warn(&serial->parent->usb->dev, | 1934 | dev_warn(&serial->parent->usb->dev, |
1910 | "Failed to submit urb - res %d\n", | 1935 | "Failed to submit urb - res %d\n", |
1911 | result); | 1936 | result); |
1912 | break; | 1937 | break; |
1913 | } | 1938 | } |
1914 | } | 1939 | } |
1915 | } else { | 1940 | } else { |
1916 | mutex_lock(&serial->shared_int->shared_int_lock); | 1941 | mutex_lock(&serial->shared_int->shared_int_lock); |
1917 | if (!serial->shared_int->use_count) { | 1942 | if (!serial->shared_int->use_count) { |
1918 | result = | 1943 | result = |
1919 | hso_mux_submit_intr_urb(serial->shared_int, | 1944 | hso_mux_submit_intr_urb(serial->shared_int, |
1920 | hso_dev->usb, flags); | 1945 | hso_dev->usb, flags); |
1921 | } | 1946 | } |
1922 | serial->shared_int->use_count++; | 1947 | serial->shared_int->use_count++; |
1923 | mutex_unlock(&serial->shared_int->shared_int_lock); | 1948 | mutex_unlock(&serial->shared_int->shared_int_lock); |
1924 | } | 1949 | } |
1925 | 1950 | ||
1926 | return result; | 1951 | return result; |
1927 | } | 1952 | } |
1928 | 1953 | ||
1929 | static int hso_stop_serial_device(struct hso_device *hso_dev) | 1954 | static int hso_stop_serial_device(struct hso_device *hso_dev) |
1930 | { | 1955 | { |
1931 | int i; | 1956 | int i; |
1932 | struct hso_serial *serial = dev2ser(hso_dev); | 1957 | struct hso_serial *serial = dev2ser(hso_dev); |
1933 | 1958 | ||
1934 | if (!serial) | 1959 | if (!serial) |
1935 | return -ENODEV; | 1960 | return -ENODEV; |
1936 | 1961 | ||
1937 | for (i = 0; i < serial->num_rx_urbs; i++) { | 1962 | for (i = 0; i < serial->num_rx_urbs; i++) { |
1938 | if (serial->rx_urb[i]) { | 1963 | if (serial->rx_urb[i]) { |
1939 | usb_kill_urb(serial->rx_urb[i]); | 1964 | usb_kill_urb(serial->rx_urb[i]); |
1940 | serial->rx_urb_filled[i] = 0; | 1965 | serial->rx_urb_filled[i] = 0; |
1941 | } | 1966 | } |
1942 | } | 1967 | } |
1943 | serial->curr_rx_urb_idx = 0; | 1968 | serial->curr_rx_urb_idx = 0; |
1944 | serial->curr_rx_urb_offset = 0; | 1969 | serial->curr_rx_urb_offset = 0; |
1945 | 1970 | ||
1946 | if (serial->tx_urb) | 1971 | if (serial->tx_urb) |
1947 | usb_kill_urb(serial->tx_urb); | 1972 | usb_kill_urb(serial->tx_urb); |
1948 | 1973 | ||
1949 | if (serial->shared_int) { | 1974 | if (serial->shared_int) { |
1950 | mutex_lock(&serial->shared_int->shared_int_lock); | 1975 | mutex_lock(&serial->shared_int->shared_int_lock); |
1951 | if (serial->shared_int->use_count && | 1976 | if (serial->shared_int->use_count && |
1952 | (--serial->shared_int->use_count == 0)) { | 1977 | (--serial->shared_int->use_count == 0)) { |
1953 | struct urb *urb; | 1978 | struct urb *urb; |
1954 | 1979 | ||
1955 | urb = serial->shared_int->shared_intr_urb; | 1980 | urb = serial->shared_int->shared_intr_urb; |
1956 | if (urb) | 1981 | if (urb) |
1957 | usb_kill_urb(urb); | 1982 | usb_kill_urb(urb); |
1958 | } | 1983 | } |
1959 | mutex_unlock(&serial->shared_int->shared_int_lock); | 1984 | mutex_unlock(&serial->shared_int->shared_int_lock); |
1960 | } | 1985 | } |
1961 | 1986 | ||
1962 | return 0; | 1987 | return 0; |
1963 | } | 1988 | } |
1964 | 1989 | ||
1965 | static void hso_serial_common_free(struct hso_serial *serial) | 1990 | static void hso_serial_common_free(struct hso_serial *serial) |
1966 | { | 1991 | { |
1967 | int i; | 1992 | int i; |
1968 | 1993 | ||
1969 | if (serial->parent->dev) | 1994 | if (serial->parent->dev) |
1970 | device_remove_file(serial->parent->dev, &dev_attr_hsotype); | 1995 | device_remove_file(serial->parent->dev, &dev_attr_hsotype); |
1971 | 1996 | ||
1972 | tty_unregister_device(tty_drv, serial->minor); | 1997 | tty_unregister_device(tty_drv, serial->minor); |
1973 | 1998 | ||
1974 | for (i = 0; i < serial->num_rx_urbs; i++) { | 1999 | for (i = 0; i < serial->num_rx_urbs; i++) { |
1975 | /* unlink and free RX URB */ | 2000 | /* unlink and free RX URB */ |
1976 | usb_free_urb(serial->rx_urb[i]); | 2001 | usb_free_urb(serial->rx_urb[i]); |
1977 | /* free the RX buffer */ | 2002 | /* free the RX buffer */ |
1978 | kfree(serial->rx_data[i]); | 2003 | kfree(serial->rx_data[i]); |
1979 | } | 2004 | } |
1980 | 2005 | ||
1981 | /* unlink and free TX URB */ | 2006 | /* unlink and free TX URB */ |
1982 | usb_free_urb(serial->tx_urb); | 2007 | usb_free_urb(serial->tx_urb); |
1983 | kfree(serial->tx_data); | 2008 | kfree(serial->tx_data); |
1984 | } | 2009 | } |
1985 | 2010 | ||
1986 | static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, | 2011 | static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, |
1987 | int rx_size, int tx_size) | 2012 | int rx_size, int tx_size) |
1988 | { | 2013 | { |
1989 | struct device *dev; | 2014 | struct device *dev; |
1990 | int minor; | 2015 | int minor; |
1991 | int i; | 2016 | int i; |
1992 | 2017 | ||
1993 | minor = get_free_serial_index(); | 2018 | minor = get_free_serial_index(); |
1994 | if (minor < 0) | 2019 | if (minor < 0) |
1995 | goto exit; | 2020 | goto exit; |
1996 | 2021 | ||
1997 | /* register our minor number */ | 2022 | /* register our minor number */ |
1998 | serial->parent->dev = tty_register_device(tty_drv, minor, | 2023 | serial->parent->dev = tty_register_device(tty_drv, minor, |
1999 | &serial->parent->interface->dev); | 2024 | &serial->parent->interface->dev); |
2000 | dev = serial->parent->dev; | 2025 | dev = serial->parent->dev; |
2001 | dev->driver_data = serial->parent; | 2026 | dev->driver_data = serial->parent; |
2002 | i = device_create_file(dev, &dev_attr_hsotype); | 2027 | i = device_create_file(dev, &dev_attr_hsotype); |
2003 | 2028 | ||
2004 | /* fill in specific data for later use */ | 2029 | /* fill in specific data for later use */ |
2005 | serial->minor = minor; | 2030 | serial->minor = minor; |
2006 | serial->magic = HSO_SERIAL_MAGIC; | 2031 | serial->magic = HSO_SERIAL_MAGIC; |
2007 | spin_lock_init(&serial->serial_lock); | 2032 | spin_lock_init(&serial->serial_lock); |
2008 | serial->num_rx_urbs = num_urbs; | 2033 | serial->num_rx_urbs = num_urbs; |
2009 | 2034 | ||
2010 | /* RX, allocate urb and initialize */ | 2035 | /* RX, allocate urb and initialize */ |
2011 | 2036 | ||
2012 | /* prepare our RX buffer */ | 2037 | /* prepare our RX buffer */ |
2013 | serial->rx_data_length = rx_size; | 2038 | serial->rx_data_length = rx_size; |
2014 | for (i = 0; i < serial->num_rx_urbs; i++) { | 2039 | for (i = 0; i < serial->num_rx_urbs; i++) { |
2015 | serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); | 2040 | serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); |
2016 | if (!serial->rx_urb[i]) { | 2041 | if (!serial->rx_urb[i]) { |
2017 | dev_err(dev, "Could not allocate urb?\n"); | 2042 | dev_err(dev, "Could not allocate urb?\n"); |
2018 | goto exit; | 2043 | goto exit; |
2019 | } | 2044 | } |
2020 | serial->rx_urb[i]->transfer_buffer = NULL; | 2045 | serial->rx_urb[i]->transfer_buffer = NULL; |
2021 | serial->rx_urb[i]->transfer_buffer_length = 0; | 2046 | serial->rx_urb[i]->transfer_buffer_length = 0; |
2022 | serial->rx_data[i] = kzalloc(serial->rx_data_length, | 2047 | serial->rx_data[i] = kzalloc(serial->rx_data_length, |
2023 | GFP_KERNEL); | 2048 | GFP_KERNEL); |
2024 | if (!serial->rx_data[i]) { | 2049 | if (!serial->rx_data[i]) { |
2025 | dev_err(dev, "%s - Out of memory\n", __func__); | 2050 | dev_err(dev, "%s - Out of memory\n", __func__); |
2026 | goto exit; | 2051 | goto exit; |
2027 | } | 2052 | } |
2028 | } | 2053 | } |
2029 | 2054 | ||
2030 | /* TX, allocate urb and initialize */ | 2055 | /* TX, allocate urb and initialize */ |
2031 | serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL); | 2056 | serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL); |
2032 | if (!serial->tx_urb) { | 2057 | if (!serial->tx_urb) { |
2033 | dev_err(dev, "Could not allocate urb?\n"); | 2058 | dev_err(dev, "Could not allocate urb?\n"); |
2034 | goto exit; | 2059 | goto exit; |
2035 | } | 2060 | } |
2036 | serial->tx_urb->transfer_buffer = NULL; | 2061 | serial->tx_urb->transfer_buffer = NULL; |
2037 | serial->tx_urb->transfer_buffer_length = 0; | 2062 | serial->tx_urb->transfer_buffer_length = 0; |
2038 | /* prepare our TX buffer */ | 2063 | /* prepare our TX buffer */ |
2039 | serial->tx_data_count = 0; | 2064 | serial->tx_data_count = 0; |
2040 | serial->tx_buffer_count = 0; | 2065 | serial->tx_buffer_count = 0; |
2041 | serial->tx_data_length = tx_size; | 2066 | serial->tx_data_length = tx_size; |
2042 | serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL); | 2067 | serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL); |
2043 | if (!serial->tx_data) { | 2068 | if (!serial->tx_data) { |
2044 | dev_err(dev, "%s - Out of memory", __func__); | 2069 | dev_err(dev, "%s - Out of memory", __func__); |
2045 | goto exit; | 2070 | goto exit; |
2046 | } | 2071 | } |
2047 | serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL); | 2072 | serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL); |
2048 | if (!serial->tx_buffer) { | 2073 | if (!serial->tx_buffer) { |
2049 | dev_err(dev, "%s - Out of memory", __func__); | 2074 | dev_err(dev, "%s - Out of memory", __func__); |
2050 | goto exit; | 2075 | goto exit; |
2051 | } | 2076 | } |
2052 | 2077 | ||
2053 | return 0; | 2078 | return 0; |
2054 | exit: | 2079 | exit: |
2055 | hso_serial_common_free(serial); | 2080 | hso_serial_common_free(serial); |
2056 | return -1; | 2081 | return -1; |
2057 | } | 2082 | } |
2058 | 2083 | ||
2059 | /* Frees a general hso device */ | 2084 | /* Frees a general hso device */ |
2060 | static void hso_free_device(struct hso_device *hso_dev) | 2085 | static void hso_free_device(struct hso_device *hso_dev) |
2061 | { | 2086 | { |
2062 | kfree(hso_dev); | 2087 | kfree(hso_dev); |
2063 | } | 2088 | } |
2064 | 2089 | ||
2065 | /* Creates a general hso device */ | 2090 | /* Creates a general hso device */ |
2066 | static struct hso_device *hso_create_device(struct usb_interface *intf, | 2091 | static struct hso_device *hso_create_device(struct usb_interface *intf, |
2067 | int port_spec) | 2092 | int port_spec) |
2068 | { | 2093 | { |
2069 | struct hso_device *hso_dev; | 2094 | struct hso_device *hso_dev; |
2070 | 2095 | ||
2071 | hso_dev = kzalloc(sizeof(*hso_dev), GFP_ATOMIC); | 2096 | hso_dev = kzalloc(sizeof(*hso_dev), GFP_ATOMIC); |
2072 | if (!hso_dev) | 2097 | if (!hso_dev) |
2073 | return NULL; | 2098 | return NULL; |
2074 | 2099 | ||
2075 | hso_dev->port_spec = port_spec; | 2100 | hso_dev->port_spec = port_spec; |
2076 | hso_dev->usb = interface_to_usbdev(intf); | 2101 | hso_dev->usb = interface_to_usbdev(intf); |
2077 | hso_dev->interface = intf; | 2102 | hso_dev->interface = intf; |
2078 | kref_init(&hso_dev->ref); | 2103 | kref_init(&hso_dev->ref); |
2079 | mutex_init(&hso_dev->mutex); | 2104 | mutex_init(&hso_dev->mutex); |
2080 | 2105 | ||
2081 | INIT_WORK(&hso_dev->async_get_intf, async_get_intf); | 2106 | INIT_WORK(&hso_dev->async_get_intf, async_get_intf); |
2082 | INIT_WORK(&hso_dev->async_put_intf, async_put_intf); | 2107 | INIT_WORK(&hso_dev->async_put_intf, async_put_intf); |
2083 | 2108 | ||
2084 | return hso_dev; | 2109 | return hso_dev; |
2085 | } | 2110 | } |
2086 | 2111 | ||
2087 | /* Removes a network device in the network device table */ | 2112 | /* Removes a network device in the network device table */ |
2088 | static int remove_net_device(struct hso_device *hso_dev) | 2113 | static int remove_net_device(struct hso_device *hso_dev) |
2089 | { | 2114 | { |
2090 | int i; | 2115 | int i; |
2091 | 2116 | ||
2092 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { | 2117 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { |
2093 | if (network_table[i] == hso_dev) { | 2118 | if (network_table[i] == hso_dev) { |
2094 | network_table[i] = NULL; | 2119 | network_table[i] = NULL; |
2095 | break; | 2120 | break; |
2096 | } | 2121 | } |
2097 | } | 2122 | } |
2098 | if (i == HSO_MAX_NET_DEVICES) | 2123 | if (i == HSO_MAX_NET_DEVICES) |
2099 | return -1; | 2124 | return -1; |
2100 | return 0; | 2125 | return 0; |
2101 | } | 2126 | } |
2102 | 2127 | ||
2103 | /* Frees our network device */ | 2128 | /* Frees our network device */ |
2104 | static void hso_free_net_device(struct hso_device *hso_dev) | 2129 | static void hso_free_net_device(struct hso_device *hso_dev) |
2105 | { | 2130 | { |
2106 | int i; | 2131 | int i; |
2107 | struct hso_net *hso_net = dev2net(hso_dev); | 2132 | struct hso_net *hso_net = dev2net(hso_dev); |
2108 | 2133 | ||
2109 | if (!hso_net) | 2134 | if (!hso_net) |
2110 | return; | 2135 | return; |
2111 | 2136 | ||
2112 | /* start freeing */ | 2137 | /* start freeing */ |
2113 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { | 2138 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { |
2114 | usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]); | 2139 | usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]); |
2115 | kfree(hso_net->mux_bulk_rx_buf_pool[i]); | 2140 | kfree(hso_net->mux_bulk_rx_buf_pool[i]); |
2116 | } | 2141 | } |
2117 | usb_free_urb(hso_net->mux_bulk_tx_urb); | 2142 | usb_free_urb(hso_net->mux_bulk_tx_urb); |
2118 | kfree(hso_net->mux_bulk_tx_buf); | 2143 | kfree(hso_net->mux_bulk_tx_buf); |
2119 | 2144 | ||
2120 | remove_net_device(hso_net->parent); | 2145 | remove_net_device(hso_net->parent); |
2121 | 2146 | ||
2122 | if (hso_net->net) { | 2147 | if (hso_net->net) { |
2123 | unregister_netdev(hso_net->net); | 2148 | unregister_netdev(hso_net->net); |
2124 | free_netdev(hso_net->net); | 2149 | free_netdev(hso_net->net); |
2125 | } | 2150 | } |
2126 | 2151 | ||
2127 | hso_free_device(hso_dev); | 2152 | hso_free_device(hso_dev); |
2128 | } | 2153 | } |
2129 | 2154 | ||
2130 | /* initialize the network interface */ | 2155 | /* initialize the network interface */ |
2131 | static void hso_net_init(struct net_device *net) | 2156 | static void hso_net_init(struct net_device *net) |
2132 | { | 2157 | { |
2133 | struct hso_net *hso_net = netdev_priv(net); | 2158 | struct hso_net *hso_net = netdev_priv(net); |
2134 | 2159 | ||
2135 | D1("sizeof hso_net is %d", (int)sizeof(*hso_net)); | 2160 | D1("sizeof hso_net is %d", (int)sizeof(*hso_net)); |
2136 | 2161 | ||
2137 | /* fill in the other fields */ | 2162 | /* fill in the other fields */ |
2138 | net->open = hso_net_open; | 2163 | net->open = hso_net_open; |
2139 | net->stop = hso_net_close; | 2164 | net->stop = hso_net_close; |
2140 | net->hard_start_xmit = hso_net_start_xmit; | 2165 | net->hard_start_xmit = hso_net_start_xmit; |
2141 | net->tx_timeout = hso_net_tx_timeout; | 2166 | net->tx_timeout = hso_net_tx_timeout; |
2142 | net->watchdog_timeo = HSO_NET_TX_TIMEOUT; | 2167 | net->watchdog_timeo = HSO_NET_TX_TIMEOUT; |
2143 | net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; | 2168 | net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; |
2144 | net->type = ARPHRD_NONE; | 2169 | net->type = ARPHRD_NONE; |
2145 | net->mtu = DEFAULT_MTU - 14; | 2170 | net->mtu = DEFAULT_MTU - 14; |
2146 | net->tx_queue_len = 10; | 2171 | net->tx_queue_len = 10; |
2147 | SET_ETHTOOL_OPS(net, &ops); | 2172 | SET_ETHTOOL_OPS(net, &ops); |
2148 | 2173 | ||
2149 | /* and initialize the semaphore */ | 2174 | /* and initialize the semaphore */ |
2150 | spin_lock_init(&hso_net->net_lock); | 2175 | spin_lock_init(&hso_net->net_lock); |
2151 | } | 2176 | } |
2152 | 2177 | ||
2153 | /* Adds a network device in the network device table */ | 2178 | /* Adds a network device in the network device table */ |
2154 | static int add_net_device(struct hso_device *hso_dev) | 2179 | static int add_net_device(struct hso_device *hso_dev) |
2155 | { | 2180 | { |
2156 | int i; | 2181 | int i; |
2157 | 2182 | ||
2158 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { | 2183 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { |
2159 | if (network_table[i] == NULL) { | 2184 | if (network_table[i] == NULL) { |
2160 | network_table[i] = hso_dev; | 2185 | network_table[i] = hso_dev; |
2161 | break; | 2186 | break; |
2162 | } | 2187 | } |
2163 | } | 2188 | } |
2164 | if (i == HSO_MAX_NET_DEVICES) | 2189 | if (i == HSO_MAX_NET_DEVICES) |
2165 | return -1; | 2190 | return -1; |
2166 | return 0; | 2191 | return 0; |
2167 | } | 2192 | } |
2168 | 2193 | ||
2169 | static int hso_radio_toggle(void *data, enum rfkill_state state) | 2194 | static int hso_radio_toggle(void *data, enum rfkill_state state) |
2170 | { | 2195 | { |
2171 | struct hso_device *hso_dev = data; | 2196 | struct hso_device *hso_dev = data; |
2172 | int enabled = (state == RFKILL_STATE_ON); | 2197 | int enabled = (state == RFKILL_STATE_ON); |
2173 | int rv; | 2198 | int rv; |
2174 | 2199 | ||
2175 | mutex_lock(&hso_dev->mutex); | 2200 | mutex_lock(&hso_dev->mutex); |
2176 | if (hso_dev->usb_gone) | 2201 | if (hso_dev->usb_gone) |
2177 | rv = 0; | 2202 | rv = 0; |
2178 | else | 2203 | else |
2179 | rv = usb_control_msg(hso_dev->usb, usb_rcvctrlpipe(hso_dev->usb, 0), | 2204 | rv = usb_control_msg(hso_dev->usb, usb_rcvctrlpipe(hso_dev->usb, 0), |
2180 | enabled ? 0x82 : 0x81, 0x40, 0, 0, NULL, 0, | 2205 | enabled ? 0x82 : 0x81, 0x40, 0, 0, NULL, 0, |
2181 | USB_CTRL_SET_TIMEOUT); | 2206 | USB_CTRL_SET_TIMEOUT); |
2182 | mutex_unlock(&hso_dev->mutex); | 2207 | mutex_unlock(&hso_dev->mutex); |
2183 | return rv; | 2208 | return rv; |
2184 | } | 2209 | } |
2185 | 2210 | ||
2186 | /* Creates and sets up everything for rfkill */ | 2211 | /* Creates and sets up everything for rfkill */ |
2187 | static void hso_create_rfkill(struct hso_device *hso_dev, | 2212 | static void hso_create_rfkill(struct hso_device *hso_dev, |
2188 | struct usb_interface *interface) | 2213 | struct usb_interface *interface) |
2189 | { | 2214 | { |
2190 | struct hso_net *hso_net = dev2net(hso_dev); | 2215 | struct hso_net *hso_net = dev2net(hso_dev); |
2191 | struct device *dev = &hso_net->net->dev; | 2216 | struct device *dev = &hso_net->net->dev; |
2192 | char *rfkn; | 2217 | char *rfkn; |
2193 | 2218 | ||
2194 | hso_net->rfkill = rfkill_allocate(&interface_to_usbdev(interface)->dev, | 2219 | hso_net->rfkill = rfkill_allocate(&interface_to_usbdev(interface)->dev, |
2195 | RFKILL_TYPE_WWAN); | 2220 | RFKILL_TYPE_WWAN); |
2196 | if (!hso_net->rfkill) { | 2221 | if (!hso_net->rfkill) { |
2197 | dev_err(dev, "%s - Out of memory\n", __func__); | 2222 | dev_err(dev, "%s - Out of memory\n", __func__); |
2198 | return; | 2223 | return; |
2199 | } | 2224 | } |
2200 | rfkn = kzalloc(20, GFP_KERNEL); | 2225 | rfkn = kzalloc(20, GFP_KERNEL); |
2201 | if (!rfkn) { | 2226 | if (!rfkn) { |
2202 | rfkill_free(hso_net->rfkill); | 2227 | rfkill_free(hso_net->rfkill); |
2203 | hso_net->rfkill = NULL; | 2228 | hso_net->rfkill = NULL; |
2204 | dev_err(dev, "%s - Out of memory\n", __func__); | 2229 | dev_err(dev, "%s - Out of memory\n", __func__); |
2205 | return; | 2230 | return; |
2206 | } | 2231 | } |
2207 | snprintf(rfkn, 20, "hso-%d", | 2232 | snprintf(rfkn, 20, "hso-%d", |
2208 | interface->altsetting->desc.bInterfaceNumber); | 2233 | interface->altsetting->desc.bInterfaceNumber); |
2209 | hso_net->rfkill->name = rfkn; | 2234 | hso_net->rfkill->name = rfkn; |
2210 | hso_net->rfkill->state = RFKILL_STATE_ON; | 2235 | hso_net->rfkill->state = RFKILL_STATE_ON; |
2211 | hso_net->rfkill->data = hso_dev; | 2236 | hso_net->rfkill->data = hso_dev; |
2212 | hso_net->rfkill->toggle_radio = hso_radio_toggle; | 2237 | hso_net->rfkill->toggle_radio = hso_radio_toggle; |
2213 | if (rfkill_register(hso_net->rfkill) < 0) { | 2238 | if (rfkill_register(hso_net->rfkill) < 0) { |
2214 | kfree(rfkn); | 2239 | kfree(rfkn); |
2215 | hso_net->rfkill->name = NULL; | 2240 | hso_net->rfkill->name = NULL; |
2216 | rfkill_free(hso_net->rfkill); | 2241 | rfkill_free(hso_net->rfkill); |
2217 | hso_net->rfkill = NULL; | 2242 | hso_net->rfkill = NULL; |
2218 | dev_err(dev, "%s - Failed to register rfkill\n", __func__); | 2243 | dev_err(dev, "%s - Failed to register rfkill\n", __func__); |
2219 | return; | 2244 | return; |
2220 | } | 2245 | } |
2221 | } | 2246 | } |
2222 | 2247 | ||
2223 | /* Creates our network device */ | 2248 | /* Creates our network device */ |
2224 | static struct hso_device *hso_create_net_device(struct usb_interface *interface) | 2249 | static struct hso_device *hso_create_net_device(struct usb_interface *interface) |
2225 | { | 2250 | { |
2226 | int result, i; | 2251 | int result, i; |
2227 | struct net_device *net; | 2252 | struct net_device *net; |
2228 | struct hso_net *hso_net; | 2253 | struct hso_net *hso_net; |
2229 | struct hso_device *hso_dev; | 2254 | struct hso_device *hso_dev; |
2230 | 2255 | ||
2231 | hso_dev = hso_create_device(interface, HSO_INTF_MUX | HSO_PORT_NETWORK); | 2256 | hso_dev = hso_create_device(interface, HSO_INTF_MUX | HSO_PORT_NETWORK); |
2232 | if (!hso_dev) | 2257 | if (!hso_dev) |
2233 | return NULL; | 2258 | return NULL; |
2234 | 2259 | ||
2235 | /* allocate our network device, then we can put in our private data */ | 2260 | /* allocate our network device, then we can put in our private data */ |
2236 | /* call hso_net_init to do the basic initialization */ | 2261 | /* call hso_net_init to do the basic initialization */ |
2237 | net = alloc_netdev(sizeof(struct hso_net), "hso%d", hso_net_init); | 2262 | net = alloc_netdev(sizeof(struct hso_net), "hso%d", hso_net_init); |
2238 | if (!net) { | 2263 | if (!net) { |
2239 | dev_err(&interface->dev, "Unable to create ethernet device\n"); | 2264 | dev_err(&interface->dev, "Unable to create ethernet device\n"); |
2240 | goto exit; | 2265 | goto exit; |
2241 | } | 2266 | } |
2242 | 2267 | ||
2243 | hso_net = netdev_priv(net); | 2268 | hso_net = netdev_priv(net); |
2244 | 2269 | ||
2245 | hso_dev->port_data.dev_net = hso_net; | 2270 | hso_dev->port_data.dev_net = hso_net; |
2246 | hso_net->net = net; | 2271 | hso_net->net = net; |
2247 | hso_net->parent = hso_dev; | 2272 | hso_net->parent = hso_dev; |
2248 | 2273 | ||
2249 | hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, | 2274 | hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, |
2250 | USB_DIR_IN); | 2275 | USB_DIR_IN); |
2251 | if (!hso_net->in_endp) { | 2276 | if (!hso_net->in_endp) { |
2252 | dev_err(&interface->dev, "Can't find BULK IN endpoint\n"); | 2277 | dev_err(&interface->dev, "Can't find BULK IN endpoint\n"); |
2253 | goto exit; | 2278 | goto exit; |
2254 | } | 2279 | } |
2255 | hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, | 2280 | hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, |
2256 | USB_DIR_OUT); | 2281 | USB_DIR_OUT); |
2257 | if (!hso_net->out_endp) { | 2282 | if (!hso_net->out_endp) { |
2258 | dev_err(&interface->dev, "Can't find BULK OUT endpoint\n"); | 2283 | dev_err(&interface->dev, "Can't find BULK OUT endpoint\n"); |
2259 | goto exit; | 2284 | goto exit; |
2260 | } | 2285 | } |
2261 | SET_NETDEV_DEV(net, &interface->dev); | 2286 | SET_NETDEV_DEV(net, &interface->dev); |
2262 | 2287 | ||
2263 | /* registering our net device */ | 2288 | /* registering our net device */ |
2264 | result = register_netdev(net); | 2289 | result = register_netdev(net); |
2265 | if (result) { | 2290 | if (result) { |
2266 | dev_err(&interface->dev, "Failed to register device\n"); | 2291 | dev_err(&interface->dev, "Failed to register device\n"); |
2267 | goto exit; | 2292 | goto exit; |
2268 | } | 2293 | } |
2269 | 2294 | ||
2270 | /* start allocating */ | 2295 | /* start allocating */ |
2271 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { | 2296 | for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { |
2272 | hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); | 2297 | hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); |
2273 | if (!hso_net->mux_bulk_rx_urb_pool[i]) { | 2298 | if (!hso_net->mux_bulk_rx_urb_pool[i]) { |
2274 | dev_err(&interface->dev, "Could not allocate rx urb\n"); | 2299 | dev_err(&interface->dev, "Could not allocate rx urb\n"); |
2275 | goto exit; | 2300 | goto exit; |
2276 | } | 2301 | } |
2277 | hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, | 2302 | hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, |
2278 | GFP_KERNEL); | 2303 | GFP_KERNEL); |
2279 | if (!hso_net->mux_bulk_rx_buf_pool[i]) { | 2304 | if (!hso_net->mux_bulk_rx_buf_pool[i]) { |
2280 | dev_err(&interface->dev, "Could not allocate rx buf\n"); | 2305 | dev_err(&interface->dev, "Could not allocate rx buf\n"); |
2281 | goto exit; | 2306 | goto exit; |
2282 | } | 2307 | } |
2283 | } | 2308 | } |
2284 | hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL); | 2309 | hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL); |
2285 | if (!hso_net->mux_bulk_tx_urb) { | 2310 | if (!hso_net->mux_bulk_tx_urb) { |
2286 | dev_err(&interface->dev, "Could not allocate tx urb\n"); | 2311 | dev_err(&interface->dev, "Could not allocate tx urb\n"); |
2287 | goto exit; | 2312 | goto exit; |
2288 | } | 2313 | } |
2289 | hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL); | 2314 | hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL); |
2290 | if (!hso_net->mux_bulk_tx_buf) { | 2315 | if (!hso_net->mux_bulk_tx_buf) { |
2291 | dev_err(&interface->dev, "Could not allocate tx buf\n"); | 2316 | dev_err(&interface->dev, "Could not allocate tx buf\n"); |
2292 | goto exit; | 2317 | goto exit; |
2293 | } | 2318 | } |
2294 | 2319 | ||
2295 | add_net_device(hso_dev); | 2320 | add_net_device(hso_dev); |
2296 | 2321 | ||
2297 | hso_log_port(hso_dev); | 2322 | hso_log_port(hso_dev); |
2298 | 2323 | ||
2299 | hso_create_rfkill(hso_dev, interface); | 2324 | hso_create_rfkill(hso_dev, interface); |
2300 | 2325 | ||
2301 | return hso_dev; | 2326 | return hso_dev; |
2302 | exit: | 2327 | exit: |
2303 | hso_free_net_device(hso_dev); | 2328 | hso_free_net_device(hso_dev); |
2304 | return NULL; | 2329 | return NULL; |
2305 | } | 2330 | } |
2306 | 2331 | ||
2307 | /* Frees an AT channel ( goes for both mux and non-mux ) */ | 2332 | /* Frees an AT channel ( goes for both mux and non-mux ) */ |
2308 | static void hso_free_serial_device(struct hso_device *hso_dev) | 2333 | static void hso_free_serial_device(struct hso_device *hso_dev) |
2309 | { | 2334 | { |
2310 | struct hso_serial *serial = dev2ser(hso_dev); | 2335 | struct hso_serial *serial = dev2ser(hso_dev); |
2311 | 2336 | ||
2312 | if (!serial) | 2337 | if (!serial) |
2313 | return; | 2338 | return; |
2314 | set_serial_by_index(serial->minor, NULL); | 2339 | set_serial_by_index(serial->minor, NULL); |
2315 | 2340 | ||
2316 | hso_serial_common_free(serial); | 2341 | hso_serial_common_free(serial); |
2317 | 2342 | ||
2318 | if (serial->shared_int) { | 2343 | if (serial->shared_int) { |
2319 | mutex_lock(&serial->shared_int->shared_int_lock); | 2344 | mutex_lock(&serial->shared_int->shared_int_lock); |
2320 | if (--serial->shared_int->ref_count == 0) | 2345 | if (--serial->shared_int->ref_count == 0) |
2321 | hso_free_shared_int(serial->shared_int); | 2346 | hso_free_shared_int(serial->shared_int); |
2322 | else | 2347 | else |
2323 | mutex_unlock(&serial->shared_int->shared_int_lock); | 2348 | mutex_unlock(&serial->shared_int->shared_int_lock); |
2324 | } | 2349 | } |
2325 | kfree(serial); | 2350 | kfree(serial); |
2326 | hso_free_device(hso_dev); | 2351 | hso_free_device(hso_dev); |
2327 | } | 2352 | } |
2328 | 2353 | ||
2329 | /* Creates a bulk AT channel */ | 2354 | /* Creates a bulk AT channel */ |
2330 | static struct hso_device *hso_create_bulk_serial_device( | 2355 | static struct hso_device *hso_create_bulk_serial_device( |
2331 | struct usb_interface *interface, int port) | 2356 | struct usb_interface *interface, int port) |
2332 | { | 2357 | { |
2333 | struct hso_device *hso_dev; | 2358 | struct hso_device *hso_dev; |
2334 | struct hso_serial *serial; | 2359 | struct hso_serial *serial; |
2335 | int num_urbs; | 2360 | int num_urbs; |
2336 | 2361 | ||
2337 | hso_dev = hso_create_device(interface, port); | 2362 | hso_dev = hso_create_device(interface, port); |
2338 | if (!hso_dev) | 2363 | if (!hso_dev) |
2339 | return NULL; | 2364 | return NULL; |
2340 | 2365 | ||
2341 | serial = kzalloc(sizeof(*serial), GFP_KERNEL); | 2366 | serial = kzalloc(sizeof(*serial), GFP_KERNEL); |
2342 | if (!serial) | 2367 | if (!serial) |
2343 | goto exit; | 2368 | goto exit; |
2344 | 2369 | ||
2345 | serial->parent = hso_dev; | 2370 | serial->parent = hso_dev; |
2346 | hso_dev->port_data.dev_serial = serial; | 2371 | hso_dev->port_data.dev_serial = serial; |
2347 | 2372 | ||
2348 | if (port & HSO_PORT_MODEM) | 2373 | if (port & HSO_PORT_MODEM) |
2349 | num_urbs = 2; | 2374 | num_urbs = 2; |
2350 | else | 2375 | else |
2351 | num_urbs = 1; | 2376 | num_urbs = 1; |
2352 | 2377 | ||
2353 | if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE, | 2378 | if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE, |
2354 | BULK_URB_TX_SIZE)) | 2379 | BULK_URB_TX_SIZE)) |
2355 | goto exit; | 2380 | goto exit; |
2356 | 2381 | ||
2357 | serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, | 2382 | serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, |
2358 | USB_DIR_IN); | 2383 | USB_DIR_IN); |
2359 | if (!serial->in_endp) { | 2384 | if (!serial->in_endp) { |
2360 | dev_err(&interface->dev, "Failed to find BULK IN ep\n"); | 2385 | dev_err(&interface->dev, "Failed to find BULK IN ep\n"); |
2361 | goto exit2; | 2386 | goto exit2; |
2362 | } | 2387 | } |
2363 | 2388 | ||
2364 | if (! | 2389 | if (! |
2365 | (serial->out_endp = | 2390 | (serial->out_endp = |
2366 | hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) { | 2391 | hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT))) { |
2367 | dev_err(&interface->dev, "Failed to find BULK IN ep\n"); | 2392 | dev_err(&interface->dev, "Failed to find BULK IN ep\n"); |
2368 | goto exit2; | 2393 | goto exit2; |
2369 | } | 2394 | } |
2370 | 2395 | ||
2371 | serial->write_data = hso_std_serial_write_data; | 2396 | serial->write_data = hso_std_serial_write_data; |
2372 | 2397 | ||
2373 | /* and record this serial */ | 2398 | /* and record this serial */ |
2374 | set_serial_by_index(serial->minor, serial); | 2399 | set_serial_by_index(serial->minor, serial); |
2375 | 2400 | ||
2376 | /* setup the proc dirs and files if needed */ | 2401 | /* setup the proc dirs and files if needed */ |
2377 | hso_log_port(hso_dev); | 2402 | hso_log_port(hso_dev); |
2378 | 2403 | ||
2379 | /* done, return it */ | 2404 | /* done, return it */ |
2380 | return hso_dev; | 2405 | return hso_dev; |
2381 | 2406 | ||
2382 | exit2: | 2407 | exit2: |
2383 | hso_serial_common_free(serial); | 2408 | hso_serial_common_free(serial); |
2384 | exit: | 2409 | exit: |
2385 | kfree(serial); | 2410 | kfree(serial); |
2386 | hso_free_device(hso_dev); | 2411 | hso_free_device(hso_dev); |
2387 | return NULL; | 2412 | return NULL; |
2388 | } | 2413 | } |
2389 | 2414 | ||
2390 | /* Creates a multiplexed AT channel */ | 2415 | /* Creates a multiplexed AT channel */ |
2391 | static | 2416 | static |
2392 | struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface, | 2417 | struct hso_device *hso_create_mux_serial_device(struct usb_interface *interface, |
2393 | int port, | 2418 | int port, |
2394 | struct hso_shared_int *mux) | 2419 | struct hso_shared_int *mux) |
2395 | { | 2420 | { |
2396 | struct hso_device *hso_dev; | 2421 | struct hso_device *hso_dev; |
2397 | struct hso_serial *serial; | 2422 | struct hso_serial *serial; |
2398 | int port_spec; | 2423 | int port_spec; |
2399 | 2424 | ||
2400 | port_spec = HSO_INTF_MUX; | 2425 | port_spec = HSO_INTF_MUX; |
2401 | port_spec &= ~HSO_PORT_MASK; | 2426 | port_spec &= ~HSO_PORT_MASK; |
2402 | 2427 | ||
2403 | port_spec |= hso_mux_to_port(port); | 2428 | port_spec |= hso_mux_to_port(port); |
2404 | if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NO_PORT) | 2429 | if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NO_PORT) |
2405 | return NULL; | 2430 | return NULL; |
2406 | 2431 | ||
2407 | hso_dev = hso_create_device(interface, port_spec); | 2432 | hso_dev = hso_create_device(interface, port_spec); |
2408 | if (!hso_dev) | 2433 | if (!hso_dev) |
2409 | return NULL; | 2434 | return NULL; |
2410 | 2435 | ||
2411 | serial = kzalloc(sizeof(*serial), GFP_KERNEL); | 2436 | serial = kzalloc(sizeof(*serial), GFP_KERNEL); |
2412 | if (!serial) | 2437 | if (!serial) |
2413 | goto exit; | 2438 | goto exit; |
2414 | 2439 | ||
2415 | hso_dev->port_data.dev_serial = serial; | 2440 | hso_dev->port_data.dev_serial = serial; |
2416 | serial->parent = hso_dev; | 2441 | serial->parent = hso_dev; |
2417 | 2442 | ||
2418 | if (hso_serial_common_create | 2443 | if (hso_serial_common_create |
2419 | (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) | 2444 | (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) |
2420 | goto exit; | 2445 | goto exit; |
2421 | 2446 | ||
2422 | serial->tx_data_length--; | 2447 | serial->tx_data_length--; |
2423 | serial->write_data = hso_mux_serial_write_data; | 2448 | serial->write_data = hso_mux_serial_write_data; |
2424 | 2449 | ||
2425 | serial->shared_int = mux; | 2450 | serial->shared_int = mux; |
2426 | mutex_lock(&serial->shared_int->shared_int_lock); | 2451 | mutex_lock(&serial->shared_int->shared_int_lock); |
2427 | serial->shared_int->ref_count++; | 2452 | serial->shared_int->ref_count++; |
2428 | mutex_unlock(&serial->shared_int->shared_int_lock); | 2453 | mutex_unlock(&serial->shared_int->shared_int_lock); |
2429 | 2454 | ||
2430 | /* and record this serial */ | 2455 | /* and record this serial */ |
2431 | set_serial_by_index(serial->minor, serial); | 2456 | set_serial_by_index(serial->minor, serial); |
2432 | 2457 | ||
2433 | /* setup the proc dirs and files if needed */ | 2458 | /* setup the proc dirs and files if needed */ |
2434 | hso_log_port(hso_dev); | 2459 | hso_log_port(hso_dev); |
2435 | 2460 | ||
2436 | /* done, return it */ | 2461 | /* done, return it */ |
2437 | return hso_dev; | 2462 | return hso_dev; |
2438 | 2463 | ||
2439 | exit: | 2464 | exit: |
2440 | if (serial) { | 2465 | if (serial) { |
2441 | tty_unregister_device(tty_drv, serial->minor); | 2466 | tty_unregister_device(tty_drv, serial->minor); |
2442 | kfree(serial); | 2467 | kfree(serial); |
2443 | } | 2468 | } |
2444 | if (hso_dev) | 2469 | if (hso_dev) |
2445 | hso_free_device(hso_dev); | 2470 | hso_free_device(hso_dev); |
2446 | return NULL; | 2471 | return NULL; |
2447 | 2472 | ||
2448 | } | 2473 | } |
2449 | 2474 | ||
2450 | static void hso_free_shared_int(struct hso_shared_int *mux) | 2475 | static void hso_free_shared_int(struct hso_shared_int *mux) |
2451 | { | 2476 | { |
2452 | usb_free_urb(mux->shared_intr_urb); | 2477 | usb_free_urb(mux->shared_intr_urb); |
2453 | kfree(mux->shared_intr_buf); | 2478 | kfree(mux->shared_intr_buf); |
2454 | mutex_unlock(&mux->shared_int_lock); | 2479 | mutex_unlock(&mux->shared_int_lock); |
2455 | kfree(mux); | 2480 | kfree(mux); |
2456 | } | 2481 | } |
2457 | 2482 | ||
2458 | static | 2483 | static |
2459 | struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface) | 2484 | struct hso_shared_int *hso_create_shared_int(struct usb_interface *interface) |
2460 | { | 2485 | { |
2461 | struct hso_shared_int *mux = kzalloc(sizeof(*mux), GFP_KERNEL); | 2486 | struct hso_shared_int *mux = kzalloc(sizeof(*mux), GFP_KERNEL); |
2462 | 2487 | ||
2463 | if (!mux) | 2488 | if (!mux) |
2464 | return NULL; | 2489 | return NULL; |
2465 | 2490 | ||
2466 | mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT, | 2491 | mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT, |
2467 | USB_DIR_IN); | 2492 | USB_DIR_IN); |
2468 | if (!mux->intr_endp) { | 2493 | if (!mux->intr_endp) { |
2469 | dev_err(&interface->dev, "Can't find INT IN endpoint\n"); | 2494 | dev_err(&interface->dev, "Can't find INT IN endpoint\n"); |
2470 | goto exit; | 2495 | goto exit; |
2471 | } | 2496 | } |
2472 | 2497 | ||
2473 | mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL); | 2498 | mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL); |
2474 | if (!mux->shared_intr_urb) { | 2499 | if (!mux->shared_intr_urb) { |
2475 | dev_err(&interface->dev, "Could not allocate intr urb?"); | 2500 | dev_err(&interface->dev, "Could not allocate intr urb?"); |
2476 | goto exit; | 2501 | goto exit; |
2477 | } | 2502 | } |
2478 | mux->shared_intr_buf = kzalloc(mux->intr_endp->wMaxPacketSize, | 2503 | mux->shared_intr_buf = kzalloc(mux->intr_endp->wMaxPacketSize, |
2479 | GFP_KERNEL); | 2504 | GFP_KERNEL); |
2480 | if (!mux->shared_intr_buf) { | 2505 | if (!mux->shared_intr_buf) { |
2481 | dev_err(&interface->dev, "Could not allocate intr buf?"); | 2506 | dev_err(&interface->dev, "Could not allocate intr buf?"); |
2482 | goto exit; | 2507 | goto exit; |
2483 | } | 2508 | } |
2484 | 2509 | ||
2485 | mutex_init(&mux->shared_int_lock); | 2510 | mutex_init(&mux->shared_int_lock); |
2486 | 2511 | ||
2487 | return mux; | 2512 | return mux; |
2488 | 2513 | ||
2489 | exit: | 2514 | exit: |
2490 | kfree(mux->shared_intr_buf); | 2515 | kfree(mux->shared_intr_buf); |
2491 | usb_free_urb(mux->shared_intr_urb); | 2516 | usb_free_urb(mux->shared_intr_urb); |
2492 | kfree(mux); | 2517 | kfree(mux); |
2493 | return NULL; | 2518 | return NULL; |
2494 | } | 2519 | } |
2495 | 2520 | ||
2496 | /* Gets the port spec for a certain interface */ | 2521 | /* Gets the port spec for a certain interface */ |
2497 | static int hso_get_config_data(struct usb_interface *interface) | 2522 | static int hso_get_config_data(struct usb_interface *interface) |
2498 | { | 2523 | { |
2499 | struct usb_device *usbdev = interface_to_usbdev(interface); | 2524 | struct usb_device *usbdev = interface_to_usbdev(interface); |
2500 | u8 config_data[17]; | 2525 | u8 config_data[17]; |
2501 | u32 if_num = interface->altsetting->desc.bInterfaceNumber; | 2526 | u32 if_num = interface->altsetting->desc.bInterfaceNumber; |
2502 | s32 result; | 2527 | s32 result; |
2503 | 2528 | ||
2504 | if (usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), | 2529 | if (usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), |
2505 | 0x86, 0xC0, 0, 0, config_data, 17, | 2530 | 0x86, 0xC0, 0, 0, config_data, 17, |
2506 | USB_CTRL_SET_TIMEOUT) != 0x11) { | 2531 | USB_CTRL_SET_TIMEOUT) != 0x11) { |
2507 | return -EIO; | 2532 | return -EIO; |
2508 | } | 2533 | } |
2509 | 2534 | ||
2510 | switch (config_data[if_num]) { | 2535 | switch (config_data[if_num]) { |
2511 | case 0x0: | 2536 | case 0x0: |
2512 | result = 0; | 2537 | result = 0; |
2513 | break; | 2538 | break; |
2514 | case 0x1: | 2539 | case 0x1: |
2515 | result = HSO_PORT_DIAG; | 2540 | result = HSO_PORT_DIAG; |
2516 | break; | 2541 | break; |
2517 | case 0x2: | 2542 | case 0x2: |
2518 | result = HSO_PORT_GPS; | 2543 | result = HSO_PORT_GPS; |
2519 | break; | 2544 | break; |
2520 | case 0x3: | 2545 | case 0x3: |
2521 | result = HSO_PORT_GPS_CONTROL; | 2546 | result = HSO_PORT_GPS_CONTROL; |
2522 | break; | 2547 | break; |
2523 | case 0x4: | 2548 | case 0x4: |
2524 | result = HSO_PORT_APP; | 2549 | result = HSO_PORT_APP; |
2525 | break; | 2550 | break; |
2526 | case 0x5: | 2551 | case 0x5: |
2527 | result = HSO_PORT_APP2; | 2552 | result = HSO_PORT_APP2; |
2528 | break; | 2553 | break; |
2529 | case 0x6: | 2554 | case 0x6: |
2530 | result = HSO_PORT_CONTROL; | 2555 | result = HSO_PORT_CONTROL; |
2531 | break; | 2556 | break; |
2532 | case 0x7: | 2557 | case 0x7: |
2533 | result = HSO_PORT_NETWORK; | 2558 | result = HSO_PORT_NETWORK; |
2534 | break; | 2559 | break; |
2535 | case 0x8: | 2560 | case 0x8: |
2536 | result = HSO_PORT_MODEM; | 2561 | result = HSO_PORT_MODEM; |
2537 | break; | 2562 | break; |
2538 | case 0x9: | 2563 | case 0x9: |
2539 | result = HSO_PORT_MSD; | 2564 | result = HSO_PORT_MSD; |
2540 | break; | 2565 | break; |
2541 | case 0xa: | 2566 | case 0xa: |
2542 | result = HSO_PORT_PCSC; | 2567 | result = HSO_PORT_PCSC; |
2543 | break; | 2568 | break; |
2544 | case 0xb: | 2569 | case 0xb: |
2545 | result = HSO_PORT_VOICE; | 2570 | result = HSO_PORT_VOICE; |
2546 | break; | 2571 | break; |
2547 | default: | 2572 | default: |
2548 | result = 0; | 2573 | result = 0; |
2549 | } | 2574 | } |
2550 | 2575 | ||
2551 | if (result) | 2576 | if (result) |
2552 | result |= HSO_INTF_BULK; | 2577 | result |= HSO_INTF_BULK; |
2553 | 2578 | ||
2554 | if (config_data[16] & 0x1) | 2579 | if (config_data[16] & 0x1) |
2555 | result |= HSO_INFO_CRC_BUG; | 2580 | result |= HSO_INFO_CRC_BUG; |
2556 | 2581 | ||
2557 | return result; | 2582 | return result; |
2558 | } | 2583 | } |
2559 | 2584 | ||
2560 | /* called once for each interface upon device insertion */ | 2585 | /* called once for each interface upon device insertion */ |
2561 | static int hso_probe(struct usb_interface *interface, | 2586 | static int hso_probe(struct usb_interface *interface, |
2562 | const struct usb_device_id *id) | 2587 | const struct usb_device_id *id) |
2563 | { | 2588 | { |
2564 | int mux, i, if_num, port_spec; | 2589 | int mux, i, if_num, port_spec; |
2565 | unsigned char port_mask; | 2590 | unsigned char port_mask; |
2566 | struct hso_device *hso_dev = NULL; | 2591 | struct hso_device *hso_dev = NULL; |
2567 | struct hso_shared_int *shared_int; | 2592 | struct hso_shared_int *shared_int; |
2568 | struct hso_device *tmp_dev = NULL; | 2593 | struct hso_device *tmp_dev = NULL; |
2569 | 2594 | ||
2570 | if_num = interface->altsetting->desc.bInterfaceNumber; | 2595 | if_num = interface->altsetting->desc.bInterfaceNumber; |
2571 | 2596 | ||
2572 | /* Get the interface/port specification from either driver_info or from | 2597 | /* Get the interface/port specification from either driver_info or from |
2573 | * the device itself */ | 2598 | * the device itself */ |
2574 | if (id->driver_info) | 2599 | if (id->driver_info) |
2575 | port_spec = ((u32 *)(id->driver_info))[if_num]; | 2600 | port_spec = ((u32 *)(id->driver_info))[if_num]; |
2576 | else | 2601 | else |
2577 | port_spec = hso_get_config_data(interface); | 2602 | port_spec = hso_get_config_data(interface); |
2578 | 2603 | ||
2579 | if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) { | 2604 | if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) { |
2580 | dev_err(&interface->dev, "Not our interface\n"); | 2605 | dev_err(&interface->dev, "Not our interface\n"); |
2581 | return -ENODEV; | 2606 | return -ENODEV; |
2582 | } | 2607 | } |
2583 | /* Check if we need to switch to alt interfaces prior to port | 2608 | /* Check if we need to switch to alt interfaces prior to port |
2584 | * configuration */ | 2609 | * configuration */ |
2585 | if (interface->num_altsetting > 1) | 2610 | if (interface->num_altsetting > 1) |
2586 | usb_set_interface(interface_to_usbdev(interface), if_num, 1); | 2611 | usb_set_interface(interface_to_usbdev(interface), if_num, 1); |
2587 | interface->needs_remote_wakeup = 1; | 2612 | interface->needs_remote_wakeup = 1; |
2588 | 2613 | ||
2589 | /* Allocate new hso device(s) */ | 2614 | /* Allocate new hso device(s) */ |
2590 | switch (port_spec & HSO_INTF_MASK) { | 2615 | switch (port_spec & HSO_INTF_MASK) { |
2591 | case HSO_INTF_MUX: | 2616 | case HSO_INTF_MUX: |
2592 | if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) { | 2617 | if ((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) { |
2593 | /* Create the network device */ | 2618 | /* Create the network device */ |
2594 | if (!disable_net) { | 2619 | if (!disable_net) { |
2595 | hso_dev = hso_create_net_device(interface); | 2620 | hso_dev = hso_create_net_device(interface); |
2596 | if (!hso_dev) | 2621 | if (!hso_dev) |
2597 | goto exit; | 2622 | goto exit; |
2598 | tmp_dev = hso_dev; | 2623 | tmp_dev = hso_dev; |
2599 | } | 2624 | } |
2600 | } | 2625 | } |
2601 | 2626 | ||
2602 | if (hso_get_mux_ports(interface, &port_mask)) | 2627 | if (hso_get_mux_ports(interface, &port_mask)) |
2603 | /* TODO: de-allocate everything */ | 2628 | /* TODO: de-allocate everything */ |
2604 | goto exit; | 2629 | goto exit; |
2605 | 2630 | ||
2606 | shared_int = hso_create_shared_int(interface); | 2631 | shared_int = hso_create_shared_int(interface); |
2607 | if (!shared_int) | 2632 | if (!shared_int) |
2608 | goto exit; | 2633 | goto exit; |
2609 | 2634 | ||
2610 | for (i = 1, mux = 0; i < 0x100; i = i << 1, mux++) { | 2635 | for (i = 1, mux = 0; i < 0x100; i = i << 1, mux++) { |
2611 | if (port_mask & i) { | 2636 | if (port_mask & i) { |
2612 | hso_dev = hso_create_mux_serial_device( | 2637 | hso_dev = hso_create_mux_serial_device( |
2613 | interface, i, shared_int); | 2638 | interface, i, shared_int); |
2614 | if (!hso_dev) | 2639 | if (!hso_dev) |
2615 | goto exit; | 2640 | goto exit; |
2616 | } | 2641 | } |
2617 | } | 2642 | } |
2618 | 2643 | ||
2619 | if (tmp_dev) | 2644 | if (tmp_dev) |
2620 | hso_dev = tmp_dev; | 2645 | hso_dev = tmp_dev; |
2621 | break; | 2646 | break; |
2622 | 2647 | ||
2623 | case HSO_INTF_BULK: | 2648 | case HSO_INTF_BULK: |
2624 | /* It's a regular bulk interface */ | 2649 | /* It's a regular bulk interface */ |
2625 | if (((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) | 2650 | if (((port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) |
2626 | && !disable_net) | 2651 | && !disable_net) |
2627 | hso_dev = hso_create_net_device(interface); | 2652 | hso_dev = hso_create_net_device(interface); |
2628 | else | 2653 | else |
2629 | hso_dev = | 2654 | hso_dev = |
2630 | hso_create_bulk_serial_device(interface, port_spec); | 2655 | hso_create_bulk_serial_device(interface, port_spec); |
2631 | if (!hso_dev) | 2656 | if (!hso_dev) |
2632 | goto exit; | 2657 | goto exit; |
2633 | break; | 2658 | break; |
2634 | default: | 2659 | default: |
2635 | goto exit; | 2660 | goto exit; |
2636 | } | 2661 | } |
2637 | 2662 | ||
2638 | usb_driver_claim_interface(&hso_driver, interface, hso_dev); | 2663 | usb_driver_claim_interface(&hso_driver, interface, hso_dev); |
2639 | 2664 | ||
2640 | /* save our data pointer in this device */ | 2665 | /* save our data pointer in this device */ |
2641 | usb_set_intfdata(interface, hso_dev); | 2666 | usb_set_intfdata(interface, hso_dev); |
2642 | 2667 | ||
2643 | /* done */ | 2668 | /* done */ |
2644 | return 0; | 2669 | return 0; |
2645 | exit: | 2670 | exit: |
2646 | hso_free_interface(interface); | 2671 | hso_free_interface(interface); |
2647 | return -ENODEV; | 2672 | return -ENODEV; |
2648 | } | 2673 | } |
2649 | 2674 | ||
2650 | /* device removed, cleaning up */ | 2675 | /* device removed, cleaning up */ |
2651 | static void hso_disconnect(struct usb_interface *interface) | 2676 | static void hso_disconnect(struct usb_interface *interface) |
2652 | { | 2677 | { |
2653 | hso_free_interface(interface); | 2678 | hso_free_interface(interface); |
2654 | 2679 | ||
2655 | /* remove reference of our private data */ | 2680 | /* remove reference of our private data */ |
2656 | usb_set_intfdata(interface, NULL); | 2681 | usb_set_intfdata(interface, NULL); |
2657 | 2682 | ||
2658 | usb_driver_release_interface(&hso_driver, interface); | 2683 | usb_driver_release_interface(&hso_driver, interface); |
2659 | } | 2684 | } |
2660 | 2685 | ||
2661 | static void async_get_intf(struct work_struct *data) | 2686 | static void async_get_intf(struct work_struct *data) |
2662 | { | 2687 | { |
2663 | struct hso_device *hso_dev = | 2688 | struct hso_device *hso_dev = |
2664 | container_of(data, struct hso_device, async_get_intf); | 2689 | container_of(data, struct hso_device, async_get_intf); |
2665 | usb_autopm_get_interface(hso_dev->interface); | 2690 | usb_autopm_get_interface(hso_dev->interface); |
2666 | } | 2691 | } |
2667 | 2692 | ||
2668 | static void async_put_intf(struct work_struct *data) | 2693 | static void async_put_intf(struct work_struct *data) |
2669 | { | 2694 | { |
2670 | struct hso_device *hso_dev = | 2695 | struct hso_device *hso_dev = |
2671 | container_of(data, struct hso_device, async_put_intf); | 2696 | container_of(data, struct hso_device, async_put_intf); |
2672 | usb_autopm_put_interface(hso_dev->interface); | 2697 | usb_autopm_put_interface(hso_dev->interface); |
2673 | } | 2698 | } |
2674 | 2699 | ||
2675 | static int hso_get_activity(struct hso_device *hso_dev) | 2700 | static int hso_get_activity(struct hso_device *hso_dev) |
2676 | { | 2701 | { |
2677 | if (hso_dev->usb->state == USB_STATE_SUSPENDED) { | 2702 | if (hso_dev->usb->state == USB_STATE_SUSPENDED) { |
2678 | if (!hso_dev->is_active) { | 2703 | if (!hso_dev->is_active) { |
2679 | hso_dev->is_active = 1; | 2704 | hso_dev->is_active = 1; |
2680 | schedule_work(&hso_dev->async_get_intf); | 2705 | schedule_work(&hso_dev->async_get_intf); |
2681 | } | 2706 | } |
2682 | } | 2707 | } |
2683 | 2708 | ||
2684 | if (hso_dev->usb->state != USB_STATE_CONFIGURED) | 2709 | if (hso_dev->usb->state != USB_STATE_CONFIGURED) |
2685 | return -EAGAIN; | 2710 | return -EAGAIN; |
2686 | 2711 | ||
2687 | usb_mark_last_busy(hso_dev->usb); | 2712 | usb_mark_last_busy(hso_dev->usb); |
2688 | 2713 | ||
2689 | return 0; | 2714 | return 0; |
2690 | } | 2715 | } |
2691 | 2716 | ||
2692 | static int hso_put_activity(struct hso_device *hso_dev) | 2717 | static int hso_put_activity(struct hso_device *hso_dev) |
2693 | { | 2718 | { |
2694 | if (hso_dev->usb->state != USB_STATE_SUSPENDED) { | 2719 | if (hso_dev->usb->state != USB_STATE_SUSPENDED) { |
2695 | if (hso_dev->is_active) { | 2720 | if (hso_dev->is_active) { |
2696 | hso_dev->is_active = 0; | 2721 | hso_dev->is_active = 0; |
2697 | schedule_work(&hso_dev->async_put_intf); | 2722 | schedule_work(&hso_dev->async_put_intf); |
2698 | return -EAGAIN; | 2723 | return -EAGAIN; |
2699 | } | 2724 | } |
2700 | } | 2725 | } |
2701 | hso_dev->is_active = 0; | 2726 | hso_dev->is_active = 0; |
2702 | return 0; | 2727 | return 0; |
2703 | } | 2728 | } |
2704 | 2729 | ||
2705 | /* called by kernel when we need to suspend device */ | 2730 | /* called by kernel when we need to suspend device */ |
2706 | static int hso_suspend(struct usb_interface *iface, pm_message_t message) | 2731 | static int hso_suspend(struct usb_interface *iface, pm_message_t message) |
2707 | { | 2732 | { |
2708 | int i, result; | 2733 | int i, result; |
2709 | 2734 | ||
2710 | /* Stop all serial ports */ | 2735 | /* Stop all serial ports */ |
2711 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { | 2736 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { |
2712 | if (serial_table[i] && (serial_table[i]->interface == iface)) { | 2737 | if (serial_table[i] && (serial_table[i]->interface == iface)) { |
2713 | result = hso_stop_serial_device(serial_table[i]); | 2738 | result = hso_stop_serial_device(serial_table[i]); |
2714 | if (result) | 2739 | if (result) |
2715 | goto out; | 2740 | goto out; |
2716 | } | 2741 | } |
2717 | } | 2742 | } |
2718 | 2743 | ||
2719 | /* Stop all network ports */ | 2744 | /* Stop all network ports */ |
2720 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { | 2745 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { |
2721 | if (network_table[i] && | 2746 | if (network_table[i] && |
2722 | (network_table[i]->interface == iface)) { | 2747 | (network_table[i]->interface == iface)) { |
2723 | result = hso_stop_net_device(network_table[i]); | 2748 | result = hso_stop_net_device(network_table[i]); |
2724 | if (result) | 2749 | if (result) |
2725 | goto out; | 2750 | goto out; |
2726 | } | 2751 | } |
2727 | } | 2752 | } |
2728 | 2753 | ||
2729 | out: | 2754 | out: |
2730 | return 0; | 2755 | return 0; |
2731 | } | 2756 | } |
2732 | 2757 | ||
2733 | /* called by kernel when we need to resume device */ | 2758 | /* called by kernel when we need to resume device */ |
2734 | static int hso_resume(struct usb_interface *iface) | 2759 | static int hso_resume(struct usb_interface *iface) |
2735 | { | 2760 | { |
2736 | int i, result = 0; | 2761 | int i, result = 0; |
2737 | struct hso_net *hso_net; | 2762 | struct hso_net *hso_net; |
2738 | 2763 | ||
2739 | /* Start all serial ports */ | 2764 | /* Start all serial ports */ |
2740 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { | 2765 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { |
2741 | if (serial_table[i] && (serial_table[i]->interface == iface)) { | 2766 | if (serial_table[i] && (serial_table[i]->interface == iface)) { |
2742 | if (dev2ser(serial_table[i])->open_count) { | 2767 | if (dev2ser(serial_table[i])->open_count) { |
2743 | result = | 2768 | result = |
2744 | hso_start_serial_device(serial_table[i], GFP_NOIO); | 2769 | hso_start_serial_device(serial_table[i], GFP_NOIO); |
2745 | hso_kick_transmit(dev2ser(serial_table[i])); | 2770 | hso_kick_transmit(dev2ser(serial_table[i])); |
2746 | if (result) | 2771 | if (result) |
2747 | goto out; | 2772 | goto out; |
2748 | } | 2773 | } |
2749 | } | 2774 | } |
2750 | } | 2775 | } |
2751 | 2776 | ||
2752 | /* Start all network ports */ | 2777 | /* Start all network ports */ |
2753 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { | 2778 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { |
2754 | if (network_table[i] && | 2779 | if (network_table[i] && |
2755 | (network_table[i]->interface == iface)) { | 2780 | (network_table[i]->interface == iface)) { |
2756 | hso_net = dev2net(network_table[i]); | 2781 | hso_net = dev2net(network_table[i]); |
2757 | if (hso_net->flags & IFF_UP) { | 2782 | if (hso_net->flags & IFF_UP) { |
2758 | /* First transmit any lingering data, | 2783 | /* First transmit any lingering data, |
2759 | then restart the device. */ | 2784 | then restart the device. */ |
2760 | if (hso_net->skb_tx_buf) { | 2785 | if (hso_net->skb_tx_buf) { |
2761 | dev_dbg(&iface->dev, | 2786 | dev_dbg(&iface->dev, |
2762 | "Transmitting" | 2787 | "Transmitting" |
2763 | " lingering data\n"); | 2788 | " lingering data\n"); |
2764 | hso_net_start_xmit(hso_net->skb_tx_buf, | 2789 | hso_net_start_xmit(hso_net->skb_tx_buf, |
2765 | hso_net->net); | 2790 | hso_net->net); |
2766 | hso_net->skb_tx_buf = NULL; | 2791 | hso_net->skb_tx_buf = NULL; |
2767 | } | 2792 | } |
2768 | result = hso_start_net_device(network_table[i]); | 2793 | result = hso_start_net_device(network_table[i]); |
2769 | if (result) | 2794 | if (result) |
2770 | goto out; | 2795 | goto out; |
2771 | } | 2796 | } |
2772 | } | 2797 | } |
2773 | } | 2798 | } |
2774 | 2799 | ||
2775 | out: | 2800 | out: |
2776 | return result; | 2801 | return result; |
2777 | } | 2802 | } |
2778 | 2803 | ||
2779 | static void hso_serial_ref_free(struct kref *ref) | 2804 | static void hso_serial_ref_free(struct kref *ref) |
2780 | { | 2805 | { |
2781 | struct hso_device *hso_dev = container_of(ref, struct hso_device, ref); | 2806 | struct hso_device *hso_dev = container_of(ref, struct hso_device, ref); |
2782 | 2807 | ||
2783 | hso_free_serial_device(hso_dev); | 2808 | hso_free_serial_device(hso_dev); |
2784 | } | 2809 | } |
2785 | 2810 | ||
2786 | static void hso_free_interface(struct usb_interface *interface) | 2811 | static void hso_free_interface(struct usb_interface *interface) |
2787 | { | 2812 | { |
2788 | struct hso_serial *hso_dev; | 2813 | struct hso_serial *hso_dev; |
2814 | struct tty_struct *tty; | ||
2789 | int i; | 2815 | int i; |
2790 | 2816 | ||
2791 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { | 2817 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { |
2792 | if (serial_table[i] | 2818 | if (serial_table[i] |
2793 | && (serial_table[i]->interface == interface)) { | 2819 | && (serial_table[i]->interface == interface)) { |
2794 | hso_dev = dev2ser(serial_table[i]); | 2820 | hso_dev = dev2ser(serial_table[i]); |
2795 | if (hso_dev->tty) | 2821 | spin_lock_irq(&hso_dev->serial_lock); |
2796 | tty_hangup(hso_dev->tty); | 2822 | tty = tty_kref_get(hso_dev->tty); |
2823 | spin_unlock_irq(&hso_dev->serial_lock); | ||
2824 | if (tty) | ||
2825 | tty_hangup(tty); | ||
2797 | mutex_lock(&hso_dev->parent->mutex); | 2826 | mutex_lock(&hso_dev->parent->mutex); |
2827 | tty_kref_put(tty); | ||
2798 | hso_dev->parent->usb_gone = 1; | 2828 | hso_dev->parent->usb_gone = 1; |
2799 | mutex_unlock(&hso_dev->parent->mutex); | 2829 | mutex_unlock(&hso_dev->parent->mutex); |
2800 | kref_put(&serial_table[i]->ref, hso_serial_ref_free); | 2830 | kref_put(&serial_table[i]->ref, hso_serial_ref_free); |
2801 | } | 2831 | } |
2802 | } | 2832 | } |
2803 | 2833 | ||
2804 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { | 2834 | for (i = 0; i < HSO_MAX_NET_DEVICES; i++) { |
2805 | if (network_table[i] | 2835 | if (network_table[i] |
2806 | && (network_table[i]->interface == interface)) { | 2836 | && (network_table[i]->interface == interface)) { |
2807 | struct rfkill *rfk = dev2net(network_table[i])->rfkill; | 2837 | struct rfkill *rfk = dev2net(network_table[i])->rfkill; |
2808 | /* hso_stop_net_device doesn't stop the net queue since | 2838 | /* hso_stop_net_device doesn't stop the net queue since |
2809 | * traffic needs to start it again when suspended */ | 2839 | * traffic needs to start it again when suspended */ |
2810 | netif_stop_queue(dev2net(network_table[i])->net); | 2840 | netif_stop_queue(dev2net(network_table[i])->net); |
2811 | hso_stop_net_device(network_table[i]); | 2841 | hso_stop_net_device(network_table[i]); |
2812 | cancel_work_sync(&network_table[i]->async_put_intf); | 2842 | cancel_work_sync(&network_table[i]->async_put_intf); |
2813 | cancel_work_sync(&network_table[i]->async_get_intf); | 2843 | cancel_work_sync(&network_table[i]->async_get_intf); |
2814 | if (rfk) | 2844 | if (rfk) |
2815 | rfkill_unregister(rfk); | 2845 | rfkill_unregister(rfk); |
2816 | hso_free_net_device(network_table[i]); | 2846 | hso_free_net_device(network_table[i]); |
2817 | } | 2847 | } |
2818 | } | 2848 | } |
2819 | } | 2849 | } |
2820 | 2850 | ||
2821 | /* Helper functions */ | 2851 | /* Helper functions */ |
2822 | 2852 | ||
2823 | /* Get the endpoint ! */ | 2853 | /* Get the endpoint ! */ |
2824 | static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, | 2854 | static struct usb_endpoint_descriptor *hso_get_ep(struct usb_interface *intf, |
2825 | int type, int dir) | 2855 | int type, int dir) |
2826 | { | 2856 | { |
2827 | int i; | 2857 | int i; |
2828 | struct usb_host_interface *iface = intf->cur_altsetting; | 2858 | struct usb_host_interface *iface = intf->cur_altsetting; |
2829 | struct usb_endpoint_descriptor *endp; | 2859 | struct usb_endpoint_descriptor *endp; |
2830 | 2860 | ||
2831 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { | 2861 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { |
2832 | endp = &iface->endpoint[i].desc; | 2862 | endp = &iface->endpoint[i].desc; |
2833 | if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) && | 2863 | if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) && |
2834 | (usb_endpoint_type(endp) == type)) | 2864 | (usb_endpoint_type(endp) == type)) |
2835 | return endp; | 2865 | return endp; |
2836 | } | 2866 | } |
2837 | 2867 | ||
2838 | return NULL; | 2868 | return NULL; |
2839 | } | 2869 | } |
2840 | 2870 | ||
2841 | /* Get the byte that describes which ports are enabled */ | 2871 | /* Get the byte that describes which ports are enabled */ |
2842 | static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports) | 2872 | static int hso_get_mux_ports(struct usb_interface *intf, unsigned char *ports) |
2843 | { | 2873 | { |
2844 | int i; | 2874 | int i; |
2845 | struct usb_host_interface *iface = intf->cur_altsetting; | 2875 | struct usb_host_interface *iface = intf->cur_altsetting; |
2846 | 2876 | ||
2847 | if (iface->extralen == 3) { | 2877 | if (iface->extralen == 3) { |
2848 | *ports = iface->extra[2]; | 2878 | *ports = iface->extra[2]; |
2849 | return 0; | 2879 | return 0; |
2850 | } | 2880 | } |
2851 | 2881 | ||
2852 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { | 2882 | for (i = 0; i < iface->desc.bNumEndpoints; i++) { |
2853 | if (iface->endpoint[i].extralen == 3) { | 2883 | if (iface->endpoint[i].extralen == 3) { |
2854 | *ports = iface->endpoint[i].extra[2]; | 2884 | *ports = iface->endpoint[i].extra[2]; |
2855 | return 0; | 2885 | return 0; |
2856 | } | 2886 | } |
2857 | } | 2887 | } |
2858 | 2888 | ||
2859 | return -1; | 2889 | return -1; |
2860 | } | 2890 | } |
2861 | 2891 | ||
2862 | /* interrupt urb needs to be submitted, used for serial read of muxed port */ | 2892 | /* interrupt urb needs to be submitted, used for serial read of muxed port */ |
2863 | static int hso_mux_submit_intr_urb(struct hso_shared_int *shared_int, | 2893 | static int hso_mux_submit_intr_urb(struct hso_shared_int *shared_int, |
2864 | struct usb_device *usb, gfp_t gfp) | 2894 | struct usb_device *usb, gfp_t gfp) |
2865 | { | 2895 | { |
2866 | int result; | 2896 | int result; |
2867 | 2897 | ||
2868 | usb_fill_int_urb(shared_int->shared_intr_urb, usb, | 2898 | usb_fill_int_urb(shared_int->shared_intr_urb, usb, |
2869 | usb_rcvintpipe(usb, | 2899 | usb_rcvintpipe(usb, |
2870 | shared_int->intr_endp->bEndpointAddress & 0x7F), | 2900 | shared_int->intr_endp->bEndpointAddress & 0x7F), |
2871 | shared_int->shared_intr_buf, | 2901 | shared_int->shared_intr_buf, |
2872 | shared_int->intr_endp->wMaxPacketSize, | 2902 | shared_int->intr_endp->wMaxPacketSize, |
2873 | intr_callback, shared_int, | 2903 | intr_callback, shared_int, |
2874 | shared_int->intr_endp->bInterval); | 2904 | shared_int->intr_endp->bInterval); |
2875 | 2905 | ||
2876 | result = usb_submit_urb(shared_int->shared_intr_urb, gfp); | 2906 | result = usb_submit_urb(shared_int->shared_intr_urb, gfp); |
2877 | if (result) | 2907 | if (result) |
2878 | dev_warn(&usb->dev, "%s failed mux_intr_urb %d", __func__, | 2908 | dev_warn(&usb->dev, "%s failed mux_intr_urb %d", __func__, |
2879 | result); | 2909 | result); |
2880 | 2910 | ||
2881 | return result; | 2911 | return result; |
2882 | } | 2912 | } |
2883 | 2913 | ||
2884 | /* operations setup of the serial interface */ | 2914 | /* operations setup of the serial interface */ |
2885 | static const struct tty_operations hso_serial_ops = { | 2915 | static const struct tty_operations hso_serial_ops = { |
2886 | .open = hso_serial_open, | 2916 | .open = hso_serial_open, |
2887 | .close = hso_serial_close, | 2917 | .close = hso_serial_close, |
2888 | .write = hso_serial_write, | 2918 | .write = hso_serial_write, |
2889 | .write_room = hso_serial_write_room, | 2919 | .write_room = hso_serial_write_room, |
2890 | .set_termios = hso_serial_set_termios, | 2920 | .set_termios = hso_serial_set_termios, |
2891 | .chars_in_buffer = hso_serial_chars_in_buffer, | 2921 | .chars_in_buffer = hso_serial_chars_in_buffer, |
2892 | .tiocmget = hso_serial_tiocmget, | 2922 | .tiocmget = hso_serial_tiocmget, |
2893 | .tiocmset = hso_serial_tiocmset, | 2923 | .tiocmset = hso_serial_tiocmset, |
2894 | .unthrottle = hso_unthrottle | 2924 | .unthrottle = hso_unthrottle |
2895 | }; | 2925 | }; |
2896 | 2926 | ||
2897 | static struct usb_driver hso_driver = { | 2927 | static struct usb_driver hso_driver = { |
2898 | .name = driver_name, | 2928 | .name = driver_name, |
2899 | .probe = hso_probe, | 2929 | .probe = hso_probe, |
2900 | .disconnect = hso_disconnect, | 2930 | .disconnect = hso_disconnect, |
2901 | .id_table = hso_ids, | 2931 | .id_table = hso_ids, |
2902 | .suspend = hso_suspend, | 2932 | .suspend = hso_suspend, |
2903 | .resume = hso_resume, | 2933 | .resume = hso_resume, |
2904 | .reset_resume = hso_resume, | 2934 | .reset_resume = hso_resume, |
2905 | .supports_autosuspend = 1, | 2935 | .supports_autosuspend = 1, |
2906 | }; | 2936 | }; |
2907 | 2937 | ||
2908 | static int __init hso_init(void) | 2938 | static int __init hso_init(void) |
2909 | { | 2939 | { |
2910 | int i; | 2940 | int i; |
2911 | int result; | 2941 | int result; |
2912 | 2942 | ||
2913 | /* put it in the log */ | 2943 | /* put it in the log */ |
2914 | printk(KERN_INFO "hso: %s\n", version); | 2944 | printk(KERN_INFO "hso: %s\n", version); |
2915 | 2945 | ||
2916 | /* Initialise the serial table semaphore and table */ | 2946 | /* Initialise the serial table semaphore and table */ |
2917 | spin_lock_init(&serial_table_lock); | 2947 | spin_lock_init(&serial_table_lock); |
2918 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) | 2948 | for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) |
2919 | serial_table[i] = NULL; | 2949 | serial_table[i] = NULL; |
2920 | 2950 | ||
2921 | /* allocate our driver using the proper amount of supported minors */ | 2951 | /* allocate our driver using the proper amount of supported minors */ |
2922 | tty_drv = alloc_tty_driver(HSO_SERIAL_TTY_MINORS); | 2952 | tty_drv = alloc_tty_driver(HSO_SERIAL_TTY_MINORS); |
2923 | if (!tty_drv) | 2953 | if (!tty_drv) |
2924 | return -ENOMEM; | 2954 | return -ENOMEM; |
2925 | 2955 | ||
2926 | /* fill in all needed values */ | 2956 | /* fill in all needed values */ |
2927 | tty_drv->magic = TTY_DRIVER_MAGIC; | 2957 | tty_drv->magic = TTY_DRIVER_MAGIC; |
2928 | tty_drv->owner = THIS_MODULE; | 2958 | tty_drv->owner = THIS_MODULE; |
2929 | tty_drv->driver_name = driver_name; | 2959 | tty_drv->driver_name = driver_name; |
2930 | tty_drv->name = tty_filename; | 2960 | tty_drv->name = tty_filename; |
2931 | 2961 | ||
2932 | /* if major number is provided as parameter, use that one */ | 2962 | /* if major number is provided as parameter, use that one */ |
2933 | if (tty_major) | 2963 | if (tty_major) |
2934 | tty_drv->major = tty_major; | 2964 | tty_drv->major = tty_major; |
2935 | 2965 | ||
2936 | tty_drv->minor_start = 0; | 2966 | tty_drv->minor_start = 0; |
2937 | tty_drv->num = HSO_SERIAL_TTY_MINORS; | 2967 | tty_drv->num = HSO_SERIAL_TTY_MINORS; |
2938 | tty_drv->type = TTY_DRIVER_TYPE_SERIAL; | 2968 | tty_drv->type = TTY_DRIVER_TYPE_SERIAL; |
2939 | tty_drv->subtype = SERIAL_TYPE_NORMAL; | 2969 | tty_drv->subtype = SERIAL_TYPE_NORMAL; |
2940 | tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 2970 | tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
2941 | tty_drv->init_termios = tty_std_termios; | 2971 | tty_drv->init_termios = tty_std_termios; |
2942 | tty_drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 2972 | tty_drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
2943 | tty_drv->termios = hso_serial_termios; | 2973 | tty_drv->termios = hso_serial_termios; |
2944 | tty_drv->termios_locked = hso_serial_termios_locked; | 2974 | tty_drv->termios_locked = hso_serial_termios_locked; |
2945 | tty_set_operations(tty_drv, &hso_serial_ops); | 2975 | tty_set_operations(tty_drv, &hso_serial_ops); |
2946 | 2976 | ||
2947 | /* register the tty driver */ | 2977 | /* register the tty driver */ |
2948 | result = tty_register_driver(tty_drv); | 2978 | result = tty_register_driver(tty_drv); |
2949 | if (result) { | 2979 | if (result) { |
2950 | printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", | 2980 | printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", |
2951 | __func__, result); | 2981 | __func__, result); |
2952 | return result; | 2982 | return result; |
2953 | } | 2983 | } |
2954 | 2984 | ||
2955 | /* register this module as an usb driver */ | 2985 | /* register this module as an usb driver */ |
2956 | result = usb_register(&hso_driver); | 2986 | result = usb_register(&hso_driver); |
2957 | if (result) { | 2987 | if (result) { |
2958 | printk(KERN_ERR "Could not register hso driver? error: %d\n", | 2988 | printk(KERN_ERR "Could not register hso driver? error: %d\n", |
2959 | result); | 2989 | result); |
2960 | /* cleanup serial interface */ | 2990 | /* cleanup serial interface */ |
2961 | tty_unregister_driver(tty_drv); | 2991 | tty_unregister_driver(tty_drv); |
2962 | return result; | 2992 | return result; |
2963 | } | 2993 | } |
2964 | 2994 | ||
2965 | /* done */ | 2995 | /* done */ |
2966 | return 0; | 2996 | return 0; |
2967 | } | 2997 | } |
2968 | 2998 | ||
2969 | static void __exit hso_exit(void) | 2999 | static void __exit hso_exit(void) |
2970 | { | 3000 | { |
2971 | printk(KERN_INFO "hso: unloaded\n"); | 3001 | printk(KERN_INFO "hso: unloaded\n"); |
2972 | 3002 | ||
2973 | tty_unregister_driver(tty_drv); | 3003 | tty_unregister_driver(tty_drv); |
2974 | /* deregister the usb driver */ | 3004 | /* deregister the usb driver */ |
2975 | usb_deregister(&hso_driver); | 3005 | usb_deregister(&hso_driver); |
2976 | } | 3006 | } |
2977 | 3007 | ||
2978 | /* Module definitions */ | 3008 | /* Module definitions */ |
2979 | module_init(hso_init); | 3009 | module_init(hso_init); |
2980 | module_exit(hso_exit); | 3010 | module_exit(hso_exit); |
2981 | 3011 | ||
2982 | MODULE_AUTHOR(MOD_AUTHOR); | 3012 | MODULE_AUTHOR(MOD_AUTHOR); |
2983 | MODULE_DESCRIPTION(MOD_DESCRIPTION); | 3013 | MODULE_DESCRIPTION(MOD_DESCRIPTION); |
2984 | MODULE_LICENSE(MOD_LICENSE); | 3014 | MODULE_LICENSE(MOD_LICENSE); |
2985 | MODULE_INFO(Version, DRIVER_VERSION); | 3015 | MODULE_INFO(Version, DRIVER_VERSION); |
2986 | 3016 | ||
2987 | /* change the debug level (eg: insmod hso.ko debug=0x04) */ | 3017 | /* change the debug level (eg: insmod hso.ko debug=0x04) */ |
2988 | MODULE_PARM_DESC(debug, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]"); | 3018 | MODULE_PARM_DESC(debug, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]"); |
2989 | module_param(debug, int, S_IRUGO | S_IWUSR); | 3019 | module_param(debug, int, S_IRUGO | S_IWUSR); |
2990 | 3020 | ||
2991 | /* set the major tty number (eg: insmod hso.ko tty_major=245) */ | 3021 | /* set the major tty number (eg: insmod hso.ko tty_major=245) */ |
2992 | MODULE_PARM_DESC(tty_major, "Set the major tty number"); | 3022 | MODULE_PARM_DESC(tty_major, "Set the major tty number"); |
2993 | module_param(tty_major, int, S_IRUGO | S_IWUSR); | 3023 | module_param(tty_major, int, S_IRUGO | S_IWUSR); |
2994 | 3024 | ||
2995 | /* disable network interface (eg: insmod hso.ko disable_net=1) */ | 3025 | /* disable network interface (eg: insmod hso.ko disable_net=1) */ |
2996 | MODULE_PARM_DESC(disable_net, "Disable the network interface"); | 3026 | MODULE_PARM_DESC(disable_net, "Disable the network interface"); |
2997 | module_param(disable_net, int, S_IRUGO | S_IWUSR); | 3027 | module_param(disable_net, int, S_IRUGO | S_IWUSR); |
2998 | 3028 |