1 /******************************************************************************
3 * Driver for Option High Speed Mobile Devices.
5 * Copyright (C) 2008 Option International
6 * Filip Aben <f.aben@option.com>
7 * Denis Joseph Barrow <d.barow@option.com>
8 * Jan Dumon <j.dumon@option.com>
9 * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
10 * <ajb@spheresystems.co.uk>
11 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
12 * Copyright (C) 2008 Novell, Inc.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 *****************************************************************************/
31 /******************************************************************************
33 * Description of the device:
35 * Interface 0: Contains the IP network interface on the bulk end points.
36 * The multiplexed serial ports are using the interrupt and
38 * Interrupt contains a bitmap telling which multiplexed
39 * serialport needs servicing.
41 * Interface 1: Diagnostics port, uses bulk only, do not submit urbs until the
42 * port is opened, as this have a huge impact on the network port
45 * Interface 2: Standard modem interface - circuit switched interface, this
46 * can be used to make a standard ppp connection however it
47 * should not be used in conjunction with the IP network interface
48 * enabled for USB performance reasons i.e. if using this set
49 * ideally disable_net=1.
51 *****************************************************************************/
53 #include <linux/sched.h>
54 #include <linux/slab.h>
55 #include <linux/init.h>
56 #include <linux/delay.h>
57 #include <linux/netdevice.h>
58 #include <linux/module.h>
59 #include <linux/ethtool.h>
60 #include <linux/usb.h>
61 #include <linux/timer.h>
62 #include <linux/tty.h>
63 #include <linux/tty_driver.h>
64 #include <linux/tty_flip.h>
65 #include <linux/kmod.h>
66 #include <linux/rfkill.h>
68 #include <linux/uaccess.h>
69 #include <linux/usb/cdc.h>
71 #include <asm/byteorder.h>
72 #include <linux/serial_core.h>
73 #include <linux/serial.h>
76 #define MOD_AUTHOR "Option Wireless"
77 #define MOD_DESCRIPTION "USB High Speed Option driver"
78 #define MOD_LICENSE "GPL"
80 #define HSO_MAX_NET_DEVICES 10
81 #define HSO__MAX_MTU 2048
82 #define DEFAULT_MTU 1500
83 #define DEFAULT_MRU 1500
85 #define CTRL_URB_RX_SIZE 1024
86 #define CTRL_URB_TX_SIZE 64
88 #define BULK_URB_RX_SIZE 4096
89 #define BULK_URB_TX_SIZE 8192
91 #define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
92 #define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
93 #define MUX_BULK_RX_BUF_COUNT 4
94 #define USB_TYPE_OPTION_VENDOR 0x20
96 /* These definitions are used with the struct hso_net flags element */
97 /* - use *_bit operations on it. (bit indices not values.) */
98 #define HSO_NET_RUNNING 0
100 #define HSO_NET_TX_TIMEOUT (HZ*10)
102 #define HSO_SERIAL_MAGIC 0x48534f31
104 /* Number of ttys to handle */
105 #define HSO_SERIAL_TTY_MINORS 256
107 #define MAX_RX_URBS 2
109 /*****************************************************************************/
110 /* Debugging functions */
111 /*****************************************************************************/
112 #define D__(lvl_, fmt, arg...) \
114 printk(lvl_ "[%d:%s]: " fmt "\n", \
115 __LINE__, __func__, ## arg); \
118 #define D_(lvl, args...) \
121 D__(KERN_INFO, args); \
124 #define D1(args...) D_(0x01, ##args)
125 #define D2(args...) D_(0x02, ##args)
126 #define D3(args...) D_(0x04, ##args)
127 #define D4(args...) D_(0x08, ##args)
128 #define D5(args...) D_(0x10, ##args)
130 /*****************************************************************************/
132 /*****************************************************************************/
133 enum pkt_parse_state
{
139 /*****************************************************************************/
141 /*****************************************************************************/
143 struct hso_shared_int
{
144 struct usb_endpoint_descriptor
*intr_endp
;
145 void *shared_intr_buf
;
146 struct urb
*shared_intr_urb
;
147 struct usb_device
*usb
;
150 struct mutex shared_int_lock
;
154 struct hso_device
*parent
;
155 struct net_device
*net
;
156 struct rfkill
*rfkill
;
158 struct usb_endpoint_descriptor
*in_endp
;
159 struct usb_endpoint_descriptor
*out_endp
;
161 struct urb
*mux_bulk_rx_urb_pool
[MUX_BULK_RX_BUF_COUNT
];
162 struct urb
*mux_bulk_tx_urb
;
163 void *mux_bulk_rx_buf_pool
[MUX_BULK_RX_BUF_COUNT
];
164 void *mux_bulk_tx_buf
;
166 struct sk_buff
*skb_rx_buf
;
167 struct sk_buff
*skb_tx_buf
;
169 enum pkt_parse_state rx_parse_state
;
172 unsigned short rx_buf_size
;
173 unsigned short rx_buf_missing
;
174 struct iphdr rx_ip_hdr
;
185 #define BM_REQUEST_TYPE (0xa1)
186 #define B_NOTIFICATION (0x20)
187 #define W_VALUE (0x0)
188 #define W_LENGTH (0x2)
190 #define B_OVERRUN (0x1<<6)
191 #define B_PARITY (0x1<<5)
192 #define B_FRAMING (0x1<<4)
193 #define B_RING_SIGNAL (0x1<<3)
194 #define B_BREAK (0x1<<2)
195 #define B_TX_CARRIER (0x1<<1)
196 #define B_RX_CARRIER (0x1<<0)
198 struct hso_serial_state_notification
{
204 u16 UART_state_bitmap
;
207 struct hso_tiocmget
{
209 wait_queue_head_t waitq
;
211 struct usb_endpoint_descriptor
*endp
;
213 struct hso_serial_state_notification serial_state_notification
;
214 u16 prev_UART_state_bitmap
;
215 struct uart_icount icount
;
220 struct hso_device
*parent
;
224 struct hso_shared_int
*shared_int
;
226 /* rx/tx urb could be either a bulk urb or a control urb depending
227 on which serial port it is used on. */
228 struct urb
*rx_urb
[MAX_RX_URBS
];
230 u8
*rx_data
[MAX_RX_URBS
];
231 u16 rx_data_length
; /* should contain allocated length */
236 u16 tx_data_length
; /* should contain allocated length */
239 struct usb_ctrlrequest ctrl_req_tx
;
240 struct usb_ctrlrequest ctrl_req_rx
;
242 struct usb_endpoint_descriptor
*in_endp
;
243 struct usb_endpoint_descriptor
*out_endp
;
245 enum rx_ctrl_state rx_state
;
248 unsigned tx_urb_used
:1;
250 struct tty_port port
;
251 /* from usb_serial_port */
252 spinlock_t serial_lock
;
254 int (*write_data
) (struct hso_serial
*serial
);
255 struct hso_tiocmget
*tiocmget
;
256 /* Hacks required to get flow control
257 * working on the serial receive buffers
258 * so as not to drop characters on the floor.
261 u8 rx_urb_filled
[MAX_RX_URBS
];
262 struct tasklet_struct unthrottle_tasklet
;
267 struct hso_serial
*dev_serial
;
268 struct hso_net
*dev_net
;
275 struct work_struct async_get_intf
;
276 struct work_struct async_put_intf
;
277 struct work_struct reset_device
;
279 struct usb_device
*usb
;
280 struct usb_interface
*interface
;
287 /* Type of interface */
288 #define HSO_INTF_MASK 0xFF00
289 #define HSO_INTF_MUX 0x0100
290 #define HSO_INTF_BULK 0x0200
293 #define HSO_PORT_MASK 0xFF
294 #define HSO_PORT_NO_PORT 0x0
295 #define HSO_PORT_CONTROL 0x1
296 #define HSO_PORT_APP 0x2
297 #define HSO_PORT_GPS 0x3
298 #define HSO_PORT_PCSC 0x4
299 #define HSO_PORT_APP2 0x5
300 #define HSO_PORT_GPS_CONTROL 0x6
301 #define HSO_PORT_MSD 0x7
302 #define HSO_PORT_VOICE 0x8
303 #define HSO_PORT_DIAG2 0x9
304 #define HSO_PORT_DIAG 0x10
305 #define HSO_PORT_MODEM 0x11
306 #define HSO_PORT_NETWORK 0x12
308 /* Additional device info */
309 #define HSO_INFO_MASK 0xFF000000
310 #define HSO_INFO_CRC_BUG 0x01000000
312 /*****************************************************************************/
314 /*****************************************************************************/
315 /* Serial driver functions */
316 static int hso_serial_tiocmset(struct tty_struct
*tty
,
317 unsigned int set
, unsigned int clear
);
318 static void ctrl_callback(struct urb
*urb
);
319 static int put_rxbuf_data(struct urb
*urb
, struct hso_serial
*serial
);
320 static void hso_kick_transmit(struct hso_serial
*serial
);
321 /* Helper functions */
322 static int hso_mux_submit_intr_urb(struct hso_shared_int
*mux_int
,
323 struct usb_device
*usb
, gfp_t gfp
);
324 static void handle_usb_error(int status
, const char *function
,
325 struct hso_device
*hso_dev
);
326 static struct usb_endpoint_descriptor
*hso_get_ep(struct usb_interface
*intf
,
328 static int hso_get_mux_ports(struct usb_interface
*intf
, unsigned char *ports
);
329 static void hso_free_interface(struct usb_interface
*intf
);
330 static int hso_start_serial_device(struct hso_device
*hso_dev
, gfp_t flags
);
331 static int hso_stop_serial_device(struct hso_device
*hso_dev
);
332 static int hso_start_net_device(struct hso_device
*hso_dev
);
333 static void hso_free_shared_int(struct hso_shared_int
*shared_int
);
334 static int hso_stop_net_device(struct hso_device
*hso_dev
);
335 static void hso_serial_ref_free(struct kref
*ref
);
336 static void hso_std_serial_read_bulk_callback(struct urb
*urb
);
337 static int hso_mux_serial_read(struct hso_serial
*serial
);
338 static void async_get_intf(struct work_struct
*data
);
339 static void async_put_intf(struct work_struct
*data
);
340 static int hso_put_activity(struct hso_device
*hso_dev
);
341 static int hso_get_activity(struct hso_device
*hso_dev
);
342 static void tiocmget_intr_callback(struct urb
*urb
);
343 static void reset_device(struct work_struct
*data
);
344 /*****************************************************************************/
345 /* Helping functions */
346 /*****************************************************************************/
350 static inline struct hso_net
*dev2net(struct hso_device
*hso_dev
)
352 return hso_dev
->port_data
.dev_net
;
355 static inline struct hso_serial
*dev2ser(struct hso_device
*hso_dev
)
357 return hso_dev
->port_data
.dev_serial
;
360 /* Debugging functions */
362 static void dbg_dump(int line_count
, const char *func_name
, unsigned char *buf
,
365 static char name
[255];
367 sprintf(name
, "hso[%d:%s]", line_count
, func_name
);
368 print_hex_dump_bytes(name
, DUMP_PREFIX_NONE
, buf
, len
);
371 #define DUMP(buf_, len_) \
372 dbg_dump(__LINE__, __func__, (unsigned char *)buf_, len_)
374 #define DUMP1(buf_, len_) \
380 #define DUMP(buf_, len_)
381 #define DUMP1(buf_, len_)
384 /* module parameters */
386 static int tty_major
;
387 static int disable_net
;
390 static const char driver_name
[] = "hso";
391 static const char tty_filename
[] = "ttyHS";
392 static const char *version
= __FILE__
": " MOD_AUTHOR
;
393 /* the usb driver itself (registered in hso_init) */
394 static struct usb_driver hso_driver
;
395 /* serial structures */
396 static struct tty_driver
*tty_drv
;
397 static struct hso_device
*serial_table
[HSO_SERIAL_TTY_MINORS
];
398 static struct hso_device
*network_table
[HSO_MAX_NET_DEVICES
];
399 static spinlock_t serial_table_lock
;
401 static const s32 default_port_spec
[] = {
402 HSO_INTF_MUX
| HSO_PORT_NETWORK
,
403 HSO_INTF_BULK
| HSO_PORT_DIAG
,
404 HSO_INTF_BULK
| HSO_PORT_MODEM
,
408 static const s32 icon321_port_spec
[] = {
409 HSO_INTF_MUX
| HSO_PORT_NETWORK
,
410 HSO_INTF_BULK
| HSO_PORT_DIAG2
,
411 HSO_INTF_BULK
| HSO_PORT_MODEM
,
412 HSO_INTF_BULK
| HSO_PORT_DIAG
,
416 #define default_port_device(vendor, product) \
417 USB_DEVICE(vendor, product), \
418 .driver_info = (kernel_ulong_t)default_port_spec
420 #define icon321_port_device(vendor, product) \
421 USB_DEVICE(vendor, product), \
422 .driver_info = (kernel_ulong_t)icon321_port_spec
424 /* list of devices we support */
425 static const struct usb_device_id hso_ids
[] = {
426 {default_port_device(0x0af0, 0x6711)},
427 {default_port_device(0x0af0, 0x6731)},
428 {default_port_device(0x0af0, 0x6751)},
429 {default_port_device(0x0af0, 0x6771)},
430 {default_port_device(0x0af0, 0x6791)},
431 {default_port_device(0x0af0, 0x6811)},
432 {default_port_device(0x0af0, 0x6911)},
433 {default_port_device(0x0af0, 0x6951)},
434 {default_port_device(0x0af0, 0x6971)},
435 {default_port_device(0x0af0, 0x7011)},
436 {default_port_device(0x0af0, 0x7031)},
437 {default_port_device(0x0af0, 0x7051)},
438 {default_port_device(0x0af0, 0x7071)},
439 {default_port_device(0x0af0, 0x7111)},
440 {default_port_device(0x0af0, 0x7211)},
441 {default_port_device(0x0af0, 0x7251)},
442 {default_port_device(0x0af0, 0x7271)},
443 {default_port_device(0x0af0, 0x7311)},
444 {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
445 {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */
446 {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
447 {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */
448 {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */
449 {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */
450 {USB_DEVICE(0x0af0, 0x7381)}, /* GE40x */
451 {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */
452 {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */
453 {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */
454 {USB_DEVICE(0x0af0, 0x7701)},
455 {USB_DEVICE(0x0af0, 0x7706)},
456 {USB_DEVICE(0x0af0, 0x7801)},
457 {USB_DEVICE(0x0af0, 0x7901)},
458 {USB_DEVICE(0x0af0, 0x7A01)},
459 {USB_DEVICE(0x0af0, 0x7A05)},
460 {USB_DEVICE(0x0af0, 0x8200)},
461 {USB_DEVICE(0x0af0, 0x8201)},
462 {USB_DEVICE(0x0af0, 0x8300)},
463 {USB_DEVICE(0x0af0, 0x8302)},
464 {USB_DEVICE(0x0af0, 0x8304)},
465 {USB_DEVICE(0x0af0, 0x8400)},
466 {USB_DEVICE(0x0af0, 0x8600)},
467 {USB_DEVICE(0x0af0, 0x8800)},
468 {USB_DEVICE(0x0af0, 0x8900)},
469 {USB_DEVICE(0x0af0, 0x9000)},
470 {USB_DEVICE(0x0af0, 0x9200)}, /* Option GTM671WFS */
471 {USB_DEVICE(0x0af0, 0xd035)},
472 {USB_DEVICE(0x0af0, 0xd055)},
473 {USB_DEVICE(0x0af0, 0xd155)},
474 {USB_DEVICE(0x0af0, 0xd255)},
475 {USB_DEVICE(0x0af0, 0xd057)},
476 {USB_DEVICE(0x0af0, 0xd157)},
477 {USB_DEVICE(0x0af0, 0xd257)},
478 {USB_DEVICE(0x0af0, 0xd357)},
479 {USB_DEVICE(0x0af0, 0xd058)},
480 {USB_DEVICE(0x0af0, 0xc100)},
483 MODULE_DEVICE_TABLE(usb
, hso_ids
);
485 /* Sysfs attribute */
486 static ssize_t
hso_sysfs_show_porttype(struct device
*dev
,
487 struct device_attribute
*attr
,
490 struct hso_device
*hso_dev
= dev_get_drvdata(dev
);
496 switch (hso_dev
->port_spec
& HSO_PORT_MASK
) {
497 case HSO_PORT_CONTROL
:
498 port_name
= "Control";
501 port_name
= "Application";
504 port_name
= "Application2";
509 case HSO_PORT_GPS_CONTROL
:
510 port_name
= "GPS Control";
516 port_name
= "Diagnostic";
519 port_name
= "Diagnostic2";
524 case HSO_PORT_NETWORK
:
525 port_name
= "Network";
528 port_name
= "Unknown";
532 return sprintf(buf
, "%s\n", port_name
);
534 static DEVICE_ATTR(hsotype
, S_IRUGO
, hso_sysfs_show_porttype
, NULL
);
536 static int hso_urb_to_index(struct hso_serial
*serial
, struct urb
*urb
)
540 for (idx
= 0; idx
< serial
->num_rx_urbs
; idx
++)
541 if (serial
->rx_urb
[idx
] == urb
)
543 dev_err(serial
->parent
->dev
, "hso_urb_to_index failed\n");
547 /* converts mux value to a port spec value */
548 static u32
hso_mux_to_port(int mux
)
554 result
= HSO_PORT_CONTROL
;
557 result
= HSO_PORT_APP
;
560 result
= HSO_PORT_PCSC
;
563 result
= HSO_PORT_GPS
;
566 result
= HSO_PORT_APP2
;
569 result
= HSO_PORT_NO_PORT
;
574 /* converts port spec value to a mux value */
575 static u32
hso_port_to_mux(int port
)
579 switch (port
& HSO_PORT_MASK
) {
580 case HSO_PORT_CONTROL
:
601 static struct hso_serial
*get_serial_by_shared_int_and_type(
602 struct hso_shared_int
*shared_int
,
607 port
= hso_mux_to_port(mux
);
609 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
610 if (serial_table
[i
] &&
611 (dev2ser(serial_table
[i
])->shared_int
== shared_int
) &&
612 ((serial_table
[i
]->port_spec
& HSO_PORT_MASK
) == port
)) {
613 return dev2ser(serial_table
[i
]);
620 static struct hso_serial
*get_serial_by_index(unsigned index
)
622 struct hso_serial
*serial
= NULL
;
625 spin_lock_irqsave(&serial_table_lock
, flags
);
626 if (serial_table
[index
])
627 serial
= dev2ser(serial_table
[index
]);
628 spin_unlock_irqrestore(&serial_table_lock
, flags
);
633 static int get_free_serial_index(void)
638 spin_lock_irqsave(&serial_table_lock
, flags
);
639 for (index
= 0; index
< HSO_SERIAL_TTY_MINORS
; index
++) {
640 if (serial_table
[index
] == NULL
) {
641 spin_unlock_irqrestore(&serial_table_lock
, flags
);
645 spin_unlock_irqrestore(&serial_table_lock
, flags
);
647 printk(KERN_ERR
"%s: no free serial devices in table\n", __func__
);
651 static void set_serial_by_index(unsigned index
, struct hso_serial
*serial
)
655 spin_lock_irqsave(&serial_table_lock
, flags
);
657 serial_table
[index
] = serial
->parent
;
659 serial_table
[index
] = NULL
;
660 spin_unlock_irqrestore(&serial_table_lock
, flags
);
663 static void handle_usb_error(int status
, const char *function
,
664 struct hso_device
*hso_dev
)
670 explanation
= "no device";
673 explanation
= "endpoint not enabled";
676 explanation
= "endpoint stalled";
679 explanation
= "not enough bandwidth";
682 explanation
= "device disabled";
685 explanation
= "device suspended";
691 explanation
= "internal error";
697 explanation
= "protocol error";
699 schedule_work(&hso_dev
->reset_device
);
702 explanation
= "unknown status";
706 /* log a meaningful explanation of an USB status */
707 D1("%s: received USB status - %s (%d)", function
, explanation
, status
);
710 /* Network interface functions */
712 /* called when net interface is brought up by ifconfig */
713 static int hso_net_open(struct net_device
*net
)
715 struct hso_net
*odev
= netdev_priv(net
);
716 unsigned long flags
= 0;
719 dev_err(&net
->dev
, "No net device !\n");
723 odev
->skb_tx_buf
= NULL
;
725 /* setup environment */
726 spin_lock_irqsave(&odev
->net_lock
, flags
);
727 odev
->rx_parse_state
= WAIT_IP
;
728 odev
->rx_buf_size
= 0;
729 odev
->rx_buf_missing
= sizeof(struct iphdr
);
730 spin_unlock_irqrestore(&odev
->net_lock
, flags
);
732 /* We are up and running. */
733 set_bit(HSO_NET_RUNNING
, &odev
->flags
);
734 hso_start_net_device(odev
->parent
);
736 /* Tell the kernel we are ready to start receiving from it */
737 netif_start_queue(net
);
742 /* called when interface is brought down by ifconfig */
743 static int hso_net_close(struct net_device
*net
)
745 struct hso_net
*odev
= netdev_priv(net
);
747 /* we don't need the queue anymore */
748 netif_stop_queue(net
);
749 /* no longer running */
750 clear_bit(HSO_NET_RUNNING
, &odev
->flags
);
752 hso_stop_net_device(odev
->parent
);
758 /* USB tells is xmit done, we should start the netqueue again */
759 static void write_bulk_callback(struct urb
*urb
)
761 struct hso_net
*odev
= urb
->context
;
762 int status
= urb
->status
;
765 if (!odev
|| !test_bit(HSO_NET_RUNNING
, &odev
->flags
)) {
766 dev_err(&urb
->dev
->dev
, "%s: device not running\n", __func__
);
770 /* Do we still have a valid kernel network device? */
771 if (!netif_device_present(odev
->net
)) {
772 dev_err(&urb
->dev
->dev
, "%s: net device not present\n",
777 /* log status, but don't act on it, we don't need to resubmit anything
780 handle_usb_error(status
, __func__
, odev
->parent
);
782 hso_put_activity(odev
->parent
);
784 /* Tell the network interface we are ready for another frame */
785 netif_wake_queue(odev
->net
);
788 /* called by kernel when we need to transmit a packet */
789 static netdev_tx_t
hso_net_start_xmit(struct sk_buff
*skb
,
790 struct net_device
*net
)
792 struct hso_net
*odev
= netdev_priv(net
);
795 /* Tell the kernel, "No more frames 'til we are done with this one." */
796 netif_stop_queue(net
);
797 if (hso_get_activity(odev
->parent
) == -EAGAIN
) {
798 odev
->skb_tx_buf
= skb
;
803 DUMP1(skb
->data
, skb
->len
);
804 /* Copy it from kernel memory to OUR memory */
805 memcpy(odev
->mux_bulk_tx_buf
, skb
->data
, skb
->len
);
806 D1("len: %d/%d", skb
->len
, MUX_BULK_TX_BUF_SIZE
);
808 /* Fill in the URB for shipping it out. */
809 usb_fill_bulk_urb(odev
->mux_bulk_tx_urb
,
811 usb_sndbulkpipe(odev
->parent
->usb
,
813 bEndpointAddress
& 0x7F),
814 odev
->mux_bulk_tx_buf
, skb
->len
, write_bulk_callback
,
817 /* Deal with the Zero Length packet problem, I hope */
818 odev
->mux_bulk_tx_urb
->transfer_flags
|= URB_ZERO_PACKET
;
820 /* Send the URB on its merry way. */
821 result
= usb_submit_urb(odev
->mux_bulk_tx_urb
, GFP_ATOMIC
);
823 dev_warn(&odev
->parent
->interface
->dev
,
824 "failed mux_bulk_tx_urb %d\n", result
);
825 net
->stats
.tx_errors
++;
826 netif_start_queue(net
);
828 net
->stats
.tx_packets
++;
829 net
->stats
.tx_bytes
+= skb
->len
;
836 static const struct ethtool_ops ops
= {
837 .get_link
= ethtool_op_get_link
840 /* called when a packet did not ack after watchdogtimeout */
841 static void hso_net_tx_timeout(struct net_device
*net
)
843 struct hso_net
*odev
= netdev_priv(net
);
848 /* Tell syslog we are hosed. */
849 dev_warn(&net
->dev
, "Tx timed out.\n");
851 /* Tear the waiting frame off the list */
852 if (odev
->mux_bulk_tx_urb
&&
853 (odev
->mux_bulk_tx_urb
->status
== -EINPROGRESS
))
854 usb_unlink_urb(odev
->mux_bulk_tx_urb
);
856 /* Update statistics */
857 net
->stats
.tx_errors
++;
860 /* make a real packet from the received USB buffer */
861 static void packetizeRx(struct hso_net
*odev
, unsigned char *ip_pkt
,
862 unsigned int count
, unsigned char is_eop
)
864 unsigned short temp_bytes
;
865 unsigned short buffer_offset
= 0;
866 unsigned short frame_len
;
867 unsigned char *tmp_rx_buf
;
870 D1("Rx %d bytes", count
);
871 DUMP(ip_pkt
, min(128, (int)count
));
874 switch (odev
->rx_parse_state
) {
876 /* waiting for IP header. */
877 /* wanted bytes - size of ip header */
880 odev
->rx_buf_missing
) ? count
: odev
->
883 memcpy(((unsigned char *)(&odev
->rx_ip_hdr
)) +
884 odev
->rx_buf_size
, ip_pkt
+ buffer_offset
,
887 odev
->rx_buf_size
+= temp_bytes
;
888 buffer_offset
+= temp_bytes
;
889 odev
->rx_buf_missing
-= temp_bytes
;
892 if (!odev
->rx_buf_missing
) {
893 /* header is complete allocate an sk_buffer and
894 * continue to WAIT_DATA */
895 frame_len
= ntohs(odev
->rx_ip_hdr
.tot_len
);
897 if ((frame_len
> DEFAULT_MRU
) ||
898 (frame_len
< sizeof(struct iphdr
))) {
899 dev_err(&odev
->net
->dev
,
900 "Invalid frame (%d) length\n",
902 odev
->rx_parse_state
= WAIT_SYNC
;
905 /* Allocate an sk_buff */
906 odev
->skb_rx_buf
= netdev_alloc_skb(odev
->net
,
908 if (!odev
->skb_rx_buf
) {
909 /* We got no receive buffer. */
910 D1("could not allocate memory");
911 odev
->rx_parse_state
= WAIT_SYNC
;
915 /* Copy what we got so far. make room for iphdr
918 skb_put(odev
->skb_rx_buf
,
919 sizeof(struct iphdr
));
920 memcpy(tmp_rx_buf
, (char *)&(odev
->rx_ip_hdr
),
921 sizeof(struct iphdr
));
924 odev
->rx_buf_size
= sizeof(struct iphdr
);
926 /* Filip actually use .tot_len */
927 odev
->rx_buf_missing
=
928 frame_len
- sizeof(struct iphdr
);
929 odev
->rx_parse_state
= WAIT_DATA
;
934 temp_bytes
= (count
< odev
->rx_buf_missing
)
935 ? count
: odev
->rx_buf_missing
;
937 /* Copy the rest of the bytes that are left in the
938 * buffer into the waiting sk_buf. */
939 /* Make room for temp_bytes after tail. */
940 tmp_rx_buf
= skb_put(odev
->skb_rx_buf
, temp_bytes
);
941 memcpy(tmp_rx_buf
, ip_pkt
+ buffer_offset
, temp_bytes
);
943 odev
->rx_buf_missing
-= temp_bytes
;
945 buffer_offset
+= temp_bytes
;
946 odev
->rx_buf_size
+= temp_bytes
;
947 if (!odev
->rx_buf_missing
) {
948 /* Packet is complete. Inject into stack. */
949 /* We have IP packet here */
950 odev
->skb_rx_buf
->protocol
= cpu_to_be16(ETH_P_IP
);
951 skb_reset_mac_header(odev
->skb_rx_buf
);
953 /* Ship it off to the kernel */
954 netif_rx(odev
->skb_rx_buf
);
955 /* No longer our buffer. */
956 odev
->skb_rx_buf
= NULL
;
958 /* update out statistics */
959 odev
->net
->stats
.rx_packets
++;
961 odev
->net
->stats
.rx_bytes
+= odev
->rx_buf_size
;
963 odev
->rx_buf_size
= 0;
964 odev
->rx_buf_missing
= sizeof(struct iphdr
);
965 odev
->rx_parse_state
= WAIT_IP
;
980 /* Recovery mechanism for WAIT_SYNC state. */
982 if (odev
->rx_parse_state
== WAIT_SYNC
) {
983 odev
->rx_parse_state
= WAIT_IP
;
984 odev
->rx_buf_size
= 0;
985 odev
->rx_buf_missing
= sizeof(struct iphdr
);
990 static void fix_crc_bug(struct urb
*urb
, __le16 max_packet_size
)
992 static const u8 crc_check
[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
993 u32 rest
= urb
->actual_length
% le16_to_cpu(max_packet_size
);
995 if (((rest
== 5) || (rest
== 6)) &&
996 !memcmp(((u8
*)urb
->transfer_buffer
) + urb
->actual_length
- 4,
998 urb
->actual_length
-= 4;
1002 /* Moving data from usb to kernel (in interrupt state) */
1003 static void read_bulk_callback(struct urb
*urb
)
1005 struct hso_net
*odev
= urb
->context
;
1006 struct net_device
*net
;
1008 int status
= urb
->status
;
1010 /* is al ok? (Filip: Who's Al ?) */
1012 handle_usb_error(status
, __func__
, odev
->parent
);
1017 if (!odev
|| !test_bit(HSO_NET_RUNNING
, &odev
->flags
)) {
1018 D1("BULK IN callback but driver is not active!");
1021 usb_mark_last_busy(urb
->dev
);
1025 if (!netif_device_present(net
)) {
1026 /* Somebody killed our network interface... */
1030 if (odev
->parent
->port_spec
& HSO_INFO_CRC_BUG
)
1031 fix_crc_bug(urb
, odev
->in_endp
->wMaxPacketSize
);
1033 /* do we even have a packet? */
1034 if (urb
->actual_length
) {
1035 /* Handle the IP stream, add header and push it onto network
1036 * stack if the packet is complete. */
1037 spin_lock(&odev
->net_lock
);
1038 packetizeRx(odev
, urb
->transfer_buffer
, urb
->actual_length
,
1039 (urb
->transfer_buffer_length
>
1040 urb
->actual_length
) ? 1 : 0);
1041 spin_unlock(&odev
->net_lock
);
1044 /* We are done with this URB, resubmit it. Prep the USB to wait for
1045 * another frame. Reuse same as received. */
1046 usb_fill_bulk_urb(urb
,
1048 usb_rcvbulkpipe(odev
->parent
->usb
,
1050 bEndpointAddress
& 0x7F),
1051 urb
->transfer_buffer
, MUX_BULK_RX_BUF_SIZE
,
1052 read_bulk_callback
, odev
);
1054 /* Give this to the USB subsystem so it can tell us when more data
1056 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1058 dev_warn(&odev
->parent
->interface
->dev
,
1059 "%s failed submit mux_bulk_rx_urb %d\n", __func__
,
1063 /* Serial driver functions */
1065 static void hso_init_termios(struct ktermios
*termios
)
1068 * The default requirements for this device are:
1071 ~(IGNBRK
/* disable ignore break */
1072 | BRKINT
/* disable break causes interrupt */
1073 | PARMRK
/* disable mark parity errors */
1074 | ISTRIP
/* disable clear high bit of input characters */
1075 | INLCR
/* disable translate NL to CR */
1076 | IGNCR
/* disable ignore CR */
1077 | ICRNL
/* disable translate CR to NL */
1078 | IXON
); /* disable enable XON/XOFF flow control */
1080 /* disable postprocess output characters */
1081 termios
->c_oflag
&= ~OPOST
;
1084 ~(ECHO
/* disable echo input characters */
1085 | ECHONL
/* disable echo new line */
1086 | ICANON
/* disable erase, kill, werase, and rprnt
1087 special characters */
1088 | ISIG
/* disable interrupt, quit, and suspend special
1090 | IEXTEN
); /* disable non-POSIX special characters */
1093 ~(CSIZE
/* no size */
1094 | PARENB
/* disable parity bit */
1095 | CBAUD
/* clear current baud rate */
1096 | CBAUDEX
); /* clear current buad rate */
1098 termios
->c_cflag
|= CS8
; /* character size 8 bits */
1100 /* baud rate 115200 */
1101 tty_termios_encode_baud_rate(termios
, 115200, 115200);
1104 static void _hso_serial_set_termios(struct tty_struct
*tty
,
1105 struct ktermios
*old
)
1107 struct hso_serial
*serial
= tty
->driver_data
;
1110 printk(KERN_ERR
"%s: no tty structures", __func__
);
1114 D4("port %d", serial
->minor
);
1117 * Fix up unsupported bits
1119 tty
->termios
.c_iflag
&= ~IXON
; /* disable enable XON/XOFF flow control */
1121 tty
->termios
.c_cflag
&=
1122 ~(CSIZE
/* no size */
1123 | PARENB
/* disable parity bit */
1124 | CBAUD
/* clear current baud rate */
1125 | CBAUDEX
); /* clear current buad rate */
1127 tty
->termios
.c_cflag
|= CS8
; /* character size 8 bits */
1129 /* baud rate 115200 */
1130 tty_encode_baud_rate(tty
, 115200, 115200);
1133 static void hso_resubmit_rx_bulk_urb(struct hso_serial
*serial
, struct urb
*urb
)
1136 /* We are done with this URB, resubmit it. Prep the USB to wait for
1138 usb_fill_bulk_urb(urb
, serial
->parent
->usb
,
1139 usb_rcvbulkpipe(serial
->parent
->usb
,
1141 bEndpointAddress
& 0x7F),
1142 urb
->transfer_buffer
, serial
->rx_data_length
,
1143 hso_std_serial_read_bulk_callback
, serial
);
1144 /* Give this to the USB subsystem so it can tell us when more data
1146 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1148 dev_err(&urb
->dev
->dev
, "%s failed submit serial rx_urb %d\n",
1156 static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial
*serial
)
1159 struct urb
*curr_urb
;
1161 while (serial
->rx_urb_filled
[serial
->curr_rx_urb_idx
]) {
1162 curr_urb
= serial
->rx_urb
[serial
->curr_rx_urb_idx
];
1163 count
= put_rxbuf_data(curr_urb
, serial
);
1167 serial
->curr_rx_urb_idx
++;
1168 if (serial
->curr_rx_urb_idx
>= serial
->num_rx_urbs
)
1169 serial
->curr_rx_urb_idx
= 0;
1170 hso_resubmit_rx_bulk_urb(serial
, curr_urb
);
1175 static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial
*serial
)
1180 urb
= serial
->rx_urb
[0];
1181 if (serial
->port
.count
> 0) {
1182 count
= put_rxbuf_data(urb
, serial
);
1186 /* Re issue a read as long as we receive data. */
1188 if (count
== 0 && ((urb
->actual_length
!= 0) ||
1189 (serial
->rx_state
== RX_PENDING
))) {
1190 serial
->rx_state
= RX_SENT
;
1191 hso_mux_serial_read(serial
);
1193 serial
->rx_state
= RX_IDLE
;
1197 /* read callback for Diag and CS port */
1198 static void hso_std_serial_read_bulk_callback(struct urb
*urb
)
1200 struct hso_serial
*serial
= urb
->context
;
1201 int status
= urb
->status
;
1203 D4("\n--- Got serial_read_bulk callback %02x ---", status
);
1207 D1("serial == NULL");
1211 handle_usb_error(status
, __func__
, serial
->parent
);
1215 D1("Actual length = %d\n", urb
->actual_length
);
1216 DUMP1(urb
->transfer_buffer
, urb
->actual_length
);
1218 /* Anyone listening? */
1219 if (serial
->port
.count
== 0)
1222 if (serial
->parent
->port_spec
& HSO_INFO_CRC_BUG
)
1223 fix_crc_bug(urb
, serial
->in_endp
->wMaxPacketSize
);
1224 /* Valid data, handle RX data */
1225 spin_lock(&serial
->serial_lock
);
1226 serial
->rx_urb_filled
[hso_urb_to_index(serial
, urb
)] = 1;
1227 put_rxbuf_data_and_resubmit_bulk_urb(serial
);
1228 spin_unlock(&serial
->serial_lock
);
1232 * This needs to be a tasklet otherwise we will
1233 * end up recursively calling this function.
1235 static void hso_unthrottle_tasklet(struct hso_serial
*serial
)
1237 unsigned long flags
;
1239 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1240 if ((serial
->parent
->port_spec
& HSO_INTF_MUX
))
1241 put_rxbuf_data_and_resubmit_ctrl_urb(serial
);
1243 put_rxbuf_data_and_resubmit_bulk_urb(serial
);
1244 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1247 static void hso_unthrottle(struct tty_struct
*tty
)
1249 struct hso_serial
*serial
= tty
->driver_data
;
1251 tasklet_hi_schedule(&serial
->unthrottle_tasklet
);
1254 /* open the requested serial port */
1255 static int hso_serial_open(struct tty_struct
*tty
, struct file
*filp
)
1257 struct hso_serial
*serial
= get_serial_by_index(tty
->index
);
1261 if (serial
== NULL
|| serial
->magic
!= HSO_SERIAL_MAGIC
) {
1263 tty
->driver_data
= NULL
;
1264 D1("Failed to open port");
1268 mutex_lock(&serial
->parent
->mutex
);
1269 result
= usb_autopm_get_interface(serial
->parent
->interface
);
1273 D1("Opening %d", serial
->minor
);
1274 kref_get(&serial
->parent
->ref
);
1277 tty
->driver_data
= serial
;
1278 tty_port_tty_set(&serial
->port
, tty
);
1280 /* check for port already opened, if not set the termios */
1281 serial
->port
.count
++;
1282 if (serial
->port
.count
== 1) {
1283 serial
->rx_state
= RX_IDLE
;
1284 /* Force default termio settings */
1285 _hso_serial_set_termios(tty
, NULL
);
1286 tasklet_init(&serial
->unthrottle_tasklet
,
1287 (void (*)(unsigned long))hso_unthrottle_tasklet
,
1288 (unsigned long)serial
);
1289 result
= hso_start_serial_device(serial
->parent
, GFP_KERNEL
);
1291 hso_stop_serial_device(serial
->parent
);
1292 serial
->port
.count
--;
1293 kref_put(&serial
->parent
->ref
, hso_serial_ref_free
);
1296 D1("Port was already open");
1299 usb_autopm_put_interface(serial
->parent
->interface
);
1303 hso_serial_tiocmset(tty
, TIOCM_RTS
| TIOCM_DTR
, 0);
1305 mutex_unlock(&serial
->parent
->mutex
);
1309 /* close the requested serial port */
1310 static void hso_serial_close(struct tty_struct
*tty
, struct file
*filp
)
1312 struct hso_serial
*serial
= tty
->driver_data
;
1315 D1("Closing serial port");
1317 /* Open failed, no close cleanup required */
1321 mutex_lock(&serial
->parent
->mutex
);
1322 usb_gone
= serial
->parent
->usb_gone
;
1325 usb_autopm_get_interface(serial
->parent
->interface
);
1327 /* reset the rts and dtr */
1328 /* do the actual close */
1329 serial
->port
.count
--;
1331 if (serial
->port
.count
<= 0) {
1332 serial
->port
.count
= 0;
1333 tty_port_tty_set(&serial
->port
, NULL
);
1335 hso_stop_serial_device(serial
->parent
);
1336 tasklet_kill(&serial
->unthrottle_tasklet
);
1340 usb_autopm_put_interface(serial
->parent
->interface
);
1342 mutex_unlock(&serial
->parent
->mutex
);
1344 kref_put(&serial
->parent
->ref
, hso_serial_ref_free
);
1347 /* close the requested serial port */
1348 static int hso_serial_write(struct tty_struct
*tty
, const unsigned char *buf
,
1351 struct hso_serial
*serial
= tty
->driver_data
;
1352 int space
, tx_bytes
;
1353 unsigned long flags
;
1356 if (serial
== NULL
) {
1357 printk(KERN_ERR
"%s: serial is NULL\n", __func__
);
1361 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1363 space
= serial
->tx_data_length
- serial
->tx_buffer_count
;
1364 tx_bytes
= (count
< space
) ? count
: space
;
1369 memcpy(serial
->tx_buffer
+ serial
->tx_buffer_count
, buf
, tx_bytes
);
1370 serial
->tx_buffer_count
+= tx_bytes
;
1373 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1375 hso_kick_transmit(serial
);
1380 /* how much room is there for writing */
1381 static int hso_serial_write_room(struct tty_struct
*tty
)
1383 struct hso_serial
*serial
= tty
->driver_data
;
1385 unsigned long flags
;
1387 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1388 room
= serial
->tx_data_length
- serial
->tx_buffer_count
;
1389 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1391 /* return free room */
1395 /* setup the term */
1396 static void hso_serial_set_termios(struct tty_struct
*tty
, struct ktermios
*old
)
1398 struct hso_serial
*serial
= tty
->driver_data
;
1399 unsigned long flags
;
1402 D5("Termios called with: cflags new[%d] - old[%d]",
1403 tty
->termios
.c_cflag
, old
->c_cflag
);
1405 /* the actual setup */
1406 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1407 if (serial
->port
.count
)
1408 _hso_serial_set_termios(tty
, old
);
1410 tty
->termios
= *old
;
1411 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1416 /* how many characters in the buffer */
1417 static int hso_serial_chars_in_buffer(struct tty_struct
*tty
)
1419 struct hso_serial
*serial
= tty
->driver_data
;
1421 unsigned long flags
;
1427 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1428 chars
= serial
->tx_buffer_count
;
1429 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1433 static int tiocmget_submit_urb(struct hso_serial
*serial
,
1434 struct hso_tiocmget
*tiocmget
,
1435 struct usb_device
*usb
)
1439 if (serial
->parent
->usb_gone
)
1441 usb_fill_int_urb(tiocmget
->urb
, usb
,
1444 bEndpointAddress
& 0x7F),
1445 &tiocmget
->serial_state_notification
,
1446 sizeof(struct hso_serial_state_notification
),
1447 tiocmget_intr_callback
, serial
,
1448 tiocmget
->endp
->bInterval
);
1449 result
= usb_submit_urb(tiocmget
->urb
, GFP_ATOMIC
);
1451 dev_warn(&usb
->dev
, "%s usb_submit_urb failed %d\n", __func__
,
1458 static void tiocmget_intr_callback(struct urb
*urb
)
1460 struct hso_serial
*serial
= urb
->context
;
1461 struct hso_tiocmget
*tiocmget
;
1462 int status
= urb
->status
;
1463 u16 UART_state_bitmap
, prev_UART_state_bitmap
;
1464 struct uart_icount
*icount
;
1465 struct hso_serial_state_notification
*serial_state_notification
;
1466 struct usb_device
*usb
;
1473 handle_usb_error(status
, __func__
, serial
->parent
);
1477 /* tiocmget is only supported on HSO_PORT_MODEM */
1478 tiocmget
= serial
->tiocmget
;
1481 BUG_ON((serial
->parent
->port_spec
& HSO_PORT_MASK
) != HSO_PORT_MODEM
);
1483 usb
= serial
->parent
->usb
;
1484 if_num
= serial
->parent
->interface
->altsetting
->desc
.bInterfaceNumber
;
1486 /* wIndex should be the USB interface number of the port to which the
1487 * notification applies, which should always be the Modem port.
1489 serial_state_notification
= &tiocmget
->serial_state_notification
;
1490 if (serial_state_notification
->bmRequestType
!= BM_REQUEST_TYPE
||
1491 serial_state_notification
->bNotification
!= B_NOTIFICATION
||
1492 le16_to_cpu(serial_state_notification
->wValue
) != W_VALUE
||
1493 le16_to_cpu(serial_state_notification
->wIndex
) != if_num
||
1494 le16_to_cpu(serial_state_notification
->wLength
) != W_LENGTH
) {
1496 "hso received invalid serial state notification\n");
1497 DUMP(serial_state_notification
,
1498 sizeof(struct hso_serial_state_notification
));
1501 UART_state_bitmap
= le16_to_cpu(serial_state_notification
->
1503 prev_UART_state_bitmap
= tiocmget
->prev_UART_state_bitmap
;
1504 icount
= &tiocmget
->icount
;
1505 spin_lock(&serial
->serial_lock
);
1506 if ((UART_state_bitmap
& B_OVERRUN
) !=
1507 (prev_UART_state_bitmap
& B_OVERRUN
))
1509 if ((UART_state_bitmap
& B_PARITY
) !=
1510 (prev_UART_state_bitmap
& B_PARITY
))
1512 if ((UART_state_bitmap
& B_FRAMING
) !=
1513 (prev_UART_state_bitmap
& B_FRAMING
))
1515 if ((UART_state_bitmap
& B_RING_SIGNAL
) &&
1516 !(prev_UART_state_bitmap
& B_RING_SIGNAL
))
1518 if ((UART_state_bitmap
& B_BREAK
) !=
1519 (prev_UART_state_bitmap
& B_BREAK
))
1521 if ((UART_state_bitmap
& B_TX_CARRIER
) !=
1522 (prev_UART_state_bitmap
& B_TX_CARRIER
))
1524 if ((UART_state_bitmap
& B_RX_CARRIER
) !=
1525 (prev_UART_state_bitmap
& B_RX_CARRIER
))
1527 tiocmget
->prev_UART_state_bitmap
= UART_state_bitmap
;
1528 spin_unlock(&serial
->serial_lock
);
1529 tiocmget
->intr_completed
= 1;
1530 wake_up_interruptible(&tiocmget
->waitq
);
1532 memset(serial_state_notification
, 0,
1533 sizeof(struct hso_serial_state_notification
));
1534 tiocmget_submit_urb(serial
,
1536 serial
->parent
->usb
);
1540 * next few functions largely stolen from drivers/serial/serial_core.c
1542 /* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1543 * - mask passed in arg for lines of interest
1544 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1545 * Caller should use TIOCGICOUNT to see which one it was
1548 hso_wait_modem_status(struct hso_serial
*serial
, unsigned long arg
)
1550 DECLARE_WAITQUEUE(wait
, current
);
1551 struct uart_icount cprev
, cnow
;
1552 struct hso_tiocmget
*tiocmget
;
1555 tiocmget
= serial
->tiocmget
;
1559 * note the counters on entry
1561 spin_lock_irq(&serial
->serial_lock
);
1562 memcpy(&cprev
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1563 spin_unlock_irq(&serial
->serial_lock
);
1564 add_wait_queue(&tiocmget
->waitq
, &wait
);
1566 spin_lock_irq(&serial
->serial_lock
);
1567 memcpy(&cnow
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1568 spin_unlock_irq(&serial
->serial_lock
);
1569 set_current_state(TASK_INTERRUPTIBLE
);
1570 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1571 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1572 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
))) {
1577 /* see if a signal did it */
1578 if (signal_pending(current
)) {
1584 current
->state
= TASK_RUNNING
;
1585 remove_wait_queue(&tiocmget
->waitq
, &wait
);
1591 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1592 * Return: write counters to the user passed counter struct
1593 * NB: both 1->0 and 0->1 transitions are counted except for
1594 * RI where only 0->1 is counted.
1596 static int hso_get_count(struct tty_struct
*tty
,
1597 struct serial_icounter_struct
*icount
)
1599 struct uart_icount cnow
;
1600 struct hso_serial
*serial
= tty
->driver_data
;
1601 struct hso_tiocmget
*tiocmget
= serial
->tiocmget
;
1603 memset(icount
, 0, sizeof(struct serial_icounter_struct
));
1607 spin_lock_irq(&serial
->serial_lock
);
1608 memcpy(&cnow
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1609 spin_unlock_irq(&serial
->serial_lock
);
1611 icount
->cts
= cnow
.cts
;
1612 icount
->dsr
= cnow
.dsr
;
1613 icount
->rng
= cnow
.rng
;
1614 icount
->dcd
= cnow
.dcd
;
1615 icount
->rx
= cnow
.rx
;
1616 icount
->tx
= cnow
.tx
;
1617 icount
->frame
= cnow
.frame
;
1618 icount
->overrun
= cnow
.overrun
;
1619 icount
->parity
= cnow
.parity
;
1620 icount
->brk
= cnow
.brk
;
1621 icount
->buf_overrun
= cnow
.buf_overrun
;
1627 static int hso_serial_tiocmget(struct tty_struct
*tty
)
1630 struct hso_serial
*serial
= tty
->driver_data
;
1631 struct hso_tiocmget
*tiocmget
;
1632 u16 UART_state_bitmap
;
1636 D1("no tty structures");
1639 spin_lock_irq(&serial
->serial_lock
);
1640 retval
= ((serial
->rts_state
) ? TIOCM_RTS
: 0) |
1641 ((serial
->dtr_state
) ? TIOCM_DTR
: 0);
1642 tiocmget
= serial
->tiocmget
;
1645 UART_state_bitmap
= le16_to_cpu(
1646 tiocmget
->prev_UART_state_bitmap
);
1647 if (UART_state_bitmap
& B_RING_SIGNAL
)
1648 retval
|= TIOCM_RNG
;
1649 if (UART_state_bitmap
& B_RX_CARRIER
)
1651 if (UART_state_bitmap
& B_TX_CARRIER
)
1652 retval
|= TIOCM_DSR
;
1654 spin_unlock_irq(&serial
->serial_lock
);
1658 static int hso_serial_tiocmset(struct tty_struct
*tty
,
1659 unsigned int set
, unsigned int clear
)
1662 unsigned long flags
;
1664 struct hso_serial
*serial
= tty
->driver_data
;
1668 D1("no tty structures");
1672 if ((serial
->parent
->port_spec
& HSO_PORT_MASK
) != HSO_PORT_MODEM
)
1675 if_num
= serial
->parent
->interface
->altsetting
->desc
.bInterfaceNumber
;
1677 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1678 if (set
& TIOCM_RTS
)
1679 serial
->rts_state
= 1;
1680 if (set
& TIOCM_DTR
)
1681 serial
->dtr_state
= 1;
1683 if (clear
& TIOCM_RTS
)
1684 serial
->rts_state
= 0;
1685 if (clear
& TIOCM_DTR
)
1686 serial
->dtr_state
= 0;
1688 if (serial
->dtr_state
)
1690 if (serial
->rts_state
)
1693 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1695 return usb_control_msg(serial
->parent
->usb
,
1696 usb_rcvctrlpipe(serial
->parent
->usb
, 0), 0x22,
1697 0x21, val
, if_num
, NULL
, 0,
1698 USB_CTRL_SET_TIMEOUT
);
1701 static int hso_serial_ioctl(struct tty_struct
*tty
,
1702 unsigned int cmd
, unsigned long arg
)
1704 struct hso_serial
*serial
= tty
->driver_data
;
1706 D4("IOCTL cmd: %d, arg: %ld", cmd
, arg
);
1712 ret
= hso_wait_modem_status(serial
, arg
);
1722 /* starts a transmit */
1723 static void hso_kick_transmit(struct hso_serial
*serial
)
1726 unsigned long flags
;
1729 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1730 if (!serial
->tx_buffer_count
)
1733 if (serial
->tx_urb_used
)
1736 /* Wakeup USB interface if necessary */
1737 if (hso_get_activity(serial
->parent
) == -EAGAIN
)
1740 /* Switch pointers around to avoid memcpy */
1741 temp
= serial
->tx_buffer
;
1742 serial
->tx_buffer
= serial
->tx_data
;
1743 serial
->tx_data
= temp
;
1744 serial
->tx_data_count
= serial
->tx_buffer_count
;
1745 serial
->tx_buffer_count
= 0;
1747 /* If temp is set, it means we switched buffers */
1748 if (temp
&& serial
->write_data
) {
1749 res
= serial
->write_data(serial
);
1751 serial
->tx_urb_used
= 1;
1754 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1757 /* make a request (for reading and writing data to muxed serial port) */
1758 static int mux_device_request(struct hso_serial
*serial
, u8 type
, u16 port
,
1759 struct urb
*ctrl_urb
,
1760 struct usb_ctrlrequest
*ctrl_req
,
1761 u8
*ctrl_urb_data
, u32 size
)
1767 if (!serial
|| !ctrl_urb
|| !ctrl_req
) {
1768 printk(KERN_ERR
"%s: Wrong arguments\n", __func__
);
1773 ctrl_req
->wValue
= 0;
1774 ctrl_req
->wIndex
= cpu_to_le16(hso_port_to_mux(port
));
1775 ctrl_req
->wLength
= cpu_to_le16(size
);
1777 if (type
== USB_CDC_GET_ENCAPSULATED_RESPONSE
) {
1778 /* Reading command */
1779 ctrl_req
->bRequestType
= USB_DIR_IN
|
1780 USB_TYPE_OPTION_VENDOR
|
1781 USB_RECIP_INTERFACE
;
1782 ctrl_req
->bRequest
= USB_CDC_GET_ENCAPSULATED_RESPONSE
;
1783 pipe
= usb_rcvctrlpipe(serial
->parent
->usb
, 0);
1785 /* Writing command */
1786 ctrl_req
->bRequestType
= USB_DIR_OUT
|
1787 USB_TYPE_OPTION_VENDOR
|
1788 USB_RECIP_INTERFACE
;
1789 ctrl_req
->bRequest
= USB_CDC_SEND_ENCAPSULATED_COMMAND
;
1790 pipe
= usb_sndctrlpipe(serial
->parent
->usb
, 0);
1793 D2("%s command (%02x) len: %d, port: %d",
1794 type
== USB_CDC_GET_ENCAPSULATED_RESPONSE
? "Read" : "Write",
1795 ctrl_req
->bRequestType
, ctrl_req
->wLength
, port
);
1798 ctrl_urb
->transfer_flags
= 0;
1799 usb_fill_control_urb(ctrl_urb
,
1800 serial
->parent
->usb
,
1803 ctrl_urb_data
, size
, ctrl_callback
, serial
);
1804 /* Send it on merry way */
1805 result
= usb_submit_urb(ctrl_urb
, GFP_ATOMIC
);
1807 dev_err(&ctrl_urb
->dev
->dev
,
1808 "%s failed submit ctrl_urb %d type %d\n", __func__
,
1817 /* called by intr_callback when read occurs */
1818 static int hso_mux_serial_read(struct hso_serial
*serial
)
1824 memset(serial
->rx_data
[0], 0, CTRL_URB_RX_SIZE
);
1825 /* make the request */
1827 if (serial
->num_rx_urbs
!= 1) {
1828 dev_err(&serial
->parent
->interface
->dev
,
1829 "ERROR: mux'd reads with multiple buffers "
1833 return mux_device_request(serial
,
1834 USB_CDC_GET_ENCAPSULATED_RESPONSE
,
1835 serial
->parent
->port_spec
& HSO_PORT_MASK
,
1837 &serial
->ctrl_req_rx
,
1838 serial
->rx_data
[0], serial
->rx_data_length
);
1841 /* used for muxed serial port callback (muxed serial read) */
1842 static void intr_callback(struct urb
*urb
)
1844 struct hso_shared_int
*shared_int
= urb
->context
;
1845 struct hso_serial
*serial
;
1846 unsigned char *port_req
;
1847 int status
= urb
->status
;
1850 usb_mark_last_busy(urb
->dev
);
1858 handle_usb_error(status
, __func__
, NULL
);
1861 D4("\n--- Got intr callback 0x%02X ---", status
);
1864 port_req
= urb
->transfer_buffer
;
1865 D4(" port_req = 0x%.2X\n", *port_req
);
1866 /* loop over all muxed ports to find the one sending this */
1867 for (i
= 0; i
< 8; i
++) {
1868 /* max 8 channels on MUX */
1869 if (*port_req
& (1 << i
)) {
1870 serial
= get_serial_by_shared_int_and_type(shared_int
,
1872 if (serial
!= NULL
) {
1873 D1("Pending read interrupt on port %d\n", i
);
1874 spin_lock(&serial
->serial_lock
);
1875 if (serial
->rx_state
== RX_IDLE
&&
1876 serial
->port
.count
> 0) {
1877 /* Setup and send a ctrl req read on
1879 if (!serial
->rx_urb_filled
[0]) {
1880 serial
->rx_state
= RX_SENT
;
1881 hso_mux_serial_read(serial
);
1883 serial
->rx_state
= RX_PENDING
;
1885 D1("Already a read pending on "
1886 "port %d or port not open\n", i
);
1888 spin_unlock(&serial
->serial_lock
);
1892 /* Resubmit interrupt urb */
1893 hso_mux_submit_intr_urb(shared_int
, urb
->dev
, GFP_ATOMIC
);
1896 /* called for writing to muxed serial port */
1897 static int hso_mux_serial_write_data(struct hso_serial
*serial
)
1902 return mux_device_request(serial
,
1903 USB_CDC_SEND_ENCAPSULATED_COMMAND
,
1904 serial
->parent
->port_spec
& HSO_PORT_MASK
,
1906 &serial
->ctrl_req_tx
,
1907 serial
->tx_data
, serial
->tx_data_count
);
1910 /* write callback for Diag and CS port */
1911 static void hso_std_serial_write_bulk_callback(struct urb
*urb
)
1913 struct hso_serial
*serial
= urb
->context
;
1914 int status
= urb
->status
;
1918 D1("serial == NULL");
1922 spin_lock(&serial
->serial_lock
);
1923 serial
->tx_urb_used
= 0;
1924 spin_unlock(&serial
->serial_lock
);
1926 handle_usb_error(status
, __func__
, serial
->parent
);
1929 hso_put_activity(serial
->parent
);
1930 tty_port_tty_wakeup(&serial
->port
);
1931 hso_kick_transmit(serial
);
1936 /* called for writing diag or CS serial port */
1937 static int hso_std_serial_write_data(struct hso_serial
*serial
)
1939 int count
= serial
->tx_data_count
;
1942 usb_fill_bulk_urb(serial
->tx_urb
,
1943 serial
->parent
->usb
,
1944 usb_sndbulkpipe(serial
->parent
->usb
,
1946 bEndpointAddress
& 0x7F),
1947 serial
->tx_data
, serial
->tx_data_count
,
1948 hso_std_serial_write_bulk_callback
, serial
);
1950 result
= usb_submit_urb(serial
->tx_urb
, GFP_ATOMIC
);
1952 dev_warn(&serial
->parent
->usb
->dev
,
1953 "Failed to submit urb - res %d\n", result
);
1960 /* callback after read or write on muxed serial port */
1961 static void ctrl_callback(struct urb
*urb
)
1963 struct hso_serial
*serial
= urb
->context
;
1964 struct usb_ctrlrequest
*req
;
1965 int status
= urb
->status
;
1971 spin_lock(&serial
->serial_lock
);
1972 serial
->tx_urb_used
= 0;
1973 spin_unlock(&serial
->serial_lock
);
1975 handle_usb_error(status
, __func__
, serial
->parent
);
1980 req
= (struct usb_ctrlrequest
*)(urb
->setup_packet
);
1981 D4("\n--- Got muxed ctrl callback 0x%02X ---", status
);
1982 D4("Actual length of urb = %d\n", urb
->actual_length
);
1983 DUMP1(urb
->transfer_buffer
, urb
->actual_length
);
1985 if (req
->bRequestType
==
1986 (USB_DIR_IN
| USB_TYPE_OPTION_VENDOR
| USB_RECIP_INTERFACE
)) {
1987 /* response to a read command */
1988 serial
->rx_urb_filled
[0] = 1;
1989 spin_lock(&serial
->serial_lock
);
1990 put_rxbuf_data_and_resubmit_ctrl_urb(serial
);
1991 spin_unlock(&serial
->serial_lock
);
1993 hso_put_activity(serial
->parent
);
1994 tty_port_tty_wakeup(&serial
->port
);
1995 /* response to a write command */
1996 hso_kick_transmit(serial
);
2000 /* handle RX data for serial port */
2001 static int put_rxbuf_data(struct urb
*urb
, struct hso_serial
*serial
)
2003 struct tty_struct
*tty
;
2007 if (urb
== NULL
|| serial
== NULL
) {
2008 D1("serial = NULL");
2012 tty
= tty_port_tty_get(&serial
->port
);
2014 if (tty
&& test_bit(TTY_THROTTLED
, &tty
->flags
)) {
2019 /* Push data to tty */
2020 D1("data to push to tty");
2021 count
= tty_buffer_request_room(&serial
->port
, urb
->actual_length
);
2022 if (count
>= urb
->actual_length
) {
2023 tty_insert_flip_string(&serial
->port
, urb
->transfer_buffer
,
2024 urb
->actual_length
);
2025 tty_flip_buffer_push(&serial
->port
);
2027 dev_warn(&serial
->parent
->usb
->dev
,
2028 "dropping data, %d bytes lost\n", urb
->actual_length
);
2033 serial
->rx_urb_filled
[hso_urb_to_index(serial
, urb
)] = 0;
2039 /* Base driver functions */
2041 static void hso_log_port(struct hso_device
*hso_dev
)
2046 switch (hso_dev
->port_spec
& HSO_PORT_MASK
) {
2047 case HSO_PORT_CONTROL
:
2048 port_type
= "Control";
2051 port_type
= "Application";
2056 case HSO_PORT_GPS_CONTROL
:
2057 port_type
= "GPS control";
2060 port_type
= "Application2";
2066 port_type
= "Diagnostic";
2068 case HSO_PORT_DIAG2
:
2069 port_type
= "Diagnostic2";
2071 case HSO_PORT_MODEM
:
2072 port_type
= "Modem";
2074 case HSO_PORT_NETWORK
:
2075 port_type
= "Network";
2078 port_type
= "Unknown";
2081 if ((hso_dev
->port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2082 sprintf(port_dev
, "%s", dev2net(hso_dev
)->net
->name
);
2084 sprintf(port_dev
, "/dev/%s%d", tty_filename
,
2085 dev2ser(hso_dev
)->minor
);
2087 dev_dbg(&hso_dev
->interface
->dev
, "HSO: Found %s port %s\n",
2088 port_type
, port_dev
);
2091 static int hso_start_net_device(struct hso_device
*hso_dev
)
2094 struct hso_net
*hso_net
= dev2net(hso_dev
);
2099 /* send URBs for all read buffers */
2100 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2102 /* Prep a receive URB */
2103 usb_fill_bulk_urb(hso_net
->mux_bulk_rx_urb_pool
[i
],
2105 usb_rcvbulkpipe(hso_dev
->usb
,
2107 bEndpointAddress
& 0x7F),
2108 hso_net
->mux_bulk_rx_buf_pool
[i
],
2109 MUX_BULK_RX_BUF_SIZE
, read_bulk_callback
,
2112 /* Put it out there so the device can send us stuff */
2113 result
= usb_submit_urb(hso_net
->mux_bulk_rx_urb_pool
[i
],
2116 dev_warn(&hso_dev
->usb
->dev
,
2117 "%s failed mux_bulk_rx_urb[%d] %d\n", __func__
,
2124 static int hso_stop_net_device(struct hso_device
*hso_dev
)
2127 struct hso_net
*hso_net
= dev2net(hso_dev
);
2132 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2133 if (hso_net
->mux_bulk_rx_urb_pool
[i
])
2134 usb_kill_urb(hso_net
->mux_bulk_rx_urb_pool
[i
]);
2137 if (hso_net
->mux_bulk_tx_urb
)
2138 usb_kill_urb(hso_net
->mux_bulk_tx_urb
);
2143 static int hso_start_serial_device(struct hso_device
*hso_dev
, gfp_t flags
)
2146 struct hso_serial
*serial
= dev2ser(hso_dev
);
2151 /* If it is not the MUX port fill in and submit a bulk urb (already
2152 * allocated in hso_serial_start) */
2153 if (!(serial
->parent
->port_spec
& HSO_INTF_MUX
)) {
2154 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2155 usb_fill_bulk_urb(serial
->rx_urb
[i
],
2156 serial
->parent
->usb
,
2157 usb_rcvbulkpipe(serial
->parent
->usb
,
2162 serial
->rx_data_length
,
2163 hso_std_serial_read_bulk_callback
,
2165 result
= usb_submit_urb(serial
->rx_urb
[i
], flags
);
2167 dev_warn(&serial
->parent
->usb
->dev
,
2168 "Failed to submit urb - res %d\n",
2174 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2175 if (!serial
->shared_int
->use_count
) {
2177 hso_mux_submit_intr_urb(serial
->shared_int
,
2178 hso_dev
->usb
, flags
);
2180 serial
->shared_int
->use_count
++;
2181 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2183 if (serial
->tiocmget
)
2184 tiocmget_submit_urb(serial
,
2186 serial
->parent
->usb
);
2190 static int hso_stop_serial_device(struct hso_device
*hso_dev
)
2193 struct hso_serial
*serial
= dev2ser(hso_dev
);
2194 struct hso_tiocmget
*tiocmget
;
2199 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2200 if (serial
->rx_urb
[i
]) {
2201 usb_kill_urb(serial
->rx_urb
[i
]);
2202 serial
->rx_urb_filled
[i
] = 0;
2205 serial
->curr_rx_urb_idx
= 0;
2208 usb_kill_urb(serial
->tx_urb
);
2210 if (serial
->shared_int
) {
2211 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2212 if (serial
->shared_int
->use_count
&&
2213 (--serial
->shared_int
->use_count
== 0)) {
2216 urb
= serial
->shared_int
->shared_intr_urb
;
2220 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2222 tiocmget
= serial
->tiocmget
;
2224 wake_up_interruptible(&tiocmget
->waitq
);
2225 usb_kill_urb(tiocmget
->urb
);
2231 static void hso_serial_common_free(struct hso_serial
*serial
)
2235 if (serial
->parent
->dev
)
2236 device_remove_file(serial
->parent
->dev
, &dev_attr_hsotype
);
2238 tty_unregister_device(tty_drv
, serial
->minor
);
2240 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2241 /* unlink and free RX URB */
2242 usb_free_urb(serial
->rx_urb
[i
]);
2243 /* free the RX buffer */
2244 kfree(serial
->rx_data
[i
]);
2247 /* unlink and free TX URB */
2248 usb_free_urb(serial
->tx_urb
);
2249 kfree(serial
->tx_data
);
2250 tty_port_destroy(&serial
->port
);
2253 static int hso_serial_common_create(struct hso_serial
*serial
, int num_urbs
,
2254 int rx_size
, int tx_size
)
2260 tty_port_init(&serial
->port
);
2262 minor
= get_free_serial_index();
2266 /* register our minor number */
2267 serial
->parent
->dev
= tty_port_register_device(&serial
->port
, tty_drv
,
2268 minor
, &serial
->parent
->interface
->dev
);
2269 dev
= serial
->parent
->dev
;
2270 dev_set_drvdata(dev
, serial
->parent
);
2271 i
= device_create_file(dev
, &dev_attr_hsotype
);
2273 /* fill in specific data for later use */
2274 serial
->minor
= minor
;
2275 serial
->magic
= HSO_SERIAL_MAGIC
;
2276 spin_lock_init(&serial
->serial_lock
);
2277 serial
->num_rx_urbs
= num_urbs
;
2279 /* RX, allocate urb and initialize */
2281 /* prepare our RX buffer */
2282 serial
->rx_data_length
= rx_size
;
2283 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2284 serial
->rx_urb
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
2285 if (!serial
->rx_urb
[i
]) {
2286 dev_err(dev
, "Could not allocate urb?\n");
2289 serial
->rx_urb
[i
]->transfer_buffer
= NULL
;
2290 serial
->rx_urb
[i
]->transfer_buffer_length
= 0;
2291 serial
->rx_data
[i
] = kzalloc(serial
->rx_data_length
,
2293 if (!serial
->rx_data
[i
])
2297 /* TX, allocate urb and initialize */
2298 serial
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2299 if (!serial
->tx_urb
) {
2300 dev_err(dev
, "Could not allocate urb?\n");
2303 serial
->tx_urb
->transfer_buffer
= NULL
;
2304 serial
->tx_urb
->transfer_buffer_length
= 0;
2305 /* prepare our TX buffer */
2306 serial
->tx_data_count
= 0;
2307 serial
->tx_buffer_count
= 0;
2308 serial
->tx_data_length
= tx_size
;
2309 serial
->tx_data
= kzalloc(serial
->tx_data_length
, GFP_KERNEL
);
2310 if (!serial
->tx_data
)
2313 serial
->tx_buffer
= kzalloc(serial
->tx_data_length
, GFP_KERNEL
);
2314 if (!serial
->tx_buffer
)
2319 hso_serial_common_free(serial
);
2323 /* Creates a general hso device */
2324 static struct hso_device
*hso_create_device(struct usb_interface
*intf
,
2327 struct hso_device
*hso_dev
;
2329 hso_dev
= kzalloc(sizeof(*hso_dev
), GFP_ATOMIC
);
2333 hso_dev
->port_spec
= port_spec
;
2334 hso_dev
->usb
= interface_to_usbdev(intf
);
2335 hso_dev
->interface
= intf
;
2336 kref_init(&hso_dev
->ref
);
2337 mutex_init(&hso_dev
->mutex
);
2339 INIT_WORK(&hso_dev
->async_get_intf
, async_get_intf
);
2340 INIT_WORK(&hso_dev
->async_put_intf
, async_put_intf
);
2341 INIT_WORK(&hso_dev
->reset_device
, reset_device
);
2346 /* Removes a network device in the network device table */
2347 static int remove_net_device(struct hso_device
*hso_dev
)
2351 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
2352 if (network_table
[i
] == hso_dev
) {
2353 network_table
[i
] = NULL
;
2357 if (i
== HSO_MAX_NET_DEVICES
)
2362 /* Frees our network device */
2363 static void hso_free_net_device(struct hso_device
*hso_dev
)
2366 struct hso_net
*hso_net
= dev2net(hso_dev
);
2371 remove_net_device(hso_net
->parent
);
2374 unregister_netdev(hso_net
->net
);
2377 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2378 usb_free_urb(hso_net
->mux_bulk_rx_urb_pool
[i
]);
2379 kfree(hso_net
->mux_bulk_rx_buf_pool
[i
]);
2380 hso_net
->mux_bulk_rx_buf_pool
[i
] = NULL
;
2382 usb_free_urb(hso_net
->mux_bulk_tx_urb
);
2383 kfree(hso_net
->mux_bulk_tx_buf
);
2384 hso_net
->mux_bulk_tx_buf
= NULL
;
2387 free_netdev(hso_net
->net
);
2392 static const struct net_device_ops hso_netdev_ops
= {
2393 .ndo_open
= hso_net_open
,
2394 .ndo_stop
= hso_net_close
,
2395 .ndo_start_xmit
= hso_net_start_xmit
,
2396 .ndo_tx_timeout
= hso_net_tx_timeout
,
2399 /* initialize the network interface */
2400 static void hso_net_init(struct net_device
*net
)
2402 struct hso_net
*hso_net
= netdev_priv(net
);
2404 D1("sizeof hso_net is %d", (int)sizeof(*hso_net
));
2406 /* fill in the other fields */
2407 net
->netdev_ops
= &hso_netdev_ops
;
2408 net
->watchdog_timeo
= HSO_NET_TX_TIMEOUT
;
2409 net
->flags
= IFF_POINTOPOINT
| IFF_NOARP
| IFF_MULTICAST
;
2410 net
->type
= ARPHRD_NONE
;
2411 net
->mtu
= DEFAULT_MTU
- 14;
2412 net
->tx_queue_len
= 10;
2413 net
->ethtool_ops
= &ops
;
2415 /* and initialize the semaphore */
2416 spin_lock_init(&hso_net
->net_lock
);
2419 /* Adds a network device in the network device table */
2420 static int add_net_device(struct hso_device
*hso_dev
)
2424 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
2425 if (network_table
[i
] == NULL
) {
2426 network_table
[i
] = hso_dev
;
2430 if (i
== HSO_MAX_NET_DEVICES
)
2435 static int hso_rfkill_set_block(void *data
, bool blocked
)
2437 struct hso_device
*hso_dev
= data
;
2438 int enabled
= !blocked
;
2441 mutex_lock(&hso_dev
->mutex
);
2442 if (hso_dev
->usb_gone
)
2445 rv
= usb_control_msg(hso_dev
->usb
, usb_rcvctrlpipe(hso_dev
->usb
, 0),
2446 enabled
? 0x82 : 0x81, 0x40, 0, 0, NULL
, 0,
2447 USB_CTRL_SET_TIMEOUT
);
2448 mutex_unlock(&hso_dev
->mutex
);
2452 static const struct rfkill_ops hso_rfkill_ops
= {
2453 .set_block
= hso_rfkill_set_block
,
2456 /* Creates and sets up everything for rfkill */
2457 static void hso_create_rfkill(struct hso_device
*hso_dev
,
2458 struct usb_interface
*interface
)
2460 struct hso_net
*hso_net
= dev2net(hso_dev
);
2461 struct device
*dev
= &hso_net
->net
->dev
;
2464 rfkn
= kzalloc(20, GFP_KERNEL
);
2466 dev_err(dev
, "%s - Out of memory\n", __func__
);
2468 snprintf(rfkn
, 20, "hso-%d",
2469 interface
->altsetting
->desc
.bInterfaceNumber
);
2471 hso_net
->rfkill
= rfkill_alloc(rfkn
,
2472 &interface_to_usbdev(interface
)->dev
,
2474 &hso_rfkill_ops
, hso_dev
);
2475 if (!hso_net
->rfkill
) {
2476 dev_err(dev
, "%s - Out of memory\n", __func__
);
2480 if (rfkill_register(hso_net
->rfkill
) < 0) {
2481 rfkill_destroy(hso_net
->rfkill
);
2483 hso_net
->rfkill
= NULL
;
2484 dev_err(dev
, "%s - Failed to register rfkill\n", __func__
);
2489 static struct device_type hso_type
= {
2493 /* Creates our network device */
2494 static struct hso_device
*hso_create_net_device(struct usb_interface
*interface
,
2498 struct net_device
*net
;
2499 struct hso_net
*hso_net
;
2500 struct hso_device
*hso_dev
;
2502 hso_dev
= hso_create_device(interface
, port_spec
);
2506 /* allocate our network device, then we can put in our private data */
2507 /* call hso_net_init to do the basic initialization */
2508 net
= alloc_netdev(sizeof(struct hso_net
), "hso%d", NET_NAME_UNKNOWN
,
2511 dev_err(&interface
->dev
, "Unable to create ethernet device\n");
2515 hso_net
= netdev_priv(net
);
2517 hso_dev
->port_data
.dev_net
= hso_net
;
2519 hso_net
->parent
= hso_dev
;
2521 hso_net
->in_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2523 if (!hso_net
->in_endp
) {
2524 dev_err(&interface
->dev
, "Can't find BULK IN endpoint\n");
2527 hso_net
->out_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2529 if (!hso_net
->out_endp
) {
2530 dev_err(&interface
->dev
, "Can't find BULK OUT endpoint\n");
2533 SET_NETDEV_DEV(net
, &interface
->dev
);
2534 SET_NETDEV_DEVTYPE(net
, &hso_type
);
2536 /* registering our net device */
2537 result
= register_netdev(net
);
2539 dev_err(&interface
->dev
, "Failed to register device\n");
2543 /* start allocating */
2544 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2545 hso_net
->mux_bulk_rx_urb_pool
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
2546 if (!hso_net
->mux_bulk_rx_urb_pool
[i
]) {
2547 dev_err(&interface
->dev
, "Could not allocate rx urb\n");
2550 hso_net
->mux_bulk_rx_buf_pool
[i
] = kzalloc(MUX_BULK_RX_BUF_SIZE
,
2552 if (!hso_net
->mux_bulk_rx_buf_pool
[i
])
2555 hso_net
->mux_bulk_tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2556 if (!hso_net
->mux_bulk_tx_urb
) {
2557 dev_err(&interface
->dev
, "Could not allocate tx urb\n");
2560 hso_net
->mux_bulk_tx_buf
= kzalloc(MUX_BULK_TX_BUF_SIZE
, GFP_KERNEL
);
2561 if (!hso_net
->mux_bulk_tx_buf
)
2564 add_net_device(hso_dev
);
2566 hso_log_port(hso_dev
);
2568 hso_create_rfkill(hso_dev
, interface
);
2572 hso_free_net_device(hso_dev
);
2576 static void hso_free_tiomget(struct hso_serial
*serial
)
2578 struct hso_tiocmget
*tiocmget
;
2581 tiocmget
= serial
->tiocmget
;
2583 usb_free_urb(tiocmget
->urb
);
2584 tiocmget
->urb
= NULL
;
2585 serial
->tiocmget
= NULL
;
2590 /* Frees an AT channel ( goes for both mux and non-mux ) */
2591 static void hso_free_serial_device(struct hso_device
*hso_dev
)
2593 struct hso_serial
*serial
= dev2ser(hso_dev
);
2597 set_serial_by_index(serial
->minor
, NULL
);
2599 hso_serial_common_free(serial
);
2601 if (serial
->shared_int
) {
2602 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2603 if (--serial
->shared_int
->ref_count
== 0)
2604 hso_free_shared_int(serial
->shared_int
);
2606 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2608 hso_free_tiomget(serial
);
2613 /* Creates a bulk AT channel */
2614 static struct hso_device
*hso_create_bulk_serial_device(
2615 struct usb_interface
*interface
, int port
)
2617 struct hso_device
*hso_dev
;
2618 struct hso_serial
*serial
;
2620 struct hso_tiocmget
*tiocmget
;
2622 hso_dev
= hso_create_device(interface
, port
);
2626 serial
= kzalloc(sizeof(*serial
), GFP_KERNEL
);
2630 serial
->parent
= hso_dev
;
2631 hso_dev
->port_data
.dev_serial
= serial
;
2633 if ((port
& HSO_PORT_MASK
) == HSO_PORT_MODEM
) {
2635 serial
->tiocmget
= kzalloc(sizeof(struct hso_tiocmget
),
2637 /* it isn't going to break our heart if serial->tiocmget
2638 * allocation fails don't bother checking this.
2640 if (serial
->tiocmget
) {
2641 tiocmget
= serial
->tiocmget
;
2642 tiocmget
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
2643 if (tiocmget
->urb
) {
2644 mutex_init(&tiocmget
->mutex
);
2645 init_waitqueue_head(&tiocmget
->waitq
);
2646 tiocmget
->endp
= hso_get_ep(
2648 USB_ENDPOINT_XFER_INT
,
2651 hso_free_tiomget(serial
);
2657 if (hso_serial_common_create(serial
, num_urbs
, BULK_URB_RX_SIZE
,
2661 serial
->in_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2663 if (!serial
->in_endp
) {
2664 dev_err(&interface
->dev
, "Failed to find BULK IN ep\n");
2670 hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
, USB_DIR_OUT
))) {
2671 dev_err(&interface
->dev
, "Failed to find BULK IN ep\n");
2675 serial
->write_data
= hso_std_serial_write_data
;
2677 /* and record this serial */
2678 set_serial_by_index(serial
->minor
, serial
);
2680 /* setup the proc dirs and files if needed */
2681 hso_log_port(hso_dev
);
2683 /* done, return it */
2687 hso_serial_common_free(serial
);
2689 hso_free_tiomget(serial
);
2695 /* Creates a multiplexed AT channel */
2697 struct hso_device
*hso_create_mux_serial_device(struct usb_interface
*interface
,
2699 struct hso_shared_int
*mux
)
2701 struct hso_device
*hso_dev
;
2702 struct hso_serial
*serial
;
2705 port_spec
= HSO_INTF_MUX
;
2706 port_spec
&= ~HSO_PORT_MASK
;
2708 port_spec
|= hso_mux_to_port(port
);
2709 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NO_PORT
)
2712 hso_dev
= hso_create_device(interface
, port_spec
);
2716 serial
= kzalloc(sizeof(*serial
), GFP_KERNEL
);
2720 hso_dev
->port_data
.dev_serial
= serial
;
2721 serial
->parent
= hso_dev
;
2723 if (hso_serial_common_create
2724 (serial
, 1, CTRL_URB_RX_SIZE
, CTRL_URB_TX_SIZE
))
2727 serial
->tx_data_length
--;
2728 serial
->write_data
= hso_mux_serial_write_data
;
2730 serial
->shared_int
= mux
;
2731 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2732 serial
->shared_int
->ref_count
++;
2733 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2735 /* and record this serial */
2736 set_serial_by_index(serial
->minor
, serial
);
2738 /* setup the proc dirs and files if needed */
2739 hso_log_port(hso_dev
);
2741 /* done, return it */
2746 tty_unregister_device(tty_drv
, serial
->minor
);
2755 static void hso_free_shared_int(struct hso_shared_int
*mux
)
2757 usb_free_urb(mux
->shared_intr_urb
);
2758 kfree(mux
->shared_intr_buf
);
2759 mutex_unlock(&mux
->shared_int_lock
);
2764 struct hso_shared_int
*hso_create_shared_int(struct usb_interface
*interface
)
2766 struct hso_shared_int
*mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
2771 mux
->intr_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_INT
,
2773 if (!mux
->intr_endp
) {
2774 dev_err(&interface
->dev
, "Can't find INT IN endpoint\n");
2778 mux
->shared_intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2779 if (!mux
->shared_intr_urb
) {
2780 dev_err(&interface
->dev
, "Could not allocate intr urb?\n");
2783 mux
->shared_intr_buf
=
2784 kzalloc(le16_to_cpu(mux
->intr_endp
->wMaxPacketSize
),
2786 if (!mux
->shared_intr_buf
)
2789 mutex_init(&mux
->shared_int_lock
);
2794 kfree(mux
->shared_intr_buf
);
2795 usb_free_urb(mux
->shared_intr_urb
);
2800 /* Gets the port spec for a certain interface */
2801 static int hso_get_config_data(struct usb_interface
*interface
)
2803 struct usb_device
*usbdev
= interface_to_usbdev(interface
);
2804 u8
*config_data
= kmalloc(17, GFP_KERNEL
);
2805 u32 if_num
= interface
->altsetting
->desc
.bInterfaceNumber
;
2810 if (usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0),
2811 0x86, 0xC0, 0, 0, config_data
, 17,
2812 USB_CTRL_SET_TIMEOUT
) != 0x11) {
2817 switch (config_data
[if_num
]) {
2822 result
= HSO_PORT_DIAG
;
2825 result
= HSO_PORT_GPS
;
2828 result
= HSO_PORT_GPS_CONTROL
;
2831 result
= HSO_PORT_APP
;
2834 result
= HSO_PORT_APP2
;
2837 result
= HSO_PORT_CONTROL
;
2840 result
= HSO_PORT_NETWORK
;
2843 result
= HSO_PORT_MODEM
;
2846 result
= HSO_PORT_MSD
;
2849 result
= HSO_PORT_PCSC
;
2852 result
= HSO_PORT_VOICE
;
2859 result
|= HSO_INTF_BULK
;
2861 if (config_data
[16] & 0x1)
2862 result
|= HSO_INFO_CRC_BUG
;
2868 /* called once for each interface upon device insertion */
2869 static int hso_probe(struct usb_interface
*interface
,
2870 const struct usb_device_id
*id
)
2872 int mux
, i
, if_num
, port_spec
;
2873 unsigned char port_mask
;
2874 struct hso_device
*hso_dev
= NULL
;
2875 struct hso_shared_int
*shared_int
;
2876 struct hso_device
*tmp_dev
= NULL
;
2878 if (interface
->cur_altsetting
->desc
.bInterfaceClass
!= 0xFF) {
2879 dev_err(&interface
->dev
, "Not our interface\n");
2883 if_num
= interface
->altsetting
->desc
.bInterfaceNumber
;
2885 /* Get the interface/port specification from either driver_info or from
2886 * the device itself */
2887 if (id
->driver_info
)
2888 port_spec
= ((u32
*)(id
->driver_info
))[if_num
];
2890 port_spec
= hso_get_config_data(interface
);
2892 /* Check if we need to switch to alt interfaces prior to port
2894 if (interface
->num_altsetting
> 1)
2895 usb_set_interface(interface_to_usbdev(interface
), if_num
, 1);
2896 interface
->needs_remote_wakeup
= 1;
2898 /* Allocate new hso device(s) */
2899 switch (port_spec
& HSO_INTF_MASK
) {
2901 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2902 /* Create the network device */
2904 hso_dev
= hso_create_net_device(interface
,
2912 if (hso_get_mux_ports(interface
, &port_mask
))
2913 /* TODO: de-allocate everything */
2916 shared_int
= hso_create_shared_int(interface
);
2920 for (i
= 1, mux
= 0; i
< 0x100; i
= i
<< 1, mux
++) {
2921 if (port_mask
& i
) {
2922 hso_dev
= hso_create_mux_serial_device(
2923 interface
, i
, shared_int
);
2934 /* It's a regular bulk interface */
2935 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2938 hso_create_net_device(interface
, port_spec
);
2941 hso_create_bulk_serial_device(interface
, port_spec
);
2950 /* save our data pointer in this device */
2951 usb_set_intfdata(interface
, hso_dev
);
2956 hso_free_interface(interface
);
2960 /* device removed, cleaning up */
2961 static void hso_disconnect(struct usb_interface
*interface
)
2963 hso_free_interface(interface
);
2965 /* remove reference of our private data */
2966 usb_set_intfdata(interface
, NULL
);
2969 static void async_get_intf(struct work_struct
*data
)
2971 struct hso_device
*hso_dev
=
2972 container_of(data
, struct hso_device
, async_get_intf
);
2973 usb_autopm_get_interface(hso_dev
->interface
);
2976 static void async_put_intf(struct work_struct
*data
)
2978 struct hso_device
*hso_dev
=
2979 container_of(data
, struct hso_device
, async_put_intf
);
2980 usb_autopm_put_interface(hso_dev
->interface
);
2983 static int hso_get_activity(struct hso_device
*hso_dev
)
2985 if (hso_dev
->usb
->state
== USB_STATE_SUSPENDED
) {
2986 if (!hso_dev
->is_active
) {
2987 hso_dev
->is_active
= 1;
2988 schedule_work(&hso_dev
->async_get_intf
);
2992 if (hso_dev
->usb
->state
!= USB_STATE_CONFIGURED
)
2995 usb_mark_last_busy(hso_dev
->usb
);
3000 static int hso_put_activity(struct hso_device
*hso_dev
)
3002 if (hso_dev
->usb
->state
!= USB_STATE_SUSPENDED
) {
3003 if (hso_dev
->is_active
) {
3004 hso_dev
->is_active
= 0;
3005 schedule_work(&hso_dev
->async_put_intf
);
3009 hso_dev
->is_active
= 0;
3013 /* called by kernel when we need to suspend device */
3014 static int hso_suspend(struct usb_interface
*iface
, pm_message_t message
)
3018 /* Stop all serial ports */
3019 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3020 if (serial_table
[i
] && (serial_table
[i
]->interface
== iface
)) {
3021 result
= hso_stop_serial_device(serial_table
[i
]);
3027 /* Stop all network ports */
3028 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3029 if (network_table
[i
] &&
3030 (network_table
[i
]->interface
== iface
)) {
3031 result
= hso_stop_net_device(network_table
[i
]);
3041 /* called by kernel when we need to resume device */
3042 static int hso_resume(struct usb_interface
*iface
)
3045 struct hso_net
*hso_net
;
3047 /* Start all serial ports */
3048 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3049 if (serial_table
[i
] && (serial_table
[i
]->interface
== iface
)) {
3050 if (dev2ser(serial_table
[i
])->port
.count
) {
3052 hso_start_serial_device(serial_table
[i
], GFP_NOIO
);
3053 hso_kick_transmit(dev2ser(serial_table
[i
]));
3060 /* Start all network ports */
3061 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3062 if (network_table
[i
] &&
3063 (network_table
[i
]->interface
== iface
)) {
3064 hso_net
= dev2net(network_table
[i
]);
3065 if (hso_net
->flags
& IFF_UP
) {
3066 /* First transmit any lingering data,
3067 then restart the device. */
3068 if (hso_net
->skb_tx_buf
) {
3069 dev_dbg(&iface
->dev
,
3071 " lingering data\n");
3072 hso_net_start_xmit(hso_net
->skb_tx_buf
,
3074 hso_net
->skb_tx_buf
= NULL
;
3076 result
= hso_start_net_device(network_table
[i
]);
3087 static void reset_device(struct work_struct
*data
)
3089 struct hso_device
*hso_dev
=
3090 container_of(data
, struct hso_device
, reset_device
);
3091 struct usb_device
*usb
= hso_dev
->usb
;
3094 if (hso_dev
->usb_gone
) {
3095 D1("No reset during disconnect\n");
3097 result
= usb_lock_device_for_reset(usb
, hso_dev
->interface
);
3099 D1("unable to lock device for reset: %d\n", result
);
3101 usb_reset_device(usb
);
3102 usb_unlock_device(usb
);
3107 static void hso_serial_ref_free(struct kref
*ref
)
3109 struct hso_device
*hso_dev
= container_of(ref
, struct hso_device
, ref
);
3111 hso_free_serial_device(hso_dev
);
3114 static void hso_free_interface(struct usb_interface
*interface
)
3116 struct hso_serial
*hso_dev
;
3119 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3120 if (serial_table
[i
] &&
3121 (serial_table
[i
]->interface
== interface
)) {
3122 hso_dev
= dev2ser(serial_table
[i
]);
3123 tty_port_tty_hangup(&hso_dev
->port
, false);
3124 mutex_lock(&hso_dev
->parent
->mutex
);
3125 hso_dev
->parent
->usb_gone
= 1;
3126 mutex_unlock(&hso_dev
->parent
->mutex
);
3127 kref_put(&serial_table
[i
]->ref
, hso_serial_ref_free
);
3131 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3132 if (network_table
[i
] &&
3133 (network_table
[i
]->interface
== interface
)) {
3134 struct rfkill
*rfk
= dev2net(network_table
[i
])->rfkill
;
3135 /* hso_stop_net_device doesn't stop the net queue since
3136 * traffic needs to start it again when suspended */
3137 netif_stop_queue(dev2net(network_table
[i
])->net
);
3138 hso_stop_net_device(network_table
[i
]);
3139 cancel_work_sync(&network_table
[i
]->async_put_intf
);
3140 cancel_work_sync(&network_table
[i
]->async_get_intf
);
3142 rfkill_unregister(rfk
);
3143 rfkill_destroy(rfk
);
3145 hso_free_net_device(network_table
[i
]);
3150 /* Helper functions */
3152 /* Get the endpoint ! */
3153 static struct usb_endpoint_descriptor
*hso_get_ep(struct usb_interface
*intf
,
3157 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
3158 struct usb_endpoint_descriptor
*endp
;
3160 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
3161 endp
= &iface
->endpoint
[i
].desc
;
3162 if (((endp
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == dir
) &&
3163 (usb_endpoint_type(endp
) == type
))
3170 /* Get the byte that describes which ports are enabled */
3171 static int hso_get_mux_ports(struct usb_interface
*intf
, unsigned char *ports
)
3174 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
3176 if (iface
->extralen
== 3) {
3177 *ports
= iface
->extra
[2];
3181 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
3182 if (iface
->endpoint
[i
].extralen
== 3) {
3183 *ports
= iface
->endpoint
[i
].extra
[2];
3191 /* interrupt urb needs to be submitted, used for serial read of muxed port */
3192 static int hso_mux_submit_intr_urb(struct hso_shared_int
*shared_int
,
3193 struct usb_device
*usb
, gfp_t gfp
)
3197 usb_fill_int_urb(shared_int
->shared_intr_urb
, usb
,
3199 shared_int
->intr_endp
->bEndpointAddress
& 0x7F),
3200 shared_int
->shared_intr_buf
,
3202 intr_callback
, shared_int
,
3203 shared_int
->intr_endp
->bInterval
);
3205 result
= usb_submit_urb(shared_int
->shared_intr_urb
, gfp
);
3207 dev_warn(&usb
->dev
, "%s failed mux_intr_urb %d\n", __func__
,
3213 /* operations setup of the serial interface */
3214 static const struct tty_operations hso_serial_ops
= {
3215 .open
= hso_serial_open
,
3216 .close
= hso_serial_close
,
3217 .write
= hso_serial_write
,
3218 .write_room
= hso_serial_write_room
,
3219 .ioctl
= hso_serial_ioctl
,
3220 .set_termios
= hso_serial_set_termios
,
3221 .chars_in_buffer
= hso_serial_chars_in_buffer
,
3222 .tiocmget
= hso_serial_tiocmget
,
3223 .tiocmset
= hso_serial_tiocmset
,
3224 .get_icount
= hso_get_count
,
3225 .unthrottle
= hso_unthrottle
3228 static struct usb_driver hso_driver
= {
3229 .name
= driver_name
,
3231 .disconnect
= hso_disconnect
,
3232 .id_table
= hso_ids
,
3233 .suspend
= hso_suspend
,
3234 .resume
= hso_resume
,
3235 .reset_resume
= hso_resume
,
3236 .supports_autosuspend
= 1,
3237 .disable_hub_initiated_lpm
= 1,
3240 static int __init
hso_init(void)
3245 /* put it in the log */
3246 printk(KERN_INFO
"hso: %s\n", version
);
3248 /* Initialise the serial table semaphore and table */
3249 spin_lock_init(&serial_table_lock
);
3250 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++)
3251 serial_table
[i
] = NULL
;
3253 /* allocate our driver using the proper amount of supported minors */
3254 tty_drv
= alloc_tty_driver(HSO_SERIAL_TTY_MINORS
);
3258 /* fill in all needed values */
3259 tty_drv
->driver_name
= driver_name
;
3260 tty_drv
->name
= tty_filename
;
3262 /* if major number is provided as parameter, use that one */
3264 tty_drv
->major
= tty_major
;
3266 tty_drv
->minor_start
= 0;
3267 tty_drv
->type
= TTY_DRIVER_TYPE_SERIAL
;
3268 tty_drv
->subtype
= SERIAL_TYPE_NORMAL
;
3269 tty_drv
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
3270 tty_drv
->init_termios
= tty_std_termios
;
3271 hso_init_termios(&tty_drv
->init_termios
);
3272 tty_set_operations(tty_drv
, &hso_serial_ops
);
3274 /* register the tty driver */
3275 result
= tty_register_driver(tty_drv
);
3277 printk(KERN_ERR
"%s - tty_register_driver failed(%d)\n",
3282 /* register this module as an usb driver */
3283 result
= usb_register(&hso_driver
);
3285 printk(KERN_ERR
"Could not register hso driver? error: %d\n",
3293 tty_unregister_driver(tty_drv
);
3295 put_tty_driver(tty_drv
);
3299 static void __exit
hso_exit(void)
3301 printk(KERN_INFO
"hso: unloaded\n");
3303 tty_unregister_driver(tty_drv
);
3304 put_tty_driver(tty_drv
);
3305 /* deregister the usb driver */
3306 usb_deregister(&hso_driver
);
3309 /* Module definitions */
3310 module_init(hso_init
);
3311 module_exit(hso_exit
);
3313 MODULE_AUTHOR(MOD_AUTHOR
);
3314 MODULE_DESCRIPTION(MOD_DESCRIPTION
);
3315 MODULE_LICENSE(MOD_LICENSE
);
3317 /* change the debug level (eg: insmod hso.ko debug=0x04) */
3318 MODULE_PARM_DESC(debug
, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]");
3319 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
3321 /* set the major tty number (eg: insmod hso.ko tty_major=245) */
3322 MODULE_PARM_DESC(tty_major
, "Set the major tty number");
3323 module_param(tty_major
, int, S_IRUGO
| S_IWUSR
);
3325 /* disable network interface (eg: insmod hso.ko disable_net=1) */
3326 MODULE_PARM_DESC(disable_net
, "Disable the network interface");
3327 module_param(disable_net
, int, S_IRUGO
| S_IWUSR
);