Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
0002 /*
0003  * Copyright 2013-2016 Freescale Semiconductor Inc.
0004  * Copyright 2017-2018 NXP
0005  */
0006 
0007 #include <linux/fsl/mc.h>
0008 #include "dpseci.h"
0009 #include "dpseci_cmd.h"
0010 
0011 /**
0012  * dpseci_open() - Open a control session for the specified object
0013  * @mc_io:  Pointer to MC portal's I/O object
0014  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0015  * @dpseci_id:  DPSECI unique ID
0016  * @token:  Returned token; use in subsequent API calls
0017  *
0018  * This function can be used to open a control session for an already created
0019  * object; an object may have been declared statically in the DPL
0020  * or created dynamically.
0021  * This function returns a unique authentication token, associated with the
0022  * specific object ID and the specific MC portal; this token must be used in all
0023  * subsequent commands for this specific object.
0024  *
0025  * Return:  '0' on success, error code otherwise
0026  */
0027 int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,
0028         u16 *token)
0029 {
0030     struct fsl_mc_command cmd = { 0 };
0031     struct dpseci_cmd_open *cmd_params;
0032     int err;
0033 
0034     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
0035                       cmd_flags,
0036                       0);
0037     cmd_params = (struct dpseci_cmd_open *)cmd.params;
0038     cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
0039     err = mc_send_command(mc_io, &cmd);
0040     if (err)
0041         return err;
0042 
0043     *token = mc_cmd_hdr_read_token(&cmd);
0044 
0045     return 0;
0046 }
0047 
0048 /**
0049  * dpseci_close() - Close the control session of the object
0050  * @mc_io:  Pointer to MC portal's I/O object
0051  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0052  * @token:  Token of DPSECI object
0053  *
0054  * After this function is called, no further operations are allowed on the
0055  * object without opening a new control session.
0056  *
0057  * Return:  '0' on success, error code otherwise
0058  */
0059 int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0060 {
0061     struct fsl_mc_command cmd = { 0 };
0062 
0063     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
0064                       cmd_flags,
0065                       token);
0066     return mc_send_command(mc_io, &cmd);
0067 }
0068 
0069 /**
0070  * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames
0071  * @mc_io:  Pointer to MC portal's I/O object
0072  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0073  * @token:  Token of DPSECI object
0074  *
0075  * Return:  '0' on success, error code otherwise
0076  */
0077 int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0078 {
0079     struct fsl_mc_command cmd = { 0 };
0080 
0081     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
0082                       cmd_flags,
0083                       token);
0084     return mc_send_command(mc_io, &cmd);
0085 }
0086 
0087 /**
0088  * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames
0089  * @mc_io:  Pointer to MC portal's I/O object
0090  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0091  * @token:  Token of DPSECI object
0092  *
0093  * Return:  '0' on success, error code otherwise
0094  */
0095 int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0096 {
0097     struct fsl_mc_command cmd = { 0 };
0098 
0099     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
0100                       cmd_flags,
0101                       token);
0102 
0103     return mc_send_command(mc_io, &cmd);
0104 }
0105 
0106 /**
0107  * dpseci_reset() - Reset the DPSECI, returns the object to initial state
0108  * @mc_io:  Pointer to MC portal's I/O object
0109  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0110  * @token:  Token of DPSECI object
0111  *
0112  * Return:  '0' on success, error code otherwise
0113  */
0114 int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
0115 {
0116     struct fsl_mc_command cmd = { 0 };
0117 
0118     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
0119                       cmd_flags,
0120                       token);
0121     return mc_send_command(mc_io, &cmd);
0122 }
0123 
0124 /**
0125  * dpseci_is_enabled() - Check if the DPSECI is enabled.
0126  * @mc_io:  Pointer to MC portal's I/O object
0127  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0128  * @token:  Token of DPSECI object
0129  * @en:     Returns '1' if object is enabled; '0' otherwise
0130  *
0131  * Return:  '0' on success, error code otherwise
0132  */
0133 int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0134               int *en)
0135 {
0136     struct fsl_mc_command cmd = { 0 };
0137     struct dpseci_rsp_is_enabled *rsp_params;
0138     int err;
0139 
0140     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
0141                       cmd_flags,
0142                       token);
0143     err = mc_send_command(mc_io, &cmd);
0144     if (err)
0145         return err;
0146 
0147     rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
0148     *en = dpseci_get_field(rsp_params->is_enabled, ENABLE);
0149 
0150     return 0;
0151 }
0152 
0153 /**
0154  * dpseci_get_attributes() - Retrieve DPSECI attributes
0155  * @mc_io:  Pointer to MC portal's I/O object
0156  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0157  * @token:  Token of DPSECI object
0158  * @attr:   Returned object's attributes
0159  *
0160  * Return:  '0' on success, error code otherwise
0161  */
0162 int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0163               struct dpseci_attr *attr)
0164 {
0165     struct fsl_mc_command cmd = { 0 };
0166     struct dpseci_rsp_get_attributes *rsp_params;
0167     int err;
0168 
0169     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
0170                       cmd_flags,
0171                       token);
0172     err = mc_send_command(mc_io, &cmd);
0173     if (err)
0174         return err;
0175 
0176     rsp_params = (struct dpseci_rsp_get_attributes *)cmd.params;
0177     attr->id = le32_to_cpu(rsp_params->id);
0178     attr->num_tx_queues = rsp_params->num_tx_queues;
0179     attr->num_rx_queues = rsp_params->num_rx_queues;
0180     attr->options = le32_to_cpu(rsp_params->options);
0181 
0182     return 0;
0183 }
0184 
0185 /**
0186  * dpseci_set_rx_queue() - Set Rx queue configuration
0187  * @mc_io:  Pointer to MC portal's I/O object
0188  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0189  * @token:  Token of DPSECI object
0190  * @queue:  Select the queue relative to number of priorities configured at
0191  *      DPSECI creation; use DPSECI_ALL_QUEUES to configure all
0192  *      Rx queues identically.
0193  * @cfg:    Rx queue configuration
0194  *
0195  * Return:  '0' on success, error code otherwise
0196  */
0197 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0198             u8 queue, const struct dpseci_rx_queue_cfg *cfg)
0199 {
0200     struct fsl_mc_command cmd = { 0 };
0201     struct dpseci_cmd_queue *cmd_params;
0202 
0203     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
0204                       cmd_flags,
0205                       token);
0206     cmd_params = (struct dpseci_cmd_queue *)cmd.params;
0207     cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
0208     cmd_params->priority = cfg->dest_cfg.priority;
0209     cmd_params->queue = queue;
0210     dpseci_set_field(cmd_params->dest_type, DEST_TYPE,
0211              cfg->dest_cfg.dest_type);
0212     cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
0213     cmd_params->options = cpu_to_le32(cfg->options);
0214     dpseci_set_field(cmd_params->order_preservation_en, ORDER_PRESERVATION,
0215              cfg->order_preservation_en);
0216 
0217     return mc_send_command(mc_io, &cmd);
0218 }
0219 
0220 /**
0221  * dpseci_get_rx_queue() - Retrieve Rx queue attributes
0222  * @mc_io:  Pointer to MC portal's I/O object
0223  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0224  * @token:  Token of DPSECI object
0225  * @queue:  Select the queue relative to number of priorities configured at
0226  *      DPSECI creation
0227  * @attr:   Returned Rx queue attributes
0228  *
0229  * Return:  '0' on success, error code otherwise
0230  */
0231 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0232             u8 queue, struct dpseci_rx_queue_attr *attr)
0233 {
0234     struct fsl_mc_command cmd = { 0 };
0235     struct dpseci_cmd_queue *cmd_params;
0236     int err;
0237 
0238     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
0239                       cmd_flags,
0240                       token);
0241     cmd_params = (struct dpseci_cmd_queue *)cmd.params;
0242     cmd_params->queue = queue;
0243     err = mc_send_command(mc_io, &cmd);
0244     if (err)
0245         return err;
0246 
0247     attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
0248     attr->dest_cfg.priority = cmd_params->priority;
0249     attr->dest_cfg.dest_type = dpseci_get_field(cmd_params->dest_type,
0250                             DEST_TYPE);
0251     attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
0252     attr->fqid = le32_to_cpu(cmd_params->fqid);
0253     attr->order_preservation_en =
0254         dpseci_get_field(cmd_params->order_preservation_en,
0255                  ORDER_PRESERVATION);
0256 
0257     return 0;
0258 }
0259 
0260 /**
0261  * dpseci_get_tx_queue() - Retrieve Tx queue attributes
0262  * @mc_io:  Pointer to MC portal's I/O object
0263  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0264  * @token:  Token of DPSECI object
0265  * @queue:  Select the queue relative to number of priorities configured at
0266  *      DPSECI creation
0267  * @attr:   Returned Tx queue attributes
0268  *
0269  * Return:  '0' on success, error code otherwise
0270  */
0271 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0272             u8 queue, struct dpseci_tx_queue_attr *attr)
0273 {
0274     struct fsl_mc_command cmd = { 0 };
0275     struct dpseci_cmd_queue *cmd_params;
0276     struct dpseci_rsp_get_tx_queue *rsp_params;
0277     int err;
0278 
0279     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
0280                       cmd_flags,
0281                       token);
0282     cmd_params = (struct dpseci_cmd_queue *)cmd.params;
0283     cmd_params->queue = queue;
0284     err = mc_send_command(mc_io, &cmd);
0285     if (err)
0286         return err;
0287 
0288     rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
0289     attr->fqid = le32_to_cpu(rsp_params->fqid);
0290     attr->priority = rsp_params->priority;
0291 
0292     return 0;
0293 }
0294 
0295 /**
0296  * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
0297  * @mc_io:  Pointer to MC portal's I/O object
0298  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0299  * @token:  Token of DPSECI object
0300  * @attr:   Returned SEC attributes
0301  *
0302  * Return:  '0' on success, error code otherwise
0303  */
0304 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
0305             struct dpseci_sec_attr *attr)
0306 {
0307     struct fsl_mc_command cmd = { 0 };
0308     struct dpseci_rsp_get_sec_attr *rsp_params;
0309     int err;
0310 
0311     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
0312                       cmd_flags,
0313                       token);
0314     err = mc_send_command(mc_io, &cmd);
0315     if (err)
0316         return err;
0317 
0318     rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
0319     attr->ip_id = le16_to_cpu(rsp_params->ip_id);
0320     attr->major_rev = rsp_params->major_rev;
0321     attr->minor_rev = rsp_params->minor_rev;
0322     attr->era = rsp_params->era;
0323     attr->deco_num = rsp_params->deco_num;
0324     attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
0325     attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
0326     attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
0327     attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
0328     attr->crc_acc_num = rsp_params->crc_acc_num;
0329     attr->pk_acc_num = rsp_params->pk_acc_num;
0330     attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
0331     attr->rng_acc_num = rsp_params->rng_acc_num;
0332     attr->md_acc_num = rsp_params->md_acc_num;
0333     attr->arc4_acc_num = rsp_params->arc4_acc_num;
0334     attr->des_acc_num = rsp_params->des_acc_num;
0335     attr->aes_acc_num = rsp_params->aes_acc_num;
0336     attr->ccha_acc_num = rsp_params->ccha_acc_num;
0337     attr->ptha_acc_num = rsp_params->ptha_acc_num;
0338 
0339     return 0;
0340 }
0341 
0342 /**
0343  * dpseci_get_api_version() - Get Data Path SEC Interface API version
0344  * @mc_io:  Pointer to MC portal's I/O object
0345  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0346  * @major_ver:  Major version of data path sec API
0347  * @minor_ver:  Minor version of data path sec API
0348  *
0349  * Return:  '0' on success, error code otherwise
0350  */
0351 int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
0352                u16 *major_ver, u16 *minor_ver)
0353 {
0354     struct fsl_mc_command cmd = { 0 };
0355     struct dpseci_rsp_get_api_version *rsp_params;
0356     int err;
0357 
0358     cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
0359                       cmd_flags, 0);
0360     err = mc_send_command(mc_io, &cmd);
0361     if (err)
0362         return err;
0363 
0364     rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
0365     *major_ver = le16_to_cpu(rsp_params->major);
0366     *minor_ver = le16_to_cpu(rsp_params->minor);
0367 
0368     return 0;
0369 }
0370 
0371 /**
0372  * dpseci_set_congestion_notification() - Set congestion group
0373  *  notification configuration
0374  * @mc_io:  Pointer to MC portal's I/O object
0375  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0376  * @token:  Token of DPSECI object
0377  * @cfg:    congestion notification configuration
0378  *
0379  * Return:  '0' on success, error code otherwise
0380  */
0381 int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
0382     u16 token, const struct dpseci_congestion_notification_cfg *cfg)
0383 {
0384     struct fsl_mc_command cmd = { 0 };
0385     struct dpseci_cmd_congestion_notification *cmd_params;
0386 
0387     cmd.header = mc_encode_cmd_header(
0388             DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
0389             cmd_flags,
0390             token);
0391     cmd_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
0392     cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
0393     cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
0394     cmd_params->priority = cfg->dest_cfg.priority;
0395     dpseci_set_field(cmd_params->options, CGN_DEST_TYPE,
0396              cfg->dest_cfg.dest_type);
0397     dpseci_set_field(cmd_params->options, CGN_UNITS, cfg->units);
0398     cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
0399     cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
0400     cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
0401     cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
0402 
0403     return mc_send_command(mc_io, &cmd);
0404 }
0405 
0406 /**
0407  * dpseci_get_congestion_notification() - Get congestion group notification
0408  *  configuration
0409  * @mc_io:  Pointer to MC portal's I/O object
0410  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
0411  * @token:  Token of DPSECI object
0412  * @cfg:    congestion notification configuration
0413  *
0414  * Return:  '0' on success, error code otherwise
0415  */
0416 int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
0417     u16 token, struct dpseci_congestion_notification_cfg *cfg)
0418 {
0419     struct fsl_mc_command cmd = { 0 };
0420     struct dpseci_cmd_congestion_notification *rsp_params;
0421     int err;
0422 
0423     cmd.header = mc_encode_cmd_header(
0424             DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
0425             cmd_flags,
0426             token);
0427     err = mc_send_command(mc_io, &cmd);
0428     if (err)
0429         return err;
0430 
0431     rsp_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
0432     cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
0433     cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
0434     cfg->dest_cfg.priority = rsp_params->priority;
0435     cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->options,
0436                            CGN_DEST_TYPE);
0437     cfg->units = dpseci_get_field(rsp_params->options, CGN_UNITS);
0438     cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
0439     cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
0440     cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
0441     cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
0442 
0443     return 0;
0444 }