Hemant Kumar | c72ab2b | 2012-01-10 12:33:49 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Hemant Kumar | 14401d5 | 2011-11-03 16:40:32 -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 | |
| 13 | |
| 14 | #ifndef __LINUX_USB_BRIDGE_H__ |
| 15 | #define __LINUX_USB_BRIDGE_H__ |
| 16 | |
| 17 | #include <linux/netdevice.h> |
| 18 | #include <linux/usb.h> |
| 19 | |
| 20 | /* bridge device 0: DUN |
| 21 | * bridge device 1 : Tethered RMNET |
| 22 | */ |
| 23 | #define MAX_BRIDGE_DEVICES 2 |
| 24 | |
Hemant Kumar | 14401d5 | 2011-11-03 16:40:32 -0700 | [diff] [blame] | 25 | struct bridge_ops { |
| 26 | int (*send_pkt)(void *, void *, size_t actual); |
| 27 | void (*send_cbits)(void *, unsigned int); |
| 28 | |
| 29 | /* flow control */ |
| 30 | void (*unthrottle_tx)(void *); |
| 31 | }; |
| 32 | |
| 33 | #define TX_THROTTLED BIT(0) |
| 34 | #define RX_THROTTLED BIT(1) |
| 35 | |
| 36 | struct bridge { |
| 37 | /* context of the gadget port using bridge driver */ |
| 38 | void *ctx; |
| 39 | |
| 40 | /* bridge device array index mapped to the gadget port array index. |
| 41 | * data bridge[ch_id] <-- bridge --> gadget port[ch_id] |
| 42 | */ |
| 43 | unsigned int ch_id; |
| 44 | |
| 45 | /* flow control bits */ |
| 46 | unsigned long flags; |
| 47 | |
| 48 | /* data/ctrl bridge callbacks */ |
| 49 | struct bridge_ops ops; |
| 50 | }; |
| 51 | |
Hemant Kumar | c72ab2b | 2012-01-10 12:33:49 -0800 | [diff] [blame] | 52 | /** |
| 53 | * timestamp_info: stores timestamp info for skb life cycle during data |
| 54 | * transfer for tethered rmnet/DUN. |
| 55 | * @created: stores timestamp at the time of creation of SKB. |
| 56 | * @rx_queued: stores timestamp when SKB queued to HW to receive |
| 57 | * data. |
| 58 | * @rx_done: stores timestamp when skb queued to h/w is completed. |
| 59 | * @rx_done_sent: stores timestamp when SKB is sent from gadget rmnet/DUN |
| 60 | * driver to bridge rmnet/DUN driver or vice versa. |
| 61 | * @tx_queued: stores timestamp when SKB is queued to send data. |
| 62 | * |
| 63 | * note that size of this struct shouldnt exceed 48bytes that's the max skb->cb |
| 64 | * holds. |
| 65 | */ |
| 66 | struct timestamp_info { |
| 67 | struct data_bridge *dev; |
| 68 | |
| 69 | unsigned int created; |
| 70 | unsigned int rx_queued; |
| 71 | unsigned int rx_done; |
| 72 | unsigned int rx_done_sent; |
| 73 | unsigned int tx_queued; |
| 74 | }; |
| 75 | |
| 76 | /* Maximum timestamp message length */ |
| 77 | #define DBG_DATA_MSG 128UL |
| 78 | |
| 79 | /* Maximum timestamp messages */ |
| 80 | #define DBG_DATA_MAX 32UL |
| 81 | |
| 82 | /* timestamp buffer descriptor */ |
| 83 | struct timestamp_buf { |
| 84 | char (buf[DBG_DATA_MAX])[DBG_DATA_MSG]; /* buffer */ |
| 85 | unsigned idx; /* index */ |
| 86 | rwlock_t lck; /* lock */ |
| 87 | }; |
| 88 | |
Hemant Kumar | 14401d5 | 2011-11-03 16:40:32 -0700 | [diff] [blame] | 89 | #if defined(CONFIG_USB_QCOM_MDM_BRIDGE) || \ |
| 90 | defined(CONFIG_USB_QCOM_MDM_BRIDGE_MODULE) |
| 91 | |
| 92 | /* Bridge APIs called by gadget driver */ |
| 93 | int ctrl_bridge_open(struct bridge *); |
| 94 | void ctrl_bridge_close(unsigned int); |
| 95 | int ctrl_bridge_write(unsigned int, char *, size_t); |
| 96 | int ctrl_bridge_set_cbits(unsigned int, unsigned int); |
| 97 | unsigned int ctrl_bridge_get_cbits_tohost(unsigned int); |
| 98 | int data_bridge_open(struct bridge *brdg); |
| 99 | void data_bridge_close(unsigned int); |
| 100 | int data_bridge_write(unsigned int , struct sk_buff *); |
| 101 | int data_bridge_unthrottle_rx(unsigned int); |
| 102 | |
| 103 | /* defined in control bridge */ |
| 104 | int ctrl_bridge_probe(struct usb_interface *, struct usb_host_endpoint *, int); |
| 105 | void ctrl_bridge_disconnect(unsigned int); |
| 106 | int ctrl_bridge_resume(unsigned int); |
| 107 | int ctrl_bridge_suspend(unsigned int); |
| 108 | |
| 109 | #else |
| 110 | |
| 111 | static inline int __maybe_unused ctrl_bridge_open(struct bridge *brdg) |
| 112 | { |
| 113 | return -ENODEV; |
| 114 | } |
| 115 | |
| 116 | static inline void __maybe_unused ctrl_bridge_close(unsigned int id) { } |
| 117 | |
| 118 | static inline int __maybe_unused ctrl_bridge_write(unsigned int id, |
| 119 | char *data, size_t size) |
| 120 | { |
| 121 | return -ENODEV; |
| 122 | } |
| 123 | |
| 124 | static inline int __maybe_unused ctrl_bridge_set_cbits(unsigned int id, |
| 125 | unsigned int cbits) |
| 126 | { |
| 127 | return -ENODEV; |
| 128 | } |
| 129 | |
| 130 | static inline unsigned int __maybe_unused |
| 131 | ctrl_bridge_get_cbits_tohost(unsigned int id) |
| 132 | { |
| 133 | return -ENODEV; |
| 134 | } |
| 135 | |
| 136 | static inline int __maybe_unused data_bridge_open(struct bridge *brdg) |
| 137 | { |
| 138 | return -ENODEV; |
| 139 | } |
| 140 | |
| 141 | static inline void __maybe_unused data_bridge_close(unsigned int id) { } |
| 142 | |
| 143 | static inline int __maybe_unused data_bridge_write(unsigned int id, |
| 144 | struct sk_buff *skb) |
| 145 | { |
| 146 | return -ENODEV; |
| 147 | } |
| 148 | |
| 149 | static inline int __maybe_unused data_bridge_unthrottle_rx(unsigned int id) |
| 150 | { |
| 151 | return -ENODEV; |
| 152 | } |
| 153 | |
| 154 | #endif |
Hemant Kumar | c72ab2b | 2012-01-10 12:33:49 -0800 | [diff] [blame] | 155 | |
Hemant Kumar | 14401d5 | 2011-11-03 16:40:32 -0700 | [diff] [blame] | 156 | #endif |