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