2022-09-21 14:21:36 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
|
|
/*
|
|
|
|
* Emulation of enough SCSI commands to find and read from a unit
|
|
|
|
*
|
|
|
|
* Copyright 2022 Google LLC
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*
|
|
|
|
* implementations of SCSI functions required so that CONFIG_SCSI can be enabled
|
|
|
|
* for sandbox
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __scsi_emul_h
|
|
|
|
#define __scsi_emul_h
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct scsi_emul_info - information for emulating a SCSI device
|
|
|
|
*
|
2022-09-21 14:21:38 +00:00
|
|
|
* @vendor: Vendor name
|
|
|
|
* @product: Product name
|
2022-09-21 14:21:39 +00:00
|
|
|
* @block_size: Block size of device in bytes (normally 512)
|
2022-09-21 14:21:40 +00:00
|
|
|
* @file_size: Size of the backing file for this emulator, in bytes
|
2022-09-21 14:21:45 +00:00
|
|
|
* @seek_block: Seek position for file (block number)
|
2022-09-21 14:21:38 +00:00
|
|
|
*
|
2022-09-21 14:21:36 +00:00
|
|
|
* @phase: Current SCSI phase
|
|
|
|
* @buff_used: Number of bytes ready to transfer back to host
|
|
|
|
* @read_len: Number of bytes of data left in the current read command
|
|
|
|
* @alloc_len: Allocation length from the last incoming command
|
|
|
|
* @transfer_len: Transfer length from CBW header
|
2022-09-21 14:21:37 +00:00
|
|
|
* @buff: Data buffer for outgoing data
|
2022-09-21 14:21:36 +00:00
|
|
|
*/
|
|
|
|
struct scsi_emul_info {
|
2022-09-21 14:21:37 +00:00
|
|
|
/* provided by the caller: */
|
|
|
|
void *buff;
|
2022-09-21 14:21:38 +00:00
|
|
|
const char *vendor;
|
|
|
|
const char *product;
|
2022-09-21 14:21:39 +00:00
|
|
|
int block_size;
|
2022-09-21 14:21:40 +00:00
|
|
|
loff_t file_size;
|
2022-09-21 14:21:45 +00:00
|
|
|
int seek_block;
|
2022-09-21 14:21:37 +00:00
|
|
|
|
|
|
|
/* state maintained by the emulator: */
|
2022-09-21 14:21:36 +00:00
|
|
|
enum scsi_cmd_phase phase;
|
|
|
|
int buff_used;
|
|
|
|
int read_len;
|
2022-09-21 14:21:45 +00:00
|
|
|
uint seek_pos;
|
2022-09-21 14:21:36 +00:00
|
|
|
int alloc_len;
|
|
|
|
uint transfer_len;
|
|
|
|
};
|
|
|
|
|
2022-09-21 14:21:45 +00:00
|
|
|
/* Indicates that a read is being started */
|
|
|
|
#define SCSI_EMUL_DO_READ 1
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sb_scsi_emul_command() - Process a SCSI command
|
|
|
|
*
|
|
|
|
* This sets up the response in info->buff and updates various other values
|
|
|
|
* in info.
|
|
|
|
*
|
|
|
|
* If SCSI_EMUL_DO_READ is returned then the caller should set up so that the
|
|
|
|
* backing file can be read, or return an error status if there is no file.
|
|
|
|
*
|
|
|
|
* @info: Emulation information
|
|
|
|
* @req: Request to process
|
|
|
|
* @len: Length of request in bytes
|
|
|
|
* @return SCSI_EMUL_DO_READ if a read has started, 0 if some other operation
|
|
|
|
* has started, -ve if there was an error
|
|
|
|
*/
|
|
|
|
int sb_scsi_emul_command(struct scsi_emul_info *info,
|
|
|
|
const struct scsi_cmd *req, int len);
|
|
|
|
|
2022-09-21 14:21:36 +00:00
|
|
|
#endif
|