18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
28c2ecf20Sopenharmony_ci/* Copyright 2013-2016 Freescale Semiconductor Inc.
38c2ecf20Sopenharmony_ci * Copyright 2019 NXP
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _FSL_DPMAC_CMD_H
68c2ecf20Sopenharmony_ci#define _FSL_DPMAC_CMD_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* DPMAC Version */
98c2ecf20Sopenharmony_ci#define DPMAC_VER_MAJOR				4
108c2ecf20Sopenharmony_ci#define DPMAC_VER_MINOR				4
118c2ecf20Sopenharmony_ci#define DPMAC_CMD_BASE_VERSION			1
128c2ecf20Sopenharmony_ci#define DPMAC_CMD_2ND_VERSION			2
138c2ecf20Sopenharmony_ci#define DPMAC_CMD_ID_OFFSET			4
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define DPMAC_CMD(id)	(((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_BASE_VERSION)
168c2ecf20Sopenharmony_ci#define DPMAC_CMD_V2(id) (((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_2ND_VERSION)
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* Command IDs */
198c2ecf20Sopenharmony_ci#define DPMAC_CMDID_CLOSE		DPMAC_CMD(0x800)
208c2ecf20Sopenharmony_ci#define DPMAC_CMDID_OPEN		DPMAC_CMD(0x80c)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define DPMAC_CMDID_GET_ATTR		DPMAC_CMD(0x004)
238c2ecf20Sopenharmony_ci#define DPMAC_CMDID_SET_LINK_STATE	DPMAC_CMD_V2(0x0c3)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define DPMAC_CMDID_GET_COUNTER		DPMAC_CMD(0x0c4)
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* Macros for accessing command fields smaller than 1byte */
288c2ecf20Sopenharmony_ci#define DPMAC_MASK(field)        \
298c2ecf20Sopenharmony_ci	GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \
308c2ecf20Sopenharmony_ci		DPMAC_##field##_SHIFT)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define dpmac_set_field(var, field, val) \
338c2ecf20Sopenharmony_ci	((var) |= (((val) << DPMAC_##field##_SHIFT) & DPMAC_MASK(field)))
348c2ecf20Sopenharmony_ci#define dpmac_get_field(var, field)      \
358c2ecf20Sopenharmony_ci	(((var) & DPMAC_MASK(field)) >> DPMAC_##field##_SHIFT)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistruct dpmac_cmd_open {
388c2ecf20Sopenharmony_ci	__le32 dpmac_id;
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistruct dpmac_rsp_get_attributes {
428c2ecf20Sopenharmony_ci	u8 eth_if;
438c2ecf20Sopenharmony_ci	u8 link_type;
448c2ecf20Sopenharmony_ci	__le16 id;
458c2ecf20Sopenharmony_ci	__le32 max_rate;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define DPMAC_STATE_SIZE	1
498c2ecf20Sopenharmony_ci#define DPMAC_STATE_SHIFT	0
508c2ecf20Sopenharmony_ci#define DPMAC_STATE_VALID_SIZE	1
518c2ecf20Sopenharmony_ci#define DPMAC_STATE_VALID_SHIFT	1
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistruct dpmac_cmd_set_link_state {
548c2ecf20Sopenharmony_ci	__le64 options;
558c2ecf20Sopenharmony_ci	__le32 rate;
568c2ecf20Sopenharmony_ci	__le32 pad0;
578c2ecf20Sopenharmony_ci	/* from lsb: up:1, state_valid:1 */
588c2ecf20Sopenharmony_ci	u8 state;
598c2ecf20Sopenharmony_ci	u8 pad1[7];
608c2ecf20Sopenharmony_ci	__le64 supported;
618c2ecf20Sopenharmony_ci	__le64 advertising;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistruct dpmac_cmd_get_counter {
658c2ecf20Sopenharmony_ci	u8 id;
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct dpmac_rsp_get_counter {
698c2ecf20Sopenharmony_ci	__le64 pad;
708c2ecf20Sopenharmony_ci	__le64 counter;
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#endif /* _FSL_DPMAC_CMD_H */
74