1/*-
2 * Copyright (c) 2010 Juli Mallett <jmallett@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29/*
30 * Cavium Octeon Ethernet pseudo-bus attachment.
31 */
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/bus.h>
36#include <sys/endian.h>
37#include <sys/kernel.h>
38#include <sys/mbuf.h>
39#include <sys/lock.h>
40#include <sys/module.h>
41#include <sys/mutex.h>
42#include <sys/rman.h>
43#include <sys/socket.h>
44#include <sys/sockio.h>
45#include <sys/sysctl.h>
46
47#include "ethernet-common.h"
48
49#include "octebusvar.h"
50
51static void		octebus_identify(driver_t *drv, device_t parent);
52static int		octebus_probe(device_t dev);
53static int		octebus_attach(device_t dev);
54static int		octebus_detach(device_t dev);
55static int		octebus_shutdown(device_t dev);
56
57static device_method_t octebus_methods[] = {
58	/* Device interface */
59	DEVMETHOD(device_identify,	octebus_identify),
60	DEVMETHOD(device_probe,		octebus_probe),
61	DEVMETHOD(device_attach,	octebus_attach),
62	DEVMETHOD(device_detach,	octebus_detach),
63	DEVMETHOD(device_shutdown,	octebus_shutdown),
64
65	/* Bus interface.  */
66	DEVMETHOD(bus_add_child,	bus_generic_add_child),
67
68	{ 0, 0 }
69};
70
71static driver_t octebus_driver = {
72	"octebus",
73	octebus_methods,
74	sizeof (struct octebus_softc),
75};
76
77static devclass_t octebus_devclass;
78
79DRIVER_MODULE(octebus, ciu, octebus_driver, octebus_devclass, 0, 0);
80
81static void
82octebus_identify(driver_t *drv, device_t parent)
83{
84	BUS_ADD_CHILD(parent, 0, "octebus", 0);
85}
86
87static int
88octebus_probe(device_t dev)
89{
90	if (device_get_unit(dev) != 0)
91		return (ENXIO);
92	device_set_desc(dev, "Cavium Octeon Ethernet pseudo-bus");
93	return (0);
94}
95
96static int
97octebus_attach(device_t dev)
98{
99	struct octebus_softc *sc;
100	int rv;
101
102	sc = device_get_softc(dev);
103	sc->sc_dev = dev;
104
105	rv = cvm_oct_init_module(dev);
106	if (rv != 0)
107		return (ENXIO);
108
109	return (0);
110}
111
112static int
113octebus_detach(device_t dev)
114{
115	cvm_oct_cleanup_module(dev);
116	return (0);
117}
118
119static int
120octebus_shutdown(device_t dev)
121{
122	return (octebus_detach(dev));
123}
124