This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7ac6e9eeb97f1d6ef96363304a2d78312960e56d Author: yangsong8 <[email protected]> AuthorDate: Tue Nov 17 19:15:48 2026 +0800 drivers/usbdev/usbmsc: fix pre-existing nxstyle errors Fix the switch/case indentation, brace and comment alignment and long lines reported by tools/nxstyle in the following files: - drivers/usbdev/usbmsc.c - drivers/usbdev/usbmsc_scsi.c Assisted-by: opencode:zhipuai/glm-5.3 Signed-off-by: yangsong8 <[email protected]> --- drivers/usbdev/usbmsc.c | 492 +++++++++++++++--------------- drivers/usbdev/usbmsc_scsi.c | 691 ++++++++++++++++++++++--------------------- 2 files changed, 598 insertions(+), 585 deletions(-) diff --git a/drivers/usbdev/usbmsc.c b/drivers/usbdev/usbmsc.c index 981ab9d7b1a..8e7e1836337 100644 --- a/drivers/usbdev/usbmsc.c +++ b/drivers/usbdev/usbmsc.c @@ -631,170 +631,174 @@ static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver, switch (ctrl->req) { - case USB_REQ_GETDESCRIPTOR: - { - /* The value field specifies the descriptor type in the MS byte - * and the descriptor index in the LS byte (order is little - * endian) - */ + case USB_REQ_GETDESCRIPTOR: + { + /* The value field specifies the descriptor type in the MS byte + * and the descriptor index in the LS byte (order is little + * endian) + */ - switch (ctrl->value[1]) - { - /* If the mass storage device is used in as part of a - * composite device, then the device descriptor is - * provided by logic in the composite device implementation. - */ + switch (ctrl->value[1]) + { + /* If the mass storage device is used in as part of a + * composite device, then the device descriptor is + * provided by logic in the composite device + * implementation. + */ #ifndef CONFIG_USBMSC_COMPOSITE - case USB_DESC_TYPE_DEVICE: - { - ret = usbdev_copy_devdesc(ctrlreq->buf, - usbmsc_getdevdesc(), - dev->speed); - } - break; + case USB_DESC_TYPE_DEVICE: + { + ret = usbdev_copy_devdesc(ctrlreq->buf, + usbmsc_getdevdesc(), + dev->speed); + } + break; #endif - /* If the mass storage device is used in as part of a - * composite device, then the device qualifier descriptor is - * provided by logic in the composite device implementation. - */ + /* If the mass storage device is used in as part of a + * composite device, then the device qualifier descriptor + * is provided by logic in the composite device + * implementation. + */ #if !defined(CONFIG_USBMSC_COMPOSITE) && defined(CONFIG_USBDEV_DUALSPEED) - case USB_DESC_TYPE_DEVICEQUALIFIER: - { - ret = USB_SIZEOF_QUALDESC; - memcpy(ctrlreq->buf, usbmsc_getqualdesc(), ret); - } - break; + case USB_DESC_TYPE_DEVICEQUALIFIER: + { + ret = USB_SIZEOF_QUALDESC; + memcpy(ctrlreq->buf, usbmsc_getqualdesc(), ret); + } + break; + + case USB_DESC_TYPE_OTHERSPEEDCONFIG: +#endif + + /* If the mass storage device is used in as part of a + * composite device, then the configuration descriptor is + * provided by logic in the composite device + * implementation. + */ - case USB_DESC_TYPE_OTHERSPEEDCONFIG: +#ifndef CONFIG_USBMSC_COMPOSITE + case USB_DESC_TYPE_CONFIG: + { + ret = usbmsc_mkcfgdesc(ctrlreq->buf, &priv->devinfo, + dev->speed, ctrl->value[1]); + } + break; #endif - /* If the mass storage device is used in as part of a - * composite device, then the configuration descriptor is - * provided by logic in the composite device implementation. - */ + /* If the mass storage device is used in as part of a + * composite device, then the language string descriptor is + * provided by logic in the composite device + * implementation. + */ #ifndef CONFIG_USBMSC_COMPOSITE - case USB_DESC_TYPE_CONFIG: + case USB_DESC_TYPE_STRING: + { + /* index == language code. */ + + ret = usbmsc_mkstrdesc(ctrl->value[0], + (FAR struct usb_strdesc_s *) + ctrlreq->buf); + } + break; +#endif + + default: + { + usbtrace(TRACE_CLSERROR + (USBMSC_TRACEERR_GETUNKNOWNDESC), value); + } + break; + } + } + break; + + case USB_REQ_SETCONFIGURATION: + { + if (ctrl->type == 0) { - ret = usbmsc_mkcfgdesc(ctrlreq->buf, &priv->devinfo, - dev->speed, ctrl->value[1]); + /* Signal the worker thread to instantiate the new + * configuration. + */ + + priv->theventset |= USBMSC_EVENT_CFGCHANGE; + priv->thvalue = value; + usbmsc_scsi_signal(priv); + + /* Return here... the response will be provided later by + * the worker thread. + */ + + return OK; } - break; -#endif + } + break; - /* If the mass storage device is used in as part of a - * composite device, then the language string descriptor is - * provided by logic in the composite device implementation. - */ + /* If the mass storage device is used in as part of a composite + * device, then the overall composite class configuration is + * managed by logic in the composite device implementation. + */ #ifndef CONFIG_USBMSC_COMPOSITE - case USB_DESC_TYPE_STRING: + case USB_REQ_GETCONFIGURATION: + { + if (ctrl->type == USB_DIR_IN) { - /* index == language code. */ - - ret = usbmsc_mkstrdesc(ctrl->value[0], - (FAR struct usb_strdesc_s *) - ctrlreq->buf); + ctrlreq->buf[0] = priv->config; + ret = 1; } - break; + } + break; #endif - default: + case USB_REQ_SETINTERFACE: + { + if (ctrl->type == USB_REQ_RECIPIENT_INTERFACE) { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_GETUNKNOWNDESC), - value); + if (priv->config == USBMSC_CONFIGID && + index == priv->devinfo.ifnobase && + value == USBMSC_ALTINTERFACEID) + { + /* Signal to instantiate the interface change */ + + priv->theventset |= USBMSC_EVENT_IFCHANGE; + usbmsc_scsi_signal(priv); + + /* Return here... the response will be provided later + * by the worker thread. + */ + + return OK; + } } - break; - } - } - break; - - case USB_REQ_SETCONFIGURATION: - { - if (ctrl->type == 0) - { - /* Signal the worker thread to instantiate the new - * configuration. - */ - - priv->theventset |= USBMSC_EVENT_CFGCHANGE; - priv->thvalue = value; - usbmsc_scsi_signal(priv); - - /* Return here... the response will be provided later by the - * worker thread. - */ - - return OK; - } - } - break; - - /* If the mass storage device is used in as part of a composite - * device, then the overall composite class configuration is - * managed by logic in the composite device implementation. - */ + } + break; -#ifndef CONFIG_USBMSC_COMPOSITE - case USB_REQ_GETCONFIGURATION: - { - if (ctrl->type == USB_DIR_IN) - { - ctrlreq->buf[0] = priv->config; - ret = 1; - } - } - break; -#endif + case USB_REQ_GETINTERFACE: + { + if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && + priv->config == USBMSC_CONFIGIDNONE) + { + if (index != priv->devinfo.ifnobase) + { + ret = -EDOM; + } + else + { + ctrlreq->buf[0] = USBMSC_ALTINTERFACEID; + ret = 1; + } + } + } + break; - case USB_REQ_SETINTERFACE: - { - if (ctrl->type == USB_REQ_RECIPIENT_INTERFACE) - { - if (priv->config == USBMSC_CONFIGID && - index == priv->devinfo.ifnobase && - value == USBMSC_ALTINTERFACEID) - { - /* Signal to instantiate the interface change */ - - priv->theventset |= USBMSC_EVENT_IFCHANGE; - usbmsc_scsi_signal(priv); - - /* Return here... the response will be provided later by - * the worker thread. - */ - - return OK; - } - } - } - break; - - case USB_REQ_GETINTERFACE: - { - if (ctrl->type == (USB_DIR_IN | USB_REQ_RECIPIENT_INTERFACE) && - priv->config == USBMSC_CONFIGIDNONE) - { - if (index != priv->devinfo.ifnobase) - { - ret = -EDOM; - } - else - { - ctrlreq->buf[0] = USBMSC_ALTINTERFACEID; - ret = 1; - } - } - } - break; - - default: - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNSUPPORTEDSTDREQ), - ctrl->req); - break; + default: + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_UNSUPPORTEDSTDREQ), + ctrl->req); + break; } } else if ((ctrl->type & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_CLASS) @@ -807,67 +811,69 @@ static int usbmsc_setup(FAR struct usbdevclass_driver_s *driver, if (!priv->config) { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_NOTCONFIGURED), 0); - return ret; + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_NOTCONFIGURED), 0); + return ret; } switch (ctrl->req) { - case USBMSC_REQ_MSRESET: /* Reset mass storage device and interface */ - { - if (ctrl->type == USBMSC_TYPE_SETUPOUT && value == 0 && len == 0) - { - /* Only one interface is supported */ - - if (index != priv->devinfo.ifnobase) - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_MSRESETNDX), - index); - ret = -EDOM; - } - else - { - /* Signal to stop the current operation and reinitialize - * state. - */ - - priv->theventset |= USBMSC_EVENT_RESET; - usbmsc_scsi_signal(priv); - - /* Return here... the response will be provided later by - * the worker thread. - */ - - return OK; - } - } - } - break; - - case USBMSC_REQ_GETMAXLUN: /* Return number LUNs supported */ - { - if (ctrl->type == USBMSC_TYPE_SETUPIN && value == 0 && len == 1) - { - /* Only one interface is supported */ - - if (index != priv->devinfo.ifnobase) - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_GETMAXLUNNDX), - index); - ret = -EDOM; - } - else - { - ctrlreq->buf[0] = priv->nluns - 1; - ret = 1; - } - } - } - break; - - default: - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BADREQUEST), ctrl->req); - break; + case USBMSC_REQ_MSRESET: /* Reset mass storage device and interface */ + { + if (ctrl->type == USBMSC_TYPE_SETUPOUT && + value == 0 && len == 0) + { + /* Only one interface is supported */ + + if (index != priv->devinfo.ifnobase) + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_MSRESETNDX), + index); + ret = -EDOM; + } + else + { + /* Signal to stop the current operation and + * reinitialize state. + */ + + priv->theventset |= USBMSC_EVENT_RESET; + usbmsc_scsi_signal(priv); + + /* Return here... the response will be provided later + * by the worker thread. + */ + + return OK; + } + } + } + break; + + case USBMSC_REQ_GETMAXLUN: /* Return number LUNs supported */ + { + if (ctrl->type == USBMSC_TYPE_SETUPIN && + value == 0 && len == 1) + { + /* Only one interface is supported */ + + if (index != priv->devinfo.ifnobase) + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_GETMAXLUNNDX), + index); + ret = -EDOM; + } + else + { + ctrlreq->buf[0] = priv->nluns - 1; + ret = 1; + } + } + } + break; + + default: + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_BADREQUEST), ctrl->req); + break; } } else @@ -1174,18 +1180,18 @@ void usbmsc_wrcomplete(FAR struct usbdev_ep_s *ep, switch (req->result) { - case OK: /* Normal completion */ - usbtrace(TRACE_CLASSWRCOMPLETE, req->xfrd); - break; + case OK: /* Normal completion */ + usbtrace(TRACE_CLASSWRCOMPLETE, req->xfrd); + break; - case -ESHUTDOWN: /* Disconnection */ - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRSHUTDOWN), 0); - break; + case -ESHUTDOWN: /* Disconnection */ + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRSHUTDOWN), 0); + break; - default: /* Some other error occurred */ - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRUNEXPECTED), - (uint16_t)-req->result); - break; + default: /* Some other error occurred */ + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_WRUNEXPECTED), + (uint16_t)-req->result); + break; }; /* Inform the worker thread that a write request has been returned */ @@ -1232,52 +1238,54 @@ void usbmsc_rdcomplete(FAR struct usbdev_ep_s *ep, switch (req->result) { - case 0: /* Normal completion */ - { - usbtrace(TRACE_CLASSRDCOMPLETE, req->xfrd); + case 0: /* Normal completion */ + { + usbtrace(TRACE_CLASSRDCOMPLETE, req->xfrd); - /* Add the filled read request from the rdreqlist */ + /* Add the filled read request from the rdreqlist */ - flags = spin_lock_irqsave_nopreempt(&priv->spinlock); - sq_addlast((FAR sq_entry_t *)privreq, &priv->rdreqlist); + flags = spin_lock_irqsave_nopreempt(&priv->spinlock); + sq_addlast((FAR sq_entry_t *)privreq, &priv->rdreqlist); - /* Signal the worker thread that there is received data to be - * processed. - */ + /* Signal the worker thread that there is received data to be + * processed. + */ - priv->theventset |= USBMSC_EVENT_RDCOMPLETE; - usbmsc_scsi_signal(priv); - spin_unlock_irqrestore_nopreempt(&priv->spinlock, flags); - } - break; + priv->theventset |= USBMSC_EVENT_RDCOMPLETE; + usbmsc_scsi_signal(priv); + spin_unlock_irqrestore_nopreempt(&priv->spinlock, flags); + } + break; - case -ESHUTDOWN: /* Disconnection */ - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDSHUTDOWN), 0); + case -ESHUTDOWN: /* Disconnection */ + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDSHUTDOWN), 0); - /* Drop the read request... it will be cleaned up later */ - } - break; + /* Drop the read request... it will be cleaned up later */ + } + break; - default: /* Some other error occurred */ - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDUNEXPECTED), - (uint16_t)-req->result); + default: /* Some other error occurred */ + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDUNEXPECTED), + (uint16_t)-req->result); - /* Return the read request to the bulk out endpoint for re-filling */ + /* Return the read request to the bulk out endpoint for + * re-filling + */ - req = privreq->req; - req->priv = privreq; - req->callback = usbmsc_rdcomplete; + req = privreq->req; + req->priv = privreq; + req->callback = usbmsc_rdcomplete; - ret = EP_SUBMIT(priv->epbulkout, req); - if (ret != OK) - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDCOMPLETERDSUBMIT), - (uint16_t)-ret); - } - } - break; + ret = EP_SUBMIT(priv->epbulkout, req); + if (ret != OK) + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_RDCOMPLETERDSUBMIT), + (uint16_t)-ret); + } + } + break; } } diff --git a/drivers/usbdev/usbmsc_scsi.c b/drivers/usbdev/usbmsc_scsi.c index 5433fdfd189..f927be89b69 100644 --- a/drivers/usbdev/usbmsc_scsi.c +++ b/drivers/usbdev/usbmsc_scsi.c @@ -1982,201 +1982,203 @@ static int usbmsc_cmdparsestate(FAR struct usbmsc_dev_s *priv) switch (priv->cdb[0]) { - case SCSI_CMD_TESTUNITREADY: /* 0x00 Mandatory */ - ret = usbmsc_cmdtestunitready(priv); - break; + case SCSI_CMD_TESTUNITREADY: /* 0x00 Mandatory */ + ret = usbmsc_cmdtestunitready(priv); + break; - /* case SCSI_CMD_REZEROUNIT: 0x01 Obsolete - * 0x02 Vendor-specific - */ + /* case SCSI_CMD_REZEROUNIT: 0x01 Obsolete + * 0x02 Vendor-specific + */ - case SCSI_CMD_REQUESTSENSE: /* 0x03 Mandatory */ - ret = usbmsc_cmdrequestsense(priv, buf); - break; + case SCSI_CMD_REQUESTSENSE: /* 0x03 Mandatory */ + ret = usbmsc_cmdrequestsense(priv, buf); + break; - /* case SCSI_CMD_FORMAT_UNIT: 0x04 Mandatory, but not impl. - * 0x05 Vendor specific - * 0x06 Vendor specific - * case SCSI_CMD_REASSIGNBLOCKS: 0x07 Optional - */ - - case SCSI_CMD_READ6: /* 0x08 Mandatory */ - ret = usbmsc_cmdread6(priv); - break; - - /* 0x09 Vendor specific */ - - case SCSI_CMD_WRITE6: /* 0x0a Optional */ - ret = usbmsc_cmdwrite6(priv); - break; - - /* case SCSI_CMD_SEEK6: 0x0b Obsolete - * 0x0c-0x10 Vendor specific - * case SCSI_CMD_SPACE6: 0x11 Vendor specific - */ - - case SCSI_CMD_INQUIRY: /* 0x12 Mandatory */ - ret = usbmsc_cmdinquiry(priv, buf); - break; - - /* 0x13-0x14 Vendor specific */ - - case SCSI_CMD_MODESELECT6: /* 0x15 Optional */ - ret = usbmsc_cmdmodeselect6(priv); - break; - - /* case SCSI_CMD_RESERVE6: 0x16 Obsolete - * case SCSI_CMD_RELEASE6: 0x17 Obsolete - * case SCSI_CMD_COPY: 0x18 Obsolete - * 0x19 Vendor specific - */ - - case SCSI_CMD_MODESENSE6: /* 0x1a Optional */ - ret = usbmsc_cmdmodesense6(priv, buf); - break; - - case SCSI_CMD_STARTSTOPUNIT: /* 0x1b Optional */ - ret = usbmsc_cmdstartstopunit(priv); - break; - - /* case SCSI_CMD_RECEIVEDIAGNOSTICRESULTS: 0x1c Optional - * case SCSI_CMD_SENDDIAGNOSTIC: 0x1d Mandatory, but not impl. - */ - - case SCSI_CMD_PREVENTMEDIAREMOVAL: /* 0x1e Optional */ - ret = usbmsc_cmdpreventmediumremoval(priv); - break; - - /* 0x20-22 Vendor specific */ - - case SCSI_CMD_READFORMATCAPACITIES: /* 0x23 Vend-spec (def. MMC spec) */ - ret = usbmsc_cmdreadformatcapacity(priv, buf); - break; - - /* 0x24 Vendor specific */ - - case SCSI_CMD_READCAPACITY10: /* 0x25 Mandatory */ - ret = usbmsc_cmdreadcapacity10(priv, buf); - break; - - /* 0x26-27 Vendor specific */ - - case SCSI_CMD_READ10: /* 0x28 Mandatory */ - ret = usbmsc_cmdread10(priv); - break; - - /* 0x29 Vendor specific */ - - case SCSI_CMD_WRITE10: /* 0x2a Optional */ - ret = usbmsc_cmdwrite10(priv); - break; - - /* case SCSI_CMD_SEEK10: 0x2b Obsolete - * 0x2c-2d Vendor specific - * case SCSI_CMD_WRITEANDVERIFY: 0x2e Optional - */ - - case SCSI_CMD_VERIFY10: /* 0x2f Opt, except Windows */ - ret = usbmsc_cmdverify10(priv); - break; - - /* case SCSI_CMD_SEARCHDATAHIGH: 0x30 Obsolete - * case SCSI_CMD_SEARCHDATAEQUAL: 0x31 Obsolete - * case SCSI_CMD_SEARCHDATALOW: 0x32 Obsolete - * case SCSI_CMD_SETLIMITS10: 0x33 Obsolete - * case SCSI_CMD_PREFETCH10: 0x34 Optional - */ - - case SCSI_CMD_SYNCHCACHE10: /* 0x35 Optional */ - ret = usbmsc_cmdsynchronizecache10(priv); - break; - - /* case SCSI_CMD_LOCKCACHE: 0x36 Obsolete - * case SCSI_CMD_READDEFECTDATA10: 0x37 Optional - * case SCSI_CMD_COMPARE: 0x39 Obsolete - * case SCSI_CMD_COPYANDVERIFY: 0x3a Obsolete - * case SCSI_CMD_WRITEBUFFER: 0x3b Optional - * case SCSI_CMD_READBUFFER: 0x3c Optional - * case SCSI_CMD_READLONG10: 0x3e Optional - * case SCSI_CMD_WRITELONG10: 0x3f Optional - * case SCSI_CMD_CHANGEDEFINITION: 0x40 Obsolete - * case SCSI_CMD_WRITESAME10: 0x41 Optional - * case SCSI_CMD_LOGSELECT: 0x4c Optional - * case SCSI_CMD_LOGSENSE: 0x4d Optional - * case SCSI_CMD_XDWRITE10: 0x50 Optional - * case SCSI_CMD_XPWRITE10: 0x51 Optional - * case SCSI_CMD_XDREAD10: 0x52 Optional - */ - - case SCSI_CMD_MODESELECT10: /* 0x55 Optional */ - ret = usbmsc_cmdmodeselect10(priv); - break; - - /* case SCSI_CMD_RESERVE10: 0x56 Obsolete - * case SCSI_CMD_RELEASE10: 0x57 Obsolete - */ - - case SCSI_CMD_MODESENSE10: /* 0x5a Optional */ - ret = usbmsc_cmdmodesense10(priv, buf); - break; - - /* case SCSI_CMD_PERSISTENTRESERVEIN: 0x5e Optional - * case SCSI_CMD_PERSISTENTRESERVEOUT: 0x5f Optional - * case SCSI_CMD_32: 0x7f Optional - * case SCSI_CMD_XDWRITEEXTENDED: 0x80 Obsolete - * case SCSI_CMD_REBUILD: 0x81 Obsolete - * case SCSI_CMD_REGENERATE: 0x82 Obsolete - * case SCSI_CMD_EXTENDEDCOPY: 0x83 Optional - * case SCSI_CMD_COPYRESULTS: 0x84 Optional - * case SCSI_CMD_ACCESSCONTROLIN: 0x86 Optional - * case SCSI_CMD_ACCESSCONTROLOUT: 0x87 Optional - * case SCSI_CMD_READ16: 0x88 Optional - * case SCSI_CMD_WRITE16: 0x8a Optional - * case SCSI_CMD_READATTRIBUTE: 0x8c Optional - * case SCSI_CMD_WRITEATTRIBUTE: 0x8d Optional - * case SCSI_CMD_WRITEANDVERIFY16: 0x8e Optional - * case SCSI_CMD_SYNCHCACHE16: 0x91 Optional - * case SCSI_CMD_LOCKUNLOCKACACHE: 0x92 Optional - * case SCSI_CMD_WRITESAME16: 0x93 Optional - * case SCSI_CMD_READCAPACITY16: 0x9e Optional - * case SCSI_CMD_READLONG16: 0x9e Optional - * case SCSI_CMD_WRITELONG16 0x9f Optional - * case SCSI_CMD_REPORTLUNS: 0xa0 Mandatory, but no-impl - * case SCSI_CMD_MAINTENANCEIN: 0xa3 Optional (SCCS==0) - * case SCSI_CMD_MAINTENANCEOUT: 0xa4 Optional (SCCS==0) - * case SCSI_CMD_MOVEMEDIUM: 0xa5 ? - * case SCSI_CMD_MOVEMEDIUMATTACHED: 0xa7 Optional (MCHNGR==0) - */ - - case SCSI_CMD_READ12: /* 0xa8 Optional */ - ret = usbmsc_cmdread12(priv); - break; - - case SCSI_CMD_WRITE12: /* 0xaa Optional */ - ret = usbmsc_cmdwrite12(priv); - break; - - /* case SCSI_CMD_READMEDIASERIALNUMBER: 0xab Optional - * case SCSI_CMD_WRITEANDVERIFY12: 0xae Optional - * case SCSI_CMD_VERIFY12: 0xaf Optional - * case SCSI_CMD_SETLIMITS12 0xb3 Obsolete - * case SCSI_CMD_READELEMENTSTATUS: 0xb4 Optional (MCHNGR==0) - * case SCSI_CMD_READDEFECTDATA12: 0xb7 Optional - * case SCSI_CMD_REDUNDANCYGROUPIN: 0xba Optional - * case SCSI_CMD_REDUNDANCYGROUPOUT: 0xbb Optional - * case SCSI_CMD_SPAREIN: 0xbc Optional (SCCS==0) - * case SCSI_CMD_SPAREOUT: 0xbd Optional (SCCS==0) - * case SCSI_CMD_VOLUMESETIN: 0xbe Optional (SCCS==0) - * case SCSI_CMD_VOLUMESETOUT: 0xbe Optional (SCCS==0) - * 0xc0-0xff Vendor specific - */ - - default: - priv->u.alloclen = 0; - priv->residue = priv->cbwlen; - priv->lun->sd = SCSI_KCQIR_INVALIDCOMMAND; - ret = -EINVAL; - break; + /* case SCSI_CMD_FORMAT_UNIT: 0x04 Mandatory, + * but not impl. + * 0x05 Vendor specific + * 0x06 Vendor specific + * case SCSI_CMD_REASSIGNBLOCKS: 0x07 Optional + */ + + case SCSI_CMD_READ6: /* 0x08 Mandatory */ + ret = usbmsc_cmdread6(priv); + break; + + /* 0x09 Vendor specific */ + + case SCSI_CMD_WRITE6: /* 0x0a Optional */ + ret = usbmsc_cmdwrite6(priv); + break; + + /* case SCSI_CMD_SEEK6: 0x0b Obsolete + * 0x0c-0x10 Vendor specific + * case SCSI_CMD_SPACE6: 0x11 Vendor specific + */ + + case SCSI_CMD_INQUIRY: /* 0x12 Mandatory */ + ret = usbmsc_cmdinquiry(priv, buf); + break; + + /* 0x13-0x14 Vendor specific */ + + case SCSI_CMD_MODESELECT6: /* 0x15 Optional */ + ret = usbmsc_cmdmodeselect6(priv); + break; + + /* case SCSI_CMD_RESERVE6: 0x16 Obsolete + * case SCSI_CMD_RELEASE6: 0x17 Obsolete + * case SCSI_CMD_COPY: 0x18 Obsolete + * 0x19 Vendor specific + */ + + case SCSI_CMD_MODESENSE6: /* 0x1a Optional */ + ret = usbmsc_cmdmodesense6(priv, buf); + break; + + case SCSI_CMD_STARTSTOPUNIT: /* 0x1b Optional */ + ret = usbmsc_cmdstartstopunit(priv); + break; + + /* case SCSI_CMD_RECEIVEDIAGNOSTICRESULTS: 0x1c Optional + * case SCSI_CMD_SENDDIAGNOSTIC: 0x1d Mandatory, + * but not impl. + */ + + case SCSI_CMD_PREVENTMEDIAREMOVAL: /* 0x1e Optional */ + ret = usbmsc_cmdpreventmediumremoval(priv); + break; + + /* 0x20-22 Vendor specific */ + + case SCSI_CMD_READFORMATCAPACITIES: /* 0x23 Vend-spec (def. MMC spec) */ + ret = usbmsc_cmdreadformatcapacity(priv, buf); + break; + + /* 0x24 Vendor specific */ + + case SCSI_CMD_READCAPACITY10: /* 0x25 Mandatory */ + ret = usbmsc_cmdreadcapacity10(priv, buf); + break; + + /* 0x26-27 Vendor specific */ + + case SCSI_CMD_READ10: /* 0x28 Mandatory */ + ret = usbmsc_cmdread10(priv); + break; + + /* 0x29 Vendor specific */ + + case SCSI_CMD_WRITE10: /* 0x2a Optional */ + ret = usbmsc_cmdwrite10(priv); + break; + + /* case SCSI_CMD_SEEK10: 0x2b Obsolete + * 0x2c-2d Vendor specific + * case SCSI_CMD_WRITEANDVERIFY: 0x2e Optional + */ + + case SCSI_CMD_VERIFY10: /* 0x2f Opt, except Windows */ + ret = usbmsc_cmdverify10(priv); + break; + + /* case SCSI_CMD_SEARCHDATAHIGH: 0x30 Obsolete + * case SCSI_CMD_SEARCHDATAEQUAL: 0x31 Obsolete + * case SCSI_CMD_SEARCHDATALOW: 0x32 Obsolete + * case SCSI_CMD_SETLIMITS10: 0x33 Obsolete + * case SCSI_CMD_PREFETCH10: 0x34 Optional + */ + + case SCSI_CMD_SYNCHCACHE10: /* 0x35 Optional */ + ret = usbmsc_cmdsynchronizecache10(priv); + break; + + /* case SCSI_CMD_LOCKCACHE: 0x36 Obsolete + * case SCSI_CMD_READDEFECTDATA10: 0x37 Optional + * case SCSI_CMD_COMPARE: 0x39 Obsolete + * case SCSI_CMD_COPYANDVERIFY: 0x3a Obsolete + * case SCSI_CMD_WRITEBUFFER: 0x3b Optional + * case SCSI_CMD_READBUFFER: 0x3c Optional + * case SCSI_CMD_READLONG10: 0x3e Optional + * case SCSI_CMD_WRITELONG10: 0x3f Optional + * case SCSI_CMD_CHANGEDEFINITION: 0x40 Obsolete + * case SCSI_CMD_WRITESAME10: 0x41 Optional + * case SCSI_CMD_LOGSELECT: 0x4c Optional + * case SCSI_CMD_LOGSENSE: 0x4d Optional + * case SCSI_CMD_XDWRITE10: 0x50 Optional + * case SCSI_CMD_XPWRITE10: 0x51 Optional + * case SCSI_CMD_XDREAD10: 0x52 Optional + */ + + case SCSI_CMD_MODESELECT10: /* 0x55 Optional */ + ret = usbmsc_cmdmodeselect10(priv); + break; + + /* case SCSI_CMD_RESERVE10: 0x56 Obsolete + * case SCSI_CMD_RELEASE10: 0x57 Obsolete + */ + + case SCSI_CMD_MODESENSE10: /* 0x5a Optional */ + ret = usbmsc_cmdmodesense10(priv, buf); + break; + + /* case SCSI_CMD_PERSISTENTRESERVEIN: 0x5e Optional + * case SCSI_CMD_PERSISTENTRESERVEOUT: 0x5f Optional + * case SCSI_CMD_32: 0x7f Optional + * case SCSI_CMD_XDWRITEEXTENDED: 0x80 Obsolete + * case SCSI_CMD_REBUILD: 0x81 Obsolete + * case SCSI_CMD_REGENERATE: 0x82 Obsolete + * case SCSI_CMD_EXTENDEDCOPY: 0x83 Optional + * case SCSI_CMD_COPYRESULTS: 0x84 Optional + * case SCSI_CMD_ACCESSCONTROLIN: 0x86 Optional + * case SCSI_CMD_ACCESSCONTROLOUT: 0x87 Optional + * case SCSI_CMD_READ16: 0x88 Optional + * case SCSI_CMD_WRITE16: 0x8a Optional + * case SCSI_CMD_READATTRIBUTE: 0x8c Optional + * case SCSI_CMD_WRITEATTRIBUTE: 0x8d Optional + * case SCSI_CMD_WRITEANDVERIFY16: 0x8e Optional + * case SCSI_CMD_SYNCHCACHE16: 0x91 Optional + * case SCSI_CMD_LOCKUNLOCKACACHE: 0x92 Optional + * case SCSI_CMD_WRITESAME16: 0x93 Optional + * case SCSI_CMD_READCAPACITY16: 0x9e Optional + * case SCSI_CMD_READLONG16: 0x9e Optional + * case SCSI_CMD_WRITELONG16 0x9f Optional + * case SCSI_CMD_REPORTLUNS: 0xa0 Mandatory, but no-impl + * case SCSI_CMD_MAINTENANCEIN: 0xa3 Optional (SCCS==0) + * case SCSI_CMD_MAINTENANCEOUT: 0xa4 Optional (SCCS==0) + * case SCSI_CMD_MOVEMEDIUM: 0xa5 ? + * case SCSI_CMD_MOVEMEDIUMATTACHED: 0xa7 Optional (MCHNGR==0) + */ + + case SCSI_CMD_READ12: /* 0xa8 Optional */ + ret = usbmsc_cmdread12(priv); + break; + + case SCSI_CMD_WRITE12: /* 0xaa Optional */ + ret = usbmsc_cmdwrite12(priv); + break; + + /* case SCSI_CMD_READMEDIASERIALNUMBER: 0xab Optional + * case SCSI_CMD_WRITEANDVERIFY12: 0xae Optional + * case SCSI_CMD_VERIFY12: 0xaf Optional + * case SCSI_CMD_SETLIMITS12 0xb3 Obsolete + * case SCSI_CMD_READELEMENTSTATUS: 0xb4 Optional (MCHNGR==0) + * case SCSI_CMD_READDEFECTDATA12: 0xb7 Optional + * case SCSI_CMD_REDUNDANCYGROUPIN: 0xba Optional + * case SCSI_CMD_REDUNDANCYGROUPOUT: 0xbb Optional + * case SCSI_CMD_SPAREIN: 0xbc Optional (SCCS==0) + * case SCSI_CMD_SPAREOUT: 0xbd Optional (SCCS==0) + * case SCSI_CMD_VOLUMESETIN: 0xbe Optional (SCCS==0) + * case SCSI_CMD_VOLUMESETOUT: 0xbe Optional (SCCS==0) + * 0xc0-0xff Vendor specific + */ + + default: + priv->u.alloclen = 0; + priv->residue = priv->cbwlen; + priv->lun->sd = SCSI_KCQIR_INVALIDCOMMAND; + ret = -EINVAL; + break; } nxmutex_unlock(&priv->thlock); @@ -2566,7 +2568,8 @@ static int usbmsc_cmdwritestate(FAR struct usbmsc_dev_s *priv) * top and attempt to get the next read request. * * While there are still data-out bytes not yet requested (beyond the - * initially queued maxpacket requests, pre-accounted in priv->residue), + * initially queued maxpacket requests, pre-accounted in + * priv->residue), * request them in full bulkoutreqlen chunks so the controller DMA * coalesces many maxpacket USB packets into one completion, cutting * the EP_SUBMIT / completion-IRQ / worker round-trips that dominate @@ -2613,7 +2616,8 @@ static int usbmsc_cmdwritestate(FAR struct usbmsc_dev_s *priv) errout: /* Rebuild the CSW residue (bytes not written to the block driver) from the - * still-untransferred sector count. During the data phase priv->residue is + * still-untransferred sector count. During the data phase + * priv->residue is * reused to size the enlarged bulk-OUT re-submits; xfrlen * sectorsize is * the exact untransferred byte count to report in the CSW. */ @@ -2670,132 +2674,133 @@ static int usbmsc_cmdfinishstate(FAR struct usbmsc_dev_s *priv) switch (priv->cbwdir) { - /* Device-to-host: All but the last data buffer has been sent */ - - case USBMSC_FLAGS_DIRDEVICE2HOST: - if (priv->cbwlen > 0) - { - bool terminated = false; - - /* On most commands (the exception is outgoing, write commands), - * the data has not yet been sent. - */ - - if (priv->nreqbytes > 0) - { - struct usbdev_req_s *req; - - /* Take a request from the wrreqlist (we've already checked - * that is it not NULL) - */ - - flags = spin_lock_irqsave(&priv->spinlock); - privreq = (FAR struct usbmsc_req_s *) - sq_remfirst(&priv->wrreqlist); - spin_unlock_irqrestore(&priv->spinlock, flags); - - /* Send the write request */ - - req = privreq->req; - req->len = priv->nreqbytes; - req->callback = usbmsc_wrcomplete; - req->priv = privreq; - req->flags = USBDEV_REQFLAGS_NULLPKT; - - ret = EP_SUBMIT(priv->epbulkin, privreq->req); - if (ret < 0) - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHSUBMIT), - (uint16_t)-ret); - } - else - { - /* The request was submitted with USBDEV_REQFLAGS_NULLPKT, - * so the transfer ends with a short packet (or a ZLP if - * the response length is an exact multiple of the packet - * size). Either way the host's Data-In phase terminates - * cleanly when this request completes. - */ - - terminated = true; - } - } - - /* If there is a residue, the host expected more data than we - * sent. If the data phase was already terminated by a short - * packet (or ZLP), nothing more is needed: the host's transfer - * has completed and the residue is reported in the CSW - * (dCSWDataResidue). Stalling here as well is permitted by BOT - * (USB MSC BOT 6.7.2), but it is gratuitous and some hosts - * (macOS) respond with a full Bulk-Only reset sequence to any - * bulk-IN halt during device probing, which costs seconds per - * command or aborts the probe entirely. - * - * Only halt the endpoint when nothing terminated the data - * phase - otherwise the host would mistake the following CSW - * for transfer data. - */ - - if (priv->residue > 0 && !terminated) - { + /* Device-to-host: All but the last data buffer has been sent */ + + case USBMSC_FLAGS_DIRDEVICE2HOST: + if (priv->cbwlen > 0) + { + bool terminated = false; + + /* On most commands (the exception is outgoing, write commands), + * the data has not yet been sent. + */ + + if (priv->nreqbytes > 0) + { + struct usbdev_req_s *req; + + /* Take a request from the wrreqlist (we've already checked + * that is it not NULL) + */ + + flags = spin_lock_irqsave(&priv->spinlock); + privreq = (FAR struct usbmsc_req_s *) + sq_remfirst(&priv->wrreqlist); + spin_unlock_irqrestore(&priv->spinlock, flags); + + /* Send the write request */ + + req = privreq->req; + req->len = priv->nreqbytes; + req->callback = usbmsc_wrcomplete; + req->priv = privreq; + req->flags = USBDEV_REQFLAGS_NULLPKT; + + ret = EP_SUBMIT(priv->epbulkin, privreq->req); + if (ret < 0) + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHSUBMIT), + (uint16_t)-ret); + } + else + { + /* The request was submitted with + * USBDEV_REQFLAGS_NULLPKT, so the transfer ends with a + * short packet (or a ZLP if the response length is an + * exact multiple of the packet size). Either way the + * host's Data-In phase terminates cleanly when this + * request completes. + */ + + terminated = true; + } + } + + /* If there is a residue, the host expected more data than we + * sent. If the data phase was already terminated by a short + * packet (or ZLP), nothing more is needed: the host's transfer + * has completed and the residue is reported in the CSW + * (dCSWDataResidue). Stalling here as well is permitted by BOT + * (USB MSC BOT 6.7.2), but it is gratuitous and some hosts + * (macOS) respond with a full Bulk-Only reset sequence to any + * bulk-IN halt during device probing, which costs seconds per + * command or aborts the probe entirely. + * + * Only halt the endpoint when nothing terminated the data + * phase - otherwise the host would mistake the following CSW + * for transfer data. + */ + + if (priv->residue > 0 && !terminated) + { #ifndef CONFIG_USBMSC_NOT_STALL_BULKEP - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHRESIDUE), - (uint16_t)priv->residue); + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHRESIDUE), + (uint16_t)priv->residue); #ifdef USBMSC_STALL_RACEWAR - /* (See description of the workaround at the top of the file). - * First, wait for the transfer to complete, then stall the - * endpoint - */ + /* (See description of the workaround at the top of the + * file). First, wait for the transfer to complete, then + * stall the endpoint + */ - nxsched_usleep (100000); - EP_STALL(priv->epbulkin); + nxsched_usleep (100000); + EP_STALL(priv->epbulkin); - /* now wait for stall to go away .... */ + /* now wait for stall to go away .... */ - nxsched_usleep (100000); + nxsched_usleep (100000); #else - EP_STALL(priv->epbulkin); + EP_STALL(priv->epbulkin); #endif #else - priv->residue = 0; + priv->residue = 0; #endif - } - } - break; - - /* Host-to-device: We have processed all we want of the host data. */ - - case USBMSC_FLAGS_DIRHOST2DEVICE: - if (priv->residue > 0) - { - /* Did the host stop sending unexpectedly early? */ - - if (priv->shortpacket) - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHSHORTPKT), - (uint16_t)priv->residue); - } - - /* Unprocessed incoming data: STALL and cancel requests. */ - - else - { - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINSHSUBMIT), - (uint16_t)priv->residue); - EP_STALL(priv->epbulkout); - } - - flags = spin_lock_irqsave(&priv->spinlock); - priv->theventset |= USBMSC_EVENT_ABORTBULKOUT; - spin_unlock_irqrestore(&priv->spinlock, flags); - } - break; - - default: - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINSHDIR), priv->cbwdir); - case USBMSC_FLAGS_DIRNONE: /* Nothing to send */ - break; + } + } + break; + + /* Host-to-device: We have processed all we want of the host data. */ + + case USBMSC_FLAGS_DIRHOST2DEVICE: + if (priv->residue > 0) + { + /* Did the host stop sending unexpectedly early? */ + + if (priv->shortpacket) + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINISHSHORTPKT), + (uint16_t)priv->residue); + } + + /* Unprocessed incoming data: STALL and cancel requests. */ + + else + { + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINSHSUBMIT), + (uint16_t)priv->residue); + EP_STALL(priv->epbulkout); + } + + flags = spin_lock_irqsave(&priv->spinlock); + priv->theventset |= USBMSC_EVENT_ABORTBULKOUT; + spin_unlock_irqrestore(&priv->spinlock, flags); + } + break; + + default: + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_CMDFINSHDIR), priv->cbwdir); + case USBMSC_FLAGS_DIRNONE: /* Nothing to send */ + break; } /* Return to the IDLE state */ @@ -3104,39 +3109,39 @@ int usbmsc_scsi_main(int argc, FAR char *argv[]) { switch (priv->thstate) { - case USBMSC_STATE_IDLE: /* Started and waiting for commands */ - ret = usbmsc_idlestate(priv); - break; - - case USBMSC_STATE_CMDPARSE: /* Parsing the received a command */ - ret = usbmsc_cmdparsestate(priv); - break; - - case USBMSC_STATE_CMDREAD: /* Continuing to process a SCSI read command */ - ret = usbmsc_cmdreadstate(priv); - break; - - case USBMSC_STATE_CMDWRITE: /* Continuing to process a SCSI write command */ - ret = usbmsc_cmdwritestate(priv); - break; - - case USBMSC_STATE_CMDFINISH: /* Finish command processing */ - ret = usbmsc_cmdfinishstate(priv); - break; - - case USBMSC_STATE_CMDSTATUS: /* Processing the status phase of a command */ - ret = usbmsc_cmdstatusstate(priv); - break; - - case USBMSC_STATE_NOTSTARTED: /* Thread has not yet been started */ - case USBMSC_STATE_STARTED: /* Started, but is not yet initialized */ - case USBMSC_STATE_TERMINATED: /* Thread has exited */ - default: - usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_INVALIDSTATE), - priv->thstate); - priv->thstate = USBMSC_STATE_IDLE; - ret = OK; - break; + case USBMSC_STATE_IDLE: /* Started and waiting for commands */ + ret = usbmsc_idlestate(priv); + break; + + case USBMSC_STATE_CMDPARSE: /* Parsing the received a command */ + ret = usbmsc_cmdparsestate(priv); + break; + + case USBMSC_STATE_CMDREAD: /* Continuing to process a SCSI read command */ + ret = usbmsc_cmdreadstate(priv); + break; + + case USBMSC_STATE_CMDWRITE: /* Continuing to process a SCSI write command */ + ret = usbmsc_cmdwritestate(priv); + break; + + case USBMSC_STATE_CMDFINISH: /* Finish command processing */ + ret = usbmsc_cmdfinishstate(priv); + break; + + case USBMSC_STATE_CMDSTATUS: /* Processing the status phase of a command */ + ret = usbmsc_cmdstatusstate(priv); + break; + + case USBMSC_STATE_NOTSTARTED: /* Thread has not yet been started */ + case USBMSC_STATE_STARTED: /* Started, but is not yet initialized */ + case USBMSC_STATE_TERMINATED: /* Thread has exited */ + default: + usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_INVALIDSTATE), + priv->thstate); + priv->thstate = USBMSC_STATE_IDLE; + ret = OK; + break; } } while (ret == OK);
