blob: b895969f949214caf381c44ab9260c95f612bc94 [file] [log] [blame]
Jack Phamf0b04de2013-02-13 09:31:50 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Hemant Kumar37c35e42011-09-14 23:44:19 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
Hemant Kumar131eb4b2012-11-26 19:47:18 -080013#ifndef __RMNET_USB_H
14#define __RMNET_USB_H
Hemant Kumar37c35e42011-09-14 23:44:19 -070015
16#include <linux/mutex.h>
17#include <linux/usb.h>
18#include <linux/cdev.h>
19#include <linux/usb/ch9.h>
20#include <linux/usb/cdc.h>
21
Jack Phamf0b04de2013-02-13 09:31:50 -080022#define MAX_RMNET_DEVS 4
Hemant Kumar131eb4b2012-11-26 19:47:18 -080023#define MAX_RMNET_INSTS_PER_DEV 17
24#define TOTAL_RMNET_DEV_COUNT (MAX_RMNET_DEVS * MAX_RMNET_INSTS_PER_DEV)
25
Jack Phamf0b04de2013-02-13 09:31:50 -080026#define CTRL_DEV_MAX_LEN 10
Hemant Kumar37c35e42011-09-14 23:44:19 -070027
Hemant Kumar131eb4b2012-11-26 19:47:18 -080028#define RMNET_CTRL_DEV_OPEN 0
29#define RMNET_CTRL_DEV_READY 1
30#define RMNET_CTRL_DEV_MUX_EN 2
31
32/*MUX header bit masks*/
33#define MUX_CTRL_MASK 0x1
34#define MUX_PAD_SHIFT 0x2
35
36/*max padding bytes for n byte alignment*/
37#define MAX_PAD_BYTES(n) (n-1)
38
39/*
40 *MUX Header Format
41 *BIT 0 : Mux type 0: Data, 1: control
42 *BIT 1: Reserved
43 *BIT 2-7: Pad bytes
44 *BIT 8-15: Mux ID
45 *BIT 16-31: PACKET_LEN_WITH_PADDING (Bytes)
46 */
47struct mux_hdr {
48 __u8 padding_info;
49 __u8 mux_id;
50 __le16 pkt_len_w_padding;
51} __packed;
52
Hemant Kumar37c35e42011-09-14 23:44:19 -070053struct rmnet_ctrl_dev {
54
55 /*for debugging purpose*/
56 char name[CTRL_DEV_MAX_LEN];
57
58 struct cdev cdev;
59 struct device *devicep;
Hemant Kumar131eb4b2012-11-26 19:47:18 -080060 unsigned ch_id;
61
62 /*to identify the usb device*/
63 unsigned id;
Hemant Kumar37c35e42011-09-14 23:44:19 -070064
65 struct usb_interface *intf;
66 unsigned int int_pipe;
67 struct urb *rcvurb;
68 struct urb *inturb;
69 struct usb_anchor tx_submitted;
Hemant Kumarfe2ec5462012-09-07 15:57:38 -070070 struct usb_anchor rx_submitted;
Hemant Kumar37c35e42011-09-14 23:44:19 -070071 void *rcvbuf;
72 void *intbuf;
73 struct usb_ctrlrequest *in_ctlreq;
74
75 spinlock_t rx_lock;
76 struct mutex dev_lock;
77 struct list_head rx_list;
78 wait_queue_head_t read_wait_queue;
79 wait_queue_head_t open_wait_queue;
80
Hemant Kumarfe2ec5462012-09-07 15:57:38 -070081 struct workqueue_struct *wq;
82 struct work_struct get_encap_work;
83
Hemant Kumar131eb4b2012-11-26 19:47:18 -080084 unsigned long status;
Hemant Kumar37c35e42011-09-14 23:44:19 -070085
Jack Pham461c4a02013-02-21 14:04:49 -080086 bool claimed;
87
Hemant Kumar37c35e42011-09-14 23:44:19 -070088 unsigned int mdm_wait_timeout;
89
Jack Phamf0b04de2013-02-13 09:31:50 -080090 /*input control lines (DSR, CTS, CD, RI)*/
91 unsigned int cbits_tolocal;
92 /*output control lines (DTR, RTS)*/
93 unsigned int cbits_tomdm;
94
Hemant Kumar37c35e42011-09-14 23:44:19 -070095 /*counters*/
96 unsigned int snd_encap_cmd_cnt;
97 unsigned int get_encap_resp_cnt;
98 unsigned int resp_avail_cnt;
Hemant Kumarfe2ec5462012-09-07 15:57:38 -070099 unsigned int get_encap_failure_cnt;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700100 unsigned int set_ctrl_line_state_cnt;
101 unsigned int tx_ctrl_err_cnt;
Hemant Kumare1757762012-04-13 16:53:09 -0700102 unsigned int zlp_cnt;
Hemant Kumar37c35e42011-09-14 23:44:19 -0700103};
104
Hemant Kumar131eb4b2012-11-26 19:47:18 -0800105extern struct workqueue_struct *usbnet_wq;
106
Devin Kimb09bf542012-09-13 09:38:53 -0700107extern int rmnet_usb_ctrl_start_rx(struct rmnet_ctrl_dev *);
Hemant Kumarfe2ec5462012-09-07 15:57:38 -0700108extern int rmnet_usb_ctrl_suspend(struct rmnet_ctrl_dev *dev);
Jack Phamf0b04de2013-02-13 09:31:50 -0800109extern int rmnet_usb_ctrl_init(int num_devs, int insts_per_dev);
110extern void rmnet_usb_ctrl_exit(int num_devs, int insts_per_dev);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700111extern int rmnet_usb_ctrl_probe(struct usb_interface *intf,
Jack Phamf0b04de2013-02-13 09:31:50 -0800112 struct usb_host_endpoint *int_in,
113 unsigned long rmnet_devnum,
Hemant Kumar131eb4b2012-11-26 19:47:18 -0800114 unsigned long *data);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700115extern void rmnet_usb_ctrl_disconnect(struct rmnet_ctrl_dev *);
Hemant Kumar131eb4b2012-11-26 19:47:18 -0800116extern void rmnet_usb_ctrl_cleanup(struct rmnet_ctrl_dev *dev);
Hemant Kumar37c35e42011-09-14 23:44:19 -0700117
118#endif /* __RMNET_USB_H*/