Lines Matching refs:cmd

41 static inline void usbg_cleanup_cmd(struct usbg_cmd *cmd)  in usbg_cleanup_cmd()  argument
43 kref_put(&cmd->ref, usbg_cmd_release); in usbg_cleanup_cmd()
55 ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); in bot_enqueue_cmd_cbw()
63 struct usbg_cmd *cmd = req->context; in bot_status_complete() local
64 struct f_uas *fu = cmd->fu; in bot_status_complete()
66 usbg_cleanup_cmd(cmd); 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
83 csw_stat = cmd->csw_code; in bot_enqueue_sense_code()
90 sense = cmd->sense_iu.sense; in bot_enqueue_sense_code()
92 csw->Tag = cmd->bot_tag; in bot_enqueue_sense_code()
94 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
102 struct usbg_cmd *cmd = req->context; in bot_err_compl() local
103 struct f_uas *fu = cmd->fu; in bot_err_compl()
108 if (cmd->data_len) { in bot_err_compl()
109 if (cmd->data_len > ep->maxpacket) { in bot_err_compl()
111 cmd->data_len -= ep->maxpacket; in bot_err_compl()
113 req->length = cmd->data_len; in bot_err_compl()
114 cmd->data_len = 0; in bot_err_compl()
120 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
123 static void bot_send_bad_status(struct usbg_cmd *cmd) in bot_send_bad_status() argument
125 struct f_uas *fu = cmd->fu; in bot_send_bad_status()
130 csw->Residue = cpu_to_le32(cmd->data_len); in bot_send_bad_status()
132 if (cmd->data_len) { in bot_send_bad_status()
133 if (cmd->is_read) { in bot_send_bad_status()
141 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
143 cmd->data_len -= ep->maxpacket; in bot_send_bad_status()
145 req->length = cmd->data_len; in bot_send_bad_status()
146 cmd->data_len = 0; in bot_send_bad_status()
149 req->context = cmd; 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()
157 static int bot_send_status(struct usbg_cmd *cmd, bool moved_data) in bot_send_status() argument
159 struct f_uas *fu = cmd->fu; in bot_send_status()
163 if (cmd->se_cmd.scsi_status == SAM_STAT_GOOD) { in bot_send_status()
164 if (!moved_data && cmd->data_len) { in bot_send_status()
169 cmd->csw_code = US_BULK_STAT_OK; in bot_send_status()
170 bot_send_bad_status(cmd); in bot_send_status()
174 csw->Tag = cmd->bot_tag; in bot_send_status()
177 fu->bot_status.req->context = cmd; in bot_send_status()
183 cmd->csw_code = US_BULK_STAT_FAIL; in bot_send_status()
184 bot_send_bad_status(cmd); in bot_send_status()
193 static int bot_send_status_response(struct usbg_cmd *cmd) in bot_send_status_response() argument
197 if (!cmd->is_read) in bot_send_status_response()
199 return bot_send_status(cmd, moved_data); in bot_send_status_response()
205 struct usbg_cmd *cmd = req->context; in bot_read_compl() local
210 bot_send_status(cmd, true); in bot_read_compl()
213 static int bot_send_read_response(struct usbg_cmd *cmd) in bot_send_read_response() argument
215 struct f_uas *fu = cmd->fu; in bot_send_read_response()
216 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_read_response()
220 if (!cmd->data_len) { in bot_send_read_response()
221 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_read_response()
222 bot_send_bad_status(cmd); in bot_send_read_response()
227 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in bot_send_read_response()
228 if (!cmd->data_buf) in bot_send_read_response()
233 cmd->data_buf, in bot_send_read_response()
236 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
245 fu->bot_req_in->context = cmd; in bot_send_read_response()
255 static int bot_send_write_request(struct usbg_cmd *cmd) in bot_send_write_request() argument
257 struct f_uas *fu = cmd->fu; in bot_send_write_request()
258 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_write_request()
262 init_completion(&cmd->write_complete); in bot_send_write_request()
263 cmd->fu = fu; in bot_send_write_request()
265 if (!cmd->data_len) { in bot_send_write_request()
266 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_write_request()
271 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_KERNEL); in bot_send_write_request()
272 if (!cmd->data_buf) in bot_send_write_request()
275 fu->bot_req_out->buf = cmd->data_buf; 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()
293 wait_for_completion(&cmd->write_complete); in bot_send_write_request()
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()
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()
355 kfree(fu->cmd.buf); in bot_prepare_reqs()
356 fu->cmd.buf = NULL; 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()
386 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
389 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
393 fu->cmd.req = NULL; in bot_cleanup_old_alt()
395 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
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()
523 static int uasp_prepare_r_request(struct usbg_cmd *cmd) in uasp_prepare_r_request() argument
525 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_r_request()
526 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request()
528 struct uas_stream *stream = cmd->stream; in uasp_prepare_r_request()
531 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in uasp_prepare_r_request()
532 if (!cmd->data_buf) in uasp_prepare_r_request()
537 cmd->data_buf, in uasp_prepare_r_request()
540 stream->req_in->buf = cmd->data_buf; in uasp_prepare_r_request()
549 stream->req_in->context = cmd; in uasp_prepare_r_request()
551 cmd->state = UASP_SEND_STATUS; in uasp_prepare_r_request()
555 static void uasp_prepare_status(struct usbg_cmd *cmd) in uasp_prepare_status() argument
557 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_status()
558 struct sense_iu *iu = &cmd->sense_iu; in uasp_prepare_status()
559 struct uas_stream *stream = cmd->stream; in uasp_prepare_status()
561 cmd->state = UASP_QUEUE_COMMAND; in uasp_prepare_status()
563 iu->tag = cpu_to_be16(cmd->tag); in uasp_prepare_status()
570 stream->req_status->context = cmd; in uasp_prepare_status()
578 struct usbg_cmd *cmd = req->context; in uasp_status_data_cmpl() local
579 struct uas_stream *stream = cmd->stream; in uasp_status_data_cmpl()
580 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl()
586 switch (cmd->state) { in uasp_status_data_cmpl()
588 ret = uasp_prepare_r_request(cmd); in uasp_status_data_cmpl()
597 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_status_data_cmpl()
606 uasp_prepare_status(cmd); in uasp_status_data_cmpl()
614 usbg_cleanup_cmd(cmd); in uasp_status_data_cmpl()
615 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
624 usbg_cleanup_cmd(cmd); in uasp_status_data_cmpl()
627 static int uasp_send_status_response(struct usbg_cmd *cmd) in uasp_send_status_response() argument
629 struct f_uas *fu = cmd->fu; in uasp_send_status_response()
630 struct uas_stream *stream = cmd->stream; in uasp_send_status_response()
631 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_status_response()
633 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_status_response()
635 stream->req_status->context = cmd; in uasp_send_status_response()
636 cmd->fu = fu; in uasp_send_status_response()
637 uasp_prepare_status(cmd); in uasp_send_status_response()
641 static int uasp_send_read_response(struct usbg_cmd *cmd) in uasp_send_read_response() argument
643 struct f_uas *fu = cmd->fu; in uasp_send_read_response()
644 struct uas_stream *stream = cmd->stream; in uasp_send_read_response()
645 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_read_response()
648 cmd->fu = fu; in uasp_send_read_response()
650 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
653 ret = uasp_prepare_r_request(cmd); in uasp_send_read_response()
659 kfree(cmd->data_buf); in uasp_send_read_response()
660 cmd->data_buf = NULL; in uasp_send_read_response()
666 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
669 stream->req_status->context = cmd; in uasp_send_read_response()
671 cmd->state = UASP_SEND_DATA; in uasp_send_read_response()
684 static int uasp_send_write_request(struct usbg_cmd *cmd) in uasp_send_write_request() argument
686 struct f_uas *fu = cmd->fu; in uasp_send_write_request()
687 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_send_write_request()
688 struct uas_stream *stream = cmd->stream; in uasp_send_write_request()
689 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_write_request()
692 init_completion(&cmd->write_complete); in uasp_send_write_request()
693 cmd->fu = fu; in uasp_send_write_request()
695 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
699 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_send_write_request()
709 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
712 stream->req_status->context = cmd; in uasp_send_write_request()
714 cmd->state = UASP_RECEIVE_DATA; in uasp_send_write_request()
724 wait_for_completion(&cmd->write_complete); in uasp_send_write_request()
749 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
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()
834 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
966 struct usbg_cmd *cmd = req->context; in usbg_data_write_cmpl() local
967 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_data_write_cmpl()
970 pr_err("%s() state %d transfer failed\n", __func__, cmd->state); in usbg_data_write_cmpl()
977 cmd->data_buf, in usbg_data_write_cmpl()
981 complete(&cmd->write_complete); in usbg_data_write_cmpl()
985 usbg_cleanup_cmd(cmd); in usbg_data_write_cmpl()
988 static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) in usbg_prepare_w_request() argument
990 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_prepare_w_request()
991 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request()
995 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in usbg_prepare_w_request()
996 if (!cmd->data_buf) in usbg_prepare_w_request()
999 req->buf = cmd->data_buf; in usbg_prepare_w_request()
1008 req->context = cmd; in usbg_prepare_w_request()
1014 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_status_response() local
1016 struct f_uas *fu = cmd->fu; in usbg_send_status_response()
1019 return bot_send_status_response(cmd); in usbg_send_status_response()
1021 return uasp_send_status_response(cmd); in usbg_send_status_response()
1026 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_write_request() local
1028 struct f_uas *fu = cmd->fu; in usbg_send_write_request()
1031 return bot_send_write_request(cmd); in usbg_send_write_request()
1033 return uasp_send_write_request(cmd); in usbg_send_write_request()
1038 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_read_response() local
1040 struct f_uas *fu = cmd->fu; in usbg_send_read_response()
1043 return bot_send_read_response(cmd); in usbg_send_read_response()
1045 return uasp_send_read_response(cmd); in usbg_send_read_response()
1050 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in usbg_cmd_work() local
1056 se_cmd = &cmd->se_cmd; in usbg_cmd_work()
1057 tpg = cmd->fu->tpg; in usbg_cmd_work()
1059 dir = get_cmd_dir(cmd->cmd_buf); in usbg_cmd_work()
1063 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in usbg_cmd_work()
1064 cmd->prio_attr, cmd->sense_iu.sense); in usbg_cmd_work()
1069 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, in usbg_cmd_work()
1070 0, cmd->prio_attr, dir, TARGET_SCF_UNKNOWN_SIZE) < 0) in usbg_cmd_work()
1078 usbg_cleanup_cmd(cmd); in usbg_cmd_work()
1085 struct usbg_cmd *cmd; in usbg_submit_command() local
1097 cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); in usbg_submit_command()
1098 if (!cmd) in usbg_submit_command()
1101 cmd->fu = fu; in usbg_submit_command()
1104 kref_init(&cmd->ref); in usbg_submit_command()
1105 kref_get(&cmd->ref); in usbg_submit_command()
1112 memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); in usbg_submit_command()
1114 cmd->tag = be16_to_cpup(&cmd_iu->tag); in usbg_submit_command()
1116 if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) in usbg_submit_command()
1118 if (!cmd->tag) 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()
1134 cmd->prio_attr = TCM_HEAD_TAG; in usbg_submit_command()
1137 cmd->prio_attr = TCM_ORDERED_TAG; in usbg_submit_command()
1140 cmd->prio_attr = TCM_ACA_TAG; in usbg_submit_command()
1146 cmd->prio_attr = TCM_SIMPLE_TAG; in usbg_submit_command()
1150 se_cmd = &cmd->se_cmd; in usbg_submit_command()
1151 cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); in usbg_submit_command()
1153 INIT_WORK(&cmd->work, usbg_cmd_work); in usbg_submit_command()
1154 ret = queue_work(tpg->workqueue, &cmd->work); in usbg_submit_command()
1160 kfree(cmd); in usbg_submit_command()
1166 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in bot_cmd_work() local
1172 se_cmd = &cmd->se_cmd; in bot_cmd_work()
1173 tpg = cmd->fu->tpg; in bot_cmd_work()
1175 dir = get_cmd_dir(cmd->cmd_buf); in bot_cmd_work()
1179 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in bot_cmd_work()
1180 cmd->prio_attr, cmd->sense_iu.sense); in bot_cmd_work()
1185 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, in bot_cmd_work()
1186 cmd->data_len, cmd->prio_attr, dir, 0) < 0) in bot_cmd_work()
1194 usbg_cleanup_cmd(cmd); in bot_cmd_work()
1201 struct usbg_cmd *cmd; in bot_submit_command() local
1221 cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); in bot_submit_command()
1222 if (!cmd) in bot_submit_command()
1225 cmd->fu = fu; in bot_submit_command()
1228 kref_init(&cmd->ref); in bot_submit_command()
1229 kref_get(&cmd->ref); in bot_submit_command()
1233 memcpy(cmd->cmd_buf, cbw->CDB, cmd_len); in bot_submit_command()
1235 cmd->bot_tag = cbw->Tag; in bot_submit_command()
1243 cmd->prio_attr = TCM_SIMPLE_TAG; in bot_submit_command()
1244 se_cmd = &cmd->se_cmd; in bot_submit_command()
1245 cmd->unpacked_lun = cbw->Lun; in bot_submit_command()
1246 cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; in bot_submit_command()
1247 cmd->data_len = le32_to_cpu(cbw->DataTransferLength); in bot_submit_command()
1249 INIT_WORK(&cmd->work, bot_cmd_work); in bot_submit_command()
1250 ret = queue_work(tpg->workqueue, &cmd->work); in bot_submit_command()
1256 kfree(cmd); in bot_submit_command()
1408 struct usbg_cmd *cmd = container_of(ref, struct usbg_cmd, in usbg_cmd_release() local
1411 transport_generic_free_cmd(&cmd->se_cmd, 0); in usbg_cmd_release()
1416 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_release_cmd() local
1418 kfree(cmd->data_buf); in usbg_release_cmd()
1419 kfree(cmd); in usbg_release_cmd()
1453 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_get_task_tag() local
1455 struct f_uas *fu = cmd->fu; in usbg_get_task_tag()
1458 return le32_to_cpu(cmd->bot_tag); in usbg_get_task_tag()
1460 return cmd->tag; in usbg_get_task_tag()
1859 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_check_stop_free() local
1862 kref_put(&cmd->ref, usbg_cmd_release); in usbg_check_stop_free()