From owner-freebsd-scsi@freebsd.org Mon Jan 30 18:13:43 2017 Return-Path: Delivered-To: freebsd-scsi@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C5464CC8062 for ; Mon, 30 Jan 2017 18:13:43 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: from mail-yb0-x22f.google.com (mail-yb0-x22f.google.com [IPv6:2607:f8b0:4002:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 938D318DF for ; Mon, 30 Jan 2017 18:13:43 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: by mail-yb0-x22f.google.com with SMTP id j82so99436937ybg.1 for ; Mon, 30 Jan 2017 10:13:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuffli-net.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=vxVY60me/Xi4REJLYrmzMl46hUfyoX5uRJm17l0hZbQ=; b=wbPHgqRvpQaaKZlqlY6fRiOQD5WT/0KMjtC8zOZQz8vkfRi1yDn8CTjSySvPTO5Ocy rikHM+4PvZpeARCb0c6RYOIAOt2r+YL+EtsHdMM8vjzZCsiQpGrvNaRm1DkKDcfxwhYt HCUfcMmR2jsA8Nlv9MH0U/RZb79MEKqTKskWWRlQkTuaq4jewODr/qAHbhs7VsRn95sC Iavx1UrQHkVnVuz2wbrwlRrtT44hzwTEC+UDobnb/jRi4CaPwbpW0GafwwNDqVGKitd+ tRtvVVL13eLuFH6uT1gRrU3zA4llmH5Z0WC3wsgp0tZq6xp98IzVk/Il5ZlSgfYesnlx GQuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=vxVY60me/Xi4REJLYrmzMl46hUfyoX5uRJm17l0hZbQ=; b=qySIFkTT7heamH1diOPyuQ8DLCSZ5NIjZZVJHdejkS9F6PSGzvnE4w1bu1aSD+gB3s bvg8vtsH4k78xwsWIDmY6b06TNCkyF5yp0XrqAxcL0hNjCPz9XZ7qMiDrB0dW+al9bTH yK6iVaoxrU9mD8WyQ7kNxGhixTSQ45FbYxDIUyFgwlPpxcxOmfoGx9qXDqxqEQWKMPFu f+kgvgG1CGRQZFs5LO+n88BwcrCvbXuWqm3Jf3SaYGZ8+90Pf9p6cwsT4f81HjofQB4p vXgEj4adiM4JTxgQFtgHToxH25Mk3+mwPZv7aus1x4/k0UkpkNPJUizMkHG1d99fiCBY 7wkA== X-Gm-Message-State: AIkVDXIW/ZLrl3lm5jE3kTF7Fy9ICJQIqvY5yIf5QhKE/3cSops/L3iti7vPTZWf03dXxD3sjXP90Gd4RpJaLg== X-Received: by 10.37.208.150 with SMTP id h144mr11665945ybg.154.1485800022644; Mon, 30 Jan 2017 10:13:42 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.167.74 with HTTP; Mon, 30 Jan 2017 10:13:42 -0800 (PST) From: Chuck Tuffli Date: Mon, 30 Jan 2017 10:13:42 -0800 Message-ID: Subject: how to determine protocol of USB devices To: freebsd-scsi Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jan 2017 18:13:43 -0000 I'm trying to use CAM to determine the protocol specific command to send to a given device (e.g. Inquiry for SCSI devices or Identify for SATA devices). The code works for direct attached SCSI/SATA devices, but I'm not sure what to do with USB attached devices and could use some advice. The current code sends a XPT_GET_TRAN_SETTINGS and uses the returned protocol field in the ccb_trans_settings structure. But for SATA drives connected via USB, the protocol is SCSI. Is there a way via CAM to determine that the drive is actually SATA? TIA. --chuck From owner-freebsd-scsi@freebsd.org Tue Jan 31 02:41:50 2017 Return-Path: Delivered-To: freebsd-scsi@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 90C20CC9612 for ; Tue, 31 Jan 2017 02:41:50 +0000 (UTC) (envelope-from ken@kdm.org) Received: from mithlond.kdm.org (mithlond.kdm.org [96.89.93.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "A1-33714", Issuer "A1-33714" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B926A62 for ; Tue, 31 Jan 2017 02:41:50 +0000 (UTC) (envelope-from ken@kdm.org) Received: from mithlond.kdm.org (localhost [127.0.0.1]) by mithlond.kdm.org (8.15.2/8.14.9) with ESMTPS id v0V2ff2T026887 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 30 Jan 2017 21:41:41 -0500 (EST) (envelope-from ken@mithlond.kdm.org) Received: (from ken@localhost) by mithlond.kdm.org (8.15.2/8.14.9/Submit) id v0V2ffip026886; Mon, 30 Jan 2017 21:41:41 -0500 (EST) (envelope-from ken) Date: Mon, 30 Jan 2017 21:41:41 -0500 From: "Kenneth D. Merry" To: Chuck Tuffli Cc: freebsd-scsi Subject: Re: how to determine protocol of USB devices Message-ID: <20170131024141.GA26604@mithlond.kdm.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (mithlond.kdm.org [127.0.0.1]); Mon, 30 Jan 2017 21:41:41 -0500 (EST) X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on mithlond.kdm.org X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jan 2017 02:41:50 -0000 On Mon, Jan 30, 2017 at 10:13:42 -0800, Chuck Tuffli wrote: > I'm trying to use CAM to determine the protocol specific command to > send to a given device (e.g. Inquiry for SCSI devices or Identify for > SATA devices). The code works for direct attached SCSI/SATA devices, > but I'm not sure what to do with USB attached devices and could use > some advice. > > The current code sends a XPT_GET_TRAN_SETTINGS and uses the returned > protocol field in the ccb_trans_settings structure. But for SATA > drives connected via USB, the protocol is SCSI. Is there a way via CAM > to determine that the drive is actually SATA? TIA. I had a similar issue for camcontrol when I was working on the firmware download code. For SATA drives behind SAS controllers, I wanted to send the ATA DOWNLOAD MICROCODE command via SCSI passthrough instead of relying on the SAT layer to properly translate the various WRITE BUFFER modes. So, look at get_device_type() in sbin/camcontrol/camcontrol.c. First, it gets the protocol of the device. For ATA, it is straightforward. For SCSI, it checks for the existence VPD page 0x89. That is defined in the SAT spec, and has to be there for a compliant SAT device. If it's there, then we have an ATA device behind a SAT layer. I don't know whether USB mass storage devices follow the SAT spec as far as translation from SCSI to ATA. If they do, you could use that method. If they generally support the SCSI ATA PASS-THROUGH command, you could try using that to send an ATA Identify command down. If you get an Illegal Opcode ASC/ASCQ back, you've got the answer. If it is a SATA device, it should return Identify data. In sbin/camcontrol/fwdownload.c I also use build_ata_cmd() (from camcontrol.c) that allows composing one function call that then composes either an XPT_ATA_IO or XPT_SCSI_IO CCB with the appropriate registers or CDB. That might be helpful if USB devices do support the ATA PASS-THROUGH command. That code might eventually move over to libcam, but I thought it might be good to give it a little time before locking down the API. The underlying components are there, though (cam_fill_ataio() and scsi_ata_pass()). I'm curious to hear what your solution is once you figure it out. It would be good to know as far as generically supporting USB devices for things like firmware downloads. (I don't know much about USB storage.) Ken -- Kenneth Merry ken@FreeBSD.ORG From owner-freebsd-scsi@freebsd.org Tue Jan 31 23:41:11 2017 Return-Path: Delivered-To: freebsd-scsi@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B2C8CCAC28 for ; Tue, 31 Jan 2017 23:41:11 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: from mail-yb0-x229.google.com (mail-yb0-x229.google.com [IPv6:2607:f8b0:4002:c09::229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 550ED901 for ; Tue, 31 Jan 2017 23:41:11 +0000 (UTC) (envelope-from chuck@tuffli.net) Received: by mail-yb0-x229.google.com with SMTP id o65so47523161ybo.2 for ; Tue, 31 Jan 2017 15:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuffli-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GwQ437s5oqH7J3p3OpJUIJLGMeDfH45LfVCPBoXa3Lo=; b=JKQKkew22pR0xwrgnSH8b9ZqXNFMqx6JOK+3hj3YC+XJzjSakcOmQPvfGoFB00FR7y iDBCS98BYi1y++SMbx93i2rFLBK6Szh1zYSLhYHHQNU2Wqb3iQgDmaIwmb9tIStmv6mh DLxe/FUCA/w/BP6BPHPZTD+7WwgCHTZsP7XWwC0PGTyZWFF8ZIKo9uojJOqdmPXn54zm bn81yPrww3Kr4iYYMtko0o5MfWEPfYJYGmEpxGkCjHtGzunJrFpGF+V8+PYHLLfG4tEh 09GcU63fg1srXORRJ/Cth8KWqSZHTdgzb7GTvpBjmxOMB81q2fKa8S19bgllJRK1kBtc syiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GwQ437s5oqH7J3p3OpJUIJLGMeDfH45LfVCPBoXa3Lo=; b=NrwqV2wzOggaz2cM4J1Jz0uO9dKhIJ/7cq0OibCpT6EXUbXWAE4BqfvQPG/JqSXrtj 6u744haDMCOsGQyuzhVlAyKFDSgxQJ267UGKwtpo16L/ahlBQAvYge5wUHioOgU93ZzF Nd7zQj05LddFN6TMRkTmamBurBoki4XgUFaBf3apuawpBCNnRlW863PAIuzWSMiPM+dr OwMVITh+GEHd+CG+NlAoDht8hmK+Il0ZxkHsSGi+XhIVVGfGGPczp0hKd5LIKObH4EGo ncN0s69doJ+qp/fZX8OMGBPd57IRe6jknG68A1ctRty9S7gAy0m4jHsBI+pFgznlr+7k BzvA== X-Gm-Message-State: AIkVDXLwqUW9VyUfSJsjGSjrT9oPwJyAQxixChV8DgNd+2p4pbqFzs4sopRVDgq5UOmWPNxxzm7T4jurE4d6Ew== X-Received: by 10.37.208.150 with SMTP id h144mr16376226ybg.154.1485906070294; Tue, 31 Jan 2017 15:41:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.129.167.74 with HTTP; Tue, 31 Jan 2017 15:41:09 -0800 (PST) In-Reply-To: <20170131024141.GA26604@mithlond.kdm.org> References: <20170131024141.GA26604@mithlond.kdm.org> From: Chuck Tuffli Date: Tue, 31 Jan 2017 15:41:09 -0800 Message-ID: Subject: Re: how to determine protocol of USB devices To: "Kenneth D. Merry" Cc: freebsd-scsi Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jan 2017 23:41:11 -0000 On Mon, Jan 30, 2017 at 6:41 PM, Kenneth D. Merry wrote: ... > That code might eventually move over to libcam, but I thought it might be > good to give it a little time before locking down the API. The underlying > components are there, though (cam_fill_ataio() and scsi_ata_pass()). > > I'm curious to hear what your solution is once you figure it out. It would > be good to know as far as generically supporting USB devices for things > like firmware downloads. (I don't know much about USB storage.) Thanks for the pointers, Ken. I'll let you know how this turns out. --chuck