Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib_scsi: configurable size of read/write buffer #418

Open
wants to merge 1 commit into
base: chibios-20.3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions os/various/lib_scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,23 @@ static bool data_read_write10(SCSITarget *scsip, const uint8_t *cmd) {
blkGetInfo(blkdev, &bdi);
size_t bs = bdi.blk_size;
uint8_t *buf = scsip->config->blkbuf;
uint32_t n_bufs = scsip->config->blkbufsize / bs;

size_t i = 0;
for (i=0; i<req.blk_cnt; i++) {
while (i < req.blk_cnt) {
size_t n = n_bufs > (req.blk_cnt - i) ? (req.blk_cnt - i) : n_bufs;

if (cmd[0] == SCSI_CMD_READ_10) {
// TODO: block error handling
blkRead(blkdev, req.first_lba + i, buf, 1);
tr->transmit(tr, buf, bs);
blkRead(blkdev, req.first_lba + i, buf, n);
tr->transmit(tr, buf, bs * n);
}
else {
// TODO: block error handling
tr->receive(tr, buf, bs);
blkWrite(blkdev, req.first_lba + i, buf, 1);
tr->receive(tr, buf, bs * n);
blkWrite(blkdev, req.first_lba + i, buf, n);
}
i += n;
}
}
return SCSI_SUCCESS;
Expand Down
6 changes: 5 additions & 1 deletion os/various/lib_scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,13 @@ typedef struct {
*/
BaseBlockDevice *blkdev;
/**
* @brief Pointer to data buffer for single block.
* @brief Pointer to data buffer.
*/
uint8_t *blkbuf;
/**
* brief Size of data buffer.
*/
uint32_t blkbufsize;
/**
* @brief Pointer to SCSI inquiry response object.
*/
Expand Down
Loading