2 * Copyright (c) 2015-2016 Chelsio Communications, Inc.
4 * Written by: John Baldwin <jhb@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/systm.h>
36 #include <dev/pci/pcivar.h>
40 #include <sys/iov_schema.h>
41 #include <dev/pci/pci_iov.h>
44 #include "common/common.h"
57 {0x4000, "Chelsio T440-dbg"},
58 {0x4001, "Chelsio T420-CR"},
59 {0x4002, "Chelsio T422-CR"},
60 {0x4003, "Chelsio T440-CR"},
61 {0x4004, "Chelsio T420-BCH"},
62 {0x4005, "Chelsio T440-BCH"},
63 {0x4006, "Chelsio T440-CH"},
64 {0x4007, "Chelsio T420-SO"},
65 {0x4008, "Chelsio T420-CX"},
66 {0x4009, "Chelsio T420-BT"},
67 {0x400a, "Chelsio T404-BT"},
68 {0x400e, "Chelsio T440-LP-CR"},
70 {0x5000, "Chelsio T580-dbg"},
71 {0x5001, "Chelsio T520-CR"}, /* 2 x 10G */
72 {0x5002, "Chelsio T522-CR"}, /* 2 x 10G, 2 X 1G */
73 {0x5003, "Chelsio T540-CR"}, /* 4 x 10G */
74 {0x5007, "Chelsio T520-SO"}, /* 2 x 10G, nomem */
75 {0x5009, "Chelsio T520-BT"}, /* 2 x 10GBaseT */
76 {0x500a, "Chelsio T504-BT"}, /* 4 x 1G */
77 {0x500d, "Chelsio T580-CR"}, /* 2 x 40G */
78 {0x500e, "Chelsio T540-LP-CR"}, /* 4 x 10G */
79 {0x5010, "Chelsio T580-LP-CR"}, /* 2 x 40G */
80 {0x5011, "Chelsio T520-LL-CR"}, /* 2 x 10G */
81 {0x5012, "Chelsio T560-CR"}, /* 1 x 40G, 2 x 10G */
82 {0x5014, "Chelsio T580-LP-SO-CR"}, /* 2 x 40G, nomem */
83 {0x5015, "Chelsio T502-BT"}, /* 2 x 1G */
85 {0x5004, "Chelsio T520-BCH"},
86 {0x5005, "Chelsio T540-BCH"},
87 {0x5006, "Chelsio T540-CH"},
88 {0x5008, "Chelsio T520-CX"},
89 {0x500b, "Chelsio B520-SR"},
90 {0x500c, "Chelsio B504-BT"},
91 {0x500f, "Chelsio Amsterdam"},
92 {0x5013, "Chelsio T580-CHR"},
95 {0x6001, "Chelsio T6225-CR"}, /* 2 x 10/25G */
96 {0x6002, "Chelsio T6225-SO-CR"}, /* 2 x 10/25G, nomem */
97 {0x6007, "Chelsio T62100-LP-CR"}, /* 2 x 40/50/100G */
98 {0x6008, "Chelsio T62100-SO-CR"}, /* 2 x 40/50/100G, nomem */
99 {0x600d, "Chelsio T62100-CR"}, /* 2 x 40/50/100G */
102 static int t4iov_attach_child(device_t dev);
105 t4iov_probe(device_t dev)
110 if (pci_get_vendor(dev) != PCI_VENDOR_ID_CHELSIO)
113 d = pci_get_device(dev);
114 for (i = 0; i < nitems(t4iov_pciids); i++) {
115 if (d == t4iov_pciids[i].device) {
116 device_set_desc(dev, t4iov_pciids[i].desc);
118 return (BUS_PROBE_DEFAULT);
125 t5iov_probe(device_t dev)
130 if (pci_get_vendor(dev) != PCI_VENDOR_ID_CHELSIO)
133 d = pci_get_device(dev);
134 for (i = 0; i < nitems(t5iov_pciids); i++) {
135 if (d == t5iov_pciids[i].device) {
136 device_set_desc(dev, t5iov_pciids[i].desc);
138 return (BUS_PROBE_DEFAULT);
145 t6iov_probe(device_t dev)
150 if (pci_get_vendor(dev) != PCI_VENDOR_ID_CHELSIO)
153 d = pci_get_device(dev);
154 for (i = 0; i < nitems(t6iov_pciids); i++) {
155 if (d == t6iov_pciids[i].device) {
156 device_set_desc(dev, t6iov_pciids[i].desc);
158 return (BUS_PROBE_DEFAULT);
165 t4iov_attach(device_t dev)
167 struct t4iov_softc *sc;
169 sc = device_get_softc(dev);
172 sc->sc_main = pci_find_dbsf(pci_get_domain(dev), pci_get_bus(dev),
173 pci_get_slot(dev), 4);
174 if (sc->sc_main == NULL)
176 if (T4_IS_MAIN_READY(sc->sc_main) == 0)
177 return (t4iov_attach_child(dev));
182 t4iov_attach_child(device_t dev)
184 struct t4iov_softc *sc;
186 nvlist_t *pf_schema, *vf_schema;
191 sc = device_get_softc(dev);
192 MPASS(!sc->sc_attached);
195 * PF0-3 are associated with a specific port on the NIC (PF0
196 * with port 0, etc.). Ask the PF4 driver for the device for
197 * this function's associated port to determine if the port is
200 error = T4_READ_PORT_DEVICE(sc->sc_main, pci_get_function(dev), &pdev);
205 pf_schema = pci_iov_schema_alloc_node();
206 vf_schema = pci_iov_schema_alloc_node();
207 error = pci_iov_attach_name(dev, pf_schema, vf_schema, "%s",
208 device_get_nameunit(pdev));
210 device_printf(dev, "Failed to initialize SR-IOV: %d\n", error);
215 sc->sc_attached = true;
220 t4iov_detach_child(device_t dev)
222 struct t4iov_softc *sc;
227 sc = device_get_softc(dev);
228 if (!sc->sc_attached)
232 error = pci_iov_detach(dev);
234 device_printf(dev, "Failed to disable SR-IOV\n");
239 sc->sc_attached = false;
244 t4iov_detach(device_t dev)
246 struct t4iov_softc *sc;
249 sc = device_get_softc(dev);
250 if (sc->sc_attached) {
251 error = t4iov_detach_child(dev);
260 t4iov_iov_init(device_t dev, uint16_t num_vfs, const struct nvlist *config)
263 /* XXX: The Linux driver sets up a vf_monitor task on T4 adapters. */
268 t4iov_iov_uninit(device_t dev)
273 t4iov_add_vf(device_t dev, uint16_t vfnum, const struct nvlist *config)
280 static device_method_t t4iov_methods[] = {
281 DEVMETHOD(device_probe, t4iov_probe),
282 DEVMETHOD(device_attach, t4iov_attach),
283 DEVMETHOD(device_detach, t4iov_detach),
286 DEVMETHOD(pci_iov_init, t4iov_iov_init),
287 DEVMETHOD(pci_iov_uninit, t4iov_iov_uninit),
288 DEVMETHOD(pci_iov_add_vf, t4iov_add_vf),
291 DEVMETHOD(t4_attach_child, t4iov_attach_child),
292 DEVMETHOD(t4_detach_child, t4iov_detach_child),
297 static driver_t t4iov_driver = {
300 sizeof(struct t4iov_softc)
303 static device_method_t t5iov_methods[] = {
304 DEVMETHOD(device_probe, t5iov_probe),
305 DEVMETHOD(device_attach, t4iov_attach),
306 DEVMETHOD(device_detach, t4iov_detach),
309 DEVMETHOD(pci_iov_init, t4iov_iov_init),
310 DEVMETHOD(pci_iov_uninit, t4iov_iov_uninit),
311 DEVMETHOD(pci_iov_add_vf, t4iov_add_vf),
314 DEVMETHOD(t4_attach_child, t4iov_attach_child),
315 DEVMETHOD(t4_detach_child, t4iov_detach_child),
320 static driver_t t5iov_driver = {
323 sizeof(struct t4iov_softc)
326 static device_method_t t6iov_methods[] = {
327 DEVMETHOD(device_probe, t6iov_probe),
328 DEVMETHOD(device_attach, t4iov_attach),
329 DEVMETHOD(device_detach, t4iov_detach),
332 DEVMETHOD(pci_iov_init, t4iov_iov_init),
333 DEVMETHOD(pci_iov_uninit, t4iov_iov_uninit),
334 DEVMETHOD(pci_iov_add_vf, t4iov_add_vf),
337 DEVMETHOD(t4_attach_child, t4iov_attach_child),
338 DEVMETHOD(t4_detach_child, t4iov_detach_child),
343 static driver_t t6iov_driver = {
346 sizeof(struct t4iov_softc)
349 static devclass_t t4iov_devclass, t5iov_devclass, t6iov_devclass;
351 DRIVER_MODULE(t4iov, pci, t4iov_driver, t4iov_devclass, 0, 0);
352 MODULE_VERSION(t4iov, 1);
354 DRIVER_MODULE(t5iov, pci, t5iov_driver, t5iov_devclass, 0, 0);
355 MODULE_VERSION(t5iov, 1);
357 DRIVER_MODULE(t6iov, pci, t6iov_driver, t6iov_devclass, 0, 0);
358 MODULE_VERSION(t6iov, 1);