1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2017-2018 NXP
7 #include <linux/fsl/mc.h>
9 #include "dpseci_cmd.h"
12 * dpseci_open() - Open a control session for the specified object
13 * @mc_io: Pointer to MC portal's I/O object
14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
15 * @dpseci_id: DPSECI unique ID
16 * @token: Returned token; use in subsequent API calls
18 * This function can be used to open a control session for an already created
19 * object; an object may have been declared statically in the DPL
20 * or created dynamically.
21 * This function returns a unique authentication token, associated with the
22 * specific object ID and the specific MC portal; this token must be used in all
23 * subsequent commands for this specific object.
25 * Return: '0' on success, error code otherwise
27 int dpseci_open(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, int dpseci_id
,
30 struct fsl_mc_command cmd
= { 0 };
31 struct dpseci_cmd_open
*cmd_params
;
34 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_OPEN
,
37 cmd_params
= (struct dpseci_cmd_open
*)cmd
.params
;
38 cmd_params
->dpseci_id
= cpu_to_le32(dpseci_id
);
39 err
= mc_send_command(mc_io
, &cmd
);
43 *token
= mc_cmd_hdr_read_token(&cmd
);
49 * dpseci_close() - Close the control session of the object
50 * @mc_io: Pointer to MC portal's I/O object
51 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
52 * @token: Token of DPSECI object
54 * After this function is called, no further operations are allowed on the
55 * object without opening a new control session.
57 * Return: '0' on success, error code otherwise
59 int dpseci_close(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
)
61 struct fsl_mc_command cmd
= { 0 };
63 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_CLOSE
,
66 return mc_send_command(mc_io
, &cmd
);
70 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames
71 * @mc_io: Pointer to MC portal's I/O object
72 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
73 * @token: Token of DPSECI object
75 * Return: '0' on success, error code otherwise
77 int dpseci_enable(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
)
79 struct fsl_mc_command cmd
= { 0 };
81 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_ENABLE
,
84 return mc_send_command(mc_io
, &cmd
);
88 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames
89 * @mc_io: Pointer to MC portal's I/O object
90 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
91 * @token: Token of DPSECI object
93 * Return: '0' on success, error code otherwise
95 int dpseci_disable(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
)
97 struct fsl_mc_command cmd
= { 0 };
99 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_DISABLE
,
103 return mc_send_command(mc_io
, &cmd
);
107 * dpseci_reset() - Reset the DPSECI, returns the object to initial state
108 * @mc_io: Pointer to MC portal's I/O object
109 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
110 * @token: Token of DPSECI object
112 * Return: '0' on success, error code otherwise
114 int dpseci_reset(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
)
116 struct fsl_mc_command cmd
= { 0 };
118 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_RESET
,
121 return mc_send_command(mc_io
, &cmd
);
125 * dpseci_is_enabled() - Check if the DPSECI is enabled.
126 * @mc_io: Pointer to MC portal's I/O object
127 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
128 * @token: Token of DPSECI object
129 * @en: Returns '1' if object is enabled; '0' otherwise
131 * Return: '0' on success, error code otherwise
133 int dpseci_is_enabled(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
136 struct fsl_mc_command cmd
= { 0 };
137 struct dpseci_rsp_is_enabled
*rsp_params
;
140 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED
,
143 err
= mc_send_command(mc_io
, &cmd
);
147 rsp_params
= (struct dpseci_rsp_is_enabled
*)cmd
.params
;
148 *en
= dpseci_get_field(rsp_params
->is_enabled
, ENABLE
);
154 * dpseci_get_attributes() - Retrieve DPSECI attributes
155 * @mc_io: Pointer to MC portal's I/O object
156 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
157 * @token: Token of DPSECI object
158 * @attr: Returned object's attributes
160 * Return: '0' on success, error code otherwise
162 int dpseci_get_attributes(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
163 struct dpseci_attr
*attr
)
165 struct fsl_mc_command cmd
= { 0 };
166 struct dpseci_rsp_get_attributes
*rsp_params
;
169 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR
,
172 err
= mc_send_command(mc_io
, &cmd
);
176 rsp_params
= (struct dpseci_rsp_get_attributes
*)cmd
.params
;
177 attr
->id
= le32_to_cpu(rsp_params
->id
);
178 attr
->num_tx_queues
= rsp_params
->num_tx_queues
;
179 attr
->num_rx_queues
= rsp_params
->num_rx_queues
;
180 attr
->options
= le32_to_cpu(rsp_params
->options
);
186 * dpseci_set_rx_queue() - Set Rx queue configuration
187 * @mc_io: Pointer to MC portal's I/O object
188 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
189 * @token: Token of DPSECI object
190 * @queue: Select the queue relative to number of priorities configured at
191 * DPSECI creation; use DPSECI_ALL_QUEUES to configure all
192 * Rx queues identically.
193 * @cfg: Rx queue configuration
195 * Return: '0' on success, error code otherwise
197 int dpseci_set_rx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
198 u8 queue
, const struct dpseci_rx_queue_cfg
*cfg
)
200 struct fsl_mc_command cmd
= { 0 };
201 struct dpseci_cmd_queue
*cmd_params
;
203 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE
,
206 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
207 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
208 cmd_params
->priority
= cfg
->dest_cfg
.priority
;
209 cmd_params
->queue
= queue
;
210 dpseci_set_field(cmd_params
->dest_type
, DEST_TYPE
,
211 cfg
->dest_cfg
.dest_type
);
212 cmd_params
->user_ctx
= cpu_to_le64(cfg
->user_ctx
);
213 cmd_params
->options
= cpu_to_le32(cfg
->options
);
214 dpseci_set_field(cmd_params
->order_preservation_en
, ORDER_PRESERVATION
,
215 cfg
->order_preservation_en
);
217 return mc_send_command(mc_io
, &cmd
);
221 * dpseci_get_rx_queue() - Retrieve Rx queue attributes
222 * @mc_io: Pointer to MC portal's I/O object
223 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
224 * @token: Token of DPSECI object
225 * @queue: Select the queue relative to number of priorities configured at
227 * @attr: Returned Rx queue attributes
229 * Return: '0' on success, error code otherwise
231 int dpseci_get_rx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
232 u8 queue
, struct dpseci_rx_queue_attr
*attr
)
234 struct fsl_mc_command cmd
= { 0 };
235 struct dpseci_cmd_queue
*cmd_params
;
238 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE
,
241 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
242 cmd_params
->queue
= queue
;
243 err
= mc_send_command(mc_io
, &cmd
);
247 attr
->dest_cfg
.dest_id
= le32_to_cpu(cmd_params
->dest_id
);
248 attr
->dest_cfg
.priority
= cmd_params
->priority
;
249 attr
->dest_cfg
.dest_type
= dpseci_get_field(cmd_params
->dest_type
,
251 attr
->user_ctx
= le64_to_cpu(cmd_params
->user_ctx
);
252 attr
->fqid
= le32_to_cpu(cmd_params
->fqid
);
253 attr
->order_preservation_en
=
254 dpseci_get_field(cmd_params
->order_preservation_en
,
261 * dpseci_get_tx_queue() - Retrieve Tx queue attributes
262 * @mc_io: Pointer to MC portal's I/O object
263 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
264 * @token: Token of DPSECI object
265 * @queue: Select the queue relative to number of priorities configured at
267 * @attr: Returned Tx queue attributes
269 * Return: '0' on success, error code otherwise
271 int dpseci_get_tx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
272 u8 queue
, struct dpseci_tx_queue_attr
*attr
)
274 struct fsl_mc_command cmd
= { 0 };
275 struct dpseci_cmd_queue
*cmd_params
;
276 struct dpseci_rsp_get_tx_queue
*rsp_params
;
279 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE
,
282 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
283 cmd_params
->queue
= queue
;
284 err
= mc_send_command(mc_io
, &cmd
);
288 rsp_params
= (struct dpseci_rsp_get_tx_queue
*)cmd
.params
;
289 attr
->fqid
= le32_to_cpu(rsp_params
->fqid
);
290 attr
->priority
= rsp_params
->priority
;
296 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
297 * @mc_io: Pointer to MC portal's I/O object
298 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
299 * @token: Token of DPSECI object
300 * @attr: Returned SEC attributes
302 * Return: '0' on success, error code otherwise
304 int dpseci_get_sec_attr(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
305 struct dpseci_sec_attr
*attr
)
307 struct fsl_mc_command cmd
= { 0 };
308 struct dpseci_rsp_get_sec_attr
*rsp_params
;
311 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR
,
314 err
= mc_send_command(mc_io
, &cmd
);
318 rsp_params
= (struct dpseci_rsp_get_sec_attr
*)cmd
.params
;
319 attr
->ip_id
= le16_to_cpu(rsp_params
->ip_id
);
320 attr
->major_rev
= rsp_params
->major_rev
;
321 attr
->minor_rev
= rsp_params
->minor_rev
;
322 attr
->era
= rsp_params
->era
;
323 attr
->deco_num
= rsp_params
->deco_num
;
324 attr
->zuc_auth_acc_num
= rsp_params
->zuc_auth_acc_num
;
325 attr
->zuc_enc_acc_num
= rsp_params
->zuc_enc_acc_num
;
326 attr
->snow_f8_acc_num
= rsp_params
->snow_f8_acc_num
;
327 attr
->snow_f9_acc_num
= rsp_params
->snow_f9_acc_num
;
328 attr
->crc_acc_num
= rsp_params
->crc_acc_num
;
329 attr
->pk_acc_num
= rsp_params
->pk_acc_num
;
330 attr
->kasumi_acc_num
= rsp_params
->kasumi_acc_num
;
331 attr
->rng_acc_num
= rsp_params
->rng_acc_num
;
332 attr
->md_acc_num
= rsp_params
->md_acc_num
;
333 attr
->arc4_acc_num
= rsp_params
->arc4_acc_num
;
334 attr
->des_acc_num
= rsp_params
->des_acc_num
;
335 attr
->aes_acc_num
= rsp_params
->aes_acc_num
;
336 attr
->ccha_acc_num
= rsp_params
->ccha_acc_num
;
337 attr
->ptha_acc_num
= rsp_params
->ptha_acc_num
;
343 * dpseci_get_api_version() - Get Data Path SEC Interface API version
344 * @mc_io: Pointer to MC portal's I/O object
345 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
346 * @major_ver: Major version of data path sec API
347 * @minor_ver: Minor version of data path sec API
349 * Return: '0' on success, error code otherwise
351 int dpseci_get_api_version(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
352 u16
*major_ver
, u16
*minor_ver
)
354 struct fsl_mc_command cmd
= { 0 };
355 struct dpseci_rsp_get_api_version
*rsp_params
;
358 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION
,
360 err
= mc_send_command(mc_io
, &cmd
);
364 rsp_params
= (struct dpseci_rsp_get_api_version
*)cmd
.params
;
365 *major_ver
= le16_to_cpu(rsp_params
->major
);
366 *minor_ver
= le16_to_cpu(rsp_params
->minor
);
372 * dpseci_set_congestion_notification() - Set congestion group
373 * notification configuration
374 * @mc_io: Pointer to MC portal's I/O object
375 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
376 * @token: Token of DPSECI object
377 * @cfg: congestion notification configuration
379 * Return: '0' on success, error code otherwise
381 int dpseci_set_congestion_notification(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
382 u16 token
, const struct dpseci_congestion_notification_cfg
*cfg
)
384 struct fsl_mc_command cmd
= { 0 };
385 struct dpseci_cmd_congestion_notification
*cmd_params
;
387 cmd
.header
= mc_encode_cmd_header(
388 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION
,
391 cmd_params
= (struct dpseci_cmd_congestion_notification
*)cmd
.params
;
392 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
393 cmd_params
->notification_mode
= cpu_to_le16(cfg
->notification_mode
);
394 cmd_params
->priority
= cfg
->dest_cfg
.priority
;
395 dpseci_set_field(cmd_params
->options
, CGN_DEST_TYPE
,
396 cfg
->dest_cfg
.dest_type
);
397 dpseci_set_field(cmd_params
->options
, CGN_UNITS
, cfg
->units
);
398 cmd_params
->message_iova
= cpu_to_le64(cfg
->message_iova
);
399 cmd_params
->message_ctx
= cpu_to_le64(cfg
->message_ctx
);
400 cmd_params
->threshold_entry
= cpu_to_le32(cfg
->threshold_entry
);
401 cmd_params
->threshold_exit
= cpu_to_le32(cfg
->threshold_exit
);
403 return mc_send_command(mc_io
, &cmd
);
407 * dpseci_get_congestion_notification() - Get congestion group notification
409 * @mc_io: Pointer to MC portal's I/O object
410 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
411 * @token: Token of DPSECI object
412 * @cfg: congestion notification configuration
414 * Return: '0' on success, error code otherwise
416 int dpseci_get_congestion_notification(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
417 u16 token
, struct dpseci_congestion_notification_cfg
*cfg
)
419 struct fsl_mc_command cmd
= { 0 };
420 struct dpseci_cmd_congestion_notification
*rsp_params
;
423 cmd
.header
= mc_encode_cmd_header(
424 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION
,
427 err
= mc_send_command(mc_io
, &cmd
);
431 rsp_params
= (struct dpseci_cmd_congestion_notification
*)cmd
.params
;
432 cfg
->dest_cfg
.dest_id
= le32_to_cpu(rsp_params
->dest_id
);
433 cfg
->notification_mode
= le16_to_cpu(rsp_params
->notification_mode
);
434 cfg
->dest_cfg
.priority
= rsp_params
->priority
;
435 cfg
->dest_cfg
.dest_type
= dpseci_get_field(rsp_params
->options
,
437 cfg
->units
= dpseci_get_field(rsp_params
->options
, CGN_UNITS
);
438 cfg
->message_iova
= le64_to_cpu(rsp_params
->message_iova
);
439 cfg
->message_ctx
= le64_to_cpu(rsp_params
->message_ctx
);
440 cfg
->threshold_entry
= le32_to_cpu(rsp_params
->threshold_entry
);
441 cfg
->threshold_exit
= le32_to_cpu(rsp_params
->threshold_exit
);