1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Freescale Management Complex (MC) bus private declarations 4 * 5 * Copyright (C) 2016 Freescale Semiconductor, Inc. 6 * 7 */ 8 #ifndef _FSL_MC_PRIVATE_H_ 9 #define _FSL_MC_PRIVATE_H_ 10 11 #include <linux/fsl/mc.h> 12 #include <linux/mutex.h> 13 14 /* 15 * Data Path Management Complex (DPMNG) General API 16 */ 17 18 /* DPMNG command versioning */ 19 #define DPMNG_CMD_BASE_VERSION 1 20 #define DPMNG_CMD_ID_OFFSET 4 21 22 #define DPMNG_CMD(id) (((id) << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION) 23 24 /* DPMNG command IDs */ 25 #define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831) 26 27 struct dpmng_rsp_get_version { 28 __le32 revision; 29 __le32 version_major; 30 __le32 version_minor; 31 }; 32 33 /* 34 * Data Path Management Command Portal (DPMCP) API 35 */ 36 37 /* Minimal supported DPMCP Version */ 38 #define DPMCP_MIN_VER_MAJOR 3 39 #define DPMCP_MIN_VER_MINOR 0 40 41 /* DPMCP command versioning */ 42 #define DPMCP_CMD_BASE_VERSION 1 43 #define DPMCP_CMD_ID_OFFSET 4 44 45 #define DPMCP_CMD(id) (((id) << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION) 46 47 /* DPMCP command IDs */ 48 #define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800) 49 #define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b) 50 #define DPMCP_CMDID_RESET DPMCP_CMD(0x005) 51 52 struct dpmcp_cmd_open { 53 __le32 dpmcp_id; 54 }; 55 56 /* 57 * Initialization and runtime control APIs for DPMCP 58 */ 59 int dpmcp_open(struct fsl_mc_io *mc_io, 60 u32 cmd_flags, 61 int dpmcp_id, 62 u16 *token); 63 64 int dpmcp_close(struct fsl_mc_io *mc_io, 65 u32 cmd_flags, 66 u16 token); 67 68 int dpmcp_reset(struct fsl_mc_io *mc_io, 69 u32 cmd_flags, 70 u16 token); 71 72 /* 73 * Data Path Resource Container (DPRC) API 74 */ 75 76 /* Minimal supported DPRC Version */ 77 #define DPRC_MIN_VER_MAJOR 6 78 #define DPRC_MIN_VER_MINOR 0 79 80 /* DPRC command versioning */ 81 #define DPRC_CMD_BASE_VERSION 1 82 #define DPRC_CMD_2ND_VERSION 2 83 #define DPRC_CMD_ID_OFFSET 4 84 85 #define DPRC_CMD(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION) 86 #define DPRC_CMD_V2(id) (((id) << DPRC_CMD_ID_OFFSET) | DPRC_CMD_2ND_VERSION) 87 88 /* DPRC command IDs */ 89 #define DPRC_CMDID_CLOSE DPRC_CMD(0x800) 90 #define DPRC_CMDID_OPEN DPRC_CMD(0x805) 91 #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05) 92 93 #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004) 94 95 #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010) 96 #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012) 97 #define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014) 98 #define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016) 99 #define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017) 100 101 #define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830) 102 #define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159) 103 #define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A) 104 #define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E) 105 #define DPRC_CMDID_GET_OBJ_REG_V2 DPRC_CMD_V2(0x15E) 106 #define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F) 107 108 #define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C) 109 110 struct dprc_cmd_open { 111 __le32 container_id; 112 }; 113 114 struct dprc_cmd_set_irq { 115 /* cmd word 0 */ 116 __le32 irq_val; 117 u8 irq_index; 118 u8 pad[3]; 119 /* cmd word 1 */ 120 __le64 irq_addr; 121 /* cmd word 2 */ 122 __le32 irq_num; 123 }; 124 125 #define DPRC_ENABLE 0x1 126 127 struct dprc_cmd_set_irq_enable { 128 u8 enable; 129 u8 pad[3]; 130 u8 irq_index; 131 }; 132 133 struct dprc_cmd_set_irq_mask { 134 __le32 mask; 135 u8 irq_index; 136 }; 137 138 struct dprc_cmd_get_irq_status { 139 __le32 status; 140 u8 irq_index; 141 }; 142 143 struct dprc_rsp_get_irq_status { 144 __le32 status; 145 }; 146 147 struct dprc_cmd_clear_irq_status { 148 __le32 status; 149 u8 irq_index; 150 }; 151 152 struct dprc_rsp_get_attributes { 153 /* response word 0 */ 154 __le32 container_id; 155 __le16 icid; 156 __le16 pad; 157 /* response word 1 */ 158 __le32 options; 159 __le32 portal_id; 160 }; 161 162 struct dprc_rsp_get_obj_count { 163 __le32 pad; 164 __le32 obj_count; 165 }; 166 167 struct dprc_cmd_get_obj { 168 __le32 obj_index; 169 }; 170 171 struct dprc_rsp_get_obj { 172 /* response word 0 */ 173 __le32 pad0; 174 __le32 id; 175 /* response word 1 */ 176 __le16 vendor; 177 u8 irq_count; 178 u8 region_count; 179 __le32 state; 180 /* response word 2 */ 181 __le16 version_major; 182 __le16 version_minor; 183 __le16 flags; 184 __le16 pad1; 185 /* response word 3-4 */ 186 u8 type[16]; 187 /* response word 5-6 */ 188 u8 label[16]; 189 }; 190 191 struct dprc_cmd_get_obj_region { 192 /* cmd word 0 */ 193 __le32 obj_id; 194 __le16 pad0; 195 u8 region_index; 196 u8 pad1; 197 /* cmd word 1-2 */ 198 __le64 pad2[2]; 199 /* cmd word 3-4 */ 200 u8 obj_type[16]; 201 }; 202 203 struct dprc_rsp_get_obj_region { 204 /* response word 0 */ 205 __le64 pad; 206 /* response word 1 */ 207 __le64 base_offset; 208 /* response word 2 */ 209 __le32 size; 210 __le32 pad2; 211 /* response word 3 */ 212 __le32 flags; 213 __le32 pad3; 214 /* response word 4 */ 215 /* base_addr may be zero if older MC firmware is used */ 216 __le64 base_addr; 217 }; 218 219 struct dprc_cmd_set_obj_irq { 220 /* cmd word 0 */ 221 __le32 irq_val; 222 u8 irq_index; 223 u8 pad[3]; 224 /* cmd word 1 */ 225 __le64 irq_addr; 226 /* cmd word 2 */ 227 __le32 irq_num; 228 __le32 obj_id; 229 /* cmd word 3-4 */ 230 u8 obj_type[16]; 231 }; 232 233 struct dprc_cmd_get_connection { 234 __le32 ep1_id; 235 __le16 ep1_interface_id; 236 u8 pad[2]; 237 u8 ep1_type[16]; 238 }; 239 240 struct dprc_rsp_get_connection { 241 __le64 pad[3]; 242 __le32 ep2_id; 243 __le16 ep2_interface_id; 244 __le16 pad1; 245 u8 ep2_type[16]; 246 __le32 state; 247 }; 248 249 /* 250 * DPRC API for managing and querying DPAA resources 251 */ 252 int dprc_open(struct fsl_mc_io *mc_io, 253 u32 cmd_flags, 254 int container_id, 255 u16 *token); 256 257 int dprc_close(struct fsl_mc_io *mc_io, 258 u32 cmd_flags, 259 u16 token); 260 261 /* DPRC IRQ events */ 262 263 /* IRQ event - Indicates that a new object added to the container */ 264 #define DPRC_IRQ_EVENT_OBJ_ADDED 0x00000001 265 /* IRQ event - Indicates that an object was removed from the container */ 266 #define DPRC_IRQ_EVENT_OBJ_REMOVED 0x00000002 267 /* 268 * IRQ event - Indicates that one of the descendant containers that opened by 269 * this container is destroyed 270 */ 271 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010 272 273 /* 274 * IRQ event - Indicates that on one of the container's opened object is 275 * destroyed 276 */ 277 #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020 278 279 /* Irq event - Indicates that object is created at the container */ 280 #define DPRC_IRQ_EVENT_OBJ_CREATED 0x00000040 281 282 /** 283 * struct dprc_irq_cfg - IRQ configuration 284 * @paddr: Address that must be written to signal a message-based interrupt 285 * @val: Value to write into irq_addr address 286 * @irq_num: A user defined number associated with this IRQ 287 */ 288 struct dprc_irq_cfg { 289 phys_addr_t paddr; 290 u32 val; 291 int irq_num; 292 }; 293 294 int dprc_set_irq(struct fsl_mc_io *mc_io, 295 u32 cmd_flags, 296 u16 token, 297 u8 irq_index, 298 struct dprc_irq_cfg *irq_cfg); 299 300 int dprc_set_irq_enable(struct fsl_mc_io *mc_io, 301 u32 cmd_flags, 302 u16 token, 303 u8 irq_index, 304 u8 en); 305 306 int dprc_set_irq_mask(struct fsl_mc_io *mc_io, 307 u32 cmd_flags, 308 u16 token, 309 u8 irq_index, 310 u32 mask); 311 312 int dprc_get_irq_status(struct fsl_mc_io *mc_io, 313 u32 cmd_flags, 314 u16 token, 315 u8 irq_index, 316 u32 *status); 317 318 int dprc_clear_irq_status(struct fsl_mc_io *mc_io, 319 u32 cmd_flags, 320 u16 token, 321 u8 irq_index, 322 u32 status); 323 324 /** 325 * struct dprc_attributes - Container attributes 326 * @container_id: Container's ID 327 * @icid: Container's ICID 328 * @portal_id: Container's portal ID 329 * @options: Container's options as set at container's creation 330 */ 331 struct dprc_attributes { 332 int container_id; 333 u16 icid; 334 int portal_id; 335 u64 options; 336 }; 337 338 int dprc_get_attributes(struct fsl_mc_io *mc_io, 339 u32 cmd_flags, 340 u16 token, 341 struct dprc_attributes *attributes); 342 343 int dprc_get_obj_count(struct fsl_mc_io *mc_io, 344 u32 cmd_flags, 345 u16 token, 346 int *obj_count); 347 348 int dprc_get_obj(struct fsl_mc_io *mc_io, 349 u32 cmd_flags, 350 u16 token, 351 int obj_index, 352 struct fsl_mc_obj_desc *obj_desc); 353 354 int dprc_set_obj_irq(struct fsl_mc_io *mc_io, 355 u32 cmd_flags, 356 u16 token, 357 char *obj_type, 358 int obj_id, 359 u8 irq_index, 360 struct dprc_irq_cfg *irq_cfg); 361 362 /* Region flags */ 363 /* Cacheable - Indicates that region should be mapped as cacheable */ 364 #define DPRC_REGION_CACHEABLE 0x00000001 365 #define DPRC_REGION_SHAREABLE 0x00000002 366 367 /** 368 * enum dprc_region_type - Region type 369 * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region 370 * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region 371 */ 372 enum dprc_region_type { 373 DPRC_REGION_TYPE_MC_PORTAL, 374 DPRC_REGION_TYPE_QBMAN_PORTAL, 375 DPRC_REGION_TYPE_QBMAN_MEM_BACKED_PORTAL 376 }; 377 378 /** 379 * struct dprc_region_desc - Mappable region descriptor 380 * @base_offset: Region offset from region's base address. 381 * For DPMCP and DPRC objects, region base is offset from SoC MC portals 382 * base address; For DPIO, region base is offset from SoC QMan portals 383 * base address 384 * @size: Region size (in bytes) 385 * @flags: Region attributes 386 * @type: Portal region type 387 */ 388 struct dprc_region_desc { 389 u32 base_offset; 390 u32 size; 391 u32 flags; 392 enum dprc_region_type type; 393 u64 base_address; 394 }; 395 396 int dprc_get_obj_region(struct fsl_mc_io *mc_io, 397 u32 cmd_flags, 398 u16 token, 399 char *obj_type, 400 int obj_id, 401 u8 region_index, 402 struct dprc_region_desc *region_desc); 403 404 int dprc_get_api_version(struct fsl_mc_io *mc_io, 405 u32 cmd_flags, 406 u16 *major_ver, 407 u16 *minor_ver); 408 409 int dprc_get_container_id(struct fsl_mc_io *mc_io, 410 u32 cmd_flags, 411 int *container_id); 412 413 /** 414 * struct dprc_endpoint - Endpoint description for link connect/disconnect 415 * operations 416 * @type: Endpoint object type: NULL terminated string 417 * @id: Endpoint object ID 418 * @if_id: Interface ID; should be set for endpoints with multiple 419 * interfaces ("dpsw", "dpdmux"); for others, always set to 0 420 */ 421 struct dprc_endpoint { 422 char type[16]; 423 int id; 424 u16 if_id; 425 }; 426 427 int dprc_get_connection(struct fsl_mc_io *mc_io, 428 u32 cmd_flags, 429 u16 token, 430 const struct dprc_endpoint *endpoint1, 431 struct dprc_endpoint *endpoint2, 432 int *state); 433 434 /* 435 * Data Path Buffer Pool (DPBP) API 436 */ 437 438 /* DPBP Version */ 439 #define DPBP_VER_MAJOR 3 440 #define DPBP_VER_MINOR 2 441 442 /* Command versioning */ 443 #define DPBP_CMD_BASE_VERSION 1 444 #define DPBP_CMD_ID_OFFSET 4 445 446 #define DPBP_CMD(id) (((id) << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION) 447 448 /* Command IDs */ 449 #define DPBP_CMDID_CLOSE DPBP_CMD(0x800) 450 #define DPBP_CMDID_OPEN DPBP_CMD(0x804) 451 452 #define DPBP_CMDID_ENABLE DPBP_CMD(0x002) 453 #define DPBP_CMDID_DISABLE DPBP_CMD(0x003) 454 #define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004) 455 #define DPBP_CMDID_RESET DPBP_CMD(0x005) 456 457 struct dpbp_cmd_open { 458 __le32 dpbp_id; 459 }; 460 461 #define DPBP_ENABLE 0x1 462 463 struct dpbp_rsp_get_attributes { 464 /* response word 0 */ 465 __le16 pad; 466 __le16 bpid; 467 __le32 id; 468 /* response word 1 */ 469 __le16 version_major; 470 __le16 version_minor; 471 }; 472 473 /* 474 * Data Path Concentrator (DPCON) API 475 */ 476 477 /* DPCON Version */ 478 #define DPCON_VER_MAJOR 3 479 #define DPCON_VER_MINOR 2 480 481 /* Command versioning */ 482 #define DPCON_CMD_BASE_VERSION 1 483 #define DPCON_CMD_ID_OFFSET 4 484 485 #define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION) 486 487 /* Command IDs */ 488 #define DPCON_CMDID_CLOSE DPCON_CMD(0x800) 489 #define DPCON_CMDID_OPEN DPCON_CMD(0x808) 490 491 #define DPCON_CMDID_ENABLE DPCON_CMD(0x002) 492 #define DPCON_CMDID_DISABLE DPCON_CMD(0x003) 493 #define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004) 494 #define DPCON_CMDID_RESET DPCON_CMD(0x005) 495 496 #define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100) 497 498 struct dpcon_cmd_open { 499 __le32 dpcon_id; 500 }; 501 502 #define DPCON_ENABLE 1 503 504 struct dpcon_rsp_get_attr { 505 /* response word 0 */ 506 __le32 id; 507 __le16 qbman_ch_id; 508 u8 num_priorities; 509 u8 pad; 510 }; 511 512 struct dpcon_cmd_set_notification { 513 /* cmd word 0 */ 514 __le32 dpio_id; 515 u8 priority; 516 u8 pad[3]; 517 /* cmd word 1 */ 518 __le64 user_ctx; 519 }; 520 521 /** 522 * Maximum number of total IRQs that can be pre-allocated for an MC bus' 523 * IRQ pool 524 */ 525 #define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256 526 527 /** 528 * struct fsl_mc_resource_pool - Pool of MC resources of a given 529 * type 530 * @type: type of resources in the pool 531 * @max_count: maximum number of resources in the pool 532 * @free_count: number of free resources in the pool 533 * @mutex: mutex to serialize access to the pool's free list 534 * @free_list: anchor node of list of free resources in the pool 535 * @mc_bus: pointer to the MC bus that owns this resource pool 536 */ 537 struct fsl_mc_resource_pool { 538 enum fsl_mc_pool_type type; 539 int max_count; 540 int free_count; 541 struct mutex mutex; /* serializes access to free_list */ 542 struct list_head free_list; 543 struct fsl_mc_bus *mc_bus; 544 }; 545 546 /** 547 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC 548 * @mc_dev: fsl-mc device for the bus device itself. 549 * @resource_pools: array of resource pools (one pool per resource type) 550 * for this MC bus. These resources represent allocatable entities 551 * from the physical DPRC. 552 * @irq_resources: Pointer to array of IRQ objects for the IRQ pool 553 * @scan_mutex: Serializes bus scanning 554 * @dprc_attr: DPRC attributes 555 */ 556 struct fsl_mc_bus { 557 struct fsl_mc_device mc_dev; 558 struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES]; 559 struct fsl_mc_device_irq *irq_resources; 560 struct mutex scan_mutex; /* serializes bus scanning */ 561 struct dprc_attributes dprc_attr; 562 }; 563 564 #define to_fsl_mc_bus(_mc_dev) \ 565 container_of(_mc_dev, struct fsl_mc_bus, mc_dev) 566 567 int __must_check fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc, 568 struct fsl_mc_io *mc_io, 569 struct device *parent_dev, 570 struct fsl_mc_device **new_mc_dev); 571 572 void fsl_mc_device_remove(struct fsl_mc_device *mc_dev); 573 574 int __init dprc_driver_init(void); 575 576 void dprc_driver_exit(void); 577 578 int __init fsl_mc_allocator_driver_init(void); 579 580 void fsl_mc_allocator_driver_exit(void); 581 582 void fsl_mc_init_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 583 584 void fsl_mc_cleanup_all_resource_pools(struct fsl_mc_device *mc_bus_dev); 585 586 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus, 587 enum fsl_mc_pool_type pool_type, 588 struct fsl_mc_resource 589 **new_resource); 590 591 void fsl_mc_resource_free(struct fsl_mc_resource *resource); 592 593 int fsl_mc_msi_domain_alloc_irqs(struct device *dev, 594 unsigned int irq_count); 595 596 void fsl_mc_msi_domain_free_irqs(struct device *dev); 597 598 int fsl_mc_find_msi_domain(struct device *mc_platform_dev, 599 struct irq_domain **mc_msi_domain); 600 601 int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus, 602 unsigned int irq_count); 603 604 void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus); 605 606 int __must_check fsl_create_mc_io(struct device *dev, 607 phys_addr_t mc_portal_phys_addr, 608 u32 mc_portal_size, 609 struct fsl_mc_device *dpmcp_dev, 610 u32 flags, struct fsl_mc_io **new_mc_io); 611 612 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io); 613 614 bool fsl_mc_is_root_dprc(struct device *dev); 615 616 struct fsl_mc_device *fsl_mc_device_lookup(struct fsl_mc_obj_desc *obj_desc, 617 struct fsl_mc_device *mc_bus_dev); 618 619 #endif /* _FSL_MC_PRIVATE_H_ */ 620