From owner-svn-src-head@FreeBSD.ORG Fri Sep 4 09:57:03 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0BA8106566C; Fri, 4 Sep 2009 09:57:03 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AF6498FC0A; Fri, 4 Sep 2009 09:57:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n849v3Fm061287; Fri, 4 Sep 2009 09:57:03 GMT (envelope-from trasz@svn.freebsd.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n849v3MZ061284; Fri, 4 Sep 2009 09:57:03 GMT (envelope-from trasz@svn.freebsd.org) Message-Id: <200909040957.n849v3MZ061284@svn.freebsd.org> From: Edward Tomasz Napierala Date: Fri, 4 Sep 2009 09:57:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196826 - head/sys/dev/usb/storage X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2009 09:57:03 -0000 Author: trasz Date: Fri Sep 4 09:57:03 2009 New Revision: 196826 URL: http://svn.freebsd.org/changeset/base/196826 Log: Make umass(4) pass device USB serial number to CAM, making it possible to e.g. retrieve it using camcontrol(8). Reviewed by: scottl, hps (earlier version) Obtained from: Wheel Sp. z o.o. (http://www.wheel.pl) Modified: head/sys/dev/usb/storage/umass.c Modified: head/sys/dev/usb/storage/umass.c ============================================================================== --- head/sys/dev/usb/storage/umass.c Fri Sep 4 09:48:18 2009 (r196825) +++ head/sys/dev/usb/storage/umass.c Fri Sep 4 09:57:03 2009 (r196826) @@ -124,6 +124,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include "usbdevs.h" #include @@ -2978,6 +2979,28 @@ umass_cam_action(struct cam_sim *sim, un if (sc->sc_transfer.cmd_data[0] == INQUIRY) { /* + * Umass devices don't generally report their serial numbers + * in the usual SCSI way. Emulate it here. + */ + if ((sc->sc_transfer.cmd_data[1] & SI_EVPD) && + sc->sc_transfer.cmd_data[2] == SVPD_UNIT_SERIAL_NUMBER && + sc->sc_udev != NULL && + sc->sc_udev->serial != NULL && + sc->sc_udev->serial[0] != '\0') { + struct scsi_vpd_unit_serial_number *vpd_serial; + + vpd_serial = (struct scsi_vpd_unit_serial_number *)ccb->csio.data_ptr; + vpd_serial->length = strlen(sc->sc_udev->serial); + if (vpd_serial->length > sizeof(vpd_serial->serial_num)) + vpd_serial->length = sizeof(vpd_serial->serial_num); + memcpy(vpd_serial->serial_num, sc->sc_udev->serial, vpd_serial->length); + ccb->csio.scsi_status = SCSI_STATUS_OK; + ccb->ccb_h.status = CAM_REQ_CMP; + xpt_done(ccb); + goto done; + } + + /* * Handle EVPD inquiry for broken devices first * NO_INQUIRY also implies NO_INQUIRY_EVPD */ @@ -3193,6 +3216,29 @@ umass_cam_cb(struct umass_softc *sc, uni maxsector = scsi_4btoul(rcap->addr) - 1; scsi_ulto4b(maxsector, rcap->addr); } + /* + * We have to add SVPD_UNIT_SERIAL_NUMBER to the list + * of pages supported by the device - otherwise, CAM + * will never ask us for the serial number if the + * device cannot handle that by itself. + */ + if (ccb->ccb_h.func_code == XPT_SCSI_IO && + sc->sc_transfer.cmd_data[0] == INQUIRY && + (sc->sc_transfer.cmd_data[1] & SI_EVPD) && + sc->sc_transfer.cmd_data[2] == SVPD_SUPPORTED_PAGE_LIST && + sc->sc_udev != NULL && + sc->sc_udev->serial != NULL && + sc->sc_udev->serial[0] != '\0') { + struct ccb_scsiio *csio; + struct scsi_vpd_supported_page_list *page_list; + + csio = &ccb->csio; + page_list = (struct scsi_vpd_supported_page_list *)csio->data_ptr; + if (page_list->length + 1 < SVPD_SUPPORTED_PAGES_SIZE) { + page_list->list[page_list->length] = SVPD_UNIT_SERIAL_NUMBER; + page_list->length++; + } + } xpt_done(ccb); break;