1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
* Copyright (c) 2026 Justin Hibbits
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Shared bits of the FMan port drivers.
*/
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <machine/bus.h>
#include "fman.h"
#include "fman_port.h"
#include "fman_port_var.h"
#include "fman_if.h"
int
fman_port_attach_common(device_t dev, struct fman_port_softc *sc,
int port_speed)
{
phandle_t node;
pcell_t cell;
sc->sc_dev = dev;
node = ofw_bus_get_node(dev);
if (OF_getencprop(node, "cell-index", &cell, sizeof(cell)) < 0) {
device_printf(dev, "No cell-index property\n");
return (ENXIO);
}
sc->sc_port_id = cell;
sc->sc_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 0,
RF_ACTIVE | RF_SHAREABLE);
if (sc->sc_mem == NULL) {
device_printf(dev, "failed to allocate MMIO\n");
return (ENXIO);
}
FMAN_GET_REVISION(device_get_parent(dev),
&sc->sc_revision_major, &sc->sc_revision_minor);
sc->sc_port_speed = port_speed;
sc->sc_bm_max_pools = MAX_BM_POOLS;
sc->sc_max_frame_length = PORT_MAX_FRAME_LENGTH;
OF_device_register_xref(OF_xref_from_node(node), dev);
return (0);
}
int
fman_port_detach_common(device_t dev, struct fman_port_softc *sc)
{
if (sc->sc_mem != NULL)
bus_release_resource(dev, sc->sc_mem);
return (0);
}
void
fman_port_config_common(struct fman_port_softc *sc,
struct fman_port_params *params)
{
sc->sc_default_fqid = params->dflt_fqid;
sc->sc_err_fqid = params->err_fqid;
sc->sc_max_port_fifo_size =
FMAN_GET_BMI_MAX_FIFO_SIZE(device_get_parent(sc->sc_dev));
switch (sc->sc_revision_major) {
case 2:
case 3:
sc->sc_max_ext_portals = 4;
sc->sc_max_sub_portals = 12;
break;
case 6:
sc->sc_max_ext_portals = 8;
sc->sc_max_sub_portals = 16;
break;
}
}
int
fman_port_get_id(device_t dev)
{
struct fman_port_softc *sc = device_get_softc(dev);
return (sc->sc_port_id);
}
|