1/* SPDX-License-Identifier: GPL-2.0 */
2/* Marvell Octeon EP (EndPoint) Ethernet Driver
3 *
4 * Copyright (C) 2020 Marvell.
5 *
6 */
7#ifndef __OCTEP_CTRL_NET_H__
8#define __OCTEP_CTRL_NET_H__
9
10#include "octep_cp_version.h"
11
12#define OCTEP_CTRL_NET_INVALID_VFID	(-1)
13
14/* Supported commands */
15enum octep_ctrl_net_cmd {
16	OCTEP_CTRL_NET_CMD_GET = 0,
17	OCTEP_CTRL_NET_CMD_SET,
18};
19
20/* Supported states */
21enum octep_ctrl_net_state {
22	OCTEP_CTRL_NET_STATE_DOWN = 0,
23	OCTEP_CTRL_NET_STATE_UP,
24};
25
26/* Supported replies */
27enum octep_ctrl_net_reply {
28	OCTEP_CTRL_NET_REPLY_OK = 0,
29	OCTEP_CTRL_NET_REPLY_GENERIC_FAIL,
30	OCTEP_CTRL_NET_REPLY_INVALID_PARAM,
31};
32
33/* Supported host to fw commands */
34enum octep_ctrl_net_h2f_cmd {
35	OCTEP_CTRL_NET_H2F_CMD_INVALID = 0,
36	OCTEP_CTRL_NET_H2F_CMD_MTU,
37	OCTEP_CTRL_NET_H2F_CMD_MAC,
38	OCTEP_CTRL_NET_H2F_CMD_GET_IF_STATS,
39	OCTEP_CTRL_NET_H2F_CMD_GET_XSTATS,
40	OCTEP_CTRL_NET_H2F_CMD_GET_Q_STATS,
41	OCTEP_CTRL_NET_H2F_CMD_LINK_STATUS,
42	OCTEP_CTRL_NET_H2F_CMD_RX_STATE,
43	OCTEP_CTRL_NET_H2F_CMD_LINK_INFO,
44	OCTEP_CTRL_NET_H2F_CMD_GET_INFO,
45	OCTEP_CTRL_NET_H2F_CMD_DEV_REMOVE,
46	OCTEP_CTRL_NET_H2F_CMD_OFFLOADS,
47	OCTEP_CTRL_NET_H2F_CMD_MAX
48};
49
50/* Supported fw to host commands */
51enum octep_ctrl_net_f2h_cmd {
52	OCTEP_CTRL_NET_F2H_CMD_INVALID = 0,
53	OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS,
54	OCTEP_CTRL_NET_F2H_CMD_MAX
55};
56
57union octep_ctrl_net_req_hdr {
58	u64 words[1];
59	struct {
60		/* sender id */
61		u16 sender;
62		/* receiver id */
63		u16 receiver;
64		/* octep_ctrl_net_h2t_cmd */
65		u16 cmd;
66		/* reserved */
67		u16 rsvd0;
68	} s;
69};
70
71/* get/set mtu request */
72struct octep_ctrl_net_h2f_req_cmd_mtu {
73	/* enum octep_ctrl_net_cmd */
74	u16 cmd;
75	/* 0-65535 */
76	u16 val;
77};
78
79/* get/set mac request */
80struct octep_ctrl_net_h2f_req_cmd_mac {
81	/* enum octep_ctrl_net_cmd */
82	u16 cmd;
83	/* xx:xx:xx:xx:xx:xx */
84	u8 addr[ETH_ALEN];
85};
86
87/* get/set link state, rx state */
88struct octep_ctrl_net_h2f_req_cmd_state {
89	/* enum octep_ctrl_net_cmd */
90	u16 cmd;
91	/* enum octep_ctrl_net_state */
92	u16 state;
93};
94
95/* link info */
96struct octep_ctrl_net_link_info {
97	/* Bitmap of Supported link speeds/modes */
98	u64 supported_modes;
99	/* Bitmap of Advertised link speeds/modes */
100	u64 advertised_modes;
101	/* Autonegotation state; bit 0=disabled; bit 1=enabled */
102	u8 autoneg;
103	/* Pause frames setting. bit 0=disabled; bit 1=enabled */
104	u8 pause;
105	/* Negotiated link speed in Mbps */
106	u32 speed;
107};
108
109/* get/set link info */
110struct octep_ctrl_net_h2f_req_cmd_link_info {
111	/* enum octep_ctrl_net_cmd */
112	u16 cmd;
113	/* struct octep_ctrl_net_link_info */
114	struct octep_ctrl_net_link_info info;
115};
116
117/* offloads */
118struct octep_ctrl_net_offloads {
119	/* supported rx offloads OCTEP_RX_OFFLOAD_* */
120	u16 rx_offloads;
121	/* supported tx offloads OCTEP_TX_OFFLOAD_* */
122	u16 tx_offloads;
123	/* reserved */
124	u32 reserved_offloads;
125	/* extra offloads */
126	u64 ext_offloads;
127};
128
129/* get/set offloads */
130struct octep_ctrl_net_h2f_req_cmd_offloads {
131	/* enum octep_ctrl_net_cmd */
132	u16 cmd;
133	/* struct octep_ctrl_net_offloads */
134	struct octep_ctrl_net_offloads offloads;
135};
136
137/* Host to fw request data */
138struct octep_ctrl_net_h2f_req {
139	union octep_ctrl_net_req_hdr hdr;
140	union {
141		struct octep_ctrl_net_h2f_req_cmd_mtu mtu;
142		struct octep_ctrl_net_h2f_req_cmd_mac mac;
143		struct octep_ctrl_net_h2f_req_cmd_state link;
144		struct octep_ctrl_net_h2f_req_cmd_state rx;
145		struct octep_ctrl_net_h2f_req_cmd_link_info link_info;
146		struct octep_ctrl_net_h2f_req_cmd_offloads offloads;
147	};
148} __packed;
149
150union octep_ctrl_net_resp_hdr {
151	u64 words[1];
152	struct {
153		/* sender id */
154		u16 sender;
155		/* receiver id */
156		u16 receiver;
157		/* octep_ctrl_net_h2t_cmd */
158		u16 cmd;
159		/* octep_ctrl_net_reply */
160		u16 reply;
161	} s;
162};
163
164/* get mtu response */
165struct octep_ctrl_net_h2f_resp_cmd_mtu {
166	/* 0-65535 */
167	u16 val;
168};
169
170/* get mac response */
171struct octep_ctrl_net_h2f_resp_cmd_mac {
172	/* xx:xx:xx:xx:xx:xx */
173	u8 addr[ETH_ALEN];
174};
175
176/* get if_stats, xstats, q_stats request */
177struct octep_ctrl_net_h2f_resp_cmd_get_stats {
178	struct octep_iface_rx_stats rx_stats;
179	struct octep_iface_tx_stats tx_stats;
180};
181
182/* get link state, rx state response */
183struct octep_ctrl_net_h2f_resp_cmd_state {
184	/* enum octep_ctrl_net_state */
185	u16 state;
186};
187
188/* get info request */
189struct octep_ctrl_net_h2f_resp_cmd_get_info {
190	struct octep_fw_info fw_info;
191};
192
193/* Host to fw response data */
194struct octep_ctrl_net_h2f_resp {
195	union octep_ctrl_net_resp_hdr hdr;
196	union {
197		struct octep_ctrl_net_h2f_resp_cmd_mtu mtu;
198		struct octep_ctrl_net_h2f_resp_cmd_mac mac;
199		struct octep_ctrl_net_h2f_resp_cmd_get_stats if_stats;
200		struct octep_ctrl_net_h2f_resp_cmd_state link;
201		struct octep_ctrl_net_h2f_resp_cmd_state rx;
202		struct octep_ctrl_net_link_info link_info;
203		struct octep_ctrl_net_h2f_resp_cmd_get_info info;
204		struct octep_ctrl_net_offloads offloads;
205	};
206} __packed;
207
208/* link state notofication */
209struct octep_ctrl_net_f2h_req_cmd_state {
210	/* enum octep_ctrl_net_state */
211	u16 state;
212};
213
214/* Fw to host request data */
215struct octep_ctrl_net_f2h_req {
216	union octep_ctrl_net_req_hdr hdr;
217	union {
218		struct octep_ctrl_net_f2h_req_cmd_state link;
219	};
220};
221
222/* Fw to host response data */
223struct octep_ctrl_net_f2h_resp {
224	union octep_ctrl_net_resp_hdr hdr;
225};
226
227/* Max data size to be transferred over mbox */
228union octep_ctrl_net_max_data {
229	struct octep_ctrl_net_h2f_req h2f_req;
230	struct octep_ctrl_net_h2f_resp h2f_resp;
231	struct octep_ctrl_net_f2h_req f2h_req;
232	struct octep_ctrl_net_f2h_resp f2h_resp;
233};
234
235struct octep_ctrl_net_wait_data {
236	struct list_head list;
237	int done;
238	struct octep_ctrl_mbox_msg msg;
239	union {
240		struct octep_ctrl_net_h2f_req req;
241		struct octep_ctrl_net_h2f_resp resp;
242	} data;
243};
244
245/**
246 * octep_ctrl_net_init() - Initialize data for ctrl net.
247 *
248 * @oct: non-null pointer to struct octep_device.
249 *
250 * return value: 0 on success, -errno on error.
251 */
252int octep_ctrl_net_init(struct octep_device *oct);
253
254/**
255 * octep_ctrl_net_get_link_status() - Get link status from firmware.
256 *
257 * @oct: non-null pointer to struct octep_device.
258 * @vfid: Index of virtual function.
259 *
260 * return value: link status 0=down, 1=up.
261 */
262int octep_ctrl_net_get_link_status(struct octep_device *oct, int vfid);
263
264/**
265 * octep_ctrl_net_set_link_status() - Set link status in firmware.
266 *
267 * @oct: non-null pointer to struct octep_device.
268 * @vfid: Index of virtual function.
269 * @up: boolean status.
270 * @wait_for_response: poll for response.
271 *
272 * return value: 0 on success, -errno on failure
273 */
274int octep_ctrl_net_set_link_status(struct octep_device *oct, int vfid, bool up,
275				   bool wait_for_response);
276
277/**
278 * octep_ctrl_net_set_rx_state() - Set rx state in firmware.
279 *
280 * @oct: non-null pointer to struct octep_device.
281 * @vfid: Index of virtual function.
282 * @up: boolean status.
283 * @wait_for_response: poll for response.
284 *
285 * return value: 0 on success, -errno on failure.
286 */
287int octep_ctrl_net_set_rx_state(struct octep_device *oct, int vfid, bool up,
288				bool wait_for_response);
289
290/**
291 * octep_ctrl_net_get_mac_addr() - Get mac address from firmware.
292 *
293 * @oct: non-null pointer to struct octep_device.
294 * @vfid: Index of virtual function.
295 * @addr: non-null pointer to mac address.
296 *
297 * return value: 0 on success, -errno on failure.
298 */
299int octep_ctrl_net_get_mac_addr(struct octep_device *oct, int vfid, u8 *addr);
300
301/**
302 * octep_ctrl_net_set_mac_addr() - Set mac address in firmware.
303 *
304 * @oct: non-null pointer to struct octep_device.
305 * @vfid: Index of virtual function.
306 * @addr: non-null pointer to mac address.
307 * @wait_for_response: poll for response.
308 *
309 * return value: 0 on success, -errno on failure.
310 */
311int octep_ctrl_net_set_mac_addr(struct octep_device *oct, int vfid, u8 *addr,
312				bool wait_for_response);
313
314/**
315 * octep_ctrl_net_get_mtu() - Get max MTU from firmware.
316 *
317 * @oct: non-null pointer to struct octep_device.
318 * @vfid: Index of virtual function.
319 *
320 * return value: mtu on success, -errno on failure.
321 */
322int octep_ctrl_net_get_mtu(struct octep_device *oct, int vfid);
323
324/**
325 * octep_ctrl_net_set_mtu() - Set mtu in firmware.
326 *
327 * @oct: non-null pointer to struct octep_device.
328 * @vfid: Index of virtual function.
329 * @mtu: mtu.
330 * @wait_for_response: poll for response.
331 *
332 * return value: 0 on success, -errno on failure.
333 */
334int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu,
335			   bool wait_for_response);
336
337/**
338 * octep_ctrl_net_get_if_stats() - Get interface statistics from firmware.
339 *
340 * @oct: non-null pointer to struct octep_device.
341 * @vfid: Index of virtual function.
342 * @rx_stats: non-null pointer struct octep_iface_rx_stats.
343 * @tx_stats: non-null pointer struct octep_iface_tx_stats.
344 *
345 * return value: 0 on success, -errno on failure.
346 */
347int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid,
348				struct octep_iface_rx_stats *rx_stats,
349				struct octep_iface_tx_stats *tx_stats);
350
351/**
352 * octep_ctrl_net_get_link_info() - Get link info from firmware.
353 *
354 * @oct: non-null pointer to struct octep_device.
355 * @vfid: Index of virtual function.
356 * @link_info: non-null pointer to struct octep_iface_link_info.
357 *
358 * return value: 0 on success, -errno on failure.
359 */
360int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid,
361				 struct octep_iface_link_info *link_info);
362
363/**
364 * octep_ctrl_net_set_link_info() - Set link info in firmware.
365 *
366 * @oct: non-null pointer to struct octep_device.
367 * @vfid: Index of virtual function.
368 * @link_info: non-null pointer to struct octep_iface_link_info.
369 * @wait_for_response: poll for response.
370 *
371 * return value: 0 on success, -errno on failure.
372 */
373int octep_ctrl_net_set_link_info(struct octep_device *oct,
374				 int vfid,
375				 struct octep_iface_link_info *link_info,
376				 bool wait_for_response);
377
378/**
379 * octep_ctrl_net_recv_fw_messages() - Poll for firmware messages and process them.
380 *
381 * @oct: non-null pointer to struct octep_device.
382 */
383void octep_ctrl_net_recv_fw_messages(struct octep_device *oct);
384
385/**
386 * octep_ctrl_net_get_info() - Get info from firmware.
387 *
388 * @oct: non-null pointer to struct octep_device.
389 * @vfid: Index of virtual function.
390 * @info: non-null pointer to struct octep_fw_info.
391 *
392 * return value: 0 on success, -errno on failure.
393 */
394int octep_ctrl_net_get_info(struct octep_device *oct, int vfid,
395			    struct octep_fw_info *info);
396
397/**
398 * octep_ctrl_net_dev_remove() - Indicate to firmware that a device unload has happened.
399 *
400 * @oct: non-null pointer to struct octep_device.
401 * @vfid: Index of virtual function.
402 *
403 * return value: 0 on success, -errno on failure.
404 */
405int octep_ctrl_net_dev_remove(struct octep_device *oct, int vfid);
406
407/**
408 * octep_ctrl_net_set_offloads() - Set offloads in firmware.
409 *
410 * @oct: non-null pointer to struct octep_device.
411 * @vfid: Index of virtual function.
412 * @offloads: non-null pointer to struct octep_ctrl_net_offloads.
413 * @wait_for_response: poll for response.
414 *
415 * return value: 0 on success, -errno on failure.
416 */
417int octep_ctrl_net_set_offloads(struct octep_device *oct, int vfid,
418				struct octep_ctrl_net_offloads *offloads,
419				bool wait_for_response);
420
421/**
422 * octep_ctrl_net_uninit() - Uninitialize data for ctrl net.
423 *
424 * @oct: non-null pointer to struct octep_device.
425 *
426 * return value: 0 on success, -errno on error.
427 */
428int octep_ctrl_net_uninit(struct octep_device *oct);
429
430#endif /* __OCTEP_CTRL_NET_H__ */
431