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 /* Supported commands */ 11 enum octep_ctrl_net_cmd { 12 OCTEP_CTRL_NET_CMD_GET = 0, 13 OCTEP_CTRL_NET_CMD_SET, 14 }; 15 16 /* Supported states */ 17 enum octep_ctrl_net_state { 18 OCTEP_CTRL_NET_STATE_DOWN = 0, 19 OCTEP_CTRL_NET_STATE_UP, 20 }; 21 22 /* Supported replies */ 23 enum octep_ctrl_net_reply { 24 OCTEP_CTRL_NET_REPLY_OK = 0, 25 OCTEP_CTRL_NET_REPLY_GENERIC_FAIL, 26 OCTEP_CTRL_NET_REPLY_INVALID_PARAM, 27 }; 28 29 /* Supported host to fw commands */ 30 enum octep_ctrl_net_h2f_cmd { 31 OCTEP_CTRL_NET_H2F_CMD_INVALID = 0, 32 OCTEP_CTRL_NET_H2F_CMD_MTU, 33 OCTEP_CTRL_NET_H2F_CMD_MAC, 34 OCTEP_CTRL_NET_H2F_CMD_GET_IF_STATS, 35 OCTEP_CTRL_NET_H2F_CMD_GET_XSTATS, 36 OCTEP_CTRL_NET_H2F_CMD_GET_Q_STATS, 37 OCTEP_CTRL_NET_H2F_CMD_LINK_STATUS, 38 OCTEP_CTRL_NET_H2F_CMD_RX_STATE, 39 OCTEP_CTRL_NET_H2F_CMD_LINK_INFO, 40 }; 41 42 /* Supported fw to host commands */ 43 enum octep_ctrl_net_f2h_cmd { 44 OCTEP_CTRL_NET_F2H_CMD_INVALID = 0, 45 OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS, 46 }; 47 48 struct octep_ctrl_net_req_hdr { 49 /* sender id */ 50 u16 sender; 51 /* receiver id */ 52 u16 receiver; 53 /* octep_ctrl_net_h2t_cmd */ 54 u16 cmd; 55 /* reserved */ 56 u16 rsvd0; 57 }; 58 59 /* get/set mtu request */ 60 struct octep_ctrl_net_h2f_req_cmd_mtu { 61 /* enum octep_ctrl_net_cmd */ 62 u16 cmd; 63 /* 0-65535 */ 64 u16 val; 65 }; 66 67 /* get/set mac request */ 68 struct octep_ctrl_net_h2f_req_cmd_mac { 69 /* enum octep_ctrl_net_cmd */ 70 u16 cmd; 71 /* xx:xx:xx:xx:xx:xx */ 72 u8 addr[ETH_ALEN]; 73 }; 74 75 /* get if_stats, xstats, q_stats request */ 76 struct octep_ctrl_net_h2f_req_cmd_get_stats { 77 /* offset into barmem where fw should copy over stats */ 78 u32 offset; 79 }; 80 81 /* get/set link state, rx state */ 82 struct octep_ctrl_net_h2f_req_cmd_state { 83 /* enum octep_ctrl_net_cmd */ 84 u16 cmd; 85 /* enum octep_ctrl_net_state */ 86 u16 state; 87 }; 88 89 /* link info */ 90 struct octep_ctrl_net_link_info { 91 /* Bitmap of Supported link speeds/modes */ 92 u64 supported_modes; 93 /* Bitmap of Advertised link speeds/modes */ 94 u64 advertised_modes; 95 /* Autonegotation state; bit 0=disabled; bit 1=enabled */ 96 u8 autoneg; 97 /* Pause frames setting. bit 0=disabled; bit 1=enabled */ 98 u8 pause; 99 /* Negotiated link speed in Mbps */ 100 u32 speed; 101 }; 102 103 /* get/set link info */ 104 struct octep_ctrl_net_h2f_req_cmd_link_info { 105 /* enum octep_ctrl_net_cmd */ 106 u16 cmd; 107 /* struct octep_ctrl_net_link_info */ 108 struct octep_ctrl_net_link_info info; 109 }; 110 111 /* Host to fw request data */ 112 struct octep_ctrl_net_h2f_req { 113 struct octep_ctrl_net_req_hdr hdr; 114 union { 115 struct octep_ctrl_net_h2f_req_cmd_mtu mtu; 116 struct octep_ctrl_net_h2f_req_cmd_mac mac; 117 struct octep_ctrl_net_h2f_req_cmd_get_stats get_stats; 118 struct octep_ctrl_net_h2f_req_cmd_state link; 119 struct octep_ctrl_net_h2f_req_cmd_state rx; 120 struct octep_ctrl_net_h2f_req_cmd_link_info link_info; 121 }; 122 } __packed; 123 124 struct octep_ctrl_net_resp_hdr { 125 /* sender id */ 126 u16 sender; 127 /* receiver id */ 128 u16 receiver; 129 /* octep_ctrl_net_h2t_cmd */ 130 u16 cmd; 131 /* octep_ctrl_net_reply */ 132 u16 reply; 133 }; 134 135 /* get mtu response */ 136 struct octep_ctrl_net_h2f_resp_cmd_mtu { 137 /* 0-65535 */ 138 u16 val; 139 }; 140 141 /* get mac response */ 142 struct octep_ctrl_net_h2f_resp_cmd_mac { 143 /* xx:xx:xx:xx:xx:xx */ 144 u8 addr[ETH_ALEN]; 145 }; 146 147 /* get link state, rx state response */ 148 struct octep_ctrl_net_h2f_resp_cmd_state { 149 /* enum octep_ctrl_net_state */ 150 u16 state; 151 }; 152 153 /* Host to fw response data */ 154 struct octep_ctrl_net_h2f_resp { 155 struct octep_ctrl_net_resp_hdr hdr; 156 union { 157 struct octep_ctrl_net_h2f_resp_cmd_mtu mtu; 158 struct octep_ctrl_net_h2f_resp_cmd_mac mac; 159 struct octep_ctrl_net_h2f_resp_cmd_state link; 160 struct octep_ctrl_net_h2f_resp_cmd_state rx; 161 struct octep_ctrl_net_link_info link_info; 162 }; 163 } __packed; 164 165 /* link state notofication */ 166 struct octep_ctrl_net_f2h_req_cmd_state { 167 /* enum octep_ctrl_net_state */ 168 u16 state; 169 }; 170 171 /* Fw to host request data */ 172 struct octep_ctrl_net_f2h_req { 173 struct octep_ctrl_net_req_hdr hdr; 174 union { 175 struct octep_ctrl_net_f2h_req_cmd_state link; 176 }; 177 }; 178 179 /* Fw to host response data */ 180 struct octep_ctrl_net_f2h_resp { 181 struct octep_ctrl_net_resp_hdr hdr; 182 }; 183 184 /* Size of host to fw octep_ctrl_mbox queue element */ 185 union octep_ctrl_net_h2f_data_sz { 186 struct octep_ctrl_net_h2f_req h2f_req; 187 struct octep_ctrl_net_h2f_resp h2f_resp; 188 }; 189 190 /* Size of fw to host octep_ctrl_mbox queue element */ 191 union octep_ctrl_net_f2h_data_sz { 192 struct octep_ctrl_net_f2h_req f2h_req; 193 struct octep_ctrl_net_f2h_resp f2h_resp; 194 }; 195 196 /* size of host to fw data in words */ 197 #define OCTEP_CTRL_NET_H2F_DATA_SZW ((sizeof(union octep_ctrl_net_h2f_data_sz)) / \ 198 (sizeof(unsigned long))) 199 200 /* size of fw to host data in words */ 201 #define OCTEP_CTRL_NET_F2H_DATA_SZW ((sizeof(union octep_ctrl_net_f2h_data_sz)) / \ 202 (sizeof(unsigned long))) 203 204 /* size in words of get/set mtu request */ 205 #define OCTEP_CTRL_NET_H2F_MTU_REQ_SZW 2 206 /* size in words of get/set mac request */ 207 #define OCTEP_CTRL_NET_H2F_MAC_REQ_SZW 2 208 /* size in words of get stats request */ 209 #define OCTEP_CTRL_NET_H2F_GET_STATS_REQ_SZW 2 210 /* size in words of get/set state request */ 211 #define OCTEP_CTRL_NET_H2F_STATE_REQ_SZW 2 212 /* size in words of get/set link info request */ 213 #define OCTEP_CTRL_NET_H2F_LINK_INFO_REQ_SZW 4 214 215 /* size in words of get mtu response */ 216 #define OCTEP_CTRL_NET_H2F_GET_MTU_RESP_SZW 2 217 /* size in words of set mtu response */ 218 #define OCTEP_CTRL_NET_H2F_SET_MTU_RESP_SZW 1 219 /* size in words of get mac response */ 220 #define OCTEP_CTRL_NET_H2F_GET_MAC_RESP_SZW 2 221 /* size in words of set mac response */ 222 #define OCTEP_CTRL_NET_H2F_SET_MAC_RESP_SZW 1 223 /* size in words of get state request */ 224 #define OCTEP_CTRL_NET_H2F_GET_STATE_RESP_SZW 2 225 /* size in words of set state request */ 226 #define OCTEP_CTRL_NET_H2F_SET_STATE_RESP_SZW 1 227 /* size in words of get link info request */ 228 #define OCTEP_CTRL_NET_H2F_GET_LINK_INFO_RESP_SZW 4 229 /* size in words of set link info request */ 230 #define OCTEP_CTRL_NET_H2F_SET_LINK_INFO_RESP_SZW 1 231 232 /** Get link status from firmware. 233 * 234 * @param oct: non-null pointer to struct octep_device. 235 * 236 * return value: link status 0=down, 1=up. 237 */ 238 int octep_get_link_status(struct octep_device *oct); 239 240 /** Set link status in firmware. 241 * 242 * @param oct: non-null pointer to struct octep_device. 243 * @param up: boolean status. 244 */ 245 void octep_set_link_status(struct octep_device *oct, bool up); 246 247 /** Set rx state in firmware. 248 * 249 * @param oct: non-null pointer to struct octep_device. 250 * @param up: boolean status. 251 */ 252 void octep_set_rx_state(struct octep_device *oct, bool up); 253 254 /** Get mac address from firmware. 255 * 256 * @param oct: non-null pointer to struct octep_device. 257 * @param addr: non-null pointer to mac address. 258 * 259 * return value: 0 on success, -errno on failure. 260 */ 261 int octep_get_mac_addr(struct octep_device *oct, u8 *addr); 262 263 /** Set mac address in firmware. 264 * 265 * @param oct: non-null pointer to struct octep_device. 266 * @param addr: non-null pointer to mac address. 267 */ 268 int octep_set_mac_addr(struct octep_device *oct, u8 *addr); 269 270 /** Set mtu in firmware. 271 * 272 * @param oct: non-null pointer to struct octep_device. 273 * @param mtu: mtu. 274 */ 275 int octep_set_mtu(struct octep_device *oct, int mtu); 276 277 /** Get interface statistics from firmware. 278 * 279 * @param oct: non-null pointer to struct octep_device. 280 * 281 * return value: 0 on success, -errno on failure. 282 */ 283 int octep_get_if_stats(struct octep_device *oct); 284 285 /** Get link info from firmware. 286 * 287 * @param oct: non-null pointer to struct octep_device. 288 * 289 * return value: 0 on success, -errno on failure. 290 */ 291 int octep_get_link_info(struct octep_device *oct); 292 293 /** Set link info in firmware. 294 * 295 * @param oct: non-null pointer to struct octep_device. 296 */ 297 int octep_set_link_info(struct octep_device *oct, struct octep_iface_link_info *link_info); 298 299 #endif /* __OCTEP_CTRL_NET_H__ */ 300