Lines Matching refs:cmd

53 	ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC);  in bot_enqueue_cmd_cbw()
61 struct usbg_cmd *cmd = req->context; in bot_status_complete() local
62 struct f_uas *fu = cmd->fu; in bot_status_complete()
64 transport_generic_free_cmd(&cmd->se_cmd, 0); 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
80 csw_stat = cmd->csw_code; in bot_enqueue_sense_code()
81 csw->Tag = cmd->bot_tag; in bot_enqueue_sense_code()
83 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
91 struct usbg_cmd *cmd = req->context; in bot_err_compl() local
92 struct f_uas *fu = cmd->fu; in bot_err_compl()
97 if (cmd->data_len) { in bot_err_compl()
98 if (cmd->data_len > ep->maxpacket) { in bot_err_compl()
100 cmd->data_len -= ep->maxpacket; in bot_err_compl()
102 req->length = cmd->data_len; in bot_err_compl()
103 cmd->data_len = 0; in bot_err_compl()
109 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
112 static void bot_send_bad_status(struct usbg_cmd *cmd) in bot_send_bad_status() argument
114 struct f_uas *fu = cmd->fu; in bot_send_bad_status()
119 csw->Residue = cpu_to_le32(cmd->data_len); in bot_send_bad_status()
121 if (cmd->data_len) { in bot_send_bad_status()
122 if (cmd->is_read) { in bot_send_bad_status()
130 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
132 cmd->data_len -= ep->maxpacket; in bot_send_bad_status()
134 req->length = cmd->data_len; in bot_send_bad_status()
135 cmd->data_len = 0; in bot_send_bad_status()
138 req->context = cmd; 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()
146 static int bot_send_status(struct usbg_cmd *cmd, bool moved_data) in bot_send_status() argument
148 struct f_uas *fu = cmd->fu; in bot_send_status()
152 if (cmd->se_cmd.scsi_status == SAM_STAT_GOOD) { in bot_send_status()
153 if (!moved_data && cmd->data_len) { in bot_send_status()
158 cmd->csw_code = US_BULK_STAT_OK; in bot_send_status()
159 bot_send_bad_status(cmd); in bot_send_status()
163 csw->Tag = cmd->bot_tag; in bot_send_status()
166 fu->bot_status.req->context = cmd; in bot_send_status()
172 cmd->csw_code = US_BULK_STAT_FAIL; in bot_send_status()
173 bot_send_bad_status(cmd); in bot_send_status()
182 static int bot_send_status_response(struct usbg_cmd *cmd) in bot_send_status_response() argument
186 if (!cmd->is_read) in bot_send_status_response()
188 return bot_send_status(cmd, moved_data); in bot_send_status_response()
194 struct usbg_cmd *cmd = req->context; in bot_read_compl() local
199 bot_send_status(cmd, true); in bot_read_compl()
202 static int bot_send_read_response(struct usbg_cmd *cmd) in bot_send_read_response() argument
204 struct f_uas *fu = cmd->fu; in bot_send_read_response()
205 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_read_response()
209 if (!cmd->data_len) { in bot_send_read_response()
210 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_read_response()
211 bot_send_bad_status(cmd); in bot_send_read_response()
216 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in bot_send_read_response()
217 if (!cmd->data_buf) in bot_send_read_response()
222 cmd->data_buf, in bot_send_read_response()
225 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
234 fu->bot_req_in->context = cmd; in bot_send_read_response()
244 static int bot_send_write_request(struct usbg_cmd *cmd) in bot_send_write_request() argument
246 struct f_uas *fu = cmd->fu; in bot_send_write_request()
247 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_write_request()
251 init_completion(&cmd->write_complete); in bot_send_write_request()
252 cmd->fu = fu; in bot_send_write_request()
254 if (!cmd->data_len) { in bot_send_write_request()
255 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_write_request()
260 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_KERNEL); in bot_send_write_request()
261 if (!cmd->data_buf) in bot_send_write_request()
264 fu->bot_req_out->buf = cmd->data_buf; 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()
282 wait_for_completion(&cmd->write_complete); in bot_send_write_request()
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()
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()
344 kfree(fu->cmd.buf); in bot_prepare_reqs()
345 fu->cmd.buf = NULL; 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()
375 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
378 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
382 fu->cmd.req = NULL; in bot_cleanup_old_alt()
384 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
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()
510 static int uasp_prepare_r_request(struct usbg_cmd *cmd) in uasp_prepare_r_request() argument
512 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_r_request()
513 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request()
515 struct uas_stream *stream = cmd->stream; in uasp_prepare_r_request()
518 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in uasp_prepare_r_request()
519 if (!cmd->data_buf) in uasp_prepare_r_request()
524 cmd->data_buf, in uasp_prepare_r_request()
527 stream->req_in->buf = cmd->data_buf; in uasp_prepare_r_request()
537 stream->req_in->context = cmd; in uasp_prepare_r_request()
539 cmd->state = UASP_SEND_STATUS; in uasp_prepare_r_request()
543 static void uasp_prepare_status(struct usbg_cmd *cmd) in uasp_prepare_status() argument
545 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_status()
546 struct sense_iu *iu = &cmd->sense_iu; in uasp_prepare_status()
547 struct uas_stream *stream = cmd->stream; in uasp_prepare_status()
549 cmd->state = UASP_QUEUE_COMMAND; in uasp_prepare_status()
551 iu->tag = cpu_to_be16(cmd->tag); in uasp_prepare_status()
559 stream->req_status->context = cmd; in uasp_prepare_status()
567 struct usbg_cmd *cmd = req->context; in uasp_status_data_cmpl() local
568 struct uas_stream *stream = cmd->stream; in uasp_status_data_cmpl()
569 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl()
575 switch (cmd->state) { in uasp_status_data_cmpl()
577 ret = uasp_prepare_r_request(cmd); in uasp_status_data_cmpl()
586 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_status_data_cmpl()
595 uasp_prepare_status(cmd); in uasp_status_data_cmpl()
603 transport_generic_free_cmd(&cmd->se_cmd, 0); in uasp_status_data_cmpl()
604 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
613 transport_generic_free_cmd(&cmd->se_cmd, 0); in uasp_status_data_cmpl()
616 static int uasp_send_status_response(struct usbg_cmd *cmd) in uasp_send_status_response() argument
618 struct f_uas *fu = cmd->fu; in uasp_send_status_response()
619 struct uas_stream *stream = cmd->stream; in uasp_send_status_response()
620 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_status_response()
622 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_status_response()
624 stream->req_status->context = cmd; in uasp_send_status_response()
625 cmd->fu = fu; in uasp_send_status_response()
626 uasp_prepare_status(cmd); in uasp_send_status_response()
630 static int uasp_send_read_response(struct usbg_cmd *cmd) in uasp_send_read_response() argument
632 struct f_uas *fu = cmd->fu; in uasp_send_read_response()
633 struct uas_stream *stream = cmd->stream; in uasp_send_read_response()
634 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_read_response()
637 cmd->fu = fu; in uasp_send_read_response()
639 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
642 ret = uasp_prepare_r_request(cmd); in uasp_send_read_response()
648 kfree(cmd->data_buf); in uasp_send_read_response()
649 cmd->data_buf = NULL; in uasp_send_read_response()
655 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
658 stream->req_status->context = cmd; in uasp_send_read_response()
660 cmd->state = UASP_SEND_DATA; in uasp_send_read_response()
673 static int uasp_send_write_request(struct usbg_cmd *cmd) in uasp_send_write_request() argument
675 struct f_uas *fu = cmd->fu; in uasp_send_write_request()
676 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_send_write_request()
677 struct uas_stream *stream = cmd->stream; in uasp_send_write_request()
678 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_write_request()
681 init_completion(&cmd->write_complete); in uasp_send_write_request()
682 cmd->fu = fu; in uasp_send_write_request()
684 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
688 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_send_write_request()
698 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
701 stream->req_status->context = cmd; in uasp_send_write_request()
703 cmd->state = UASP_RECEIVE_DATA; in uasp_send_write_request()
713 wait_for_completion(&cmd->write_complete); in uasp_send_write_request()
738 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
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()
824 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
957 struct usbg_cmd *cmd = req->context; in usbg_data_write_cmpl() local
958 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_data_write_cmpl()
961 pr_err("%s() state %d transfer failed\n", __func__, cmd->state); in usbg_data_write_cmpl()
968 cmd->data_buf, in usbg_data_write_cmpl()
972 complete(&cmd->write_complete); in usbg_data_write_cmpl()
976 transport_generic_free_cmd(&cmd->se_cmd, 0); in usbg_data_write_cmpl()
979 static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) in usbg_prepare_w_request() argument
981 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_prepare_w_request()
982 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request()
986 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in usbg_prepare_w_request()
987 if (!cmd->data_buf) in usbg_prepare_w_request()
990 req->buf = cmd->data_buf; in usbg_prepare_w_request()
1000 req->context = cmd; in usbg_prepare_w_request()
1006 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_status_response() local
1008 struct f_uas *fu = cmd->fu; in usbg_send_status_response()
1011 return bot_send_status_response(cmd); in usbg_send_status_response()
1013 return uasp_send_status_response(cmd); in usbg_send_status_response()
1018 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_write_request() local
1020 struct f_uas *fu = cmd->fu; in usbg_send_write_request()
1023 return bot_send_write_request(cmd); in usbg_send_write_request()
1025 return uasp_send_write_request(cmd); in usbg_send_write_request()
1030 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_read_response() local
1032 struct f_uas *fu = cmd->fu; in usbg_send_read_response()
1035 return bot_send_read_response(cmd); in usbg_send_read_response()
1037 return uasp_send_read_response(cmd); in usbg_send_read_response()
1042 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in usbg_cmd_work() local
1048 se_cmd = &cmd->se_cmd; in usbg_cmd_work()
1049 tpg = cmd->fu->tpg; in usbg_cmd_work()
1051 dir = get_cmd_dir(cmd->cmd_buf); in usbg_cmd_work()
1055 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in usbg_cmd_work()
1056 cmd->prio_attr, cmd->sense_iu.sense, in usbg_cmd_work()
1057 cmd->unpacked_lun, NULL); in usbg_cmd_work()
1061 target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf, in usbg_cmd_work()
1062 cmd->sense_iu.sense, cmd->unpacked_lun, 0, in usbg_cmd_work()
1063 cmd->prio_attr, dir, flags); in usbg_cmd_work()
1069 transport_generic_free_cmd(&cmd->se_cmd, 0); in usbg_cmd_work()
1076 struct usbg_cmd *cmd; in usbg_get_cmd() local
1083 cmd = &((struct usbg_cmd *)se_sess->sess_cmd_map)[tag]; in usbg_get_cmd()
1084 memset(cmd, 0, sizeof(*cmd)); in usbg_get_cmd()
1085 cmd->se_cmd.map_tag = tag; in usbg_get_cmd()
1086 cmd->se_cmd.map_cpu = cpu; in usbg_get_cmd()
1087 cmd->se_cmd.tag = cmd->tag = scsi_tag; in usbg_get_cmd()
1088 cmd->fu = fu; in usbg_get_cmd()
1090 return cmd; in usbg_get_cmd()
1099 struct usbg_cmd *cmd; in usbg_submit_command() local
1121 cmd = usbg_get_cmd(fu, tv_nexus, scsi_tag); in usbg_submit_command()
1122 if (IS_ERR(cmd)) { in usbg_submit_command()
1126 memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); in usbg_submit_command()
1129 if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) in usbg_submit_command()
1131 if (!cmd->tag) 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()
1141 cmd->prio_attr = TCM_HEAD_TAG; in usbg_submit_command()
1144 cmd->prio_attr = TCM_ORDERED_TAG; in usbg_submit_command()
1147 cmd->prio_attr = TCM_ACA_TAG; in usbg_submit_command()
1154 cmd->prio_attr = TCM_SIMPLE_TAG; in usbg_submit_command()
1158 cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); in usbg_submit_command()
1160 INIT_WORK(&cmd->work, usbg_cmd_work); in usbg_submit_command()
1161 queue_work(tpg->workqueue, &cmd->work); in usbg_submit_command()
1165 usbg_release_cmd(&cmd->se_cmd); in usbg_submit_command()
1171 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in bot_cmd_work() local
1177 se_cmd = &cmd->se_cmd; in bot_cmd_work()
1178 tpg = cmd->fu->tpg; in bot_cmd_work()
1180 dir = get_cmd_dir(cmd->cmd_buf); in bot_cmd_work()
1184 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in bot_cmd_work()
1185 cmd->prio_attr, cmd->sense_iu.sense, in bot_cmd_work()
1186 cmd->unpacked_lun, NULL); in bot_cmd_work()
1191 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, in bot_cmd_work()
1192 cmd->data_len, cmd->prio_attr, dir, 0); in bot_cmd_work()
1198 transport_generic_free_cmd(&cmd->se_cmd, 0); in bot_cmd_work()
1205 struct usbg_cmd *cmd; in bot_submit_command() local
1229 cmd = usbg_get_cmd(fu, tv_nexus, cbw->Tag); in bot_submit_command()
1230 if (IS_ERR(cmd)) { in bot_submit_command()
1234 memcpy(cmd->cmd_buf, cbw->CDB, cmd_len); in bot_submit_command()
1236 cmd->bot_tag = cbw->Tag; in bot_submit_command()
1237 cmd->prio_attr = TCM_SIMPLE_TAG; in bot_submit_command()
1238 cmd->unpacked_lun = cbw->Lun; in bot_submit_command()
1239 cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; in bot_submit_command()
1240 cmd->data_len = le32_to_cpu(cbw->DataTransferLength); in bot_submit_command()
1241 cmd->se_cmd.tag = le32_to_cpu(cmd->bot_tag); in bot_submit_command()
1243 INIT_WORK(&cmd->work, bot_cmd_work); in bot_submit_command()
1244 queue_work(tpg->workqueue, &cmd->work); in bot_submit_command()
1274 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_release_cmd() local
1278 kfree(cmd->data_buf); in usbg_release_cmd()