| Jack Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 2 | * |
| 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 Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 13 | #ifndef __RMNET_USB_H |
| 14 | #define __RMNET_USB_H |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 15 | |
| 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 Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 22 | #define MAX_RMNET_DEVS 4 |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 23 | #define MAX_RMNET_INSTS_PER_DEV 17 |
| 24 | #define TOTAL_RMNET_DEV_COUNT (MAX_RMNET_DEVS * MAX_RMNET_INSTS_PER_DEV) |
| 25 | |
| Jack Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 26 | #define CTRL_DEV_MAX_LEN 10 |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 27 | |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 28 | #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 | */ |
| 47 | struct mux_hdr { |
| 48 | __u8 padding_info; |
| 49 | __u8 mux_id; |
| 50 | __le16 pkt_len_w_padding; |
| 51 | } __packed; |
| 52 | |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 53 | struct 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 Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 60 | unsigned ch_id; |
| 61 | |
| 62 | /*to identify the usb device*/ |
| 63 | unsigned id; |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 64 | |
| 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 Kumar | fe2ec546 | 2012-09-07 15:57:38 -0700 | [diff] [blame] | 70 | struct usb_anchor rx_submitted; |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 71 | 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 Kumar | fe2ec546 | 2012-09-07 15:57:38 -0700 | [diff] [blame] | 81 | struct workqueue_struct *wq; |
| 82 | struct work_struct get_encap_work; |
| 83 | |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 84 | unsigned long status; |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 85 | |
| Jack Pham | 461c4a0 | 2013-02-21 14:04:49 -0800 | [diff] [blame] | 86 | bool claimed; |
| 87 | |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 88 | unsigned int mdm_wait_timeout; |
| 89 | |
| Jack Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 90 | /*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 Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 95 | /*counters*/ |
| 96 | unsigned int snd_encap_cmd_cnt; |
| 97 | unsigned int get_encap_resp_cnt; |
| 98 | unsigned int resp_avail_cnt; |
| Hemant Kumar | fe2ec546 | 2012-09-07 15:57:38 -0700 | [diff] [blame] | 99 | unsigned int get_encap_failure_cnt; |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 100 | unsigned int set_ctrl_line_state_cnt; |
| 101 | unsigned int tx_ctrl_err_cnt; |
| Hemant Kumar | e175776 | 2012-04-13 16:53:09 -0700 | [diff] [blame] | 102 | unsigned int zlp_cnt; |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 105 | extern struct workqueue_struct *usbnet_wq; |
| 106 | |
| Devin Kim | b09bf54 | 2012-09-13 09:38:53 -0700 | [diff] [blame] | 107 | extern int rmnet_usb_ctrl_start_rx(struct rmnet_ctrl_dev *); |
| Hemant Kumar | fe2ec546 | 2012-09-07 15:57:38 -0700 | [diff] [blame] | 108 | extern int rmnet_usb_ctrl_suspend(struct rmnet_ctrl_dev *dev); |
| Jack Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 109 | extern int rmnet_usb_ctrl_init(int num_devs, int insts_per_dev); |
| 110 | extern void rmnet_usb_ctrl_exit(int num_devs, int insts_per_dev); |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 111 | extern int rmnet_usb_ctrl_probe(struct usb_interface *intf, |
| Jack Pham | f0b04de | 2013-02-13 09:31:50 -0800 | [diff] [blame] | 112 | struct usb_host_endpoint *int_in, |
| 113 | unsigned long rmnet_devnum, |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 114 | unsigned long *data); |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 115 | extern void rmnet_usb_ctrl_disconnect(struct rmnet_ctrl_dev *); |
| Hemant Kumar | 131eb4b | 2012-11-26 19:47:18 -0800 | [diff] [blame] | 116 | extern void rmnet_usb_ctrl_cleanup(struct rmnet_ctrl_dev *dev); |
| Hemant Kumar | 37c35e4 | 2011-09-14 23:44:19 -0700 | [diff] [blame] | 117 | |
| 118 | #endif /* __RMNET_USB_H*/ |