Lines Matching refs:fu

46 static int bot_enqueue_cmd_cbw(struct f_uas *fu)  in bot_enqueue_cmd_cbw()  argument
50 if (fu->flags & USBG_BOT_CMD_PEND) in bot_enqueue_cmd_cbw()
53 ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); in bot_enqueue_cmd_cbw()
55 fu->flags |= USBG_BOT_CMD_PEND; in bot_enqueue_cmd_cbw()
62 struct f_uas *fu = cmd->fu; in bot_status_complete() local
71 bot_enqueue_cmd_cbw(fu); in bot_status_complete()
74 static void bot_enqueue_sense_code(struct f_uas *fu, struct usbg_cmd *cmd) in bot_enqueue_sense_code() argument
76 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_enqueue_sense_code()
83 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
84 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_ATOMIC); in bot_enqueue_sense_code()
92 struct f_uas *fu = cmd->fu; in bot_err_compl() local
109 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
114 struct f_uas *fu = cmd->fu; in bot_send_bad_status() local
115 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_bad_status()
123 ep = fu->ep_in; in bot_send_bad_status()
124 req = fu->bot_req_in; in bot_send_bad_status()
126 ep = fu->ep_out; in bot_send_bad_status()
127 req = fu->bot_req_out; in bot_send_bad_status()
130 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
139 req->buf = fu->cmd.buf; in bot_send_bad_status()
142 bot_enqueue_sense_code(fu, cmd); in bot_send_bad_status()
148 struct f_uas *fu = cmd->fu; in bot_send_status() local
149 struct bulk_cs_wrap *csw = &fu->bot_status.csw; in bot_send_status()
166 fu->bot_status.req->context = cmd; in bot_send_status()
168 ret = usb_ep_queue(fu->ep_in, fu->bot_status.req, GFP_KERNEL); in bot_send_status()
204 struct f_uas *fu = cmd->fu; in bot_send_read_response() local
206 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_read_response()
225 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
227 fu->bot_req_in->buf = NULL; in bot_send_read_response()
228 fu->bot_req_in->num_sgs = se_cmd->t_data_nents; in bot_send_read_response()
229 fu->bot_req_in->sg = se_cmd->t_data_sg; in bot_send_read_response()
232 fu->bot_req_in->complete = bot_read_compl; in bot_send_read_response()
233 fu->bot_req_in->length = se_cmd->data_length; in bot_send_read_response()
234 fu->bot_req_in->context = cmd; in bot_send_read_response()
235 ret = usb_ep_queue(fu->ep_in, fu->bot_req_in, GFP_ATOMIC); in bot_send_read_response()
246 struct f_uas *fu = cmd->fu; in bot_send_write_request() local
248 struct usb_gadget *gadget = fuas_to_gadget(fu); in bot_send_write_request()
252 cmd->fu = fu; in bot_send_write_request()
264 fu->bot_req_out->buf = cmd->data_buf; in bot_send_write_request()
266 fu->bot_req_out->buf = NULL; in bot_send_write_request()
267 fu->bot_req_out->num_sgs = se_cmd->t_data_nents; in bot_send_write_request()
268 fu->bot_req_out->sg = se_cmd->t_data_sg; in bot_send_write_request()
271 fu->bot_req_out->complete = usbg_data_write_cmpl; in bot_send_write_request()
272 fu->bot_req_out->length = se_cmd->data_length; in bot_send_write_request()
273 fu->bot_req_out->context = cmd; in bot_send_write_request()
275 ret = usbg_prepare_w_request(cmd, fu->bot_req_out); in bot_send_write_request()
278 ret = usb_ep_queue(fu->ep_out, fu->bot_req_out, GFP_KERNEL); in bot_send_write_request()
292 struct f_uas *fu = req->context; in bot_cmd_complete() local
295 fu->flags &= ~USBG_BOT_CMD_PEND; in bot_cmd_complete()
300 ret = bot_submit_command(fu, req->buf, req->actual); in bot_cmd_complete()
305 static int bot_prepare_reqs(struct f_uas *fu) in bot_prepare_reqs() argument
309 fu->bot_req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
310 if (!fu->bot_req_in) in bot_prepare_reqs()
313 fu->bot_req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
314 if (!fu->bot_req_out) in bot_prepare_reqs()
317 fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
318 if (!fu->cmd.req) in bot_prepare_reqs()
321 fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in bot_prepare_reqs()
322 if (!fu->bot_status.req) in bot_prepare_reqs()
325 fu->bot_status.req->buf = &fu->bot_status.csw; in bot_prepare_reqs()
326 fu->bot_status.req->length = US_BULK_CS_WRAP_LEN; in bot_prepare_reqs()
327 fu->bot_status.req->complete = bot_status_complete; in bot_prepare_reqs()
328 fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); in bot_prepare_reqs()
330 fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); in bot_prepare_reqs()
331 if (!fu->cmd.buf) in bot_prepare_reqs()
334 fu->cmd.req->complete = bot_cmd_complete; in bot_prepare_reqs()
335 fu->cmd.req->buf = fu->cmd.buf; in bot_prepare_reqs()
336 fu->cmd.req->length = fu->ep_out->maxpacket; in bot_prepare_reqs()
337 fu->cmd.req->context = fu; in bot_prepare_reqs()
339 ret = bot_enqueue_cmd_cbw(fu); in bot_prepare_reqs()
344 kfree(fu->cmd.buf); in bot_prepare_reqs()
345 fu->cmd.buf = NULL; in bot_prepare_reqs()
347 usb_ep_free_request(fu->ep_in, fu->bot_status.req); in bot_prepare_reqs()
349 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_prepare_reqs()
350 fu->cmd.req = NULL; in bot_prepare_reqs()
352 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_prepare_reqs()
353 fu->bot_req_out = NULL; in bot_prepare_reqs()
355 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_prepare_reqs()
356 fu->bot_req_in = NULL; in bot_prepare_reqs()
362 static void bot_cleanup_old_alt(struct f_uas *fu) in bot_cleanup_old_alt() argument
364 if (!(fu->flags & USBG_ENABLED)) in bot_cleanup_old_alt()
367 usb_ep_disable(fu->ep_in); in bot_cleanup_old_alt()
368 usb_ep_disable(fu->ep_out); in bot_cleanup_old_alt()
370 if (!fu->bot_req_in) in bot_cleanup_old_alt()
373 usb_ep_free_request(fu->ep_in, fu->bot_req_in); in bot_cleanup_old_alt()
374 usb_ep_free_request(fu->ep_out, fu->bot_req_out); in bot_cleanup_old_alt()
375 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
376 usb_ep_free_request(fu->ep_in, fu->bot_status.req); in bot_cleanup_old_alt()
378 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
380 fu->bot_req_in = NULL; in bot_cleanup_old_alt()
381 fu->bot_req_out = NULL; in bot_cleanup_old_alt()
382 fu->cmd.req = NULL; in bot_cleanup_old_alt()
383 fu->bot_status.req = NULL; in bot_cleanup_old_alt()
384 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
387 static void bot_set_alt(struct f_uas *fu) in bot_set_alt() argument
389 struct usb_function *f = &fu->function; in bot_set_alt()
393 fu->flags = USBG_IS_BOT; in bot_set_alt()
395 config_ep_by_speed(gadget, f, fu->ep_in); in bot_set_alt()
396 ret = usb_ep_enable(fu->ep_in); in bot_set_alt()
400 config_ep_by_speed(gadget, f, fu->ep_out); in bot_set_alt()
401 ret = usb_ep_enable(fu->ep_out); in bot_set_alt()
405 ret = bot_prepare_reqs(fu); in bot_set_alt()
408 fu->flags |= USBG_ENABLED; in bot_set_alt()
412 usb_ep_disable(fu->ep_out); in bot_set_alt()
414 usb_ep_disable(fu->ep_in); in bot_set_alt()
416 fu->flags = USBG_IS_BOT; in bot_set_alt()
422 struct f_uas *fu = to_f_uas(f); in usbg_bot_setup() local
439 luns = atomic_read(&fu->tpg->tpg_port_count); in usbg_bot_setup()
460 bot_enqueue_cmd_cbw(fu); in usbg_bot_setup()
468 static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) in uasp_cleanup_one_stream() argument
474 usb_ep_free_request(fu->ep_in, stream->req_in); in uasp_cleanup_one_stream()
475 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_cleanup_one_stream()
476 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_cleanup_one_stream()
483 static void uasp_free_cmdreq(struct f_uas *fu) in uasp_free_cmdreq() argument
485 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_free_cmdreq()
486 kfree(fu->cmd.buf); in uasp_free_cmdreq()
487 fu->cmd.req = NULL; in uasp_free_cmdreq()
488 fu->cmd.buf = NULL; in uasp_free_cmdreq()
491 static void uasp_cleanup_old_alt(struct f_uas *fu) in uasp_cleanup_old_alt() argument
495 if (!(fu->flags & USBG_ENABLED)) in uasp_cleanup_old_alt()
498 usb_ep_disable(fu->ep_in); in uasp_cleanup_old_alt()
499 usb_ep_disable(fu->ep_out); in uasp_cleanup_old_alt()
500 usb_ep_disable(fu->ep_status); in uasp_cleanup_old_alt()
501 usb_ep_disable(fu->ep_cmd); in uasp_cleanup_old_alt()
504 uasp_cleanup_one_stream(fu, &fu->stream[i]); in uasp_cleanup_old_alt()
505 uasp_free_cmdreq(fu); in uasp_cleanup_old_alt()
513 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request() local
514 struct usb_gadget *gadget = fuas_to_gadget(fu); in uasp_prepare_r_request()
567 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl() local
578 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_status_data_cmpl()
587 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_status_data_cmpl()
594 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_status_data_cmpl()
602 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
616 struct f_uas *fu = cmd->fu; in uasp_send_status_response() local
623 cmd->fu = fu; in uasp_send_status_response()
625 return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); in uasp_send_status_response()
630 struct f_uas *fu = cmd->fu; in uasp_send_read_response() local
635 cmd->fu = fu; in uasp_send_read_response()
638 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_read_response()
643 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_send_read_response()
662 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_read_response()
673 struct f_uas *fu = cmd->fu; in uasp_send_write_request() local
680 cmd->fu = fu; in uasp_send_write_request()
684 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_write_request()
689 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_send_write_request()
705 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_write_request()
721 struct f_uas *fu = req->context; in uasp_cmd_complete() local
727 ret = usbg_submit_command(fu, req->buf, req->actual); in uasp_cmd_complete()
736 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
739 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) in uasp_alloc_stream_res() argument
741 stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in uasp_alloc_stream_res()
745 stream->req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in uasp_alloc_stream_res()
749 stream->req_status = usb_ep_alloc_request(fu->ep_status, GFP_KERNEL); in uasp_alloc_stream_res()
755 usb_ep_free_request(fu->ep_status, stream->req_status); in uasp_alloc_stream_res()
758 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_alloc_stream_res()
764 static int uasp_alloc_cmd(struct f_uas *fu) in uasp_alloc_cmd() argument
766 fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); in uasp_alloc_cmd()
767 if (!fu->cmd.req) in uasp_alloc_cmd()
770 fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); in uasp_alloc_cmd()
771 if (!fu->cmd.buf) in uasp_alloc_cmd()
774 fu->cmd.req->complete = uasp_cmd_complete; in uasp_alloc_cmd()
775 fu->cmd.req->buf = fu->cmd.buf; in uasp_alloc_cmd()
776 fu->cmd.req->length = fu->ep_cmd->maxpacket; in uasp_alloc_cmd()
777 fu->cmd.req->context = fu; in uasp_alloc_cmd()
781 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_alloc_cmd()
786 static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) in uasp_setup_stream_res() argument
791 struct uas_stream *s = &fu->stream[i]; in uasp_setup_stream_res()
799 static int uasp_prepare_reqs(struct f_uas *fu) in uasp_prepare_reqs() argument
805 if (fu->flags & USBG_USE_STREAMS) in uasp_prepare_reqs()
811 ret = uasp_alloc_stream_res(fu, &fu->stream[i]); in uasp_prepare_reqs()
816 ret = uasp_alloc_cmd(fu); in uasp_prepare_reqs()
819 uasp_setup_stream_res(fu, max_streams); in uasp_prepare_reqs()
821 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
828 uasp_free_cmdreq(fu); in uasp_prepare_reqs()
833 uasp_cleanup_one_stream(fu, &fu->stream[i - 1]); in uasp_prepare_reqs()
841 static void uasp_set_alt(struct f_uas *fu) in uasp_set_alt() argument
843 struct usb_function *f = &fu->function; in uasp_set_alt()
847 fu->flags = USBG_IS_UAS; in uasp_set_alt()
850 fu->flags |= USBG_USE_STREAMS; in uasp_set_alt()
852 config_ep_by_speed(gadget, f, fu->ep_in); in uasp_set_alt()
853 ret = usb_ep_enable(fu->ep_in); in uasp_set_alt()
857 config_ep_by_speed(gadget, f, fu->ep_out); in uasp_set_alt()
858 ret = usb_ep_enable(fu->ep_out); in uasp_set_alt()
862 config_ep_by_speed(gadget, f, fu->ep_cmd); in uasp_set_alt()
863 ret = usb_ep_enable(fu->ep_cmd); in uasp_set_alt()
866 config_ep_by_speed(gadget, f, fu->ep_status); in uasp_set_alt()
867 ret = usb_ep_enable(fu->ep_status); in uasp_set_alt()
871 ret = uasp_prepare_reqs(fu); in uasp_set_alt()
874 fu->flags |= USBG_ENABLED; in uasp_set_alt()
879 usb_ep_disable(fu->ep_status); in uasp_set_alt()
881 usb_ep_disable(fu->ep_cmd); in uasp_set_alt()
883 usb_ep_disable(fu->ep_out); in uasp_set_alt()
885 usb_ep_disable(fu->ep_in); in uasp_set_alt()
887 fu->flags = 0; in uasp_set_alt()
979 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request() local
980 struct usb_gadget *gadget = fuas_to_gadget(fu); in usbg_prepare_w_request()
1004 struct f_uas *fu = cmd->fu; in usbg_send_status_response() local
1006 if (fu->flags & USBG_IS_BOT) in usbg_send_status_response()
1016 struct f_uas *fu = cmd->fu; in usbg_send_write_request() local
1018 if (fu->flags & USBG_IS_BOT) in usbg_send_write_request()
1028 struct f_uas *fu = cmd->fu; in usbg_send_read_response() local
1030 if (fu->flags & USBG_IS_BOT) in usbg_send_read_response()
1045 tpg = cmd->fu->tpg; in usbg_cmd_work()
1069 static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, in usbg_get_cmd() argument
1085 cmd->fu = fu; in usbg_get_cmd()
1092 static int usbg_submit_command(struct f_uas *fu, in usbg_submit_command() argument
1097 struct usbg_tpg *tpg = fu->tpg; in usbg_submit_command()
1118 cmd = usbg_get_cmd(fu, tv_nexus, scsi_tag); in usbg_submit_command()
1125 if (fu->flags & USBG_USE_STREAMS) { in usbg_submit_command()
1129 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1131 cmd->stream = &fu->stream[cmd->tag - 1]; in usbg_submit_command()
1133 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1175 tpg = cmd->fu->tpg; in bot_cmd_work()
1199 static int bot_submit_command(struct f_uas *fu, in bot_submit_command() argument
1204 struct usbg_tpg *tpg = fu->tpg; in bot_submit_command()
1227 cmd = usbg_get_cmd(fu, tv_nexus, cbw->Tag); in bot_submit_command()
1989 struct f_uas *fu = to_f_uas(f); in tcm_bind() local
2018 fu->iface = iface; in tcm_bind()
2024 fu->ep_in = ep; in tcm_bind()
2030 fu->ep_out = ep; in tcm_bind()
2036 fu->ep_status = ep; in tcm_bind()
2042 fu->ep_cmd = ep; in tcm_bind()
2071 struct f_uas *fu; member
2079 struct f_uas *fu = work->fu; in tcm_delayed_set_alt() local
2084 if (fu->flags & USBG_IS_BOT) in tcm_delayed_set_alt()
2085 bot_cleanup_old_alt(fu); in tcm_delayed_set_alt()
2086 if (fu->flags & USBG_IS_UAS) in tcm_delayed_set_alt()
2087 uasp_cleanup_old_alt(fu); in tcm_delayed_set_alt()
2090 bot_set_alt(fu); in tcm_delayed_set_alt()
2092 uasp_set_alt(fu); in tcm_delayed_set_alt()
2093 usb_composite_setup_continue(fu->function.config->cdev); in tcm_delayed_set_alt()
2098 struct f_uas *fu = to_f_uas(f); in tcm_set_alt() local
2107 work->fu = fu; in tcm_set_alt()
2117 struct f_uas *fu = to_f_uas(f); in tcm_disable() local
2119 if (fu->flags & USBG_IS_UAS) in tcm_disable()
2120 uasp_cleanup_old_alt(fu); in tcm_disable()
2121 else if (fu->flags & USBG_IS_BOT) in tcm_disable()
2122 bot_cleanup_old_alt(fu); in tcm_disable()
2123 fu->flags = 0; in tcm_disable()
2129 struct f_uas *fu = to_f_uas(f); in tcm_setup() local
2131 if (!(fu->flags & USBG_IS_BOT)) in tcm_setup()
2281 struct f_uas *fu; in tcm_alloc() local
2293 fu = kzalloc(sizeof(*fu), GFP_KERNEL); in tcm_alloc()
2294 if (!fu) { in tcm_alloc()
2299 fu->function.name = "Target Function"; in tcm_alloc()
2300 fu->function.bind = tcm_bind; in tcm_alloc()
2301 fu->function.unbind = tcm_unbind; in tcm_alloc()
2302 fu->function.set_alt = tcm_set_alt; in tcm_alloc()
2303 fu->function.setup = tcm_setup; in tcm_alloc()
2304 fu->function.disable = tcm_disable; in tcm_alloc()
2305 fu->function.free_func = tcm_free; in tcm_alloc()
2306 fu->tpg = tpg_instances[i].tpg; in tcm_alloc()
2309 return &fu->function; in tcm_alloc()