~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: adecb8135764f97087d7f79c419a86784c16e16f (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2015 Freescale Semiconductor
 */

#include <common.h>
#include <asm/io.h>
#include <asm/types.h>
#include <malloc.h>
#include <net.h>
#include <linux/compat.h>
#include <asm/arch/fsl_serdes.h>
#include <fsl-mc/ldpaa_wriop.h>

struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS];

__weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc)
{
	return PHY_INTERFACE_MODE_NA;
}

void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl)
{
	phy_interface_t enet_if;
	int phy_num;

	dpmac_info[dpmac_id].enabled = 0;
	dpmac_info[dpmac_id].id = 0;
	dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA;

	enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl);
	if (enet_if != PHY_INTERFACE_MODE_NA) {
		dpmac_info[dpmac_id].enabled = 1;
		dpmac_info[dpmac_id].id = dpmac_id;
		dpmac_info[dpmac_id].enet_if = enet_if;
	}
	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
	}
}

void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if)
{
	int phy_num;

	dpmac_info[dpmac_id].enabled = 1;
	dpmac_info[dpmac_id].id = dpmac_id;
	dpmac_info[dpmac_id].enet_if = enet_if;
	for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) {
		dpmac_info[dpmac_id].phydev[phy_num] = NULL;
		dpmac_info[dpmac_id].phy_addr[phy_num] = -1;
	}
}


/*TODO what it do */
static int wriop_dpmac_to_index(int dpmac_id)
{
	int i;

	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
		if (dpmac_info[i].id == dpmac_id)
			return i;
	}

	return -1;
}

int wriop_disable_dpmac(int dpmac_id)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;

	dpmac_info[i].enabled = 0;
	wriop_dpmac_disable(dpmac_id);

	return 0;
}

int wriop_enable_dpmac(int dpmac_id)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;

	dpmac_info[i].enabled = 1;
	wriop_dpmac_enable(dpmac_id);

	return 0;
}

int wriop_is_enabled_dpmac(int dpmac_id)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;

	return dpmac_info[i].enabled;
}


int wriop_set_mdio(int dpmac_id, struct mii_dev *bus)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;

	dpmac_info[i].bus = bus;

	return 0;
}

struct mii_dev *wriop_get_mdio(int dpmac_id)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return NULL;

	return dpmac_info[i].bus;
}

int wriop_set_phy_address(int dpmac_id, int phy_num, int address)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;
	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
		return -EINVAL;

	dpmac_info[i].phy_addr[phy_num] = address;

	return 0;
}

int wriop_get_phy_address(int dpmac_id, int phy_num)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;
	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
		return -EINVAL;

	return dpmac_info[i].phy_addr[phy_num];
}

int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return -ENODEV;
	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
		return -EINVAL;

	dpmac_info[i].phydev[phy_num] = phydev;

	return 0;
}

struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return NULL;
	if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM)
		return NULL;

	return dpmac_info[i].phydev[phy_num];
}

phy_interface_t wriop_get_enet_if(int dpmac_id)
{
	int i = wriop_dpmac_to_index(dpmac_id);

	if (i == -1)
		return PHY_INTERFACE_MODE_NA;

	if (dpmac_info[i].enabled)
		return dpmac_info[i].enet_if;

	return PHY_INTERFACE_MODE_NA;
}