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/tty.h>
62 #include <linux/tty_driver.h>
63 #include <linux/tty_flip.h>
64 #include <linux/kmod.h>
65 #include <linux/rfkill.h>
67 #include <linux/uaccess.h>
68 #include <linux/usb/cdc.h>
70 #include <asm/byteorder.h>
71 #include <linux/serial_core.h>
72 #include <linux/serial.h>
75 #define MOD_AUTHOR "Option Wireless"
76 #define MOD_DESCRIPTION "USB High Speed Option driver"
77 #define MOD_LICENSE "GPL"
79 #define HSO_MAX_NET_DEVICES 10
80 #define HSO__MAX_MTU 2048
81 #define DEFAULT_MTU 1500
82 #define DEFAULT_MRU 1500
84 #define CTRL_URB_RX_SIZE 1024
85 #define CTRL_URB_TX_SIZE 64
87 #define BULK_URB_RX_SIZE 4096
88 #define BULK_URB_TX_SIZE 8192
90 #define MUX_BULK_RX_BUF_SIZE HSO__MAX_MTU
91 #define MUX_BULK_TX_BUF_SIZE HSO__MAX_MTU
92 #define MUX_BULK_RX_BUF_COUNT 4
93 #define USB_TYPE_OPTION_VENDOR 0x20
95 /* These definitions are used with the struct hso_net flags element */
96 /* - use *_bit operations on it. (bit indices not values.) */
97 #define HSO_NET_RUNNING 0
99 #define HSO_NET_TX_TIMEOUT (HZ*10)
101 #define HSO_SERIAL_MAGIC 0x48534f31
103 /* Number of ttys to handle */
104 #define HSO_SERIAL_TTY_MINORS 256
106 #define MAX_RX_URBS 2
108 /*****************************************************************************/
109 /* Debugging functions */
110 /*****************************************************************************/
111 #define D__(lvl_, fmt, arg...) \
113 printk(lvl_ "[%d:%s]: " fmt "\n", \
114 __LINE__, __func__, ## arg); \
117 #define D_(lvl, args...) \
120 D__(KERN_INFO, args); \
123 #define D1(args...) D_(0x01, ##args)
124 #define D2(args...) D_(0x02, ##args)
125 #define D3(args...) D_(0x04, ##args)
126 #define D4(args...) D_(0x08, ##args)
127 #define D5(args...) D_(0x10, ##args)
129 /*****************************************************************************/
131 /*****************************************************************************/
132 enum pkt_parse_state
{
138 /*****************************************************************************/
140 /*****************************************************************************/
142 struct hso_shared_int
{
143 struct usb_endpoint_descriptor
*intr_endp
;
144 void *shared_intr_buf
;
145 struct urb
*shared_intr_urb
;
146 struct usb_device
*usb
;
149 struct mutex shared_int_lock
;
153 struct hso_device
*parent
;
154 struct net_device
*net
;
155 struct rfkill
*rfkill
;
157 struct usb_endpoint_descriptor
*in_endp
;
158 struct usb_endpoint_descriptor
*out_endp
;
160 struct urb
*mux_bulk_rx_urb_pool
[MUX_BULK_RX_BUF_COUNT
];
161 struct urb
*mux_bulk_tx_urb
;
162 void *mux_bulk_rx_buf_pool
[MUX_BULK_RX_BUF_COUNT
];
163 void *mux_bulk_tx_buf
;
165 struct sk_buff
*skb_rx_buf
;
166 struct sk_buff
*skb_tx_buf
;
168 enum pkt_parse_state rx_parse_state
;
171 unsigned short rx_buf_size
;
172 unsigned short rx_buf_missing
;
173 struct iphdr rx_ip_hdr
;
184 #define BM_REQUEST_TYPE (0xa1)
185 #define B_NOTIFICATION (0x20)
186 #define W_VALUE (0x0)
187 #define W_LENGTH (0x2)
189 #define B_OVERRUN (0x1<<6)
190 #define B_PARITY (0x1<<5)
191 #define B_FRAMING (0x1<<4)
192 #define B_RING_SIGNAL (0x1<<3)
193 #define B_BREAK (0x1<<2)
194 #define B_TX_CARRIER (0x1<<1)
195 #define B_RX_CARRIER (0x1<<0)
197 struct hso_serial_state_notification
{
203 u16 UART_state_bitmap
;
206 struct hso_tiocmget
{
208 wait_queue_head_t waitq
;
210 struct usb_endpoint_descriptor
*endp
;
212 struct hso_serial_state_notification serial_state_notification
;
213 u16 prev_UART_state_bitmap
;
214 struct uart_icount icount
;
219 struct hso_device
*parent
;
223 struct hso_shared_int
*shared_int
;
225 /* rx/tx urb could be either a bulk urb or a control urb depending
226 on which serial port it is used on. */
227 struct urb
*rx_urb
[MAX_RX_URBS
];
229 u8
*rx_data
[MAX_RX_URBS
];
230 u16 rx_data_length
; /* should contain allocated length */
235 u16 tx_data_length
; /* should contain allocated length */
238 struct usb_ctrlrequest ctrl_req_tx
;
239 struct usb_ctrlrequest ctrl_req_rx
;
241 struct usb_endpoint_descriptor
*in_endp
;
242 struct usb_endpoint_descriptor
*out_endp
;
244 enum rx_ctrl_state rx_state
;
247 unsigned tx_urb_used
:1;
249 struct tty_port port
;
250 /* from usb_serial_port */
251 spinlock_t serial_lock
;
253 int (*write_data
) (struct hso_serial
*serial
);
254 struct hso_tiocmget
*tiocmget
;
255 /* Hacks required to get flow control
256 * working on the serial receive buffers
257 * so as not to drop characters on the floor.
260 u8 rx_urb_filled
[MAX_RX_URBS
];
261 struct tasklet_struct unthrottle_tasklet
;
266 struct hso_serial
*dev_serial
;
267 struct hso_net
*dev_net
;
274 struct work_struct async_get_intf
;
275 struct work_struct async_put_intf
;
276 struct work_struct reset_device
;
278 struct usb_device
*usb
;
279 struct usb_interface
*interface
;
286 /* Type of interface */
287 #define HSO_INTF_MASK 0xFF00
288 #define HSO_INTF_MUX 0x0100
289 #define HSO_INTF_BULK 0x0200
292 #define HSO_PORT_MASK 0xFF
293 #define HSO_PORT_NO_PORT 0x0
294 #define HSO_PORT_CONTROL 0x1
295 #define HSO_PORT_APP 0x2
296 #define HSO_PORT_GPS 0x3
297 #define HSO_PORT_PCSC 0x4
298 #define HSO_PORT_APP2 0x5
299 #define HSO_PORT_GPS_CONTROL 0x6
300 #define HSO_PORT_MSD 0x7
301 #define HSO_PORT_VOICE 0x8
302 #define HSO_PORT_DIAG2 0x9
303 #define HSO_PORT_DIAG 0x10
304 #define HSO_PORT_MODEM 0x11
305 #define HSO_PORT_NETWORK 0x12
307 /* Additional device info */
308 #define HSO_INFO_MASK 0xFF000000
309 #define HSO_INFO_CRC_BUG 0x01000000
311 /*****************************************************************************/
313 /*****************************************************************************/
314 /* Serial driver functions */
315 static int hso_serial_tiocmset(struct tty_struct
*tty
,
316 unsigned int set
, unsigned int clear
);
317 static void ctrl_callback(struct urb
*urb
);
318 static int put_rxbuf_data(struct urb
*urb
, struct hso_serial
*serial
);
319 static void hso_kick_transmit(struct hso_serial
*serial
);
320 /* Helper functions */
321 static int hso_mux_submit_intr_urb(struct hso_shared_int
*mux_int
,
322 struct usb_device
*usb
, gfp_t gfp
);
323 static void handle_usb_error(int status
, const char *function
,
324 struct hso_device
*hso_dev
);
325 static struct usb_endpoint_descriptor
*hso_get_ep(struct usb_interface
*intf
,
327 static int hso_get_mux_ports(struct usb_interface
*intf
, unsigned char *ports
);
328 static void hso_free_interface(struct usb_interface
*intf
);
329 static int hso_start_serial_device(struct hso_device
*hso_dev
, gfp_t flags
);
330 static int hso_stop_serial_device(struct hso_device
*hso_dev
);
331 static int hso_start_net_device(struct hso_device
*hso_dev
);
332 static void hso_free_shared_int(struct hso_shared_int
*shared_int
);
333 static int hso_stop_net_device(struct hso_device
*hso_dev
);
334 static void hso_serial_ref_free(struct kref
*ref
);
335 static void hso_std_serial_read_bulk_callback(struct urb
*urb
);
336 static int hso_mux_serial_read(struct hso_serial
*serial
);
337 static void async_get_intf(struct work_struct
*data
);
338 static void async_put_intf(struct work_struct
*data
);
339 static int hso_put_activity(struct hso_device
*hso_dev
);
340 static int hso_get_activity(struct hso_device
*hso_dev
);
341 static void tiocmget_intr_callback(struct urb
*urb
);
342 static void reset_device(struct work_struct
*data
);
343 /*****************************************************************************/
344 /* Helping functions */
345 /*****************************************************************************/
349 static inline struct hso_net
*dev2net(struct hso_device
*hso_dev
)
351 return hso_dev
->port_data
.dev_net
;
354 static inline struct hso_serial
*dev2ser(struct hso_device
*hso_dev
)
356 return hso_dev
->port_data
.dev_serial
;
359 /* Debugging functions */
361 static void dbg_dump(int line_count
, const char *func_name
, unsigned char *buf
,
364 static char name
[255];
366 sprintf(name
, "hso[%d:%s]", line_count
, func_name
);
367 print_hex_dump_bytes(name
, DUMP_PREFIX_NONE
, buf
, len
);
370 #define DUMP(buf_, len_) \
371 dbg_dump(__LINE__, __func__, (unsigned char *)buf_, len_)
373 #define DUMP1(buf_, len_) \
379 #define DUMP(buf_, len_)
380 #define DUMP1(buf_, len_)
383 /* module parameters */
385 static int tty_major
;
386 static int disable_net
;
389 static const char driver_name
[] = "hso";
390 static const char tty_filename
[] = "ttyHS";
391 static const char *version
= __FILE__
": " MOD_AUTHOR
;
392 /* the usb driver itself (registered in hso_init) */
393 static struct usb_driver hso_driver
;
394 /* serial structures */
395 static struct tty_driver
*tty_drv
;
396 static struct hso_device
*serial_table
[HSO_SERIAL_TTY_MINORS
];
397 static struct hso_device
*network_table
[HSO_MAX_NET_DEVICES
];
398 static spinlock_t serial_table_lock
;
400 static const s32 default_port_spec
[] = {
401 HSO_INTF_MUX
| HSO_PORT_NETWORK
,
402 HSO_INTF_BULK
| HSO_PORT_DIAG
,
403 HSO_INTF_BULK
| HSO_PORT_MODEM
,
407 static const s32 icon321_port_spec
[] = {
408 HSO_INTF_MUX
| HSO_PORT_NETWORK
,
409 HSO_INTF_BULK
| HSO_PORT_DIAG2
,
410 HSO_INTF_BULK
| HSO_PORT_MODEM
,
411 HSO_INTF_BULK
| HSO_PORT_DIAG
,
415 #define default_port_device(vendor, product) \
416 USB_DEVICE(vendor, product), \
417 .driver_info = (kernel_ulong_t)default_port_spec
419 #define icon321_port_device(vendor, product) \
420 USB_DEVICE(vendor, product), \
421 .driver_info = (kernel_ulong_t)icon321_port_spec
423 /* list of devices we support */
424 static const struct usb_device_id hso_ids
[] = {
425 {default_port_device(0x0af0, 0x6711)},
426 {default_port_device(0x0af0, 0x6731)},
427 {default_port_device(0x0af0, 0x6751)},
428 {default_port_device(0x0af0, 0x6771)},
429 {default_port_device(0x0af0, 0x6791)},
430 {default_port_device(0x0af0, 0x6811)},
431 {default_port_device(0x0af0, 0x6911)},
432 {default_port_device(0x0af0, 0x6951)},
433 {default_port_device(0x0af0, 0x6971)},
434 {default_port_device(0x0af0, 0x7011)},
435 {default_port_device(0x0af0, 0x7031)},
436 {default_port_device(0x0af0, 0x7051)},
437 {default_port_device(0x0af0, 0x7071)},
438 {default_port_device(0x0af0, 0x7111)},
439 {default_port_device(0x0af0, 0x7211)},
440 {default_port_device(0x0af0, 0x7251)},
441 {default_port_device(0x0af0, 0x7271)},
442 {default_port_device(0x0af0, 0x7311)},
443 {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
444 {icon321_port_device(0x0af0, 0xd013)}, /* Module HSxPA */
445 {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
446 {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */
447 {USB_DEVICE(0x0af0, 0x7301)}, /* GE40x */
448 {USB_DEVICE(0x0af0, 0x7361)}, /* GE40x */
449 {USB_DEVICE(0x0af0, 0x7381)}, /* GE40x */
450 {USB_DEVICE(0x0af0, 0x7401)}, /* GI 0401 */
451 {USB_DEVICE(0x0af0, 0x7501)}, /* GTM 382 */
452 {USB_DEVICE(0x0af0, 0x7601)}, /* GE40x */
453 {USB_DEVICE(0x0af0, 0x7701)},
454 {USB_DEVICE(0x0af0, 0x7706)},
455 {USB_DEVICE(0x0af0, 0x7801)},
456 {USB_DEVICE(0x0af0, 0x7901)},
457 {USB_DEVICE(0x0af0, 0x7A01)},
458 {USB_DEVICE(0x0af0, 0x7A05)},
459 {USB_DEVICE(0x0af0, 0x8200)},
460 {USB_DEVICE(0x0af0, 0x8201)},
461 {USB_DEVICE(0x0af0, 0x8300)},
462 {USB_DEVICE(0x0af0, 0x8302)},
463 {USB_DEVICE(0x0af0, 0x8304)},
464 {USB_DEVICE(0x0af0, 0x8400)},
465 {USB_DEVICE(0x0af0, 0x8600)},
466 {USB_DEVICE(0x0af0, 0x8800)},
467 {USB_DEVICE(0x0af0, 0x8900)},
468 {USB_DEVICE(0x0af0, 0x9000)},
469 {USB_DEVICE(0x0af0, 0x9200)}, /* Option GTM671WFS */
470 {USB_DEVICE(0x0af0, 0xd035)},
471 {USB_DEVICE(0x0af0, 0xd055)},
472 {USB_DEVICE(0x0af0, 0xd155)},
473 {USB_DEVICE(0x0af0, 0xd255)},
474 {USB_DEVICE(0x0af0, 0xd057)},
475 {USB_DEVICE(0x0af0, 0xd157)},
476 {USB_DEVICE(0x0af0, 0xd257)},
477 {USB_DEVICE(0x0af0, 0xd357)},
478 {USB_DEVICE(0x0af0, 0xd058)},
479 {USB_DEVICE(0x0af0, 0xc100)},
482 MODULE_DEVICE_TABLE(usb
, hso_ids
);
484 /* Sysfs attribute */
485 static ssize_t
hso_sysfs_show_porttype(struct device
*dev
,
486 struct device_attribute
*attr
,
489 struct hso_device
*hso_dev
= dev_get_drvdata(dev
);
495 switch (hso_dev
->port_spec
& HSO_PORT_MASK
) {
496 case HSO_PORT_CONTROL
:
497 port_name
= "Control";
500 port_name
= "Application";
503 port_name
= "Application2";
508 case HSO_PORT_GPS_CONTROL
:
509 port_name
= "GPS Control";
515 port_name
= "Diagnostic";
518 port_name
= "Diagnostic2";
523 case HSO_PORT_NETWORK
:
524 port_name
= "Network";
527 port_name
= "Unknown";
531 return sprintf(buf
, "%s\n", port_name
);
533 static DEVICE_ATTR(hsotype
, S_IRUGO
, hso_sysfs_show_porttype
, NULL
);
535 static int hso_urb_to_index(struct hso_serial
*serial
, struct urb
*urb
)
539 for (idx
= 0; idx
< serial
->num_rx_urbs
; idx
++)
540 if (serial
->rx_urb
[idx
] == urb
)
542 dev_err(serial
->parent
->dev
, "hso_urb_to_index failed\n");
546 /* converts mux value to a port spec value */
547 static u32
hso_mux_to_port(int mux
)
553 result
= HSO_PORT_CONTROL
;
556 result
= HSO_PORT_APP
;
559 result
= HSO_PORT_PCSC
;
562 result
= HSO_PORT_GPS
;
565 result
= HSO_PORT_APP2
;
568 result
= HSO_PORT_NO_PORT
;
573 /* converts port spec value to a mux value */
574 static u32
hso_port_to_mux(int port
)
578 switch (port
& HSO_PORT_MASK
) {
579 case HSO_PORT_CONTROL
:
600 static struct hso_serial
*get_serial_by_shared_int_and_type(
601 struct hso_shared_int
*shared_int
,
606 port
= hso_mux_to_port(mux
);
608 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
609 if (serial_table
[i
] &&
610 (dev2ser(serial_table
[i
])->shared_int
== shared_int
) &&
611 ((serial_table
[i
]->port_spec
& HSO_PORT_MASK
) == port
)) {
612 return dev2ser(serial_table
[i
]);
619 static struct hso_serial
*get_serial_by_index(unsigned index
)
621 struct hso_serial
*serial
= NULL
;
624 spin_lock_irqsave(&serial_table_lock
, flags
);
625 if (serial_table
[index
])
626 serial
= dev2ser(serial_table
[index
]);
627 spin_unlock_irqrestore(&serial_table_lock
, flags
);
632 static int get_free_serial_index(void)
637 spin_lock_irqsave(&serial_table_lock
, flags
);
638 for (index
= 0; index
< HSO_SERIAL_TTY_MINORS
; index
++) {
639 if (serial_table
[index
] == NULL
) {
640 spin_unlock_irqrestore(&serial_table_lock
, flags
);
644 spin_unlock_irqrestore(&serial_table_lock
, flags
);
646 printk(KERN_ERR
"%s: no free serial devices in table\n", __func__
);
650 static void set_serial_by_index(unsigned index
, struct hso_serial
*serial
)
654 spin_lock_irqsave(&serial_table_lock
, flags
);
656 serial_table
[index
] = serial
->parent
;
658 serial_table
[index
] = NULL
;
659 spin_unlock_irqrestore(&serial_table_lock
, flags
);
662 static void handle_usb_error(int status
, const char *function
,
663 struct hso_device
*hso_dev
)
669 explanation
= "no device";
672 explanation
= "endpoint not enabled";
675 explanation
= "endpoint stalled";
678 explanation
= "not enough bandwidth";
681 explanation
= "device disabled";
684 explanation
= "device suspended";
690 explanation
= "internal error";
696 explanation
= "protocol error";
698 schedule_work(&hso_dev
->reset_device
);
701 explanation
= "unknown status";
705 /* log a meaningful explanation of an USB status */
706 D1("%s: received USB status - %s (%d)", function
, explanation
, status
);
709 /* Network interface functions */
711 /* called when net interface is brought up by ifconfig */
712 static int hso_net_open(struct net_device
*net
)
714 struct hso_net
*odev
= netdev_priv(net
);
715 unsigned long flags
= 0;
718 dev_err(&net
->dev
, "No net device !\n");
722 odev
->skb_tx_buf
= NULL
;
724 /* setup environment */
725 spin_lock_irqsave(&odev
->net_lock
, flags
);
726 odev
->rx_parse_state
= WAIT_IP
;
727 odev
->rx_buf_size
= 0;
728 odev
->rx_buf_missing
= sizeof(struct iphdr
);
729 spin_unlock_irqrestore(&odev
->net_lock
, flags
);
731 /* We are up and running. */
732 set_bit(HSO_NET_RUNNING
, &odev
->flags
);
733 hso_start_net_device(odev
->parent
);
735 /* Tell the kernel we are ready to start receiving from it */
736 netif_start_queue(net
);
741 /* called when interface is brought down by ifconfig */
742 static int hso_net_close(struct net_device
*net
)
744 struct hso_net
*odev
= netdev_priv(net
);
746 /* we don't need the queue anymore */
747 netif_stop_queue(net
);
748 /* no longer running */
749 clear_bit(HSO_NET_RUNNING
, &odev
->flags
);
751 hso_stop_net_device(odev
->parent
);
757 /* USB tells is xmit done, we should start the netqueue again */
758 static void write_bulk_callback(struct urb
*urb
)
760 struct hso_net
*odev
= urb
->context
;
761 int status
= urb
->status
;
764 if (!odev
|| !test_bit(HSO_NET_RUNNING
, &odev
->flags
)) {
765 dev_err(&urb
->dev
->dev
, "%s: device not running\n", __func__
);
769 /* Do we still have a valid kernel network device? */
770 if (!netif_device_present(odev
->net
)) {
771 dev_err(&urb
->dev
->dev
, "%s: net device not present\n",
776 /* log status, but don't act on it, we don't need to resubmit anything
779 handle_usb_error(status
, __func__
, odev
->parent
);
781 hso_put_activity(odev
->parent
);
783 /* Tell the network interface we are ready for another frame */
784 netif_wake_queue(odev
->net
);
787 /* called by kernel when we need to transmit a packet */
788 static netdev_tx_t
hso_net_start_xmit(struct sk_buff
*skb
,
789 struct net_device
*net
)
791 struct hso_net
*odev
= netdev_priv(net
);
794 /* Tell the kernel, "No more frames 'til we are done with this one." */
795 netif_stop_queue(net
);
796 if (hso_get_activity(odev
->parent
) == -EAGAIN
) {
797 odev
->skb_tx_buf
= skb
;
802 DUMP1(skb
->data
, skb
->len
);
803 /* Copy it from kernel memory to OUR memory */
804 memcpy(odev
->mux_bulk_tx_buf
, skb
->data
, skb
->len
);
805 D1("len: %d/%d", skb
->len
, MUX_BULK_TX_BUF_SIZE
);
807 /* Fill in the URB for shipping it out. */
808 usb_fill_bulk_urb(odev
->mux_bulk_tx_urb
,
810 usb_sndbulkpipe(odev
->parent
->usb
,
812 bEndpointAddress
& 0x7F),
813 odev
->mux_bulk_tx_buf
, skb
->len
, write_bulk_callback
,
816 /* Deal with the Zero Length packet problem, I hope */
817 odev
->mux_bulk_tx_urb
->transfer_flags
|= URB_ZERO_PACKET
;
819 /* Send the URB on its merry way. */
820 result
= usb_submit_urb(odev
->mux_bulk_tx_urb
, GFP_ATOMIC
);
822 dev_warn(&odev
->parent
->interface
->dev
,
823 "failed mux_bulk_tx_urb %d\n", result
);
824 net
->stats
.tx_errors
++;
825 netif_start_queue(net
);
827 net
->stats
.tx_packets
++;
828 net
->stats
.tx_bytes
+= skb
->len
;
835 static const struct ethtool_ops ops
= {
836 .get_link
= ethtool_op_get_link
839 /* called when a packet did not ack after watchdogtimeout */
840 static void hso_net_tx_timeout(struct net_device
*net
)
842 struct hso_net
*odev
= netdev_priv(net
);
847 /* Tell syslog we are hosed. */
848 dev_warn(&net
->dev
, "Tx timed out.\n");
850 /* Tear the waiting frame off the list */
851 if (odev
->mux_bulk_tx_urb
&&
852 (odev
->mux_bulk_tx_urb
->status
== -EINPROGRESS
))
853 usb_unlink_urb(odev
->mux_bulk_tx_urb
);
855 /* Update statistics */
856 net
->stats
.tx_errors
++;
859 /* make a real packet from the received USB buffer */
860 static void packetizeRx(struct hso_net
*odev
, unsigned char *ip_pkt
,
861 unsigned int count
, unsigned char is_eop
)
863 unsigned short temp_bytes
;
864 unsigned short buffer_offset
= 0;
865 unsigned short frame_len
;
866 unsigned char *tmp_rx_buf
;
869 D1("Rx %d bytes", count
);
870 DUMP(ip_pkt
, min(128, (int)count
));
873 switch (odev
->rx_parse_state
) {
875 /* waiting for IP header. */
876 /* wanted bytes - size of ip header */
879 odev
->rx_buf_missing
) ? count
: odev
->
882 memcpy(((unsigned char *)(&odev
->rx_ip_hdr
)) +
883 odev
->rx_buf_size
, ip_pkt
+ buffer_offset
,
886 odev
->rx_buf_size
+= temp_bytes
;
887 buffer_offset
+= temp_bytes
;
888 odev
->rx_buf_missing
-= temp_bytes
;
891 if (!odev
->rx_buf_missing
) {
892 /* header is complete allocate an sk_buffer and
893 * continue to WAIT_DATA */
894 frame_len
= ntohs(odev
->rx_ip_hdr
.tot_len
);
896 if ((frame_len
> DEFAULT_MRU
) ||
897 (frame_len
< sizeof(struct iphdr
))) {
898 dev_err(&odev
->net
->dev
,
899 "Invalid frame (%d) length\n",
901 odev
->rx_parse_state
= WAIT_SYNC
;
904 /* Allocate an sk_buff */
905 odev
->skb_rx_buf
= netdev_alloc_skb(odev
->net
,
907 if (!odev
->skb_rx_buf
) {
908 /* We got no receive buffer. */
909 D1("could not allocate memory");
910 odev
->rx_parse_state
= WAIT_SYNC
;
914 /* Copy what we got so far. make room for iphdr
917 skb_put(odev
->skb_rx_buf
,
918 sizeof(struct iphdr
));
919 memcpy(tmp_rx_buf
, (char *)&(odev
->rx_ip_hdr
),
920 sizeof(struct iphdr
));
923 odev
->rx_buf_size
= sizeof(struct iphdr
);
925 /* Filip actually use .tot_len */
926 odev
->rx_buf_missing
=
927 frame_len
- sizeof(struct iphdr
);
928 odev
->rx_parse_state
= WAIT_DATA
;
933 temp_bytes
= (count
< odev
->rx_buf_missing
)
934 ? count
: odev
->rx_buf_missing
;
936 /* Copy the rest of the bytes that are left in the
937 * buffer into the waiting sk_buf. */
938 /* Make room for temp_bytes after tail. */
939 tmp_rx_buf
= skb_put(odev
->skb_rx_buf
, temp_bytes
);
940 memcpy(tmp_rx_buf
, ip_pkt
+ buffer_offset
, temp_bytes
);
942 odev
->rx_buf_missing
-= temp_bytes
;
944 buffer_offset
+= temp_bytes
;
945 odev
->rx_buf_size
+= temp_bytes
;
946 if (!odev
->rx_buf_missing
) {
947 /* Packet is complete. Inject into stack. */
948 /* We have IP packet here */
949 odev
->skb_rx_buf
->protocol
= cpu_to_be16(ETH_P_IP
);
950 skb_reset_mac_header(odev
->skb_rx_buf
);
952 /* Ship it off to the kernel */
953 netif_rx(odev
->skb_rx_buf
);
954 /* No longer our buffer. */
955 odev
->skb_rx_buf
= NULL
;
957 /* update out statistics */
958 odev
->net
->stats
.rx_packets
++;
960 odev
->net
->stats
.rx_bytes
+= odev
->rx_buf_size
;
962 odev
->rx_buf_size
= 0;
963 odev
->rx_buf_missing
= sizeof(struct iphdr
);
964 odev
->rx_parse_state
= WAIT_IP
;
979 /* Recovery mechanism for WAIT_SYNC state. */
981 if (odev
->rx_parse_state
== WAIT_SYNC
) {
982 odev
->rx_parse_state
= WAIT_IP
;
983 odev
->rx_buf_size
= 0;
984 odev
->rx_buf_missing
= sizeof(struct iphdr
);
989 static void fix_crc_bug(struct urb
*urb
, __le16 max_packet_size
)
991 static const u8 crc_check
[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
992 u32 rest
= urb
->actual_length
% le16_to_cpu(max_packet_size
);
994 if (((rest
== 5) || (rest
== 6)) &&
995 !memcmp(((u8
*)urb
->transfer_buffer
) + urb
->actual_length
- 4,
997 urb
->actual_length
-= 4;
1001 /* Moving data from usb to kernel (in interrupt state) */
1002 static void read_bulk_callback(struct urb
*urb
)
1004 struct hso_net
*odev
= urb
->context
;
1005 struct net_device
*net
;
1007 int status
= urb
->status
;
1009 /* is al ok? (Filip: Who's Al ?) */
1011 handle_usb_error(status
, __func__
, odev
->parent
);
1016 if (!odev
|| !test_bit(HSO_NET_RUNNING
, &odev
->flags
)) {
1017 D1("BULK IN callback but driver is not active!");
1020 usb_mark_last_busy(urb
->dev
);
1024 if (!netif_device_present(net
)) {
1025 /* Somebody killed our network interface... */
1029 if (odev
->parent
->port_spec
& HSO_INFO_CRC_BUG
)
1030 fix_crc_bug(urb
, odev
->in_endp
->wMaxPacketSize
);
1032 /* do we even have a packet? */
1033 if (urb
->actual_length
) {
1034 /* Handle the IP stream, add header and push it onto network
1035 * stack if the packet is complete. */
1036 spin_lock(&odev
->net_lock
);
1037 packetizeRx(odev
, urb
->transfer_buffer
, urb
->actual_length
,
1038 (urb
->transfer_buffer_length
>
1039 urb
->actual_length
) ? 1 : 0);
1040 spin_unlock(&odev
->net_lock
);
1043 /* We are done with this URB, resubmit it. Prep the USB to wait for
1044 * another frame. Reuse same as received. */
1045 usb_fill_bulk_urb(urb
,
1047 usb_rcvbulkpipe(odev
->parent
->usb
,
1049 bEndpointAddress
& 0x7F),
1050 urb
->transfer_buffer
, MUX_BULK_RX_BUF_SIZE
,
1051 read_bulk_callback
, odev
);
1053 /* Give this to the USB subsystem so it can tell us when more data
1055 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1057 dev_warn(&odev
->parent
->interface
->dev
,
1058 "%s failed submit mux_bulk_rx_urb %d\n", __func__
,
1062 /* Serial driver functions */
1064 static void hso_init_termios(struct ktermios
*termios
)
1067 * The default requirements for this device are:
1070 ~(IGNBRK
/* disable ignore break */
1071 | BRKINT
/* disable break causes interrupt */
1072 | PARMRK
/* disable mark parity errors */
1073 | ISTRIP
/* disable clear high bit of input characters */
1074 | INLCR
/* disable translate NL to CR */
1075 | IGNCR
/* disable ignore CR */
1076 | ICRNL
/* disable translate CR to NL */
1077 | IXON
); /* disable enable XON/XOFF flow control */
1079 /* disable postprocess output characters */
1080 termios
->c_oflag
&= ~OPOST
;
1083 ~(ECHO
/* disable echo input characters */
1084 | ECHONL
/* disable echo new line */
1085 | ICANON
/* disable erase, kill, werase, and rprnt
1086 special characters */
1087 | ISIG
/* disable interrupt, quit, and suspend special
1089 | IEXTEN
); /* disable non-POSIX special characters */
1092 ~(CSIZE
/* no size */
1093 | PARENB
/* disable parity bit */
1094 | CBAUD
/* clear current baud rate */
1095 | CBAUDEX
); /* clear current buad rate */
1097 termios
->c_cflag
|= CS8
; /* character size 8 bits */
1099 /* baud rate 115200 */
1100 tty_termios_encode_baud_rate(termios
, 115200, 115200);
1103 static void _hso_serial_set_termios(struct tty_struct
*tty
,
1104 struct ktermios
*old
)
1106 struct hso_serial
*serial
= tty
->driver_data
;
1109 printk(KERN_ERR
"%s: no tty structures", __func__
);
1113 D4("port %d", serial
->minor
);
1116 * Fix up unsupported bits
1118 tty
->termios
.c_iflag
&= ~IXON
; /* disable enable XON/XOFF flow control */
1120 tty
->termios
.c_cflag
&=
1121 ~(CSIZE
/* no size */
1122 | PARENB
/* disable parity bit */
1123 | CBAUD
/* clear current baud rate */
1124 | CBAUDEX
); /* clear current buad rate */
1126 tty
->termios
.c_cflag
|= CS8
; /* character size 8 bits */
1128 /* baud rate 115200 */
1129 tty_encode_baud_rate(tty
, 115200, 115200);
1132 static void hso_resubmit_rx_bulk_urb(struct hso_serial
*serial
, struct urb
*urb
)
1135 /* We are done with this URB, resubmit it. Prep the USB to wait for
1137 usb_fill_bulk_urb(urb
, serial
->parent
->usb
,
1138 usb_rcvbulkpipe(serial
->parent
->usb
,
1140 bEndpointAddress
& 0x7F),
1141 urb
->transfer_buffer
, serial
->rx_data_length
,
1142 hso_std_serial_read_bulk_callback
, serial
);
1143 /* Give this to the USB subsystem so it can tell us when more data
1145 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1147 dev_err(&urb
->dev
->dev
, "%s failed submit serial rx_urb %d\n",
1155 static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial
*serial
)
1158 struct urb
*curr_urb
;
1160 while (serial
->rx_urb_filled
[serial
->curr_rx_urb_idx
]) {
1161 curr_urb
= serial
->rx_urb
[serial
->curr_rx_urb_idx
];
1162 count
= put_rxbuf_data(curr_urb
, serial
);
1166 serial
->curr_rx_urb_idx
++;
1167 if (serial
->curr_rx_urb_idx
>= serial
->num_rx_urbs
)
1168 serial
->curr_rx_urb_idx
= 0;
1169 hso_resubmit_rx_bulk_urb(serial
, curr_urb
);
1174 static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial
*serial
)
1179 urb
= serial
->rx_urb
[0];
1180 if (serial
->port
.count
> 0) {
1181 count
= put_rxbuf_data(urb
, serial
);
1185 /* Re issue a read as long as we receive data. */
1187 if (count
== 0 && ((urb
->actual_length
!= 0) ||
1188 (serial
->rx_state
== RX_PENDING
))) {
1189 serial
->rx_state
= RX_SENT
;
1190 hso_mux_serial_read(serial
);
1192 serial
->rx_state
= RX_IDLE
;
1196 /* read callback for Diag and CS port */
1197 static void hso_std_serial_read_bulk_callback(struct urb
*urb
)
1199 struct hso_serial
*serial
= urb
->context
;
1200 int status
= urb
->status
;
1202 D4("\n--- Got serial_read_bulk callback %02x ---", status
);
1206 D1("serial == NULL");
1210 handle_usb_error(status
, __func__
, serial
->parent
);
1214 D1("Actual length = %d\n", urb
->actual_length
);
1215 DUMP1(urb
->transfer_buffer
, urb
->actual_length
);
1217 /* Anyone listening? */
1218 if (serial
->port
.count
== 0)
1221 if (serial
->parent
->port_spec
& HSO_INFO_CRC_BUG
)
1222 fix_crc_bug(urb
, serial
->in_endp
->wMaxPacketSize
);
1223 /* Valid data, handle RX data */
1224 spin_lock(&serial
->serial_lock
);
1225 serial
->rx_urb_filled
[hso_urb_to_index(serial
, urb
)] = 1;
1226 put_rxbuf_data_and_resubmit_bulk_urb(serial
);
1227 spin_unlock(&serial
->serial_lock
);
1231 * This needs to be a tasklet otherwise we will
1232 * end up recursively calling this function.
1234 static void hso_unthrottle_tasklet(struct hso_serial
*serial
)
1236 unsigned long flags
;
1238 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1239 if ((serial
->parent
->port_spec
& HSO_INTF_MUX
))
1240 put_rxbuf_data_and_resubmit_ctrl_urb(serial
);
1242 put_rxbuf_data_and_resubmit_bulk_urb(serial
);
1243 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1246 static void hso_unthrottle(struct tty_struct
*tty
)
1248 struct hso_serial
*serial
= tty
->driver_data
;
1250 tasklet_hi_schedule(&serial
->unthrottle_tasklet
);
1253 /* open the requested serial port */
1254 static int hso_serial_open(struct tty_struct
*tty
, struct file
*filp
)
1256 struct hso_serial
*serial
= get_serial_by_index(tty
->index
);
1260 if (serial
== NULL
|| serial
->magic
!= HSO_SERIAL_MAGIC
) {
1262 tty
->driver_data
= NULL
;
1263 D1("Failed to open port");
1267 mutex_lock(&serial
->parent
->mutex
);
1268 result
= usb_autopm_get_interface(serial
->parent
->interface
);
1272 D1("Opening %d", serial
->minor
);
1275 tty
->driver_data
= serial
;
1276 tty_port_tty_set(&serial
->port
, tty
);
1278 /* check for port already opened, if not set the termios */
1279 serial
->port
.count
++;
1280 if (serial
->port
.count
== 1) {
1281 serial
->rx_state
= RX_IDLE
;
1282 /* Force default termio settings */
1283 _hso_serial_set_termios(tty
, NULL
);
1284 tasklet_init(&serial
->unthrottle_tasklet
,
1285 (void (*)(unsigned long))hso_unthrottle_tasklet
,
1286 (unsigned long)serial
);
1287 result
= hso_start_serial_device(serial
->parent
, GFP_KERNEL
);
1289 hso_stop_serial_device(serial
->parent
);
1290 serial
->port
.count
--;
1292 kref_get(&serial
->parent
->ref
);
1295 D1("Port was already open");
1298 usb_autopm_put_interface(serial
->parent
->interface
);
1302 hso_serial_tiocmset(tty
, TIOCM_RTS
| TIOCM_DTR
, 0);
1304 mutex_unlock(&serial
->parent
->mutex
);
1308 /* close the requested serial port */
1309 static void hso_serial_close(struct tty_struct
*tty
, struct file
*filp
)
1311 struct hso_serial
*serial
= tty
->driver_data
;
1314 D1("Closing serial port");
1316 /* Open failed, no close cleanup required */
1320 mutex_lock(&serial
->parent
->mutex
);
1321 usb_gone
= serial
->parent
->usb_gone
;
1324 usb_autopm_get_interface(serial
->parent
->interface
);
1326 /* reset the rts and dtr */
1327 /* do the actual close */
1328 serial
->port
.count
--;
1330 if (serial
->port
.count
<= 0) {
1331 serial
->port
.count
= 0;
1332 tty_port_tty_set(&serial
->port
, NULL
);
1334 hso_stop_serial_device(serial
->parent
);
1335 tasklet_kill(&serial
->unthrottle_tasklet
);
1339 usb_autopm_put_interface(serial
->parent
->interface
);
1341 mutex_unlock(&serial
->parent
->mutex
);
1344 /* close the requested serial port */
1345 static int hso_serial_write(struct tty_struct
*tty
, const unsigned char *buf
,
1348 struct hso_serial
*serial
= tty
->driver_data
;
1349 int space
, tx_bytes
;
1350 unsigned long flags
;
1353 if (serial
== NULL
) {
1354 printk(KERN_ERR
"%s: serial is NULL\n", __func__
);
1358 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1360 space
= serial
->tx_data_length
- serial
->tx_buffer_count
;
1361 tx_bytes
= (count
< space
) ? count
: space
;
1366 memcpy(serial
->tx_buffer
+ serial
->tx_buffer_count
, buf
, tx_bytes
);
1367 serial
->tx_buffer_count
+= tx_bytes
;
1370 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1372 hso_kick_transmit(serial
);
1377 /* how much room is there for writing */
1378 static int hso_serial_write_room(struct tty_struct
*tty
)
1380 struct hso_serial
*serial
= tty
->driver_data
;
1382 unsigned long flags
;
1384 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1385 room
= serial
->tx_data_length
- serial
->tx_buffer_count
;
1386 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1388 /* return free room */
1392 static void hso_serial_cleanup(struct tty_struct
*tty
)
1394 struct hso_serial
*serial
= tty
->driver_data
;
1399 kref_put(&serial
->parent
->ref
, hso_serial_ref_free
);
1402 /* setup the term */
1403 static void hso_serial_set_termios(struct tty_struct
*tty
, struct ktermios
*old
)
1405 struct hso_serial
*serial
= tty
->driver_data
;
1406 unsigned long flags
;
1409 D5("Termios called with: cflags new[%d] - old[%d]",
1410 tty
->termios
.c_cflag
, old
->c_cflag
);
1412 /* the actual setup */
1413 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1414 if (serial
->port
.count
)
1415 _hso_serial_set_termios(tty
, old
);
1417 tty
->termios
= *old
;
1418 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1423 /* how many characters in the buffer */
1424 static int hso_serial_chars_in_buffer(struct tty_struct
*tty
)
1426 struct hso_serial
*serial
= tty
->driver_data
;
1428 unsigned long flags
;
1434 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1435 chars
= serial
->tx_buffer_count
;
1436 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1440 static int tiocmget_submit_urb(struct hso_serial
*serial
,
1441 struct hso_tiocmget
*tiocmget
,
1442 struct usb_device
*usb
)
1446 if (serial
->parent
->usb_gone
)
1448 usb_fill_int_urb(tiocmget
->urb
, usb
,
1451 bEndpointAddress
& 0x7F),
1452 &tiocmget
->serial_state_notification
,
1453 sizeof(struct hso_serial_state_notification
),
1454 tiocmget_intr_callback
, serial
,
1455 tiocmget
->endp
->bInterval
);
1456 result
= usb_submit_urb(tiocmget
->urb
, GFP_ATOMIC
);
1458 dev_warn(&usb
->dev
, "%s usb_submit_urb failed %d\n", __func__
,
1465 static void tiocmget_intr_callback(struct urb
*urb
)
1467 struct hso_serial
*serial
= urb
->context
;
1468 struct hso_tiocmget
*tiocmget
;
1469 int status
= urb
->status
;
1470 u16 UART_state_bitmap
, prev_UART_state_bitmap
;
1471 struct uart_icount
*icount
;
1472 struct hso_serial_state_notification
*serial_state_notification
;
1473 struct usb_device
*usb
;
1480 handle_usb_error(status
, __func__
, serial
->parent
);
1484 /* tiocmget is only supported on HSO_PORT_MODEM */
1485 tiocmget
= serial
->tiocmget
;
1488 BUG_ON((serial
->parent
->port_spec
& HSO_PORT_MASK
) != HSO_PORT_MODEM
);
1490 usb
= serial
->parent
->usb
;
1491 if_num
= serial
->parent
->interface
->altsetting
->desc
.bInterfaceNumber
;
1493 /* wIndex should be the USB interface number of the port to which the
1494 * notification applies, which should always be the Modem port.
1496 serial_state_notification
= &tiocmget
->serial_state_notification
;
1497 if (serial_state_notification
->bmRequestType
!= BM_REQUEST_TYPE
||
1498 serial_state_notification
->bNotification
!= B_NOTIFICATION
||
1499 le16_to_cpu(serial_state_notification
->wValue
) != W_VALUE
||
1500 le16_to_cpu(serial_state_notification
->wIndex
) != if_num
||
1501 le16_to_cpu(serial_state_notification
->wLength
) != W_LENGTH
) {
1503 "hso received invalid serial state notification\n");
1504 DUMP(serial_state_notification
,
1505 sizeof(struct hso_serial_state_notification
));
1508 UART_state_bitmap
= le16_to_cpu(serial_state_notification
->
1510 prev_UART_state_bitmap
= tiocmget
->prev_UART_state_bitmap
;
1511 icount
= &tiocmget
->icount
;
1512 spin_lock(&serial
->serial_lock
);
1513 if ((UART_state_bitmap
& B_OVERRUN
) !=
1514 (prev_UART_state_bitmap
& B_OVERRUN
))
1516 if ((UART_state_bitmap
& B_PARITY
) !=
1517 (prev_UART_state_bitmap
& B_PARITY
))
1519 if ((UART_state_bitmap
& B_FRAMING
) !=
1520 (prev_UART_state_bitmap
& B_FRAMING
))
1522 if ((UART_state_bitmap
& B_RING_SIGNAL
) &&
1523 !(prev_UART_state_bitmap
& B_RING_SIGNAL
))
1525 if ((UART_state_bitmap
& B_BREAK
) !=
1526 (prev_UART_state_bitmap
& B_BREAK
))
1528 if ((UART_state_bitmap
& B_TX_CARRIER
) !=
1529 (prev_UART_state_bitmap
& B_TX_CARRIER
))
1531 if ((UART_state_bitmap
& B_RX_CARRIER
) !=
1532 (prev_UART_state_bitmap
& B_RX_CARRIER
))
1534 tiocmget
->prev_UART_state_bitmap
= UART_state_bitmap
;
1535 spin_unlock(&serial
->serial_lock
);
1536 tiocmget
->intr_completed
= 1;
1537 wake_up_interruptible(&tiocmget
->waitq
);
1539 memset(serial_state_notification
, 0,
1540 sizeof(struct hso_serial_state_notification
));
1541 tiocmget_submit_urb(serial
,
1543 serial
->parent
->usb
);
1547 * next few functions largely stolen from drivers/serial/serial_core.c
1549 /* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1550 * - mask passed in arg for lines of interest
1551 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1552 * Caller should use TIOCGICOUNT to see which one it was
1555 hso_wait_modem_status(struct hso_serial
*serial
, unsigned long arg
)
1557 DECLARE_WAITQUEUE(wait
, current
);
1558 struct uart_icount cprev
, cnow
;
1559 struct hso_tiocmget
*tiocmget
;
1562 tiocmget
= serial
->tiocmget
;
1566 * note the counters on entry
1568 spin_lock_irq(&serial
->serial_lock
);
1569 memcpy(&cprev
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1570 spin_unlock_irq(&serial
->serial_lock
);
1571 add_wait_queue(&tiocmget
->waitq
, &wait
);
1573 spin_lock_irq(&serial
->serial_lock
);
1574 memcpy(&cnow
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1575 spin_unlock_irq(&serial
->serial_lock
);
1576 set_current_state(TASK_INTERRUPTIBLE
);
1577 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1578 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1579 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
))) {
1584 /* see if a signal did it */
1585 if (signal_pending(current
)) {
1591 current
->state
= TASK_RUNNING
;
1592 remove_wait_queue(&tiocmget
->waitq
, &wait
);
1598 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1599 * Return: write counters to the user passed counter struct
1600 * NB: both 1->0 and 0->1 transitions are counted except for
1601 * RI where only 0->1 is counted.
1603 static int hso_get_count(struct tty_struct
*tty
,
1604 struct serial_icounter_struct
*icount
)
1606 struct uart_icount cnow
;
1607 struct hso_serial
*serial
= tty
->driver_data
;
1608 struct hso_tiocmget
*tiocmget
= serial
->tiocmget
;
1610 memset(icount
, 0, sizeof(struct serial_icounter_struct
));
1614 spin_lock_irq(&serial
->serial_lock
);
1615 memcpy(&cnow
, &tiocmget
->icount
, sizeof(struct uart_icount
));
1616 spin_unlock_irq(&serial
->serial_lock
);
1618 icount
->cts
= cnow
.cts
;
1619 icount
->dsr
= cnow
.dsr
;
1620 icount
->rng
= cnow
.rng
;
1621 icount
->dcd
= cnow
.dcd
;
1622 icount
->rx
= cnow
.rx
;
1623 icount
->tx
= cnow
.tx
;
1624 icount
->frame
= cnow
.frame
;
1625 icount
->overrun
= cnow
.overrun
;
1626 icount
->parity
= cnow
.parity
;
1627 icount
->brk
= cnow
.brk
;
1628 icount
->buf_overrun
= cnow
.buf_overrun
;
1634 static int hso_serial_tiocmget(struct tty_struct
*tty
)
1637 struct hso_serial
*serial
= tty
->driver_data
;
1638 struct hso_tiocmget
*tiocmget
;
1639 u16 UART_state_bitmap
;
1643 D1("no tty structures");
1646 spin_lock_irq(&serial
->serial_lock
);
1647 retval
= ((serial
->rts_state
) ? TIOCM_RTS
: 0) |
1648 ((serial
->dtr_state
) ? TIOCM_DTR
: 0);
1649 tiocmget
= serial
->tiocmget
;
1652 UART_state_bitmap
= le16_to_cpu(
1653 tiocmget
->prev_UART_state_bitmap
);
1654 if (UART_state_bitmap
& B_RING_SIGNAL
)
1655 retval
|= TIOCM_RNG
;
1656 if (UART_state_bitmap
& B_RX_CARRIER
)
1658 if (UART_state_bitmap
& B_TX_CARRIER
)
1659 retval
|= TIOCM_DSR
;
1661 spin_unlock_irq(&serial
->serial_lock
);
1665 static int hso_serial_tiocmset(struct tty_struct
*tty
,
1666 unsigned int set
, unsigned int clear
)
1669 unsigned long flags
;
1671 struct hso_serial
*serial
= tty
->driver_data
;
1675 D1("no tty structures");
1679 if ((serial
->parent
->port_spec
& HSO_PORT_MASK
) != HSO_PORT_MODEM
)
1682 if_num
= serial
->parent
->interface
->altsetting
->desc
.bInterfaceNumber
;
1684 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1685 if (set
& TIOCM_RTS
)
1686 serial
->rts_state
= 1;
1687 if (set
& TIOCM_DTR
)
1688 serial
->dtr_state
= 1;
1690 if (clear
& TIOCM_RTS
)
1691 serial
->rts_state
= 0;
1692 if (clear
& TIOCM_DTR
)
1693 serial
->dtr_state
= 0;
1695 if (serial
->dtr_state
)
1697 if (serial
->rts_state
)
1700 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1702 return usb_control_msg(serial
->parent
->usb
,
1703 usb_rcvctrlpipe(serial
->parent
->usb
, 0), 0x22,
1704 0x21, val
, if_num
, NULL
, 0,
1705 USB_CTRL_SET_TIMEOUT
);
1708 static int hso_serial_ioctl(struct tty_struct
*tty
,
1709 unsigned int cmd
, unsigned long arg
)
1711 struct hso_serial
*serial
= tty
->driver_data
;
1713 D4("IOCTL cmd: %d, arg: %ld", cmd
, arg
);
1719 ret
= hso_wait_modem_status(serial
, arg
);
1729 /* starts a transmit */
1730 static void hso_kick_transmit(struct hso_serial
*serial
)
1733 unsigned long flags
;
1736 spin_lock_irqsave(&serial
->serial_lock
, flags
);
1737 if (!serial
->tx_buffer_count
)
1740 if (serial
->tx_urb_used
)
1743 /* Wakeup USB interface if necessary */
1744 if (hso_get_activity(serial
->parent
) == -EAGAIN
)
1747 /* Switch pointers around to avoid memcpy */
1748 temp
= serial
->tx_buffer
;
1749 serial
->tx_buffer
= serial
->tx_data
;
1750 serial
->tx_data
= temp
;
1751 serial
->tx_data_count
= serial
->tx_buffer_count
;
1752 serial
->tx_buffer_count
= 0;
1754 /* If temp is set, it means we switched buffers */
1755 if (temp
&& serial
->write_data
) {
1756 res
= serial
->write_data(serial
);
1758 serial
->tx_urb_used
= 1;
1761 spin_unlock_irqrestore(&serial
->serial_lock
, flags
);
1764 /* make a request (for reading and writing data to muxed serial port) */
1765 static int mux_device_request(struct hso_serial
*serial
, u8 type
, u16 port
,
1766 struct urb
*ctrl_urb
,
1767 struct usb_ctrlrequest
*ctrl_req
,
1768 u8
*ctrl_urb_data
, u32 size
)
1774 if (!serial
|| !ctrl_urb
|| !ctrl_req
) {
1775 printk(KERN_ERR
"%s: Wrong arguments\n", __func__
);
1780 ctrl_req
->wValue
= 0;
1781 ctrl_req
->wIndex
= cpu_to_le16(hso_port_to_mux(port
));
1782 ctrl_req
->wLength
= cpu_to_le16(size
);
1784 if (type
== USB_CDC_GET_ENCAPSULATED_RESPONSE
) {
1785 /* Reading command */
1786 ctrl_req
->bRequestType
= USB_DIR_IN
|
1787 USB_TYPE_OPTION_VENDOR
|
1788 USB_RECIP_INTERFACE
;
1789 ctrl_req
->bRequest
= USB_CDC_GET_ENCAPSULATED_RESPONSE
;
1790 pipe
= usb_rcvctrlpipe(serial
->parent
->usb
, 0);
1792 /* Writing command */
1793 ctrl_req
->bRequestType
= USB_DIR_OUT
|
1794 USB_TYPE_OPTION_VENDOR
|
1795 USB_RECIP_INTERFACE
;
1796 ctrl_req
->bRequest
= USB_CDC_SEND_ENCAPSULATED_COMMAND
;
1797 pipe
= usb_sndctrlpipe(serial
->parent
->usb
, 0);
1800 D2("%s command (%02x) len: %d, port: %d",
1801 type
== USB_CDC_GET_ENCAPSULATED_RESPONSE
? "Read" : "Write",
1802 ctrl_req
->bRequestType
, ctrl_req
->wLength
, port
);
1805 ctrl_urb
->transfer_flags
= 0;
1806 usb_fill_control_urb(ctrl_urb
,
1807 serial
->parent
->usb
,
1810 ctrl_urb_data
, size
, ctrl_callback
, serial
);
1811 /* Send it on merry way */
1812 result
= usb_submit_urb(ctrl_urb
, GFP_ATOMIC
);
1814 dev_err(&ctrl_urb
->dev
->dev
,
1815 "%s failed submit ctrl_urb %d type %d\n", __func__
,
1824 /* called by intr_callback when read occurs */
1825 static int hso_mux_serial_read(struct hso_serial
*serial
)
1831 memset(serial
->rx_data
[0], 0, CTRL_URB_RX_SIZE
);
1832 /* make the request */
1834 if (serial
->num_rx_urbs
!= 1) {
1835 dev_err(&serial
->parent
->interface
->dev
,
1836 "ERROR: mux'd reads with multiple buffers "
1840 return mux_device_request(serial
,
1841 USB_CDC_GET_ENCAPSULATED_RESPONSE
,
1842 serial
->parent
->port_spec
& HSO_PORT_MASK
,
1844 &serial
->ctrl_req_rx
,
1845 serial
->rx_data
[0], serial
->rx_data_length
);
1848 /* used for muxed serial port callback (muxed serial read) */
1849 static void intr_callback(struct urb
*urb
)
1851 struct hso_shared_int
*shared_int
= urb
->context
;
1852 struct hso_serial
*serial
;
1853 unsigned char *port_req
;
1854 int status
= urb
->status
;
1857 usb_mark_last_busy(urb
->dev
);
1865 handle_usb_error(status
, __func__
, NULL
);
1868 D4("\n--- Got intr callback 0x%02X ---", status
);
1871 port_req
= urb
->transfer_buffer
;
1872 D4(" port_req = 0x%.2X\n", *port_req
);
1873 /* loop over all muxed ports to find the one sending this */
1874 for (i
= 0; i
< 8; i
++) {
1875 /* max 8 channels on MUX */
1876 if (*port_req
& (1 << i
)) {
1877 serial
= get_serial_by_shared_int_and_type(shared_int
,
1879 if (serial
!= NULL
) {
1880 D1("Pending read interrupt on port %d\n", i
);
1881 spin_lock(&serial
->serial_lock
);
1882 if (serial
->rx_state
== RX_IDLE
&&
1883 serial
->port
.count
> 0) {
1884 /* Setup and send a ctrl req read on
1886 if (!serial
->rx_urb_filled
[0]) {
1887 serial
->rx_state
= RX_SENT
;
1888 hso_mux_serial_read(serial
);
1890 serial
->rx_state
= RX_PENDING
;
1892 D1("Already a read pending on "
1893 "port %d or port not open\n", i
);
1895 spin_unlock(&serial
->serial_lock
);
1899 /* Resubmit interrupt urb */
1900 hso_mux_submit_intr_urb(shared_int
, urb
->dev
, GFP_ATOMIC
);
1903 /* called for writing to muxed serial port */
1904 static int hso_mux_serial_write_data(struct hso_serial
*serial
)
1909 return mux_device_request(serial
,
1910 USB_CDC_SEND_ENCAPSULATED_COMMAND
,
1911 serial
->parent
->port_spec
& HSO_PORT_MASK
,
1913 &serial
->ctrl_req_tx
,
1914 serial
->tx_data
, serial
->tx_data_count
);
1917 /* write callback for Diag and CS port */
1918 static void hso_std_serial_write_bulk_callback(struct urb
*urb
)
1920 struct hso_serial
*serial
= urb
->context
;
1921 int status
= urb
->status
;
1925 D1("serial == NULL");
1929 spin_lock(&serial
->serial_lock
);
1930 serial
->tx_urb_used
= 0;
1931 spin_unlock(&serial
->serial_lock
);
1933 handle_usb_error(status
, __func__
, serial
->parent
);
1936 hso_put_activity(serial
->parent
);
1937 tty_port_tty_wakeup(&serial
->port
);
1938 hso_kick_transmit(serial
);
1943 /* called for writing diag or CS serial port */
1944 static int hso_std_serial_write_data(struct hso_serial
*serial
)
1946 int count
= serial
->tx_data_count
;
1949 usb_fill_bulk_urb(serial
->tx_urb
,
1950 serial
->parent
->usb
,
1951 usb_sndbulkpipe(serial
->parent
->usb
,
1953 bEndpointAddress
& 0x7F),
1954 serial
->tx_data
, serial
->tx_data_count
,
1955 hso_std_serial_write_bulk_callback
, serial
);
1957 result
= usb_submit_urb(serial
->tx_urb
, GFP_ATOMIC
);
1959 dev_warn(&serial
->parent
->usb
->dev
,
1960 "Failed to submit urb - res %d\n", result
);
1967 /* callback after read or write on muxed serial port */
1968 static void ctrl_callback(struct urb
*urb
)
1970 struct hso_serial
*serial
= urb
->context
;
1971 struct usb_ctrlrequest
*req
;
1972 int status
= urb
->status
;
1978 spin_lock(&serial
->serial_lock
);
1979 serial
->tx_urb_used
= 0;
1980 spin_unlock(&serial
->serial_lock
);
1982 handle_usb_error(status
, __func__
, serial
->parent
);
1987 req
= (struct usb_ctrlrequest
*)(urb
->setup_packet
);
1988 D4("\n--- Got muxed ctrl callback 0x%02X ---", status
);
1989 D4("Actual length of urb = %d\n", urb
->actual_length
);
1990 DUMP1(urb
->transfer_buffer
, urb
->actual_length
);
1992 if (req
->bRequestType
==
1993 (USB_DIR_IN
| USB_TYPE_OPTION_VENDOR
| USB_RECIP_INTERFACE
)) {
1994 /* response to a read command */
1995 serial
->rx_urb_filled
[0] = 1;
1996 spin_lock(&serial
->serial_lock
);
1997 put_rxbuf_data_and_resubmit_ctrl_urb(serial
);
1998 spin_unlock(&serial
->serial_lock
);
2000 hso_put_activity(serial
->parent
);
2001 tty_port_tty_wakeup(&serial
->port
);
2002 /* response to a write command */
2003 hso_kick_transmit(serial
);
2007 /* handle RX data for serial port */
2008 static int put_rxbuf_data(struct urb
*urb
, struct hso_serial
*serial
)
2010 struct tty_struct
*tty
;
2014 if (urb
== NULL
|| serial
== NULL
) {
2015 D1("serial = NULL");
2019 tty
= tty_port_tty_get(&serial
->port
);
2021 if (tty
&& test_bit(TTY_THROTTLED
, &tty
->flags
)) {
2026 /* Push data to tty */
2027 D1("data to push to tty");
2028 count
= tty_buffer_request_room(&serial
->port
, urb
->actual_length
);
2029 if (count
>= urb
->actual_length
) {
2030 tty_insert_flip_string(&serial
->port
, urb
->transfer_buffer
,
2031 urb
->actual_length
);
2032 tty_flip_buffer_push(&serial
->port
);
2034 dev_warn(&serial
->parent
->usb
->dev
,
2035 "dropping data, %d bytes lost\n", urb
->actual_length
);
2040 serial
->rx_urb_filled
[hso_urb_to_index(serial
, urb
)] = 0;
2046 /* Base driver functions */
2048 static void hso_log_port(struct hso_device
*hso_dev
)
2053 switch (hso_dev
->port_spec
& HSO_PORT_MASK
) {
2054 case HSO_PORT_CONTROL
:
2055 port_type
= "Control";
2058 port_type
= "Application";
2063 case HSO_PORT_GPS_CONTROL
:
2064 port_type
= "GPS control";
2067 port_type
= "Application2";
2073 port_type
= "Diagnostic";
2075 case HSO_PORT_DIAG2
:
2076 port_type
= "Diagnostic2";
2078 case HSO_PORT_MODEM
:
2079 port_type
= "Modem";
2081 case HSO_PORT_NETWORK
:
2082 port_type
= "Network";
2085 port_type
= "Unknown";
2088 if ((hso_dev
->port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2089 sprintf(port_dev
, "%s", dev2net(hso_dev
)->net
->name
);
2091 sprintf(port_dev
, "/dev/%s%d", tty_filename
,
2092 dev2ser(hso_dev
)->minor
);
2094 dev_dbg(&hso_dev
->interface
->dev
, "HSO: Found %s port %s\n",
2095 port_type
, port_dev
);
2098 static int hso_start_net_device(struct hso_device
*hso_dev
)
2101 struct hso_net
*hso_net
= dev2net(hso_dev
);
2106 /* send URBs for all read buffers */
2107 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2109 /* Prep a receive URB */
2110 usb_fill_bulk_urb(hso_net
->mux_bulk_rx_urb_pool
[i
],
2112 usb_rcvbulkpipe(hso_dev
->usb
,
2114 bEndpointAddress
& 0x7F),
2115 hso_net
->mux_bulk_rx_buf_pool
[i
],
2116 MUX_BULK_RX_BUF_SIZE
, read_bulk_callback
,
2119 /* Put it out there so the device can send us stuff */
2120 result
= usb_submit_urb(hso_net
->mux_bulk_rx_urb_pool
[i
],
2123 dev_warn(&hso_dev
->usb
->dev
,
2124 "%s failed mux_bulk_rx_urb[%d] %d\n", __func__
,
2131 static int hso_stop_net_device(struct hso_device
*hso_dev
)
2134 struct hso_net
*hso_net
= dev2net(hso_dev
);
2139 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2140 if (hso_net
->mux_bulk_rx_urb_pool
[i
])
2141 usb_kill_urb(hso_net
->mux_bulk_rx_urb_pool
[i
]);
2144 if (hso_net
->mux_bulk_tx_urb
)
2145 usb_kill_urb(hso_net
->mux_bulk_tx_urb
);
2150 static int hso_start_serial_device(struct hso_device
*hso_dev
, gfp_t flags
)
2153 struct hso_serial
*serial
= dev2ser(hso_dev
);
2158 /* If it is not the MUX port fill in and submit a bulk urb (already
2159 * allocated in hso_serial_start) */
2160 if (!(serial
->parent
->port_spec
& HSO_INTF_MUX
)) {
2161 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2162 usb_fill_bulk_urb(serial
->rx_urb
[i
],
2163 serial
->parent
->usb
,
2164 usb_rcvbulkpipe(serial
->parent
->usb
,
2169 serial
->rx_data_length
,
2170 hso_std_serial_read_bulk_callback
,
2172 result
= usb_submit_urb(serial
->rx_urb
[i
], flags
);
2174 dev_warn(&serial
->parent
->usb
->dev
,
2175 "Failed to submit urb - res %d\n",
2181 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2182 if (!serial
->shared_int
->use_count
) {
2184 hso_mux_submit_intr_urb(serial
->shared_int
,
2185 hso_dev
->usb
, flags
);
2187 serial
->shared_int
->use_count
++;
2188 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2190 if (serial
->tiocmget
)
2191 tiocmget_submit_urb(serial
,
2193 serial
->parent
->usb
);
2197 static int hso_stop_serial_device(struct hso_device
*hso_dev
)
2200 struct hso_serial
*serial
= dev2ser(hso_dev
);
2201 struct hso_tiocmget
*tiocmget
;
2206 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2207 if (serial
->rx_urb
[i
]) {
2208 usb_kill_urb(serial
->rx_urb
[i
]);
2209 serial
->rx_urb_filled
[i
] = 0;
2212 serial
->curr_rx_urb_idx
= 0;
2215 usb_kill_urb(serial
->tx_urb
);
2217 if (serial
->shared_int
) {
2218 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2219 if (serial
->shared_int
->use_count
&&
2220 (--serial
->shared_int
->use_count
== 0)) {
2223 urb
= serial
->shared_int
->shared_intr_urb
;
2227 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2229 tiocmget
= serial
->tiocmget
;
2231 wake_up_interruptible(&tiocmget
->waitq
);
2232 usb_kill_urb(tiocmget
->urb
);
2238 static void hso_serial_common_free(struct hso_serial
*serial
)
2242 if (serial
->parent
->dev
)
2243 device_remove_file(serial
->parent
->dev
, &dev_attr_hsotype
);
2245 tty_unregister_device(tty_drv
, serial
->minor
);
2247 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2248 /* unlink and free RX URB */
2249 usb_free_urb(serial
->rx_urb
[i
]);
2250 /* free the RX buffer */
2251 kfree(serial
->rx_data
[i
]);
2254 /* unlink and free TX URB */
2255 usb_free_urb(serial
->tx_urb
);
2256 kfree(serial
->tx_data
);
2257 tty_port_destroy(&serial
->port
);
2260 static int hso_serial_common_create(struct hso_serial
*serial
, int num_urbs
,
2261 int rx_size
, int tx_size
)
2267 tty_port_init(&serial
->port
);
2269 minor
= get_free_serial_index();
2273 /* register our minor number */
2274 serial
->parent
->dev
= tty_port_register_device(&serial
->port
, tty_drv
,
2275 minor
, &serial
->parent
->interface
->dev
);
2276 dev
= serial
->parent
->dev
;
2277 dev_set_drvdata(dev
, serial
->parent
);
2278 i
= device_create_file(dev
, &dev_attr_hsotype
);
2280 /* fill in specific data for later use */
2281 serial
->minor
= minor
;
2282 serial
->magic
= HSO_SERIAL_MAGIC
;
2283 spin_lock_init(&serial
->serial_lock
);
2284 serial
->num_rx_urbs
= num_urbs
;
2286 /* RX, allocate urb and initialize */
2288 /* prepare our RX buffer */
2289 serial
->rx_data_length
= rx_size
;
2290 for (i
= 0; i
< serial
->num_rx_urbs
; i
++) {
2291 serial
->rx_urb
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
2292 if (!serial
->rx_urb
[i
]) {
2293 dev_err(dev
, "Could not allocate urb?\n");
2296 serial
->rx_urb
[i
]->transfer_buffer
= NULL
;
2297 serial
->rx_urb
[i
]->transfer_buffer_length
= 0;
2298 serial
->rx_data
[i
] = kzalloc(serial
->rx_data_length
,
2300 if (!serial
->rx_data
[i
])
2304 /* TX, allocate urb and initialize */
2305 serial
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2306 if (!serial
->tx_urb
) {
2307 dev_err(dev
, "Could not allocate urb?\n");
2310 serial
->tx_urb
->transfer_buffer
= NULL
;
2311 serial
->tx_urb
->transfer_buffer_length
= 0;
2312 /* prepare our TX buffer */
2313 serial
->tx_data_count
= 0;
2314 serial
->tx_buffer_count
= 0;
2315 serial
->tx_data_length
= tx_size
;
2316 serial
->tx_data
= kzalloc(serial
->tx_data_length
, GFP_KERNEL
);
2317 if (!serial
->tx_data
)
2320 serial
->tx_buffer
= kzalloc(serial
->tx_data_length
, GFP_KERNEL
);
2321 if (!serial
->tx_buffer
)
2326 hso_serial_common_free(serial
);
2330 /* Creates a general hso device */
2331 static struct hso_device
*hso_create_device(struct usb_interface
*intf
,
2334 struct hso_device
*hso_dev
;
2336 hso_dev
= kzalloc(sizeof(*hso_dev
), GFP_ATOMIC
);
2340 hso_dev
->port_spec
= port_spec
;
2341 hso_dev
->usb
= interface_to_usbdev(intf
);
2342 hso_dev
->interface
= intf
;
2343 kref_init(&hso_dev
->ref
);
2344 mutex_init(&hso_dev
->mutex
);
2346 INIT_WORK(&hso_dev
->async_get_intf
, async_get_intf
);
2347 INIT_WORK(&hso_dev
->async_put_intf
, async_put_intf
);
2348 INIT_WORK(&hso_dev
->reset_device
, reset_device
);
2353 /* Removes a network device in the network device table */
2354 static int remove_net_device(struct hso_device
*hso_dev
)
2358 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
2359 if (network_table
[i
] == hso_dev
) {
2360 network_table
[i
] = NULL
;
2364 if (i
== HSO_MAX_NET_DEVICES
)
2369 /* Frees our network device */
2370 static void hso_free_net_device(struct hso_device
*hso_dev
)
2373 struct hso_net
*hso_net
= dev2net(hso_dev
);
2378 remove_net_device(hso_net
->parent
);
2381 unregister_netdev(hso_net
->net
);
2384 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2385 usb_free_urb(hso_net
->mux_bulk_rx_urb_pool
[i
]);
2386 kfree(hso_net
->mux_bulk_rx_buf_pool
[i
]);
2387 hso_net
->mux_bulk_rx_buf_pool
[i
] = NULL
;
2389 usb_free_urb(hso_net
->mux_bulk_tx_urb
);
2390 kfree(hso_net
->mux_bulk_tx_buf
);
2391 hso_net
->mux_bulk_tx_buf
= NULL
;
2394 free_netdev(hso_net
->net
);
2399 static const struct net_device_ops hso_netdev_ops
= {
2400 .ndo_open
= hso_net_open
,
2401 .ndo_stop
= hso_net_close
,
2402 .ndo_start_xmit
= hso_net_start_xmit
,
2403 .ndo_tx_timeout
= hso_net_tx_timeout
,
2406 /* initialize the network interface */
2407 static void hso_net_init(struct net_device
*net
)
2409 struct hso_net
*hso_net
= netdev_priv(net
);
2411 D1("sizeof hso_net is %d", (int)sizeof(*hso_net
));
2413 /* fill in the other fields */
2414 net
->netdev_ops
= &hso_netdev_ops
;
2415 net
->watchdog_timeo
= HSO_NET_TX_TIMEOUT
;
2416 net
->flags
= IFF_POINTOPOINT
| IFF_NOARP
| IFF_MULTICAST
;
2417 net
->type
= ARPHRD_NONE
;
2418 net
->mtu
= DEFAULT_MTU
- 14;
2419 net
->tx_queue_len
= 10;
2420 net
->ethtool_ops
= &ops
;
2422 /* and initialize the semaphore */
2423 spin_lock_init(&hso_net
->net_lock
);
2426 /* Adds a network device in the network device table */
2427 static int add_net_device(struct hso_device
*hso_dev
)
2431 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
2432 if (network_table
[i
] == NULL
) {
2433 network_table
[i
] = hso_dev
;
2437 if (i
== HSO_MAX_NET_DEVICES
)
2442 static int hso_rfkill_set_block(void *data
, bool blocked
)
2444 struct hso_device
*hso_dev
= data
;
2445 int enabled
= !blocked
;
2448 mutex_lock(&hso_dev
->mutex
);
2449 if (hso_dev
->usb_gone
)
2452 rv
= usb_control_msg(hso_dev
->usb
, usb_rcvctrlpipe(hso_dev
->usb
, 0),
2453 enabled
? 0x82 : 0x81, 0x40, 0, 0, NULL
, 0,
2454 USB_CTRL_SET_TIMEOUT
);
2455 mutex_unlock(&hso_dev
->mutex
);
2459 static const struct rfkill_ops hso_rfkill_ops
= {
2460 .set_block
= hso_rfkill_set_block
,
2463 /* Creates and sets up everything for rfkill */
2464 static void hso_create_rfkill(struct hso_device
*hso_dev
,
2465 struct usb_interface
*interface
)
2467 struct hso_net
*hso_net
= dev2net(hso_dev
);
2468 struct device
*dev
= &hso_net
->net
->dev
;
2471 rfkn
= kzalloc(20, GFP_KERNEL
);
2473 dev_err(dev
, "%s - Out of memory\n", __func__
);
2475 snprintf(rfkn
, 20, "hso-%d",
2476 interface
->altsetting
->desc
.bInterfaceNumber
);
2478 hso_net
->rfkill
= rfkill_alloc(rfkn
,
2479 &interface_to_usbdev(interface
)->dev
,
2481 &hso_rfkill_ops
, hso_dev
);
2482 if (!hso_net
->rfkill
) {
2483 dev_err(dev
, "%s - Out of memory\n", __func__
);
2487 if (rfkill_register(hso_net
->rfkill
) < 0) {
2488 rfkill_destroy(hso_net
->rfkill
);
2490 hso_net
->rfkill
= NULL
;
2491 dev_err(dev
, "%s - Failed to register rfkill\n", __func__
);
2496 static struct device_type hso_type
= {
2500 /* Creates our network device */
2501 static struct hso_device
*hso_create_net_device(struct usb_interface
*interface
,
2505 struct net_device
*net
;
2506 struct hso_net
*hso_net
;
2507 struct hso_device
*hso_dev
;
2509 hso_dev
= hso_create_device(interface
, port_spec
);
2513 /* allocate our network device, then we can put in our private data */
2514 /* call hso_net_init to do the basic initialization */
2515 net
= alloc_netdev(sizeof(struct hso_net
), "hso%d", NET_NAME_UNKNOWN
,
2518 dev_err(&interface
->dev
, "Unable to create ethernet device\n");
2522 hso_net
= netdev_priv(net
);
2524 hso_dev
->port_data
.dev_net
= hso_net
;
2526 hso_net
->parent
= hso_dev
;
2528 hso_net
->in_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2530 if (!hso_net
->in_endp
) {
2531 dev_err(&interface
->dev
, "Can't find BULK IN endpoint\n");
2534 hso_net
->out_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2536 if (!hso_net
->out_endp
) {
2537 dev_err(&interface
->dev
, "Can't find BULK OUT endpoint\n");
2540 SET_NETDEV_DEV(net
, &interface
->dev
);
2541 SET_NETDEV_DEVTYPE(net
, &hso_type
);
2543 /* registering our net device */
2544 result
= register_netdev(net
);
2546 dev_err(&interface
->dev
, "Failed to register device\n");
2550 /* start allocating */
2551 for (i
= 0; i
< MUX_BULK_RX_BUF_COUNT
; i
++) {
2552 hso_net
->mux_bulk_rx_urb_pool
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
2553 if (!hso_net
->mux_bulk_rx_urb_pool
[i
]) {
2554 dev_err(&interface
->dev
, "Could not allocate rx urb\n");
2557 hso_net
->mux_bulk_rx_buf_pool
[i
] = kzalloc(MUX_BULK_RX_BUF_SIZE
,
2559 if (!hso_net
->mux_bulk_rx_buf_pool
[i
])
2562 hso_net
->mux_bulk_tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2563 if (!hso_net
->mux_bulk_tx_urb
) {
2564 dev_err(&interface
->dev
, "Could not allocate tx urb\n");
2567 hso_net
->mux_bulk_tx_buf
= kzalloc(MUX_BULK_TX_BUF_SIZE
, GFP_KERNEL
);
2568 if (!hso_net
->mux_bulk_tx_buf
)
2571 add_net_device(hso_dev
);
2573 hso_log_port(hso_dev
);
2575 hso_create_rfkill(hso_dev
, interface
);
2579 hso_free_net_device(hso_dev
);
2583 static void hso_free_tiomget(struct hso_serial
*serial
)
2585 struct hso_tiocmget
*tiocmget
;
2588 tiocmget
= serial
->tiocmget
;
2590 usb_free_urb(tiocmget
->urb
);
2591 tiocmget
->urb
= NULL
;
2592 serial
->tiocmget
= NULL
;
2597 /* Frees an AT channel ( goes for both mux and non-mux ) */
2598 static void hso_free_serial_device(struct hso_device
*hso_dev
)
2600 struct hso_serial
*serial
= dev2ser(hso_dev
);
2604 set_serial_by_index(serial
->minor
, NULL
);
2606 hso_serial_common_free(serial
);
2608 if (serial
->shared_int
) {
2609 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2610 if (--serial
->shared_int
->ref_count
== 0)
2611 hso_free_shared_int(serial
->shared_int
);
2613 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2615 hso_free_tiomget(serial
);
2620 /* Creates a bulk AT channel */
2621 static struct hso_device
*hso_create_bulk_serial_device(
2622 struct usb_interface
*interface
, int port
)
2624 struct hso_device
*hso_dev
;
2625 struct hso_serial
*serial
;
2627 struct hso_tiocmget
*tiocmget
;
2629 hso_dev
= hso_create_device(interface
, port
);
2633 serial
= kzalloc(sizeof(*serial
), GFP_KERNEL
);
2637 serial
->parent
= hso_dev
;
2638 hso_dev
->port_data
.dev_serial
= serial
;
2640 if ((port
& HSO_PORT_MASK
) == HSO_PORT_MODEM
) {
2642 serial
->tiocmget
= kzalloc(sizeof(struct hso_tiocmget
),
2644 /* it isn't going to break our heart if serial->tiocmget
2645 * allocation fails don't bother checking this.
2647 if (serial
->tiocmget
) {
2648 tiocmget
= serial
->tiocmget
;
2649 tiocmget
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
2650 if (tiocmget
->urb
) {
2651 mutex_init(&tiocmget
->mutex
);
2652 init_waitqueue_head(&tiocmget
->waitq
);
2653 tiocmget
->endp
= hso_get_ep(
2655 USB_ENDPOINT_XFER_INT
,
2658 hso_free_tiomget(serial
);
2664 if (hso_serial_common_create(serial
, num_urbs
, BULK_URB_RX_SIZE
,
2668 serial
->in_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
,
2670 if (!serial
->in_endp
) {
2671 dev_err(&interface
->dev
, "Failed to find BULK IN ep\n");
2677 hso_get_ep(interface
, USB_ENDPOINT_XFER_BULK
, USB_DIR_OUT
))) {
2678 dev_err(&interface
->dev
, "Failed to find BULK IN ep\n");
2682 serial
->write_data
= hso_std_serial_write_data
;
2684 /* and record this serial */
2685 set_serial_by_index(serial
->minor
, serial
);
2687 /* setup the proc dirs and files if needed */
2688 hso_log_port(hso_dev
);
2690 /* done, return it */
2694 hso_serial_common_free(serial
);
2696 hso_free_tiomget(serial
);
2702 /* Creates a multiplexed AT channel */
2704 struct hso_device
*hso_create_mux_serial_device(struct usb_interface
*interface
,
2706 struct hso_shared_int
*mux
)
2708 struct hso_device
*hso_dev
;
2709 struct hso_serial
*serial
;
2712 port_spec
= HSO_INTF_MUX
;
2713 port_spec
&= ~HSO_PORT_MASK
;
2715 port_spec
|= hso_mux_to_port(port
);
2716 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NO_PORT
)
2719 hso_dev
= hso_create_device(interface
, port_spec
);
2723 serial
= kzalloc(sizeof(*serial
), GFP_KERNEL
);
2727 hso_dev
->port_data
.dev_serial
= serial
;
2728 serial
->parent
= hso_dev
;
2730 if (hso_serial_common_create
2731 (serial
, 1, CTRL_URB_RX_SIZE
, CTRL_URB_TX_SIZE
))
2734 serial
->tx_data_length
--;
2735 serial
->write_data
= hso_mux_serial_write_data
;
2737 serial
->shared_int
= mux
;
2738 mutex_lock(&serial
->shared_int
->shared_int_lock
);
2739 serial
->shared_int
->ref_count
++;
2740 mutex_unlock(&serial
->shared_int
->shared_int_lock
);
2742 /* and record this serial */
2743 set_serial_by_index(serial
->minor
, serial
);
2745 /* setup the proc dirs and files if needed */
2746 hso_log_port(hso_dev
);
2748 /* done, return it */
2753 tty_unregister_device(tty_drv
, serial
->minor
);
2761 static void hso_free_shared_int(struct hso_shared_int
*mux
)
2763 usb_free_urb(mux
->shared_intr_urb
);
2764 kfree(mux
->shared_intr_buf
);
2765 mutex_unlock(&mux
->shared_int_lock
);
2770 struct hso_shared_int
*hso_create_shared_int(struct usb_interface
*interface
)
2772 struct hso_shared_int
*mux
= kzalloc(sizeof(*mux
), GFP_KERNEL
);
2777 mux
->intr_endp
= hso_get_ep(interface
, USB_ENDPOINT_XFER_INT
,
2779 if (!mux
->intr_endp
) {
2780 dev_err(&interface
->dev
, "Can't find INT IN endpoint\n");
2784 mux
->shared_intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
2785 if (!mux
->shared_intr_urb
) {
2786 dev_err(&interface
->dev
, "Could not allocate intr urb?\n");
2789 mux
->shared_intr_buf
=
2790 kzalloc(le16_to_cpu(mux
->intr_endp
->wMaxPacketSize
),
2792 if (!mux
->shared_intr_buf
)
2795 mutex_init(&mux
->shared_int_lock
);
2800 kfree(mux
->shared_intr_buf
);
2801 usb_free_urb(mux
->shared_intr_urb
);
2806 /* Gets the port spec for a certain interface */
2807 static int hso_get_config_data(struct usb_interface
*interface
)
2809 struct usb_device
*usbdev
= interface_to_usbdev(interface
);
2810 u8
*config_data
= kmalloc(17, GFP_KERNEL
);
2811 u32 if_num
= interface
->altsetting
->desc
.bInterfaceNumber
;
2816 if (usb_control_msg(usbdev
, usb_rcvctrlpipe(usbdev
, 0),
2817 0x86, 0xC0, 0, 0, config_data
, 17,
2818 USB_CTRL_SET_TIMEOUT
) != 0x11) {
2823 switch (config_data
[if_num
]) {
2828 result
= HSO_PORT_DIAG
;
2831 result
= HSO_PORT_GPS
;
2834 result
= HSO_PORT_GPS_CONTROL
;
2837 result
= HSO_PORT_APP
;
2840 result
= HSO_PORT_APP2
;
2843 result
= HSO_PORT_CONTROL
;
2846 result
= HSO_PORT_NETWORK
;
2849 result
= HSO_PORT_MODEM
;
2852 result
= HSO_PORT_MSD
;
2855 result
= HSO_PORT_PCSC
;
2858 result
= HSO_PORT_VOICE
;
2865 result
|= HSO_INTF_BULK
;
2867 if (config_data
[16] & 0x1)
2868 result
|= HSO_INFO_CRC_BUG
;
2874 /* called once for each interface upon device insertion */
2875 static int hso_probe(struct usb_interface
*interface
,
2876 const struct usb_device_id
*id
)
2878 int mux
, i
, if_num
, port_spec
;
2879 unsigned char port_mask
;
2880 struct hso_device
*hso_dev
= NULL
;
2881 struct hso_shared_int
*shared_int
;
2882 struct hso_device
*tmp_dev
= NULL
;
2884 if (interface
->cur_altsetting
->desc
.bInterfaceClass
!= 0xFF) {
2885 dev_err(&interface
->dev
, "Not our interface\n");
2889 if_num
= interface
->altsetting
->desc
.bInterfaceNumber
;
2891 /* Get the interface/port specification from either driver_info or from
2892 * the device itself */
2893 if (id
->driver_info
)
2894 port_spec
= ((u32
*)(id
->driver_info
))[if_num
];
2896 port_spec
= hso_get_config_data(interface
);
2898 /* Check if we need to switch to alt interfaces prior to port
2900 if (interface
->num_altsetting
> 1)
2901 usb_set_interface(interface_to_usbdev(interface
), if_num
, 1);
2902 interface
->needs_remote_wakeup
= 1;
2904 /* Allocate new hso device(s) */
2905 switch (port_spec
& HSO_INTF_MASK
) {
2907 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2908 /* Create the network device */
2910 hso_dev
= hso_create_net_device(interface
,
2918 if (hso_get_mux_ports(interface
, &port_mask
))
2919 /* TODO: de-allocate everything */
2922 shared_int
= hso_create_shared_int(interface
);
2926 for (i
= 1, mux
= 0; i
< 0x100; i
= i
<< 1, mux
++) {
2927 if (port_mask
& i
) {
2928 hso_dev
= hso_create_mux_serial_device(
2929 interface
, i
, shared_int
);
2940 /* It's a regular bulk interface */
2941 if ((port_spec
& HSO_PORT_MASK
) == HSO_PORT_NETWORK
) {
2944 hso_create_net_device(interface
, port_spec
);
2947 hso_create_bulk_serial_device(interface
, port_spec
);
2956 /* save our data pointer in this device */
2957 usb_set_intfdata(interface
, hso_dev
);
2962 hso_free_interface(interface
);
2966 /* device removed, cleaning up */
2967 static void hso_disconnect(struct usb_interface
*interface
)
2969 hso_free_interface(interface
);
2971 /* remove reference of our private data */
2972 usb_set_intfdata(interface
, NULL
);
2975 static void async_get_intf(struct work_struct
*data
)
2977 struct hso_device
*hso_dev
=
2978 container_of(data
, struct hso_device
, async_get_intf
);
2979 usb_autopm_get_interface(hso_dev
->interface
);
2982 static void async_put_intf(struct work_struct
*data
)
2984 struct hso_device
*hso_dev
=
2985 container_of(data
, struct hso_device
, async_put_intf
);
2986 usb_autopm_put_interface(hso_dev
->interface
);
2989 static int hso_get_activity(struct hso_device
*hso_dev
)
2991 if (hso_dev
->usb
->state
== USB_STATE_SUSPENDED
) {
2992 if (!hso_dev
->is_active
) {
2993 hso_dev
->is_active
= 1;
2994 schedule_work(&hso_dev
->async_get_intf
);
2998 if (hso_dev
->usb
->state
!= USB_STATE_CONFIGURED
)
3001 usb_mark_last_busy(hso_dev
->usb
);
3006 static int hso_put_activity(struct hso_device
*hso_dev
)
3008 if (hso_dev
->usb
->state
!= USB_STATE_SUSPENDED
) {
3009 if (hso_dev
->is_active
) {
3010 hso_dev
->is_active
= 0;
3011 schedule_work(&hso_dev
->async_put_intf
);
3015 hso_dev
->is_active
= 0;
3019 /* called by kernel when we need to suspend device */
3020 static int hso_suspend(struct usb_interface
*iface
, pm_message_t message
)
3024 /* Stop all serial ports */
3025 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3026 if (serial_table
[i
] && (serial_table
[i
]->interface
== iface
)) {
3027 result
= hso_stop_serial_device(serial_table
[i
]);
3033 /* Stop all network ports */
3034 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3035 if (network_table
[i
] &&
3036 (network_table
[i
]->interface
== iface
)) {
3037 result
= hso_stop_net_device(network_table
[i
]);
3047 /* called by kernel when we need to resume device */
3048 static int hso_resume(struct usb_interface
*iface
)
3051 struct hso_net
*hso_net
;
3053 /* Start all serial ports */
3054 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3055 if (serial_table
[i
] && (serial_table
[i
]->interface
== iface
)) {
3056 if (dev2ser(serial_table
[i
])->port
.count
) {
3058 hso_start_serial_device(serial_table
[i
], GFP_NOIO
);
3059 hso_kick_transmit(dev2ser(serial_table
[i
]));
3066 /* Start all network ports */
3067 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3068 if (network_table
[i
] &&
3069 (network_table
[i
]->interface
== iface
)) {
3070 hso_net
= dev2net(network_table
[i
]);
3071 if (hso_net
->flags
& IFF_UP
) {
3072 /* First transmit any lingering data,
3073 then restart the device. */
3074 if (hso_net
->skb_tx_buf
) {
3075 dev_dbg(&iface
->dev
,
3077 " lingering data\n");
3078 hso_net_start_xmit(hso_net
->skb_tx_buf
,
3080 hso_net
->skb_tx_buf
= NULL
;
3082 result
= hso_start_net_device(network_table
[i
]);
3093 static void reset_device(struct work_struct
*data
)
3095 struct hso_device
*hso_dev
=
3096 container_of(data
, struct hso_device
, reset_device
);
3097 struct usb_device
*usb
= hso_dev
->usb
;
3100 if (hso_dev
->usb_gone
) {
3101 D1("No reset during disconnect\n");
3103 result
= usb_lock_device_for_reset(usb
, hso_dev
->interface
);
3105 D1("unable to lock device for reset: %d\n", result
);
3107 usb_reset_device(usb
);
3108 usb_unlock_device(usb
);
3113 static void hso_serial_ref_free(struct kref
*ref
)
3115 struct hso_device
*hso_dev
= container_of(ref
, struct hso_device
, ref
);
3117 hso_free_serial_device(hso_dev
);
3120 static void hso_free_interface(struct usb_interface
*interface
)
3122 struct hso_serial
*hso_dev
;
3125 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++) {
3126 if (serial_table
[i
] &&
3127 (serial_table
[i
]->interface
== interface
)) {
3128 hso_dev
= dev2ser(serial_table
[i
]);
3129 tty_port_tty_hangup(&hso_dev
->port
, false);
3130 mutex_lock(&hso_dev
->parent
->mutex
);
3131 hso_dev
->parent
->usb_gone
= 1;
3132 mutex_unlock(&hso_dev
->parent
->mutex
);
3133 kref_put(&serial_table
[i
]->ref
, hso_serial_ref_free
);
3137 for (i
= 0; i
< HSO_MAX_NET_DEVICES
; i
++) {
3138 if (network_table
[i
] &&
3139 (network_table
[i
]->interface
== interface
)) {
3140 struct rfkill
*rfk
= dev2net(network_table
[i
])->rfkill
;
3141 /* hso_stop_net_device doesn't stop the net queue since
3142 * traffic needs to start it again when suspended */
3143 netif_stop_queue(dev2net(network_table
[i
])->net
);
3144 hso_stop_net_device(network_table
[i
]);
3145 cancel_work_sync(&network_table
[i
]->async_put_intf
);
3146 cancel_work_sync(&network_table
[i
]->async_get_intf
);
3148 rfkill_unregister(rfk
);
3149 rfkill_destroy(rfk
);
3151 hso_free_net_device(network_table
[i
]);
3156 /* Helper functions */
3158 /* Get the endpoint ! */
3159 static struct usb_endpoint_descriptor
*hso_get_ep(struct usb_interface
*intf
,
3163 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
3164 struct usb_endpoint_descriptor
*endp
;
3166 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
3167 endp
= &iface
->endpoint
[i
].desc
;
3168 if (((endp
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
) == dir
) &&
3169 (usb_endpoint_type(endp
) == type
))
3176 /* Get the byte that describes which ports are enabled */
3177 static int hso_get_mux_ports(struct usb_interface
*intf
, unsigned char *ports
)
3180 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
3182 if (iface
->extralen
== 3) {
3183 *ports
= iface
->extra
[2];
3187 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
3188 if (iface
->endpoint
[i
].extralen
== 3) {
3189 *ports
= iface
->endpoint
[i
].extra
[2];
3197 /* interrupt urb needs to be submitted, used for serial read of muxed port */
3198 static int hso_mux_submit_intr_urb(struct hso_shared_int
*shared_int
,
3199 struct usb_device
*usb
, gfp_t gfp
)
3203 usb_fill_int_urb(shared_int
->shared_intr_urb
, usb
,
3205 shared_int
->intr_endp
->bEndpointAddress
& 0x7F),
3206 shared_int
->shared_intr_buf
,
3208 intr_callback
, shared_int
,
3209 shared_int
->intr_endp
->bInterval
);
3211 result
= usb_submit_urb(shared_int
->shared_intr_urb
, gfp
);
3213 dev_warn(&usb
->dev
, "%s failed mux_intr_urb %d\n", __func__
,
3219 /* operations setup of the serial interface */
3220 static const struct tty_operations hso_serial_ops
= {
3221 .open
= hso_serial_open
,
3222 .close
= hso_serial_close
,
3223 .write
= hso_serial_write
,
3224 .write_room
= hso_serial_write_room
,
3225 .cleanup
= hso_serial_cleanup
,
3226 .ioctl
= hso_serial_ioctl
,
3227 .set_termios
= hso_serial_set_termios
,
3228 .chars_in_buffer
= hso_serial_chars_in_buffer
,
3229 .tiocmget
= hso_serial_tiocmget
,
3230 .tiocmset
= hso_serial_tiocmset
,
3231 .get_icount
= hso_get_count
,
3232 .unthrottle
= hso_unthrottle
3235 static struct usb_driver hso_driver
= {
3236 .name
= driver_name
,
3238 .disconnect
= hso_disconnect
,
3239 .id_table
= hso_ids
,
3240 .suspend
= hso_suspend
,
3241 .resume
= hso_resume
,
3242 .reset_resume
= hso_resume
,
3243 .supports_autosuspend
= 1,
3244 .disable_hub_initiated_lpm
= 1,
3247 static int __init
hso_init(void)
3252 /* put it in the log */
3253 printk(KERN_INFO
"hso: %s\n", version
);
3255 /* Initialise the serial table semaphore and table */
3256 spin_lock_init(&serial_table_lock
);
3257 for (i
= 0; i
< HSO_SERIAL_TTY_MINORS
; i
++)
3258 serial_table
[i
] = NULL
;
3260 /* allocate our driver using the proper amount of supported minors */
3261 tty_drv
= alloc_tty_driver(HSO_SERIAL_TTY_MINORS
);
3265 /* fill in all needed values */
3266 tty_drv
->driver_name
= driver_name
;
3267 tty_drv
->name
= tty_filename
;
3269 /* if major number is provided as parameter, use that one */
3271 tty_drv
->major
= tty_major
;
3273 tty_drv
->minor_start
= 0;
3274 tty_drv
->type
= TTY_DRIVER_TYPE_SERIAL
;
3275 tty_drv
->subtype
= SERIAL_TYPE_NORMAL
;
3276 tty_drv
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
3277 tty_drv
->init_termios
= tty_std_termios
;
3278 hso_init_termios(&tty_drv
->init_termios
);
3279 tty_set_operations(tty_drv
, &hso_serial_ops
);
3281 /* register the tty driver */
3282 result
= tty_register_driver(tty_drv
);
3284 printk(KERN_ERR
"%s - tty_register_driver failed(%d)\n",
3289 /* register this module as an usb driver */
3290 result
= usb_register(&hso_driver
);
3292 printk(KERN_ERR
"Could not register hso driver? error: %d\n",
3300 tty_unregister_driver(tty_drv
);
3302 put_tty_driver(tty_drv
);
3306 static void __exit
hso_exit(void)
3308 printk(KERN_INFO
"hso: unloaded\n");
3310 tty_unregister_driver(tty_drv
);
3311 put_tty_driver(tty_drv
);
3312 /* deregister the usb driver */
3313 usb_deregister(&hso_driver
);
3316 /* Module definitions */
3317 module_init(hso_init
);
3318 module_exit(hso_exit
);
3320 MODULE_AUTHOR(MOD_AUTHOR
);
3321 MODULE_DESCRIPTION(MOD_DESCRIPTION
);
3322 MODULE_LICENSE(MOD_LICENSE
);
3324 /* change the debug level (eg: insmod hso.ko debug=0x04) */
3325 MODULE_PARM_DESC(debug
, "Level of debug [0x01 | 0x02 | 0x04 | 0x08 | 0x10]");
3326 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
3328 /* set the major tty number (eg: insmod hso.ko tty_major=245) */
3329 MODULE_PARM_DESC(tty_major
, "Set the major tty number");
3330 module_param(tty_major
, int, S_IRUGO
| S_IWUSR
);
3332 /* disable network interface (eg: insmod hso.ko disable_net=1) */
3333 MODULE_PARM_DESC(disable_net
, "Disable the network interface");
3334 module_param(disable_net
, int, S_IRUGO
| S_IWUSR
);