Lines Matching refs:fu
42 static int bot_enqueue_cmd_cbw(struct f_uas *fu) in bot_enqueue_cmd_cbw() argument
46 if (fu->flags & USBG_BOT_CMD_PEND) in bot_enqueue_cmd_cbw()
49 ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); in bot_enqueue_cmd_cbw()
51 fu->flags |= USBG_BOT_CMD_PEND; in bot_enqueue_cmd_cbw()
58 struct f_uas *fu = cmd->fu; in bot_status_complete() local
67 bot_enqueue_cmd_cbw(fu); in bot_status_complete()
70 static void bot_enqueue_sense_code(struct f_uas *fu, struct usbg_cmd *cmd) in bot_enqueue_sense_code() argument
72 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_enqueue_sense_code()
88 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
89 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_ATOMIC); in bot_enqueue_sense_code()
97 struct f_uas *fu = cmd->fu; in bot_err_compl() local
114 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
119 struct f_uas *fu = cmd->fu; in bot_send_bad_status() local
120 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_bad_status()
128 ep = fu->ep_in; in bot_send_bad_status()
129 req = fu->bot_req_in; in bot_send_bad_status()
131 ep = fu->ep_out; in bot_send_bad_status()
132 req = fu->bot_req_out; in bot_send_bad_status()
135 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
144 req->buf = fu->cmd.buf; in bot_send_bad_status()
147 bot_enqueue_sense_code(fu, cmd); in bot_send_bad_status()
153 struct f_uas *fu = cmd->fu; in bot_send_status() local
154 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_status()
171 fu->bot_status.req->context = cmd; in bot_send_status()
173 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_KERNEL); in bot_send_status()
209 struct f_uas *fu = cmd->fu; in bot_send_read_response() local
211 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_read_response()
230 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
232 fu->bot_req_in->buf = NULL; in bot_send_read_response()
233 fu->bot_req_in->num_sgs = se_cmd->t_data_nents; in bot_send_read_response()
234 fu->bot_req_in->sg = se_cmd->t_data_sg; in bot_send_read_response()
237 fu->bot_req_in->complete = bot_read_compl; in bot_send_read_response()
238 fu->bot_req_in->length = se_cmd->data_length; in bot_send_read_response()
239 fu->bot_req_in->context = cmd; in bot_send_read_response()
240 ret = usb_ep_queue(fu->ep_in, fu->bot_req_in, GFP_ATOMIC); in bot_send_read_response()
251 struct f_uas *fu = cmd->fu; in bot_send_write_request() local
253 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_write_request()
257 cmd->fu = fu; in bot_send_write_request()
269 fu->bot_req_out->buf = cmd->data_buf; in bot_send_write_request()
271 fu->bot_req_out->buf = NULL; in bot_send_write_request()
272 fu->bot_req_out->num_sgs = se_cmd->t_data_nents; in bot_send_write_request()
273 fu->bot_req_out->sg = se_cmd->t_data_sg; in bot_send_write_request()
276 fu->bot_req_out->complete = usbg_data_write_cmpl; in bot_send_write_request()
277 fu->bot_req_out->length = se_cmd->data_length; in bot_send_write_request()
278 fu->bot_req_out->context = cmd; in bot_send_write_request()
280 ret = usbg_prepare_w_request(cmd, fu->bot_req_out); in bot_send_write_request()
283 ret = usb_ep_queue(fu->ep_out, fu->bot_req_out, GFP_KERNEL); in bot_send_write_request()
297 struct f_uas *fu = req->context; in bot_cmd_complete() local
300 fu->flags &= ~USBG_BOT_CMD_PEND; in bot_cmd_complete()
305 ret = bot_submit_command(fu, req->buf, req->actual); in bot_cmd_complete()
310 static int bot_prepare_reqs(struct f_uas *fu) in bot_prepare_reqs() argument
314 fu->bot_req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
315 if (!fu->bot_req_in) in bot_prepare_reqs()
318 fu->bot_req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
319 if (!fu->bot_req_out) in bot_prepare_reqs()
322 fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
323 if (!fu->cmd.req) in bot_prepare_reqs()
326 fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
327 if (!fu->bot_status.req) in bot_prepare_reqs()
330 fu->bot_status.req->buf = &fu->bot_status.csw; in bot_prepare_reqs()
331 fu->bot_status.req->length = US_BULK_CS_WRAP_LEN; in bot_prepare_reqs()
332 fu->bot_status.req->complete = bot_status_complete; in bot_prepare_reqs()
333 fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); in bot_prepare_reqs()
335 fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); in bot_prepare_reqs()
336 if (!fu->cmd.buf) in bot_prepare_reqs()
339 fu->cmd.req->complete = bot_cmd_complete; in bot_prepare_reqs()
340 fu->cmd.req->buf = fu->cmd.buf; in bot_prepare_reqs()
341 fu->cmd.req->length = fu->ep_out->maxpacket; in bot_prepare_reqs()
342 fu->cmd.req->context = fu; in bot_prepare_reqs()
344 ret = bot_enqueue_cmd_cbw(fu); in bot_prepare_reqs()
349 kfree(fu->cmd.buf); in bot_prepare_reqs()
350 fu->cmd.buf = NULL; in bot_prepare_reqs()
352 usb_ep_free_request(fu->ep_in, fu->bot_status.req); in bot_prepare_reqs()
354 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_prepare_reqs()
355 fu->cmd.req = NULL; in bot_prepare_reqs()
357 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_prepare_reqs()
358 fu->bot_req_out = NULL; in bot_prepare_reqs()
360 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_prepare_reqs()
361 fu->bot_req_in = NULL; in bot_prepare_reqs()
367 static void bot_cleanup_old_alt(struct f_uas *fu) in bot_cleanup_old_alt() argument
369 if (!(fu->flags & USBG_ENABLED)) in bot_cleanup_old_alt()
372 usb_ep_disable(fu->ep_in); in bot_cleanup_old_alt()
373 usb_ep_disable(fu->ep_out); in bot_cleanup_old_alt()
375 if (!fu->bot_req_in) in bot_cleanup_old_alt()
378 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_cleanup_old_alt()
379 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_cleanup_old_alt()
380 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
381 usb_ep_free_request(fu->ep_out, fu->bot_status.req); in bot_cleanup_old_alt()
383 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
385 fu->bot_req_in = NULL; in bot_cleanup_old_alt()
386 fu->bot_req_out = NULL; in bot_cleanup_old_alt()
387 fu->cmd.req = NULL; in bot_cleanup_old_alt()
388 fu->bot_status.req = NULL; in bot_cleanup_old_alt()
389 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
392 static void bot_set_alt(struct f_uas *fu) in bot_set_alt() argument
394 struct usb_function *f = &fu->function; in bot_set_alt()
398 fu->flags = USBG_IS_BOT; in bot_set_alt()
400 config_ep_by_speed(gadget, f, fu->ep_in); in bot_set_alt()
401 ret = usb_ep_enable(fu->ep_in); in bot_set_alt()
405 config_ep_by_speed(gadget, f, fu->ep_out); in bot_set_alt()
406 ret = usb_ep_enable(fu->ep_out); in bot_set_alt()
410 ret = bot_prepare_reqs(fu); in bot_set_alt()
413 fu->flags |= USBG_ENABLED; in bot_set_alt()
417 usb_ep_disable(fu->ep_out); in bot_set_alt()
419 usb_ep_disable(fu->ep_in); in bot_set_alt()
421 fu->flags = USBG_IS_BOT; in bot_set_alt()
427 struct f_uas *fu = to_f_uas(f); in usbg_bot_setup() local
444 luns = atomic_read(&fu->tpg->tpg_port_count); in usbg_bot_setup()
466 bot_enqueue_cmd_cbw(fu); in usbg_bot_setup()
475 static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) in uasp_cleanup_one_stream() argument
481 usb_ep_free_request(fu->ep_in, stream->req_in); in uasp_cleanup_one_stream()
482 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_cleanup_one_stream()
483 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_cleanup_one_stream()
490 static void uasp_free_cmdreq(struct f_uas *fu) in uasp_free_cmdreq() argument
492 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_free_cmdreq()
493 kfree(fu->cmd.buf); in uasp_free_cmdreq()
494 fu->cmd.req = NULL; in uasp_free_cmdreq()
495 fu->cmd.buf = NULL; in uasp_free_cmdreq()
498 static void uasp_cleanup_old_alt(struct f_uas *fu) in uasp_cleanup_old_alt() argument
502 if (!(fu->flags & USBG_ENABLED)) in uasp_cleanup_old_alt()
505 usb_ep_disable(fu->ep_in); in uasp_cleanup_old_alt()
506 usb_ep_disable(fu->ep_out); in uasp_cleanup_old_alt()
507 usb_ep_disable(fu->ep_status); in uasp_cleanup_old_alt()
508 usb_ep_disable(fu->ep_cmd); in uasp_cleanup_old_alt()
511 uasp_cleanup_one_stream(fu, &fu->stream[i]); in uasp_cleanup_old_alt()
512 uasp_free_cmdreq(fu); in uasp_cleanup_old_alt()
520 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request() local
521 struct usb_gadget *gadget = fuas_to_gadget(fu); in uasp_prepare_r_request()
574 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl() local
585 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_status_data_cmpl()
594 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_status_data_cmpl()
601 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_status_data_cmpl()
609 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
623 struct f_uas *fu = cmd->fu; in uasp_send_status_response() local
630 cmd->fu = fu; in uasp_send_status_response()
632 return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); in uasp_send_status_response()
637 struct f_uas *fu = cmd->fu; in uasp_send_read_response() local
642 cmd->fu = fu; in uasp_send_read_response()
645 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_read_response()
650 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_send_read_response()
669 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_read_response()
680 struct f_uas *fu = cmd->fu; in uasp_send_write_request() local
687 cmd->fu = fu; in uasp_send_write_request()
691 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_write_request()
696 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_send_write_request()
712 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_write_request()
728 struct f_uas *fu = req->context; in uasp_cmd_complete() local
734 ret = usbg_submit_command(fu, req->buf, req->actual); in uasp_cmd_complete()
743 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
746 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) in uasp_alloc_stream_res() argument
748 stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in uasp_alloc_stream_res()
752 stream->req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in uasp_alloc_stream_res()
756 stream->req_status = usb_ep_alloc_request(fu->ep_status, GFP_KERNEL); in uasp_alloc_stream_res()
762 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_alloc_stream_res()
765 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_alloc_stream_res()
771 static int uasp_alloc_cmd(struct f_uas *fu) in uasp_alloc_cmd() argument
773 fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); in uasp_alloc_cmd()
774 if (!fu->cmd.req) in uasp_alloc_cmd()
777 fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); in uasp_alloc_cmd()
778 if (!fu->cmd.buf) in uasp_alloc_cmd()
781 fu->cmd.req->complete = uasp_cmd_complete; in uasp_alloc_cmd()
782 fu->cmd.req->buf = fu->cmd.buf; in uasp_alloc_cmd()
783 fu->cmd.req->length = fu->ep_cmd->maxpacket; in uasp_alloc_cmd()
784 fu->cmd.req->context = fu; in uasp_alloc_cmd()
788 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_alloc_cmd()
793 static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) in uasp_setup_stream_res() argument
798 struct uas_stream *s = &fu->stream[i]; in uasp_setup_stream_res()
806 static int uasp_prepare_reqs(struct f_uas *fu) in uasp_prepare_reqs() argument
812 if (fu->flags & USBG_USE_STREAMS) in uasp_prepare_reqs()
818 ret = uasp_alloc_stream_res(fu, &fu->stream[i]); in uasp_prepare_reqs()
823 ret = uasp_alloc_cmd(fu); in uasp_prepare_reqs()
826 uasp_setup_stream_res(fu, max_streams); in uasp_prepare_reqs()
828 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
835 uasp_free_cmdreq(fu); in uasp_prepare_reqs()
840 uasp_cleanup_one_stream(fu, &fu->stream[i - 1]); in uasp_prepare_reqs()
848 static void uasp_set_alt(struct f_uas *fu) in uasp_set_alt() argument
850 struct usb_function *f = &fu->function; in uasp_set_alt()
854 fu->flags = USBG_IS_UAS; in uasp_set_alt()
857 fu->flags |= USBG_USE_STREAMS; in uasp_set_alt()
859 config_ep_by_speed(gadget, f, fu->ep_in); in uasp_set_alt()
860 ret = usb_ep_enable(fu->ep_in); in uasp_set_alt()
864 config_ep_by_speed(gadget, f, fu->ep_out); in uasp_set_alt()
865 ret = usb_ep_enable(fu->ep_out); in uasp_set_alt()
869 config_ep_by_speed(gadget, f, fu->ep_cmd); in uasp_set_alt()
870 ret = usb_ep_enable(fu->ep_cmd); in uasp_set_alt()
873 config_ep_by_speed(gadget, f, fu->ep_status); in uasp_set_alt()
874 ret = usb_ep_enable(fu->ep_status); in uasp_set_alt()
878 ret = uasp_prepare_reqs(fu); in uasp_set_alt()
881 fu->flags |= USBG_ENABLED; in uasp_set_alt()
886 usb_ep_disable(fu->ep_status); in uasp_set_alt()
888 usb_ep_disable(fu->ep_cmd); in uasp_set_alt()
890 usb_ep_disable(fu->ep_out); in uasp_set_alt()
892 usb_ep_disable(fu->ep_in); in uasp_set_alt()
894 fu->flags = 0; in uasp_set_alt()
985 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request() local
986 struct usb_gadget *gadget = fuas_to_gadget(fu); in usbg_prepare_w_request()
1010 struct f_uas *fu = cmd->fu; in usbg_send_status_response() local
1012 if (fu->flags & USBG_IS_BOT) in usbg_send_status_response()
1022 struct f_uas *fu = cmd->fu; in usbg_send_write_request() local
1024 if (fu->flags & USBG_IS_BOT) in usbg_send_write_request()
1034 struct f_uas *fu = cmd->fu; in usbg_send_read_response() local
1036 if (fu->flags & USBG_IS_BOT) in usbg_send_read_response()
1051 tpg = cmd->fu->tpg; in usbg_cmd_work()
1075 static int usbg_submit_command(struct f_uas *fu, in usbg_submit_command() argument
1095 cmd->fu = fu; in usbg_submit_command()
1101 tpg = fu->tpg; in usbg_submit_command()
1110 if (fu->flags & USBG_USE_STREAMS) { in usbg_submit_command()
1114 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1116 cmd->stream = &fu->stream[cmd->tag - 1]; in usbg_submit_command()
1118 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1168 tpg = cmd->fu->tpg; in bot_cmd_work()
1192 static int bot_submit_command(struct f_uas *fu, in bot_submit_command() argument
1220 cmd->fu = fu; in bot_submit_command()
1226 tpg = fu->tpg; in bot_submit_command()
2017 struct f_uas *fu = to_f_uas(f); in usbg_bind() local
2029 fu->iface = iface; in usbg_bind()
2034 fu->ep_in = ep; in usbg_bind()
2040 fu->ep_out = ep; in usbg_bind()
2046 fu->ep_status = ep; in usbg_bind()
2052 fu->ep_cmd = ep; in usbg_bind()
2080 struct f_uas *fu = to_f_uas(f); in usbg_unbind() local
2083 kfree(fu); in usbg_unbind()
2088 struct f_uas *fu; member
2096 struct f_uas *fu = work->fu; in usbg_delayed_set_alt() local
2101 if (fu->flags & USBG_IS_BOT) in usbg_delayed_set_alt()
2102 bot_cleanup_old_alt(fu); in usbg_delayed_set_alt()
2103 if (fu->flags & USBG_IS_UAS) in usbg_delayed_set_alt()
2104 uasp_cleanup_old_alt(fu); in usbg_delayed_set_alt()
2107 bot_set_alt(fu); in usbg_delayed_set_alt()
2109 uasp_set_alt(fu); in usbg_delayed_set_alt()
2110 usb_composite_setup_continue(fu->function.config->cdev); in usbg_delayed_set_alt()
2115 struct f_uas *fu = to_f_uas(f); in usbg_set_alt() local
2124 work->fu = fu; in usbg_set_alt()
2134 struct f_uas *fu = to_f_uas(f); in usbg_disable() local
2136 if (fu->flags & USBG_IS_UAS) in usbg_disable()
2137 uasp_cleanup_old_alt(fu); in usbg_disable()
2138 else if (fu->flags & USBG_IS_BOT) in usbg_disable()
2139 bot_cleanup_old_alt(fu); in usbg_disable()
2140 fu->flags = 0; in usbg_disable()
2146 struct f_uas *fu = to_f_uas(f); in usbg_setup() local
2148 if (!(fu->flags & USBG_IS_BOT)) in usbg_setup()
2156 struct f_uas *fu; in usbg_cfg_bind() local
2159 fu = kzalloc(sizeof(*fu), GFP_KERNEL); in usbg_cfg_bind()
2160 if (!fu) in usbg_cfg_bind()
2162 fu->function.name = "Target Function"; in usbg_cfg_bind()
2163 fu->function.bind = usbg_bind; in usbg_cfg_bind()
2164 fu->function.unbind = usbg_unbind; in usbg_cfg_bind()
2165 fu->function.set_alt = usbg_set_alt; in usbg_cfg_bind()
2166 fu->function.setup = usbg_setup; in usbg_cfg_bind()
2167 fu->function.disable = usbg_disable; in usbg_cfg_bind()
2168 fu->tpg = the_only_tpg_I_currently_have; in usbg_cfg_bind()
2173 ret = usb_add_function(c, &fu->function); in usbg_cfg_bind()
2179 kfree(fu); in usbg_cfg_bind()