Lines Matching refs:fu
48 static int bot_enqueue_cmd_cbw(struct f_uas *fu) in bot_enqueue_cmd_cbw() argument
52 if (fu->flags & USBG_BOT_CMD_PEND) in bot_enqueue_cmd_cbw()
55 ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); in bot_enqueue_cmd_cbw()
57 fu->flags |= USBG_BOT_CMD_PEND; in bot_enqueue_cmd_cbw()
64 struct f_uas *fu = cmd->fu; in bot_status_complete() local
73 bot_enqueue_cmd_cbw(fu); in bot_status_complete()
76 static void bot_enqueue_sense_code(struct f_uas *fu, struct usbg_cmd *cmd) in bot_enqueue_sense_code() argument
78 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_enqueue_sense_code()
94 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
95 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_ATOMIC); in bot_enqueue_sense_code()
103 struct f_uas *fu = cmd->fu; in bot_err_compl() local
120 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
125 struct f_uas *fu = cmd->fu; in bot_send_bad_status() local
126 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_bad_status()
134 ep = fu->ep_in; in bot_send_bad_status()
135 req = fu->bot_req_in; in bot_send_bad_status()
137 ep = fu->ep_out; in bot_send_bad_status()
138 req = fu->bot_req_out; in bot_send_bad_status()
141 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
150 req->buf = fu->cmd.buf; in bot_send_bad_status()
153 bot_enqueue_sense_code(fu, cmd); in bot_send_bad_status()
159 struct f_uas *fu = cmd->fu; in bot_send_status() local
160 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_status()
177 fu->bot_status.req->context = cmd; in bot_send_status()
179 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_KERNEL); in bot_send_status()
215 struct f_uas *fu = cmd->fu; in bot_send_read_response() local
217 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_read_response()
236 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
238 fu->bot_req_in->buf = NULL; in bot_send_read_response()
239 fu->bot_req_in->num_sgs = se_cmd->t_data_nents; in bot_send_read_response()
240 fu->bot_req_in->sg = se_cmd->t_data_sg; in bot_send_read_response()
243 fu->bot_req_in->complete = bot_read_compl; in bot_send_read_response()
244 fu->bot_req_in->length = se_cmd->data_length; in bot_send_read_response()
245 fu->bot_req_in->context = cmd; in bot_send_read_response()
246 ret = usb_ep_queue(fu->ep_in, fu->bot_req_in, GFP_ATOMIC); in bot_send_read_response()
257 struct f_uas *fu = cmd->fu; in bot_send_write_request() local
259 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_write_request()
263 cmd->fu = fu; in bot_send_write_request()
275 fu->bot_req_out->buf = cmd->data_buf; in bot_send_write_request()
277 fu->bot_req_out->buf = NULL; in bot_send_write_request()
278 fu->bot_req_out->num_sgs = se_cmd->t_data_nents; in bot_send_write_request()
279 fu->bot_req_out->sg = se_cmd->t_data_sg; in bot_send_write_request()
282 fu->bot_req_out->complete = usbg_data_write_cmpl; in bot_send_write_request()
283 fu->bot_req_out->length = se_cmd->data_length; in bot_send_write_request()
284 fu->bot_req_out->context = cmd; in bot_send_write_request()
286 ret = usbg_prepare_w_request(cmd, fu->bot_req_out); in bot_send_write_request()
289 ret = usb_ep_queue(fu->ep_out, fu->bot_req_out, GFP_KERNEL); in bot_send_write_request()
303 struct f_uas *fu = req->context; in bot_cmd_complete() local
306 fu->flags &= ~USBG_BOT_CMD_PEND; in bot_cmd_complete()
311 ret = bot_submit_command(fu, req->buf, req->actual); in bot_cmd_complete()
316 static int bot_prepare_reqs(struct f_uas *fu) in bot_prepare_reqs() argument
320 fu->bot_req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
321 if (!fu->bot_req_in) in bot_prepare_reqs()
324 fu->bot_req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
325 if (!fu->bot_req_out) in bot_prepare_reqs()
328 fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
329 if (!fu->cmd.req) in bot_prepare_reqs()
332 fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
333 if (!fu->bot_status.req) in bot_prepare_reqs()
336 fu->bot_status.req->buf = &fu->bot_status.csw; in bot_prepare_reqs()
337 fu->bot_status.req->length = US_BULK_CS_WRAP_LEN; in bot_prepare_reqs()
338 fu->bot_status.req->complete = bot_status_complete; in bot_prepare_reqs()
339 fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); in bot_prepare_reqs()
341 fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); in bot_prepare_reqs()
342 if (!fu->cmd.buf) in bot_prepare_reqs()
345 fu->cmd.req->complete = bot_cmd_complete; in bot_prepare_reqs()
346 fu->cmd.req->buf = fu->cmd.buf; in bot_prepare_reqs()
347 fu->cmd.req->length = fu->ep_out->maxpacket; in bot_prepare_reqs()
348 fu->cmd.req->context = fu; in bot_prepare_reqs()
350 ret = bot_enqueue_cmd_cbw(fu); in bot_prepare_reqs()
355 kfree(fu->cmd.buf); in bot_prepare_reqs()
356 fu->cmd.buf = NULL; in bot_prepare_reqs()
358 usb_ep_free_request(fu->ep_in, fu->bot_status.req); in bot_prepare_reqs()
360 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_prepare_reqs()
361 fu->cmd.req = NULL; in bot_prepare_reqs()
363 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_prepare_reqs()
364 fu->bot_req_out = NULL; in bot_prepare_reqs()
366 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_prepare_reqs()
367 fu->bot_req_in = NULL; in bot_prepare_reqs()
373 static void bot_cleanup_old_alt(struct f_uas *fu) in bot_cleanup_old_alt() argument
375 if (!(fu->flags & USBG_ENABLED)) in bot_cleanup_old_alt()
378 usb_ep_disable(fu->ep_in); in bot_cleanup_old_alt()
379 usb_ep_disable(fu->ep_out); in bot_cleanup_old_alt()
381 if (!fu->bot_req_in) in bot_cleanup_old_alt()
384 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_cleanup_old_alt()
385 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_cleanup_old_alt()
386 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
387 usb_ep_free_request(fu->ep_out, fu->bot_status.req); in bot_cleanup_old_alt()
389 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
391 fu->bot_req_in = NULL; in bot_cleanup_old_alt()
392 fu->bot_req_out = NULL; in bot_cleanup_old_alt()
393 fu->cmd.req = NULL; in bot_cleanup_old_alt()
394 fu->bot_status.req = NULL; in bot_cleanup_old_alt()
395 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
398 static void bot_set_alt(struct f_uas *fu) in bot_set_alt() argument
400 struct usb_function *f = &fu->function; in bot_set_alt()
404 fu->flags = USBG_IS_BOT; in bot_set_alt()
406 config_ep_by_speed(gadget, f, fu->ep_in); in bot_set_alt()
407 ret = usb_ep_enable(fu->ep_in); in bot_set_alt()
411 config_ep_by_speed(gadget, f, fu->ep_out); in bot_set_alt()
412 ret = usb_ep_enable(fu->ep_out); in bot_set_alt()
416 ret = bot_prepare_reqs(fu); in bot_set_alt()
419 fu->flags |= USBG_ENABLED; in bot_set_alt()
423 usb_ep_disable(fu->ep_out); in bot_set_alt()
425 usb_ep_disable(fu->ep_in); in bot_set_alt()
427 fu->flags = USBG_IS_BOT; in bot_set_alt()
433 struct f_uas *fu = to_f_uas(f); in usbg_bot_setup() local
450 luns = atomic_read(&fu->tpg->tpg_port_count); in usbg_bot_setup()
472 bot_enqueue_cmd_cbw(fu); in usbg_bot_setup()
481 static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) in uasp_cleanup_one_stream() argument
487 usb_ep_free_request(fu->ep_in, stream->req_in); in uasp_cleanup_one_stream()
488 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_cleanup_one_stream()
489 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_cleanup_one_stream()
496 static void uasp_free_cmdreq(struct f_uas *fu) in uasp_free_cmdreq() argument
498 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_free_cmdreq()
499 kfree(fu->cmd.buf); in uasp_free_cmdreq()
500 fu->cmd.req = NULL; in uasp_free_cmdreq()
501 fu->cmd.buf = NULL; in uasp_free_cmdreq()
504 static void uasp_cleanup_old_alt(struct f_uas *fu) in uasp_cleanup_old_alt() argument
508 if (!(fu->flags & USBG_ENABLED)) in uasp_cleanup_old_alt()
511 usb_ep_disable(fu->ep_in); in uasp_cleanup_old_alt()
512 usb_ep_disable(fu->ep_out); in uasp_cleanup_old_alt()
513 usb_ep_disable(fu->ep_status); in uasp_cleanup_old_alt()
514 usb_ep_disable(fu->ep_cmd); in uasp_cleanup_old_alt()
517 uasp_cleanup_one_stream(fu, &fu->stream[i]); in uasp_cleanup_old_alt()
518 uasp_free_cmdreq(fu); in uasp_cleanup_old_alt()
526 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request() local
527 struct usb_gadget *gadget = fuas_to_gadget(fu); in uasp_prepare_r_request()
580 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl() local
591 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_status_data_cmpl()
600 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_status_data_cmpl()
607 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_status_data_cmpl()
615 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
629 struct f_uas *fu = cmd->fu; in uasp_send_status_response() local
636 cmd->fu = fu; in uasp_send_status_response()
638 return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); in uasp_send_status_response()
643 struct f_uas *fu = cmd->fu; in uasp_send_read_response() local
648 cmd->fu = fu; in uasp_send_read_response()
651 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_read_response()
656 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_send_read_response()
675 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_read_response()
686 struct f_uas *fu = cmd->fu; in uasp_send_write_request() local
693 cmd->fu = fu; in uasp_send_write_request()
697 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_write_request()
702 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_send_write_request()
718 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_write_request()
734 struct f_uas *fu = req->context; in uasp_cmd_complete() local
740 ret = usbg_submit_command(fu, req->buf, req->actual); in uasp_cmd_complete()
749 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
752 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) in uasp_alloc_stream_res() argument
754 stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in uasp_alloc_stream_res()
758 stream->req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in uasp_alloc_stream_res()
762 stream->req_status = usb_ep_alloc_request(fu->ep_status, GFP_KERNEL); in uasp_alloc_stream_res()
768 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_alloc_stream_res()
771 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_alloc_stream_res()
777 static int uasp_alloc_cmd(struct f_uas *fu) in uasp_alloc_cmd() argument
779 fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); in uasp_alloc_cmd()
780 if (!fu->cmd.req) in uasp_alloc_cmd()
783 fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); in uasp_alloc_cmd()
784 if (!fu->cmd.buf) in uasp_alloc_cmd()
787 fu->cmd.req->complete = uasp_cmd_complete; in uasp_alloc_cmd()
788 fu->cmd.req->buf = fu->cmd.buf; in uasp_alloc_cmd()
789 fu->cmd.req->length = fu->ep_cmd->maxpacket; in uasp_alloc_cmd()
790 fu->cmd.req->context = fu; in uasp_alloc_cmd()
794 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_alloc_cmd()
799 static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) in uasp_setup_stream_res() argument
804 struct uas_stream *s = &fu->stream[i]; in uasp_setup_stream_res()
812 static int uasp_prepare_reqs(struct f_uas *fu) in uasp_prepare_reqs() argument
818 if (fu->flags & USBG_USE_STREAMS) in uasp_prepare_reqs()
824 ret = uasp_alloc_stream_res(fu, &fu->stream[i]); in uasp_prepare_reqs()
829 ret = uasp_alloc_cmd(fu); in uasp_prepare_reqs()
832 uasp_setup_stream_res(fu, max_streams); in uasp_prepare_reqs()
834 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
841 uasp_free_cmdreq(fu); in uasp_prepare_reqs()
846 uasp_cleanup_one_stream(fu, &fu->stream[i - 1]); in uasp_prepare_reqs()
854 static void uasp_set_alt(struct f_uas *fu) in uasp_set_alt() argument
856 struct usb_function *f = &fu->function; in uasp_set_alt()
860 fu->flags = USBG_IS_UAS; in uasp_set_alt()
863 fu->flags |= USBG_USE_STREAMS; in uasp_set_alt()
865 config_ep_by_speed(gadget, f, fu->ep_in); in uasp_set_alt()
866 ret = usb_ep_enable(fu->ep_in); in uasp_set_alt()
870 config_ep_by_speed(gadget, f, fu->ep_out); in uasp_set_alt()
871 ret = usb_ep_enable(fu->ep_out); in uasp_set_alt()
875 config_ep_by_speed(gadget, f, fu->ep_cmd); in uasp_set_alt()
876 ret = usb_ep_enable(fu->ep_cmd); in uasp_set_alt()
879 config_ep_by_speed(gadget, f, fu->ep_status); in uasp_set_alt()
880 ret = usb_ep_enable(fu->ep_status); in uasp_set_alt()
884 ret = uasp_prepare_reqs(fu); in uasp_set_alt()
887 fu->flags |= USBG_ENABLED; in uasp_set_alt()
892 usb_ep_disable(fu->ep_status); in uasp_set_alt()
894 usb_ep_disable(fu->ep_cmd); in uasp_set_alt()
896 usb_ep_disable(fu->ep_out); in uasp_set_alt()
898 usb_ep_disable(fu->ep_in); in uasp_set_alt()
900 fu->flags = 0; in uasp_set_alt()
991 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request() local
992 struct usb_gadget *gadget = fuas_to_gadget(fu); in usbg_prepare_w_request()
1016 struct f_uas *fu = cmd->fu; in usbg_send_status_response() local
1018 if (fu->flags & USBG_IS_BOT) in usbg_send_status_response()
1028 struct f_uas *fu = cmd->fu; in usbg_send_write_request() local
1030 if (fu->flags & USBG_IS_BOT) in usbg_send_write_request()
1040 struct f_uas *fu = cmd->fu; in usbg_send_read_response() local
1042 if (fu->flags & USBG_IS_BOT) in usbg_send_read_response()
1057 tpg = cmd->fu->tpg; in usbg_cmd_work()
1081 static int usbg_submit_command(struct f_uas *fu, in usbg_submit_command() argument
1101 cmd->fu = fu; in usbg_submit_command()
1107 tpg = fu->tpg; in usbg_submit_command()
1115 if (fu->flags & USBG_USE_STREAMS) { in usbg_submit_command()
1119 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1121 cmd->stream = &fu->stream[cmd->tag - 1]; in usbg_submit_command()
1123 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1173 tpg = cmd->fu->tpg; in bot_cmd_work()
1197 static int bot_submit_command(struct f_uas *fu, in bot_submit_command() argument
1225 cmd->fu = fu; in bot_submit_command()
1231 tpg = fu->tpg; in bot_submit_command()
1455 struct f_uas *fu = cmd->fu; in usbg_get_task_tag() local
1457 if (fu->flags & USBG_IS_BOT) in usbg_get_task_tag()
2200 struct f_uas *fu = to_f_uas(f); in usbg_bind() local
2212 fu->iface = iface; in usbg_bind()
2218 ep->driver_data = fu; in usbg_bind()
2219 fu->ep_in = ep; in usbg_bind()
2225 ep->driver_data = fu; in usbg_bind()
2226 fu->ep_out = ep; in usbg_bind()
2232 ep->driver_data = fu; in usbg_bind()
2233 fu->ep_status = ep; in usbg_bind()
2239 ep->driver_data = fu; in usbg_bind()
2240 fu->ep_cmd = ep; in usbg_bind()
2264 give_back_ep(&fu->ep_in); in usbg_bind()
2265 give_back_ep(&fu->ep_out); in usbg_bind()
2266 give_back_ep(&fu->ep_status); in usbg_bind()
2267 give_back_ep(&fu->ep_cmd); in usbg_bind()
2273 struct f_uas *fu = to_f_uas(f); in usbg_unbind() local
2276 kfree(fu); in usbg_unbind()
2281 struct f_uas *fu; member
2289 struct f_uas *fu = work->fu; in usbg_delayed_set_alt() local
2294 if (fu->flags & USBG_IS_BOT) in usbg_delayed_set_alt()
2295 bot_cleanup_old_alt(fu); in usbg_delayed_set_alt()
2296 if (fu->flags & USBG_IS_UAS) in usbg_delayed_set_alt()
2297 uasp_cleanup_old_alt(fu); in usbg_delayed_set_alt()
2300 bot_set_alt(fu); in usbg_delayed_set_alt()
2302 uasp_set_alt(fu); in usbg_delayed_set_alt()
2303 usb_composite_setup_continue(fu->function.config->cdev); in usbg_delayed_set_alt()
2308 struct f_uas *fu = to_f_uas(f); in usbg_set_alt() local
2317 work->fu = fu; in usbg_set_alt()
2327 struct f_uas *fu = to_f_uas(f); in usbg_disable() local
2329 if (fu->flags & USBG_IS_UAS) in usbg_disable()
2330 uasp_cleanup_old_alt(fu); in usbg_disable()
2331 else if (fu->flags & USBG_IS_BOT) in usbg_disable()
2332 bot_cleanup_old_alt(fu); in usbg_disable()
2333 fu->flags = 0; in usbg_disable()
2339 struct f_uas *fu = to_f_uas(f); in usbg_setup() local
2341 if (!(fu->flags & USBG_IS_BOT)) in usbg_setup()
2349 struct f_uas *fu; in usbg_cfg_bind() local
2352 fu = kzalloc(sizeof(*fu), GFP_KERNEL); in usbg_cfg_bind()
2353 if (!fu) in usbg_cfg_bind()
2355 fu->function.name = "Target Function"; in usbg_cfg_bind()
2356 fu->function.bind = usbg_bind; in usbg_cfg_bind()
2357 fu->function.unbind = usbg_unbind; in usbg_cfg_bind()
2358 fu->function.set_alt = usbg_set_alt; in usbg_cfg_bind()
2359 fu->function.setup = usbg_setup; in usbg_cfg_bind()
2360 fu->function.disable = usbg_disable; in usbg_cfg_bind()
2361 fu->tpg = the_only_tpg_I_currently_have; in usbg_cfg_bind()
2366 ret = usb_add_function(c, &fu->function); in usbg_cfg_bind()
2372 kfree(fu); in usbg_cfg_bind()