445 lines · c
1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)2/*3 * Copyright 2013-2016 Freescale Semiconductor Inc.4 * Copyright 2017-2018 NXP5 */6 7#include <linux/fsl/mc.h>8#include "dpseci.h"9#include "dpseci_cmd.h"10 11/**12 * dpseci_open() - Open a control session for the specified object13 * @mc_io: Pointer to MC portal's I/O object14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'15 * @dpseci_id: DPSECI unique ID16 * @token: Returned token; use in subsequent API calls17 *18 * This function can be used to open a control session for an already created19 * object; an object may have been declared statically in the DPL20 * or created dynamically.21 * This function returns a unique authentication token, associated with the22 * specific object ID and the specific MC portal; this token must be used in all23 * subsequent commands for this specific object.24 *25 * Return: '0' on success, error code otherwise26 */27int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,28 u16 *token)29{30 struct fsl_mc_command cmd = { 0 };31 struct dpseci_cmd_open *cmd_params;32 int err;33 34 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,35 cmd_flags,36 0);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);40 if (err)41 return err;42 43 *token = mc_cmd_hdr_read_token(&cmd);44 45 return 0;46}47 48/**49 * dpseci_close() - Close the control session of the object50 * @mc_io: Pointer to MC portal's I/O object51 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'52 * @token: Token of DPSECI object53 *54 * After this function is called, no further operations are allowed on the55 * object without opening a new control session.56 *57 * Return: '0' on success, error code otherwise58 */59int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)60{61 struct fsl_mc_command cmd = { 0 };62 63 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,64 cmd_flags,65 token);66 return mc_send_command(mc_io, &cmd);67}68 69/**70 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames71 * @mc_io: Pointer to MC portal's I/O object72 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'73 * @token: Token of DPSECI object74 *75 * Return: '0' on success, error code otherwise76 */77int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)78{79 struct fsl_mc_command cmd = { 0 };80 81 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,82 cmd_flags,83 token);84 return mc_send_command(mc_io, &cmd);85}86 87/**88 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames89 * @mc_io: Pointer to MC portal's I/O object90 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'91 * @token: Token of DPSECI object92 *93 * Return: '0' on success, error code otherwise94 */95int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)96{97 struct fsl_mc_command cmd = { 0 };98 99 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,100 cmd_flags,101 token);102 103 return mc_send_command(mc_io, &cmd);104}105 106/**107 * dpseci_reset() - Reset the DPSECI, returns the object to initial state108 * @mc_io: Pointer to MC portal's I/O object109 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'110 * @token: Token of DPSECI object111 *112 * Return: '0' on success, error code otherwise113 */114int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)115{116 struct fsl_mc_command cmd = { 0 };117 118 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,119 cmd_flags,120 token);121 return mc_send_command(mc_io, &cmd);122}123 124/**125 * dpseci_is_enabled() - Check if the DPSECI is enabled.126 * @mc_io: Pointer to MC portal's I/O object127 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'128 * @token: Token of DPSECI object129 * @en: Returns '1' if object is enabled; '0' otherwise130 *131 * Return: '0' on success, error code otherwise132 */133int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,134 int *en)135{136 struct fsl_mc_command cmd = { 0 };137 struct dpseci_rsp_is_enabled *rsp_params;138 int err;139 140 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,141 cmd_flags,142 token);143 err = mc_send_command(mc_io, &cmd);144 if (err)145 return err;146 147 rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;148 *en = dpseci_get_field(rsp_params->is_enabled, ENABLE);149 150 return 0;151}152 153/**154 * dpseci_get_attributes() - Retrieve DPSECI attributes155 * @mc_io: Pointer to MC portal's I/O object156 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'157 * @token: Token of DPSECI object158 * @attr: Returned object's attributes159 *160 * Return: '0' on success, error code otherwise161 */162int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,163 struct dpseci_attr *attr)164{165 struct fsl_mc_command cmd = { 0 };166 struct dpseci_rsp_get_attributes *rsp_params;167 int err;168 169 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,170 cmd_flags,171 token);172 err = mc_send_command(mc_io, &cmd);173 if (err)174 return err;175 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);181 182 return 0;183}184 185/**186 * dpseci_set_rx_queue() - Set Rx queue configuration187 * @mc_io: Pointer to MC portal's I/O object188 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'189 * @token: Token of DPSECI object190 * @queue: Select the queue relative to number of priorities configured at191 * DPSECI creation; use DPSECI_ALL_QUEUES to configure all192 * Rx queues identically.193 * @cfg: Rx queue configuration194 *195 * Return: '0' on success, error code otherwise196 */197int 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)199{200 struct fsl_mc_command cmd = { 0 };201 struct dpseci_cmd_queue *cmd_params;202 203 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,204 cmd_flags,205 token);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);216 217 return mc_send_command(mc_io, &cmd);218}219 220/**221 * dpseci_get_rx_queue() - Retrieve Rx queue attributes222 * @mc_io: Pointer to MC portal's I/O object223 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'224 * @token: Token of DPSECI object225 * @queue: Select the queue relative to number of priorities configured at226 * DPSECI creation227 * @attr: Returned Rx queue attributes228 *229 * Return: '0' on success, error code otherwise230 */231int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,232 u8 queue, struct dpseci_rx_queue_attr *attr)233{234 struct fsl_mc_command cmd = { 0 };235 struct dpseci_cmd_queue *cmd_params;236 int err;237 238 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,239 cmd_flags,240 token);241 cmd_params = (struct dpseci_cmd_queue *)cmd.params;242 cmd_params->queue = queue;243 err = mc_send_command(mc_io, &cmd);244 if (err)245 return err;246 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,250 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,255 ORDER_PRESERVATION);256 257 return 0;258}259 260/**261 * dpseci_get_tx_queue() - Retrieve Tx queue attributes262 * @mc_io: Pointer to MC portal's I/O object263 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'264 * @token: Token of DPSECI object265 * @queue: Select the queue relative to number of priorities configured at266 * DPSECI creation267 * @attr: Returned Tx queue attributes268 *269 * Return: '0' on success, error code otherwise270 */271int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,272 u8 queue, struct dpseci_tx_queue_attr *attr)273{274 struct fsl_mc_command cmd = { 0 };275 struct dpseci_cmd_queue *cmd_params;276 struct dpseci_rsp_get_tx_queue *rsp_params;277 int err;278 279 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,280 cmd_flags,281 token);282 cmd_params = (struct dpseci_cmd_queue *)cmd.params;283 cmd_params->queue = queue;284 err = mc_send_command(mc_io, &cmd);285 if (err)286 return err;287 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;291 292 return 0;293}294 295/**296 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes297 * @mc_io: Pointer to MC portal's I/O object298 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'299 * @token: Token of DPSECI object300 * @attr: Returned SEC attributes301 *302 * Return: '0' on success, error code otherwise303 */304int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,305 struct dpseci_sec_attr *attr)306{307 struct fsl_mc_command cmd = { 0 };308 struct dpseci_rsp_get_sec_attr *rsp_params;309 int err;310 311 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,312 cmd_flags,313 token);314 err = mc_send_command(mc_io, &cmd);315 if (err)316 return err;317 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;338 339 return 0;340}341 342/**343 * dpseci_get_api_version() - Get Data Path SEC Interface API version344 * @mc_io: Pointer to MC portal's I/O object345 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'346 * @major_ver: Major version of data path sec API347 * @minor_ver: Minor version of data path sec API348 *349 * Return: '0' on success, error code otherwise350 */351int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,352 u16 *major_ver, u16 *minor_ver)353{354 struct fsl_mc_command cmd = { 0 };355 struct dpseci_rsp_get_api_version *rsp_params;356 int err;357 358 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,359 cmd_flags, 0);360 err = mc_send_command(mc_io, &cmd);361 if (err)362 return err;363 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);367 368 return 0;369}370 371/**372 * dpseci_set_congestion_notification() - Set congestion group373 * notification configuration374 * @mc_io: Pointer to MC portal's I/O object375 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'376 * @token: Token of DPSECI object377 * @cfg: congestion notification configuration378 *379 * Return: '0' on success, error code otherwise380 */381int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,382 u16 token, const struct dpseci_congestion_notification_cfg *cfg)383{384 struct fsl_mc_command cmd = { 0 };385 struct dpseci_cmd_congestion_notification *cmd_params;386 387 cmd.header = mc_encode_cmd_header(388 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,389 cmd_flags,390 token);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);402 403 return mc_send_command(mc_io, &cmd);404}405 406/**407 * dpseci_get_congestion_notification() - Get congestion group notification408 * configuration409 * @mc_io: Pointer to MC portal's I/O object410 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'411 * @token: Token of DPSECI object412 * @cfg: congestion notification configuration413 *414 * Return: '0' on success, error code otherwise415 */416int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,417 u16 token, struct dpseci_congestion_notification_cfg *cfg)418{419 struct fsl_mc_command cmd = { 0 };420 struct dpseci_cmd_congestion_notification *rsp_params;421 int err;422 423 cmd.header = mc_encode_cmd_header(424 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,425 cmd_flags,426 token);427 err = mc_send_command(mc_io, &cmd);428 if (err)429 return err;430 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,436 CGN_DEST_TYPE);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);442 443 return 0;444}445