From owner-svn-src-all@FreeBSD.ORG Fri May 30 07:30:25 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BACF0555; Fri, 30 May 2014 07:30:25 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A7C2828F7; Fri, 30 May 2014 07:30:25 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4U7UPLU001007; Fri, 30 May 2014 07:30:25 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4U7UP2T001005; Fri, 30 May 2014 07:30:25 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201405300730.s4U7UP2T001005@svn.freebsd.org> From: Hans Petter Selasky Date: Fri, 30 May 2014 07:30:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r266873 - head/sys/dev/usb X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 May 2014 07:30:25 -0000 Author: hselasky Date: Fri May 30 07:30:24 2014 New Revision: 266873 URL: http://svnweb.freebsd.org/changeset/base/266873 Log: Add support for basic read, write and read capacity disk operations to the USB mass storage test utility file. Sponsored by: DARPA, AFRL Modified: head/sys/dev/usb/usb_msctest.c head/sys/dev/usb/usb_msctest.h Modified: head/sys/dev/usb/usb_msctest.c ============================================================================== --- head/sys/dev/usb/usb_msctest.c Fri May 30 06:45:50 2014 (r266872) +++ head/sys/dev/usb/usb_msctest.c Fri May 30 07:30:24 2014 (r266873) @@ -87,9 +87,10 @@ enum { DIR_NONE, }; -#define SCSI_MAX_LEN MAX(0x100, BULK_SIZE) +#define SCSI_MAX_LEN MAX(SCSI_FIXED_BLOCK_SIZE, USB_MSCTEST_BULK_SIZE) #define SCSI_INQ_LEN 0x24 #define SCSI_SENSE_LEN 0xFF +#define SCSI_FIXED_BLOCK_SIZE 512 /* bytes */ static uint8_t scsi_test_unit_ready[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static uint8_t scsi_inquiry[] = { 0x12, 0x00, 0x00, 0x00, SCSI_INQ_LEN, 0x00 }; @@ -110,7 +111,10 @@ static uint8_t scsi_request_sense[] = { static uint8_t scsi_read_capacity[] = { 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -#define BULK_SIZE 64 /* dummy */ +#ifndef USB_MSCTEST_BULK_SIZE +#define USB_MSCTEST_BULK_SIZE 64 /* dummy */ +#endif + #define ERR_CSW_FAILED -1 /* Command Block Wrapper */ @@ -851,3 +855,101 @@ usb_msc_eject(struct usb_device *udev, u bbb_detach(sc); return (0); } + +usb_error_t +usb_msc_read_10(struct usb_device *udev, uint8_t iface_index, + uint32_t lba, uint32_t blocks, void *buffer) +{ + struct bbb_transfer *sc; + uint8_t cmd[10]; + usb_error_t err; + + cmd[0] = 0x28; /* READ_10 */ + cmd[1] = 0; + cmd[2] = lba >> 24; + cmd[3] = lba >> 16; + cmd[4] = lba >> 8; + cmd[5] = lba >> 0; + cmd[6] = 0; + cmd[7] = blocks >> 8; + cmd[8] = blocks; + cmd[9] = 0; + + sc = bbb_attach(udev, iface_index); + if (sc == NULL) + return (USB_ERR_INVAL); + + err = bbb_command_start(sc, DIR_IN, 0, buffer, + blocks * SCSI_FIXED_BLOCK_SIZE, cmd, 10, USB_MS_HZ); + + bbb_detach(sc); + + return (err); +} + +usb_error_t +usb_msc_write_10(struct usb_device *udev, uint8_t iface_index, + uint32_t lba, uint32_t blocks, void *buffer) +{ + struct bbb_transfer *sc; + uint8_t cmd[10]; + usb_error_t err; + + cmd[0] = 0x2a; /* WRITE_10 */ + cmd[1] = 0; + cmd[2] = lba >> 24; + cmd[3] = lba >> 16; + cmd[4] = lba >> 8; + cmd[5] = lba >> 0; + cmd[6] = 0; + cmd[7] = blocks >> 8; + cmd[8] = blocks; + cmd[9] = 0; + + sc = bbb_attach(udev, iface_index); + if (sc == NULL) + return (USB_ERR_INVAL); + + err = bbb_command_start(sc, DIR_OUT, 0, buffer, + blocks * SCSI_FIXED_BLOCK_SIZE, cmd, 10, USB_MS_HZ); + + bbb_detach(sc); + + return (err); +} + +usb_error_t +usb_msc_read_capacity(struct usb_device *udev, uint8_t iface_index, + uint32_t *lba_last, uint32_t *block_size) +{ + struct bbb_transfer *sc; + usb_error_t err; + + sc = bbb_attach(udev, iface_index); + if (sc == NULL) + return (USB_ERR_INVAL); + + err = bbb_command_start(sc, DIR_IN, 0, sc->buffer, 8, + &scsi_read_capacity, sizeof(scsi_read_capacity), + USB_MS_HZ); + + *lba_last = + (sc->buffer[0] << 24) | + (sc->buffer[1] << 16) | + (sc->buffer[2] << 8) | + (sc->buffer[3]); + + *block_size = + (sc->buffer[4] << 24) | + (sc->buffer[5] << 16) | + (sc->buffer[6] << 8) | + (sc->buffer[7]); + + /* we currently only support one block size */ + if (*block_size != SCSI_FIXED_BLOCK_SIZE) + err = USB_ERR_INVAL; + + bbb_detach(sc); + + return (err); +} Modified: head/sys/dev/usb/usb_msctest.h ============================================================================== --- head/sys/dev/usb/usb_msctest.h Fri May 30 06:45:50 2014 (r266872) +++ head/sys/dev/usb/usb_msctest.h Fri May 30 07:30:24 2014 (r266873) @@ -42,5 +42,14 @@ usb_error_t usb_msc_eject(struct usb_dev uint8_t iface_index, int method); usb_error_t usb_msc_auto_quirk(struct usb_device *udev, uint8_t iface_index); +usb_error_t usb_msc_read_10(struct usb_device *udev, + uint8_t iface_index, uint32_t lba, uint32_t blocks, + void *buffer); +usb_error_t usb_msc_write_10(struct usb_device *udev, + uint8_t iface_index, uint32_t lba, uint32_t blocks, + void *buffer); +usb_error_t usb_msc_read_capacity(struct usb_device *udev, + uint8_t iface_index, uint32_t *lba_last, + uint32_t *block_size); #endif /* _USB_MSCTEST_H_ */