Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
| 2 | /* |
| 3 | * Copyright 2013-2016 Freescale Semiconductor Inc. |
| 4 | * Copyright 2016 NXP |
| 5 | * |
| 6 | */ |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/fsl/mc.h> |
| 9 | |
| 10 | #include "dpio.h" |
| 11 | #include "dpio-cmd.h" |
| 12 | |
| 13 | /* |
| 14 | * Data Path I/O Portal API |
| 15 | * Contains initialization APIs and runtime control APIs for DPIO |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * dpio_open() - Open a control session for the specified object |
| 20 | * @mc_io: Pointer to MC portal's I/O object |
| 21 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 22 | * @dpio_id: DPIO unique ID |
| 23 | * @token: Returned token; use in subsequent API calls |
| 24 | * |
| 25 | * This function can be used to open a control session for an |
| 26 | * already created object; an object may have been declared in |
| 27 | * the DPL or by calling the dpio_create() function. |
| 28 | * This function returns a unique authentication token, |
| 29 | * associated with the specific object ID and the specific MC |
| 30 | * portal; this token must be used in all subsequent commands for |
| 31 | * this specific object. |
| 32 | * |
| 33 | * Return: '0' on Success; Error code otherwise. |
| 34 | */ |
| 35 | int dpio_open(struct fsl_mc_io *mc_io, |
| 36 | u32 cmd_flags, |
| 37 | int dpio_id, |
| 38 | u16 *token) |
| 39 | { |
| 40 | struct fsl_mc_command cmd = { 0 }; |
| 41 | struct dpio_cmd_open *dpio_cmd; |
| 42 | int err; |
| 43 | |
| 44 | /* prepare command */ |
| 45 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN, |
| 46 | cmd_flags, |
| 47 | 0); |
| 48 | dpio_cmd = (struct dpio_cmd_open *)cmd.params; |
| 49 | dpio_cmd->dpio_id = cpu_to_le32(dpio_id); |
| 50 | |
| 51 | err = mc_send_command(mc_io, &cmd); |
| 52 | if (err) |
| 53 | return err; |
| 54 | |
| 55 | /* retrieve response parameters */ |
| 56 | *token = mc_cmd_hdr_read_token(&cmd); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * dpio_close() - Close the control session of the object |
| 63 | * @mc_io: Pointer to MC portal's I/O object |
| 64 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 65 | * @token: Token of DPIO object |
| 66 | * |
| 67 | * Return: '0' on Success; Error code otherwise. |
| 68 | */ |
| 69 | int dpio_close(struct fsl_mc_io *mc_io, |
| 70 | u32 cmd_flags, |
| 71 | u16 token) |
| 72 | { |
| 73 | struct fsl_mc_command cmd = { 0 }; |
| 74 | |
| 75 | /* prepare command */ |
| 76 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE, |
| 77 | cmd_flags, |
| 78 | token); |
| 79 | |
| 80 | return mc_send_command(mc_io, &cmd); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * dpio_enable() - Enable the DPIO, allow I/O portal operations. |
| 85 | * @mc_io: Pointer to MC portal's I/O object |
| 86 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 87 | * @token: Token of DPIO object |
| 88 | * |
| 89 | * Return: '0' on Success; Error code otherwise |
| 90 | */ |
| 91 | int dpio_enable(struct fsl_mc_io *mc_io, |
| 92 | u32 cmd_flags, |
| 93 | u16 token) |
| 94 | { |
| 95 | struct fsl_mc_command cmd = { 0 }; |
| 96 | |
| 97 | /* prepare command */ |
| 98 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE, |
| 99 | cmd_flags, |
| 100 | token); |
| 101 | |
| 102 | return mc_send_command(mc_io, &cmd); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * dpio_disable() - Disable the DPIO, stop any I/O portal operation. |
| 107 | * @mc_io: Pointer to MC portal's I/O object |
| 108 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 109 | * @token: Token of DPIO object |
| 110 | * |
| 111 | * Return: '0' on Success; Error code otherwise |
| 112 | */ |
| 113 | int dpio_disable(struct fsl_mc_io *mc_io, |
| 114 | u32 cmd_flags, |
| 115 | u16 token) |
| 116 | { |
| 117 | struct fsl_mc_command cmd = { 0 }; |
| 118 | |
| 119 | /* prepare command */ |
| 120 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE, |
| 121 | cmd_flags, |
| 122 | token); |
| 123 | |
| 124 | return mc_send_command(mc_io, &cmd); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * dpio_get_attributes() - Retrieve DPIO attributes |
| 129 | * @mc_io: Pointer to MC portal's I/O object |
| 130 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 131 | * @token: Token of DPIO object |
| 132 | * @attr: Returned object's attributes |
| 133 | * |
| 134 | * Return: '0' on Success; Error code otherwise |
| 135 | */ |
| 136 | int dpio_get_attributes(struct fsl_mc_io *mc_io, |
| 137 | u32 cmd_flags, |
| 138 | u16 token, |
| 139 | struct dpio_attr *attr) |
| 140 | { |
| 141 | struct fsl_mc_command cmd = { 0 }; |
| 142 | struct dpio_rsp_get_attr *dpio_rsp; |
| 143 | int err; |
| 144 | |
| 145 | /* prepare command */ |
| 146 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR, |
| 147 | cmd_flags, |
| 148 | token); |
| 149 | |
| 150 | err = mc_send_command(mc_io, &cmd); |
| 151 | if (err) |
| 152 | return err; |
| 153 | |
| 154 | /* retrieve response parameters */ |
| 155 | dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params; |
| 156 | attr->id = le32_to_cpu(dpio_rsp->id); |
| 157 | attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id); |
| 158 | attr->num_priorities = dpio_rsp->num_priorities; |
| 159 | attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK; |
| 160 | attr->qbman_portal_ce_offset = |
| 161 | le64_to_cpu(dpio_rsp->qbman_portal_ce_addr); |
| 162 | attr->qbman_portal_ci_offset = |
| 163 | le64_to_cpu(dpio_rsp->qbman_portal_ci_addr); |
| 164 | attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * dpio_get_api_version - Get Data Path I/O API version |
| 171 | * @mc_io: Pointer to MC portal's DPIO object |
| 172 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 173 | * @major_ver: Major version of DPIO API |
| 174 | * @minor_ver: Minor version of DPIO API |
| 175 | * |
| 176 | * Return: '0' on Success; Error code otherwise |
| 177 | */ |
| 178 | int dpio_get_api_version(struct fsl_mc_io *mc_io, |
| 179 | u32 cmd_flags, |
| 180 | u16 *major_ver, |
| 181 | u16 *minor_ver) |
| 182 | { |
| 183 | struct fsl_mc_command cmd = { 0 }; |
| 184 | int err; |
| 185 | |
| 186 | /* prepare command */ |
| 187 | cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION, |
| 188 | cmd_flags, 0); |
| 189 | |
| 190 | err = mc_send_command(mc_io, &cmd); |
| 191 | if (err) |
| 192 | return err; |
| 193 | |
| 194 | /* retrieve response parameters */ |
| 195 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 196 | |
| 197 | return 0; |
| 198 | } |