Home | History | Annotate | Download | only in fsl-mc
      1 /* SPDX-License-Identifier: GPL-2.0+ */
      2 /*
      3  * Copyright 2013-2016 Freescale Semiconductor, Inc.
      4  * Copyright 2017 NXP
      5  */
      6 
      7 #ifndef _FSL_DPIO_H
      8 #define _FSL_DPIO_H
      9 
     10 /* DPIO Version */
     11 #define DPIO_VER_MAJOR				4
     12 #define DPIO_VER_MINOR				2
     13 
     14 /* Command IDs */
     15 #define DPIO_CMDID_CLOSE					0x8001
     16 #define DPIO_CMDID_OPEN						0x8031
     17 #define DPIO_CMDID_CREATE					0x9031
     18 #define DPIO_CMDID_DESTROY					0x9831
     19 #define DPIO_CMDID_GET_API_VERSION				0xa031
     20 
     21 #define DPIO_CMDID_ENABLE					0x0021
     22 #define DPIO_CMDID_DISABLE					0x0031
     23 #define DPIO_CMDID_GET_ATTR					0x0041
     24 #define DPIO_CMDID_RESET					0x0051
     25 
     26 /*                cmd, param, offset, width, type, arg_name */
     27 #define DPIO_CMD_OPEN(cmd, dpio_id) \
     28 	MC_CMD_OP(cmd, 0, 0,  32, int,     dpio_id)
     29 
     30 /*                cmd, param, offset, width, type, arg_name */
     31 #define DPIO_CMD_CREATE(cmd, cfg) \
     32 do { \
     33 	MC_CMD_OP(cmd, 0, 16, 2,  enum dpio_channel_mode,	\
     34 					   cfg->channel_mode);\
     35 	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t, cfg->num_priorities);\
     36 } while (0)
     37 
     38 /*                cmd, param, offset, width, type, arg_name */
     39 #define DPIO_RSP_GET_ATTR(cmd, attr) \
     40 do { \
     41 	MC_RSP_OP(cmd, 0, 0,  32, int,	    attr->id);\
     42 	MC_RSP_OP(cmd, 0, 32, 16, uint16_t, attr->qbman_portal_id);\
     43 	MC_RSP_OP(cmd, 0, 48, 8,  uint8_t,  attr->num_priorities);\
     44 	MC_RSP_OP(cmd, 0, 56, 4,  enum dpio_channel_mode, attr->channel_mode);\
     45 	MC_RSP_OP(cmd, 1, 0,  64, uint64_t, attr->qbman_portal_ce_offset);\
     46 	MC_RSP_OP(cmd, 2, 0,  64, uint64_t, attr->qbman_portal_ci_offset);\
     47 	MC_RSP_OP(cmd, 3, 32, 32, uint32_t, attr->qbman_version);\
     48 } while (0)
     49 
     50 /* Data Path I/O Portal API
     51  * Contains initialization APIs and runtime control APIs for DPIO
     52  */
     53 
     54 struct fsl_mc_io;
     55 
     56 /**
     57  * dpio_open() - Open a control session for the specified object
     58  * @mc_io:	Pointer to MC portal's I/O object
     59  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
     60  * @dpio_id:	DPIO unique ID
     61  * @token:	Returned token; use in subsequent API calls
     62  *
     63  * This function can be used to open a control session for an
     64  * already created object; an object may have been declared in
     65  * the DPL or by calling the dpio_create() function.
     66  * This function returns a unique authentication token,
     67  * associated with the specific object ID and the specific MC
     68  * portal; this token must be used in all subsequent commands for
     69  * this specific object.
     70  *
     71  * Return:	'0' on Success; Error code otherwise.
     72  */
     73 int dpio_open(struct fsl_mc_io	*mc_io,
     74 	      uint32_t		cmd_flags,
     75 	      uint32_t		dpio_id,
     76 	      uint16_t		*token);
     77 
     78 /**
     79  * dpio_close() - Close the control session of the object
     80  * @mc_io:	Pointer to MC portal's I/O object
     81  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
     82  * @token:	Token of DPIO object
     83  *
     84  * Return:	'0' on Success; Error code otherwise.
     85  */
     86 int dpio_close(struct fsl_mc_io	*mc_io,
     87 	       uint32_t		cmd_flags,
     88 	       uint16_t		token);
     89 
     90 /**
     91  * enum dpio_channel_mode - DPIO notification channel mode
     92  * @DPIO_NO_CHANNEL: No support for notification channel
     93  * @DPIO_LOCAL_CHANNEL: Notifications on data availability can be received by a
     94  *	dedicated channel in the DPIO; user should point the queue's
     95  *	destination in the relevant interface to this DPIO
     96  */
     97 enum dpio_channel_mode {
     98 	DPIO_NO_CHANNEL = 0,
     99 	DPIO_LOCAL_CHANNEL = 1,
    100 };
    101 
    102 /**
    103  * struct dpio_cfg - Structure representing DPIO configuration
    104  * @channel_mode: Notification channel mode
    105  * @num_priorities: Number of priorities for the notification channel (1-8);
    106  *			relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
    107  */
    108 struct dpio_cfg {
    109 	enum dpio_channel_mode	channel_mode;
    110 	uint8_t		num_priorities;
    111 };
    112 
    113 /**
    114  * dpio_create() - Create the DPIO object.
    115  * @mc_io:	Pointer to MC portal's I/O object
    116  * @token:	Authentication token.
    117  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    118  * @cfg:	Configuration structure
    119  * @obj_id:	Returned obj_id; use in subsequent API calls
    120  *
    121  * Create the DPIO object, allocate required resources and
    122  * perform required initialization.
    123  *
    124  * The object can be created either by declaring it in the
    125  * DPL file, or by calling this function.
    126  *
    127  * This function returns a unique authentication token,
    128  * associated with the specific object ID and the specific MC
    129  * portal; this token must be used in all subsequent calls to
    130  * this specific object. For objects that are created using the
    131  * DPL file, call dpio_open() function to get an authentication
    132  * token first.
    133  *
    134  * Return:	'0' on Success; Error code otherwise.
    135  */
    136 int dpio_create(struct fsl_mc_io	*mc_io,
    137 		uint16_t		token,
    138 		uint32_t		cmd_flags,
    139 		const struct dpio_cfg	*cfg,
    140 		uint32_t		*obj_id);
    141 
    142 /**
    143  * dpio_destroy() - Destroy the DPIO object and release all its resources.
    144  * @mc_io:	Pointer to MC portal's I/O object
    145  * @token:	Authentication token.
    146  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    147  * @obj_id:	Object ID of DPIO
    148  *
    149  * Return:	'0' on Success; Error code otherwise
    150  */
    151 int dpio_destroy(struct fsl_mc_io	*mc_io,
    152 		 uint16_t		token,
    153 		 uint32_t		cmd_flags,
    154 		 uint32_t		obj_id);
    155 
    156 /**
    157  * dpio_enable() - Enable the DPIO, allow I/O portal operations.
    158  * @mc_io:	Pointer to MC portal's I/O object
    159  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    160  * @token:	Token of DPIO object
    161  *
    162  * Return:	'0' on Success; Error code otherwise
    163  */
    164 int dpio_enable(struct fsl_mc_io	*mc_io,
    165 		uint32_t		cmd_flags,
    166 		uint16_t		token);
    167 
    168 /**
    169  * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
    170  * @mc_io:	Pointer to MC portal's I/O object
    171  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    172  * @token:	Token of DPIO object
    173  *
    174  * Return:	'0' on Success; Error code otherwise
    175  */
    176 int dpio_disable(struct fsl_mc_io	*mc_io,
    177 		 uint32_t		cmd_flags,
    178 		 uint16_t		token);
    179 
    180 /**
    181  * dpio_reset() - Reset the DPIO, returns the object to initial state.
    182  * @mc_io:	Pointer to MC portal's I/O object
    183  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    184  * @token:	Token of DPIO object
    185  *
    186  * Return:	'0' on Success; Error code otherwise.
    187  */
    188 int dpio_reset(struct fsl_mc_io	*mc_io,
    189 	       uint32_t			cmd_flags,
    190 	       uint16_t		token);
    191 
    192 /**
    193  * struct dpio_attr - Structure representing DPIO attributes
    194  * @id: DPIO object ID
    195  * @version: DPIO version
    196  * @qbman_portal_ce_offset: offset of the software portal cache-enabled area
    197  * @qbman_portal_ci_offset: offset of the software portal cache-inhibited area
    198  * @qbman_portal_id: Software portal ID
    199  * @channel_mode: Notification channel mode
    200  * @num_priorities: Number of priorities for the notification channel (1-8);
    201  *			relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
    202  * @qbman_version: QBMAN version
    203  */
    204 struct dpio_attr {
    205 	uint32_t id;
    206 	uint64_t qbman_portal_ce_offset;
    207 	uint64_t qbman_portal_ci_offset;
    208 	uint16_t qbman_portal_id;
    209 	enum dpio_channel_mode channel_mode;
    210 	uint8_t num_priorities;
    211 	uint32_t		qbman_version;
    212 };
    213 
    214 /**
    215  * dpio_get_attributes() - Retrieve DPIO attributes
    216  * @mc_io:	Pointer to MC portal's I/O object
    217  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    218  * @token:	Token of DPIO object
    219  * @attr:	Returned object's attributes
    220  *
    221  * Return:	'0' on Success; Error code otherwise
    222  */
    223 int dpio_get_attributes(struct fsl_mc_io	*mc_io,
    224 			uint32_t		cmd_flags,
    225 			uint16_t		token,
    226 			struct dpio_attr	*attr);
    227 
    228 /**
    229  * dpio_get_api_version - Retrieve DPIO Major and Minor version info.
    230  *
    231  * @mc_io:	Pointer to MC portal's I/O object
    232  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
    233  * @major_ver:	DPIO major version
    234  * @minor_ver:	DPIO minor version
    235  *
    236  * Return:	'0' on Success; Error code otherwise.
    237  */
    238 int dpio_get_api_version(struct fsl_mc_io *mc_io,
    239 			 u32 cmd_flags,
    240 			 u16 *major_ver,
    241 			 u16 *minor_ver);
    242 
    243 #endif /* _FSL_DPIO_H */
    244