601a4bf6aafa71dde3db5db74a3d61a0930f8dd6
[openwrt/staging/mkresin.git] /
1 From d84bd24a4d6e5b05f7eb1a544dfd0bd98c7f5bb1 Mon Sep 17 00:00:00 2001
2 From: Ioana Radulescu <ruxandra.radulescu@nxp.com>
3 Date: Wed, 17 Oct 2018 20:14:24 +0300
4 Subject: [PATCH] staging: fsl-dpaa2/mac: Add support for new link state APIs
5
6 Add v2 of dpmac_set_link_state() and dpmac_get_link_cfg() commands.
7 The new version allows setting & getting advertised and supported
8 link options.
9
10 Signed-off-by: Valentin Catalin Neacsu <valentin-catalin.neacsu@nxp.com>
11 Signed-off-by: Ioana Radulescu <ruxandra.radulescu@nxp.com>
12 ---
13 drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h | 24 +++++++++++
14 drivers/staging/fsl-dpaa2/mac/dpmac.c | 70 +++++++++++++++++++++++++++++++
15 drivers/staging/fsl-dpaa2/mac/dpmac.h | 32 ++++++++++++++
16 3 files changed, 126 insertions(+)
17
18 --- a/drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h
19 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac-cmd.h
20 @@ -36,9 +36,11 @@
21 #define DPMAC_VER_MAJOR 4
22 #define DPMAC_VER_MINOR 2
23 #define DPMAC_CMD_BASE_VERSION 1
24 +#define DPMAC_CMD_2ND_VERSION 2
25 #define DPMAC_CMD_ID_OFFSET 4
26
27 #define DPMAC_CMD(id) (((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_BASE_VERSION)
28 +#define DPMAC_CMD_V2(id) (((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_2ND_VERSION)
29
30 /* Command IDs */
31 #define DPMAC_CMDID_CLOSE DPMAC_CMD(0x800)
32 @@ -58,7 +60,9 @@
33 #define DPMAC_CMDID_CLEAR_IRQ_STATUS DPMAC_CMD(0x017)
34
35 #define DPMAC_CMDID_GET_LINK_CFG DPMAC_CMD(0x0c2)
36 +#define DPMAC_CMDID_GET_LINK_CFG_V2 DPMAC_CMD_V2(0x0c2)
37 #define DPMAC_CMDID_SET_LINK_STATE DPMAC_CMD(0x0c3)
38 +#define DPMAC_CMDID_SET_LINK_STATE_V2 DPMAC_CMD_V2(0x0c3)
39 #define DPMAC_CMDID_GET_COUNTER DPMAC_CMD(0x0c4)
40
41 #define DPMAC_CMDID_SET_PORT_MAC_ADDR DPMAC_CMD(0x0c5)
42 @@ -139,8 +143,17 @@ struct dpmac_rsp_get_link_cfg {
43 u32 rate;
44 };
45
46 +struct dpmac_rsp_get_link_cfg_v2 {
47 + u64 options;
48 + u32 rate;
49 + u32 pad;
50 + u64 advertising;
51 +};
52 +
53 #define DPMAC_STATE_SIZE 1
54 #define DPMAC_STATE_SHIFT 0
55 +#define DPMAC_STATE_VALID_SIZE 1
56 +#define DPMAC_STATE_VALID_SHIFT 1
57
58 struct dpmac_cmd_set_link_state {
59 u64 options;
60 @@ -150,6 +163,17 @@ struct dpmac_cmd_set_link_state {
61 u8 up;
62 };
63
64 +struct dpmac_cmd_set_link_state_v2 {
65 + u64 options;
66 + u32 rate;
67 + u32 pad0;
68 + /* from lsb: up:1, state_valid:1 */
69 + u8 state;
70 + u8 pad1[7];
71 + u64 supported;
72 + u64 advertising;
73 +};
74 +
75 struct dpmac_cmd_get_counter {
76 u8 type;
77 };
78 --- a/drivers/staging/fsl-dpaa2/mac/dpmac.c
79 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac.c
80 @@ -492,6 +492,42 @@ int dpmac_get_link_cfg(struct fsl_mc_io
81 }
82
83 /**
84 + * dpmac_get_link_cfg_v2() - Get Ethernet link configuration
85 + * @mc_io: Pointer to opaque I/O object
86 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 + * @token: Token of DPMAC object
88 + * @cfg: Returned structure with the link configuration
89 + *
90 + * Return: '0' on Success; Error code otherwise.
91 + */
92 +int dpmac_get_link_cfg_v2(struct fsl_mc_io *mc_io,
93 + u32 cmd_flags,
94 + u16 token,
95 + struct dpmac_link_cfg *cfg)
96 +{
97 + struct dpmac_rsp_get_link_cfg_v2 *rsp_params;
98 + struct fsl_mc_command cmd = { 0 };
99 + int err = 0;
100 +
101 + /* prepare command */
102 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_GET_LINK_CFG_V2,
103 + cmd_flags,
104 + token);
105 +
106 + /* send command to mc*/
107 + err = mc_send_command(mc_io, &cmd);
108 + if (err)
109 + return err;
110 +
111 + rsp_params = (struct dpmac_rsp_get_link_cfg_v2 *)cmd.params;
112 + cfg->options = le64_to_cpu(rsp_params->options);
113 + cfg->rate = le32_to_cpu(rsp_params->rate);
114 + cfg->advertising = le64_to_cpu(rsp_params->advertising);
115 +
116 + return 0;
117 +}
118 +
119 +/**
120 * dpmac_set_link_state() - Set the Ethernet link status
121 * @mc_io: Pointer to opaque I/O object
122 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
123 @@ -519,6 +555,40 @@ int dpmac_set_link_state(struct fsl_mc_i
124
125 /* send command to mc*/
126 return mc_send_command(mc_io, &cmd);
127 +}
128 +
129 +/**
130 + * dpmac_set_link_state_v2() - Set the Ethernet link status
131 + * @mc_io: Pointer to opaque I/O object
132 + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
133 + * @token: Token of DPMAC object
134 + * @link_state: Link state configuration
135 + *
136 + * Return: '0' on Success; Error code otherwise.
137 + */
138 +int dpmac_set_link_state_v2(struct fsl_mc_io *mc_io,
139 + u32 cmd_flags,
140 + u16 token,
141 + struct dpmac_link_state *link_state)
142 +{
143 + struct dpmac_cmd_set_link_state_v2 *cmd_params;
144 + struct fsl_mc_command cmd = { 0 };
145 +
146 + /* prepare command */
147 + cmd.header = mc_encode_cmd_header(DPMAC_CMDID_SET_LINK_STATE_V2,
148 + cmd_flags,
149 + token);
150 + cmd_params = (struct dpmac_cmd_set_link_state_v2 *)cmd.params;
151 + cmd_params->options = cpu_to_le64(link_state->options);
152 + cmd_params->rate = cpu_to_le32(link_state->rate);
153 + dpmac_set_field(cmd_params->state, STATE, link_state->up);
154 + dpmac_set_field(cmd_params->state, STATE_VALID,
155 + link_state->state_valid);
156 + cmd_params->supported = cpu_to_le64(link_state->supported);
157 + cmd_params->advertising = cpu_to_le64(link_state->advertising);
158 +
159 + /* send command to mc*/
160 + return mc_send_command(mc_io, &cmd);
161 }
162
163 /**
164 --- a/drivers/staging/fsl-dpaa2/mac/dpmac.h
165 +++ b/drivers/staging/fsl-dpaa2/mac/dpmac.h
166 @@ -202,13 +202,29 @@ int dpmac_get_attributes(struct fsl_mc_i
167 #define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL
168
169 /**
170 + * Advertised link speeds
171 + */
172 +#define DPMAC_ADVERTISED_10BASET_FULL 0x0000000000000001ULL
173 +#define DPMAC_ADVERTISED_100BASET_FULL 0x0000000000000002ULL
174 +#define DPMAC_ADVERTISED_1000BASET_FULL 0x0000000000000004ULL
175 +#define DPMAC_ADVERTISED_10000BASET_FULL 0x0000000000000010ULL
176 +#define DPMAC_ADVERTISED_2500BASEX_FULL 0x0000000000000020ULL
177 +
178 +/**
179 + * Advertise auto-negotiation enable
180 + */
181 +#define DPMAC_ADVERTISED_AUTONEG 0x0000000000000008ULL
182 +
183 +/**
184 * struct dpmac_link_cfg - Structure representing DPMAC link configuration
185 * @rate: Link's rate - in Mbps
186 * @options: Enable/Disable DPMAC link cfg features (bitmap)
187 + * @advertising: Speeds that are advertised for autoneg (bitmap)
188 */
189 struct dpmac_link_cfg {
190 u32 rate;
191 u64 options;
192 + u64 advertising;
193 };
194
195 int dpmac_get_link_cfg(struct fsl_mc_io *mc_io,
196 @@ -216,16 +232,27 @@ int dpmac_get_link_cfg(struct fsl_mc_io
197 u16 token,
198 struct dpmac_link_cfg *cfg);
199
200 +int dpmac_get_link_cfg_v2(struct fsl_mc_io *mc_io,
201 + u32 cmd_flags,
202 + u16 token,
203 + struct dpmac_link_cfg *cfg);
204 +
205 /**
206 * struct dpmac_link_state - DPMAC link configuration request
207 * @rate: Rate in Mbps
208 * @options: Enable/Disable DPMAC link cfg features (bitmap)
209 * @up: Link state
210 + * @state_valid: Ignore/Update the state of the link
211 + * @supported: Speeds capability of the phy (bitmap)
212 + * @advertising: Speeds that are advertised for autoneg (bitmap)
213 */
214 struct dpmac_link_state {
215 u32 rate;
216 u64 options;
217 int up;
218 + int state_valid;
219 + u64 supported;
220 + u64 advertising;
221 };
222
223 int dpmac_set_link_state(struct fsl_mc_io *mc_io,
224 @@ -233,6 +260,11 @@ int dpmac_set_link_state(struct fsl_mc_i
225 u16 token,
226 struct dpmac_link_state *link_state);
227
228 +int dpmac_set_link_state_v2(struct fsl_mc_io *mc_io,
229 + u32 cmd_flags,
230 + u16 token,
231 + struct dpmac_link_state *link_state);
232 +
233 /**
234 * enum dpmac_counter - DPMAC counter types
235 * @DPMAC_CNT_ING_FRAME_64: counts 64-bytes frames, good or bad.