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