1 /* 2 * Freescale Layerscape MC I/O wrapper 3 * 4 * Copyright (C) 2015 Freescale Semiconductor, Inc. 5 * Author: Prabhakar Kushwaha <prabhakar@freescale.com> 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #ifndef __FSL_DPMAC_H 11 #define __FSL_DPMAC_H 12 13 /* DPMAC Version */ 14 #define DPMAC_VER_MAJOR 3 15 #define DPMAC_VER_MINOR 1 16 17 /* Command IDs */ 18 #define DPMAC_CMDID_CLOSE 0x800 19 #define DPMAC_CMDID_OPEN 0x80c 20 #define DPMAC_CMDID_CREATE 0x90c 21 #define DPMAC_CMDID_DESTROY 0x900 22 23 #define DPMAC_CMDID_GET_ATTR 0x004 24 #define DPMAC_CMDID_RESET 0x005 25 26 #define DPMAC_CMDID_MDIO_READ 0x0c0 27 #define DPMAC_CMDID_MDIO_WRITE 0x0c1 28 #define DPMAC_CMDID_GET_LINK_CFG 0x0c2 29 #define DPMAC_CMDID_SET_LINK_STATE 0x0c3 30 #define DPMAC_CMDID_GET_COUNTER 0x0c4 31 32 /* cmd, param, offset, width, type, arg_name */ 33 #define DPMAC_CMD_CREATE(cmd, cfg) \ 34 MC_CMD_OP(cmd, 0, 0, 32, int, cfg->mac_id) 35 36 /* cmd, param, offset, width, type, arg_name */ 37 #define DPMAC_CMD_OPEN(cmd, dpmac_id) \ 38 MC_CMD_OP(cmd, 0, 0, 32, int, dpmac_id) 39 40 /* cmd, param, offset, width, type, arg_name */ 41 #define DPMAC_RSP_GET_ATTRIBUTES(cmd, attr) \ 42 do { \ 43 MC_RSP_OP(cmd, 0, 0, 32, int, attr->phy_id);\ 44 MC_RSP_OP(cmd, 0, 32, 32, int, attr->id);\ 45 MC_RSP_OP(cmd, 1, 0, 16, uint16_t, attr->version.major);\ 46 MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\ 47 MC_RSP_OP(cmd, 1, 32, 8, enum dpmac_link_type, attr->link_type);\ 48 MC_RSP_OP(cmd, 1, 40, 8, enum dpmac_eth_if, attr->eth_if);\ 49 MC_RSP_OP(cmd, 2, 0, 32, uint32_t, attr->max_rate);\ 50 } while (0) 51 52 /* cmd, param, offset, width, type, arg_name */ 53 #define DPMAC_CMD_MDIO_READ(cmd, cfg) \ 54 do { \ 55 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \ 56 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \ 57 } while (0) 58 59 /* cmd, param, offset, width, type, arg_name */ 60 #define DPMAC_RSP_MDIO_READ(cmd, data) \ 61 MC_RSP_OP(cmd, 0, 16, 16, uint16_t, data) 62 63 /* cmd, param, offset, width, type, arg_name */ 64 #define DPMAC_CMD_MDIO_WRITE(cmd, cfg) \ 65 do { \ 66 MC_CMD_OP(cmd, 0, 0, 8, uint8_t, cfg->phy_addr); \ 67 MC_CMD_OP(cmd, 0, 8, 8, uint8_t, cfg->reg); \ 68 MC_CMD_OP(cmd, 0, 16, 16, uint16_t, cfg->data); \ 69 } while (0) 70 71 /* cmd, param, offset, width, type, arg_name */ 72 #define DPMAC_RSP_GET_LINK_CFG(cmd, cfg) \ 73 do { \ 74 MC_RSP_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \ 75 MC_RSP_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \ 76 } while (0) 77 78 /* cmd, param, offset, width, type, arg_name */ 79 #define DPMAC_CMD_SET_LINK_STATE(cmd, cfg) \ 80 do { \ 81 MC_CMD_OP(cmd, 0, 0, 64, uint64_t, cfg->options); \ 82 MC_CMD_OP(cmd, 1, 0, 32, uint32_t, cfg->rate); \ 83 MC_CMD_OP(cmd, 2, 0, 1, int, cfg->up); \ 84 } while (0) 85 86 /* cmd, param, offset, width, type, arg_name */ 87 #define DPMAC_CMD_GET_COUNTER(cmd, type) \ 88 MC_CMD_OP(cmd, 0, 0, 8, enum dpmac_counter, type) 89 90 /* cmd, param, offset, width, type, arg_name */ 91 #define DPMAC_RSP_GET_COUNTER(cmd, counter) \ 92 MC_RSP_OP(cmd, 1, 0, 64, uint64_t, counter) 93 94 /* Data Path MAC API 95 * Contains initialization APIs and runtime control APIs for DPMAC 96 */ 97 98 struct fsl_mc_io; 99 100 /** 101 * dpmac_open() - Open a control session for the specified object. 102 * @mc_io: Pointer to MC portal's I/O object 103 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 104 * @dpmac_id: DPMAC unique ID 105 * @token: Returned token; use in subsequent API calls 106 * 107 * This function can be used to open a control session for an 108 * already created object; an object may have been declared in 109 * the DPL or by calling the dpmac_create function. 110 * This function returns a unique authentication token, 111 * associated with the specific object ID and the specific MC 112 * portal; this token must be used in all subsequent commands for 113 * this specific object 114 * 115 * Return: '0' on Success; Error code otherwise. 116 */ 117 int dpmac_open(struct fsl_mc_io *mc_io, 118 uint32_t cmd_flags, 119 int dpmac_id, 120 uint16_t *token); 121 122 /** 123 * dpmac_close() - Close the control session of the object 124 * @mc_io: Pointer to MC portal's I/O object 125 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 126 * @token: Token of DPMAC object 127 * 128 * After this function is called, no further operations are 129 * allowed on the object without opening a new control session. 130 * 131 * Return: '0' on Success; Error code otherwise. 132 */ 133 int dpmac_close(struct fsl_mc_io *mc_io, 134 uint32_t cmd_flags, 135 uint16_t token); 136 137 /** 138 * enum dpmac_link_type - DPMAC link type 139 * @DPMAC_LINK_TYPE_NONE: No link 140 * @DPMAC_LINK_TYPE_FIXED: Link is fixed type 141 * @DPMAC_LINK_TYPE_PHY: Link by PHY ID 142 * @DPMAC_LINK_TYPE_BACKPLANE: Backplane link type 143 */ 144 enum dpmac_link_type { 145 DPMAC_LINK_TYPE_NONE, 146 DPMAC_LINK_TYPE_FIXED, 147 DPMAC_LINK_TYPE_PHY, 148 DPMAC_LINK_TYPE_BACKPLANE 149 }; 150 151 /** 152 * enum dpmac_eth_if - DPMAC Ethrnet interface 153 * @DPMAC_ETH_IF_MII: MII interface 154 * @DPMAC_ETH_IF_RMII: RMII interface 155 * @DPMAC_ETH_IF_SMII: SMII interface 156 * @DPMAC_ETH_IF_GMII: GMII interface 157 * @DPMAC_ETH_IF_RGMII: RGMII interface 158 * @DPMAC_ETH_IF_SGMII: SGMII interface 159 * @DPMAC_ETH_IF_QSGMII: QSGMII interface 160 * @DPMAC_ETH_IF_XAUI: XAUI interface 161 * @DPMAC_ETH_IF_XFI: XFI interface 162 */ 163 enum dpmac_eth_if { 164 DPMAC_ETH_IF_MII, 165 DPMAC_ETH_IF_RMII, 166 DPMAC_ETH_IF_SMII, 167 DPMAC_ETH_IF_GMII, 168 DPMAC_ETH_IF_RGMII, 169 DPMAC_ETH_IF_SGMII, 170 DPMAC_ETH_IF_QSGMII, 171 DPMAC_ETH_IF_XAUI, 172 DPMAC_ETH_IF_XFI 173 }; 174 175 /** 176 * struct dpmac_cfg - Structure representing DPMAC configuration 177 * @mac_id: Represents the Hardware MAC ID; in case of multiple WRIOP, 178 * the MAC IDs are continuous. 179 * For example: 2 WRIOPs, 16 MACs in each: 180 * MAC IDs for the 1st WRIOP: 1-16, 181 * MAC IDs for the 2nd WRIOP: 17-32. 182 */ 183 struct dpmac_cfg { 184 int mac_id; 185 }; 186 187 /** 188 * dpmac_create() - Create the DPMAC object. 189 * @mc_io: Pointer to MC portal's I/O object 190 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 191 * @cfg: Configuration structure 192 * @token: Returned token; use in subsequent API calls 193 * 194 * Create the DPMAC object, allocate required resources and 195 * perform required initialization. 196 * 197 * The object can be created either by declaring it in the 198 * DPL file, or by calling this function. 199 * This function returns a unique authentication token, 200 * associated with the specific object ID and the specific MC 201 * portal; this token must be used in all subsequent calls to 202 * this specific object. For objects that are created using the 203 * DPL file, call dpmac_open function to get an authentication 204 * token first. 205 * 206 * Return: '0' on Success; Error code otherwise. 207 */ 208 int dpmac_create(struct fsl_mc_io *mc_io, 209 uint32_t cmd_flags, 210 const struct dpmac_cfg *cfg, 211 uint16_t *token); 212 213 /** 214 * dpmac_destroy() - Destroy the DPMAC object and release all its resources. 215 * @mc_io: Pointer to MC portal's I/O object 216 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 217 * @token: Token of DPMAC object 218 * 219 * Return: '0' on Success; error code otherwise. 220 */ 221 int dpmac_destroy(struct fsl_mc_io *mc_io, 222 uint32_t cmd_flags, 223 uint16_t token); 224 225 /* DPMAC IRQ Index and Events */ 226 227 /* IRQ index */ 228 #define DPMAC_IRQ_INDEX 0 229 /* IRQ event - indicates a change in link state */ 230 #define DPMAC_IRQ_EVENT_LINK_CFG_REQ 0x00000001 231 /* irq event - Indicates that the link state changed */ 232 #define DPMAC_IRQ_EVENT_LINK_CHANGED 0x00000002 233 234 /** 235 * struct dpmac_attr - Structure representing DPMAC attributes 236 * @id: DPMAC object ID 237 * @phy_id: PHY ID 238 * @link_type: link type 239 * @eth_if: Ethernet interface 240 * @max_rate: Maximum supported rate - in Mbps 241 * @version: DPMAC version 242 */ 243 struct dpmac_attr { 244 int id; 245 int phy_id; 246 enum dpmac_link_type link_type; 247 enum dpmac_eth_if eth_if; 248 uint32_t max_rate; 249 /** 250 * struct version - Structure representing DPMAC version 251 * @major: DPMAC major version 252 * @minor: DPMAC minor version 253 */ 254 struct { 255 uint16_t major; 256 uint16_t minor; 257 } version; 258 }; 259 260 /** 261 * dpmac_get_attributes - Retrieve DPMAC attributes. 262 * 263 * @mc_io: Pointer to MC portal's I/O object 264 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 265 * @token: Token of DPMAC object 266 * @attr: Returned object's attributes 267 * 268 * Return: '0' on Success; Error code otherwise. 269 */ 270 int dpmac_get_attributes(struct fsl_mc_io *mc_io, 271 uint32_t cmd_flags, 272 uint16_t token, 273 struct dpmac_attr *attr); 274 275 /** 276 * struct dpmac_mdio_cfg - DPMAC MDIO read/write parameters 277 * @phy_addr: MDIO device address 278 * @reg: Address of the register within the Clause 45 PHY device from which data 279 * is to be read 280 * @data: Data read/write from/to MDIO 281 */ 282 struct dpmac_mdio_cfg { 283 uint8_t phy_addr; 284 uint8_t reg; 285 uint16_t data; 286 }; 287 288 /** 289 * dpmac_mdio_read() - Perform MDIO read transaction 290 * @mc_io: Pointer to opaque I/O object 291 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 292 * @token: Token of DPMAC object 293 * @cfg: Structure with MDIO transaction parameters 294 * 295 * Return: '0' on Success; Error code otherwise. 296 */ 297 int dpmac_mdio_read(struct fsl_mc_io *mc_io, 298 uint32_t cmd_flags, 299 uint16_t token, 300 struct dpmac_mdio_cfg *cfg); 301 302 /** 303 * dpmac_mdio_write() - Perform MDIO write transaction 304 * @mc_io: Pointer to opaque I/O object 305 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 306 * @token: Token of DPMAC object 307 * @cfg: Structure with MDIO transaction parameters 308 * 309 * Return: '0' on Success; Error code otherwise. 310 */ 311 int dpmac_mdio_write(struct fsl_mc_io *mc_io, 312 uint32_t cmd_flags, 313 uint16_t token, 314 struct dpmac_mdio_cfg *cfg); 315 316 /* DPMAC link configuration/state options */ 317 318 /* Enable auto-negotiation */ 319 #define DPMAC_LINK_OPT_AUTONEG 0x0000000000000001ULL 320 /* Enable half-duplex mode */ 321 #define DPMAC_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL 322 /* Enable pause frames */ 323 #define DPMAC_LINK_OPT_PAUSE 0x0000000000000004ULL 324 /* Enable a-symmetric pause frames */ 325 #define DPMAC_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL 326 327 /** 328 * struct dpmac_link_cfg - Structure representing DPMAC link configuration 329 * @rate: Link's rate - in Mbps 330 * @options: Enable/Disable DPMAC link cfg features (bitmap) 331 */ 332 struct dpmac_link_cfg { 333 uint32_t rate; 334 uint64_t options; 335 }; 336 337 /** 338 * dpmac_get_link_cfg() - Get Ethernet link configuration 339 * @mc_io: Pointer to opaque I/O object 340 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 341 * @token: Token of DPMAC object 342 * @cfg: Returned structure with the link configuration 343 * 344 * Return: '0' on Success; Error code otherwise. 345 */ 346 int dpmac_get_link_cfg(struct fsl_mc_io *mc_io, 347 uint32_t cmd_flags, 348 uint16_t token, 349 struct dpmac_link_cfg *cfg); 350 351 /** 352 * struct dpmac_link_state - DPMAC link configuration request 353 * @rate: Rate in Mbps 354 * @options: Enable/Disable DPMAC link cfg features (bitmap) 355 * @up: Link state 356 */ 357 struct dpmac_link_state { 358 uint32_t rate; 359 uint64_t options; 360 int up; 361 }; 362 363 /** 364 * dpmac_set_link_state() - Set the Ethernet link status 365 * @mc_io: Pointer to opaque I/O object 366 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 367 * @token: Token of DPMAC object 368 * @link_state: Link state configuration 369 * 370 * Return: '0' on Success; Error code otherwise. 371 */ 372 int dpmac_set_link_state(struct fsl_mc_io *mc_io, 373 uint32_t cmd_flags, 374 uint16_t token, 375 struct dpmac_link_state *link_state); 376 377 /** 378 * enum dpni_counter - DPNI counter types 379 * @DPMAC_CNT_ING_FRAME_64: counts 64-octet frame, good or bad. 380 * @DPMAC_CNT_ING_FRAME_127: counts 65- to 127-octet frame, good or bad. 381 * @DPMAC_CNT_ING_FRAME_255: counts 128- to 255-octet frame, good or bad. 382 * @DPMAC_CNT_ING_FRAME_511: counts 256- to 511-octet frame, good or bad. 383 * @DPMAC_CNT_ING_FRAME_1023: counts 512- to 1023-octet frame, good or bad. 384 * @DPMAC_CNT_ING_FRAME_1518: counts 1024- to 1518-octet frame, good or bad. 385 * @DPMAC_CNT_ING_FRAME_1519_MAX: counts 1519-octet frame and larger 386 * (up to max frame length specified), 387 * good or bad. 388 * @DPMAC_CNT_ING_FRAG: counts packet which is shorter than 64 octets received 389 * with a wrong CRC 390 * @DPMAC_CNT_ING_JABBER: counts packet longer than the maximum frame length 391 * specified, with a bad frame check sequence. 392 * @DPMAC_CNT_ING_FRAME_DISCARD: counts dropped packet due to internal errors. 393 * Occurs when a receive FIFO overflows. 394 * Includes also packets truncated as a result of 395 * the receive FIFO overflow. 396 * @DPMAC_CNT_ING_ALIGN_ERR: counts frame with an alignment error 397 * (optional used for wrong SFD) 398 * @DPMAC_CNT_EGR_UNDERSIZED: counts packet transmitted that was less than 64 399 * octets long with a good CRC. 400 * @DPMAC_CNT_ING_OVERSIZED: counts packet longer than the maximum frame length 401 * specified, with a good frame check sequence. 402 * @DPMAC_CNT_ING_VALID_PAUSE_FRAME: counts valid pause frame (regular and PFC). 403 * @DPMAC_CNT_EGR_VALID_PAUSE_FRAME: counts valid pause frame transmitted 404 * (regular and PFC). 405 * @DPMAC_CNT_ING_BYTE: counts octet received except preamble for all valid 406 * frames and valid pause frames. 407 * @DPMAC_CNT_ING_MCAST_FRAME: counts received multicast frame 408 * @DPMAC_CNT_ING_BCAST_FRAME: counts received broadcast frame 409 * @DPMAC_CNT_ING_ALL_FRAME: counts each good or bad packet received. 410 * @DPMAC_CNT_ING_UCAST_FRAME: counts received unicast frame 411 * @DPMAC_CNT_ING_ERR_FRAME: counts frame received with an error 412 * (except for undersized/fragment frame) 413 * @DPMAC_CNT_EGR_BYTE: counts octet transmitted except preamble for all valid 414 * frames and valid pause frames transmitted. 415 * @DPMAC_CNT_EGR_MCAST_FRAME: counts transmitted multicast frame 416 * @DPMAC_CNT_EGR_BCAST_FRAME: counts transmitted broadcast frame 417 * @DPMAC_CNT_EGR_UCAST_FRAME: counts transmitted unicast frame 418 * @DPMAC_CNT_EGR_ERR_FRAME: counts frame transmitted with an error 419 * @DPMAC_CNT_ING_GOOD_FRAME: counts frame received without error, including 420 * pause frames. 421 */ 422 enum dpmac_counter { 423 DPMAC_CNT_ING_FRAME_64, 424 DPMAC_CNT_ING_FRAME_127, 425 DPMAC_CNT_ING_FRAME_255, 426 DPMAC_CNT_ING_FRAME_511, 427 DPMAC_CNT_ING_FRAME_1023, 428 DPMAC_CNT_ING_FRAME_1518, 429 DPMAC_CNT_ING_FRAME_1519_MAX, 430 DPMAC_CNT_ING_FRAG, 431 DPMAC_CNT_ING_JABBER, 432 DPMAC_CNT_ING_FRAME_DISCARD, 433 DPMAC_CNT_ING_ALIGN_ERR, 434 DPMAC_CNT_EGR_UNDERSIZED, 435 DPMAC_CNT_ING_OVERSIZED, 436 DPMAC_CNT_ING_VALID_PAUSE_FRAME, 437 DPMAC_CNT_EGR_VALID_PAUSE_FRAME, 438 DPMAC_CNT_ING_BYTE, 439 DPMAC_CNT_ING_MCAST_FRAME, 440 DPMAC_CNT_ING_BCAST_FRAME, 441 DPMAC_CNT_ING_ALL_FRAME, 442 DPMAC_CNT_ING_UCAST_FRAME, 443 DPMAC_CNT_ING_ERR_FRAME, 444 DPMAC_CNT_EGR_BYTE, 445 DPMAC_CNT_EGR_MCAST_FRAME, 446 DPMAC_CNT_EGR_BCAST_FRAME, 447 DPMAC_CNT_EGR_UCAST_FRAME, 448 DPMAC_CNT_EGR_ERR_FRAME, 449 DPMAC_CNT_ING_GOOD_FRAME 450 }; 451 452 /** 453 * dpmac_get_counter() - Read a specific DPMAC counter 454 * @mc_io: Pointer to opaque I/O object 455 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 456 * @token: Token of DPMAC object 457 * @type: The requested counter 458 * @counter: Returned counter value 459 * 460 * Return: The requested counter; '0' otherwise. 461 */ 462 int dpmac_get_counter(struct fsl_mc_io *mc_io, 463 uint32_t cmd_flags, 464 uint16_t token, 465 enum dpmac_counter type, 466 uint64_t *counter); 467 468 #endif /* __FSL_DPMAC_H */ 469