linux/drivers/crypto/caam/dpseci.c
<<
>>
Prefs
   1// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
   2/*
   3 * Copyright 2013-2016 Freescale Semiconductor Inc.
   4 * Copyright 2017-2018 NXP
   5 */
   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 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
  17 *
  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.
  24 *
  25 * Return:      '0' on success, error code otherwise
  26 */
  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 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
  53 *
  54 * After this function is called, no further operations are allowed on the
  55 * object without opening a new control session.
  56 *
  57 * Return:      '0' on success, error code otherwise
  58 */
  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 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
  74 *
  75 * Return:      '0' on success, error code otherwise
  76 */
  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 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
  92 *
  93 * Return:      '0' on success, error code otherwise
  94 */
  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 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
 111 *
 112 * Return:      '0' on success, error code otherwise
 113 */
 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 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
 130 *
 131 * Return:      '0' on success, error code otherwise
 132 */
 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 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
 159 *
 160 * Return:      '0' on success, error code otherwise
 161 */
 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 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
 194 *
 195 * Return:      '0' on success, error code otherwise
 196 */
 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 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
 226 *              DPSECI creation
 227 * @attr:       Returned Rx queue attributes
 228 *
 229 * Return:      '0' on success, error code otherwise
 230 */
 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 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
 266 *              DPSECI creation
 267 * @attr:       Returned Tx queue attributes
 268 *
 269 * Return:      '0' on success, error code otherwise
 270 */
 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 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
 301 *
 302 * Return:      '0' on success, error code otherwise
 303 */
 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 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
 348 *
 349 * Return:      '0' on success, error code otherwise
 350 */
 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 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
 378 *
 379 * Return:      '0' on success, error code otherwise
 380 */
 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 notification
 408 *      configuration
 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
 413 *
 414 * Return:      '0' on success, error code otherwise
 415 */
 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