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_and_alt(gadget, f, fu->ep_in, USB_G_ALT_INT_BBB); in bot_set_alt()
396 ret = usb_ep_enable(fu->ep_in); in bot_set_alt()
400 config_ep_by_speed_and_alt(gadget, f, fu->ep_out, USB_G_ALT_INT_BBB); 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()
569 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl() local
580 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_status_data_cmpl()
589 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_status_data_cmpl()
596 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_status_data_cmpl()
604 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
618 struct f_uas *fu = cmd->fu; in uasp_send_status_response() local
625 cmd->fu = fu; in uasp_send_status_response()
627 return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); in uasp_send_status_response()
632 struct f_uas *fu = cmd->fu; in uasp_send_read_response() local
637 cmd->fu = fu; in uasp_send_read_response()
640 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_read_response()
645 ret = usb_ep_queue(fu->ep_in, stream->req_in, GFP_ATOMIC); in uasp_send_read_response()
664 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_read_response()
675 struct f_uas *fu = cmd->fu; in uasp_send_write_request() local
682 cmd->fu = fu; in uasp_send_write_request()
686 if (fu->flags & USBG_USE_STREAMS) { in uasp_send_write_request()
691 ret = usb_ep_queue(fu->ep_out, stream->req_out, GFP_ATOMIC); in uasp_send_write_request()
707 ret = usb_ep_queue(fu->ep_status, stream->req_status, in uasp_send_write_request()
723 struct f_uas *fu = req->context; in uasp_cmd_complete() local
729 ret = usbg_submit_command(fu, req->buf, req->actual); in uasp_cmd_complete()
738 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
741 static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) in uasp_alloc_stream_res() argument
743 stream->req_in = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); in uasp_alloc_stream_res()
747 stream->req_out = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in uasp_alloc_stream_res()
751 stream->req_status = usb_ep_alloc_request(fu->ep_status, GFP_KERNEL); in uasp_alloc_stream_res()
758 usb_ep_free_request(fu->ep_out, stream->req_out); in uasp_alloc_stream_res()
761 usb_ep_free_request(fu->ep_in, stream->req_in); in uasp_alloc_stream_res()
767 static int uasp_alloc_cmd(struct f_uas *fu) in uasp_alloc_cmd() argument
769 fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); in uasp_alloc_cmd()
770 if (!fu->cmd.req) in uasp_alloc_cmd()
773 fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); in uasp_alloc_cmd()
774 if (!fu->cmd.buf) in uasp_alloc_cmd()
777 fu->cmd.req->complete = uasp_cmd_complete; in uasp_alloc_cmd()
778 fu->cmd.req->buf = fu->cmd.buf; in uasp_alloc_cmd()
779 fu->cmd.req->length = fu->ep_cmd->maxpacket; in uasp_alloc_cmd()
780 fu->cmd.req->context = fu; in uasp_alloc_cmd()
784 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_alloc_cmd()
789 static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) in uasp_setup_stream_res() argument
794 struct uas_stream *s = &fu->stream[i]; in uasp_setup_stream_res()
802 static int uasp_prepare_reqs(struct f_uas *fu) in uasp_prepare_reqs() argument
808 if (fu->flags & USBG_USE_STREAMS) in uasp_prepare_reqs()
814 ret = uasp_alloc_stream_res(fu, &fu->stream[i]); in uasp_prepare_reqs()
819 ret = uasp_alloc_cmd(fu); in uasp_prepare_reqs()
822 uasp_setup_stream_res(fu, max_streams); in uasp_prepare_reqs()
824 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
831 uasp_free_cmdreq(fu); in uasp_prepare_reqs()
836 uasp_cleanup_one_stream(fu, &fu->stream[i - 1]); in uasp_prepare_reqs()
844 static void uasp_set_alt(struct f_uas *fu) in uasp_set_alt() argument
846 struct usb_function *f = &fu->function; in uasp_set_alt()
850 fu->flags = USBG_IS_UAS; in uasp_set_alt()
853 fu->flags |= USBG_USE_STREAMS; in uasp_set_alt()
855 config_ep_by_speed_and_alt(gadget, f, fu->ep_in, USB_G_ALT_INT_UAS); in uasp_set_alt()
856 ret = usb_ep_enable(fu->ep_in); in uasp_set_alt()
860 config_ep_by_speed_and_alt(gadget, f, fu->ep_out, USB_G_ALT_INT_UAS); in uasp_set_alt()
861 ret = usb_ep_enable(fu->ep_out); in uasp_set_alt()
865 config_ep_by_speed_and_alt(gadget, f, fu->ep_cmd, USB_G_ALT_INT_UAS); in uasp_set_alt()
866 ret = usb_ep_enable(fu->ep_cmd); in uasp_set_alt()
869 config_ep_by_speed_and_alt(gadget, f, fu->ep_status, USB_G_ALT_INT_UAS); in uasp_set_alt()
870 ret = usb_ep_enable(fu->ep_status); in uasp_set_alt()
874 ret = uasp_prepare_reqs(fu); in uasp_set_alt()
877 fu->flags |= USBG_ENABLED; in uasp_set_alt()
882 usb_ep_disable(fu->ep_status); in uasp_set_alt()
884 usb_ep_disable(fu->ep_cmd); in uasp_set_alt()
886 usb_ep_disable(fu->ep_out); in uasp_set_alt()
888 usb_ep_disable(fu->ep_in); in uasp_set_alt()
890 fu->flags = 0; in uasp_set_alt()
982 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request() local
983 struct usb_gadget *gadget = fuas_to_gadget(fu); in usbg_prepare_w_request()
1008 struct f_uas *fu = cmd->fu; in usbg_send_status_response() local
1010 if (fu->flags & USBG_IS_BOT) in usbg_send_status_response()
1020 struct f_uas *fu = cmd->fu; in usbg_send_write_request() local
1022 if (fu->flags & USBG_IS_BOT) in usbg_send_write_request()
1032 struct f_uas *fu = cmd->fu; in usbg_send_read_response() local
1034 if (fu->flags & USBG_IS_BOT) in usbg_send_read_response()
1049 tpg = cmd->fu->tpg; in usbg_cmd_work()
1072 static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, in usbg_get_cmd() argument
1088 cmd->fu = fu; in usbg_get_cmd()
1095 static int usbg_submit_command(struct f_uas *fu, in usbg_submit_command() argument
1100 struct usbg_tpg *tpg = fu->tpg; in usbg_submit_command()
1121 cmd = usbg_get_cmd(fu, tv_nexus, scsi_tag); in usbg_submit_command()
1128 if (fu->flags & USBG_USE_STREAMS) { in usbg_submit_command()
1132 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1134 cmd->stream = &fu->stream[cmd->tag - 1]; in usbg_submit_command()
1136 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1178 tpg = cmd->fu->tpg; in bot_cmd_work()
1201 static int bot_submit_command(struct f_uas *fu, in bot_submit_command() argument
1206 struct usbg_tpg *tpg = fu->tpg; in bot_submit_command()
1229 cmd = usbg_get_cmd(fu, tv_nexus, cbw->Tag); in bot_submit_command()
1941 struct f_uas *fu = to_f_uas(f); in tcm_bind() local
1970 fu->iface = iface; in tcm_bind()
1976 fu->ep_in = ep; in tcm_bind()
1982 fu->ep_out = ep; in tcm_bind()
1988 fu->ep_status = ep; in tcm_bind()
1994 fu->ep_cmd = ep; in tcm_bind()
2024 struct f_uas *fu; member
2032 struct f_uas *fu = work->fu; in tcm_delayed_set_alt() local
2037 if (fu->flags & USBG_IS_BOT) in tcm_delayed_set_alt()
2038 bot_cleanup_old_alt(fu); in tcm_delayed_set_alt()
2039 if (fu->flags & USBG_IS_UAS) in tcm_delayed_set_alt()
2040 uasp_cleanup_old_alt(fu); in tcm_delayed_set_alt()
2043 bot_set_alt(fu); in tcm_delayed_set_alt()
2045 uasp_set_alt(fu); in tcm_delayed_set_alt()
2046 usb_composite_setup_continue(fu->function.config->cdev); in tcm_delayed_set_alt()
2061 struct f_uas *fu = to_f_uas(f); in tcm_set_alt() local
2070 work->fu = fu; in tcm_set_alt()
2080 struct f_uas *fu = to_f_uas(f); in tcm_disable() local
2082 if (fu->flags & USBG_IS_UAS) in tcm_disable()
2083 uasp_cleanup_old_alt(fu); in tcm_disable()
2084 else if (fu->flags & USBG_IS_BOT) in tcm_disable()
2085 bot_cleanup_old_alt(fu); in tcm_disable()
2086 fu->flags = 0; in tcm_disable()
2092 struct f_uas *fu = to_f_uas(f); in tcm_setup() local
2094 if (!(fu->flags & USBG_IS_BOT)) in tcm_setup()
2244 struct f_uas *fu; in tcm_alloc() local
2256 fu = kzalloc(sizeof(*fu), GFP_KERNEL); in tcm_alloc()
2257 if (!fu) { in tcm_alloc()
2262 fu->function.name = "Target Function"; in tcm_alloc()
2263 fu->function.bind = tcm_bind; in tcm_alloc()
2264 fu->function.unbind = tcm_unbind; in tcm_alloc()
2265 fu->function.set_alt = tcm_set_alt; in tcm_alloc()
2266 fu->function.get_alt = tcm_get_alt; in tcm_alloc()
2267 fu->function.setup = tcm_setup; in tcm_alloc()
2268 fu->function.disable = tcm_disable; in tcm_alloc()
2269 fu->function.free_func = tcm_free; in tcm_alloc()
2270 fu->tpg = tpg_instances[i].tpg; in tcm_alloc()
2273 return &fu->function; in tcm_alloc()