From owner-svn-src-head@FreeBSD.ORG Fri Feb 27 19:27:33 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 A80E91065676; Fri, 27 Feb 2009 19:27:33 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7C7AB8FC1A; Fri, 27 Feb 2009 19:27:33 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1RJRXdR080796; Fri, 27 Feb 2009 19:27:33 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1RJRXWZ080795; Fri, 27 Feb 2009 19:27:33 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <200902271927.n1RJRXWZ080795@svn.freebsd.org> From: Alexander Motin Date: Fri, 27 Feb 2009 19:27:33 +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: r189119 - head/sys/dev/ata 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, 27 Feb 2009 19:27:34 -0000 Author: mav Date: Fri Feb 27 19:27:33 2009 New Revision: 189119 URL: http://svn.freebsd.org/changeset/base/189119 Log: Merge rev. 188615, 188812 changes from old-USB to USB2 driver. Modified: head/sys/dev/ata/ata-usb.c Modified: head/sys/dev/ata/ata-usb.c ============================================================================== --- head/sys/dev/ata/ata-usb.c Fri Feb 27 19:26:23 2009 (r189118) +++ head/sys/dev/ata/ata-usb.c Fri Feb 27 19:27:33 2009 (r189119) @@ -322,6 +322,7 @@ atausb2_attach(device_t dev) struct usb2_interface_descriptor *id; const char *proto, *subclass; struct usb2_device_request request; + device_t child; uint16_t i; uint8_t maxlun; uint8_t has_intr; @@ -413,11 +414,11 @@ atausb2_attach(device_t dev) /* ata channels are children to this USB control device */ for (i = 0; i <= sc->maxlun; i++) { - if (!device_add_child(sc->dev, "ata", - devclass_find_free_unit(ata_devclass, 2))) { - device_printf(sc->dev, "failed to attach ata child device\n"); - goto detach; - } + if ((child = device_add_child(sc->dev, "ata", + devclass_find_free_unit(ata_devclass, 2))) == NULL) { + device_printf(sc->dev, "failed to add ata child device\n"); + } else + device_set_ivars(child, (void *)(intptr_t)i); } bus_generic_attach(sc->dev); @@ -957,23 +958,10 @@ ata_usbchannel_end_transaction(struct at static int ata_usbchannel_probe(device_t dev) { - struct ata_channel *ch = device_get_softc(dev); - device_t *children; - int count, i; char buffer[32]; - /* take care of green memory */ - bzero(ch, sizeof(struct ata_channel)); - - /* find channel number on this controller */ - if (!device_get_children(device_get_parent(dev), &children, &count)) { - for (i = 0; i < count; i++) { - if (children[i] == dev) - ch->unit = i; - } - free(children, M_TEMP); - } - snprintf(buffer, sizeof(buffer), "USB lun %d", ch->unit); + snprintf(buffer, sizeof(buffer), "USB lun %d", + (int)(intptr_t)device_get_ivars(dev)); device_set_desc_copy(dev, buffer); return (0); @@ -984,8 +972,13 @@ ata_usbchannel_attach(device_t dev) { struct ata_channel *ch = device_get_softc(dev); + if (ch->attached) + return (0); + ch->attached = 1; + /* initialize the softc basics */ ch->dev = dev; + ch->unit = (intptr_t)device_get_ivars(dev); ch->state = ATA_IDLE; ch->hw.begin_transaction = ata_usbchannel_begin_transaction; ch->hw.end_transaction = ata_usbchannel_end_transaction; @@ -1015,6 +1008,10 @@ ata_usbchannel_detach(device_t dev) device_t *children; int nchildren, i; + if (!ch->attached) + return (0); + ch->attached = 0; + /* detach & delete all children */ if (!device_get_children(dev, &children, &nchildren)) { for (i = 0; i < nchildren; i++)