Lines Matching +full:short +full:- +full:codes
4 * SPDX-License-Identifier: Apache-2.0
22 /* Subclass and Protocol codes */
63 /* Can be 64 if device is not High-Speed capable */
72 /* NULL to request Bulk-Only Mass Storage Reset
141 bi->ep = ep; in msc_buf_alloc()
150 struct msc_bot_desc *desc = ctx->desc; in msc_get_bulk_in()
153 return desc->if0_hs_in_ep.bEndpointAddress; in msc_get_bulk_in()
156 return desc->if0_in_ep.bEndpointAddress; in msc_get_bulk_in()
163 struct msc_bot_desc *desc = ctx->desc; in msc_get_bulk_out()
166 return desc->if0_hs_out_ep.bEndpointAddress; in msc_get_bulk_out()
169 return desc->if0_out_ep.bEndpointAddress; in msc_get_bulk_out()
179 if (atomic_test_and_set_bit(&ctx->bits, MSC_BULK_OUT_QUEUED)) { in msc_queue_bulk_out_ep()
196 atomic_clear_bit(&ctx->bits, MSC_BULK_OUT_QUEUED); in msc_queue_bulk_out_ep()
221 LOG_INF("Bulk-Only Mass Storage Reset"); in msc_reset_handler()
222 ctx->state = MSC_BBB_EXPECT_CBW; in msc_reset_handler()
223 for (i = 0; i < ctx->registered_luns; i++) { in msc_reset_handler()
224 scsi_reset(&ctx->luns[i]); in msc_reset_handler()
227 atomic_clear_bit(&ctx->bits, MSC_BULK_IN_WEDGED); in msc_reset_handler()
228 atomic_clear_bit(&ctx->bits, MSC_BULK_OUT_WEDGED); in msc_reset_handler()
233 if (ctx->cbw.bmCBWFlags & CBW_FLAGS_RESERVED_MASK) { in is_cbw_meaningful()
238 if (ctx->cbw.bCBWLUN >= ctx->registered_luns) { in is_cbw_meaningful()
243 if (ctx->cbw.bCBWCBLength < 1 || ctx->cbw.bCBWCBLength > 16) { in is_cbw_meaningful()
253 struct scsi_ctx *lun = &ctx->luns[ctx->cbw.bCBWLUN]; in msc_process_read()
261 if (ctx->scsi_bytes == 0) { in msc_process_read()
262 ctx->scsi_bytes = scsi_read_data(lun, ctx->scsi_buf); in msc_process_read()
263 ctx->scsi_offset = 0; in msc_process_read()
266 if (atomic_test_and_set_bit(&ctx->bits, MSC_BULK_IN_QUEUED)) { in msc_process_read()
272 ep = msc_get_bulk_in(ctx->class_node); in msc_process_read()
279 while (ctx->scsi_bytes - ctx->scsi_offset > 0) { in msc_process_read()
280 len = MIN(ctx->scsi_bytes - ctx->scsi_offset, in msc_process_read()
281 MSC_BUF_SIZE - bytes_queued); in msc_process_read()
289 net_buf_add_mem(buf, &ctx->scsi_buf[ctx->scsi_offset], len); in msc_process_read()
291 ctx->scsi_offset += len; in msc_process_read()
293 if (ctx->scsi_bytes == ctx->scsi_offset) { in msc_process_read()
295 ctx->scsi_bytes = scsi_read_data(lun, ctx->scsi_buf); in msc_process_read()
296 ctx->scsi_offset = 0; in msc_process_read()
301 ctx->csw.dCSWDataResidue -= bytes_queued; in msc_process_read()
302 ret = usbd_ep_enqueue(ctx->class_node, buf); in msc_process_read()
306 atomic_clear_bit(&ctx->bits, MSC_BULK_IN_QUEUED); in msc_process_read()
312 struct scsi_ctx *lun = &ctx->luns[ctx->cbw.bCBWLUN]; in msc_process_cbw()
317 cb_len = scsi_usb_boot_cmd_len(ctx->cbw.CBWCB, ctx->cbw.bCBWCBLength); in msc_process_cbw()
318 data_len = scsi_cmd(lun, ctx->cbw.CBWCB, cb_len, ctx->scsi_buf); in msc_process_cbw()
319 ctx->scsi_bytes = data_len; in msc_process_cbw()
320 ctx->scsi_offset = 0; in msc_process_cbw()
326 __ASSERT_NO_MSG(cmd_is_data_read || ctx->scsi_bytes == 0); in msc_process_cbw()
328 if (ctx->cbw.dCBWDataTransferLength == 0) { in msc_process_cbw()
329 /* 6.7.1 Hn - Host expects no data transfers */ in msc_process_cbw()
333 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_PASSED; in msc_process_cbw()
335 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_FAILED; in msc_process_cbw()
339 ctx->csw.bCSWStatus = CSW_STATUS_PHASE_ERROR; in msc_process_cbw()
342 ctx->state = MSC_BBB_SEND_CSW; in msc_process_cbw()
350 if (ctx->cbw.bmCBWFlags & CBW_FLAGS_DIRECTION_IN) { in msc_process_cbw()
352 msc_stall_bulk_in_ep(ctx->class_node); in msc_process_cbw()
355 msc_stall_bulk_out_ep(ctx->class_node); in msc_process_cbw()
359 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_PASSED; in msc_process_cbw()
361 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_FAILED; in msc_process_cbw()
364 ctx->state = MSC_BBB_SEND_CSW; in msc_process_cbw()
365 } else if (ctx->cbw.bmCBWFlags & CBW_FLAGS_DIRECTION_IN) { in msc_process_cbw()
366 /* 6.7.2 Hi - Host expects to receive data from device */ in msc_process_cbw()
367 if ((data_len > ctx->cbw.dCBWDataTransferLength) || in msc_process_cbw()
370 msc_stall_bulk_in_ep(ctx->class_node); in msc_process_cbw()
371 ctx->csw.bCSWStatus = CSW_STATUS_PHASE_ERROR; in msc_process_cbw()
372 ctx->state = MSC_BBB_SEND_CSW; in msc_process_cbw()
375 ctx->state = MSC_BBB_PROCESS_READ; in msc_process_cbw()
378 /* 6.7.3 Ho - Host expects to send data to the device */ in msc_process_cbw()
379 if ((data_len > ctx->cbw.dCBWDataTransferLength) || in msc_process_cbw()
382 msc_stall_bulk_out_ep(ctx->class_node); in msc_process_cbw()
383 ctx->csw.bCSWStatus = CSW_STATUS_PHASE_ERROR; in msc_process_cbw()
384 ctx->state = MSC_BBB_SEND_CSW; in msc_process_cbw()
387 ctx->state = MSC_BBB_PROCESS_WRITE; in msc_process_cbw()
396 struct scsi_ctx *lun = &ctx->luns[ctx->cbw.bCBWLUN]; in msc_process_write()
398 ctx->transferred_data += len; in msc_process_write()
402 tmp = MIN(len, sizeof(ctx->scsi_buf) - ctx->scsi_bytes); in msc_process_write()
403 memcpy(&ctx->scsi_buf[ctx->scsi_bytes], buf, tmp); in msc_process_write()
404 ctx->scsi_bytes += tmp; in msc_process_write()
406 len -= tmp; in msc_process_write()
411 while ((ctx->scsi_bytes >= scsi_cmd_remaining_data_len(lun)) || in msc_process_write()
412 (ctx->scsi_bytes == sizeof(ctx->scsi_buf))) { in msc_process_write()
413 tmp = scsi_write_data(lun, ctx->scsi_buf, ctx->scsi_bytes); in msc_process_write()
414 __ASSERT(tmp <= ctx->scsi_bytes, in msc_process_write()
418 ctx->scsi_bytes); in msc_process_write()
419 ctx->scsi_bytes = 0; in msc_process_write()
422 tmp, ctx->scsi_bytes); in msc_process_write()
425 ctx->csw.dCSWDataResidue -= tmp; in msc_process_write()
428 ctx->scsi_bytes = 0; in msc_process_write()
437 memmove(ctx->scsi_buf, &ctx->scsi_buf[tmp], ctx->scsi_bytes - tmp); in msc_process_write()
438 ctx->scsi_bytes -= tmp; in msc_process_write()
442 if ((ctx->transferred_data >= ctx->cbw.dCBWDataTransferLength) || in msc_process_write()
444 if (ctx->transferred_data < ctx->cbw.dCBWDataTransferLength) { in msc_process_write()
447 * stall the Bulk-Out pipe. in msc_process_write()
449 msc_stall_bulk_out_ep(ctx->class_node); in msc_process_write()
453 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_PASSED; in msc_process_write()
455 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_FAILED; in msc_process_write()
458 ctx->state = MSC_BBB_SEND_CSW; in msc_process_write()
465 if (ctx->state == MSC_BBB_EXPECT_CBW) { in msc_handle_bulk_out()
467 memcpy(&ctx->cbw, buf, sizeof(struct CBW)); in msc_handle_bulk_out()
471 ctx->cbw.dCBWDataTransferLength = in msc_handle_bulk_out()
472 sys_le32_to_cpu(ctx->cbw.dCBWDataTransferLength); in msc_handle_bulk_out()
474 ctx->csw.dCSWSignature = sys_cpu_to_le32(CSW_SIGNATURE); in msc_handle_bulk_out()
475 ctx->csw.dCSWTag = ctx->cbw.dCBWTag; in msc_handle_bulk_out()
476 ctx->csw.dCSWDataResidue = ctx->cbw.dCBWDataTransferLength; in msc_handle_bulk_out()
477 ctx->transferred_data = 0; in msc_handle_bulk_out()
479 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_FAILED; in msc_handle_bulk_out()
480 ctx->state = MSC_BBB_PROCESS_CBW; in msc_handle_bulk_out()
483 /* Mass Storage Class - Bulk Only Transport in msc_handle_bulk_out()
487 msc_stall_bulk_in_ep(ctx->class_node); in msc_handle_bulk_out()
488 ctx->csw.bCSWStatus = CSW_STATUS_PHASE_ERROR; in msc_handle_bulk_out()
489 ctx->state = MSC_BBB_SEND_CSW; in msc_handle_bulk_out()
494 atomic_set_bit(&ctx->bits, MSC_BULK_IN_WEDGED); in msc_handle_bulk_out()
495 atomic_set_bit(&ctx->bits, MSC_BULK_OUT_WEDGED); in msc_handle_bulk_out()
496 msc_stall_bulk_in_ep(ctx->class_node); in msc_handle_bulk_out()
497 msc_stall_bulk_out_ep(ctx->class_node); in msc_handle_bulk_out()
498 ctx->state = MSC_BBB_WAIT_FOR_RESET_RECOVERY; in msc_handle_bulk_out()
500 } else if (ctx->state == MSC_BBB_PROCESS_WRITE) { in msc_handle_bulk_out()
508 if (ctx->state == MSC_BBB_WAIT_FOR_CSW_SENT) { in msc_handle_bulk_in()
510 ctx->state = MSC_BBB_EXPECT_CBW; in msc_handle_bulk_in()
511 } else if (ctx->state == MSC_BBB_PROCESS_READ) { in msc_handle_bulk_in()
512 struct scsi_ctx *lun = &ctx->luns[ctx->cbw.bCBWLUN]; in msc_handle_bulk_in()
514 ctx->transferred_data += len; in msc_handle_bulk_in()
515 if (ctx->scsi_bytes == 0) { in msc_handle_bulk_in()
516 if (ctx->csw.dCSWDataResidue > 0) { in msc_handle_bulk_in()
518 * While we may have sent short packet, device in msc_handle_bulk_in()
519 * shall STALL the Bulk-In pipe (if it does not in msc_handle_bulk_in()
522 msc_stall_bulk_in_ep(ctx->class_node); in msc_handle_bulk_in()
525 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_PASSED; in msc_handle_bulk_in()
527 ctx->csw.bCSWStatus = CSW_STATUS_COMMAND_FAILED; in msc_handle_bulk_in()
529 ctx->state = MSC_BBB_SEND_CSW; in msc_handle_bulk_in()
540 if (atomic_test_and_set_bit(&ctx->bits, MSC_BULK_IN_QUEUED)) { in msc_send_csw()
547 ctx->csw.dCSWDataResidue = sys_cpu_to_le32(ctx->csw.dCSWDataResidue); in msc_send_csw()
548 ep = msc_get_bulk_in(ctx->class_node); in msc_send_csw()
555 net_buf_add_mem(buf, &ctx->csw, sizeof(ctx->csw)); in msc_send_csw()
556 ret = usbd_ep_enqueue(ctx->class_node, buf); in msc_send_csw()
560 atomic_clear_bit(&ctx->bits, MSC_BULK_IN_QUEUED); in msc_send_csw()
562 ctx->state = MSC_BBB_WAIT_FOR_CSW_SENT; in msc_send_csw()
574 if (err == -ECONNABORTED) { in usbd_msc_handle_request()
576 bi->ep, buf->len); in usbd_msc_handle_request()
579 bi->ep, buf->len); in usbd_msc_handle_request()
585 if (bi->ep == msc_get_bulk_out(c_data)) { in usbd_msc_handle_request()
586 msc_handle_bulk_out(ctx, buf->data, buf->len); in usbd_msc_handle_request()
587 } else if (bi->ep == msc_get_bulk_in(c_data)) { in usbd_msc_handle_request()
588 msc_handle_bulk_in(ctx, buf->data, buf->len); in usbd_msc_handle_request()
592 if (bi->ep == msc_get_bulk_out(c_data)) { in usbd_msc_handle_request()
593 atomic_clear_bit(&ctx->bits, MSC_BULK_OUT_QUEUED); in usbd_msc_handle_request()
594 } else if (bi->ep == msc_get_bulk_in(c_data)) { in usbd_msc_handle_request()
595 atomic_clear_bit(&ctx->bits, MSC_BULK_IN_QUEUED); in usbd_msc_handle_request()
618 if (!atomic_test_bit(&ctx->bits, MSC_CLASS_ENABLED)) { in usbd_msc_thread()
622 switch (ctx->state) { in usbd_msc_thread()
635 if (atomic_test_bit(&ctx->bits, MSC_BULK_IN_QUEUED)) { in usbd_msc_thread()
639 if (ctx->state == MSC_BBB_PROCESS_CBW) { in usbd_msc_thread()
643 if (ctx->state == MSC_BBB_PROCESS_READ) { in usbd_msc_thread()
645 } else if (ctx->state == MSC_BBB_PROCESS_WRITE) { in usbd_msc_thread()
647 } else if (ctx->state == MSC_BBB_SEND_CSW) { in usbd_msc_thread()
657 .buf = NULL, /* Bulk-Only Mass Storage Reset */ in msc_bot_schedule_reset()
670 atomic_test_bit(&ctx->bits, MSC_BULK_IN_WEDGED)) { in msc_bot_feature_halt()
674 atomic_test_bit(&ctx->bits, MSC_BULK_OUT_WEDGED)) { in msc_bot_feature_halt()
685 if (setup->bRequest == BULK_ONLY_MASS_STORAGE_RESET && in msc_bot_control_to_dev()
686 setup->wValue == 0 && setup->wLength == 0) { in msc_bot_control_to_dev()
689 errno = -ENOTSUP; in msc_bot_control_to_dev()
703 if (setup->bRequest == GET_MAX_LUN && in msc_bot_control_to_host()
704 setup->wValue == 0 && setup->wLength >= 1) { in msc_bot_control_to_host()
709 max_lun = ctx->registered_luns ? ctx->registered_luns - 1 : 0; in msc_bot_control_to_host()
712 errno = -ENOTSUP; in msc_bot_control_to_host()
740 atomic_set_bit(&ctx->bits, MSC_CLASS_ENABLED); in msc_bot_enable()
750 atomic_clear_bit(&ctx->bits, MSC_CLASS_ENABLED); in msc_bot_disable()
759 return ctx->hs_desc; in msc_bot_get_desc()
762 return ctx->fs_desc; in msc_bot_get_desc()
770 ctx->class_node = c_data; in msc_bot_init()
771 ctx->state = MSC_BBB_EXPECT_CBW; in msc_bot_init()
772 ctx->registered_luns = 0; in msc_bot_init()
775 if (ctx->registered_luns >= CONFIG_USBD_MSC_LUNS_PER_INSTANCE) { in msc_bot_init()
776 LOG_ERR("Cannot register LUN %s", lun->disk); in msc_bot_init()
777 return -ENOMEM; in msc_bot_init()
780 scsi_init(&ctx->luns[ctx->registered_luns++], lun->disk, in msc_bot_init()
781 lun->vendor, lun->product, lun->revision); in msc_bot_init()