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_is_enabled() - Check if the DPSECI is enabled.
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
111 * @en: Returns '1' if object is enabled; '0' otherwise
113 * Return: '0' on success, error code otherwise
115 int dpseci_is_enabled(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
118 struct fsl_mc_command cmd
= { 0 };
119 struct dpseci_rsp_is_enabled
*rsp_params
;
122 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED
,
125 err
= mc_send_command(mc_io
, &cmd
);
129 rsp_params
= (struct dpseci_rsp_is_enabled
*)cmd
.params
;
130 *en
= dpseci_get_field(rsp_params
->is_enabled
, ENABLE
);
136 * dpseci_get_attributes() - Retrieve DPSECI attributes
137 * @mc_io: Pointer to MC portal's I/O object
138 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
139 * @token: Token of DPSECI object
140 * @attr: Returned object's attributes
142 * Return: '0' on success, error code otherwise
144 int dpseci_get_attributes(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
145 struct dpseci_attr
*attr
)
147 struct fsl_mc_command cmd
= { 0 };
148 struct dpseci_rsp_get_attributes
*rsp_params
;
151 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR
,
154 err
= mc_send_command(mc_io
, &cmd
);
158 rsp_params
= (struct dpseci_rsp_get_attributes
*)cmd
.params
;
159 attr
->id
= le32_to_cpu(rsp_params
->id
);
160 attr
->num_tx_queues
= rsp_params
->num_tx_queues
;
161 attr
->num_rx_queues
= rsp_params
->num_rx_queues
;
162 attr
->options
= le32_to_cpu(rsp_params
->options
);
168 * dpseci_set_rx_queue() - Set Rx queue configuration
169 * @mc_io: Pointer to MC portal's I/O object
170 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
171 * @token: Token of DPSECI object
172 * @queue: Select the queue relative to number of priorities configured at
173 * DPSECI creation; use DPSECI_ALL_QUEUES to configure all
174 * Rx queues identically.
175 * @cfg: Rx queue configuration
177 * Return: '0' on success, error code otherwise
179 int dpseci_set_rx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
180 u8 queue
, const struct dpseci_rx_queue_cfg
*cfg
)
182 struct fsl_mc_command cmd
= { 0 };
183 struct dpseci_cmd_queue
*cmd_params
;
185 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE
,
188 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
189 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
190 cmd_params
->priority
= cfg
->dest_cfg
.priority
;
191 cmd_params
->queue
= queue
;
192 dpseci_set_field(cmd_params
->dest_type
, DEST_TYPE
,
193 cfg
->dest_cfg
.dest_type
);
194 cmd_params
->user_ctx
= cpu_to_le64(cfg
->user_ctx
);
195 cmd_params
->options
= cpu_to_le32(cfg
->options
);
196 dpseci_set_field(cmd_params
->order_preservation_en
, ORDER_PRESERVATION
,
197 cfg
->order_preservation_en
);
199 return mc_send_command(mc_io
, &cmd
);
203 * dpseci_get_rx_queue() - Retrieve Rx queue attributes
204 * @mc_io: Pointer to MC portal's I/O object
205 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
206 * @token: Token of DPSECI object
207 * @queue: Select the queue relative to number of priorities configured at
209 * @attr: Returned Rx queue attributes
211 * Return: '0' on success, error code otherwise
213 int dpseci_get_rx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
214 u8 queue
, struct dpseci_rx_queue_attr
*attr
)
216 struct fsl_mc_command cmd
= { 0 };
217 struct dpseci_cmd_queue
*cmd_params
;
220 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE
,
223 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
224 cmd_params
->queue
= queue
;
225 err
= mc_send_command(mc_io
, &cmd
);
229 attr
->dest_cfg
.dest_id
= le32_to_cpu(cmd_params
->dest_id
);
230 attr
->dest_cfg
.priority
= cmd_params
->priority
;
231 attr
->dest_cfg
.dest_type
= dpseci_get_field(cmd_params
->dest_type
,
233 attr
->user_ctx
= le64_to_cpu(cmd_params
->user_ctx
);
234 attr
->fqid
= le32_to_cpu(cmd_params
->fqid
);
235 attr
->order_preservation_en
=
236 dpseci_get_field(cmd_params
->order_preservation_en
,
243 * dpseci_get_tx_queue() - Retrieve Tx queue attributes
244 * @mc_io: Pointer to MC portal's I/O object
245 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
246 * @token: Token of DPSECI object
247 * @queue: Select the queue relative to number of priorities configured at
249 * @attr: Returned Tx queue attributes
251 * Return: '0' on success, error code otherwise
253 int dpseci_get_tx_queue(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
254 u8 queue
, struct dpseci_tx_queue_attr
*attr
)
256 struct fsl_mc_command cmd
= { 0 };
257 struct dpseci_cmd_queue
*cmd_params
;
258 struct dpseci_rsp_get_tx_queue
*rsp_params
;
261 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE
,
264 cmd_params
= (struct dpseci_cmd_queue
*)cmd
.params
;
265 cmd_params
->queue
= queue
;
266 err
= mc_send_command(mc_io
, &cmd
);
270 rsp_params
= (struct dpseci_rsp_get_tx_queue
*)cmd
.params
;
271 attr
->fqid
= le32_to_cpu(rsp_params
->fqid
);
272 attr
->priority
= rsp_params
->priority
;
278 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
279 * @mc_io: Pointer to MC portal's I/O object
280 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
281 * @token: Token of DPSECI object
282 * @attr: Returned SEC attributes
284 * Return: '0' on success, error code otherwise
286 int dpseci_get_sec_attr(struct fsl_mc_io
*mc_io
, u32 cmd_flags
, u16 token
,
287 struct dpseci_sec_attr
*attr
)
289 struct fsl_mc_command cmd
= { 0 };
290 struct dpseci_rsp_get_sec_attr
*rsp_params
;
293 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR
,
296 err
= mc_send_command(mc_io
, &cmd
);
300 rsp_params
= (struct dpseci_rsp_get_sec_attr
*)cmd
.params
;
301 attr
->ip_id
= le16_to_cpu(rsp_params
->ip_id
);
302 attr
->major_rev
= rsp_params
->major_rev
;
303 attr
->minor_rev
= rsp_params
->minor_rev
;
304 attr
->era
= rsp_params
->era
;
305 attr
->deco_num
= rsp_params
->deco_num
;
306 attr
->zuc_auth_acc_num
= rsp_params
->zuc_auth_acc_num
;
307 attr
->zuc_enc_acc_num
= rsp_params
->zuc_enc_acc_num
;
308 attr
->snow_f8_acc_num
= rsp_params
->snow_f8_acc_num
;
309 attr
->snow_f9_acc_num
= rsp_params
->snow_f9_acc_num
;
310 attr
->crc_acc_num
= rsp_params
->crc_acc_num
;
311 attr
->pk_acc_num
= rsp_params
->pk_acc_num
;
312 attr
->kasumi_acc_num
= rsp_params
->kasumi_acc_num
;
313 attr
->rng_acc_num
= rsp_params
->rng_acc_num
;
314 attr
->md_acc_num
= rsp_params
->md_acc_num
;
315 attr
->arc4_acc_num
= rsp_params
->arc4_acc_num
;
316 attr
->des_acc_num
= rsp_params
->des_acc_num
;
317 attr
->aes_acc_num
= rsp_params
->aes_acc_num
;
318 attr
->ccha_acc_num
= rsp_params
->ccha_acc_num
;
319 attr
->ptha_acc_num
= rsp_params
->ptha_acc_num
;
325 * dpseci_get_api_version() - Get Data Path SEC Interface API version
326 * @mc_io: Pointer to MC portal's I/O object
327 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
328 * @major_ver: Major version of data path sec API
329 * @minor_ver: Minor version of data path sec API
331 * Return: '0' on success, error code otherwise
333 int dpseci_get_api_version(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
334 u16
*major_ver
, u16
*minor_ver
)
336 struct fsl_mc_command cmd
= { 0 };
337 struct dpseci_rsp_get_api_version
*rsp_params
;
340 cmd
.header
= mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION
,
342 err
= mc_send_command(mc_io
, &cmd
);
346 rsp_params
= (struct dpseci_rsp_get_api_version
*)cmd
.params
;
347 *major_ver
= le16_to_cpu(rsp_params
->major
);
348 *minor_ver
= le16_to_cpu(rsp_params
->minor
);
354 * dpseci_set_congestion_notification() - Set congestion group
355 * notification configuration
356 * @mc_io: Pointer to MC portal's I/O object
357 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
358 * @token: Token of DPSECI object
359 * @cfg: congestion notification configuration
361 * Return: '0' on success, error code otherwise
363 int dpseci_set_congestion_notification(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
364 u16 token
, const struct dpseci_congestion_notification_cfg
*cfg
)
366 struct fsl_mc_command cmd
= { 0 };
367 struct dpseci_cmd_congestion_notification
*cmd_params
;
369 cmd
.header
= mc_encode_cmd_header(
370 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION
,
373 cmd_params
= (struct dpseci_cmd_congestion_notification
*)cmd
.params
;
374 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
375 cmd_params
->notification_mode
= cpu_to_le16(cfg
->notification_mode
);
376 cmd_params
->priority
= cfg
->dest_cfg
.priority
;
377 dpseci_set_field(cmd_params
->options
, CGN_DEST_TYPE
,
378 cfg
->dest_cfg
.dest_type
);
379 dpseci_set_field(cmd_params
->options
, CGN_UNITS
, cfg
->units
);
380 cmd_params
->message_iova
= cpu_to_le64(cfg
->message_iova
);
381 cmd_params
->message_ctx
= cpu_to_le64(cfg
->message_ctx
);
382 cmd_params
->threshold_entry
= cpu_to_le32(cfg
->threshold_entry
);
383 cmd_params
->threshold_exit
= cpu_to_le32(cfg
->threshold_exit
);
385 return mc_send_command(mc_io
, &cmd
);
389 * dpseci_get_congestion_notification() - Get congestion group notification
391 * @mc_io: Pointer to MC portal's I/O object
392 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
393 * @token: Token of DPSECI object
394 * @cfg: congestion notification configuration
396 * Return: '0' on success, error code otherwise
398 int dpseci_get_congestion_notification(struct fsl_mc_io
*mc_io
, u32 cmd_flags
,
399 u16 token
, struct dpseci_congestion_notification_cfg
*cfg
)
401 struct fsl_mc_command cmd
= { 0 };
402 struct dpseci_cmd_congestion_notification
*rsp_params
;
405 cmd
.header
= mc_encode_cmd_header(
406 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION
,
409 err
= mc_send_command(mc_io
, &cmd
);
413 rsp_params
= (struct dpseci_cmd_congestion_notification
*)cmd
.params
;
414 cfg
->dest_cfg
.dest_id
= le32_to_cpu(rsp_params
->dest_id
);
415 cfg
->notification_mode
= le16_to_cpu(rsp_params
->notification_mode
);
416 cfg
->dest_cfg
.priority
= rsp_params
->priority
;
417 cfg
->dest_cfg
.dest_type
= dpseci_get_field(rsp_params
->options
,
419 cfg
->units
= dpseci_get_field(rsp_params
->options
, CGN_UNITS
);
420 cfg
->message_iova
= le64_to_cpu(rsp_params
->message_iova
);
421 cfg
->message_ctx
= le64_to_cpu(rsp_params
->message_ctx
);
422 cfg
->threshold_entry
= le32_to_cpu(rsp_params
->threshold_entry
);
423 cfg
->threshold_exit
= le32_to_cpu(rsp_params
->threshold_exit
);