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