scsi: Move cmd_phase enum to the header

This can be used by common files, so move it to the SCSI header and rename
it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2022-09-21 16:21:35 +02:00
parent 8bae79744b
commit 0e0b9e9459
2 changed files with 22 additions and 15 deletions

View file

@ -23,12 +23,6 @@ enum {
SANDBOX_FLASH_BLOCK_LEN = 512, SANDBOX_FLASH_BLOCK_LEN = 512,
}; };
enum cmd_phase {
PHASE_START,
PHASE_DATA,
PHASE_STATUS,
};
enum { enum {
STRINGID_MANUFACTURER = 1, STRINGID_MANUFACTURER = 1,
STRINGID_PRODUCT, STRINGID_PRODUCT,
@ -56,7 +50,7 @@ struct sandbox_flash_priv {
int alloc_len; int alloc_len;
int transfer_len; int transfer_len;
int read_len; int read_len;
enum cmd_phase phase; enum scsi_cmd_phase phase;
u32 tag; u32 tag;
int fd; int fd;
loff_t file_size; loff_t file_size;
@ -290,7 +284,7 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
return -EPROTONOSUPPORT; return -EPROTONOSUPPORT;
} }
priv->phase = priv->transfer_len ? PHASE_DATA : PHASE_STATUS; priv->phase = priv->transfer_len ? SCSIPH_DATA : SCSIPH_STATUS;
return 0; return 0;
} }
@ -307,7 +301,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev,
switch (ep) { switch (ep) {
case SANDBOX_FLASH_EP_OUT: case SANDBOX_FLASH_EP_OUT:
switch (priv->phase) { switch (priv->phase) {
case PHASE_START: case SCSIPH_START:
priv->alloc_len = 0; priv->alloc_len = 0;
priv->read_len = 0; priv->read_len = 0;
if (priv->error || len != UMASS_BBB_CBW_SIZE || if (priv->error || len != UMASS_BBB_CBW_SIZE ||
@ -322,7 +316,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev,
priv->tag = cbw->dCBWTag; priv->tag = cbw->dCBWTag;
return handle_ufi_command(plat, priv, cbw->CBWCDB, return handle_ufi_command(plat, priv, cbw->CBWCDB,
cbw->bCDBLength); cbw->bCDBLength);
case PHASE_DATA: case SCSIPH_DATA:
debug("data out\n"); debug("data out\n");
break; break;
default: default:
@ -330,7 +324,7 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev,
} }
case SANDBOX_FLASH_EP_IN: case SANDBOX_FLASH_EP_IN:
switch (priv->phase) { switch (priv->phase) {
case PHASE_DATA: case SCSIPH_DATA:
debug("data in, len=%x, alloc_len=%x, priv->read_len=%x\n", debug("data in, len=%x, alloc_len=%x, priv->read_len=%x\n",
len, priv->alloc_len, priv->read_len); len, priv->alloc_len, priv->read_len);
if (priv->read_len) { if (priv->read_len) {
@ -344,22 +338,22 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev,
return -EIO; return -EIO;
priv->read_len -= len / SANDBOX_FLASH_BLOCK_LEN; priv->read_len -= len / SANDBOX_FLASH_BLOCK_LEN;
if (!priv->read_len) if (!priv->read_len)
priv->phase = PHASE_STATUS; priv->phase = SCSIPH_STATUS;
} else { } else {
if (priv->alloc_len && len > priv->alloc_len) if (priv->alloc_len && len > priv->alloc_len)
len = priv->alloc_len; len = priv->alloc_len;
if (len > sizeof(priv->buff)) if (len > sizeof(priv->buff))
len = sizeof(priv->buff); len = sizeof(priv->buff);
memcpy(buff, priv->buff, len); memcpy(buff, priv->buff, len);
priv->phase = PHASE_STATUS; priv->phase = SCSIPH_STATUS;
} }
return len; return len;
case PHASE_STATUS: case SCSIPH_STATUS:
debug("status in, len=%x\n", len); debug("status in, len=%x\n", len);
if (len > sizeof(priv->status)) if (len > sizeof(priv->status))
len = sizeof(priv->status); len = sizeof(priv->status);
memcpy(buff, &priv->status, len); memcpy(buff, &priv->status, len);
priv->phase = PHASE_START; priv->phase = SCSIPH_START;
return len; return len;
default: default:
break; break;

View file

@ -187,6 +187,19 @@ struct scsi_cmd {
#define SCSI_WRITE_LONG 0x3F /* Write Long (O) */ #define SCSI_WRITE_LONG 0x3F /* Write Long (O) */
#define SCSI_WRITE_SAME 0x41 /* Write Same (O) */ #define SCSI_WRITE_SAME 0x41 /* Write Same (O) */
/**
* enum scsi_cmd_phase - current phase of the SCSI protocol
*
* @SCSIPH_START: Start phase
* @SCSIPH_DATA: Data phase
* @SCSIPH_STATUS: Status phase
*/
enum scsi_cmd_phase {
SCSIPH_START,
SCSIPH_DATA,
SCSIPH_STATUS,
};
/** /**
* struct scsi_plat - stores information about SCSI controller * struct scsi_plat - stores information about SCSI controller
* *