^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * AMD Cryptographic Coprocessor (CCP) driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Gary R Hook <gary.hook@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/ccp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "ccp-dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /* DebugFS helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define OBUFP (obuf + oboff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define OBUFLEN 512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define OBUFSPC (OBUFLEN - oboff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define OSCNPRINTF(fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define BUFLEN 63
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define RI_VERSION_NUM 0x0000003F
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define RI_AES_PRESENT 0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define RI_3DES_PRESENT 0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define RI_SHA_PRESENT 0x00000100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define RI_RSA_PRESENT 0x00000200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define RI_ECC_PRESENT 0x00000400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define RI_ZDE_PRESENT 0x00000800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define RI_ZCE_PRESENT 0x00001000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RI_TRNG_PRESENT 0x00002000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define RI_ELFC_PRESENT 0x00004000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define RI_ELFC_SHIFT 14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define RI_NUM_VQM 0x00078000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define RI_NVQM_SHIFT 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define RI_NVQM(r) (((r) * RI_NUM_VQM) >> RI_NVQM_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define RI_LSB_ENTRIES 0x0FF80000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define RI_NLSB_SHIFT 19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define RI_NLSB(r) (((r) * RI_LSB_ENTRIES) >> RI_NLSB_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static ssize_t ccp5_debugfs_info_read(struct file *filp, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) size_t count, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ccp_device *ccp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned int oboff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) unsigned int regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) char *obuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (!ccp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) obuf = kmalloc(OBUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!obuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) oboff += OSCNPRINTF("Device name: %s\n", ccp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) oboff += OSCNPRINTF(" RNG name: %s\n", ccp->rngname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) oboff += OSCNPRINTF(" # Queues: %d\n", ccp->cmd_q_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) oboff += OSCNPRINTF(" # Cmds: %d\n", ccp->cmd_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) regval = ioread32(ccp->io_regs + CMD5_PSP_CCP_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) oboff += OSCNPRINTF(" Version: %d\n", regval & RI_VERSION_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) oboff += OSCNPRINTF(" Engines:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (regval & RI_AES_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) oboff += OSCNPRINTF(" AES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (regval & RI_3DES_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) oboff += OSCNPRINTF(" 3DES");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (regval & RI_SHA_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) oboff += OSCNPRINTF(" SHA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (regval & RI_RSA_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) oboff += OSCNPRINTF(" RSA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (regval & RI_ECC_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) oboff += OSCNPRINTF(" ECC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (regval & RI_ZDE_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) oboff += OSCNPRINTF(" ZDE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (regval & RI_ZCE_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) oboff += OSCNPRINTF(" ZCE");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (regval & RI_TRNG_PRESENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) oboff += OSCNPRINTF(" TRNG");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) oboff += OSCNPRINTF("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) oboff += OSCNPRINTF(" Queues: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) (regval & RI_NUM_VQM) >> RI_NVQM_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) oboff += OSCNPRINTF("LSB Entries: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) (regval & RI_LSB_ENTRIES) >> RI_NLSB_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) kfree(obuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* Return a formatted buffer containing the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * statistics across all queues for a CCP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static ssize_t ccp5_debugfs_stats_read(struct file *filp, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) size_t count, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct ccp_device *ccp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) unsigned long total_xts_aes_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned long total_3des_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned long total_aes_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned long total_sha_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned long total_rsa_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned long total_ecc_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned long total_pt_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned long total_ops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned int oboff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ssize_t ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) char *obuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) for (i = 0; i < ccp->cmd_q_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct ccp_cmd_queue *cmd_q = &ccp->cmd_q[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) total_ops += cmd_q->total_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) total_aes_ops += cmd_q->total_aes_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) total_xts_aes_ops += cmd_q->total_xts_aes_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) total_3des_ops += cmd_q->total_3des_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) total_sha_ops += cmd_q->total_sha_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) total_rsa_ops += cmd_q->total_rsa_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) total_pt_ops += cmd_q->total_pt_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) total_ecc_ops += cmd_q->total_ecc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) obuf = kmalloc(OBUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (!obuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) oboff += OSCNPRINTF("Total Interrupts Handled: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ccp->total_interrupts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) oboff += OSCNPRINTF(" Total Operations: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) total_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) oboff += OSCNPRINTF(" AES: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) total_aes_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) oboff += OSCNPRINTF(" XTS AES: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) total_xts_aes_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) oboff += OSCNPRINTF(" SHA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) total_3des_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) oboff += OSCNPRINTF(" SHA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) total_sha_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) oboff += OSCNPRINTF(" RSA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) total_rsa_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) oboff += OSCNPRINTF(" Pass-Thru: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) total_pt_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) oboff += OSCNPRINTF(" ECC: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) total_ecc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) kfree(obuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* Reset the counters in a queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static void ccp5_debugfs_reset_queue_stats(struct ccp_cmd_queue *cmd_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) cmd_q->total_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) cmd_q->total_aes_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) cmd_q->total_xts_aes_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) cmd_q->total_3des_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cmd_q->total_sha_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) cmd_q->total_rsa_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) cmd_q->total_pt_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) cmd_q->total_ecc_ops = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* A value was written to the stats variable, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * should be used to reset the queue counters across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * that device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static ssize_t ccp5_debugfs_stats_write(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) size_t count, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct ccp_device *ccp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) for (i = 0; i < ccp->cmd_q_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ccp5_debugfs_reset_queue_stats(&ccp->cmd_q[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) ccp->total_interrupts = 0L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* Return a formatted buffer containing the current information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * for that queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static ssize_t ccp5_debugfs_queue_read(struct file *filp, char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) size_t count, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct ccp_cmd_queue *cmd_q = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) unsigned int oboff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) unsigned int regval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) char *obuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (!cmd_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) obuf = kmalloc(OBUFLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (!obuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) oboff += OSCNPRINTF(" Total Queue Operations: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) cmd_q->total_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) oboff += OSCNPRINTF(" AES: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) cmd_q->total_aes_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) oboff += OSCNPRINTF(" XTS AES: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) cmd_q->total_xts_aes_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) oboff += OSCNPRINTF(" SHA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) cmd_q->total_3des_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) oboff += OSCNPRINTF(" SHA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) cmd_q->total_sha_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) oboff += OSCNPRINTF(" RSA: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) cmd_q->total_rsa_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) oboff += OSCNPRINTF(" Pass-Thru: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) cmd_q->total_pt_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) oboff += OSCNPRINTF(" ECC: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) cmd_q->total_ecc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) regval = ioread32(cmd_q->reg_int_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) oboff += OSCNPRINTF(" Enabled Interrupts:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (regval & INT_EMPTY_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) oboff += OSCNPRINTF(" EMPTY");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (regval & INT_QUEUE_STOPPED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) oboff += OSCNPRINTF(" STOPPED");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (regval & INT_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) oboff += OSCNPRINTF(" ERROR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (regval & INT_COMPLETION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) oboff += OSCNPRINTF(" COMPLETION");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) oboff += OSCNPRINTF("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) kfree(obuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /* A value was written to the stats variable for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * queue. Reset the queue counters to this value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static ssize_t ccp5_debugfs_queue_write(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) size_t count, loff_t *offp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct ccp_cmd_queue *cmd_q = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) ccp5_debugfs_reset_queue_stats(cmd_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static const struct file_operations ccp_debugfs_info_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .read = ccp5_debugfs_info_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .write = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct file_operations ccp_debugfs_queue_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .read = ccp5_debugfs_queue_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .write = ccp5_debugfs_queue_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static const struct file_operations ccp_debugfs_stats_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .open = simple_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .read = ccp5_debugfs_stats_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .write = ccp5_debugfs_stats_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static struct dentry *ccp_debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static DEFINE_MUTEX(ccp_debugfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define MAX_NAME_LEN 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void ccp5_debugfs_setup(struct ccp_device *ccp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct ccp_cmd_queue *cmd_q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) char name[MAX_NAME_LEN + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct dentry *debugfs_q_instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (!debugfs_initialized())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) mutex_lock(&ccp_debugfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (!ccp_debugfs_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ccp_debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) mutex_unlock(&ccp_debugfs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) ccp->debugfs_instance = debugfs_create_dir(ccp->name, ccp_debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) debugfs_create_file("info", 0400, ccp->debugfs_instance, ccp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) &ccp_debugfs_info_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) debugfs_create_file("stats", 0600, ccp->debugfs_instance, ccp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) &ccp_debugfs_stats_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) for (i = 0; i < ccp->cmd_q_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) cmd_q = &ccp->cmd_q[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) snprintf(name, MAX_NAME_LEN - 1, "q%d", cmd_q->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) debugfs_q_instance =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) debugfs_create_dir(name, ccp->debugfs_instance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) debugfs_create_file("stats", 0600, debugfs_q_instance, cmd_q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) &ccp_debugfs_queue_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) void ccp5_debugfs_destroy(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) debugfs_remove_recursive(ccp_debugfs_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }