xref: /linux/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_mbox.h (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
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_VF_MBOX_H_
8 #define _OCTEP_VF_MBOX_H_
9 
10 /* When a new command is implemented, VF Mbox version should be bumped.
11  */
12 enum octep_pfvf_mbox_version {
13 	OCTEP_PFVF_MBOX_VERSION_V0,
14 	OCTEP_PFVF_MBOX_VERSION_V1,
15 	OCTEP_PFVF_MBOX_VERSION_V2
16 };
17 
18 #define OCTEP_PFVF_MBOX_VERSION_CURRENT OCTEP_PFVF_MBOX_VERSION_V2
19 
20 enum octep_pfvf_mbox_opcode {
21 	OCTEP_PFVF_MBOX_CMD_VERSION,
22 	OCTEP_PFVF_MBOX_CMD_SET_MTU,
23 	OCTEP_PFVF_MBOX_CMD_SET_MAC_ADDR,
24 	OCTEP_PFVF_MBOX_CMD_GET_MAC_ADDR,
25 	OCTEP_PFVF_MBOX_CMD_GET_LINK_INFO,
26 	OCTEP_PFVF_MBOX_CMD_GET_STATS,
27 	OCTEP_PFVF_MBOX_CMD_SET_RX_STATE,
28 	OCTEP_PFVF_MBOX_CMD_SET_LINK_STATUS,
29 	OCTEP_PFVF_MBOX_CMD_GET_LINK_STATUS,
30 	OCTEP_PFVF_MBOX_CMD_GET_MTU,
31 	OCTEP_PFVF_MBOX_CMD_DEV_REMOVE,
32 	OCTEP_PFVF_MBOX_CMD_GET_FW_INFO,
33 	OCTEP_PFVF_MBOX_CMD_SET_OFFLOADS,
34 	OCTEP_PFVF_MBOX_NOTIF_LINK_STATUS,
35 	OCTEP_PFVF_MBOX_CMD_MAX,
36 };
37 
38 enum octep_pfvf_mbox_word_type {
39 	OCTEP_PFVF_MBOX_TYPE_CMD,
40 	OCTEP_PFVF_MBOX_TYPE_RSP_ACK,
41 	OCTEP_PFVF_MBOX_TYPE_RSP_NACK,
42 };
43 
44 enum octep_pfvf_mbox_cmd_status {
45 	OCTEP_PFVF_MBOX_CMD_STATUS_NOT_SETUP = 1,
46 	OCTEP_PFVF_MBOX_CMD_STATUS_TIMEDOUT = 2,
47 	OCTEP_PFVF_MBOX_CMD_STATUS_NACK = 3,
48 	OCTEP_PFVF_MBOX_CMD_STATUS_BUSY = 4,
49 	OCTEP_PFVF_MBOX_CMD_STATUS_ERR = 5
50 };
51 
52 enum octep_pfvf_link_status {
53 	OCTEP_PFVF_LINK_STATUS_DOWN,
54 	OCTEP_PFVF_LINK_STATUS_UP,
55 };
56 
57 enum octep_pfvf_link_speed {
58 	OCTEP_PFVF_LINK_SPEED_NONE,
59 	OCTEP_PFVF_LINK_SPEED_1000,
60 	OCTEP_PFVF_LINK_SPEED_10000,
61 	OCTEP_PFVF_LINK_SPEED_25000,
62 	OCTEP_PFVF_LINK_SPEED_40000,
63 	OCTEP_PFVF_LINK_SPEED_50000,
64 	OCTEP_PFVF_LINK_SPEED_100000,
65 	OCTEP_PFVF_LINK_SPEED_LAST,
66 };
67 
68 enum octep_pfvf_link_duplex {
69 	OCTEP_PFVF_LINK_HALF_DUPLEX,
70 	OCTEP_PFVF_LINK_FULL_DUPLEX,
71 };
72 
73 enum octep_pfvf_link_autoneg {
74 	OCTEP_PFVF_LINK_AUTONEG,
75 	OCTEP_PFVF_LINK_FIXED,
76 };
77 
78 #define OCTEP_PFVF_MBOX_TIMEOUT_WAIT_COUNT  8000
79 #define OCTEP_PFVF_MBOX_TIMEOUT_WAIT_UDELAY 1000
80 #define OCTEP_PFVF_MBOX_MAX_RETRIES    2
81 #define OCTEP_PFVF_MBOX_VERSION        0
82 #define OCTEP_PFVF_MBOX_MAX_DATA_SIZE  6
83 #define OCTEP_PFVF_MBOX_MAX_DATA_BUF_SIZE 320
84 #define OCTEP_PFVF_MBOX_MORE_FRAG_FLAG 1
85 
86 union octep_pfvf_mbox_word {
87 	u64 u64;
88 	struct {
89 		u64 opcode:8;
90 		u64 type:2;
91 		u64 rsvd:6;
92 		u64 data:48;
93 	} s;
94 	struct {
95 		u64 opcode:8;
96 		u64 type:2;
97 		u64 frag:1;
98 		u64 rsvd:5;
99 		u8 data[6];
100 	} s_data;
101 	struct {
102 		u64 opcode:8;
103 		u64 type:2;
104 		u64 rsvd:6;
105 		u64 version:48;
106 	} s_version;
107 	struct {
108 		u64 opcode:8;
109 		u64 type:2;
110 		u64 rsvd:6;
111 		u8 mac_addr[6];
112 	} s_set_mac;
113 	struct {
114 		u64 opcode:8;
115 		u64 type:2;
116 		u64 rsvd:6;
117 		u64 mtu:48;
118 	} s_set_mtu;
119 	struct {
120 		u64 opcode:8;
121 		u64 type:2;
122 		u64 state:1;
123 		u64 rsvd:53;
124 	} s_link_state;
125 	struct {
126 		u64 opcode:8;
127 		u64 type:2;
128 		u64 status:1;
129 		u64 rsvd:53;
130 	} s_link_status;
131 	struct {
132 		u64 opcode:8;
133 		u64 type:2;
134 		u64 pkind:8;
135 		u64 fsz:8;
136 		u64 rx_ol_flags:16;
137 		u64 tx_ol_flags:16;
138 		u64 rsvd:6;
139 	} s_fw_info;
140 	struct {
141 		u64 opcode:8;
142 		u64 type:2;
143 		u64 rsvd:22;
144 		u64 rx_ol_flags:16;
145 		u64 tx_ol_flags:16;
146 	} s_offloads;
147 } __packed;
148 
149 int octep_vf_setup_mbox(struct octep_vf_device *oct);
150 void octep_vf_delete_mbox(struct octep_vf_device *oct);
151 int octep_vf_mbox_send_cmd(struct octep_vf_device *oct, union octep_pfvf_mbox_word cmd,
152 			   union octep_pfvf_mbox_word *rsp);
153 int octep_vf_mbox_bulk_read(struct octep_vf_device *oct, enum octep_pfvf_mbox_opcode opcode,
154 			    u8 *data, int *size);
155 int octep_vf_mbox_set_mtu(struct octep_vf_device *oct, int mtu);
156 int octep_vf_mbox_set_mac_addr(struct octep_vf_device *oct, char *mac_addr);
157 int octep_vf_mbox_get_mac_addr(struct octep_vf_device *oct, char *mac_addr);
158 int octep_vf_mbox_version_check(struct octep_vf_device *oct);
159 int octep_vf_mbox_set_rx_state(struct octep_vf_device *oct, bool state);
160 int octep_vf_mbox_set_link_status(struct octep_vf_device *oct, bool status);
161 int octep_vf_mbox_get_link_status(struct octep_vf_device *oct, u8 *oper_up);
162 int octep_vf_mbox_dev_remove(struct octep_vf_device *oct);
163 int octep_vf_mbox_get_fw_info(struct octep_vf_device *oct);
164 int octep_vf_mbox_set_offloads(struct octep_vf_device *oct, u16 tx_offloads, u16 rx_offloads);
165 
166 #endif
167