Date: Fri, 27 Feb 2009 19:27:33 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r189119 - head/sys/dev/ata Message-ID: <200902271927.n1RJRXWZ080795@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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++)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200902271927.n1RJRXWZ080795>