Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F150433196
D41440.id125963.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D41440.id125963.diff
View Options
diff --git a/sys/arm64/conf/std.nxp b/sys/arm64/conf/std.nxp
--- a/sys/arm64/conf/std.nxp
+++ b/sys/arm64/conf/std.nxp
@@ -25,6 +25,9 @@
device dpaa2 # Data Path Acceleration Architecture (2nd Gen)
device enetc # QorIQ LS1028A NIC
+# SFF/SFP
+device sff # Small Form Factor Transceivers
+
options FDT
device acpi
diff --git a/sys/conf/files b/sys/conf/files
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -3060,6 +3060,8 @@
dev/sdio/sdio_if.m optional mmccam
dev/sdio/sdio_subr.c optional mmccam
dev/sdio/sdiob.c optional mmccam
+dev/sff/sff_if.m optional sff
+dev/sff/sfp_fdt.c optional sff fdt
dev/sge/if_sge.c optional sge pci
dev/siis/siis.c optional siis pci
dev/sis/if_sis.c optional sis pci
diff --git a/sys/dev/sff/sff_if.m b/sys/dev/sff/sff_if.m
new file mode 100644
--- /dev/null
+++ b/sys/dev/sff/sff_if.m
@@ -0,0 +1,35 @@
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright © 2023 Dmitry Salychev
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+
+#include <machine/bus.h>
+
+INTERFACE sff;
+
+METHOD int get_i2c_bus {
+ device_t dev;
+ device_t *i2c_bus;
+};
diff --git a/sys/dev/sff/sfp_fdt.c b/sys/dev/sff/sfp_fdt.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/sff/sfp_fdt.c
@@ -0,0 +1,156 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright © 2023 Dmitry Salychev
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+/*
+ * Small Form Factor (SFF) Committee Pluggable (SFP) Transceiver (FDT-based).
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/module.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/fdt/simplebus.h>
+
+#include "sff_if.h"
+
+struct sfp_fdt_softc {
+ phandle_t ofw_node;
+ phandle_t i2c_bus;
+
+ phandle_t mod_def;
+ phandle_t los;
+ phandle_t tx_fault;
+ phandle_t tx_disable;
+ phandle_t rx_rate;
+ phandle_t tx_rate;
+ uint32_t max_power; /* in mW */
+};
+
+static int
+sfp_fdt_probe(device_t dev)
+{
+ phandle_t node;
+ ssize_t s;
+
+ node = ofw_bus_get_node(dev);
+ if (!ofw_bus_node_is_compatible(node, "sff,sfp")) {
+ return (ENXIO);
+ }
+
+ s = device_get_property(dev, "i2c-bus", &node, sizeof(node),
+ DEVICE_PROP_HANDLE);
+ if (s == -1) {
+ device_printf(dev, "%s: '%s' has no 'i2c-bus' property, s %zd\n",
+ __func__, ofw_bus_get_name(dev), s);
+ return (ENXIO);
+ }
+
+ device_set_desc(dev, "Small Form-factor Pluggable Transceiver");
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+sfp_fdt_attach(device_t dev)
+{
+ struct sfp_fdt_softc *sc;
+ ssize_t s;
+ int error;
+
+ sc = device_get_softc(dev);
+ sc->ofw_node = ofw_bus_get_node(dev);
+
+ s = device_get_property(dev, "i2c-bus", &sc->i2c_bus,
+ sizeof(sc->i2c_bus), DEVICE_PROP_HANDLE);
+ if (s == -1) {
+ device_printf(dev, "%s: cannot find 'i2c-bus' property: %zd\n",
+ __func__, s);
+ return (ENXIO);
+ }
+
+ /* Optional properties */
+ (void)device_get_property(dev, "mod-def0-gpios", &sc->mod_def,
+ sizeof(sc->mod_def), DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "los-gpios", &sc->los, sizeof(sc->los),
+ DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "tx-fault-gpios", &sc->tx_fault,
+ sizeof(sc->tx_fault), DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "tx-disable-gpios", &sc->tx_disable,
+ sizeof(sc->tx_disable), DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "rate-select0-gpios", &sc->rx_rate,
+ sizeof(sc->rx_rate), DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "rate-select1-gpios", &sc->tx_rate,
+ sizeof(sc->tx_rate), DEVICE_PROP_HANDLE);
+ (void)device_get_property(dev, "maximum-power-milliwatt", &sc->max_power,
+ sizeof(sc->max_power), DEVICE_PROP_UINT32);
+
+ error = OF_device_register_xref(OF_xref_from_node(sc->ofw_node), dev);
+ if (error != 0) {
+ device_printf(dev, "%s: failed to register xref %#x\n",
+ __func__, OF_xref_from_node(sc->ofw_node));
+ }
+
+ return (error);
+}
+
+static int
+sfp_fdt_get_i2c_bus(device_t dev, device_t *i2c_bus)
+{
+ struct sfp_fdt_softc *sc = device_get_softc(dev);
+ device_t xdev = OF_device_from_xref(OF_xref_from_node(sc->i2c_bus));
+
+ if (xdev != NULL) {
+ *i2c_bus = xdev;
+ return (0);
+ }
+ return (ENXIO);
+}
+
+static device_method_t sfp_fdt_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, sfp_fdt_probe),
+ DEVMETHOD(device_attach, sfp_fdt_attach),
+ DEVMETHOD(device_detach, bus_generic_detach),
+
+ /* SFF */
+ DEVMETHOD(sff_get_i2c_bus, sfp_fdt_get_i2c_bus),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(sfp_fdt, sfp_fdt_driver, sfp_fdt_methods,
+ sizeof(struct sfp_fdt_softc));
+
+EARLY_DRIVER_MODULE(sfp_fdt, simplebus, sfp_fdt_driver, 0, 0,
+ BUS_PASS_SUPPORTDEV);
+EARLY_DRIVER_MODULE(sfp_fdt, ofwbus, sfp_fdt_driver, 0, 0,
+ BUS_PASS_SUPPORTDEV);
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -357,6 +357,7 @@
${_sdhci_fdt} \
sdhci_pci \
sdio \
+ ${_sff} \
sem \
send \
${_sfxge} \
@@ -679,6 +680,7 @@
.if ${MACHINE_CPUARCH} == "aarch64"
_armv8crypto= armv8crypto
_dpaa2= dpaa2
+_sff= sff
_em= em
_hyperv= hyperv
diff --git a/sys/modules/sff/Makefile b/sys/modules/sff/Makefile
new file mode 100644
--- /dev/null
+++ b/sys/modules/sff/Makefile
@@ -0,0 +1,13 @@
+.PATH: ${SRCTOP}/sys/dev/sff
+
+KMOD= sff
+
+SRCS+= sff_if.c sff_if.h
+SRCS+= bus_if.h device_if.h
+
+.if !empty(OPT_FDT)
+SRCS+= sfp_fdt.c \
+ ofw_bus_if.h
+.endif
+
+.include <bsd.kmod.mk>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 2, 4:57 AM (2 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30705368
Default Alt Text
D41440.id125963.diff (7 KB)
Attached To
Mode
D41440: sff: Add SFP driver (fdt-based draft)
Attached
Detach File
Event Timeline
Log In to Comment