Lines Matching refs:cmd

35 static inline void usbg_cleanup_cmd(struct usbg_cmd *cmd)  in usbg_cleanup_cmd()  argument
37 kref_put(&cmd->ref, usbg_cmd_release); in usbg_cleanup_cmd()
49 ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); in bot_enqueue_cmd_cbw()
57 struct usbg_cmd *cmd = req->context; in bot_status_complete() local
58 struct f_uas *fu = cmd->fu; in bot_status_complete()
60 usbg_cleanup_cmd(cmd); in bot_status_complete()
70 static void bot_enqueue_sense_code(struct f_uas *fu, struct usbg_cmd *cmd) in bot_enqueue_sense_code() argument
77 csw_stat = cmd->csw_code; in bot_enqueue_sense_code()
84 sense = cmd->sense_iu.sense; in bot_enqueue_sense_code()
86 csw->Tag = cmd->bot_tag; in bot_enqueue_sense_code()
88 fu->bot_status.req->context = cmd; in bot_enqueue_sense_code()
96 struct usbg_cmd *cmd = req->context; in bot_err_compl() local
97 struct f_uas *fu = cmd->fu; in bot_err_compl()
102 if (cmd->data_len) { in bot_err_compl()
103 if (cmd->data_len > ep->maxpacket) { in bot_err_compl()
105 cmd->data_len -= ep->maxpacket; in bot_err_compl()
107 req->length = cmd->data_len; in bot_err_compl()
108 cmd->data_len = 0; in bot_err_compl()
114 bot_enqueue_sense_code(fu, cmd); in bot_err_compl()
117 static void bot_send_bad_status(struct usbg_cmd *cmd) in bot_send_bad_status() argument
119 struct f_uas *fu = cmd->fu; in bot_send_bad_status()
124 csw->Residue = cpu_to_le32(cmd->data_len); in bot_send_bad_status()
126 if (cmd->data_len) { in bot_send_bad_status()
127 if (cmd->is_read) { in bot_send_bad_status()
135 if (cmd->data_len > fu->ep_in->maxpacket) { in bot_send_bad_status()
137 cmd->data_len -= ep->maxpacket; in bot_send_bad_status()
139 req->length = cmd->data_len; in bot_send_bad_status()
140 cmd->data_len = 0; in bot_send_bad_status()
143 req->context = cmd; in bot_send_bad_status()
144 req->buf = fu->cmd.buf; in bot_send_bad_status()
147 bot_enqueue_sense_code(fu, cmd); in bot_send_bad_status()
151 static int bot_send_status(struct usbg_cmd *cmd, bool moved_data) in bot_send_status() argument
153 struct f_uas *fu = cmd->fu; in bot_send_status()
157 if (cmd->se_cmd.scsi_status == SAM_STAT_GOOD) { in bot_send_status()
158 if (!moved_data && cmd->data_len) { in bot_send_status()
163 cmd->csw_code = US_BULK_STAT_OK; in bot_send_status()
164 bot_send_bad_status(cmd); in bot_send_status()
168 csw->Tag = cmd->bot_tag; in bot_send_status()
171 fu->bot_status.req->context = cmd; in bot_send_status()
177 cmd->csw_code = US_BULK_STAT_FAIL; in bot_send_status()
178 bot_send_bad_status(cmd); in bot_send_status()
187 static int bot_send_status_response(struct usbg_cmd *cmd) in bot_send_status_response() argument
191 if (!cmd->is_read) in bot_send_status_response()
193 return bot_send_status(cmd, moved_data); in bot_send_status_response()
199 struct usbg_cmd *cmd = req->context; in bot_read_compl() local
204 bot_send_status(cmd, true); in bot_read_compl()
207 static int bot_send_read_response(struct usbg_cmd *cmd) in bot_send_read_response() argument
209 struct f_uas *fu = cmd->fu; in bot_send_read_response()
210 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_read_response()
214 if (!cmd->data_len) { in bot_send_read_response()
215 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_read_response()
216 bot_send_bad_status(cmd); in bot_send_read_response()
221 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in bot_send_read_response()
222 if (!cmd->data_buf) in bot_send_read_response()
227 cmd->data_buf, in bot_send_read_response()
230 fu->bot_req_in->buf = cmd->data_buf; in bot_send_read_response()
239 fu->bot_req_in->context = cmd; in bot_send_read_response()
249 static int bot_send_write_request(struct usbg_cmd *cmd) in bot_send_write_request() argument
251 struct f_uas *fu = cmd->fu; in bot_send_write_request()
252 struct se_cmd *se_cmd = &cmd->se_cmd; in bot_send_write_request()
256 init_completion(&cmd->write_complete); in bot_send_write_request()
257 cmd->fu = fu; in bot_send_write_request()
259 if (!cmd->data_len) { in bot_send_write_request()
260 cmd->csw_code = US_BULK_STAT_PHASE; in bot_send_write_request()
265 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_KERNEL); in bot_send_write_request()
266 if (!cmd->data_buf) in bot_send_write_request()
269 fu->bot_req_out->buf = cmd->data_buf; in bot_send_write_request()
278 fu->bot_req_out->context = cmd; in bot_send_write_request()
280 ret = usbg_prepare_w_request(cmd, fu->bot_req_out); in bot_send_write_request()
287 wait_for_completion(&cmd->write_complete); in bot_send_write_request()
322 fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); in bot_prepare_reqs()
323 if (!fu->cmd.req) in bot_prepare_reqs()
335 fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); in bot_prepare_reqs()
336 if (!fu->cmd.buf) in bot_prepare_reqs()
339 fu->cmd.req->complete = bot_cmd_complete; in bot_prepare_reqs()
340 fu->cmd.req->buf = fu->cmd.buf; in bot_prepare_reqs()
341 fu->cmd.req->length = fu->ep_out->maxpacket; in bot_prepare_reqs()
342 fu->cmd.req->context = fu; in bot_prepare_reqs()
349 kfree(fu->cmd.buf); in bot_prepare_reqs()
350 fu->cmd.buf = NULL; in bot_prepare_reqs()
354 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_prepare_reqs()
355 fu->cmd.req = NULL; in bot_prepare_reqs()
380 usb_ep_free_request(fu->ep_out, fu->cmd.req); in bot_cleanup_old_alt()
383 kfree(fu->cmd.buf); in bot_cleanup_old_alt()
387 fu->cmd.req = NULL; in bot_cleanup_old_alt()
389 fu->cmd.buf = NULL; in bot_cleanup_old_alt()
492 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_free_cmdreq()
493 kfree(fu->cmd.buf); in uasp_free_cmdreq()
494 fu->cmd.req = NULL; in uasp_free_cmdreq()
495 fu->cmd.buf = NULL; in uasp_free_cmdreq()
517 static int uasp_prepare_r_request(struct usbg_cmd *cmd) in uasp_prepare_r_request() argument
519 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_r_request()
520 struct f_uas *fu = cmd->fu; in uasp_prepare_r_request()
522 struct uas_stream *stream = cmd->stream; in uasp_prepare_r_request()
525 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in uasp_prepare_r_request()
526 if (!cmd->data_buf) in uasp_prepare_r_request()
531 cmd->data_buf, in uasp_prepare_r_request()
534 stream->req_in->buf = cmd->data_buf; in uasp_prepare_r_request()
543 stream->req_in->context = cmd; in uasp_prepare_r_request()
545 cmd->state = UASP_SEND_STATUS; in uasp_prepare_r_request()
549 static void uasp_prepare_status(struct usbg_cmd *cmd) in uasp_prepare_status() argument
551 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_prepare_status()
552 struct sense_iu *iu = &cmd->sense_iu; in uasp_prepare_status()
553 struct uas_stream *stream = cmd->stream; in uasp_prepare_status()
555 cmd->state = UASP_QUEUE_COMMAND; in uasp_prepare_status()
557 iu->tag = cpu_to_be16(cmd->tag); in uasp_prepare_status()
564 stream->req_status->context = cmd; in uasp_prepare_status()
572 struct usbg_cmd *cmd = req->context; in uasp_status_data_cmpl() local
573 struct uas_stream *stream = cmd->stream; in uasp_status_data_cmpl()
574 struct f_uas *fu = cmd->fu; in uasp_status_data_cmpl()
580 switch (cmd->state) { in uasp_status_data_cmpl()
582 ret = uasp_prepare_r_request(cmd); in uasp_status_data_cmpl()
591 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_status_data_cmpl()
600 uasp_prepare_status(cmd); in uasp_status_data_cmpl()
608 usbg_cleanup_cmd(cmd); in uasp_status_data_cmpl()
609 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_status_data_cmpl()
618 usbg_cleanup_cmd(cmd); in uasp_status_data_cmpl()
621 static int uasp_send_status_response(struct usbg_cmd *cmd) in uasp_send_status_response() argument
623 struct f_uas *fu = cmd->fu; in uasp_send_status_response()
624 struct uas_stream *stream = cmd->stream; in uasp_send_status_response()
625 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_status_response()
627 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_status_response()
629 stream->req_status->context = cmd; in uasp_send_status_response()
630 cmd->fu = fu; in uasp_send_status_response()
631 uasp_prepare_status(cmd); in uasp_send_status_response()
635 static int uasp_send_read_response(struct usbg_cmd *cmd) in uasp_send_read_response() argument
637 struct f_uas *fu = cmd->fu; in uasp_send_read_response()
638 struct uas_stream *stream = cmd->stream; in uasp_send_read_response()
639 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_read_response()
642 cmd->fu = fu; in uasp_send_read_response()
644 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
647 ret = uasp_prepare_r_request(cmd); in uasp_send_read_response()
653 kfree(cmd->data_buf); in uasp_send_read_response()
654 cmd->data_buf = NULL; in uasp_send_read_response()
660 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_read_response()
663 stream->req_status->context = cmd; in uasp_send_read_response()
665 cmd->state = UASP_SEND_DATA; in uasp_send_read_response()
678 static int uasp_send_write_request(struct usbg_cmd *cmd) in uasp_send_write_request() argument
680 struct f_uas *fu = cmd->fu; in uasp_send_write_request()
681 struct se_cmd *se_cmd = &cmd->se_cmd; in uasp_send_write_request()
682 struct uas_stream *stream = cmd->stream; in uasp_send_write_request()
683 struct sense_iu *iu = &cmd->sense_iu; in uasp_send_write_request()
686 init_completion(&cmd->write_complete); in uasp_send_write_request()
687 cmd->fu = fu; in uasp_send_write_request()
689 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
693 ret = usbg_prepare_w_request(cmd, stream->req_out); in uasp_send_write_request()
703 iu->tag = cpu_to_be16(cmd->tag); in uasp_send_write_request()
706 stream->req_status->context = cmd; in uasp_send_write_request()
708 cmd->state = UASP_RECEIVE_DATA; in uasp_send_write_request()
718 wait_for_completion(&cmd->write_complete); in uasp_send_write_request()
743 usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_cmd_complete()
773 fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); in uasp_alloc_cmd()
774 if (!fu->cmd.req) in uasp_alloc_cmd()
777 fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); in uasp_alloc_cmd()
778 if (!fu->cmd.buf) in uasp_alloc_cmd()
781 fu->cmd.req->complete = uasp_cmd_complete; in uasp_alloc_cmd()
782 fu->cmd.req->buf = fu->cmd.buf; in uasp_alloc_cmd()
783 fu->cmd.req->length = fu->ep_cmd->maxpacket; in uasp_alloc_cmd()
784 fu->cmd.req->context = fu; in uasp_alloc_cmd()
788 usb_ep_free_request(fu->ep_cmd, fu->cmd.req); in uasp_alloc_cmd()
828 ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); in uasp_prepare_reqs()
960 struct usbg_cmd *cmd = req->context; in usbg_data_write_cmpl() local
961 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_data_write_cmpl()
964 pr_err("%s() state %d transfer failed\n", __func__, cmd->state); in usbg_data_write_cmpl()
971 cmd->data_buf, in usbg_data_write_cmpl()
975 complete(&cmd->write_complete); in usbg_data_write_cmpl()
979 usbg_cleanup_cmd(cmd); in usbg_data_write_cmpl()
982 static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) in usbg_prepare_w_request() argument
984 struct se_cmd *se_cmd = &cmd->se_cmd; in usbg_prepare_w_request()
985 struct f_uas *fu = cmd->fu; in usbg_prepare_w_request()
989 cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); in usbg_prepare_w_request()
990 if (!cmd->data_buf) in usbg_prepare_w_request()
993 req->buf = cmd->data_buf; in usbg_prepare_w_request()
1002 req->context = cmd; in usbg_prepare_w_request()
1008 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_status_response() local
1010 struct f_uas *fu = cmd->fu; in usbg_send_status_response()
1013 return bot_send_status_response(cmd); in usbg_send_status_response()
1015 return uasp_send_status_response(cmd); in usbg_send_status_response()
1020 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_write_request() local
1022 struct f_uas *fu = cmd->fu; in usbg_send_write_request()
1025 return bot_send_write_request(cmd); in usbg_send_write_request()
1027 return uasp_send_write_request(cmd); in usbg_send_write_request()
1032 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_send_read_response() local
1034 struct f_uas *fu = cmd->fu; in usbg_send_read_response()
1037 return bot_send_read_response(cmd); in usbg_send_read_response()
1039 return uasp_send_read_response(cmd); in usbg_send_read_response()
1044 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in usbg_cmd_work() local
1050 se_cmd = &cmd->se_cmd; in usbg_cmd_work()
1051 tpg = cmd->fu->tpg; in usbg_cmd_work()
1053 dir = get_cmd_dir(cmd->cmd_buf); in usbg_cmd_work()
1057 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in usbg_cmd_work()
1058 cmd->prio_attr, cmd->sense_iu.sense); in usbg_cmd_work()
1063 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, in usbg_cmd_work()
1064 0, cmd->prio_attr, dir, TARGET_SCF_UNKNOWN_SIZE) < 0) in usbg_cmd_work()
1072 usbg_cleanup_cmd(cmd); in usbg_cmd_work()
1079 struct usbg_cmd *cmd; in usbg_submit_command() local
1091 cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); in usbg_submit_command()
1092 if (!cmd) in usbg_submit_command()
1095 cmd->fu = fu; in usbg_submit_command()
1098 kref_init(&cmd->ref); in usbg_submit_command()
1099 kref_get(&cmd->ref); in usbg_submit_command()
1106 memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); in usbg_submit_command()
1108 cmd->tag = be16_to_cpup(&cmd_iu->tag); in usbg_submit_command()
1109 cmd->se_cmd.tag = cmd->tag; in usbg_submit_command()
1111 if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) in usbg_submit_command()
1113 if (!cmd->tag) in usbg_submit_command()
1114 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1116 cmd->stream = &fu->stream[cmd->tag - 1]; in usbg_submit_command()
1118 cmd->stream = &fu->stream[0]; in usbg_submit_command()
1129 cmd->prio_attr = TCM_HEAD_TAG; in usbg_submit_command()
1132 cmd->prio_attr = TCM_ORDERED_TAG; in usbg_submit_command()
1135 cmd->prio_attr = TCM_ACA_TAG; in usbg_submit_command()
1141 cmd->prio_attr = TCM_SIMPLE_TAG; in usbg_submit_command()
1145 se_cmd = &cmd->se_cmd; in usbg_submit_command()
1146 cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); in usbg_submit_command()
1148 INIT_WORK(&cmd->work, usbg_cmd_work); in usbg_submit_command()
1149 ret = queue_work(tpg->workqueue, &cmd->work); in usbg_submit_command()
1155 kfree(cmd); in usbg_submit_command()
1161 struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); in bot_cmd_work() local
1167 se_cmd = &cmd->se_cmd; in bot_cmd_work()
1168 tpg = cmd->fu->tpg; in bot_cmd_work()
1170 dir = get_cmd_dir(cmd->cmd_buf); in bot_cmd_work()
1174 tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, in bot_cmd_work()
1175 cmd->prio_attr, cmd->sense_iu.sense); in bot_cmd_work()
1180 cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, in bot_cmd_work()
1181 cmd->data_len, cmd->prio_attr, dir, 0) < 0) in bot_cmd_work()
1189 usbg_cleanup_cmd(cmd); in bot_cmd_work()
1196 struct usbg_cmd *cmd; in bot_submit_command() local
1216 cmd = kzalloc(sizeof *cmd, GFP_ATOMIC); in bot_submit_command()
1217 if (!cmd) in bot_submit_command()
1220 cmd->fu = fu; in bot_submit_command()
1223 kref_init(&cmd->ref); in bot_submit_command()
1224 kref_get(&cmd->ref); in bot_submit_command()
1228 memcpy(cmd->cmd_buf, cbw->CDB, cmd_len); in bot_submit_command()
1230 cmd->bot_tag = cbw->Tag; in bot_submit_command()
1238 cmd->prio_attr = TCM_SIMPLE_TAG; in bot_submit_command()
1239 se_cmd = &cmd->se_cmd; in bot_submit_command()
1240 cmd->unpacked_lun = cbw->Lun; in bot_submit_command()
1241 cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; in bot_submit_command()
1242 cmd->data_len = le32_to_cpu(cbw->DataTransferLength); in bot_submit_command()
1243 cmd->se_cmd.tag = le32_to_cpu(cmd->bot_tag); in bot_submit_command()
1245 INIT_WORK(&cmd->work, bot_cmd_work); in bot_submit_command()
1246 ret = queue_work(tpg->workqueue, &cmd->work); in bot_submit_command()
1252 kfree(cmd); in bot_submit_command()
1296 struct usbg_cmd *cmd = container_of(ref, struct usbg_cmd, in usbg_cmd_release() local
1299 transport_generic_free_cmd(&cmd->se_cmd, 0); in usbg_cmd_release()
1304 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_release_cmd() local
1306 kfree(cmd->data_buf); in usbg_release_cmd()
1307 kfree(cmd); in usbg_release_cmd()
1695 struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, in usbg_check_stop_free() local
1698 kref_put(&cmd->ref, usbg_cmd_release); in usbg_check_stop_free()