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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/* $OpenBSD: if_em_soc.c,v 1.2 2011/04/07 15:30:16 miod Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <dev/pci/if_em.h>
#include <dev/pci/if_em_hw.h>
#include <dev/pci/if_em_soc.h>
#include <dev/pci/gcu.h>
#include <dev/pci/gcu_reg.h>
void em_media_status(struct ifnet *, struct ifmediareq *);
int em_media_change(struct ifnet *);
void *
em_lookup_gcu(struct device *self)
{
struct device *dev;
INIT_DEBUGOUT("em_lookup_gcu");
TAILQ_FOREACH(dev, &alldevs, dv_list) {
if (strcmp(dev->dv_xname, "gcu0") == 0) {
return dev;
}
}
return 0;
}
int
em_attach_miibus(struct device *self)
{
return 0;
}
int
gcu_miibus_readreg(struct em_hw *hw, int phy, int reg)
{
struct em_softc *sc = (struct em_softc *)
((struct em_osdep *)hw->back)->dev;
struct gcu_softc *gcu = hw->gcu;
uint32_t data = 0;
uint32_t done = 0;
int i = 0;
if (gcu == 0)
return 0;
/* format the data to be written to MDIO_COMMAND_REG */
data |= (reg << MDIO_COMMAND_PHY_REG_OFFSET);
data |= (phy << MDIO_COMMAND_PHY_ADDR_OFFSET);
data |= MDIO_COMMAND_GO_MASK;
mtx_enter(&gcu->mdio_mtx);
bus_space_write_4(gcu->tag, gcu->handle, MDIO_COMMAND_REG, data);
while (!done && (i++ < GCU_MAX_ATTEMPTS)) {
DELAY(GCU_CMD_DELAY);
data = bus_space_read_4(gcu->tag, gcu->handle,
MDIO_COMMAND_REG);
done = !((data & MDIO_COMMAND_GO_MASK) >>
MDIO_COMMAND_GO_OFFSET);
}
mtx_leave(&gcu->mdio_mtx);
if (i >= GCU_MAX_ATTEMPTS) {
printf("%s: phy read timeout: phy %d, reg %d\n",
sc->sc_dv.dv_xname, phy, reg);
return (0);
}
mtx_enter(&gcu->mdio_mtx);
data = bus_space_read_4(gcu->tag, gcu->handle, MDIO_STATUS_REG);
mtx_leave(&gcu->mdio_mtx);
if((data & MDIO_STATUS_STATUS_MASK) != 0) {
printf("%s: unable to read phy %d reg %d\n",
sc->sc_dv.dv_xname, phy, reg);
return (0);
}
return (uint16_t) (data & MDIO_STATUS_READ_DATA_MASK);
}
void
gcu_miibus_writereg(struct em_hw *hw, int phy, int reg, int val)
{
struct em_softc *sc = (struct em_softc *)
((struct em_osdep *)hw->back)->dev;
struct gcu_softc *gcu = hw->gcu;
uint32_t data, done = 0;
int i = 0;
if (gcu == 0)
return;
/* format the data to be written to the MDIO_COMMAND_REG */
data = val;
data |= (reg << MDIO_COMMAND_PHY_REG_OFFSET);
data |= (phy << MDIO_COMMAND_PHY_ADDR_OFFSET);
data |= MDIO_COMMAND_OPER_MASK | MDIO_COMMAND_GO_MASK;
mtx_enter(&gcu->mdio_mtx);
bus_space_write_4(gcu->tag, gcu->handle, MDIO_COMMAND_REG, data);
while (!done && (i++ < GCU_MAX_ATTEMPTS)) {
DELAY(GCU_CMD_DELAY);
data = bus_space_read_4(gcu->tag, gcu->handle,
MDIO_COMMAND_REG);
done = !((data & MDIO_COMMAND_GO_MASK) >>
MDIO_COMMAND_GO_OFFSET);
}
mtx_leave(&gcu->mdio_mtx);
if (i >= GCU_MAX_ATTEMPTS) {
printf("%s: phy read timeout: phy %d, reg %d\n",
sc->sc_dv.dv_xname, phy, reg);
return;
}
}
void
gcu_miibus_statchg(struct device *dev)
{
}
|