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