From patchwork Thu Oct 8 16:14:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 35502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B5F15B70B3 for ; Fri, 9 Oct 2009 04:52:31 +1100 (EST) Received: from localhost ([127.0.0.1]:36291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvxAB-0005eE-Nk for incoming@patchwork.ozlabs.org; Thu, 08 Oct 2009 13:52:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mvvdd-0006DZ-Cz for qemu-devel@nongnu.org; Thu, 08 Oct 2009 12:14:45 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvvdY-00065b-7K for qemu-devel@nongnu.org; Thu, 08 Oct 2009 12:14:44 -0400 Received: from [199.232.76.173] (port=58449 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvvdX-00065L-LJ for qemu-devel@nongnu.org; Thu, 08 Oct 2009 12:14:39 -0400 Received: from mail-gx0-f210.google.com ([209.85.217.210]:57814) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MvvdX-0005oI-Bn for qemu-devel@nongnu.org; Thu, 08 Oct 2009 12:14:39 -0400 Received: by gxk2 with SMTP id 2so862845gxk.4 for ; Thu, 08 Oct 2009 09:14:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=EYF1M3FlD8/VJts2ZHKapT+a3Pc3cuXANMK/nHQ54Xg=; b=rZBRo2e3ThLEreKdqkQTaufT5ZDhwGFhvo4z4tMfULK0feYIW1ReQpk9iIDMRhpnph G5eaaswZTws0tx5EksjFViNquY5AKQmVKXT6NH1bvu7fgylFPr5Qh0qWvMD4MzpgPAID tLTmTSYlQi68oWUL1oBolRMgnGKPt8jRxQe1Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=oLyun+QVRJsV7OsMGdyx2v2KLYmmbjaqjg7L/bR+m5gvrrMy8H/vrbBCOcHq8/DXFR FHWJl0c8VPkxsL6y/mnYElbYEMSog+aq/mzM5n04WdVTN+AEF1rNHeaFihssUfFqoVKe SE3ubS5450EkMqT7IuKhQIxLCysEsUo58pUr4= MIME-Version: 1.0 Received: by 10.91.178.19 with SMTP id f19mr843798agp.33.1255018477098; Thu, 08 Oct 2009 09:14:37 -0700 (PDT) In-Reply-To: References: From: Artyom Tarasenko Date: Thu, 8 Oct 2009 18:14:16 +0200 Message-ID: Subject: Re: [Qemu-devel] Re: sparc esp NetBSD-guest "sd3: mode sense (4) returned nonsense" To: Blue Swirl X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 2009/9/23 Artyom Tarasenko : > 2009/9/19 Blue Swirl : >> On Fri, Sep 18, 2009 at 8:26 PM, Artyom Tarasenko >> wrote: >>> 2009/9/14 Blue Swirl : >>>> On Mon, Sep 14, 2009 at 7:47 PM, Artyom Tarasenko >>>> wrote: >>>>> 2009/9/14 Blue Swirl : >>>>>> On Mon, Sep 14, 2009 at 7:29 PM, Artyom Tarasenko >>>>>> wrote: >>>>>>> 2009/9/14 Blue Swirl : >>>>>>>> On Mon, Sep 14, 2009 at 12:32 AM, Artyom Tarasenko >>>>>>>> wrote: >>>>>>>>> From NetBSD source, it looks like HDD geometry detection should work >>>>>>>>> under qemu: they call "mode sense" and "read capacity", and both >>>>>>>>> commands are implemented in qemu's hw/scsi-disk.h. It doesn't work >>>>>>>>> though, so NetBSD has to fabricate a disk geometry. >>>>>>>>> >>>>>>>>> To make debugging easier I tried to boot an older version - NetBSD >>>>>>>>> 1.3.3. And put some extra debugging in esp.c: >>>>>>>>> >>>>>>>>> static uint32_t get_cmd(ESPState *s, uint8_t *buf) >>>>>>>>> { >>>>>>>>>    uint32_t dmalen; >>>>>>>>>    int target; >>>>>>>>> >>>>>>>>>    target = s->wregs[ESP_WBUSID] & BUSID_DID; >>>>>>>>>    if (s->dma) { >>>>>>>>>        dmalen = s->rregs[ESP_TCLO] | (s->rregs[ESP_TCMID] << 8); >>>>>>>>>        s->dma_memory_read(s->dma_opaque, buf, dmalen); >>>>>>>>>    } else { >>>>>>>>>        dmalen = s->ti_size; >>>>>>>>>        memcpy(buf, s->ti_buf, dmalen); >>>>>>>>> printf("NON-DMA rptr %d, wptr %d %2x (0) %2x %2x %2x %2x\n", >>>>>>>>> s->ti_rptr, s-> ti_wptr, buf[0],buf[1], buf[2],buf[3], buf[4]); >>>>>>>>>        buf[0] = 0; >>>>>>>>>    } >>>>>>>>> >>>>>>>>> qemu-system-sparc -M SS-20 -nographic  -hda ~/sparc/miniroot-133.fs -m 64 >>>>>>>>> ... >>>>>>>>> NON-DMA rptr 0, wptr 1 c0 (0)  0  0 1a  0 >>>>>>>>> Set ATN & Stop: cmdlen 3 >>>>>>>>> scsi-disk: Command: lun=0 tag=0x0 data=0x00 0x00 0x1a 0x00 0x04 0x00 >>>>>>>>> scsi-disk: Test Unit Ready >>>>>>>>> scsi-disk: Command complete tag=0x0 status=0 sense=0 >>>>>>>>> sd3: mode sense (4) returned nonsense; using fictitious geometry >>>>>>>>> >>>>>>>>> >>>>>>>>> NetBSD sent command "0x1a" via Set ATN & Stop, but it for some reason >>>>>>>>> the command got padded and disk got "0x0 0x0 0x1a", no wonder that its >>>>>>>>> output looks like a non-sense to NetBSD. >>>>>>>>> >>>>>>>>> Any ideas why does it happen? >>>>>>>>> >>>>>>>> >>>>>>>> The problem could be in the DMA (sparc32_dma.c), or incorrect >>>>>>>> programming of DMA or IOMMU DVMA by NetBSD, (or bug in iommu.c). >>>>>>> >>>>>>> Why DMA? It hits the else branch of "if (s->dma)". Does the command >>>>>>> still get in via DMA? >>>>>> >>>>>> Sorry, I missed that. But is the response also read without DMA? >>>>>> >>>>> >>>>> You mean the disk's response? It doesn't matter, because the disk just >>>>> doesn't get the command. >>>> >>>> Ah, I see. What about FIFO state then, perhaps there are some leftover >>>> bytes (0, 0 could be status + sense?) from the previous command in the >>>> buffer before the command is written there? >>> >>> You were right, it was FIFO, but I ran the tests in a wrong qemu >>> branch. It's sort of funny, because the bug was fixed in the HEAD by >>> my own patch (the "Message accepted" patch). >>> >>> Now the disk gets commands properly, but NetBSD still complains about >>> getting nonsense. >>> >>> One of the reasons is, the disk's geometry has to be explicitly >>> specified via -hdachs , but >>> >>>> But is the response also read without DMA? >>> >>> you are right about this one too. It is read via DMA, and it seems >>> that the response gets shifted by -8 bytes: >>> the follofing hack in hw/sparc32_dma.c makes NetBSD to recognize the geometry: >> >> Could be a bug in the DMA controller. For example, the feature for >> automatic load of next address is not implemented. IIRC it's not >> available in all versions, so downgrading the controller version may >> help. > > Downgrading the controller version didn't change anything. I also > tried to boot with -M LX , to downgrade other components as well, the > result was still the same. > > But this brings me to another question: Is there a reason for silent > catching of errors produced by unimplemented features? > > I like the way it is implenented in hw/scsi-disk.c: along with DPRINTF > for debugging there is a BADF for reporting unimplemented/unexpected > cases. DPRINTFs may be turned on by a #define, and BADFs are always > on. Shouldn't similar constructs were used for mmu, iommu and other > units with partially implemented funcionality? Actually, scsi-disk.c doesn't implement block descriptor for mode pages. The SCSI-2 documentation suggests, that although the block descriptor is optional for an arbitrary SCSI-2 device (chapter 8.2.10, http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2/SCSI2-08.html ) it is mandatory for a disk: chapters 9.1.2, 9.3.3 ( http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-09.html ) don't say "optional" any more, just "The block descriptor in the MODE SENSE data describes the block lengths that are used on the medium." NetBSD expects that the block descriptor is always there: sd.c: struct scsi_mode_sense_data { struct scsi_mode_header header; struct scsi_blk_desc blk_desc; union scsi_disk_pages pages; }; Shall we implement the block descriptor? We can start with the following, which fixes NetBSD geometry detection. Shall I post it as a patch? And there is one more problem regarding the disk geometry. The "-hdachs" command line switch's sanity check seems to be IDE-specific: for instance it doesn't accept "-hdachs 6,64,32". Is there an alternative way to specify the SCSI disk geometry? Signed-off-by: Artyom Tarasenko --- p = outbuf; @@ -635,7 +637,25 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, outbuf[2] = 0x80; /* Readonly. */ } p += 4; - if (page == 4) { + bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors); + if ((~dbd) & nb_sectors) { + nb_sectors /= s->cluster_size; + if (nb_sectors > UINT32_MAX) + nb_sectors = UINT32_MAX; + nb_sectors--; + outbuf[3] = 8; /* Block descriptor length. */ + p[0] = 0; + p[1] = (nb_sectors >> 16) & 0xff; + p[2] = (nb_sectors >> 8) & 0xff; + p[3] = nb_sectors & 0xff; + p[4] = 0; /* reserved */ + p[5] = 0; /* bytes 5-7 are the sector size in bytes */ + p[6] = s->cluster_size * 2; + p[7] = 0; + p += 8; + } + + if (page == 4 ) { diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 3940726..9041902 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, { uint8_t *p; int page; - + int dbd; + + dbd = buf[1] & 0x8; page = buf[2] & 0x3f; DPRINTF("Mode Sense (page %d, len %d)\n", page, len);