1 /* 2 * Copyright (C) 2013-2015 Freescale Semiconductor 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <fsl-mc/fsl_mc_sys.h> 8 #include <fsl-mc/fsl_mc_cmd.h> 9 #include <fsl-mc/fsl_dpni.h> 10 11 int dpni_open(struct fsl_mc_io *mc_io, int dpni_id, uint16_t *token) 12 { 13 struct mc_command cmd = { 0 }; 14 int err; 15 16 /* prepare command */ 17 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN, 18 MC_CMD_PRI_LOW, 0); 19 DPNI_CMD_OPEN(cmd, dpni_id); 20 21 /* send command to mc*/ 22 err = mc_send_command(mc_io, &cmd); 23 if (err) 24 return err; 25 26 /* retrieve response parameters */ 27 *token = MC_CMD_HDR_READ_TOKEN(cmd.header); 28 29 return 0; 30 } 31 32 int dpni_close(struct fsl_mc_io *mc_io, uint16_t token) 33 { 34 struct mc_command cmd = { 0 }; 35 36 /* prepare command */ 37 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE, 38 MC_CMD_PRI_HIGH, token); 39 40 /* send command to mc*/ 41 return mc_send_command(mc_io, &cmd); 42 } 43 44 int dpni_set_pools(struct fsl_mc_io *mc_io, 45 uint16_t token, 46 const struct dpni_pools_cfg *cfg) 47 { 48 struct mc_command cmd = { 0 }; 49 50 /* prepare command */ 51 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS, 52 MC_CMD_PRI_LOW, 53 token); 54 DPNI_CMD_SET_POOLS(cmd, cfg); 55 56 /* send command to mc*/ 57 return mc_send_command(mc_io, &cmd); 58 } 59 60 int dpni_enable(struct fsl_mc_io *mc_io, uint16_t token) 61 { 62 struct mc_command cmd = { 0 }; 63 64 /* prepare command */ 65 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE, 66 MC_CMD_PRI_LOW, token); 67 68 /* send command to mc*/ 69 return mc_send_command(mc_io, &cmd); 70 } 71 72 int dpni_disable(struct fsl_mc_io *mc_io, uint16_t token) 73 { 74 struct mc_command cmd = { 0 }; 75 76 /* prepare command */ 77 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE, 78 MC_CMD_PRI_LOW, 79 token); 80 81 /* send command to mc*/ 82 return mc_send_command(mc_io, &cmd); 83 } 84 85 int dpni_reset(struct fsl_mc_io *mc_io, uint16_t token) 86 { 87 struct mc_command cmd = { 0 }; 88 89 /* prepare command */ 90 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET, 91 MC_CMD_PRI_LOW, token); 92 93 /* send command to mc*/ 94 return mc_send_command(mc_io, &cmd); 95 } 96 97 int dpni_get_attributes(struct fsl_mc_io *mc_io, 98 uint16_t token, 99 struct dpni_attr *attr) 100 { 101 struct mc_command cmd = { 0 }; 102 int err; 103 104 /* prepare command */ 105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR, 106 MC_CMD_PRI_LOW, 107 token); 108 109 /* send command to mc*/ 110 err = mc_send_command(mc_io, &cmd); 111 if (err) 112 return err; 113 114 /* retrieve response parameters */ 115 DPNI_RSP_GET_ATTR(cmd, attr); 116 117 return 0; 118 } 119 120 int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io, 121 uint16_t token, 122 struct dpni_buffer_layout *layout) 123 { 124 struct mc_command cmd = { 0 }; 125 int err; 126 127 /* prepare command */ 128 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT, 129 MC_CMD_PRI_LOW, token); 130 131 /* send command to mc*/ 132 err = mc_send_command(mc_io, &cmd); 133 if (err) 134 return err; 135 136 /* retrieve response parameters */ 137 DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout); 138 139 return 0; 140 } 141 142 int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io, 143 uint16_t token, 144 const struct dpni_buffer_layout *layout) 145 { 146 struct mc_command cmd = { 0 }; 147 148 /* prepare command */ 149 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT, 150 MC_CMD_PRI_LOW, token); 151 DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout); 152 153 /* send command to mc*/ 154 return mc_send_command(mc_io, &cmd); 155 } 156 157 int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io, 158 uint16_t token, 159 struct dpni_buffer_layout *layout) 160 { 161 struct mc_command cmd = { 0 }; 162 int err; 163 164 /* prepare command */ 165 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT, 166 MC_CMD_PRI_LOW, token); 167 168 /* send command to mc*/ 169 err = mc_send_command(mc_io, &cmd); 170 if (err) 171 return err; 172 173 /* retrieve response parameters */ 174 DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout); 175 176 return 0; 177 } 178 179 int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io, 180 uint16_t token, 181 const struct dpni_buffer_layout *layout) 182 { 183 struct mc_command cmd = { 0 }; 184 185 /* prepare command */ 186 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT, 187 MC_CMD_PRI_LOW, token); 188 DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout); 189 190 /* send command to mc*/ 191 return mc_send_command(mc_io, &cmd); 192 } 193 194 int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io, 195 uint16_t token, 196 struct dpni_buffer_layout *layout) 197 { 198 struct mc_command cmd = { 0 }; 199 int err; 200 201 /* prepare command */ 202 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT, 203 MC_CMD_PRI_LOW, token); 204 205 /* send command to mc*/ 206 err = mc_send_command(mc_io, &cmd); 207 if (err) 208 return err; 209 210 /* retrieve response parameters */ 211 DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout); 212 213 return 0; 214 } 215 216 int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io, 217 uint16_t token, 218 const struct dpni_buffer_layout *layout) 219 { 220 struct mc_command cmd = { 0 }; 221 222 /* prepare command */ 223 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT, 224 MC_CMD_PRI_LOW, token); 225 DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout); 226 227 /* send command to mc*/ 228 return mc_send_command(mc_io, &cmd); 229 } 230 231 int dpni_get_qdid(struct fsl_mc_io *mc_io, uint16_t token, uint16_t *qdid) 232 { 233 struct mc_command cmd = { 0 }; 234 int err; 235 236 /* prepare command */ 237 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID, 238 MC_CMD_PRI_LOW, 239 token); 240 241 /* send command to mc*/ 242 err = mc_send_command(mc_io, &cmd); 243 if (err) 244 return err; 245 246 /* retrieve response parameters */ 247 DPNI_RSP_GET_QDID(cmd, *qdid); 248 249 return 0; 250 } 251 252 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io, 253 uint16_t token, 254 uint16_t *data_offset) 255 { 256 struct mc_command cmd = { 0 }; 257 int err; 258 259 /* prepare command */ 260 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET, 261 MC_CMD_PRI_LOW, token); 262 263 /* send command to mc*/ 264 err = mc_send_command(mc_io, &cmd); 265 if (err) 266 return err; 267 268 /* retrieve response parameters */ 269 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset); 270 271 return 0; 272 } 273 274 int dpni_get_counter(struct fsl_mc_io *mc_io, 275 uint16_t token, 276 enum dpni_counter counter, 277 uint64_t *value) 278 { 279 struct mc_command cmd = { 0 }; 280 int err; 281 282 /* prepare command */ 283 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER, 284 MC_CMD_PRI_LOW, token); 285 DPNI_CMD_GET_COUNTER(cmd, counter); 286 287 /* send command to mc*/ 288 err = mc_send_command(mc_io, &cmd); 289 if (err) 290 return err; 291 292 /* retrieve response parameters */ 293 DPNI_RSP_GET_COUNTER(cmd, *value); 294 295 return 0; 296 } 297 298 int dpni_set_counter(struct fsl_mc_io *mc_io, 299 uint16_t token, 300 enum dpni_counter counter, 301 uint64_t value) 302 { 303 struct mc_command cmd = { 0 }; 304 305 /* prepare command */ 306 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER, 307 MC_CMD_PRI_LOW, token); 308 DPNI_CMD_SET_COUNTER(cmd, counter, value); 309 310 /* send command to mc*/ 311 return mc_send_command(mc_io, &cmd); 312 } 313 314 int dpni_set_link_cfg(struct fsl_mc_io *mc_io, 315 uint16_t token, 316 struct dpni_link_cfg *cfg) 317 { 318 struct mc_command cmd = { 0 }; 319 320 /* prepare command */ 321 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG, 322 MC_CMD_PRI_LOW, token); 323 DPNI_CMD_SET_LINK_CFG(cmd, cfg); 324 325 /* send command to mc*/ 326 return mc_send_command(mc_io, &cmd); 327 } 328 329 int dpni_get_link_state(struct fsl_mc_io *mc_io, 330 uint16_t token, 331 struct dpni_link_state *state) 332 { 333 struct mc_command cmd = { 0 }; 334 int err; 335 336 /* prepare command */ 337 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE, 338 MC_CMD_PRI_LOW, token); 339 340 /* send command to mc*/ 341 err = mc_send_command(mc_io, &cmd); 342 if (err) 343 return err; 344 345 /* retrieve response parameters */ 346 DPNI_RSP_GET_LINK_STATE(cmd, state); 347 348 return 0; 349 } 350 351 352 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io, 353 uint16_t token, 354 const uint8_t mac_addr[6]) 355 { 356 struct mc_command cmd = { 0 }; 357 358 /* prepare command */ 359 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC, 360 MC_CMD_PRI_LOW, token); 361 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr); 362 363 /* send command to mc*/ 364 return mc_send_command(mc_io, &cmd); 365 } 366 367 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io, 368 uint16_t token, 369 uint8_t mac_addr[6]) 370 { 371 struct mc_command cmd = { 0 }; 372 int err; 373 374 /* prepare command */ 375 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC, 376 MC_CMD_PRI_LOW, token); 377 378 /* send command to mc*/ 379 err = mc_send_command(mc_io, &cmd); 380 if (err) 381 return err; 382 383 /* retrieve response parameters */ 384 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr); 385 386 return 0; 387 } 388 389 int dpni_add_mac_addr(struct fsl_mc_io *mc_io, 390 uint16_t token, 391 const uint8_t mac_addr[6]) 392 { 393 struct mc_command cmd = { 0 }; 394 395 /* prepare command */ 396 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR, 397 MC_CMD_PRI_LOW, token); 398 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr); 399 400 /* send command to mc*/ 401 return mc_send_command(mc_io, &cmd); 402 } 403 404 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io, 405 uint16_t token, 406 const uint8_t mac_addr[6]) 407 { 408 struct mc_command cmd = { 0 }; 409 410 /* prepare command */ 411 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR, 412 MC_CMD_PRI_LOW, token); 413 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr); 414 415 /* send command to mc*/ 416 return mc_send_command(mc_io, &cmd); 417 } 418 419 int dpni_set_tx_flow(struct fsl_mc_io *mc_io, 420 uint16_t token, 421 uint16_t *flow_id, 422 const struct dpni_tx_flow_cfg *cfg) 423 { 424 struct mc_command cmd = { 0 }; 425 int err; 426 427 /* prepare command */ 428 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW, 429 MC_CMD_PRI_LOW, token); 430 DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg); 431 432 /* send command to mc*/ 433 err = mc_send_command(mc_io, &cmd); 434 if (err) 435 return err; 436 437 /* retrieve response parameters */ 438 DPNI_RSP_SET_TX_FLOW(cmd, *flow_id); 439 440 return 0; 441 } 442 443 int dpni_get_tx_flow(struct fsl_mc_io *mc_io, 444 uint16_t token, 445 uint16_t flow_id, 446 struct dpni_tx_flow_attr *attr) 447 { 448 struct mc_command cmd = { 0 }; 449 int err; 450 451 /* prepare command */ 452 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW, 453 MC_CMD_PRI_LOW, token); 454 DPNI_CMD_GET_TX_FLOW(cmd, flow_id); 455 456 /* send command to mc*/ 457 err = mc_send_command(mc_io, &cmd); 458 if (err) 459 return err; 460 461 /* retrieve response parameters */ 462 DPNI_RSP_GET_TX_FLOW(cmd, attr); 463 464 return 0; 465 } 466 467 int dpni_set_rx_flow(struct fsl_mc_io *mc_io, 468 uint16_t token, 469 uint8_t tc_id, 470 uint16_t flow_id, 471 const struct dpni_queue_cfg *cfg) 472 { 473 struct mc_command cmd = { 0 }; 474 475 /* prepare command */ 476 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW, 477 MC_CMD_PRI_LOW, token); 478 DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg); 479 480 /* send command to mc*/ 481 return mc_send_command(mc_io, &cmd); 482 } 483 484 int dpni_get_rx_flow(struct fsl_mc_io *mc_io, 485 uint16_t token, 486 uint8_t tc_id, 487 uint16_t flow_id, 488 struct dpni_queue_attr *attr) 489 { 490 struct mc_command cmd = { 0 }; 491 int err; 492 /* prepare command */ 493 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW, 494 MC_CMD_PRI_LOW, token); 495 DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id); 496 497 /* send command to mc*/ 498 err = mc_send_command(mc_io, &cmd); 499 if (err) 500 return err; 501 502 /* retrieve response parameters */ 503 DPNI_RSP_GET_RX_FLOW(cmd, attr); 504 505 return 0; 506 } 507