171947923SIoana Ciornei/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
271947923SIoana Ciornei/* Copyright 2013-2016 Freescale Semiconductor Inc.
371947923SIoana Ciornei * Copyright 2019 NXP
471947923SIoana Ciornei */
571947923SIoana Ciornei#ifndef _FSL_DPMAC_CMD_H
671947923SIoana Ciornei#define _FSL_DPMAC_CMD_H
771947923SIoana Ciornei
871947923SIoana Ciornei/* DPMAC Version */
971947923SIoana Ciornei#define DPMAC_VER_MAJOR				4
1071947923SIoana Ciornei#define DPMAC_VER_MINOR				4
1171947923SIoana Ciornei#define DPMAC_CMD_BASE_VERSION			1
1271947923SIoana Ciornei#define DPMAC_CMD_2ND_VERSION			2
1371947923SIoana Ciornei#define DPMAC_CMD_ID_OFFSET			4
1471947923SIoana Ciornei
1571947923SIoana Ciornei#define DPMAC_CMD(id)	(((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_BASE_VERSION)
1671947923SIoana Ciornei#define DPMAC_CMD_V2(id) (((id) << DPMAC_CMD_ID_OFFSET) | DPMAC_CMD_2ND_VERSION)
1771947923SIoana Ciornei
1871947923SIoana Ciornei/* Command IDs */
1971947923SIoana Ciornei#define DPMAC_CMDID_CLOSE		DPMAC_CMD(0x800)
2071947923SIoana Ciornei#define DPMAC_CMDID_OPEN		DPMAC_CMD(0x80c)
2171947923SIoana Ciornei
2271947923SIoana Ciornei#define DPMAC_CMDID_GET_ATTR		DPMAC_CMD(0x004)
2371947923SIoana Ciornei#define DPMAC_CMDID_SET_LINK_STATE	DPMAC_CMD_V2(0x0c3)
2471947923SIoana Ciornei
25991df1fbSIoana Ciornei#define DPMAC_CMDID_GET_COUNTER		DPMAC_CMD(0x0c4)
26991df1fbSIoana Ciornei
2771947923SIoana Ciornei/* Macros for accessing command fields smaller than 1byte */
2871947923SIoana Ciornei#define DPMAC_MASK(field)        \
2971947923SIoana Ciornei	GENMASK(DPMAC_##field##_SHIFT + DPMAC_##field##_SIZE - 1, \
3071947923SIoana Ciornei		DPMAC_##field##_SHIFT)
3171947923SIoana Ciornei
3271947923SIoana Ciornei#define dpmac_set_field(var, field, val) \
3371947923SIoana Ciornei	((var) |= (((val) << DPMAC_##field##_SHIFT) & DPMAC_MASK(field)))
3471947923SIoana Ciornei#define dpmac_get_field(var, field)      \
3571947923SIoana Ciornei	(((var) & DPMAC_MASK(field)) >> DPMAC_##field##_SHIFT)
3671947923SIoana Ciornei
3771947923SIoana Ciorneistruct dpmac_cmd_open {
3871947923SIoana Ciornei	__le32 dpmac_id;
3971947923SIoana Ciornei};
4071947923SIoana Ciornei
4171947923SIoana Ciorneistruct dpmac_rsp_get_attributes {
4271947923SIoana Ciornei	u8 eth_if;
4371947923SIoana Ciornei	u8 link_type;
4471947923SIoana Ciornei	__le16 id;
4571947923SIoana Ciornei	__le32 max_rate;
4671947923SIoana Ciornei};
4771947923SIoana Ciornei
4871947923SIoana Ciornei#define DPMAC_STATE_SIZE	1
4971947923SIoana Ciornei#define DPMAC_STATE_SHIFT	0
5071947923SIoana Ciornei#define DPMAC_STATE_VALID_SIZE	1
5171947923SIoana Ciornei#define DPMAC_STATE_VALID_SHIFT	1
5271947923SIoana Ciornei
5371947923SIoana Ciorneistruct dpmac_cmd_set_link_state {
5471947923SIoana Ciornei	__le64 options;
5571947923SIoana Ciornei	__le32 rate;
5671947923SIoana Ciornei	__le32 pad0;
5771947923SIoana Ciornei	/* from lsb: up:1, state_valid:1 */
5871947923SIoana Ciornei	u8 state;
5971947923SIoana Ciornei	u8 pad1[7];
6071947923SIoana Ciornei	__le64 supported;
6171947923SIoana Ciornei	__le64 advertising;
6271947923SIoana Ciornei};
6371947923SIoana Ciornei
64991df1fbSIoana Ciorneistruct dpmac_cmd_get_counter {
65991df1fbSIoana Ciornei	u8 id;
66991df1fbSIoana Ciornei};
67991df1fbSIoana Ciornei
68991df1fbSIoana Ciorneistruct dpmac_rsp_get_counter {
69a1285927SYangbo Lu	__le64 pad;
70a1285927SYangbo Lu	__le64 counter;
71991df1fbSIoana Ciornei};
72991df1fbSIoana Ciornei
7371947923SIoana Ciornei#endif /* _FSL_DPMAC_CMD_H */
74