0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/debugfs.h>
0011 #include <linux/ccp.h>
0012
0013 #include "ccp-dev.h"
0014
0015
0016 #define OBUFP (obuf + oboff)
0017 #define OBUFLEN 512
0018 #define OBUFSPC (OBUFLEN - oboff)
0019 #define OSCNPRINTF(fmt, ...) \
0020 scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__)
0021
0022 #define BUFLEN 63
0023
0024 #define RI_VERSION_NUM 0x0000003F
0025 #define RI_AES_PRESENT 0x00000040
0026 #define RI_3DES_PRESENT 0x00000080
0027 #define RI_SHA_PRESENT 0x00000100
0028 #define RI_RSA_PRESENT 0x00000200
0029 #define RI_ECC_PRESENT 0x00000400
0030 #define RI_ZDE_PRESENT 0x00000800
0031 #define RI_ZCE_PRESENT 0x00001000
0032 #define RI_TRNG_PRESENT 0x00002000
0033 #define RI_ELFC_PRESENT 0x00004000
0034 #define RI_ELFC_SHIFT 14
0035 #define RI_NUM_VQM 0x00078000
0036 #define RI_NVQM_SHIFT 15
0037 #define RI_NVQM(r) (((r) * RI_NUM_VQM) >> RI_NVQM_SHIFT)
0038 #define RI_LSB_ENTRIES 0x0FF80000
0039 #define RI_NLSB_SHIFT 19
0040 #define RI_NLSB(r) (((r) * RI_LSB_ENTRIES) >> RI_NLSB_SHIFT)
0041
0042 static ssize_t ccp5_debugfs_info_read(struct file *filp, char __user *ubuf,
0043 size_t count, loff_t *offp)
0044 {
0045 struct ccp_device *ccp = filp->private_data;
0046 unsigned int oboff = 0;
0047 unsigned int regval;
0048 ssize_t ret;
0049 char *obuf;
0050
0051 if (!ccp)
0052 return 0;
0053
0054 obuf = kmalloc(OBUFLEN, GFP_KERNEL);
0055 if (!obuf)
0056 return -ENOMEM;
0057
0058 oboff += OSCNPRINTF("Device name: %s\n", ccp->name);
0059 oboff += OSCNPRINTF(" RNG name: %s\n", ccp->rngname);
0060 oboff += OSCNPRINTF(" # Queues: %d\n", ccp->cmd_q_count);
0061 oboff += OSCNPRINTF(" # Cmds: %d\n", ccp->cmd_count);
0062
0063 regval = ioread32(ccp->io_regs + CMD5_PSP_CCP_VERSION);
0064 oboff += OSCNPRINTF(" Version: %d\n", regval & RI_VERSION_NUM);
0065 oboff += OSCNPRINTF(" Engines:");
0066 if (regval & RI_AES_PRESENT)
0067 oboff += OSCNPRINTF(" AES");
0068 if (regval & RI_3DES_PRESENT)
0069 oboff += OSCNPRINTF(" 3DES");
0070 if (regval & RI_SHA_PRESENT)
0071 oboff += OSCNPRINTF(" SHA");
0072 if (regval & RI_RSA_PRESENT)
0073 oboff += OSCNPRINTF(" RSA");
0074 if (regval & RI_ECC_PRESENT)
0075 oboff += OSCNPRINTF(" ECC");
0076 if (regval & RI_ZDE_PRESENT)
0077 oboff += OSCNPRINTF(" ZDE");
0078 if (regval & RI_ZCE_PRESENT)
0079 oboff += OSCNPRINTF(" ZCE");
0080 if (regval & RI_TRNG_PRESENT)
0081 oboff += OSCNPRINTF(" TRNG");
0082 oboff += OSCNPRINTF("\n");
0083 oboff += OSCNPRINTF(" Queues: %d\n",
0084 (regval & RI_NUM_VQM) >> RI_NVQM_SHIFT);
0085 oboff += OSCNPRINTF("LSB Entries: %d\n",
0086 (regval & RI_LSB_ENTRIES) >> RI_NLSB_SHIFT);
0087
0088 ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
0089 kfree(obuf);
0090
0091 return ret;
0092 }
0093
0094
0095
0096
0097 static ssize_t ccp5_debugfs_stats_read(struct file *filp, char __user *ubuf,
0098 size_t count, loff_t *offp)
0099 {
0100 struct ccp_device *ccp = filp->private_data;
0101 unsigned long total_xts_aes_ops = 0;
0102 unsigned long total_3des_ops = 0;
0103 unsigned long total_aes_ops = 0;
0104 unsigned long total_sha_ops = 0;
0105 unsigned long total_rsa_ops = 0;
0106 unsigned long total_ecc_ops = 0;
0107 unsigned long total_pt_ops = 0;
0108 unsigned long total_ops = 0;
0109 unsigned int oboff = 0;
0110 ssize_t ret = 0;
0111 unsigned int i;
0112 char *obuf;
0113
0114 for (i = 0; i < ccp->cmd_q_count; i++) {
0115 struct ccp_cmd_queue *cmd_q = &ccp->cmd_q[i];
0116
0117 total_ops += cmd_q->total_ops;
0118 total_aes_ops += cmd_q->total_aes_ops;
0119 total_xts_aes_ops += cmd_q->total_xts_aes_ops;
0120 total_3des_ops += cmd_q->total_3des_ops;
0121 total_sha_ops += cmd_q->total_sha_ops;
0122 total_rsa_ops += cmd_q->total_rsa_ops;
0123 total_pt_ops += cmd_q->total_pt_ops;
0124 total_ecc_ops += cmd_q->total_ecc_ops;
0125 }
0126
0127 obuf = kmalloc(OBUFLEN, GFP_KERNEL);
0128 if (!obuf)
0129 return -ENOMEM;
0130
0131 oboff += OSCNPRINTF("Total Interrupts Handled: %ld\n",
0132 ccp->total_interrupts);
0133 oboff += OSCNPRINTF(" Total Operations: %ld\n",
0134 total_ops);
0135 oboff += OSCNPRINTF(" AES: %ld\n",
0136 total_aes_ops);
0137 oboff += OSCNPRINTF(" XTS AES: %ld\n",
0138 total_xts_aes_ops);
0139 oboff += OSCNPRINTF(" SHA: %ld\n",
0140 total_3des_ops);
0141 oboff += OSCNPRINTF(" SHA: %ld\n",
0142 total_sha_ops);
0143 oboff += OSCNPRINTF(" RSA: %ld\n",
0144 total_rsa_ops);
0145 oboff += OSCNPRINTF(" Pass-Thru: %ld\n",
0146 total_pt_ops);
0147 oboff += OSCNPRINTF(" ECC: %ld\n",
0148 total_ecc_ops);
0149
0150 ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
0151 kfree(obuf);
0152
0153 return ret;
0154 }
0155
0156
0157
0158 static void ccp5_debugfs_reset_queue_stats(struct ccp_cmd_queue *cmd_q)
0159 {
0160 cmd_q->total_ops = 0L;
0161 cmd_q->total_aes_ops = 0L;
0162 cmd_q->total_xts_aes_ops = 0L;
0163 cmd_q->total_3des_ops = 0L;
0164 cmd_q->total_sha_ops = 0L;
0165 cmd_q->total_rsa_ops = 0L;
0166 cmd_q->total_pt_ops = 0L;
0167 cmd_q->total_ecc_ops = 0L;
0168 }
0169
0170
0171
0172
0173
0174 static ssize_t ccp5_debugfs_stats_write(struct file *filp,
0175 const char __user *ubuf,
0176 size_t count, loff_t *offp)
0177 {
0178 struct ccp_device *ccp = filp->private_data;
0179 int i;
0180
0181 for (i = 0; i < ccp->cmd_q_count; i++)
0182 ccp5_debugfs_reset_queue_stats(&ccp->cmd_q[i]);
0183 ccp->total_interrupts = 0L;
0184
0185 return count;
0186 }
0187
0188
0189
0190
0191 static ssize_t ccp5_debugfs_queue_read(struct file *filp, char __user *ubuf,
0192 size_t count, loff_t *offp)
0193 {
0194 struct ccp_cmd_queue *cmd_q = filp->private_data;
0195 unsigned int oboff = 0;
0196 unsigned int regval;
0197 ssize_t ret;
0198 char *obuf;
0199
0200 if (!cmd_q)
0201 return 0;
0202
0203 obuf = kmalloc(OBUFLEN, GFP_KERNEL);
0204 if (!obuf)
0205 return -ENOMEM;
0206
0207 oboff += OSCNPRINTF(" Total Queue Operations: %ld\n",
0208 cmd_q->total_ops);
0209 oboff += OSCNPRINTF(" AES: %ld\n",
0210 cmd_q->total_aes_ops);
0211 oboff += OSCNPRINTF(" XTS AES: %ld\n",
0212 cmd_q->total_xts_aes_ops);
0213 oboff += OSCNPRINTF(" SHA: %ld\n",
0214 cmd_q->total_3des_ops);
0215 oboff += OSCNPRINTF(" SHA: %ld\n",
0216 cmd_q->total_sha_ops);
0217 oboff += OSCNPRINTF(" RSA: %ld\n",
0218 cmd_q->total_rsa_ops);
0219 oboff += OSCNPRINTF(" Pass-Thru: %ld\n",
0220 cmd_q->total_pt_ops);
0221 oboff += OSCNPRINTF(" ECC: %ld\n",
0222 cmd_q->total_ecc_ops);
0223
0224 regval = ioread32(cmd_q->reg_int_enable);
0225 oboff += OSCNPRINTF(" Enabled Interrupts:");
0226 if (regval & INT_EMPTY_QUEUE)
0227 oboff += OSCNPRINTF(" EMPTY");
0228 if (regval & INT_QUEUE_STOPPED)
0229 oboff += OSCNPRINTF(" STOPPED");
0230 if (regval & INT_ERROR)
0231 oboff += OSCNPRINTF(" ERROR");
0232 if (regval & INT_COMPLETION)
0233 oboff += OSCNPRINTF(" COMPLETION");
0234 oboff += OSCNPRINTF("\n");
0235
0236 ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
0237 kfree(obuf);
0238
0239 return ret;
0240 }
0241
0242
0243
0244
0245 static ssize_t ccp5_debugfs_queue_write(struct file *filp,
0246 const char __user *ubuf,
0247 size_t count, loff_t *offp)
0248 {
0249 struct ccp_cmd_queue *cmd_q = filp->private_data;
0250
0251 ccp5_debugfs_reset_queue_stats(cmd_q);
0252
0253 return count;
0254 }
0255
0256 static const struct file_operations ccp_debugfs_info_ops = {
0257 .owner = THIS_MODULE,
0258 .open = simple_open,
0259 .read = ccp5_debugfs_info_read,
0260 .write = NULL,
0261 };
0262
0263 static const struct file_operations ccp_debugfs_queue_ops = {
0264 .owner = THIS_MODULE,
0265 .open = simple_open,
0266 .read = ccp5_debugfs_queue_read,
0267 .write = ccp5_debugfs_queue_write,
0268 };
0269
0270 static const struct file_operations ccp_debugfs_stats_ops = {
0271 .owner = THIS_MODULE,
0272 .open = simple_open,
0273 .read = ccp5_debugfs_stats_read,
0274 .write = ccp5_debugfs_stats_write,
0275 };
0276
0277 static struct dentry *ccp_debugfs_dir;
0278 static DEFINE_MUTEX(ccp_debugfs_lock);
0279
0280 #define MAX_NAME_LEN 20
0281
0282 void ccp5_debugfs_setup(struct ccp_device *ccp)
0283 {
0284 struct ccp_cmd_queue *cmd_q;
0285 char name[MAX_NAME_LEN + 1];
0286 struct dentry *debugfs_q_instance;
0287 int i;
0288
0289 if (!debugfs_initialized())
0290 return;
0291
0292 mutex_lock(&ccp_debugfs_lock);
0293 if (!ccp_debugfs_dir)
0294 ccp_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
0295 mutex_unlock(&ccp_debugfs_lock);
0296
0297 ccp->debugfs_instance = debugfs_create_dir(ccp->name, ccp_debugfs_dir);
0298
0299 debugfs_create_file("info", 0400, ccp->debugfs_instance, ccp,
0300 &ccp_debugfs_info_ops);
0301
0302 debugfs_create_file("stats", 0600, ccp->debugfs_instance, ccp,
0303 &ccp_debugfs_stats_ops);
0304
0305 for (i = 0; i < ccp->cmd_q_count; i++) {
0306 cmd_q = &ccp->cmd_q[i];
0307
0308 snprintf(name, MAX_NAME_LEN - 1, "q%d", cmd_q->id);
0309
0310 debugfs_q_instance =
0311 debugfs_create_dir(name, ccp->debugfs_instance);
0312
0313 debugfs_create_file("stats", 0600, debugfs_q_instance, cmd_q,
0314 &ccp_debugfs_queue_ops);
0315 }
0316
0317 return;
0318 }
0319
0320 void ccp5_debugfs_destroy(void)
0321 {
0322 debugfs_remove_recursive(ccp_debugfs_dir);
0323 }