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 */ 15 enum octep_ctrl_net_cmd { 16 OCTEP_CTRL_NET_CMD_GET = 0, 17 OCTEP_CTRL_NET_CMD_SET, 18 }; 19 20 /* Supported states */ 21 enum octep_ctrl_net_state { 22 OCTEP_CTRL_NET_STATE_DOWN = 0, 23 OCTEP_CTRL_NET_STATE_UP, 24 }; 25 26 /* Supported replies */ 27 enum 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 */ 34 enum 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_MAX 45 }; 46 47 /* Supported fw to host commands */ 48 enum octep_ctrl_net_f2h_cmd { 49 OCTEP_CTRL_NET_F2H_CMD_INVALID = 0, 50 OCTEP_CTRL_NET_F2H_CMD_LINK_STATUS, 51 OCTEP_CTRL_NET_F2H_CMD_MAX 52 }; 53 54 union octep_ctrl_net_req_hdr { 55 u64 words[1]; 56 struct { 57 /* sender id */ 58 u16 sender; 59 /* receiver id */ 60 u16 receiver; 61 /* octep_ctrl_net_h2t_cmd */ 62 u16 cmd; 63 /* reserved */ 64 u16 rsvd0; 65 } s; 66 }; 67 68 /* get/set mtu request */ 69 struct octep_ctrl_net_h2f_req_cmd_mtu { 70 /* enum octep_ctrl_net_cmd */ 71 u16 cmd; 72 /* 0-65535 */ 73 u16 val; 74 }; 75 76 /* get/set mac request */ 77 struct octep_ctrl_net_h2f_req_cmd_mac { 78 /* enum octep_ctrl_net_cmd */ 79 u16 cmd; 80 /* xx:xx:xx:xx:xx:xx */ 81 u8 addr[ETH_ALEN]; 82 }; 83 84 /* get/set link state, rx state */ 85 struct octep_ctrl_net_h2f_req_cmd_state { 86 /* enum octep_ctrl_net_cmd */ 87 u16 cmd; 88 /* enum octep_ctrl_net_state */ 89 u16 state; 90 }; 91 92 /* link info */ 93 struct octep_ctrl_net_link_info { 94 /* Bitmap of Supported link speeds/modes */ 95 u64 supported_modes; 96 /* Bitmap of Advertised link speeds/modes */ 97 u64 advertised_modes; 98 /* Autonegotation state; bit 0=disabled; bit 1=enabled */ 99 u8 autoneg; 100 /* Pause frames setting. bit 0=disabled; bit 1=enabled */ 101 u8 pause; 102 /* Negotiated link speed in Mbps */ 103 u32 speed; 104 }; 105 106 /* get/set link info */ 107 struct octep_ctrl_net_h2f_req_cmd_link_info { 108 /* enum octep_ctrl_net_cmd */ 109 u16 cmd; 110 /* struct octep_ctrl_net_link_info */ 111 struct octep_ctrl_net_link_info info; 112 }; 113 114 /* Host to fw request data */ 115 struct octep_ctrl_net_h2f_req { 116 union octep_ctrl_net_req_hdr hdr; 117 union { 118 struct octep_ctrl_net_h2f_req_cmd_mtu mtu; 119 struct octep_ctrl_net_h2f_req_cmd_mac mac; 120 struct octep_ctrl_net_h2f_req_cmd_state link; 121 struct octep_ctrl_net_h2f_req_cmd_state rx; 122 struct octep_ctrl_net_h2f_req_cmd_link_info link_info; 123 }; 124 } __packed; 125 126 union octep_ctrl_net_resp_hdr { 127 u64 words[1]; 128 struct { 129 /* sender id */ 130 u16 sender; 131 /* receiver id */ 132 u16 receiver; 133 /* octep_ctrl_net_h2t_cmd */ 134 u16 cmd; 135 /* octep_ctrl_net_reply */ 136 u16 reply; 137 } s; 138 }; 139 140 /* get mtu response */ 141 struct octep_ctrl_net_h2f_resp_cmd_mtu { 142 /* 0-65535 */ 143 u16 val; 144 }; 145 146 /* get mac response */ 147 struct octep_ctrl_net_h2f_resp_cmd_mac { 148 /* xx:xx:xx:xx:xx:xx */ 149 u8 addr[ETH_ALEN]; 150 }; 151 152 /* get if_stats, xstats, q_stats request */ 153 struct octep_ctrl_net_h2f_resp_cmd_get_stats { 154 struct octep_iface_rx_stats rx_stats; 155 struct octep_iface_tx_stats tx_stats; 156 }; 157 158 /* get link state, rx state response */ 159 struct octep_ctrl_net_h2f_resp_cmd_state { 160 /* enum octep_ctrl_net_state */ 161 u16 state; 162 }; 163 164 /* Host to fw response data */ 165 struct octep_ctrl_net_h2f_resp { 166 union octep_ctrl_net_resp_hdr hdr; 167 union { 168 struct octep_ctrl_net_h2f_resp_cmd_mtu mtu; 169 struct octep_ctrl_net_h2f_resp_cmd_mac mac; 170 struct octep_ctrl_net_h2f_resp_cmd_get_stats if_stats; 171 struct octep_ctrl_net_h2f_resp_cmd_state link; 172 struct octep_ctrl_net_h2f_resp_cmd_state rx; 173 struct octep_ctrl_net_link_info link_info; 174 }; 175 } __packed; 176 177 /* link state notofication */ 178 struct octep_ctrl_net_f2h_req_cmd_state { 179 /* enum octep_ctrl_net_state */ 180 u16 state; 181 }; 182 183 /* Fw to host request data */ 184 struct octep_ctrl_net_f2h_req { 185 union octep_ctrl_net_req_hdr hdr; 186 union { 187 struct octep_ctrl_net_f2h_req_cmd_state link; 188 }; 189 }; 190 191 /* Fw to host response data */ 192 struct octep_ctrl_net_f2h_resp { 193 union octep_ctrl_net_resp_hdr hdr; 194 }; 195 196 /* Max data size to be transferred over mbox */ 197 union octep_ctrl_net_max_data { 198 struct octep_ctrl_net_h2f_req h2f_req; 199 struct octep_ctrl_net_h2f_resp h2f_resp; 200 struct octep_ctrl_net_f2h_req f2h_req; 201 struct octep_ctrl_net_f2h_resp f2h_resp; 202 }; 203 204 struct octep_ctrl_net_wait_data { 205 struct list_head list; 206 int done; 207 struct octep_ctrl_mbox_msg msg; 208 union { 209 struct octep_ctrl_net_h2f_req req; 210 struct octep_ctrl_net_h2f_resp resp; 211 } data; 212 }; 213 214 /** Initialize data for ctrl net. 215 * 216 * @param oct: non-null pointer to struct octep_device. 217 * 218 * return value: 0 on success, -errno on error. 219 */ 220 int octep_ctrl_net_init(struct octep_device *oct); 221 222 /** Get link status from firmware. 223 * 224 * @param oct: non-null pointer to struct octep_device. 225 * @param vfid: Index of virtual function. 226 * 227 * return value: link status 0=down, 1=up. 228 */ 229 int octep_ctrl_net_get_link_status(struct octep_device *oct, int vfid); 230 231 /** Set link status in firmware. 232 * 233 * @param oct: non-null pointer to struct octep_device. 234 * @param vfid: Index of virtual function. 235 * @param up: boolean status. 236 * @param wait_for_response: poll for response. 237 * 238 * return value: 0 on success, -errno on failure 239 */ 240 int octep_ctrl_net_set_link_status(struct octep_device *oct, int vfid, bool up, 241 bool wait_for_response); 242 243 /** Set rx state in firmware. 244 * 245 * @param oct: non-null pointer to struct octep_device. 246 * @param vfid: Index of virtual function. 247 * @param up: boolean status. 248 * @param wait_for_response: poll for response. 249 * 250 * return value: 0 on success, -errno on failure. 251 */ 252 int octep_ctrl_net_set_rx_state(struct octep_device *oct, int vfid, bool up, 253 bool wait_for_response); 254 255 /** Get mac address from firmware. 256 * 257 * @param oct: non-null pointer to struct octep_device. 258 * @param vfid: Index of virtual function. 259 * @param addr: non-null pointer to mac address. 260 * 261 * return value: 0 on success, -errno on failure. 262 */ 263 int octep_ctrl_net_get_mac_addr(struct octep_device *oct, int vfid, u8 *addr); 264 265 /** Set mac address in firmware. 266 * 267 * @param oct: non-null pointer to struct octep_device. 268 * @param vfid: Index of virtual function. 269 * @param addr: non-null pointer to mac address. 270 * @param wait_for_response: poll for response. 271 * 272 * return value: 0 on success, -errno on failure. 273 */ 274 int octep_ctrl_net_set_mac_addr(struct octep_device *oct, int vfid, u8 *addr, 275 bool wait_for_response); 276 277 /** Set mtu in firmware. 278 * 279 * @param oct: non-null pointer to struct octep_device. 280 * @param vfid: Index of virtual function. 281 * @param mtu: mtu. 282 * @param wait_for_response: poll for response. 283 * 284 * return value: 0 on success, -errno on failure. 285 */ 286 int octep_ctrl_net_set_mtu(struct octep_device *oct, int vfid, int mtu, 287 bool wait_for_response); 288 289 /** Get interface statistics from firmware. 290 * 291 * @param oct: non-null pointer to struct octep_device. 292 * @param vfid: Index of virtual function. 293 * @param rx_stats: non-null pointer struct octep_iface_rx_stats. 294 * @param tx_stats: non-null pointer struct octep_iface_tx_stats. 295 * 296 * return value: 0 on success, -errno on failure. 297 */ 298 int octep_ctrl_net_get_if_stats(struct octep_device *oct, int vfid, 299 struct octep_iface_rx_stats *rx_stats, 300 struct octep_iface_tx_stats *tx_stats); 301 302 /** Get link info from firmware. 303 * 304 * @param oct: non-null pointer to struct octep_device. 305 * @param vfid: Index of virtual function. 306 * @param link_info: non-null pointer to struct octep_iface_link_info. 307 * 308 * return value: 0 on success, -errno on failure. 309 */ 310 int octep_ctrl_net_get_link_info(struct octep_device *oct, int vfid, 311 struct octep_iface_link_info *link_info); 312 313 /** Set link info in firmware. 314 * 315 * @param oct: non-null pointer to struct octep_device. 316 * @param vfid: Index of virtual function. 317 * @param link_info: non-null pointer to struct octep_iface_link_info. 318 * @param wait_for_response: poll for response. 319 * 320 * return value: 0 on success, -errno on failure. 321 */ 322 int octep_ctrl_net_set_link_info(struct octep_device *oct, 323 int vfid, 324 struct octep_iface_link_info *link_info, 325 bool wait_for_response); 326 327 /** Poll for firmware messages and process them. 328 * 329 * @param oct: non-null pointer to struct octep_device. 330 */ 331 void octep_ctrl_net_recv_fw_messages(struct octep_device *oct); 332 333 /** Uninitialize data for ctrl net. 334 * 335 * @param oct: non-null pointer to struct octep_device. 336 * 337 * return value: 0 on success, -errno on error. 338 */ 339 int octep_ctrl_net_uninit(struct octep_device *oct); 340 341 #endif /* __OCTEP_CTRL_NET_H__ */ 342