f_gsi.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _F_GSI_H
  7. #define _F_GSI_H
  8. #include <linux/poll.h>
  9. #include <linux/cdev.h>
  10. #include <uapi/linux/usb/cdc.h>
  11. #include <linux/usb/ch9.h>
  12. #include <linux/usb/composite.h>
  13. #include <linux/usb/gadget.h>
  14. #include <uapi/linux/usb/usb_ctrl_qti.h>
  15. #include <linux/usb/dwc3-msm.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/debugfs.h>
  18. #include <linux/ipa_usb.h>
  19. #include <linux/ipc_logging.h>
  20. #include <linux/timer.h>
  21. #define USB_CDC_RESET_FUNCTION 0x05
  22. #define GSI_RMNET_CTRL_NAME "rmnet_ctrl"
  23. #define GSI_MBIM_CTRL_NAME "android_mbim"
  24. #define GSI_DPL_CTRL_NAME "dpl_ctrl"
  25. #define GSI_CTRL_NAME_LEN (sizeof(GSI_MBIM_CTRL_NAME)+2)
  26. #define GSI_MAX_CTRL_PKT_SIZE 8192
  27. #define GSI_CTRL_DTR (1 << 0)
  28. #define GSI_NUM_IN_RNDIS_BUFFERS 50
  29. #define GSI_NUM_IN_RMNET_BUFFERS 50
  30. #define GSI_NUM_IN_BUFFERS 15
  31. #define GSI_IN_BUFF_SIZE 2048
  32. #define GSI_IN_RMNET_BUFF_SIZE 31744
  33. #define GSI_IN_RNDIS_BUFF_SIZE 16384
  34. #define GSI_NUM_OUT_BUFFERS 14
  35. #define GSI_OUT_AGGR_SIZE 24576
  36. #define GSI_IN_RNDIS_AGGR_SIZE 16384
  37. #define GSI_IN_MBIM_AGGR_SIZE 16384
  38. #define GSI_IN_RMNET_AGGR_SIZE 16384
  39. #define GSI_ECM_AGGR_SIZE 2048
  40. #define GSI_OUT_MBIM_BUF_LEN 16384
  41. #define GSI_OUT_RMNET_BUF_LEN 31744
  42. #define GSI_OUT_ECM_BUF_LEN 2048
  43. #define GSI_IPA_READY_TIMEOUT 5000
  44. #define ETH_ADDR_STR_LEN 14
  45. /* mbin and ecm */
  46. #define GSI_CTRL_NOTIFY_BUFF_LEN 16
  47. /* default max packets per tarnsfer value */
  48. #define DEFAULT_MAX_PKT_PER_XFER 15
  49. /* default pkt alignment factor */
  50. #define DEFAULT_PKT_ALIGNMENT_FACTOR 4
  51. #define GSI_MBIM_DATA_EP_TYPE_HSUSB 0x2
  52. /* ID for Microsoft OS String */
  53. #define GSI_MBIM_OS_STRING_ID 0xEE
  54. #define EVT_NONE 0
  55. #define EVT_UNINITIALIZED 1
  56. #define EVT_INITIALIZED 2
  57. #define EVT_SET_ALT 3
  58. #define EVT_IPA_READY 4
  59. #define EVT_HOST_NRDY 5
  60. #define EVT_HOST_READY 6
  61. #define EVT_DISCONNECTED 7
  62. #define EVT_SUSPEND 8
  63. #define EVT_IPA_SUSPEND 9
  64. #define EVT_RESUMED 10
  65. #define NUM_LOG_PAGES 10
  66. #define log_event_err(x, ...) do { \
  67. if (gsi) { \
  68. ipc_log_string(gsi->ipc_log_ctxt, x, ##__VA_ARGS__); \
  69. pr_err(x, ##__VA_ARGS__); \
  70. } \
  71. } while (0)
  72. #define log_event_dbg(x, ...) do { \
  73. if (gsi) { \
  74. ipc_log_string(gsi->ipc_log_ctxt, x, ##__VA_ARGS__); \
  75. pr_debug(x, ##__VA_ARGS__); \
  76. } \
  77. } while (0)
  78. #define log_event_info(x, ...) do { \
  79. if (gsi) { \
  80. ipc_log_string(gsi->ipc_log_ctxt, x, ##__VA_ARGS__); \
  81. pr_info(x, ##__VA_ARGS__); \
  82. } \
  83. } while (0)
  84. enum connection_state {
  85. STATE_UNINITIALIZED,
  86. STATE_INITIALIZED,
  87. STATE_WAIT_FOR_IPA_RDY,
  88. STATE_CONNECTED,
  89. STATE_HOST_NRDY,
  90. STATE_DISCONNECTED,
  91. STATE_SUSPEND_IN_PROGRESS,
  92. STATE_SUSPENDED
  93. };
  94. enum gsi_ctrl_notify_state {
  95. GSI_CTRL_NOTIFY_NONE,
  96. GSI_CTRL_NOTIFY_CONNECT,
  97. GSI_CTRL_NOTIFY_SPEED,
  98. GSI_CTRL_NOTIFY_OFFLINE,
  99. GSI_CTRL_NOTIFY_RESPONSE_AVAILABLE,
  100. };
  101. enum rndis_class_id {
  102. RNDIS_ID_UNKNOWN,
  103. WIRELESS_CONTROLLER_REMOTE_NDIS,
  104. MISC_ACTIVE_SYNC,
  105. MISC_RNDIS_OVER_ETHERNET,
  106. MISC_RNDIS_OVER_WIFI,
  107. MISC_RNDIS_OVER_WIMAX,
  108. MISC_RNDIS_OVER_WWAN,
  109. MISC_RNDIS_FOR_IPV4,
  110. MISC_RNDIS_FOR_IPV6,
  111. MISC_RNDIS_FOR_GPRS,
  112. RNDIS_ID_MAX,
  113. };
  114. #define MAXQUEUELEN 128
  115. struct event_queue {
  116. u8 event[MAXQUEUELEN];
  117. u8 head, tail;
  118. spinlock_t q_lock;
  119. };
  120. struct gsi_ntb_info {
  121. __u32 ntb_input_size;
  122. __u16 ntb_max_datagrams;
  123. __u16 reserved;
  124. };
  125. struct gsi_ctrl_pkt {
  126. void *buf;
  127. int len;
  128. enum gsi_ctrl_notify_state type;
  129. struct list_head list;
  130. };
  131. struct gsi_function_bind_info {
  132. struct usb_string *string_defs;
  133. int ctrl_str_idx;
  134. int data_str_idx;
  135. int iad_str_idx;
  136. int mac_str_idx;
  137. struct usb_interface_descriptor *ctrl_desc;
  138. struct usb_interface_descriptor *data_desc;
  139. struct usb_interface_assoc_descriptor *iad_desc;
  140. struct usb_cdc_ether_desc *cdc_eth_desc;
  141. struct usb_cdc_union_desc *union_desc;
  142. struct usb_interface_descriptor *data_nop_desc;
  143. struct usb_endpoint_descriptor *fs_in_desc;
  144. struct usb_endpoint_descriptor *fs_out_desc;
  145. struct usb_endpoint_descriptor *fs_notify_desc;
  146. struct usb_endpoint_descriptor *hs_in_desc;
  147. struct usb_endpoint_descriptor *hs_out_desc;
  148. struct usb_endpoint_descriptor *hs_notify_desc;
  149. struct usb_endpoint_descriptor *ss_in_desc;
  150. struct usb_endpoint_descriptor *ss_out_desc;
  151. struct usb_endpoint_descriptor *ss_notify_desc;
  152. struct usb_descriptor_header **fs_desc_hdr;
  153. struct usb_descriptor_header **hs_desc_hdr;
  154. struct usb_descriptor_header **ss_desc_hdr;
  155. const char *in_epname;
  156. const char *out_epname;
  157. u32 in_req_buf_len;
  158. u32 in_req_num_buf;
  159. u32 out_req_buf_len;
  160. u32 out_req_num_buf;
  161. u32 notify_buf_len;
  162. };
  163. struct gsi_ctrl_port {
  164. char name[GSI_CTRL_NAME_LEN];
  165. struct cdev cdev;
  166. struct usb_ep *notify;
  167. struct usb_request *notify_req;
  168. bool notify_req_queued;
  169. atomic_t ctrl_online;
  170. bool is_open;
  171. wait_queue_head_t read_wq;
  172. struct list_head cpkt_req_q;
  173. struct list_head cpkt_resp_q;
  174. unsigned long cpkts_len;
  175. spinlock_t lock;
  176. int ipa_cons_clnt_hdl;
  177. int ipa_prod_clnt_hdl;
  178. unsigned int host_to_modem;
  179. unsigned int copied_to_modem;
  180. unsigned int copied_from_modem;
  181. unsigned int modem_to_host;
  182. unsigned int cpkt_drop_cnt;
  183. unsigned int get_encap_cnt;
  184. };
  185. struct gsi_data_port {
  186. struct usb_ep *in_ep;
  187. struct usb_ep *out_ep;
  188. struct usb_gsi_request in_request;
  189. struct usb_gsi_request out_request;
  190. struct usb_gadget *gadget;
  191. struct usb_composite_dev *cdev;
  192. int (*ipa_usb_notify_cb)(enum ipa_usb_notify_event, void *driver_data);
  193. struct ipa_usb_teth_params ipa_init_params;
  194. int in_channel_handle;
  195. int out_channel_handle;
  196. u32 in_xfer_rsc_index;
  197. u32 out_xfer_rsc_index;
  198. u16 in_last_trb_addr;
  199. u16 cdc_filter;
  200. u32 in_aggr_size;
  201. u32 out_aggr_size;
  202. bool ipa_ready;
  203. bool net_ready_trigger;
  204. struct gsi_ntb_info ntb_info;
  205. spinlock_t lock;
  206. struct delayed_work usb_ipa_w;
  207. struct workqueue_struct *ipa_usb_wq;
  208. enum connection_state sm_state;
  209. struct event_queue evt_q;
  210. wait_queue_head_t wait_for_ipa_ready;
  211. /* Track these for debugfs */
  212. struct ipa_usb_xdci_chan_params ipa_in_channel_params;
  213. struct ipa_usb_xdci_chan_params ipa_out_channel_params;
  214. struct ipa_usb_xdci_connect_params ipa_conn_pms;
  215. struct ipa_usb_ops *ipa_ops;
  216. };
  217. struct f_gsi {
  218. struct usb_function function;
  219. enum ipa_usb_teth_prot prot_id;
  220. int ctrl_id;
  221. int data_id;
  222. u32 vendorID;
  223. u8 ethaddr[ETH_ADDR_STR_LEN];
  224. const char *manufacturer;
  225. struct rndis_params *params;
  226. atomic_t connected;
  227. bool data_interface_up;
  228. enum rndis_class_id rndis_id;
  229. /* function suspend status */
  230. bool func_is_suspended;
  231. bool func_wakeup_allowed;
  232. const struct usb_endpoint_descriptor *in_ep_desc_backup;
  233. const struct usb_endpoint_descriptor *out_ep_desc_backup;
  234. struct gsi_data_port d_port;
  235. struct gsi_ctrl_port c_port;
  236. void *ipc_log_ctxt;
  237. bool rmnet_dtr_status;
  238. /* To test remote wakeup using debugfs */
  239. struct timer_list gsi_rw_timer;
  240. u8 debugfs_rw_timer_enable;
  241. u16 gsi_rw_timer_interval;
  242. bool host_supports_flow_control;
  243. };
  244. static inline struct f_gsi *func_to_gsi(struct usb_function *f)
  245. {
  246. return container_of(f, struct f_gsi, function);
  247. }
  248. static inline struct f_gsi *d_port_to_gsi(struct gsi_data_port *d)
  249. {
  250. return container_of(d, struct f_gsi, d_port);
  251. }
  252. static inline struct f_gsi *c_port_to_gsi(struct gsi_ctrl_port *d)
  253. {
  254. return container_of(d, struct f_gsi, c_port);
  255. }
  256. /* for configfs support */
  257. #define MAX_INST_NAME_LEN 40
  258. struct gsi_opts {
  259. struct usb_function_instance func_inst;
  260. struct f_gsi *gsi;
  261. };
  262. static inline struct gsi_opts *to_gsi_opts(struct config_item *item)
  263. {
  264. return container_of(to_config_group(item), struct gsi_opts,
  265. func_inst.group);
  266. }
  267. static enum ipa_usb_teth_prot name_to_prot_id(const char *name)
  268. {
  269. if (!name)
  270. goto error;
  271. if (!strncasecmp(name, "rndis", strlen("rndis")))
  272. return IPA_USB_RNDIS;
  273. if (!strncasecmp(name, "ecm", strlen("ecm")))
  274. return IPA_USB_ECM;
  275. if (!strncasecmp(name, "rmnet", strlen("rmnet")))
  276. return IPA_USB_RMNET;
  277. if (!strncasecmp(name, "mbim", strlen("mbim")))
  278. return IPA_USB_MBIM;
  279. if (!strncasecmp(name, "dpl", strlen("dpl")))
  280. return IPA_USB_DIAG;
  281. error:
  282. return -EINVAL;
  283. }
  284. /* device descriptors */
  285. #define LOG2_STATUS_INTERVAL_MSEC 5
  286. #define MAX_NOTIFY_SIZE sizeof(struct usb_cdc_notification)
  287. /* rmnet device descriptors */
  288. static struct usb_interface_descriptor rmnet_gsi_interface_desc = {
  289. .bLength = USB_DT_INTERFACE_SIZE,
  290. .bDescriptorType = USB_DT_INTERFACE,
  291. .bNumEndpoints = 3,
  292. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  293. .bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC,
  294. .bInterfaceProtocol = 0x50,
  295. /* .iInterface = DYNAMIC */
  296. };
  297. /* Full speed support */
  298. static struct usb_endpoint_descriptor rmnet_gsi_fs_notify_desc = {
  299. .bLength = USB_DT_ENDPOINT_SIZE,
  300. .bDescriptorType = USB_DT_ENDPOINT,
  301. .bEndpointAddress = USB_DIR_IN,
  302. .bmAttributes = USB_ENDPOINT_XFER_INT,
  303. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  304. .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
  305. };
  306. static struct usb_endpoint_descriptor rmnet_gsi_fs_in_desc = {
  307. .bLength = USB_DT_ENDPOINT_SIZE,
  308. .bDescriptorType = USB_DT_ENDPOINT,
  309. .bEndpointAddress = USB_DIR_IN,
  310. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  311. .wMaxPacketSize = cpu_to_le16(64),
  312. };
  313. static struct usb_endpoint_descriptor rmnet_gsi_fs_out_desc = {
  314. .bLength = USB_DT_ENDPOINT_SIZE,
  315. .bDescriptorType = USB_DT_ENDPOINT,
  316. .bEndpointAddress = USB_DIR_OUT,
  317. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  318. .wMaxPacketSize = cpu_to_le16(64),
  319. };
  320. static struct usb_descriptor_header *rmnet_gsi_fs_function[] = {
  321. (struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
  322. (struct usb_descriptor_header *) &rmnet_gsi_fs_notify_desc,
  323. (struct usb_descriptor_header *) &rmnet_gsi_fs_in_desc,
  324. (struct usb_descriptor_header *) &rmnet_gsi_fs_out_desc,
  325. NULL,
  326. };
  327. /* High speed support */
  328. static struct usb_endpoint_descriptor rmnet_gsi_hs_notify_desc = {
  329. .bLength = USB_DT_ENDPOINT_SIZE,
  330. .bDescriptorType = USB_DT_ENDPOINT,
  331. .bEndpointAddress = USB_DIR_IN,
  332. .bmAttributes = USB_ENDPOINT_XFER_INT,
  333. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  334. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  335. };
  336. static struct usb_endpoint_descriptor rmnet_gsi_hs_in_desc = {
  337. .bLength = USB_DT_ENDPOINT_SIZE,
  338. .bDescriptorType = USB_DT_ENDPOINT,
  339. .bEndpointAddress = USB_DIR_IN,
  340. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  341. .wMaxPacketSize = cpu_to_le16(512),
  342. };
  343. static struct usb_endpoint_descriptor rmnet_gsi_hs_out_desc = {
  344. .bLength = USB_DT_ENDPOINT_SIZE,
  345. .bDescriptorType = USB_DT_ENDPOINT,
  346. .bEndpointAddress = USB_DIR_OUT,
  347. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  348. .wMaxPacketSize = cpu_to_le16(512),
  349. };
  350. static struct usb_descriptor_header *rmnet_gsi_hs_function[] = {
  351. (struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
  352. (struct usb_descriptor_header *) &rmnet_gsi_hs_notify_desc,
  353. (struct usb_descriptor_header *) &rmnet_gsi_hs_in_desc,
  354. (struct usb_descriptor_header *) &rmnet_gsi_hs_out_desc,
  355. NULL,
  356. };
  357. /* Super speed support */
  358. static struct usb_endpoint_descriptor rmnet_gsi_ss_notify_desc = {
  359. .bLength = USB_DT_ENDPOINT_SIZE,
  360. .bDescriptorType = USB_DT_ENDPOINT,
  361. .bEndpointAddress = USB_DIR_IN,
  362. .bmAttributes = USB_ENDPOINT_XFER_INT,
  363. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  364. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  365. };
  366. static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_notify_comp_desc = {
  367. .bLength = sizeof(rmnet_gsi_ss_notify_comp_desc),
  368. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  369. /* the following 3 values can be tweaked if necessary */
  370. /* .bMaxBurst = 0, */
  371. /* .bmAttributes = 0, */
  372. .wBytesPerInterval = cpu_to_le16(MAX_NOTIFY_SIZE),
  373. };
  374. static struct usb_endpoint_descriptor rmnet_gsi_ss_in_desc = {
  375. .bLength = USB_DT_ENDPOINT_SIZE,
  376. .bDescriptorType = USB_DT_ENDPOINT,
  377. .bEndpointAddress = USB_DIR_IN,
  378. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  379. .wMaxPacketSize = cpu_to_le16(1024),
  380. };
  381. static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_in_comp_desc = {
  382. .bLength = sizeof(rmnet_gsi_ss_in_comp_desc),
  383. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  384. /* the following 2 values can be tweaked if necessary */
  385. .bMaxBurst = 6,
  386. /* .bmAttributes = 0, */
  387. };
  388. static struct usb_endpoint_descriptor rmnet_gsi_ss_out_desc = {
  389. .bLength = USB_DT_ENDPOINT_SIZE,
  390. .bDescriptorType = USB_DT_ENDPOINT,
  391. .bEndpointAddress = USB_DIR_OUT,
  392. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  393. .wMaxPacketSize = cpu_to_le16(1024),
  394. };
  395. static struct usb_ss_ep_comp_descriptor rmnet_gsi_ss_out_comp_desc = {
  396. .bLength = sizeof(rmnet_gsi_ss_out_comp_desc),
  397. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  398. /* the following 2 values can be tweaked if necessary */
  399. .bMaxBurst = 2,
  400. /* .bmAttributes = 0, */
  401. };
  402. static struct usb_descriptor_header *rmnet_gsi_ss_function[] = {
  403. (struct usb_descriptor_header *) &rmnet_gsi_interface_desc,
  404. (struct usb_descriptor_header *) &rmnet_gsi_ss_notify_desc,
  405. (struct usb_descriptor_header *) &rmnet_gsi_ss_notify_comp_desc,
  406. (struct usb_descriptor_header *) &rmnet_gsi_ss_in_desc,
  407. (struct usb_descriptor_header *) &rmnet_gsi_ss_in_comp_desc,
  408. (struct usb_descriptor_header *) &rmnet_gsi_ss_out_desc,
  409. (struct usb_descriptor_header *) &rmnet_gsi_ss_out_comp_desc,
  410. NULL,
  411. };
  412. /* String descriptors */
  413. static struct usb_string rmnet_gsi_string_defs[] = {
  414. [0].s = "RmNet",
  415. { } /* end of list */
  416. };
  417. static struct usb_gadget_strings rmnet_gsi_string_table = {
  418. .language = 0x0409, /* en-us */
  419. .strings = rmnet_gsi_string_defs,
  420. };
  421. static struct usb_gadget_strings *rmnet_gsi_strings[] = {
  422. &rmnet_gsi_string_table,
  423. NULL,
  424. };
  425. /* rndis device descriptors */
  426. /* interface descriptor: Supports "Wireless" RNDIS; auto-detected by Windows*/
  427. static struct usb_interface_descriptor rndis_gsi_control_intf = {
  428. .bLength = sizeof(rndis_gsi_control_intf),
  429. .bDescriptorType = USB_DT_INTERFACE,
  430. /* .bInterfaceNumber = DYNAMIC */
  431. /* status endpoint is optional; this could be patched later */
  432. .bNumEndpoints = 1,
  433. .bInterfaceClass = USB_CLASS_WIRELESS_CONTROLLER,
  434. .bInterfaceSubClass = 0x01,
  435. .bInterfaceProtocol = 0x03,
  436. /* .iInterface = DYNAMIC */
  437. };
  438. static struct usb_cdc_header_desc rndis_gsi_header_desc = {
  439. .bLength = sizeof(rndis_gsi_header_desc),
  440. .bDescriptorType = USB_DT_CS_INTERFACE,
  441. .bDescriptorSubType = USB_CDC_HEADER_TYPE,
  442. .bcdCDC = cpu_to_le16(0x0110),
  443. };
  444. static struct usb_cdc_call_mgmt_descriptor rndis_gsi_call_mgmt_descriptor = {
  445. .bLength = sizeof(rndis_gsi_call_mgmt_descriptor),
  446. .bDescriptorType = USB_DT_CS_INTERFACE,
  447. .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
  448. .bmCapabilities = 0x00,
  449. .bDataInterface = 0x01,
  450. };
  451. static struct usb_cdc_acm_descriptor rndis_gsi_acm_descriptor = {
  452. .bLength = sizeof(rndis_gsi_acm_descriptor),
  453. .bDescriptorType = USB_DT_CS_INTERFACE,
  454. .bDescriptorSubType = USB_CDC_ACM_TYPE,
  455. .bmCapabilities = 0x00,
  456. };
  457. static struct usb_cdc_union_desc rndis_gsi_union_desc = {
  458. .bLength = sizeof(rndis_gsi_union_desc),
  459. .bDescriptorType = USB_DT_CS_INTERFACE,
  460. .bDescriptorSubType = USB_CDC_UNION_TYPE,
  461. /* .bMasterInterface0 = DYNAMIC */
  462. /* .bSlaveInterface0 = DYNAMIC */
  463. };
  464. /* the data interface has two bulk endpoints */
  465. static struct usb_interface_descriptor rndis_gsi_data_intf = {
  466. .bLength = sizeof(rndis_gsi_data_intf),
  467. .bDescriptorType = USB_DT_INTERFACE,
  468. /* .bInterfaceNumber = DYNAMIC */
  469. .bNumEndpoints = 2,
  470. .bInterfaceClass = USB_CLASS_CDC_DATA,
  471. .bInterfaceSubClass = 0,
  472. .bInterfaceProtocol = 0,
  473. /* .iInterface = DYNAMIC */
  474. };
  475. /* Supports "Wireless" RNDIS; auto-detected by Windows */
  476. static struct usb_interface_assoc_descriptor
  477. rndis_gsi_iad_descriptor = {
  478. .bLength = sizeof(rndis_gsi_iad_descriptor),
  479. .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
  480. .bFirstInterface = 0, /* XXX, hardcoded */
  481. .bInterfaceCount = 2, /* control + data */
  482. .bFunctionClass = USB_CLASS_WIRELESS_CONTROLLER,
  483. .bFunctionSubClass = 0x01,
  484. .bFunctionProtocol = 0x03,
  485. /* .iFunction = DYNAMIC */
  486. };
  487. /* full speed support: */
  488. static struct usb_endpoint_descriptor rndis_gsi_fs_notify_desc = {
  489. .bLength = USB_DT_ENDPOINT_SIZE,
  490. .bDescriptorType = USB_DT_ENDPOINT,
  491. .bEndpointAddress = USB_DIR_IN,
  492. .bmAttributes = USB_ENDPOINT_XFER_INT,
  493. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  494. .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
  495. };
  496. static struct usb_endpoint_descriptor rndis_gsi_fs_in_desc = {
  497. .bLength = USB_DT_ENDPOINT_SIZE,
  498. .bDescriptorType = USB_DT_ENDPOINT,
  499. .wMaxPacketSize = cpu_to_le16(64),
  500. .bEndpointAddress = USB_DIR_IN,
  501. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  502. };
  503. static struct usb_endpoint_descriptor rndis_gsi_fs_out_desc = {
  504. .bLength = USB_DT_ENDPOINT_SIZE,
  505. .bDescriptorType = USB_DT_ENDPOINT,
  506. .wMaxPacketSize = cpu_to_le16(64),
  507. .bEndpointAddress = USB_DIR_OUT,
  508. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  509. };
  510. static struct usb_descriptor_header *gsi_eth_fs_function[] = {
  511. (struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
  512. /* control interface matches ACM, not Ethernet */
  513. (struct usb_descriptor_header *) &rndis_gsi_control_intf,
  514. (struct usb_descriptor_header *) &rndis_gsi_header_desc,
  515. (struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
  516. (struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
  517. (struct usb_descriptor_header *) &rndis_gsi_union_desc,
  518. (struct usb_descriptor_header *) &rndis_gsi_fs_notify_desc,
  519. /* data interface has no altsetting */
  520. (struct usb_descriptor_header *) &rndis_gsi_data_intf,
  521. (struct usb_descriptor_header *) &rndis_gsi_fs_in_desc,
  522. (struct usb_descriptor_header *) &rndis_gsi_fs_out_desc,
  523. NULL,
  524. };
  525. /* high speed support: */
  526. static struct usb_endpoint_descriptor rndis_gsi_hs_notify_desc = {
  527. .bLength = USB_DT_ENDPOINT_SIZE,
  528. .bDescriptorType = USB_DT_ENDPOINT,
  529. .bEndpointAddress = USB_DIR_IN,
  530. .bmAttributes = USB_ENDPOINT_XFER_INT,
  531. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  532. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  533. };
  534. static struct usb_endpoint_descriptor rndis_gsi_hs_in_desc = {
  535. .bLength = USB_DT_ENDPOINT_SIZE,
  536. .bDescriptorType = USB_DT_ENDPOINT,
  537. .bEndpointAddress = USB_DIR_IN,
  538. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  539. .wMaxPacketSize = cpu_to_le16(512),
  540. };
  541. static struct usb_endpoint_descriptor rndis_gsi_hs_out_desc = {
  542. .bLength = USB_DT_ENDPOINT_SIZE,
  543. .bDescriptorType = USB_DT_ENDPOINT,
  544. .bEndpointAddress = USB_DIR_OUT,
  545. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  546. .wMaxPacketSize = cpu_to_le16(512),
  547. };
  548. static struct usb_descriptor_header *gsi_eth_hs_function[] = {
  549. (struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
  550. /* control interface matches ACM, not Ethernet */
  551. (struct usb_descriptor_header *) &rndis_gsi_control_intf,
  552. (struct usb_descriptor_header *) &rndis_gsi_header_desc,
  553. (struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
  554. (struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
  555. (struct usb_descriptor_header *) &rndis_gsi_union_desc,
  556. (struct usb_descriptor_header *) &rndis_gsi_hs_notify_desc,
  557. /* data interface has no altsetting */
  558. (struct usb_descriptor_header *) &rndis_gsi_data_intf,
  559. (struct usb_descriptor_header *) &rndis_gsi_hs_in_desc,
  560. (struct usb_descriptor_header *) &rndis_gsi_hs_out_desc,
  561. NULL,
  562. };
  563. /* super speed support: */
  564. static struct usb_endpoint_descriptor rndis_gsi_ss_notify_desc = {
  565. .bLength = USB_DT_ENDPOINT_SIZE,
  566. .bDescriptorType = USB_DT_ENDPOINT,
  567. .bEndpointAddress = USB_DIR_IN,
  568. .bmAttributes = USB_ENDPOINT_XFER_INT,
  569. .wMaxPacketSize = cpu_to_le16(MAX_NOTIFY_SIZE),
  570. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  571. };
  572. static struct usb_ss_ep_comp_descriptor rndis_gsi_ss_intr_comp_desc = {
  573. .bLength = sizeof(rndis_gsi_ss_intr_comp_desc),
  574. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  575. /* the following 3 values can be tweaked if necessary */
  576. /* .bMaxBurst = 0, */
  577. /* .bmAttributes = 0, */
  578. .wBytesPerInterval = cpu_to_le16(MAX_NOTIFY_SIZE),
  579. };
  580. static struct usb_endpoint_descriptor rndis_gsi_ss_in_desc = {
  581. .bLength = USB_DT_ENDPOINT_SIZE,
  582. .bDescriptorType = USB_DT_ENDPOINT,
  583. .bEndpointAddress = USB_DIR_IN,
  584. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  585. .wMaxPacketSize = cpu_to_le16(1024),
  586. };
  587. static struct usb_endpoint_descriptor rndis_gsi_ss_out_desc = {
  588. .bLength = USB_DT_ENDPOINT_SIZE,
  589. .bDescriptorType = USB_DT_ENDPOINT,
  590. .bEndpointAddress = USB_DIR_OUT,
  591. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  592. .wMaxPacketSize = cpu_to_le16(1024),
  593. };
  594. static struct usb_ss_ep_comp_descriptor rndis_gsi_ss_bulk_comp_desc = {
  595. .bLength = sizeof(rndis_gsi_ss_bulk_comp_desc),
  596. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  597. /* the following 2 values can be tweaked if necessary */
  598. .bMaxBurst = 6,
  599. /* .bmAttributes = 0, */
  600. };
  601. static struct usb_descriptor_header *gsi_eth_ss_function[] = {
  602. (struct usb_descriptor_header *) &rndis_gsi_iad_descriptor,
  603. /* control interface matches ACM, not Ethernet */
  604. (struct usb_descriptor_header *) &rndis_gsi_control_intf,
  605. (struct usb_descriptor_header *) &rndis_gsi_header_desc,
  606. (struct usb_descriptor_header *) &rndis_gsi_call_mgmt_descriptor,
  607. (struct usb_descriptor_header *) &rndis_gsi_acm_descriptor,
  608. (struct usb_descriptor_header *) &rndis_gsi_union_desc,
  609. (struct usb_descriptor_header *) &rndis_gsi_ss_notify_desc,
  610. (struct usb_descriptor_header *) &rndis_gsi_ss_intr_comp_desc,
  611. /* data interface has no altsetting */
  612. (struct usb_descriptor_header *) &rndis_gsi_data_intf,
  613. (struct usb_descriptor_header *) &rndis_gsi_ss_in_desc,
  614. (struct usb_descriptor_header *) &rndis_gsi_ss_bulk_comp_desc,
  615. (struct usb_descriptor_header *) &rndis_gsi_ss_out_desc,
  616. (struct usb_descriptor_header *) &rndis_gsi_ss_bulk_comp_desc,
  617. NULL,
  618. };
  619. /* string descriptors: */
  620. static struct usb_string rndis_gsi_string_defs[] = {
  621. [0].s = "RNDIS Communications Control",
  622. [1].s = "RNDIS Ethernet Data",
  623. [2].s = "RNDIS",
  624. { } /* end of list */
  625. };
  626. static struct usb_gadget_strings rndis_gsi_string_table = {
  627. .language = 0x0409, /* en-us */
  628. .strings = rndis_gsi_string_defs,
  629. };
  630. static struct usb_gadget_strings *rndis_gsi_strings[] = {
  631. &rndis_gsi_string_table,
  632. NULL,
  633. };
  634. /* mbim device descriptors */
  635. #define MBIM_NTB_DEFAULT_IN_SIZE (0x4000)
  636. static struct usb_cdc_ncm_ntb_parameters mbim_gsi_ntb_parameters = {
  637. .wLength = cpu_to_le16(sizeof(mbim_gsi_ntb_parameters)),
  638. .bmNtbFormatsSupported = cpu_to_le16(USB_CDC_NCM_NTB16_SUPPORTED),
  639. .dwNtbInMaxSize = cpu_to_le32(MBIM_NTB_DEFAULT_IN_SIZE),
  640. .wNdpInDivisor = cpu_to_le16(4),
  641. .wNdpInPayloadRemainder = cpu_to_le16(0),
  642. .wNdpInAlignment = cpu_to_le16(4),
  643. .dwNtbOutMaxSize = cpu_to_le32(0x4000),
  644. .wNdpOutDivisor = cpu_to_le16(4),
  645. .wNdpOutPayloadRemainder = cpu_to_le16(0),
  646. .wNdpOutAlignment = cpu_to_le16(4),
  647. .wNtbOutMaxDatagrams = cpu_to_le16(16),
  648. };
  649. /*
  650. * Use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one
  651. * packet, to simplify cancellation;
  652. */
  653. #define NCM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
  654. static struct usb_interface_assoc_descriptor mbim_gsi_iad_desc = {
  655. .bLength = sizeof(mbim_gsi_iad_desc),
  656. .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
  657. /* .bFirstInterface = DYNAMIC, */
  658. .bInterfaceCount = 2, /* control + data */
  659. .bFunctionClass = 2,
  660. .bFunctionSubClass = 0x0e,
  661. .bFunctionProtocol = 0,
  662. /* .iFunction = DYNAMIC */
  663. };
  664. /* interface descriptor: */
  665. static struct usb_interface_descriptor mbim_gsi_control_intf = {
  666. .bLength = sizeof(mbim_gsi_control_intf),
  667. .bDescriptorType = USB_DT_INTERFACE,
  668. /* .bInterfaceNumber = DYNAMIC */
  669. .bNumEndpoints = 1,
  670. .bInterfaceClass = 0x02,
  671. .bInterfaceSubClass = 0x0e,
  672. .bInterfaceProtocol = 0,
  673. /* .iInterface = DYNAMIC */
  674. };
  675. static struct usb_cdc_header_desc mbim_gsi_header_desc = {
  676. .bLength = sizeof(mbim_gsi_header_desc),
  677. .bDescriptorType = USB_DT_CS_INTERFACE,
  678. .bDescriptorSubType = USB_CDC_HEADER_TYPE,
  679. .bcdCDC = cpu_to_le16(0x0110),
  680. };
  681. static struct usb_cdc_union_desc mbim_gsi_union_desc = {
  682. .bLength = sizeof(mbim_gsi_union_desc),
  683. .bDescriptorType = USB_DT_CS_INTERFACE,
  684. .bDescriptorSubType = USB_CDC_UNION_TYPE,
  685. /* .bMasterInterface0 = DYNAMIC */
  686. /* .bSlaveInterface0 = DYNAMIC */
  687. };
  688. static struct usb_cdc_mbim_desc mbim_gsi_desc = {
  689. .bLength = sizeof(mbim_gsi_desc),
  690. .bDescriptorType = USB_DT_CS_INTERFACE,
  691. .bDescriptorSubType = USB_CDC_MBIM_TYPE,
  692. .bcdMBIMVersion = cpu_to_le16(0x0100),
  693. .wMaxControlMessage = cpu_to_le16(0x1000),
  694. .bNumberFilters = 0x20,
  695. .bMaxFilterSize = 0x80,
  696. .wMaxSegmentSize = cpu_to_le16(0xfe0),
  697. .bmNetworkCapabilities = 0x20,
  698. };
  699. static struct usb_cdc_mbim_extended_desc mbim_gsi_ext_mbb_desc = {
  700. .bLength = sizeof(mbim_gsi_ext_mbb_desc),
  701. .bDescriptorType = USB_DT_CS_INTERFACE,
  702. .bDescriptorSubType = USB_CDC_MBIM_EXTENDED_TYPE,
  703. .bcdMBIMExtendedVersion = cpu_to_le16(0x0100),
  704. .bMaxOutstandingCommandMessages = 64,
  705. .wMTU = cpu_to_le16(1500),
  706. };
  707. /* the default data interface has no endpoints ... */
  708. static struct usb_interface_descriptor mbim_gsi_data_nop_intf = {
  709. .bLength = sizeof(mbim_gsi_data_nop_intf),
  710. .bDescriptorType = USB_DT_INTERFACE,
  711. /* .bInterfaceNumber = DYNAMIC */
  712. .bAlternateSetting = 0,
  713. .bNumEndpoints = 0,
  714. .bInterfaceClass = 0x0a,
  715. .bInterfaceSubClass = 0,
  716. .bInterfaceProtocol = 0x02,
  717. /* .iInterface = DYNAMIC */
  718. };
  719. /* ... but the "real" data interface has two bulk endpoints */
  720. static struct usb_interface_descriptor mbim_gsi_data_intf = {
  721. .bLength = sizeof(mbim_gsi_data_intf),
  722. .bDescriptorType = USB_DT_INTERFACE,
  723. /* .bInterfaceNumber = DYNAMIC */
  724. .bAlternateSetting = 1,
  725. .bNumEndpoints = 2,
  726. .bInterfaceClass = 0x0a,
  727. .bInterfaceSubClass = 0,
  728. .bInterfaceProtocol = 0x02,
  729. /* .iInterface = DYNAMIC */
  730. };
  731. /* full speed support: */
  732. static struct usb_endpoint_descriptor mbim_gsi_fs_notify_desc = {
  733. .bLength = USB_DT_ENDPOINT_SIZE,
  734. .bDescriptorType = USB_DT_ENDPOINT,
  735. .bEndpointAddress = USB_DIR_IN,
  736. .bmAttributes = USB_ENDPOINT_XFER_INT,
  737. .wMaxPacketSize = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  738. .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
  739. };
  740. static struct usb_endpoint_descriptor mbim_gsi_fs_in_desc = {
  741. .bLength = USB_DT_ENDPOINT_SIZE,
  742. .bDescriptorType = USB_DT_ENDPOINT,
  743. .bEndpointAddress = USB_DIR_IN,
  744. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  745. .wMaxPacketSize = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  746. };
  747. static struct usb_endpoint_descriptor mbim_gsi_fs_out_desc = {
  748. .bLength = USB_DT_ENDPOINT_SIZE,
  749. .bDescriptorType = USB_DT_ENDPOINT,
  750. .bEndpointAddress = USB_DIR_OUT,
  751. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  752. .wMaxPacketSize = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  753. };
  754. static struct usb_descriptor_header *mbim_gsi_fs_function[] = {
  755. (struct usb_descriptor_header *) &mbim_gsi_iad_desc,
  756. /* MBIM control descriptors */
  757. (struct usb_descriptor_header *) &mbim_gsi_control_intf,
  758. (struct usb_descriptor_header *) &mbim_gsi_header_desc,
  759. (struct usb_descriptor_header *) &mbim_gsi_union_desc,
  760. (struct usb_descriptor_header *) &mbim_gsi_desc,
  761. (struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
  762. (struct usb_descriptor_header *) &mbim_gsi_fs_notify_desc,
  763. /* data interface, altsettings 0 and 1 */
  764. (struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
  765. (struct usb_descriptor_header *) &mbim_gsi_data_intf,
  766. (struct usb_descriptor_header *) &mbim_gsi_fs_in_desc,
  767. (struct usb_descriptor_header *) &mbim_gsi_fs_out_desc,
  768. NULL,
  769. };
  770. /* high speed support: */
  771. static struct usb_endpoint_descriptor mbim_gsi_hs_notify_desc = {
  772. .bLength = USB_DT_ENDPOINT_SIZE,
  773. .bDescriptorType = USB_DT_ENDPOINT,
  774. .bEndpointAddress = USB_DIR_IN,
  775. .bmAttributes = USB_ENDPOINT_XFER_INT,
  776. .wMaxPacketSize = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  777. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  778. };
  779. static struct usb_endpoint_descriptor mbim_gsi_hs_in_desc = {
  780. .bLength = USB_DT_ENDPOINT_SIZE,
  781. .bDescriptorType = USB_DT_ENDPOINT,
  782. .bEndpointAddress = USB_DIR_IN,
  783. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  784. .wMaxPacketSize = cpu_to_le16(512),
  785. };
  786. static struct usb_endpoint_descriptor mbim_gsi_hs_out_desc = {
  787. .bLength = USB_DT_ENDPOINT_SIZE,
  788. .bDescriptorType = USB_DT_ENDPOINT,
  789. .bEndpointAddress = USB_DIR_OUT,
  790. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  791. .wMaxPacketSize = cpu_to_le16(512),
  792. };
  793. static struct usb_descriptor_header *mbim_gsi_hs_function[] = {
  794. (struct usb_descriptor_header *) &mbim_gsi_iad_desc,
  795. /* MBIM control descriptors */
  796. (struct usb_descriptor_header *) &mbim_gsi_control_intf,
  797. (struct usb_descriptor_header *) &mbim_gsi_header_desc,
  798. (struct usb_descriptor_header *) &mbim_gsi_union_desc,
  799. (struct usb_descriptor_header *) &mbim_gsi_desc,
  800. (struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
  801. (struct usb_descriptor_header *) &mbim_gsi_hs_notify_desc,
  802. /* data interface, altsettings 0 and 1 */
  803. (struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
  804. (struct usb_descriptor_header *) &mbim_gsi_data_intf,
  805. (struct usb_descriptor_header *) &mbim_gsi_hs_in_desc,
  806. (struct usb_descriptor_header *) &mbim_gsi_hs_out_desc,
  807. NULL,
  808. };
  809. /* Super Speed Support */
  810. static struct usb_endpoint_descriptor mbim_gsi_ss_notify_desc = {
  811. .bLength = USB_DT_ENDPOINT_SIZE,
  812. .bDescriptorType = USB_DT_ENDPOINT,
  813. .bEndpointAddress = USB_DIR_IN,
  814. .bmAttributes = USB_ENDPOINT_XFER_INT,
  815. .wMaxPacketSize = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  816. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  817. };
  818. static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_notify_comp_desc = {
  819. .bLength = sizeof(mbim_gsi_ss_notify_comp_desc),
  820. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  821. /* the following 3 values can be tweaked if necessary */
  822. /* .bMaxBurst = 0, */
  823. /* .bmAttributes = 0, */
  824. .wBytesPerInterval = cpu_to_le16(4 * NCM_STATUS_BYTECOUNT),
  825. };
  826. static struct usb_endpoint_descriptor mbim_gsi_ss_in_desc = {
  827. .bLength = USB_DT_ENDPOINT_SIZE,
  828. .bDescriptorType = USB_DT_ENDPOINT,
  829. .bEndpointAddress = USB_DIR_IN,
  830. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  831. .wMaxPacketSize = cpu_to_le16(1024),
  832. };
  833. static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_in_comp_desc = {
  834. .bLength = sizeof(mbim_gsi_ss_in_comp_desc),
  835. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  836. /* the following 2 values can be tweaked if necessary */
  837. .bMaxBurst = 6,
  838. /* .bmAttributes = 0, */
  839. };
  840. static struct usb_endpoint_descriptor mbim_gsi_ss_out_desc = {
  841. .bLength = USB_DT_ENDPOINT_SIZE,
  842. .bDescriptorType = USB_DT_ENDPOINT,
  843. .bEndpointAddress = USB_DIR_OUT,
  844. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  845. .wMaxPacketSize = cpu_to_le16(1024),
  846. };
  847. static struct usb_ss_ep_comp_descriptor mbim_gsi_ss_out_comp_desc = {
  848. .bLength = sizeof(mbim_gsi_ss_out_comp_desc),
  849. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  850. /* the following 2 values can be tweaked if necessary */
  851. .bMaxBurst = 2,
  852. /* .bmAttributes = 0, */
  853. };
  854. static struct usb_descriptor_header *mbim_gsi_ss_function[] = {
  855. (struct usb_descriptor_header *) &mbim_gsi_iad_desc,
  856. /* MBIM control descriptors */
  857. (struct usb_descriptor_header *) &mbim_gsi_control_intf,
  858. (struct usb_descriptor_header *) &mbim_gsi_header_desc,
  859. (struct usb_descriptor_header *) &mbim_gsi_union_desc,
  860. (struct usb_descriptor_header *) &mbim_gsi_desc,
  861. (struct usb_descriptor_header *) &mbim_gsi_ext_mbb_desc,
  862. (struct usb_descriptor_header *) &mbim_gsi_ss_notify_desc,
  863. (struct usb_descriptor_header *) &mbim_gsi_ss_notify_comp_desc,
  864. /* data interface, altsettings 0 and 1 */
  865. (struct usb_descriptor_header *) &mbim_gsi_data_nop_intf,
  866. (struct usb_descriptor_header *) &mbim_gsi_data_intf,
  867. (struct usb_descriptor_header *) &mbim_gsi_ss_in_desc,
  868. (struct usb_descriptor_header *) &mbim_gsi_ss_in_comp_desc,
  869. (struct usb_descriptor_header *) &mbim_gsi_ss_out_desc,
  870. (struct usb_descriptor_header *) &mbim_gsi_ss_out_comp_desc,
  871. NULL,
  872. };
  873. /* string descriptors: */
  874. static struct usb_string mbim_gsi_string_defs[] = {
  875. [0].s = "MBIM Control",
  876. [1].s = "MBIM Data",
  877. { } /* end of list */
  878. };
  879. static struct usb_gadget_strings mbim_gsi_string_table = {
  880. .language = 0x0409, /* en-us */
  881. .strings = mbim_gsi_string_defs,
  882. };
  883. static struct usb_gadget_strings *mbim_gsi_strings[] = {
  884. &mbim_gsi_string_table,
  885. NULL,
  886. };
  887. /* Microsoft OS Descriptors */
  888. /*
  889. * We specify our own bMS_VendorCode byte which Windows will use
  890. * as the bRequest value in subsequent device get requests.
  891. */
  892. #define MBIM_VENDOR_CODE 0xA5
  893. /* Microsoft Extended Configuration Descriptor Header Section */
  894. struct mbim_gsi_ext_config_desc_header {
  895. __le32 dwLength;
  896. __le16 bcdVersion;
  897. __le16 wIndex;
  898. __u8 bCount;
  899. __u8 reserved[7];
  900. };
  901. /* Microsoft Extended Configuration Descriptor Function Section */
  902. struct mbim_gsi_ext_config_desc_function {
  903. __u8 bFirstInterfaceNumber;
  904. __u8 bInterfaceCount;
  905. __u8 compatibleID[8];
  906. __u8 subCompatibleID[8];
  907. __u8 reserved[6];
  908. };
  909. /* Microsoft Extended Configuration Descriptor */
  910. static struct {
  911. struct mbim_gsi_ext_config_desc_header header;
  912. struct mbim_gsi_ext_config_desc_function function;
  913. } mbim_gsi_ext_config_desc = {
  914. .header = {
  915. .dwLength = cpu_to_le32(sizeof(mbim_gsi_ext_config_desc)),
  916. .bcdVersion = cpu_to_le16(0x0100),
  917. .wIndex = cpu_to_le16(4),
  918. .bCount = 1,
  919. },
  920. .function = {
  921. .bFirstInterfaceNumber = 0,
  922. .bInterfaceCount = 1,
  923. .compatibleID = { 'A', 'L', 'T', 'R', 'C', 'F', 'G' },
  924. /* .subCompatibleID = DYNAMIC */
  925. },
  926. };
  927. /* ecm device descriptors */
  928. #define ECM_QC_LOG2_STATUS_INTERVAL_MSEC 5
  929. #define ECM_QC_STATUS_BYTECOUNT 16 /* 8 byte header + data */
  930. /* interface descriptor: */
  931. static struct usb_interface_descriptor ecm_gsi_control_intf = {
  932. .bLength = sizeof(ecm_gsi_control_intf),
  933. .bDescriptorType = USB_DT_INTERFACE,
  934. /* .bInterfaceNumber = DYNAMIC */
  935. /* status endpoint is optional; this could be patched later */
  936. .bNumEndpoints = 1,
  937. .bInterfaceClass = USB_CLASS_COMM,
  938. .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET,
  939. .bInterfaceProtocol = USB_CDC_PROTO_NONE,
  940. /* .iInterface = DYNAMIC */
  941. };
  942. static struct usb_cdc_header_desc ecm_gsi_header_desc = {
  943. .bLength = sizeof(ecm_gsi_header_desc),
  944. .bDescriptorType = USB_DT_CS_INTERFACE,
  945. .bDescriptorSubType = USB_CDC_HEADER_TYPE,
  946. .bcdCDC = cpu_to_le16(0x0110),
  947. };
  948. static struct usb_cdc_union_desc ecm_gsi_union_desc = {
  949. .bLength = sizeof(ecm_gsi_union_desc),
  950. .bDescriptorType = USB_DT_CS_INTERFACE,
  951. .bDescriptorSubType = USB_CDC_UNION_TYPE,
  952. /* .bMasterInterface0 = DYNAMIC */
  953. /* .bSlaveInterface0 = DYNAMIC */
  954. };
  955. static struct usb_cdc_ether_desc ecm_gsi_desc = {
  956. .bLength = sizeof(ecm_gsi_desc),
  957. .bDescriptorType = USB_DT_CS_INTERFACE,
  958. .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
  959. /* this descriptor actually adds value, surprise! */
  960. /* .iMACAddress = DYNAMIC */
  961. .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
  962. .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
  963. .wNumberMCFilters = cpu_to_le16(0),
  964. .bNumberPowerFilters = 0,
  965. };
  966. /* the default data interface has no endpoints ... */
  967. static struct usb_interface_descriptor ecm_gsi_data_nop_intf = {
  968. .bLength = sizeof(ecm_gsi_data_nop_intf),
  969. .bDescriptorType = USB_DT_INTERFACE,
  970. .bInterfaceNumber = 1,
  971. .bAlternateSetting = 0,
  972. .bNumEndpoints = 0,
  973. .bInterfaceClass = USB_CLASS_CDC_DATA,
  974. .bInterfaceSubClass = 0,
  975. .bInterfaceProtocol = 0,
  976. /* .iInterface = DYNAMIC */
  977. };
  978. /* ... but the "real" data interface has two bulk endpoints */
  979. static struct usb_interface_descriptor ecm_gsi_data_intf = {
  980. .bLength = sizeof(ecm_gsi_data_intf),
  981. .bDescriptorType = USB_DT_INTERFACE,
  982. .bInterfaceNumber = 1,
  983. .bAlternateSetting = 1,
  984. .bNumEndpoints = 2,
  985. .bInterfaceClass = USB_CLASS_CDC_DATA,
  986. .bInterfaceSubClass = 0,
  987. .bInterfaceProtocol = 0,
  988. /* .iInterface = DYNAMIC */
  989. };
  990. /* full speed support: */
  991. static struct usb_endpoint_descriptor ecm_gsi_fs_notify_desc = {
  992. .bLength = USB_DT_ENDPOINT_SIZE,
  993. .bDescriptorType = USB_DT_ENDPOINT,
  994. .bEndpointAddress = USB_DIR_IN,
  995. .bmAttributes = USB_ENDPOINT_XFER_INT,
  996. .wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  997. .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
  998. };
  999. static struct usb_endpoint_descriptor ecm_gsi_fs_in_desc = {
  1000. .bLength = USB_DT_ENDPOINT_SIZE,
  1001. .bDescriptorType = USB_DT_ENDPOINT,
  1002. .bEndpointAddress = USB_DIR_IN,
  1003. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1004. .wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  1005. };
  1006. static struct usb_endpoint_descriptor ecm_gsi_fs_out_desc = {
  1007. .bLength = USB_DT_ENDPOINT_SIZE,
  1008. .bDescriptorType = USB_DT_ENDPOINT,
  1009. .bEndpointAddress = USB_DIR_OUT,
  1010. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1011. .wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  1012. };
  1013. static struct usb_descriptor_header *ecm_gsi_fs_function[] = {
  1014. /* CDC ECM control descriptors */
  1015. (struct usb_descriptor_header *) &ecm_gsi_control_intf,
  1016. (struct usb_descriptor_header *) &ecm_gsi_header_desc,
  1017. (struct usb_descriptor_header *) &ecm_gsi_union_desc,
  1018. (struct usb_descriptor_header *) &ecm_gsi_desc,
  1019. /* NOTE: status endpoint might need to be removed */
  1020. (struct usb_descriptor_header *) &ecm_gsi_fs_notify_desc,
  1021. /* data interface, altsettings 0 and 1 */
  1022. (struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
  1023. (struct usb_descriptor_header *) &ecm_gsi_data_intf,
  1024. (struct usb_descriptor_header *) &ecm_gsi_fs_in_desc,
  1025. (struct usb_descriptor_header *) &ecm_gsi_fs_out_desc,
  1026. NULL,
  1027. };
  1028. /* high speed support: */
  1029. static struct usb_endpoint_descriptor ecm_gsi_hs_notify_desc = {
  1030. .bLength = USB_DT_ENDPOINT_SIZE,
  1031. .bDescriptorType = USB_DT_ENDPOINT,
  1032. .bEndpointAddress = USB_DIR_IN,
  1033. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1034. .wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  1035. .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
  1036. };
  1037. static struct usb_endpoint_descriptor ecm_gsi_hs_in_desc = {
  1038. .bLength = USB_DT_ENDPOINT_SIZE,
  1039. .bDescriptorType = USB_DT_ENDPOINT,
  1040. .bEndpointAddress = USB_DIR_IN,
  1041. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1042. .wMaxPacketSize = cpu_to_le16(512),
  1043. };
  1044. static struct usb_endpoint_descriptor ecm_gsi_hs_out_desc = {
  1045. .bLength = USB_DT_ENDPOINT_SIZE,
  1046. .bDescriptorType = USB_DT_ENDPOINT,
  1047. .bEndpointAddress = USB_DIR_OUT,
  1048. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1049. .wMaxPacketSize = cpu_to_le16(512),
  1050. };
  1051. static struct usb_descriptor_header *ecm_gsi_hs_function[] = {
  1052. /* CDC ECM control descriptors */
  1053. (struct usb_descriptor_header *) &ecm_gsi_control_intf,
  1054. (struct usb_descriptor_header *) &ecm_gsi_header_desc,
  1055. (struct usb_descriptor_header *) &ecm_gsi_union_desc,
  1056. (struct usb_descriptor_header *) &ecm_gsi_desc,
  1057. /* NOTE: status endpoint might need to be removed */
  1058. (struct usb_descriptor_header *) &ecm_gsi_hs_notify_desc,
  1059. /* data interface, altsettings 0 and 1 */
  1060. (struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
  1061. (struct usb_descriptor_header *) &ecm_gsi_data_intf,
  1062. (struct usb_descriptor_header *) &ecm_gsi_hs_in_desc,
  1063. (struct usb_descriptor_header *) &ecm_gsi_hs_out_desc,
  1064. NULL,
  1065. };
  1066. static struct usb_endpoint_descriptor ecm_gsi_ss_notify_desc = {
  1067. .bLength = USB_DT_ENDPOINT_SIZE,
  1068. .bDescriptorType = USB_DT_ENDPOINT,
  1069. .bEndpointAddress = USB_DIR_IN,
  1070. .bmAttributes = USB_ENDPOINT_XFER_INT,
  1071. .wMaxPacketSize = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  1072. .bInterval = ECM_QC_LOG2_STATUS_INTERVAL_MSEC + 4,
  1073. };
  1074. static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_notify_comp_desc = {
  1075. .bLength = sizeof(ecm_gsi_ss_notify_comp_desc),
  1076. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  1077. /* the following 3 values can be tweaked if necessary */
  1078. /* .bMaxBurst = 0, */
  1079. /* .bmAttributes = 0, */
  1080. .wBytesPerInterval = cpu_to_le16(ECM_QC_STATUS_BYTECOUNT),
  1081. };
  1082. static struct usb_endpoint_descriptor ecm_gsi_ss_in_desc = {
  1083. .bLength = USB_DT_ENDPOINT_SIZE,
  1084. .bDescriptorType = USB_DT_ENDPOINT,
  1085. .bEndpointAddress = USB_DIR_IN,
  1086. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1087. .wMaxPacketSize = cpu_to_le16(1024),
  1088. };
  1089. static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_in_comp_desc = {
  1090. .bLength = sizeof(ecm_gsi_ss_in_comp_desc),
  1091. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  1092. /* the following 2 values can be tweaked if necessary */
  1093. .bMaxBurst = 6,
  1094. /* .bmAttributes = 0, */
  1095. };
  1096. static struct usb_endpoint_descriptor ecm_gsi_ss_out_desc = {
  1097. .bLength = USB_DT_ENDPOINT_SIZE,
  1098. .bDescriptorType = USB_DT_ENDPOINT,
  1099. .bEndpointAddress = USB_DIR_OUT,
  1100. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1101. .wMaxPacketSize = cpu_to_le16(1024),
  1102. };
  1103. static struct usb_ss_ep_comp_descriptor ecm_gsi_ss_out_comp_desc = {
  1104. .bLength = sizeof(ecm_gsi_ss_out_comp_desc),
  1105. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  1106. /* the following 2 values can be tweaked if necessary */
  1107. .bMaxBurst = 2,
  1108. /* .bmAttributes = 0, */
  1109. };
  1110. static struct usb_descriptor_header *ecm_gsi_ss_function[] = {
  1111. /* CDC ECM control descriptors */
  1112. (struct usb_descriptor_header *) &ecm_gsi_control_intf,
  1113. (struct usb_descriptor_header *) &ecm_gsi_header_desc,
  1114. (struct usb_descriptor_header *) &ecm_gsi_union_desc,
  1115. (struct usb_descriptor_header *) &ecm_gsi_desc,
  1116. /* NOTE: status endpoint might need to be removed */
  1117. (struct usb_descriptor_header *) &ecm_gsi_ss_notify_desc,
  1118. (struct usb_descriptor_header *) &ecm_gsi_ss_notify_comp_desc,
  1119. /* data interface, altsettings 0 and 1 */
  1120. (struct usb_descriptor_header *) &ecm_gsi_data_nop_intf,
  1121. (struct usb_descriptor_header *) &ecm_gsi_data_intf,
  1122. (struct usb_descriptor_header *) &ecm_gsi_ss_in_desc,
  1123. (struct usb_descriptor_header *) &ecm_gsi_ss_in_comp_desc,
  1124. (struct usb_descriptor_header *) &ecm_gsi_ss_out_desc,
  1125. (struct usb_descriptor_header *) &ecm_gsi_ss_out_comp_desc,
  1126. NULL,
  1127. };
  1128. /* string descriptors: */
  1129. static struct usb_string ecm_gsi_string_defs[] = {
  1130. [0].s = "CDC Ethernet Control Model (ECM)",
  1131. [1].s = NULL /* DYNAMIC */,
  1132. [2].s = "CDC Ethernet Data",
  1133. { } /* end of list */
  1134. };
  1135. static struct usb_gadget_strings ecm_gsi_string_table = {
  1136. .language = 0x0409, /* en-us */
  1137. .strings = ecm_gsi_string_defs,
  1138. };
  1139. static struct usb_gadget_strings *ecm_gsi_strings[] = {
  1140. &ecm_gsi_string_table,
  1141. NULL,
  1142. };
  1143. /* qdss device descriptor */
  1144. static struct usb_interface_descriptor qdss_gsi_data_intf_desc = {
  1145. .bLength = sizeof(qdss_gsi_data_intf_desc),
  1146. .bDescriptorType = USB_DT_INTERFACE,
  1147. .bAlternateSetting = 0,
  1148. .bNumEndpoints = 1,
  1149. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  1150. .bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC,
  1151. .bInterfaceProtocol = 0x80,
  1152. };
  1153. static struct usb_endpoint_descriptor qdss_gsi_fs_data_desc = {
  1154. .bLength = USB_DT_ENDPOINT_SIZE,
  1155. .bDescriptorType = USB_DT_ENDPOINT,
  1156. .bEndpointAddress = USB_DIR_IN,
  1157. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1158. .wMaxPacketSize = cpu_to_le16(64),
  1159. };
  1160. static struct usb_endpoint_descriptor qdss_gsi_hs_data_desc = {
  1161. .bLength = USB_DT_ENDPOINT_SIZE,
  1162. .bDescriptorType = USB_DT_ENDPOINT,
  1163. .bEndpointAddress = USB_DIR_IN,
  1164. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1165. .wMaxPacketSize = cpu_to_le16(512),
  1166. };
  1167. static struct usb_endpoint_descriptor qdss_gsi_ss_data_desc = {
  1168. .bLength = USB_DT_ENDPOINT_SIZE,
  1169. .bDescriptorType = USB_DT_ENDPOINT,
  1170. .bEndpointAddress = USB_DIR_IN,
  1171. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  1172. .wMaxPacketSize = cpu_to_le16(1024),
  1173. };
  1174. static struct usb_ss_ep_comp_descriptor qdss_gsi_data_ep_comp_desc = {
  1175. .bLength = sizeof(qdss_gsi_data_ep_comp_desc),
  1176. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  1177. .bMaxBurst = 1,
  1178. .bmAttributes = 0,
  1179. .wBytesPerInterval = 0,
  1180. };
  1181. static struct usb_descriptor_header *qdss_gsi_fs_data_only_desc[] = {
  1182. (struct usb_descriptor_header *) &qdss_gsi_data_intf_desc,
  1183. (struct usb_descriptor_header *) &qdss_gsi_fs_data_desc,
  1184. NULL,
  1185. };
  1186. static struct usb_descriptor_header *qdss_gsi_hs_data_only_desc[] = {
  1187. (struct usb_descriptor_header *) &qdss_gsi_data_intf_desc,
  1188. (struct usb_descriptor_header *) &qdss_gsi_hs_data_desc,
  1189. NULL,
  1190. };
  1191. static struct usb_descriptor_header *qdss_gsi_ss_data_only_desc[] = {
  1192. (struct usb_descriptor_header *) &qdss_gsi_data_intf_desc,
  1193. (struct usb_descriptor_header *) &qdss_gsi_ss_data_desc,
  1194. (struct usb_descriptor_header *) &qdss_gsi_data_ep_comp_desc,
  1195. NULL,
  1196. };
  1197. /* string descriptors: */
  1198. static struct usb_string qdss_gsi_string_defs[] = {
  1199. [0].s = "DPL Data",
  1200. {}, /* end of list */
  1201. };
  1202. static struct usb_gadget_strings qdss_gsi_string_table = {
  1203. .language = 0x0409,
  1204. .strings = qdss_gsi_string_defs,
  1205. };
  1206. static struct usb_gadget_strings *qdss_gsi_strings[] = {
  1207. &qdss_gsi_string_table,
  1208. NULL,
  1209. };
  1210. #endif