Commit 58eb17f155704062d76729d1fb7e23d3559ca86a

Authored by Denis Joseph Barrow
Committed by Linus Torvalds
1 parent ad36b88e2d

hso modem detect fix patch against Alan Cox'es tty tree

Fixed incorrect check for the modem port, this prevents
crashes caused by issueing a tiocmget_submit_urb
on endpoints which don't exist for non modem devices.

Signed-off-by: Denis Joseph Barrow <D.Barow@option.com>
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

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