root/drivers/crypto/qat/qat_common/adf_transport_debug.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. adf_ring_start
  2. adf_ring_next
  3. adf_ring_show
  4. adf_ring_stop
  5. adf_ring_open
  6. adf_ring_debugfs_add
  7. adf_ring_debugfs_rm
  8. adf_bank_start
  9. adf_bank_next
  10. adf_bank_show
  11. adf_bank_stop
  12. adf_bank_open
  13. adf_bank_debugfs_add
  14. adf_bank_debugfs_rm

   1 /*
   2   This file is provided under a dual BSD/GPLv2 license.  When using or
   3   redistributing this file, you may do so under either license.
   4 
   5   GPL LICENSE SUMMARY
   6   Copyright(c) 2014 Intel Corporation.
   7   This program is free software; you can redistribute it and/or modify
   8   it under the terms of version 2 of the GNU General Public License as
   9   published by the Free Software Foundation.
  10 
  11   This program is distributed in the hope that it will be useful, but
  12   WITHOUT ANY WARRANTY; without even the implied warranty of
  13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14   General Public License for more details.
  15 
  16   Contact Information:
  17   qat-linux@intel.com
  18 
  19   BSD LICENSE
  20   Copyright(c) 2014 Intel Corporation.
  21   Redistribution and use in source and binary forms, with or without
  22   modification, are permitted provided that the following conditions
  23   are met:
  24 
  25     * Redistributions of source code must retain the above copyright
  26       notice, this list of conditions and the following disclaimer.
  27     * Redistributions in binary form must reproduce the above copyright
  28       notice, this list of conditions and the following disclaimer in
  29       the documentation and/or other materials provided with the
  30       distribution.
  31     * Neither the name of Intel Corporation nor the names of its
  32       contributors may be used to endorse or promote products derived
  33       from this software without specific prior written permission.
  34 
  35   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  36   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  37   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  38   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  39   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  42   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  43   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  45   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46 */
  47 #include <linux/mutex.h>
  48 #include <linux/slab.h>
  49 #include <linux/seq_file.h>
  50 #include "adf_accel_devices.h"
  51 #include "adf_transport_internal.h"
  52 #include "adf_transport_access_macros.h"
  53 
  54 static DEFINE_MUTEX(ring_read_lock);
  55 static DEFINE_MUTEX(bank_read_lock);
  56 
  57 static void *adf_ring_start(struct seq_file *sfile, loff_t *pos)
  58 {
  59         struct adf_etr_ring_data *ring = sfile->private;
  60 
  61         mutex_lock(&ring_read_lock);
  62         if (*pos == 0)
  63                 return SEQ_START_TOKEN;
  64 
  65         if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
  66                      ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
  67                 return NULL;
  68 
  69         return ring->base_addr +
  70                 (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
  71 }
  72 
  73 static void *adf_ring_next(struct seq_file *sfile, void *v, loff_t *pos)
  74 {
  75         struct adf_etr_ring_data *ring = sfile->private;
  76 
  77         if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
  78                      ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
  79                 return NULL;
  80 
  81         return ring->base_addr +
  82                 (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
  83 }
  84 
  85 static int adf_ring_show(struct seq_file *sfile, void *v)
  86 {
  87         struct adf_etr_ring_data *ring = sfile->private;
  88         struct adf_etr_bank_data *bank = ring->bank;
  89         void __iomem *csr = ring->bank->csr_addr;
  90 
  91         if (v == SEQ_START_TOKEN) {
  92                 int head, tail, empty;
  93 
  94                 head = READ_CSR_RING_HEAD(csr, bank->bank_number,
  95                                           ring->ring_number);
  96                 tail = READ_CSR_RING_TAIL(csr, bank->bank_number,
  97                                           ring->ring_number);
  98                 empty = READ_CSR_E_STAT(csr, bank->bank_number);
  99 
 100                 seq_puts(sfile, "------- Ring configuration -------\n");
 101                 seq_printf(sfile, "ring name: %s\n",
 102                            ring->ring_debug->ring_name);
 103                 seq_printf(sfile, "ring num %d, bank num %d\n",
 104                            ring->ring_number, ring->bank->bank_number);
 105                 seq_printf(sfile, "head %x, tail %x, empty: %d\n",
 106                            head, tail, (empty & 1 << ring->ring_number)
 107                            >> ring->ring_number);
 108                 seq_printf(sfile, "ring size %d, msg size %d\n",
 109                            ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size),
 110                            ADF_MSG_SIZE_TO_BYTES(ring->msg_size));
 111                 seq_puts(sfile, "----------- Ring data ------------\n");
 112                 return 0;
 113         }
 114         seq_hex_dump(sfile, "", DUMP_PREFIX_ADDRESS, 32, 4,
 115                      v, ADF_MSG_SIZE_TO_BYTES(ring->msg_size), false);
 116         return 0;
 117 }
 118 
 119 static void adf_ring_stop(struct seq_file *sfile, void *v)
 120 {
 121         mutex_unlock(&ring_read_lock);
 122 }
 123 
 124 static const struct seq_operations adf_ring_sops = {
 125         .start = adf_ring_start,
 126         .next = adf_ring_next,
 127         .stop = adf_ring_stop,
 128         .show = adf_ring_show
 129 };
 130 
 131 static int adf_ring_open(struct inode *inode, struct file *file)
 132 {
 133         int ret = seq_open(file, &adf_ring_sops);
 134 
 135         if (!ret) {
 136                 struct seq_file *seq_f = file->private_data;
 137 
 138                 seq_f->private = inode->i_private;
 139         }
 140         return ret;
 141 }
 142 
 143 static const struct file_operations adf_ring_debug_fops = {
 144         .open = adf_ring_open,
 145         .read = seq_read,
 146         .llseek = seq_lseek,
 147         .release = seq_release
 148 };
 149 
 150 int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name)
 151 {
 152         struct adf_etr_ring_debug_entry *ring_debug;
 153         char entry_name[8];
 154 
 155         ring_debug = kzalloc(sizeof(*ring_debug), GFP_KERNEL);
 156         if (!ring_debug)
 157                 return -ENOMEM;
 158 
 159         strlcpy(ring_debug->ring_name, name, sizeof(ring_debug->ring_name));
 160         snprintf(entry_name, sizeof(entry_name), "ring_%02d",
 161                  ring->ring_number);
 162 
 163         ring_debug->debug = debugfs_create_file(entry_name, S_IRUSR,
 164                                                 ring->bank->bank_debug_dir,
 165                                                 ring, &adf_ring_debug_fops);
 166         ring->ring_debug = ring_debug;
 167         return 0;
 168 }
 169 
 170 void adf_ring_debugfs_rm(struct adf_etr_ring_data *ring)
 171 {
 172         if (ring->ring_debug) {
 173                 debugfs_remove(ring->ring_debug->debug);
 174                 kfree(ring->ring_debug);
 175                 ring->ring_debug = NULL;
 176         }
 177 }
 178 
 179 static void *adf_bank_start(struct seq_file *sfile, loff_t *pos)
 180 {
 181         mutex_lock(&bank_read_lock);
 182         if (*pos == 0)
 183                 return SEQ_START_TOKEN;
 184 
 185         if (*pos >= ADF_ETR_MAX_RINGS_PER_BANK)
 186                 return NULL;
 187 
 188         return pos;
 189 }
 190 
 191 static void *adf_bank_next(struct seq_file *sfile, void *v, loff_t *pos)
 192 {
 193         if (++(*pos) >= ADF_ETR_MAX_RINGS_PER_BANK)
 194                 return NULL;
 195 
 196         return pos;
 197 }
 198 
 199 static int adf_bank_show(struct seq_file *sfile, void *v)
 200 {
 201         struct adf_etr_bank_data *bank = sfile->private;
 202 
 203         if (v == SEQ_START_TOKEN) {
 204                 seq_printf(sfile, "------- Bank %d configuration -------\n",
 205                            bank->bank_number);
 206         } else {
 207                 int ring_id = *((int *)v) - 1;
 208                 struct adf_etr_ring_data *ring = &bank->rings[ring_id];
 209                 void __iomem *csr = bank->csr_addr;
 210                 int head, tail, empty;
 211 
 212                 if (!(bank->ring_mask & 1 << ring_id))
 213                         return 0;
 214 
 215                 head = READ_CSR_RING_HEAD(csr, bank->bank_number,
 216                                           ring->ring_number);
 217                 tail = READ_CSR_RING_TAIL(csr, bank->bank_number,
 218                                           ring->ring_number);
 219                 empty = READ_CSR_E_STAT(csr, bank->bank_number);
 220 
 221                 seq_printf(sfile,
 222                            "ring num %02d, head %04x, tail %04x, empty: %d\n",
 223                            ring->ring_number, head, tail,
 224                            (empty & 1 << ring->ring_number) >>
 225                            ring->ring_number);
 226         }
 227         return 0;
 228 }
 229 
 230 static void adf_bank_stop(struct seq_file *sfile, void *v)
 231 {
 232         mutex_unlock(&bank_read_lock);
 233 }
 234 
 235 static const struct seq_operations adf_bank_sops = {
 236         .start = adf_bank_start,
 237         .next = adf_bank_next,
 238         .stop = adf_bank_stop,
 239         .show = adf_bank_show
 240 };
 241 
 242 static int adf_bank_open(struct inode *inode, struct file *file)
 243 {
 244         int ret = seq_open(file, &adf_bank_sops);
 245 
 246         if (!ret) {
 247                 struct seq_file *seq_f = file->private_data;
 248 
 249                 seq_f->private = inode->i_private;
 250         }
 251         return ret;
 252 }
 253 
 254 static const struct file_operations adf_bank_debug_fops = {
 255         .open = adf_bank_open,
 256         .read = seq_read,
 257         .llseek = seq_lseek,
 258         .release = seq_release
 259 };
 260 
 261 int adf_bank_debugfs_add(struct adf_etr_bank_data *bank)
 262 {
 263         struct adf_accel_dev *accel_dev = bank->accel_dev;
 264         struct dentry *parent = accel_dev->transport->debug;
 265         char name[8];
 266 
 267         snprintf(name, sizeof(name), "bank_%02d", bank->bank_number);
 268         bank->bank_debug_dir = debugfs_create_dir(name, parent);
 269         bank->bank_debug_cfg = debugfs_create_file("config", S_IRUSR,
 270                                                    bank->bank_debug_dir, bank,
 271                                                    &adf_bank_debug_fops);
 272         return 0;
 273 }
 274 
 275 void adf_bank_debugfs_rm(struct adf_etr_bank_data *bank)
 276 {
 277         debugfs_remove(bank->bank_debug_cfg);
 278         debugfs_remove(bank->bank_debug_dir);
 279 }

/* [<][>][^][v][top][bottom][index][help] */