Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / fsl / mc.h
CommitLineData
203e2de3 1/* SPDX-License-Identifier: GPL-2.0 */
bbf9d17d
GR
2/*
3 * Freescale Management Complex (MC) bus public interface
4 *
6466dac7 5 * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
bbf9d17d
GR
6 * Author: German Rivera <German.Rivera@freescale.com>
7 *
bbf9d17d
GR
8 */
9#ifndef _FSL_MC_H_
10#define _FSL_MC_H_
11
12#include <linux/device.h>
13#include <linux/mod_devicetable.h>
89f067df 14#include <linux/interrupt.h>
bbf9d17d
GR
15
16#define FSL_MC_VENDOR_FREESCALE 0x1957
17
7211e711
LT
18struct irq_domain;
19struct msi_domain_info;
20
bbf9d17d
GR
21struct fsl_mc_device;
22struct fsl_mc_io;
23
24/**
25 * struct fsl_mc_driver - MC object device driver object
26 * @driver: Generic device driver
27 * @match_id_table: table of supported device matching Ids
28 * @probe: Function called when a device is added
29 * @remove: Function called when a device is removed
30 * @shutdown: Function called at shutdown time to quiesce the device
31 * @suspend: Function called when a device is stopped
32 * @resume: Function called when a device is resumed
33 *
34 * Generic DPAA device driver object for device drivers that are registered
35 * with a DPRC bus. This structure is to be embedded in each device-specific
36 * driver structure.
37 */
38struct fsl_mc_driver {
39 struct device_driver driver;
57538afb 40 const struct fsl_mc_device_id *match_id_table;
bbf9d17d
GR
41 int (*probe)(struct fsl_mc_device *dev);
42 int (*remove)(struct fsl_mc_device *dev);
43 void (*shutdown)(struct fsl_mc_device *dev);
44 int (*suspend)(struct fsl_mc_device *dev, pm_message_t state);
45 int (*resume)(struct fsl_mc_device *dev);
46};
47
48#define to_fsl_mc_driver(_drv) \
49 container_of(_drv, struct fsl_mc_driver, driver)
50
197f4d6a
GR
51/**
52 * enum fsl_mc_pool_type - Types of allocatable MC bus resources
53 *
54 * Entries in these enum are used as indices in the array of resource
55 * pools of an fsl_mc_bus object.
56 */
57enum fsl_mc_pool_type {
58 FSL_MC_POOL_DPMCP = 0x0, /* corresponds to "dpmcp" in the MC */
59 FSL_MC_POOL_DPBP, /* corresponds to "dpbp" in the MC */
60 FSL_MC_POOL_DPCON, /* corresponds to "dpcon" in the MC */
89f067df 61 FSL_MC_POOL_IRQ,
197f4d6a
GR
62
63 /*
64 * NOTE: New resource pool types must be added before this entry
65 */
66 FSL_MC_NUM_POOL_TYPES
67};
68
69/**
70 * struct fsl_mc_resource - MC generic resource
71 * @type: type of resource
72 * @id: unique MC resource Id within the resources of the same type
73 * @data: pointer to resource-specific data if the resource is currently
74 * allocated, or NULL if the resource is not currently allocated.
75 * @parent_pool: pointer to the parent resource pool from which this
76 * resource is allocated from.
77 * @node: Node in the free list of the corresponding resource pool
78 *
79 * NOTE: This structure is to be embedded as a field of specific
80 * MC resource structures.
81 */
82struct fsl_mc_resource {
83 enum fsl_mc_pool_type type;
e273d543 84 s32 id;
197f4d6a
GR
85 void *data;
86 struct fsl_mc_resource_pool *parent_pool;
87 struct list_head node;
88};
89
679c2c75
GR
90/**
91 * struct fsl_mc_device_irq - MC object device message-based interrupt
92 * @msi_desc: pointer to MSI descriptor allocated by fsl_mc_msi_alloc_descs()
93 * @mc_dev: MC object device that owns this interrupt
94 * @dev_irq_index: device-relative IRQ index
95 * @resource: MC generic resource associated with the interrupt
96 */
97struct fsl_mc_device_irq {
98 struct msi_desc *msi_desc;
99 struct fsl_mc_device *mc_dev;
100 u8 dev_irq_index;
101 struct fsl_mc_resource resource;
102};
103
104#define to_fsl_mc_irq(_mc_resource) \
105 container_of(_mc_resource, struct fsl_mc_device_irq, resource)
106
0cf9f509
LT
107/* Opened state - Indicates that an object is open by at least one owner */
108#define FSL_MC_OBJ_STATE_OPEN 0x00000001
109/* Plugged state - Indicates that the object is plugged */
110#define FSL_MC_OBJ_STATE_PLUGGED 0x00000002
111
112/**
113 * Shareability flag - Object flag indicating no memory shareability.
114 * the object generates memory accesses that are non coherent with other
115 * masters;
116 * user is responsible for proper memory handling through IOMMU configuration.
117 */
118#define FSL_MC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
119
120/**
121 * struct fsl_mc_obj_desc - Object descriptor
122 * @type: Type of object: NULL terminated string
123 * @id: ID of logical object resource
124 * @vendor: Object vendor identifier
125 * @ver_major: Major version number
126 * @ver_minor: Minor version number
127 * @irq_count: Number of interrupts supported by the object
128 * @region_count: Number of mappable regions supported by the object
129 * @state: Object state: combination of FSL_MC_OBJ_STATE_ states
130 * @label: Object label: NULL terminated string
131 * @flags: Object's flags
132 */
133struct fsl_mc_obj_desc {
134 char type[16];
135 int id;
136 u16 vendor;
137 u16 ver_major;
138 u16 ver_minor;
139 u8 irq_count;
140 u8 region_count;
141 u32 state;
142 char label[16];
143 u16 flags;
144};
145
bbf9d17d
GR
146/**
147 * Bit masks for a MC object device (struct fsl_mc_device) flags
148 */
149#define FSL_MC_IS_DPRC 0x0001
150
bbf9d17d
GR
151/**
152 * struct fsl_mc_device - MC object device object
153 * @dev: Linux driver model device object
154 * @dma_mask: Default DMA mask
155 * @flags: MC object device flags
156 * @icid: Isolation context ID for the device
157 * @mc_handle: MC handle for the corresponding MC object opened
158 * @mc_io: Pointer to MC IO object assigned to this device or
159 * NULL if none.
160 * @obj_desc: MC description of the DPAA device
161 * @regions: pointer to array of MMIO region entries
89f067df 162 * @irqs: pointer to array of pointers to interrupts allocated to this device
197f4d6a 163 * @resource: generic resource associated with this MC object device, if any.
bbf9d17d
GR
164 *
165 * Generic device object for MC object devices that are "attached" to a
166 * MC bus.
167 *
168 * NOTES:
169 * - For a non-DPRC object its icid is the same as its parent DPRC's icid.
170 * - The SMMU notifier callback gets invoked after device_add() has been
171 * called for an MC object device, but before the device-specific probe
172 * callback gets called.
197f4d6a
GR
173 * - DP_OBJ_DPRC objects are the only MC objects that have built-in MC
174 * portals. For all other MC objects, their device drivers are responsible for
175 * allocating MC portals for them by calling fsl_mc_portal_allocate().
176 * - Some types of MC objects (e.g., DP_OBJ_DPBP, DP_OBJ_DPCON) are
177 * treated as resources that can be allocated/deallocated from the
178 * corresponding resource pool in the object's parent DPRC, using the
179 * fsl_mc_object_allocate()/fsl_mc_object_free() functions. These MC objects
180 * are known as "allocatable" objects. For them, the corresponding
181 * fsl_mc_device's 'resource' points to the associated resource object.
182 * For MC objects that are not allocatable (e.g., DP_OBJ_DPRC, DP_OBJ_DPNI),
183 * 'resource' is NULL.
bbf9d17d
GR
184 */
185struct fsl_mc_device {
186 struct device dev;
ba72f25b
GR
187 u64 dma_mask;
188 u16 flags;
189 u16 icid;
190 u16 mc_handle;
bbf9d17d 191 struct fsl_mc_io *mc_io;
0cf9f509 192 struct fsl_mc_obj_desc obj_desc;
bbf9d17d 193 struct resource *regions;
89f067df 194 struct fsl_mc_device_irq **irqs;
197f4d6a 195 struct fsl_mc_resource *resource;
afb77422 196 struct device_link *consumer_link;
bbf9d17d
GR
197};
198
199#define to_fsl_mc_device(_dev) \
200 container_of(_dev, struct fsl_mc_device, dev)
201
d30a41db
LT
202#define MC_CMD_NUM_OF_PARAMS 7
203
204struct mc_cmd_header {
205 u8 src_id;
206 u8 flags_hw;
207 u8 status;
208 u8 flags_sw;
209 __le16 token;
210 __le16 cmd_id;
211};
212
5b04cede 213struct fsl_mc_command {
d693eb39
IC
214 __le64 header;
215 __le64 params[MC_CMD_NUM_OF_PARAMS];
d30a41db
LT
216};
217
218enum mc_cmd_status {
219 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
220 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
221 MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
222 MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
223 MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
224 MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
225 MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
226 MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
227 MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
228 MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
229 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
230 MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
231};
232
233/*
234 * MC command flags
235 */
236
237/* High priority flag */
238#define MC_CMD_FLAG_PRI 0x80
239/* Command completion flag */
240#define MC_CMD_FLAG_INTR_DIS 0x01
241
d693eb39
IC
242static inline __le64 mc_encode_cmd_header(u16 cmd_id,
243 u32 cmd_flags,
244 u16 token)
d30a41db 245{
d693eb39 246 __le64 header = 0;
d30a41db
LT
247 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
248
249 hdr->cmd_id = cpu_to_le16(cmd_id);
250 hdr->token = cpu_to_le16(token);
251 hdr->status = MC_CMD_STATUS_READY;
252 if (cmd_flags & MC_CMD_FLAG_PRI)
253 hdr->flags_hw = MC_CMD_FLAG_PRI;
254 if (cmd_flags & MC_CMD_FLAG_INTR_DIS)
255 hdr->flags_sw = MC_CMD_FLAG_INTR_DIS;
256
257 return header;
258}
259
5b04cede 260static inline u16 mc_cmd_hdr_read_token(struct fsl_mc_command *cmd)
d30a41db
LT
261{
262 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
263 u16 token = le16_to_cpu(hdr->token);
264
265 return token;
266}
267
268struct mc_rsp_create {
269 __le32 object_id;
270};
271
272struct mc_rsp_api_ver {
273 __le16 major_ver;
274 __le16 minor_ver;
275};
276
5b04cede 277static inline u32 mc_cmd_read_object_id(struct fsl_mc_command *cmd)
d30a41db
LT
278{
279 struct mc_rsp_create *rsp_params;
280
281 rsp_params = (struct mc_rsp_create *)cmd->params;
282 return le32_to_cpu(rsp_params->object_id);
283}
284
5b04cede 285static inline void mc_cmd_read_api_version(struct fsl_mc_command *cmd,
d30a41db
LT
286 u16 *major_ver,
287 u16 *minor_ver)
288{
289 struct mc_rsp_api_ver *rsp_params;
290
291 rsp_params = (struct mc_rsp_api_ver *)cmd->params;
292 *major_ver = le16_to_cpu(rsp_params->major_ver);
293 *minor_ver = le16_to_cpu(rsp_params->minor_ver);
294}
295
fab8ca58
LT
296/**
297 * Bit masks for a MC I/O object (struct fsl_mc_io) flags
298 */
299#define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL 0x0001
300
301/**
302 * struct fsl_mc_io - MC I/O object to be passed-in to mc_send_command()
303 * @dev: device associated with this Mc I/O object
304 * @flags: flags for mc_send_command()
305 * @portal_size: MC command portal size in bytes
306 * @portal_phys_addr: MC command portal physical address
307 * @portal_virt_addr: MC command portal virtual address
308 * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
309 *
310 * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not
311 * set:
312 * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
313 * portal, if the fsl_mc_io object was created with the
314 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
315 * fsl_mc_io object must be made only from non-atomic context.
316 *
317 * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is
318 * set:
319 * @spinlock: Spinlock to serialize mc_send_command() calls that use the same MC
320 * portal, if the fsl_mc_io object was created with the
321 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag on. mc_send_command() calls for this
322 * fsl_mc_io object can be made from atomic or non-atomic context.
323 */
324struct fsl_mc_io {
325 struct device *dev;
326 u16 flags;
612b5bac 327 u32 portal_size;
fab8ca58
LT
328 phys_addr_t portal_phys_addr;
329 void __iomem *portal_virt_addr;
330 struct fsl_mc_device *dpmcp_dev;
331 union {
332 /*
333 * This field is only meaningful if the
334 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not set
335 */
336 struct mutex mutex; /* serializes mc_send_command() */
337
338 /*
339 * This field is only meaningful if the
340 * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is set
341 */
342 spinlock_t spinlock; /* serializes mc_send_command() */
343 };
344};
345
5b04cede 346int mc_send_command(struct fsl_mc_io *mc_io, struct fsl_mc_command *cmd);
fab8ca58 347
61aa52c7
LT
348#ifdef CONFIG_FSL_MC_BUS
349#define dev_is_fsl_mc(_dev) ((_dev)->bus == &fsl_mc_bus_type)
350#else
351/* If fsl-mc bus is not present device cannot belong to fsl-mc bus */
352#define dev_is_fsl_mc(_dev) (0)
353#endif
354
eab03e2a
NG
355/* Macro to check if a device is a container device */
356#define fsl_mc_is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & \
357 FSL_MC_IS_DPRC)
358
359/* Macro to get the container device of a MC device */
360#define fsl_mc_cont_dev(_dev) (fsl_mc_is_cont_dev(_dev) ? \
361 (_dev) : (_dev)->parent)
362
bbf9d17d
GR
363/*
364 * module_fsl_mc_driver() - Helper macro for drivers that don't do
365 * anything special in module init/exit. This eliminates a lot of
366 * boilerplate. Each module may only use this macro once, and
367 * calling it replaces module_init() and module_exit()
368 */
369#define module_fsl_mc_driver(__fsl_mc_driver) \
370 module_driver(__fsl_mc_driver, fsl_mc_driver_register, \
371 fsl_mc_driver_unregister)
372
373/*
374 * Macro to avoid include chaining to get THIS_MODULE
375 */
376#define fsl_mc_driver_register(drv) \
377 __fsl_mc_driver_register(drv, THIS_MODULE)
378
379int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
380 struct module *owner);
381
382void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
383
197f4d6a 384int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
ba72f25b 385 u16 mc_io_flags,
197f4d6a
GR
386 struct fsl_mc_io **new_mc_io);
387
388void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
389
390int fsl_mc_portal_reset(struct fsl_mc_io *mc_io);
391
392int __must_check fsl_mc_object_allocate(struct fsl_mc_device *mc_dev,
393 enum fsl_mc_pool_type pool_type,
394 struct fsl_mc_device **new_mc_adev);
395
396void fsl_mc_object_free(struct fsl_mc_device *mc_adev);
397
7211e711
LT
398struct irq_domain *fsl_mc_msi_create_irq_domain(struct fwnode_handle *fwnode,
399 struct msi_domain_info *info,
400 struct irq_domain *parent);
401
89f067df
GR
402int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev);
403
404void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
405
1ac210d1
IC
406struct fsl_mc_device *fsl_mc_get_endpoint(struct fsl_mc_device *mc_dev);
407
61aa52c7
LT
408extern struct bus_type fsl_mc_bus_type;
409
47433b63
LT
410extern struct device_type fsl_mc_bus_dprc_type;
411extern struct device_type fsl_mc_bus_dpni_type;
412extern struct device_type fsl_mc_bus_dpio_type;
413extern struct device_type fsl_mc_bus_dpsw_type;
414extern struct device_type fsl_mc_bus_dpbp_type;
415extern struct device_type fsl_mc_bus_dpcon_type;
416extern struct device_type fsl_mc_bus_dpmcp_type;
417extern struct device_type fsl_mc_bus_dpmac_type;
418extern struct device_type fsl_mc_bus_dprtc_type;
e9158b35 419extern struct device_type fsl_mc_bus_dpseci_type;
47433b63
LT
420
421static inline bool is_fsl_mc_bus_dprc(const struct fsl_mc_device *mc_dev)
422{
423 return mc_dev->dev.type == &fsl_mc_bus_dprc_type;
424}
425
426static inline bool is_fsl_mc_bus_dpni(const struct fsl_mc_device *mc_dev)
427{
428 return mc_dev->dev.type == &fsl_mc_bus_dpni_type;
429}
430
431static inline bool is_fsl_mc_bus_dpio(const struct fsl_mc_device *mc_dev)
432{
433 return mc_dev->dev.type == &fsl_mc_bus_dpio_type;
434}
435
436static inline bool is_fsl_mc_bus_dpsw(const struct fsl_mc_device *mc_dev)
437{
438 return mc_dev->dev.type == &fsl_mc_bus_dpsw_type;
439}
440
441static inline bool is_fsl_mc_bus_dpbp(const struct fsl_mc_device *mc_dev)
442{
443 return mc_dev->dev.type == &fsl_mc_bus_dpbp_type;
444}
445
446static inline bool is_fsl_mc_bus_dpcon(const struct fsl_mc_device *mc_dev)
447{
448 return mc_dev->dev.type == &fsl_mc_bus_dpcon_type;
449}
450
451static inline bool is_fsl_mc_bus_dpmcp(const struct fsl_mc_device *mc_dev)
452{
453 return mc_dev->dev.type == &fsl_mc_bus_dpmcp_type;
454}
455
456static inline bool is_fsl_mc_bus_dpmac(const struct fsl_mc_device *mc_dev)
457{
458 return mc_dev->dev.type == &fsl_mc_bus_dpmac_type;
459}
460
461static inline bool is_fsl_mc_bus_dprtc(const struct fsl_mc_device *mc_dev)
462{
463 return mc_dev->dev.type == &fsl_mc_bus_dprtc_type;
464}
465
e9158b35
HG
466static inline bool is_fsl_mc_bus_dpseci(const struct fsl_mc_device *mc_dev)
467{
468 return mc_dev->dev.type == &fsl_mc_bus_dpseci_type;
469}
470
9c692d5a
BP
471/*
472 * Data Path Buffer Pool (DPBP) API
473 * Contains initialization APIs and runtime control APIs for DPBP
474 */
475
476int dpbp_open(struct fsl_mc_io *mc_io,
477 u32 cmd_flags,
478 int dpbp_id,
479 u16 *token);
480
481int dpbp_close(struct fsl_mc_io *mc_io,
482 u32 cmd_flags,
483 u16 token);
484
485int dpbp_enable(struct fsl_mc_io *mc_io,
486 u32 cmd_flags,
487 u16 token);
488
489int dpbp_disable(struct fsl_mc_io *mc_io,
490 u32 cmd_flags,
491 u16 token);
492
493int dpbp_reset(struct fsl_mc_io *mc_io,
494 u32 cmd_flags,
495 u16 token);
496
497/**
498 * struct dpbp_attr - Structure representing DPBP attributes
499 * @id: DPBP object ID
500 * @bpid: Hardware buffer pool ID; should be used as an argument in
501 * acquire/release operations on buffers
502 */
503struct dpbp_attr {
504 int id;
505 u16 bpid;
506};
507
508int dpbp_get_attributes(struct fsl_mc_io *mc_io,
509 u32 cmd_flags,
510 u16 token,
511 struct dpbp_attr *attr);
512
70ae9cf0
BP
513/* Data Path Concentrator (DPCON) API
514 * Contains initialization APIs and runtime control APIs for DPCON
515 */
516
517/**
518 * Use it to disable notifications; see dpcon_set_notification()
519 */
520#define DPCON_INVALID_DPIO_ID (int)(-1)
521
522int dpcon_open(struct fsl_mc_io *mc_io,
523 u32 cmd_flags,
524 int dpcon_id,
525 u16 *token);
526
527int dpcon_close(struct fsl_mc_io *mc_io,
528 u32 cmd_flags,
529 u16 token);
530
531int dpcon_enable(struct fsl_mc_io *mc_io,
532 u32 cmd_flags,
533 u16 token);
534
535int dpcon_disable(struct fsl_mc_io *mc_io,
536 u32 cmd_flags,
537 u16 token);
538
539int dpcon_reset(struct fsl_mc_io *mc_io,
540 u32 cmd_flags,
541 u16 token);
542
543/**
544 * struct dpcon_attr - Structure representing DPCON attributes
545 * @id: DPCON object ID
546 * @qbman_ch_id: Channel ID to be used by dequeue operation
547 * @num_priorities: Number of priorities for the DPCON channel (1-8)
548 */
549struct dpcon_attr {
550 int id;
551 u16 qbman_ch_id;
552 u8 num_priorities;
553};
554
555int dpcon_get_attributes(struct fsl_mc_io *mc_io,
556 u32 cmd_flags,
557 u16 token,
558 struct dpcon_attr *attr);
559
560/**
561 * struct dpcon_notification_cfg - Structure representing notification params
562 * @dpio_id: DPIO object ID; must be configured with a notification channel;
563 * to disable notifications set it to 'DPCON_INVALID_DPIO_ID';
564 * @priority: Priority selection within the DPIO channel; valid values
565 * are 0-7, depending on the number of priorities in that channel
566 * @user_ctx: User context value provided with each CDAN message
567 */
568struct dpcon_notification_cfg {
569 int dpio_id;
570 u8 priority;
571 u64 user_ctx;
572};
573
574int dpcon_set_notification(struct fsl_mc_io *mc_io,
575 u32 cmd_flags,
576 u16 token,
577 struct dpcon_notification_cfg *cfg);
578
bbf9d17d 579#endif /* _FSL_MC_H_ */