Bogdan Purcareata | 203e2de | 2018-01-17 18:36:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
Stuart Yoder | 363b0cb | 2016-10-26 11:20:28 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2013-2016 Freescale Semiconductor Inc. |
Ramiro Oliveira | f86a180 | 2016-09-30 15:01:21 +0100 | [diff] [blame] | 4 | * |
Ramiro Oliveira | f86a180 | 2016-09-30 15:01:21 +0100 | [diff] [blame] | 5 | */ |
Laurentiu Tudor | 409acdd | 2017-06-27 17:41:32 +0300 | [diff] [blame] | 6 | #include <linux/kernel.h> |
Bogdan Purcareata | 6bd067c48 | 2018-02-05 08:07:42 -0600 | [diff] [blame] | 7 | #include <linux/fsl/mc.h> |
Bogdan Purcareata | 9c692d5 | 2018-03-02 04:23:58 -0600 | [diff] [blame] | 8 | #include <linux/fsl/mc.h> |
Stuart Yoder | 824ebf1 | 2016-10-17 13:42:18 -0500 | [diff] [blame] | 9 | |
Bogdan Purcareata | 9c692d5 | 2018-03-02 04:23:58 -0600 | [diff] [blame] | 10 | #include "fsl-mc-private.h" |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 11 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 12 | /** |
| 13 | * dpbp_open() - Open a control session for the specified object. |
| 14 | * @mc_io: Pointer to MC portal's I/O object |
| 15 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 16 | * @dpbp_id: DPBP unique ID |
| 17 | * @token: Returned token; use in subsequent API calls |
| 18 | * |
| 19 | * This function can be used to open a control session for an |
| 20 | * already created object; an object may have been declared in |
| 21 | * the DPL or by calling the dpbp_create function. |
| 22 | * This function returns a unique authentication token, |
| 23 | * associated with the specific object ID and the specific MC |
| 24 | * portal; this token must be used in all subsequent commands for |
| 25 | * this specific object |
| 26 | * |
| 27 | * Return: '0' on Success; Error code otherwise. |
| 28 | */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 29 | int dpbp_open(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 30 | u32 cmd_flags, |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 31 | int dpbp_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 32 | u16 *token) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 33 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 34 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 35 | struct dpbp_cmd_open *cmd_params; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 36 | int err; |
| 37 | |
| 38 | /* prepare command */ |
| 39 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN, |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 40 | cmd_flags, 0); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 41 | cmd_params = (struct dpbp_cmd_open *)cmd.params; |
| 42 | cmd_params->dpbp_id = cpu_to_le32(dpbp_id); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 43 | |
| 44 | /* send command to mc*/ |
| 45 | err = mc_send_command(mc_io, &cmd); |
| 46 | if (err) |
| 47 | return err; |
| 48 | |
| 49 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 50 | *token = mc_cmd_hdr_read_token(&cmd); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 51 | |
| 52 | return err; |
| 53 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 54 | EXPORT_SYMBOL_GPL(dpbp_open); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 55 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 56 | /** |
| 57 | * dpbp_close() - Close the control session of the 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 | * @token: Token of DPBP object |
| 61 | * |
| 62 | * After this function is called, no further operations are |
| 63 | * allowed on the object without opening a new control session. |
| 64 | * |
| 65 | * Return: '0' on Success; Error code otherwise. |
| 66 | */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 67 | int dpbp_close(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 68 | u32 cmd_flags, |
| 69 | u16 token) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 70 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 71 | struct fsl_mc_command cmd = { 0 }; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 72 | |
| 73 | /* prepare command */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 74 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags, |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 75 | token); |
| 76 | |
| 77 | /* send command to mc*/ |
| 78 | return mc_send_command(mc_io, &cmd); |
| 79 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 80 | EXPORT_SYMBOL_GPL(dpbp_close); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 81 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 82 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 83 | * dpbp_enable() - Enable the DPBP. |
| 84 | * @mc_io: Pointer to MC portal's I/O object |
| 85 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 86 | * @token: Token of DPBP object |
| 87 | * |
| 88 | * Return: '0' on Success; Error code otherwise. |
| 89 | */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 90 | int dpbp_enable(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 91 | u32 cmd_flags, |
| 92 | u16 token) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 93 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 94 | struct fsl_mc_command cmd = { 0 }; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 95 | |
| 96 | /* prepare command */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 97 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags, |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 98 | token); |
| 99 | |
| 100 | /* send command to mc*/ |
| 101 | return mc_send_command(mc_io, &cmd); |
| 102 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 103 | EXPORT_SYMBOL_GPL(dpbp_enable); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 104 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 105 | /** |
| 106 | * dpbp_disable() - Disable the DPBP. |
| 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 DPBP object |
| 110 | * |
| 111 | * Return: '0' on Success; Error code otherwise. |
| 112 | */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 113 | int dpbp_disable(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 114 | u32 cmd_flags, |
| 115 | u16 token) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 116 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 117 | struct fsl_mc_command cmd = { 0 }; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 118 | |
| 119 | /* prepare command */ |
| 120 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE, |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 121 | cmd_flags, token); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 122 | |
| 123 | /* send command to mc*/ |
| 124 | return mc_send_command(mc_io, &cmd); |
| 125 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 126 | EXPORT_SYMBOL_GPL(dpbp_disable); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 127 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 128 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 129 | * dpbp_reset() - Reset the DPBP, returns the object to initial state. |
| 130 | * @mc_io: Pointer to MC portal's I/O object |
| 131 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 132 | * @token: Token of DPBP object |
| 133 | * |
| 134 | * Return: '0' on Success; Error code otherwise. |
| 135 | */ |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 136 | int dpbp_reset(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 137 | u32 cmd_flags, |
| 138 | u16 token) |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 139 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 140 | struct fsl_mc_command cmd = { 0 }; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 141 | |
| 142 | /* prepare command */ |
| 143 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET, |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 144 | cmd_flags, token); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 145 | |
| 146 | /* send command to mc*/ |
| 147 | return mc_send_command(mc_io, &cmd); |
| 148 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 149 | EXPORT_SYMBOL_GPL(dpbp_reset); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 150 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 151 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 152 | * dpbp_get_attributes - Retrieve DPBP attributes. |
| 153 | * |
| 154 | * @mc_io: Pointer to MC portal's I/O object |
| 155 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 156 | * @token: Token of DPBP object |
| 157 | * @attr: Returned object's attributes |
| 158 | * |
| 159 | * Return: '0' on Success; Error code otherwise. |
| 160 | */ |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 161 | int dpbp_get_attributes(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 162 | u32 cmd_flags, |
| 163 | u16 token, |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 164 | struct dpbp_attr *attr) |
| 165 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 166 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 167 | struct dpbp_rsp_get_attributes *rsp_params; |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 168 | int err; |
| 169 | |
| 170 | /* prepare command */ |
| 171 | cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR, |
J. German Rivera | c4d88721 | 2015-09-23 16:11:00 -0500 | [diff] [blame] | 172 | cmd_flags, token); |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 173 | |
| 174 | /* send command to mc*/ |
| 175 | err = mc_send_command(mc_io, &cmd); |
| 176 | if (err) |
| 177 | return err; |
| 178 | |
| 179 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 180 | rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params; |
| 181 | attr->bpid = le16_to_cpu(rsp_params->bpid); |
| 182 | attr->id = le32_to_cpu(rsp_params->id); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 183 | |
J. German Rivera | 197f4d6 | 2015-03-05 19:35:25 -0600 | [diff] [blame] | 184 | return 0; |
| 185 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 186 | EXPORT_SYMBOL_GPL(dpbp_get_attributes); |