1
2
3
4
5
6
7
8
9
10#ifndef _FSL_MC_H_
11#define _FSL_MC_H_
12
13#include <linux/device.h>
14#include <linux/mod_devicetable.h>
15#include <linux/interrupt.h>
16#include <uapi/linux/fsl_mc.h>
17
18#define FSL_MC_VENDOR_FREESCALE 0x1957
19
20struct irq_domain;
21struct msi_domain_info;
22
23struct fsl_mc_device;
24struct fsl_mc_io;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40struct fsl_mc_driver {
41 struct device_driver driver;
42 const struct fsl_mc_device_id *match_id_table;
43 int (*probe)(struct fsl_mc_device *dev);
44 int (*remove)(struct fsl_mc_device *dev);
45 void (*shutdown)(struct fsl_mc_device *dev);
46 int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
47 int (*resume)(struct fsl_mc_device *dev);
48};
49
50#define to_fsl_mc_driver(_drv) \
51 container_of(_drv, struct fsl_mc_driver, driver)
52
53
54
55
56
57
58
59enum fsl_mc_pool_type {
60 FSL_MC_POOL_DPMCP = 0x0,
61 FSL_MC_POOL_DPBP,
62 FSL_MC_POOL_DPCON,
63 FSL_MC_POOL_IRQ,
64
65
66
67
68 FSL_MC_NUM_POOL_TYPES
69};
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84struct fsl_mc_resource {
85 enum fsl_mc_pool_type type;
86 s32 id;
87 void *data;
88 struct fsl_mc_resource_pool *parent_pool;
89 struct list_head node;
90};
91
92
93
94
95
96
97
98
99struct fsl_mc_device_irq {
100 struct msi_desc *msi_desc;
101 struct fsl_mc_device *mc_dev;
102 u8 dev_irq_index;
103 struct fsl_mc_resource resource;
104};
105
106#define to_fsl_mc_irq(_mc_resource) \
107 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
108
109
110#define FSL_MC_OBJ_STATE_OPEN 0x00000001
111
112#define FSL_MC_OBJ_STATE_PLUGGED 0x00000002
113
114
115
116
117
118
119
120#define FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135struct fsl_mc_obj_desc {
136 char type[16];
137 int id;
138 u16 vendor;
139 u16 ver_major;
140 u16 ver_minor;
141 u8 irq_count;
142 u8 region_count;
143 u32 state;
144 char label[16];
145 u16 flags;
146};
147
148
149
150
151#define FSL_MC_IS_DPRC 0x0001
152
153
154
155#define FSL_MC_REGION_CACHEABLE 0x00000001
156
157
158#define FSL_MC_REGION_SHAREABLE 0x00000002
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195struct fsl_mc_device {
196 struct device dev;
197 u64 dma_mask;
198 u16 flags;
199 u32 icid;
200 u16 mc_handle;
201 struct fsl_mc_io *mc_io;
202 struct fsl_mc_obj_desc obj_desc;
203 struct resource *regions;
204 struct fsl_mc_device_irq **irqs;
205 struct fsl_mc_resource *resource;
206 struct device_link *consumer_link;
207 char *driver_override;
208};
209
210#define to_fsl_mc_device(_dev) \
211 container_of(_dev, struct fsl_mc_device, dev)
212
213struct mc_cmd_header {
214 u8 src_id;
215 u8 flags_hw;
216 u8 status;
217 u8 flags_sw;
218 __le16 token;
219 __le16 cmd_id;
220};
221
222enum mc_cmd_status {
223 MC_CMD_STATUS_OK = 0x0,
224 MC_CMD_STATUS_READY = 0x1,
225 MC_CMD_STATUS_AUTH_ERR = 0x3,
226 MC_CMD_STATUS_NO_PRIVILEGE = 0x4,
227 MC_CMD_STATUS_DMA_ERR = 0x5,
228 MC_CMD_STATUS_CONFIG_ERR = 0x6,
229 MC_CMD_STATUS_TIMEOUT = 0x7,
230 MC_CMD_STATUS_NO_RESOURCE = 0x8,
231 MC_CMD_STATUS_NO_MEMORY = 0x9,
232 MC_CMD_STATUS_BUSY = 0xA,
233 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB,
234 MC_CMD_STATUS_INVALID_STATE = 0xC
235};
236
237
238
239
240
241
242#define MC_CMD_FLAG_PRI 0x80
243
244#define MC_CMD_FLAG_INTR_DIS 0x01
245
246static inline __le64 mc_encode_cmd_header(u16 cmd_id,
247 u32 cmd_flags,
248 u16 token)
249{
250 __le64 header = 0;
251 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
252
253 hdr->cmd_id = cpu_to_le16(cmd_id);
254 hdr->token = cpu_to_le16(token);
255 hdr->status = MC_CMD_STATUS_READY;
256 if (cmd_flags & MC_CMD_FLAG_PRI)
257 hdr->flags_hw = MC_CMD_FLAG_PRI;
258 if (cmd_flags & MC_CMD_FLAG_INTR_DIS)
259 hdr->flags_sw = MC_CMD_FLAG_INTR_DIS;
260
261 return header;
262}
263
264static inline u16 mc_cmd_hdr_read_token(struct fsl_mc_command *cmd)
265{
266 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
267 u16 token = le16_to_cpu(hdr->token);
268
269 return token;
270}
271
272struct mc_rsp_create {
273 __le32 object_id;
274};
275
276struct mc_rsp_api_ver {
277 __le16 major_ver;
278 __le16 minor_ver;
279};
280
281static inline u32 mc_cmd_read_object_id(struct fsl_mc_command *cmd)
282{
283 struct mc_rsp_create *rsp_params;
284
285 rsp_params = (struct mc_rsp_create *)cmd->params;
286 return le32_to_cpu(rsp_params->object_id);
287}
288
289static inline void mc_cmd_read_api_version(struct fsl_mc_command *cmd,
290 u16 *major_ver,
291 u16 *minor_ver)
292{
293 struct mc_rsp_api_ver *rsp_params;
294
295 rsp_params = (struct mc_rsp_api_ver *)cmd->params;
296 *major_ver = le16_to_cpu(rsp_params->major_ver);
297 *minor_ver = le16_to_cpu(rsp_params->minor_ver);
298}
299
300
301
302
303#define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL 0x0001
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328struct fsl_mc_io {
329 struct device *dev;
330 u16 flags;
331 u32 portal_size;
332 phys_addr_t portal_phys_addr;
333 void __iomem *portal_virt_addr;
334 struct fsl_mc_device *dpmcp_dev;
335 union {
336
337
338
339
340 struct mutex mutex;
341
342
343
344
345
346 raw_spinlock_t spinlock;
347 };
348};
349
350int mc_send_command(struct fsl_mc_io *mc_io, struct fsl_mc_command *cmd);
351
352#ifdef CONFIG_FSL_MC_BUS
353#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type)
354#else
355
356#define dev_is_fsl_mc(_dev) (0)
357#endif
358
359
360#define fsl_mc_is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & \
361 FSL_MC_IS_DPRC)
362
363
364#define fsl_mc_cont_dev(_dev) (fsl_mc_is_cont_dev(_dev) ? \
365 (_dev) : (_dev)->parent)
366
367
368
369
370
371
372
373#define module_fsl_mc_driver(__fsl_mc_driver) \
374 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
375 fsl_mc_driver_unregister)
376
377
378
379
380#define fsl_mc_driver_register(drv) \
381 __fsl_mc_driver_register(drv, THIS_MODULE)
382
383int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
384 struct module *owner);
385
386void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
387
388
389
390
391
392
393
394
395
396struct fsl_mc_version {
397 u32 major;
398 u32 minor;
399 u32 revision;
400};
401
402struct fsl_mc_version *fsl_mc_get_version(void);
403
404int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
405 u16 mc_io_flags,
406 struct fsl_mc_io **new_mc_io);
407
408void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
409
410int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
411
412int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
413 enum fsl_mc_pool_type pool_type,
414 struct fsl_mc_device **new_mc_adev);
415
416void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
417
418struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
419 struct msi_domain_info *info,
420 struct irq_domain *parent);
421
422int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
423
424void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
425
426struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev,
427 u16 if_id);
428
429extern struct bus_type fsl_mc_bus_type;
430
431extern struct device_type fsl_mc_bus_dprc_type;
432extern struct device_type fsl_mc_bus_dpni_type;
433extern struct device_type fsl_mc_bus_dpio_type;
434extern struct device_type fsl_mc_bus_dpsw_type;
435extern struct device_type fsl_mc_bus_dpbp_type;
436extern struct device_type fsl_mc_bus_dpcon_type;
437extern struct device_type fsl_mc_bus_dpmcp_type;
438extern struct device_type fsl_mc_bus_dpmac_type;
439extern struct device_type fsl_mc_bus_dprtc_type;
440extern struct device_type fsl_mc_bus_dpseci_type;
441extern struct device_type fsl_mc_bus_dpdmux_type;
442extern struct device_type fsl_mc_bus_dpdcei_type;
443extern struct device_type fsl_mc_bus_dpaiop_type;
444extern struct device_type fsl_mc_bus_dpci_type;
445extern struct device_type fsl_mc_bus_dpdmai_type;
446
447static inline bool is_fsl_mc_bus_dprc(const struct fsl_mc_device *mc_dev)
448{
449 return mc_dev->dev.type == &fsl_mc_bus_dprc_type;
450}
451
452static inline bool is_fsl_mc_bus_dpni(const struct fsl_mc_device *mc_dev)
453{
454 return mc_dev->dev.type == &fsl_mc_bus_dpni_type;
455}
456
457static inline bool is_fsl_mc_bus_dpio(const struct fsl_mc_device *mc_dev)
458{
459 return mc_dev->dev.type == &fsl_mc_bus_dpio_type;
460}
461
462static inline bool is_fsl_mc_bus_dpsw(const struct fsl_mc_device *mc_dev)
463{
464 return mc_dev->dev.type == &fsl_mc_bus_dpsw_type;
465}
466
467static inline bool is_fsl_mc_bus_dpdmux(const struct fsl_mc_device *mc_dev)
468{
469 return mc_dev->dev.type == &fsl_mc_bus_dpdmux_type;
470}
471
472static inline bool is_fsl_mc_bus_dpbp(const struct fsl_mc_device *mc_dev)
473{
474 return mc_dev->dev.type == &fsl_mc_bus_dpbp_type;
475}
476
477static inline bool is_fsl_mc_bus_dpcon(const struct fsl_mc_device *mc_dev)
478{
479 return mc_dev->dev.type == &fsl_mc_bus_dpcon_type;
480}
481
482static inline bool is_fsl_mc_bus_dpmcp(const struct fsl_mc_device *mc_dev)
483{
484 return mc_dev->dev.type == &fsl_mc_bus_dpmcp_type;
485}
486
487static inline bool is_fsl_mc_bus_dpmac(const struct fsl_mc_device *mc_dev)
488{
489 return mc_dev->dev.type == &fsl_mc_bus_dpmac_type;
490}
491
492static inline bool is_fsl_mc_bus_dprtc(const struct fsl_mc_device *mc_dev)
493{
494 return mc_dev->dev.type == &fsl_mc_bus_dprtc_type;
495}
496
497static inline bool is_fsl_mc_bus_dpseci(const struct fsl_mc_device *mc_dev)
498{
499 return mc_dev->dev.type == &fsl_mc_bus_dpseci_type;
500}
501
502static inline bool is_fsl_mc_bus_dpdcei(const struct fsl_mc_device *mc_dev)
503{
504 return mc_dev->dev.type == &fsl_mc_bus_dpdcei_type;
505}
506
507static inline bool is_fsl_mc_bus_dpaiop(const struct fsl_mc_device *mc_dev)
508{
509 return mc_dev->dev.type == &fsl_mc_bus_dpaiop_type;
510}
511
512static inline bool is_fsl_mc_bus_dpci(const struct fsl_mc_device *mc_dev)
513{
514 return mc_dev->dev.type == &fsl_mc_bus_dpci_type;
515}
516
517static inline bool is_fsl_mc_bus_dpdmai(const struct fsl_mc_device *mc_dev)
518{
519 return mc_dev->dev.type == &fsl_mc_bus_dpdmai_type;
520}
521
522#define DPRC_RESET_OPTION_NON_RECURSIVE 0x00000001
523int dprc_reset_container(struct fsl_mc_io *mc_io,
524 u32 cmd_flags,
525 u16 token,
526 int child_container_id,
527 u32 options);
528
529int dprc_scan_container(struct fsl_mc_device *mc_bus_dev,
530 bool alloc_interrupts);
531
532void dprc_remove_devices(struct fsl_mc_device *mc_bus_dev,
533 struct fsl_mc_obj_desc *obj_desc_array,
534 int num_child_objects_in_mc);
535
536int dprc_cleanup(struct fsl_mc_device *mc_dev);
537
538int dprc_setup(struct fsl_mc_device *mc_dev);
539
540
541
542
543
544#define FSL_MC_IRQ_POOL_MAX_TOTAL_IRQS 256
545
546int fsl_mc_populate_irq_pool(struct fsl_mc_device *mc_bus_dev,
547 unsigned int irq_count);
548
549void fsl_mc_cleanup_irq_pool(struct fsl_mc_device *mc_bus_dev);
550
551
552
553
554
555
556int dpbp_open(struct fsl_mc_io *mc_io,
557 u32 cmd_flags,
558 int dpbp_id,
559 u16 *token);
560
561int dpbp_close(struct fsl_mc_io *mc_io,
562 u32 cmd_flags,
563 u16 token);
564
565int dpbp_enable(struct fsl_mc_io *mc_io,
566 u32 cmd_flags,
567 u16 token);
568
569int dpbp_disable(struct fsl_mc_io *mc_io,
570 u32 cmd_flags,
571 u16 token);
572
573int dpbp_reset(struct fsl_mc_io *mc_io,
574 u32 cmd_flags,
575 u16 token);
576
577
578
579
580
581
582
583struct dpbp_attr {
584 int id;
585 u16 bpid;
586};
587
588int dpbp_get_attributes(struct fsl_mc_io *mc_io,
589 u32 cmd_flags,
590 u16 token,
591 struct dpbp_attr *attr);
592
593
594
595
596
597
598
599
600#define DPCON_INVALID_DPIO_ID (int)(-1)
601
602int dpcon_open(struct fsl_mc_io *mc_io,
603 u32 cmd_flags,
604 int dpcon_id,
605 u16 *token);
606
607int dpcon_close(struct fsl_mc_io *mc_io,
608 u32 cmd_flags,
609 u16 token);
610
611int dpcon_enable(struct fsl_mc_io *mc_io,
612 u32 cmd_flags,
613 u16 token);
614
615int dpcon_disable(struct fsl_mc_io *mc_io,
616 u32 cmd_flags,
617 u16 token);
618
619int dpcon_reset(struct fsl_mc_io *mc_io,
620 u32 cmd_flags,
621 u16 token);
622
623
624
625
626
627
628
629struct dpcon_attr {
630 int id;
631 u16 qbman_ch_id;
632 u8 num_priorities;
633};
634
635int dpcon_get_attributes(struct fsl_mc_io *mc_io,
636 u32 cmd_flags,
637 u16 token,
638 struct dpcon_attr *attr);
639
640
641
642
643
644
645
646
647
648struct dpcon_notification_cfg {
649 int dpio_id;
650 u8 priority;
651 u64 user_ctx;
652};
653
654int dpcon_set_notification(struct fsl_mc_io *mc_io,
655 u32 cmd_flags,
656 u16 token,
657 struct dpcon_notification_cfg *cfg);
658
659#endif
660