f_qdss.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * f_qdss.c -- QDSS function Driver
  4. *
  5. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  6. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/device.h>
  12. #include <linux/usb/usb_qdss.h>
  13. #include <linux/usb/cdc.h>
  14. #include <linux/usb/dwc3-msm.h>
  15. #include "f_qdss.h"
  16. static void *_qdss_ipc_log;
  17. #define NUM_PAGES 10 /* # of pages for ipc logging */
  18. #ifdef CONFIG_DYNAMIC_DEBUG
  19. #define qdss_log(fmt, ...) do { \
  20. ipc_log_string(_qdss_ipc_log, "%s: " fmt, __func__, ##__VA_ARGS__); \
  21. dynamic_pr_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
  22. } while (0)
  23. #else
  24. #define qdss_log(fmt, ...) \
  25. ipc_log_string(_qdss_ipc_log, "%s: " fmt, __func__, ##__VA_ARGS__)
  26. #endif
  27. static DEFINE_SPINLOCK(channel_lock);
  28. static LIST_HEAD(usb_qdss_ch_list);
  29. static struct usb_interface_descriptor qdss_data_intf_desc = {
  30. .bLength = sizeof(qdss_data_intf_desc),
  31. .bDescriptorType = USB_DT_INTERFACE,
  32. .bAlternateSetting = 0,
  33. .bNumEndpoints = 1,
  34. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  35. .bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC,
  36. .bInterfaceProtocol = 0x70,
  37. };
  38. static struct usb_endpoint_descriptor qdss_hs_data_desc = {
  39. .bLength = USB_DT_ENDPOINT_SIZE,
  40. .bDescriptorType = USB_DT_ENDPOINT,
  41. .bEndpointAddress = USB_DIR_IN,
  42. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  43. .wMaxPacketSize = cpu_to_le16(512),
  44. };
  45. static struct usb_endpoint_descriptor qdss_ss_data_desc = {
  46. .bLength = USB_DT_ENDPOINT_SIZE,
  47. .bDescriptorType = USB_DT_ENDPOINT,
  48. .bEndpointAddress = USB_DIR_IN,
  49. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  50. .wMaxPacketSize = cpu_to_le16(1024),
  51. };
  52. static struct usb_ss_ep_comp_descriptor qdss_data_ep_comp_desc = {
  53. .bLength = sizeof(qdss_data_ep_comp_desc),
  54. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  55. .bMaxBurst = 1,
  56. .bmAttributes = 0,
  57. .wBytesPerInterval = 0,
  58. };
  59. static struct usb_interface_descriptor qdss_ctrl_intf_desc = {
  60. .bLength = sizeof(qdss_ctrl_intf_desc),
  61. .bDescriptorType = USB_DT_INTERFACE,
  62. .bAlternateSetting = 0,
  63. .bNumEndpoints = 2,
  64. .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
  65. .bInterfaceSubClass = USB_SUBCLASS_VENDOR_SPEC,
  66. .bInterfaceProtocol = 0x70,
  67. };
  68. static struct usb_endpoint_descriptor qdss_hs_ctrl_in_desc = {
  69. .bLength = USB_DT_ENDPOINT_SIZE,
  70. .bDescriptorType = USB_DT_ENDPOINT,
  71. .bEndpointAddress = USB_DIR_IN,
  72. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  73. .wMaxPacketSize = cpu_to_le16(512),
  74. };
  75. static struct usb_endpoint_descriptor qdss_ss_ctrl_in_desc = {
  76. .bLength = USB_DT_ENDPOINT_SIZE,
  77. .bDescriptorType = USB_DT_ENDPOINT,
  78. .bEndpointAddress = USB_DIR_IN,
  79. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  80. .wMaxPacketSize = cpu_to_le16(1024),
  81. };
  82. static struct usb_endpoint_descriptor qdss_hs_ctrl_out_desc = {
  83. .bLength = USB_DT_ENDPOINT_SIZE,
  84. .bDescriptorType = USB_DT_ENDPOINT,
  85. .bEndpointAddress = USB_DIR_OUT,
  86. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  87. .wMaxPacketSize = cpu_to_le16(512),
  88. };
  89. static struct usb_endpoint_descriptor qdss_ss_ctrl_out_desc = {
  90. .bLength = USB_DT_ENDPOINT_SIZE,
  91. .bDescriptorType = USB_DT_ENDPOINT,
  92. .bEndpointAddress = USB_DIR_OUT,
  93. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  94. .wMaxPacketSize = cpu_to_le16(0x400),
  95. };
  96. static struct usb_ss_ep_comp_descriptor qdss_ctrl_in_ep_comp_desc = {
  97. .bLength = sizeof(qdss_ctrl_in_ep_comp_desc),
  98. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  99. .bMaxBurst = 0,
  100. .bmAttributes = 0,
  101. .wBytesPerInterval = 0,
  102. };
  103. static struct usb_ss_ep_comp_descriptor qdss_ctrl_out_ep_comp_desc = {
  104. .bLength = sizeof(qdss_ctrl_out_ep_comp_desc),
  105. .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
  106. .bMaxBurst = 0,
  107. .bmAttributes = 0,
  108. .wBytesPerInterval = 0,
  109. };
  110. /* Full speed support */
  111. static struct usb_endpoint_descriptor qdss_fs_data_desc = {
  112. .bLength = USB_DT_ENDPOINT_SIZE,
  113. .bDescriptorType = USB_DT_ENDPOINT,
  114. .bEndpointAddress = USB_DIR_IN,
  115. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  116. .wMaxPacketSize = cpu_to_le16(64),
  117. };
  118. static struct usb_endpoint_descriptor qdss_fs_ctrl_in_desc = {
  119. .bLength = USB_DT_ENDPOINT_SIZE,
  120. .bDescriptorType = USB_DT_ENDPOINT,
  121. .bEndpointAddress = USB_DIR_IN,
  122. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  123. .wMaxPacketSize = cpu_to_le16(64),
  124. };
  125. static struct usb_endpoint_descriptor qdss_fs_ctrl_out_desc = {
  126. .bLength = USB_DT_ENDPOINT_SIZE,
  127. .bDescriptorType = USB_DT_ENDPOINT,
  128. .bEndpointAddress = USB_DIR_OUT,
  129. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  130. .wMaxPacketSize = cpu_to_le16(64),
  131. };
  132. static struct usb_descriptor_header *qdss_fs_desc[] = {
  133. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  134. (struct usb_descriptor_header *) &qdss_fs_data_desc,
  135. (struct usb_descriptor_header *) &qdss_ctrl_intf_desc,
  136. (struct usb_descriptor_header *) &qdss_fs_ctrl_in_desc,
  137. (struct usb_descriptor_header *) &qdss_fs_ctrl_out_desc,
  138. NULL,
  139. };
  140. static struct usb_descriptor_header *qdss_hs_desc[] = {
  141. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  142. (struct usb_descriptor_header *) &qdss_hs_data_desc,
  143. (struct usb_descriptor_header *) &qdss_ctrl_intf_desc,
  144. (struct usb_descriptor_header *) &qdss_hs_ctrl_in_desc,
  145. (struct usb_descriptor_header *) &qdss_hs_ctrl_out_desc,
  146. NULL,
  147. };
  148. static struct usb_descriptor_header *qdss_ss_desc[] = {
  149. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  150. (struct usb_descriptor_header *) &qdss_ss_data_desc,
  151. (struct usb_descriptor_header *) &qdss_data_ep_comp_desc,
  152. (struct usb_descriptor_header *) &qdss_ctrl_intf_desc,
  153. (struct usb_descriptor_header *) &qdss_ss_ctrl_in_desc,
  154. (struct usb_descriptor_header *) &qdss_ctrl_in_ep_comp_desc,
  155. (struct usb_descriptor_header *) &qdss_ss_ctrl_out_desc,
  156. (struct usb_descriptor_header *) &qdss_ctrl_out_ep_comp_desc,
  157. NULL,
  158. };
  159. static struct usb_descriptor_header *qdss_fs_data_only_desc[] = {
  160. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  161. (struct usb_descriptor_header *) &qdss_fs_data_desc,
  162. NULL,
  163. };
  164. static struct usb_descriptor_header *qdss_hs_data_only_desc[] = {
  165. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  166. (struct usb_descriptor_header *) &qdss_hs_data_desc,
  167. NULL,
  168. };
  169. static struct usb_descriptor_header *qdss_ss_data_only_desc[] = {
  170. (struct usb_descriptor_header *) &qdss_data_intf_desc,
  171. (struct usb_descriptor_header *) &qdss_ss_data_desc,
  172. (struct usb_descriptor_header *) &qdss_data_ep_comp_desc,
  173. NULL,
  174. };
  175. /* string descriptors: */
  176. #define QDSS_DATA_IDX 0
  177. #define QDSS_CTRL_IDX 1
  178. static struct usb_string qdss_string_defs[] = {
  179. [QDSS_DATA_IDX].s = "QDSS DATA",
  180. [QDSS_CTRL_IDX].s = "QDSS CTRL",
  181. {}, /* end of list */
  182. };
  183. static struct usb_gadget_strings qdss_string_table = {
  184. .language = 0x0409,
  185. .strings = qdss_string_defs,
  186. };
  187. static struct usb_gadget_strings *qdss_strings[] = {
  188. &qdss_string_table,
  189. NULL,
  190. };
  191. static void qdss_disable(struct usb_function *f);
  192. static inline struct f_qdss *func_to_qdss(struct usb_function *f)
  193. {
  194. return container_of(f, struct f_qdss, port.function);
  195. }
  196. static
  197. struct usb_qdss_opts *to_fi_usb_qdss_opts(struct usb_function_instance *fi)
  198. {
  199. return container_of(fi, struct usb_qdss_opts, func_inst);
  200. }
  201. static inline bool qdss_uses_sw_path(struct f_qdss *qdss)
  202. {
  203. return (!strcmp(qdss->ch.name, USB_QDSS_CH_MDM) ||
  204. !strcmp(qdss->ch.name, USB_QDSS_CH_SW));
  205. }
  206. /*----------------------------------------------------------------------*/
  207. static void qdss_write_complete(struct usb_ep *ep,
  208. struct usb_request *req)
  209. {
  210. struct f_qdss *qdss = ep->driver_data;
  211. struct qdss_req *qreq = req->context;
  212. struct qdss_request *d_req = qreq->qdss_req;
  213. struct usb_ep *in;
  214. enum qdss_state state;
  215. unsigned long flags;
  216. in = qdss->port.data;
  217. state = USB_QDSS_DATA_WRITE_DONE;
  218. qdss_log("channel:%s ep:%s req:%pK req->status:%d req->length:%d\n",
  219. qdss->ch.name, ep->name, req, req->status, req->length);
  220. spin_lock_irqsave(&qdss->lock, flags);
  221. list_move_tail(&qreq->list, &qdss->data_write_pool);
  222. /*
  223. * When channel is closed, we move all queued requests to
  224. * dequeued_data_pool list and wait for it to be drained.
  225. * Signal the completion here if the channel is closed
  226. * and both queued & dequeued lists are empty.
  227. */
  228. if (!qdss->opened && list_empty(&qdss->dequeued_data_pool) &&
  229. list_empty(&qdss->queued_data_pool))
  230. complete(&qdss->dequeue_done);
  231. if (req->length != 0) {
  232. d_req->actual = req->actual;
  233. d_req->status = req->status;
  234. }
  235. spin_unlock_irqrestore(&qdss->lock, flags);
  236. if (qdss->ch.notify)
  237. qdss->ch.notify(qdss->ch.priv, state, d_req, NULL);
  238. }
  239. static void qdss_free_reqs(struct f_qdss *qdss)
  240. {
  241. struct list_head *act, *tmp;
  242. struct qdss_req *qreq;
  243. int data_write_req = 0;
  244. unsigned long flags;
  245. lockdep_assert_held(&qdss->mutex);
  246. spin_lock_irqsave(&qdss->lock, flags);
  247. list_for_each_safe(act, tmp, &qdss->data_write_pool) {
  248. qreq = list_entry(act, struct qdss_req, list);
  249. list_del(&qreq->list);
  250. usb_ep_free_request(qdss->port.data, qreq->usb_req);
  251. kfree(qreq);
  252. data_write_req++;
  253. }
  254. qdss_log("channel:%s data_write_req:%d freed\n", qdss->ch.name,
  255. data_write_req);
  256. spin_unlock_irqrestore(&qdss->lock, flags);
  257. }
  258. void usb_qdss_free_req(struct usb_qdss_ch *ch)
  259. {
  260. struct f_qdss *qdss = container_of(ch, struct f_qdss, ch);
  261. if (!ch) {
  262. pr_err("%s: ch is NULL\n", __func__);
  263. return;
  264. }
  265. mutex_lock(&qdss->mutex);
  266. if (!qdss->opened)
  267. pr_err("%s: channel %s closed\n", __func__, ch->name);
  268. else
  269. qdss_free_reqs(qdss);
  270. mutex_unlock(&qdss->mutex);
  271. }
  272. EXPORT_SYMBOL(usb_qdss_free_req);
  273. int usb_qdss_alloc_req(struct usb_qdss_ch *ch, int no_write_buf)
  274. {
  275. struct f_qdss *qdss = container_of(ch, struct f_qdss, ch);
  276. struct usb_request *req;
  277. struct usb_ep *in;
  278. struct list_head *list_pool;
  279. int i;
  280. struct qdss_req *qreq;
  281. unsigned long flags;
  282. if (!ch) {
  283. pr_err("%s: ch is NULL\n", __func__);
  284. return -EINVAL;
  285. }
  286. qdss_log("channel:%s num_write_buf:%d\n", ch->name, no_write_buf);
  287. if (!qdss) {
  288. pr_err("%s: %s closed\n", __func__, ch->name);
  289. return -ENODEV;
  290. }
  291. mutex_lock(&qdss->mutex);
  292. in = qdss->port.data;
  293. list_pool = &qdss->data_write_pool;
  294. for (i = 0; i < no_write_buf; i++) {
  295. qreq = kzalloc(sizeof(struct qdss_req), GFP_KERNEL);
  296. if (!qreq)
  297. goto fail;
  298. req = usb_ep_alloc_request(in, GFP_ATOMIC);
  299. if (!req) {
  300. pr_err("%s: ctrl_in allocation err\n", __func__);
  301. kfree(qreq);
  302. goto fail;
  303. }
  304. spin_lock_irqsave(&qdss->lock, flags);
  305. qreq->usb_req = req;
  306. req->context = qreq;
  307. req->complete = qdss_write_complete;
  308. list_add_tail(&qreq->list, list_pool);
  309. spin_unlock_irqrestore(&qdss->lock, flags);
  310. }
  311. mutex_unlock(&qdss->mutex);
  312. return 0;
  313. fail:
  314. qdss_free_reqs(qdss);
  315. mutex_unlock(&qdss->mutex);
  316. return -ENOMEM;
  317. }
  318. EXPORT_SYMBOL(usb_qdss_alloc_req);
  319. static void clear_eps(struct usb_function *f)
  320. {
  321. struct f_qdss *qdss = func_to_qdss(f);
  322. qdss_log("channel:%s\n", qdss->ch.name);
  323. if (qdss->port.ctrl_in)
  324. qdss->port.ctrl_in->driver_data = NULL;
  325. if (qdss->port.ctrl_out)
  326. qdss->port.ctrl_out->driver_data = NULL;
  327. if (qdss->port.data) {
  328. if (!qdss_uses_sw_path(qdss)) {
  329. msm_ep_clear_ops(qdss->port.data);
  330. msm_ep_set_mode(qdss->port.data, USB_EP_NONE);
  331. }
  332. qdss->port.data->driver_data = NULL;
  333. }
  334. }
  335. static void clear_desc(struct usb_gadget *gadget, struct usb_function *f)
  336. {
  337. struct f_qdss *qdss = func_to_qdss(f);
  338. qdss_log("channel:%s\n", qdss->ch.name);
  339. usb_free_all_descriptors(f);
  340. }
  341. static int qdss_bind(struct usb_configuration *c, struct usb_function *f)
  342. {
  343. struct usb_gadget *gadget = c->cdev->gadget;
  344. struct f_qdss *qdss = func_to_qdss(f);
  345. struct usb_ep *ep;
  346. int iface, id, ret;
  347. qdss_log("channel:%s\n", qdss->ch.name);
  348. /* Allocate data I/F */
  349. iface = usb_interface_id(c, f);
  350. if (iface < 0) {
  351. pr_err("interface allocation error\n");
  352. return iface;
  353. }
  354. qdss_data_intf_desc.bInterfaceNumber = iface;
  355. qdss->data_iface_id = iface;
  356. if (!qdss_string_defs[QDSS_DATA_IDX].id) {
  357. id = usb_string_id(c->cdev);
  358. if (id < 0)
  359. return id;
  360. qdss_string_defs[QDSS_DATA_IDX].id = id;
  361. qdss_data_intf_desc.iInterface = id;
  362. }
  363. if (qdss->debug_inface_enabled) {
  364. /* Allocate ctrl I/F */
  365. iface = usb_interface_id(c, f);
  366. if (iface < 0) {
  367. pr_err("interface allocation error\n");
  368. return iface;
  369. }
  370. qdss_ctrl_intf_desc.bInterfaceNumber = iface;
  371. qdss->ctrl_iface_id = iface;
  372. if (!qdss_string_defs[QDSS_CTRL_IDX].id) {
  373. id = usb_string_id(c->cdev);
  374. if (id < 0)
  375. return id;
  376. qdss_string_defs[QDSS_CTRL_IDX].id = id;
  377. qdss_ctrl_intf_desc.iInterface = id;
  378. }
  379. }
  380. /* for non-accelerated path keep tx fifo size 1k */
  381. if (qdss_uses_sw_path(qdss))
  382. qdss_data_ep_comp_desc.bMaxBurst = 0;
  383. ep = usb_ep_autoconfig(gadget, &qdss_fs_data_desc);
  384. if (!ep) {
  385. pr_err("%s: ep_autoconfig error\n", __func__);
  386. goto clear_ep;
  387. }
  388. qdss->port.data = ep;
  389. ep->driver_data = qdss;
  390. if (!qdss_uses_sw_path(qdss)) {
  391. ret = msm_ep_set_mode(qdss->port.data, qdss->ch.ch_type);
  392. if (ret < 0)
  393. goto clear_ep;
  394. msm_ep_update_ops(qdss->port.data);
  395. }
  396. if (qdss->debug_inface_enabled) {
  397. ep = usb_ep_autoconfig(gadget, &qdss_fs_ctrl_in_desc);
  398. if (!ep) {
  399. pr_err("%s: ep_autoconfig error\n", __func__);
  400. goto clear_ep;
  401. }
  402. qdss->port.ctrl_in = ep;
  403. ep->driver_data = qdss;
  404. ep = usb_ep_autoconfig(gadget, &qdss_fs_ctrl_out_desc);
  405. if (!ep) {
  406. pr_err("%s: ep_autoconfig error\n", __func__);
  407. goto clear_ep;
  408. }
  409. qdss->port.ctrl_out = ep;
  410. ep->driver_data = qdss;
  411. }
  412. if (!qdss_uses_sw_path(qdss)) {
  413. ret = alloc_hw_req(qdss->port.data);
  414. if (ret) {
  415. pr_err("%s: alloc_sps_req error (%d)\n",
  416. __func__, ret);
  417. goto clear_ep;
  418. }
  419. }
  420. /* update hs/ss descriptors */
  421. qdss_hs_data_desc.bEndpointAddress =
  422. qdss_ss_data_desc.bEndpointAddress =
  423. qdss_fs_data_desc.bEndpointAddress;
  424. if (qdss->debug_inface_enabled) {
  425. qdss_hs_ctrl_in_desc.bEndpointAddress =
  426. qdss_ss_ctrl_in_desc.bEndpointAddress =
  427. qdss_fs_ctrl_in_desc.bEndpointAddress;
  428. qdss_hs_ctrl_out_desc.bEndpointAddress =
  429. qdss_ss_ctrl_out_desc.bEndpointAddress =
  430. qdss_fs_ctrl_out_desc.bEndpointAddress;
  431. }
  432. if (qdss->debug_inface_enabled)
  433. ret = usb_assign_descriptors(f, qdss_fs_desc, qdss_hs_desc,
  434. qdss_ss_desc, qdss_ss_desc);
  435. else
  436. ret = usb_assign_descriptors(f, qdss_fs_data_only_desc,
  437. qdss_hs_data_only_desc, qdss_ss_data_only_desc,
  438. qdss_ss_data_only_desc);
  439. if (ret)
  440. goto fail;
  441. return 0;
  442. fail:
  443. /* check if usb_request allocated */
  444. if (qdss->endless_req) {
  445. usb_ep_free_request(qdss->port.data,
  446. qdss->endless_req);
  447. qdss->endless_req = NULL;
  448. }
  449. clear_ep:
  450. clear_eps(f);
  451. return -EOPNOTSUPP;
  452. }
  453. static void qdss_unbind(struct usb_configuration *c, struct usb_function *f)
  454. {
  455. struct f_qdss *qdss = func_to_qdss(f);
  456. struct usb_gadget *gadget = c->cdev->gadget;
  457. qdss_log("channel:%s\n", qdss->ch.name);
  458. qdss_disable(f);
  459. flush_workqueue(qdss->wq);
  460. if (qdss->endless_req) {
  461. usb_ep_free_request(qdss->port.data,
  462. qdss->endless_req);
  463. qdss->endless_req = NULL;
  464. }
  465. /* Reset string ids */
  466. qdss_string_defs[QDSS_DATA_IDX].id = 0;
  467. qdss_string_defs[QDSS_CTRL_IDX].id = 0;
  468. clear_eps(f);
  469. clear_desc(gadget, f);
  470. }
  471. static void qdss_eps_disable(struct usb_function *f)
  472. {
  473. struct f_qdss *qdss = func_to_qdss(f);
  474. qdss_log("channel:%s\n", qdss->ch.name);
  475. if (qdss->ctrl_in_enabled) {
  476. usb_ep_disable(qdss->port.ctrl_in);
  477. qdss->ctrl_in_enabled = 0;
  478. }
  479. if (qdss->ctrl_out_enabled) {
  480. usb_ep_disable(qdss->port.ctrl_out);
  481. qdss->ctrl_out_enabled = 0;
  482. }
  483. if (qdss->data_enabled) {
  484. usb_ep_disable(qdss->port.data);
  485. qdss->data_enabled = 0;
  486. }
  487. }
  488. static void usb_qdss_disconnect_work(struct work_struct *work)
  489. {
  490. struct f_qdss *qdss;
  491. int status;
  492. qdss = container_of(work, struct f_qdss, disconnect_w);
  493. qdss_log("channel:%s\n", qdss->ch.name);
  494. /* Notify qdss to cancel all active transfers */
  495. if (qdss->ch.notify)
  496. qdss->ch.notify(qdss->ch.priv,
  497. USB_QDSS_DISCONNECT,
  498. NULL,
  499. NULL);
  500. mutex_lock(&qdss->mutex);
  501. /* Uninitialized init data i.e. ep specific operation */
  502. if (qdss->opened && !qdss_uses_sw_path(qdss)) {
  503. status = set_qdss_data_connection(qdss, 0);
  504. if (status)
  505. pr_err("qdss_disconnect error\n");
  506. }
  507. /*
  508. * Decrement usage count which was incremented
  509. * before calling connect work
  510. */
  511. usb_gadget_autopm_put_async(qdss->gadget);
  512. mutex_unlock(&qdss->mutex);
  513. }
  514. static void qdss_disable(struct usb_function *f)
  515. {
  516. struct f_qdss *qdss = func_to_qdss(f);
  517. unsigned long flags;
  518. qdss_log("channel:%s\n", qdss->ch.name);
  519. spin_lock_irqsave(&qdss->lock, flags);
  520. if (!qdss->usb_connected) {
  521. spin_unlock_irqrestore(&qdss->lock, flags);
  522. return;
  523. }
  524. qdss->usb_connected = 0;
  525. spin_unlock_irqrestore(&qdss->lock, flags);
  526. /*cancell all active xfers*/
  527. qdss_eps_disable(f);
  528. queue_work(qdss->wq, &qdss->disconnect_w);
  529. }
  530. static void usb_qdss_connect_work(struct work_struct *work)
  531. {
  532. struct f_qdss *qdss;
  533. int status;
  534. struct usb_request *req = NULL;
  535. unsigned long flags;
  536. qdss = container_of(work, struct f_qdss, connect_w);
  537. /* If cable is already removed, discard connect_work */
  538. if (qdss->usb_connected == 0) {
  539. cancel_work_sync(&qdss->disconnect_w);
  540. usb_gadget_autopm_put_async(qdss->gadget);
  541. return;
  542. }
  543. mutex_lock(&qdss->mutex);
  544. qdss_log("channel:%s opened:%d\n", qdss->ch.name, qdss->opened);
  545. if (!qdss->opened)
  546. goto unlock_out;
  547. if (qdss_uses_sw_path(qdss))
  548. goto notify;
  549. status = set_qdss_data_connection(qdss, 1);
  550. if (status) {
  551. pr_err("set_qdss_data_connection error(%d)\n", status);
  552. goto unlock_out;
  553. }
  554. spin_lock_irqsave(&qdss->lock, flags);
  555. req = qdss->endless_req;
  556. spin_unlock_irqrestore(&qdss->lock, flags);
  557. if (!req)
  558. goto unlock_out;
  559. status = usb_ep_queue(qdss->port.data, req, GFP_ATOMIC);
  560. if (status) {
  561. pr_err("%s: usb_ep_queue error (%d)\n", __func__, status);
  562. goto unlock_out;
  563. }
  564. notify:
  565. mutex_unlock(&qdss->mutex);
  566. if (qdss->ch.notify)
  567. qdss->ch.notify(qdss->ch.priv, USB_QDSS_CONNECT,
  568. NULL, &qdss->ch);
  569. return;
  570. unlock_out:
  571. mutex_unlock(&qdss->mutex);
  572. }
  573. static int qdss_set_alt(struct usb_function *f, unsigned int intf,
  574. unsigned int alt)
  575. {
  576. struct f_qdss *qdss = func_to_qdss(f);
  577. struct usb_gadget *gadget = f->config->cdev->gadget;
  578. int ret = 0;
  579. qdss_log("qdss pointer = %pK\n", qdss);
  580. qdss->gadget = gadget;
  581. if (alt != 0)
  582. goto fail1;
  583. if (gadget->speed < USB_SPEED_HIGH) {
  584. pr_err("%s: qdss doesn't support USB full or low speed\n",
  585. __func__);
  586. ret = -EINVAL;
  587. goto fail1;
  588. }
  589. if (intf == qdss->data_iface_id && !qdss->data_enabled) {
  590. /* Increment usage count on connect */
  591. usb_gadget_autopm_get_async(qdss->gadget);
  592. ret = config_ep_by_speed(gadget, f, qdss->port.data);
  593. if (ret) {
  594. pr_err("%s: failed config_ep_by_speed ret:%d\n",
  595. __func__, ret);
  596. goto fail;
  597. }
  598. ret = usb_ep_enable(qdss->port.data);
  599. if (ret) {
  600. pr_err("%s: failed to enable ep ret:%d\n",
  601. __func__, ret);
  602. goto fail;
  603. }
  604. qdss->port.data->driver_data = qdss;
  605. qdss->data_enabled = 1;
  606. } else if ((intf == qdss->ctrl_iface_id) &&
  607. (qdss->debug_inface_enabled)) {
  608. if (config_ep_by_speed(gadget, f, qdss->port.ctrl_in)) {
  609. ret = -EINVAL;
  610. goto fail1;
  611. }
  612. ret = usb_ep_enable(qdss->port.ctrl_in);
  613. if (ret)
  614. goto fail1;
  615. qdss->port.ctrl_in->driver_data = qdss;
  616. qdss->ctrl_in_enabled = 1;
  617. if (config_ep_by_speed(gadget, f, qdss->port.ctrl_out)) {
  618. ret = -EINVAL;
  619. goto fail1;
  620. }
  621. ret = usb_ep_enable(qdss->port.ctrl_out);
  622. if (ret)
  623. goto fail1;
  624. qdss->port.ctrl_out->driver_data = qdss;
  625. qdss->ctrl_out_enabled = 1;
  626. }
  627. if (qdss->debug_inface_enabled) {
  628. if (qdss->ctrl_out_enabled && qdss->ctrl_in_enabled &&
  629. qdss->data_enabled) {
  630. qdss->usb_connected = 1;
  631. qdss_log("usb_connected INTF enabled\n");
  632. }
  633. } else {
  634. if (qdss->data_enabled) {
  635. qdss->usb_connected = 1;
  636. qdss_log("usb_connected INTF disabled\n");
  637. }
  638. }
  639. if (qdss->usb_connected)
  640. queue_work(qdss->wq, &qdss->connect_w);
  641. return 0;
  642. fail:
  643. /* Decrement usage count in case of failure */
  644. usb_gadget_autopm_put_async(qdss->gadget);
  645. fail1:
  646. pr_err("%s failed ret:%d\n", __func__, ret);
  647. qdss_eps_disable(f);
  648. return ret;
  649. }
  650. static struct f_qdss *alloc_usb_qdss(char *channel_name)
  651. {
  652. struct f_qdss *qdss;
  653. int found = 0;
  654. struct usb_qdss_ch *ch;
  655. unsigned long flags;
  656. spin_lock_irqsave(&channel_lock, flags);
  657. list_for_each_entry(ch, &usb_qdss_ch_list, list) {
  658. if (!strcmp(channel_name, ch->name)) {
  659. found = 1;
  660. break;
  661. }
  662. }
  663. spin_unlock_irqrestore(&channel_lock, flags);
  664. if (found) {
  665. pr_err("%s: (%s) is already available.\n",
  666. __func__, channel_name);
  667. return ERR_PTR(-EEXIST);
  668. }
  669. qdss = kzalloc(sizeof(struct f_qdss), GFP_KERNEL);
  670. if (!qdss)
  671. return ERR_PTR(-ENOMEM);
  672. qdss->wq = create_singlethread_workqueue(channel_name);
  673. if (!qdss->wq) {
  674. kfree(qdss);
  675. return ERR_PTR(-ENOMEM);
  676. }
  677. spin_lock_irqsave(&channel_lock, flags);
  678. ch = &qdss->ch;
  679. ch->name = channel_name;
  680. if (!strcmp(ch->name, USB_QDSS_CH_EBC))
  681. ch->ch_type = USB_EP_EBC;
  682. else
  683. ch->ch_type = USB_EP_NONE;
  684. list_add_tail(&ch->list, &usb_qdss_ch_list);
  685. spin_unlock_irqrestore(&channel_lock, flags);
  686. spin_lock_init(&qdss->lock);
  687. INIT_LIST_HEAD(&qdss->data_write_pool);
  688. INIT_LIST_HEAD(&qdss->queued_data_pool);
  689. INIT_LIST_HEAD(&qdss->dequeued_data_pool);
  690. INIT_WORK(&qdss->connect_w, usb_qdss_connect_work);
  691. INIT_WORK(&qdss->disconnect_w, usb_qdss_disconnect_work);
  692. mutex_init(&qdss->mutex);
  693. init_completion(&qdss->dequeue_done);
  694. return qdss;
  695. }
  696. int usb_qdss_write(struct usb_qdss_ch *ch, struct qdss_request *d_req)
  697. {
  698. struct f_qdss *qdss = container_of(ch, struct f_qdss, ch);
  699. unsigned long flags;
  700. struct usb_request *req = NULL;
  701. struct qdss_req *qreq;
  702. if (!ch) {
  703. pr_err("%s: ch is NULL\n", __func__);
  704. return -EINVAL;
  705. }
  706. mutex_lock(&qdss->mutex);
  707. qdss_log("channel:%s d_req:%pK\n", ch->name, d_req);
  708. spin_lock_irqsave(&qdss->lock, flags);
  709. if (!qdss->opened || !qdss->usb_connected) {
  710. spin_unlock_irqrestore(&qdss->lock, flags);
  711. qdss_log("return -EIO\n");
  712. mutex_unlock(&qdss->mutex);
  713. return -EIO;
  714. }
  715. if (list_empty(&qdss->data_write_pool)) {
  716. pr_err("error: usb_qdss_data_write list is empty\n");
  717. spin_unlock_irqrestore(&qdss->lock, flags);
  718. mutex_unlock(&qdss->mutex);
  719. return -EAGAIN;
  720. }
  721. qreq = list_first_entry(&qdss->data_write_pool, struct qdss_req,
  722. list);
  723. list_move_tail(&qreq->list, &qdss->queued_data_pool);
  724. spin_unlock_irqrestore(&qdss->lock, flags);
  725. qreq->qdss_req = d_req;
  726. req = qreq->usb_req;
  727. req->buf = d_req->buf;
  728. req->length = d_req->length;
  729. req->sg = d_req->sg;
  730. req->num_sgs = d_req->num_sgs;
  731. if (req->sg)
  732. qdss_log("%s: req:%pK req->num_sgs:0x%x\n",
  733. ch->name, req, req->num_sgs);
  734. else
  735. qdss_log("%s: req:%pK rq->length:0x%x\n",
  736. ch->name, req, req->length);
  737. if (usb_ep_queue(qdss->port.data, req, GFP_ATOMIC)) {
  738. spin_lock_irqsave(&qdss->lock, flags);
  739. /* Remove from queued pool and add back to data pool */
  740. list_move_tail(&qreq->list, &qdss->data_write_pool);
  741. spin_unlock_irqrestore(&qdss->lock, flags);
  742. pr_err("qdss usb_ep_queue failed\n");
  743. mutex_unlock(&qdss->mutex);
  744. return -EIO;
  745. }
  746. mutex_unlock(&qdss->mutex);
  747. return 0;
  748. }
  749. EXPORT_SYMBOL(usb_qdss_write);
  750. struct usb_qdss_ch *usb_qdss_open(const char *name, void *priv,
  751. void (*notify)(void *priv, unsigned int event,
  752. struct qdss_request *d_req, struct usb_qdss_ch *))
  753. {
  754. struct usb_qdss_ch *ch;
  755. struct f_qdss *qdss = NULL;
  756. unsigned long flags;
  757. qdss_log("called for channel:%s\n", name);
  758. if (!notify) {
  759. pr_err("%s: notification func is missing\n", __func__);
  760. return NULL;
  761. }
  762. spin_lock_irqsave(&channel_lock, flags);
  763. retry:
  764. /* Check if we already have a channel with this name */
  765. list_for_each_entry(ch, &usb_qdss_ch_list, list) {
  766. if (!strcmp(name, ch->name)) {
  767. qdss = container_of(ch, struct f_qdss, ch);
  768. break;
  769. }
  770. }
  771. if (!strcmp(name, USB_QDSS_CH_SW) &&
  772. (!qdss || !qdss->port.function.name)) {
  773. qdss_log("qdss_sw not added to config, fall back to qdss_mdm\n");
  774. name = USB_QDSS_CH_MDM;
  775. qdss = NULL;
  776. goto retry;
  777. }
  778. spin_unlock_irqrestore(&channel_lock, flags);
  779. if (!qdss) {
  780. qdss_log("failed to find channel:%s\n", name);
  781. return NULL;
  782. }
  783. mutex_lock(&qdss->mutex);
  784. qdss_log("qdss ctx found for channel:%s\n", name);
  785. ch->priv = priv;
  786. ch->notify = notify;
  787. qdss->opened = true;
  788. reinit_completion(&qdss->dequeue_done);
  789. /* the case USB cabel was connected before qdss called qdss_open */
  790. if (qdss->usb_connected)
  791. queue_work(qdss->wq, &qdss->connect_w);
  792. mutex_unlock(&qdss->mutex);
  793. return ch;
  794. }
  795. EXPORT_SYMBOL(usb_qdss_open);
  796. void usb_qdss_close(struct usb_qdss_ch *ch)
  797. {
  798. struct f_qdss *qdss = container_of(ch, struct f_qdss, ch);
  799. struct usb_gadget *gadget;
  800. unsigned long flags;
  801. int status;
  802. struct qdss_req *qreq;
  803. bool do_wait;
  804. if (!ch) {
  805. pr_err("%s: ch is NULL\n", __func__);
  806. return;
  807. }
  808. qdss_log("channel:%s\n", ch->name);
  809. mutex_lock(&qdss->mutex);
  810. if (!qdss->opened) {
  811. pr_err("%s: channel %s closed\n", __func__, ch->name);
  812. goto unlock_out;
  813. }
  814. spin_lock_irqsave(&qdss->lock, flags);
  815. qdss->opened = false;
  816. /*
  817. * Some UDCs like DWC3 stop the endpoint transfer upon dequeue
  818. * of a request and retire all the previously *started* requests.
  819. * This introduces a race between the below dequeue loop and
  820. * retiring of all started requests. As soon as we drop the lock
  821. * here before dequeue, the request gets retired and UDC thinks
  822. * we are dequeuing a request that was not queued before. To
  823. * avoid this problem, lets dequeue the requests in the reverse
  824. * order.
  825. */
  826. while (!list_empty(&qdss->queued_data_pool)) {
  827. qreq = list_last_entry(&qdss->queued_data_pool,
  828. struct qdss_req, list);
  829. list_move_tail(&qreq->list, &qdss->dequeued_data_pool);
  830. spin_unlock_irqrestore(&qdss->lock, flags);
  831. status = usb_ep_dequeue(qdss->port.data, qreq->usb_req);
  832. qdss_log("dequeue req:%pK status=%d\n", qreq->usb_req, status);
  833. spin_lock_irqsave(&qdss->lock, flags);
  834. }
  835. /*
  836. * It's possible that requests may be completed synchronously during
  837. * usb_ep_dequeue() and would have already been moved back to
  838. * data_write_pool. So make sure to check that our dequeued_data_pool
  839. * is empty. If not, wait for it to happen. The request completion
  840. * handler would signal us when this list is empty and channel close
  841. * is in progress.
  842. */
  843. do_wait = !list_empty(&qdss->dequeued_data_pool);
  844. spin_unlock_irqrestore(&qdss->lock, flags);
  845. if (do_wait) {
  846. qdss_log("waiting for completion on dequeued requests\n");
  847. wait_for_completion(&qdss->dequeue_done);
  848. }
  849. WARN_ON(!list_empty(&qdss->dequeued_data_pool));
  850. qdss_free_reqs(qdss);
  851. ch->notify = NULL;
  852. if (!qdss->usb_connected || qdss_uses_sw_path(qdss))
  853. goto unlock_out;
  854. if (qdss->endless_req)
  855. usb_ep_dequeue(qdss->port.data, qdss->endless_req);
  856. gadget = qdss->gadget;
  857. status = set_qdss_data_connection(qdss, 0);
  858. if (status)
  859. pr_err("%s:qdss_disconnect error\n", __func__);
  860. unlock_out:
  861. mutex_unlock(&qdss->mutex);
  862. }
  863. EXPORT_SYMBOL(usb_qdss_close);
  864. static void qdss_cleanup(void)
  865. {
  866. struct f_qdss *qdss;
  867. struct list_head *act, *tmp;
  868. struct usb_qdss_ch *_ch;
  869. unsigned long flags;
  870. qdss_log("cleaning up channel resources.\n");
  871. list_for_each_safe(act, tmp, &usb_qdss_ch_list) {
  872. _ch = list_entry(act, struct usb_qdss_ch, list);
  873. qdss = container_of(_ch, struct f_qdss, ch);
  874. destroy_workqueue(qdss->wq);
  875. spin_lock_irqsave(&channel_lock, flags);
  876. if (!_ch->priv) {
  877. list_del(&_ch->list);
  878. kfree(qdss);
  879. }
  880. spin_unlock_irqrestore(&channel_lock, flags);
  881. }
  882. }
  883. static void qdss_free_func(struct usb_function *f)
  884. {
  885. struct f_qdss *qdss = func_to_qdss(f);
  886. qdss->debug_inface_enabled = false;
  887. }
  888. static inline struct usb_qdss_opts *to_f_qdss_opts(struct config_item *item)
  889. {
  890. return container_of(to_config_group(item), struct usb_qdss_opts,
  891. func_inst.group);
  892. }
  893. static void qdss_attr_release(struct config_item *item)
  894. {
  895. struct usb_qdss_opts *opts = to_f_qdss_opts(item);
  896. usb_put_function_instance(&opts->func_inst);
  897. }
  898. static struct configfs_item_operations qdss_item_ops = {
  899. .release = qdss_attr_release,
  900. };
  901. static ssize_t qdss_enable_debug_inface_show(struct config_item *item,
  902. char *page)
  903. {
  904. return scnprintf(page, PAGE_SIZE, "%s\n",
  905. (to_f_qdss_opts(item)->usb_qdss->debug_inface_enabled) ?
  906. "Enabled" : "Disabled");
  907. }
  908. static ssize_t qdss_enable_debug_inface_store(struct config_item *item,
  909. const char *page, size_t len)
  910. {
  911. struct f_qdss *qdss = to_f_qdss_opts(item)->usb_qdss;
  912. unsigned long flags;
  913. u8 stats;
  914. if (page == NULL) {
  915. pr_err("Invalid buffer\n");
  916. return len;
  917. }
  918. if (kstrtou8(page, 0, &stats) != 0 && !(stats == 0 || stats == 1)) {
  919. pr_err("(%u)Wrong value. enter 0 to disable or 1 to enable.\n",
  920. stats);
  921. return len;
  922. }
  923. spin_lock_irqsave(&qdss->lock, flags);
  924. qdss->debug_inface_enabled = stats;
  925. spin_unlock_irqrestore(&qdss->lock, flags);
  926. return len;
  927. }
  928. CONFIGFS_ATTR(qdss_, enable_debug_inface);
  929. static struct configfs_attribute *qdss_attrs[] = {
  930. &qdss_attr_enable_debug_inface,
  931. NULL,
  932. };
  933. static struct config_item_type qdss_func_type = {
  934. .ct_item_ops = &qdss_item_ops,
  935. .ct_attrs = qdss_attrs,
  936. .ct_owner = THIS_MODULE,
  937. };
  938. static void usb_qdss_free_inst(struct usb_function_instance *fi)
  939. {
  940. struct usb_qdss_opts *opts;
  941. opts = container_of(fi, struct usb_qdss_opts, func_inst);
  942. kfree(opts->usb_qdss);
  943. kfree(opts);
  944. }
  945. static int usb_qdss_set_inst_name(struct usb_function_instance *f,
  946. const char *name)
  947. {
  948. struct usb_qdss_opts *opts =
  949. container_of(f, struct usb_qdss_opts, func_inst);
  950. char *ptr;
  951. size_t name_len;
  952. struct f_qdss *usb_qdss;
  953. /* get channel_name as expected input qdss.<channel_name> */
  954. name_len = strlen(name) + 1;
  955. if (name_len > 15)
  956. return -ENAMETOOLONG;
  957. /* get channel name */
  958. ptr = kstrndup(name, name_len, GFP_KERNEL);
  959. if (!ptr) {
  960. pr_err("error:%ld\n", PTR_ERR(ptr));
  961. return -ENOMEM;
  962. }
  963. opts->channel_name = ptr;
  964. qdss_log("qdss: channel_name:%s\n", opts->channel_name);
  965. usb_qdss = alloc_usb_qdss(opts->channel_name);
  966. if (IS_ERR(usb_qdss)) {
  967. pr_err("Failed to create usb_qdss port(%s)\n",
  968. opts->channel_name);
  969. return -ENOMEM;
  970. }
  971. opts->usb_qdss = usb_qdss;
  972. return 0;
  973. }
  974. static struct usb_function_instance *qdss_alloc_inst(void)
  975. {
  976. struct usb_qdss_opts *opts;
  977. opts = kzalloc(sizeof(*opts), GFP_KERNEL);
  978. if (!opts)
  979. return ERR_PTR(-ENOMEM);
  980. opts->func_inst.free_func_inst = usb_qdss_free_inst;
  981. opts->func_inst.set_inst_name = usb_qdss_set_inst_name;
  982. config_group_init_type_name(&opts->func_inst.group, "",
  983. &qdss_func_type);
  984. return &opts->func_inst;
  985. }
  986. static struct usb_function *qdss_alloc(struct usb_function_instance *fi)
  987. {
  988. struct usb_qdss_opts *opts = to_fi_usb_qdss_opts(fi);
  989. struct f_qdss *usb_qdss = opts->usb_qdss;
  990. usb_qdss->port.function.name = "usb_qdss";
  991. usb_qdss->port.function.strings = qdss_strings;
  992. usb_qdss->port.function.bind = qdss_bind;
  993. usb_qdss->port.function.unbind = qdss_unbind;
  994. usb_qdss->port.function.set_alt = qdss_set_alt;
  995. usb_qdss->port.function.disable = qdss_disable;
  996. usb_qdss->port.function.setup = NULL;
  997. usb_qdss->port.function.free_func = qdss_free_func;
  998. return &usb_qdss->port.function;
  999. }
  1000. DECLARE_USB_FUNCTION(qdss, qdss_alloc_inst, qdss_alloc);
  1001. static int __init usb_qdss_init(void)
  1002. {
  1003. int ret;
  1004. _qdss_ipc_log = ipc_log_context_create(NUM_PAGES, "usb_qdss", 0);
  1005. if (IS_ERR_OR_NULL(_qdss_ipc_log))
  1006. _qdss_ipc_log = NULL;
  1007. INIT_LIST_HEAD(&usb_qdss_ch_list);
  1008. ret = usb_function_register(&qdssusb_func);
  1009. if (ret) {
  1010. pr_err("%s: failed to register diag %d\n", __func__, ret);
  1011. return ret;
  1012. }
  1013. return ret;
  1014. }
  1015. static void __exit usb_qdss_exit(void)
  1016. {
  1017. ipc_log_context_destroy(_qdss_ipc_log);
  1018. usb_function_unregister(&qdssusb_func);
  1019. qdss_cleanup();
  1020. }
  1021. module_init(usb_qdss_init);
  1022. module_exit(usb_qdss_exit);
  1023. MODULE_DESCRIPTION("USB QDSS Function Driver");
  1024. MODULE_LICENSE("GPL");