156896Sfenner/* $FreeBSD: stable/11/stand/usb/storage/umass_common.c 291401 2015-11-27 18:16:10Z zbb $ */
275119Sfenner/*-
356896Sfenner * Copyright (c) 2014 Hans Petter Selasky <hselasky@FreeBSD.org>
456896Sfenner * All rights reserved.
556896Sfenner *
656896Sfenner * This software was developed by SRI International and the University of
756896Sfenner * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
856896Sfenner * ("CTSRD"), as part of the DARPA CRASH research programme.
956896Sfenner *
1056896Sfenner * Redistribution and use in source and binary forms, with or without
1156896Sfenner * modification, are permitted provided that the following conditions
1256896Sfenner * are met:
1356896Sfenner * 1. Redistributions of source code must retain the above copyright
1456896Sfenner *    notice, this list of conditions and the following disclaimer.
1556896Sfenner * 2. Redistributions in binary form must reproduce the above copyright
1656896Sfenner *    notice, this list of conditions and the following disclaimer in the
1756896Sfenner *    documentation and/or other materials provided with the distribution.
1856896Sfenner *
1956896Sfenner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2056896Sfenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2156896Sfenner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2256896Sfenner * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2356896Sfenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2475119Sfenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2575119Sfenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2675119Sfenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2756896Sfenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2856896Sfenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2956896Sfenner * SUCH DAMAGE.
3056896Sfenner */
3156896Sfenner
3275119Sfenner#include USB_GLOBAL_INCLUDE_FILE
3356896Sfenner
3456896Sfenner#include "umass_common.h"
3575119Sfenner
3656896Sfennerstruct usb_attach_arg umass_uaa;
3756896Sfenner
3856896Sfennerstatic device_probe_t umass_probe;
3956896Sfennerstatic device_attach_t umass_attach;
4056896Sfennerstatic device_detach_t umass_detach;
4156896Sfenner
4256896Sfennerstatic devclass_t umass_devclass;
4356896Sfenner
4456896Sfennerstatic device_method_t umass_methods[] = {
4556896Sfenner	/* Device interface */
4656896Sfenner	DEVMETHOD(device_probe, umass_probe),
4756896Sfenner	DEVMETHOD(device_attach, umass_attach),
4856896Sfenner	DEVMETHOD(device_detach, umass_detach),
4956896Sfenner
5056896Sfenner	DEVMETHOD_END
5156896Sfenner};
5256896Sfenner
5356896Sfennerstatic driver_t umass_driver = {
5456896Sfenner	.name = "umass",
5556896Sfenner	.methods = umass_methods,
5656896Sfenner};
5756896Sfenner
5856896SfennerDRIVER_MODULE(umass, uhub, umass_driver, umass_devclass, NULL, 0);
5956896Sfenner
6056896Sfennerstatic int
6156896Sfennerumass_probe(device_t dev)
6256896Sfenner{
6356896Sfenner	struct usb_attach_arg *uaa = device_get_ivars(dev);
6498528Sfenner
6598528Sfenner	if (uaa->usb_mode != USB_MODE_HOST ||
6675119Sfenner	    uaa->info.bInterfaceClass != UICLASS_MASS ||
6756896Sfenner	    uaa->info.bInterfaceSubClass != UISUBCLASS_SCSI ||
6856896Sfenner	    uaa->info.bInterfaceProtocol != UIPROTO_MASS_BBB ||
6956896Sfenner	    device_get_unit(dev) != 0)
7056896Sfenner		return (ENXIO);
7156896Sfenner	return (0);
7256896Sfenner}
7356896Sfenner
7456896Sfennerstatic int
7556896Sfennerumass_attach(device_t dev)
7656896Sfenner{
7756896Sfenner	struct usb_attach_arg *uaa = device_get_ivars(dev);
7856896Sfenner	umass_uaa = *uaa;
7956896Sfenner	return (0);			/* success */
8056896Sfenner}
8156896Sfenner
8256896Sfennerstatic int
8356896Sfennerumass_detach(device_t dev)
8456896Sfenner{
8556896Sfenner
8656896Sfenner#ifdef USB_DEBUG
8756896Sfenner	memset(&umass_uaa, 0, sizeof(umass_uaa));
8856896Sfenner#endif
8956896Sfenner	return (0);
9098528Sfenner}
9198528Sfenner