^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) * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2014- QLogic Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * All rights reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * www.qlogic.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "bfad_drv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "bfad_im.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * BFA debufs interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * To access the interface, debugfs file system should be mounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * if not already mounted using:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * mount -t debugfs none /sys/kernel/debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * BFA Hierarchy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * - bfa/pci_dev:<pci_name>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * where the pci_name corresponds to the one under /sys/bus/pci/drivers/bfa
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Debugging service available per pci_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * fwtrc: To collect current firmware trace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * drvtrc: To collect current driver trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * fwsave: To collect last saved fw trace as a result of firmware crash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * regwr: To write one word to chip register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * regrd: To read one or more words from chip register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct bfad_debug_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) char *debug_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) void *i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int buffer_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) bfad_debugfs_open_drvtrc(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct bfad_port_s *port = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct bfad_debug_info *debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) debug = kzalloc(sizeof(struct bfad_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) debug->debug_buffer = (void *) bfad->trcmod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) debug->buffer_len = sizeof(struct bfa_trc_mod_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) file->private_data = debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) bfad_debugfs_open_fwtrc(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct bfad_port_s *port = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct bfad_debug_info *fw_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) fw_debug = kzalloc(sizeof(struct bfad_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!fw_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (!fw_debug->debug_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) kfree(fw_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printk(KERN_INFO "bfad[%d]: Failed to allocate fwtrc buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rc = bfa_ioc_debug_fwtrc(&bfad->bfa.ioc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) fw_debug->debug_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) &fw_debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (rc != BFA_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) vfree(fw_debug->debug_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) fw_debug->debug_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) kfree(fw_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) printk(KERN_INFO "bfad[%d]: Failed to collect fwtrc\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) file->private_data = fw_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bfad_debugfs_open_fwsave(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct bfad_port_s *port = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct bfad_debug_info *fw_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) fw_debug = kzalloc(sizeof(struct bfad_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!fw_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (!fw_debug->debug_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) kfree(fw_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) printk(KERN_INFO "bfad[%d]: Failed to allocate fwsave buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) rc = bfa_ioc_debug_fwsave(&bfad->bfa.ioc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) fw_debug->debug_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) &fw_debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (rc != BFA_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) vfree(fw_debug->debug_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) fw_debug->debug_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) kfree(fw_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) printk(KERN_INFO "bfad[%d]: Failed to collect fwsave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) file->private_data = fw_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) bfad_debugfs_open_reg(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct bfad_debug_info *reg_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) reg_debug = kzalloc(sizeof(struct bfad_debug_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (!reg_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) reg_debug->i_private = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) file->private_data = reg_debug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Changes the current file position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static loff_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) bfad_debugfs_lseek(struct file *file, loff_t offset, int orig)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct bfad_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return fixed_size_llseek(file, offset, orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) debug->buffer_len);
^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) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) bfad_debugfs_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) size_t nbytes, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct bfad_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (!debug || !debug->debug_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return simple_read_from_buffer(buf, nbytes, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) debug->debug_buffer, debug->buffer_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define BFA_REG_CT_ADDRSZ (0x40000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define BFA_REG_CB_ADDRSZ (0x20000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define BFA_REG_ADDRSZ(__ioc) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) ((u32)(bfa_asic_id_ctc(bfa_ioc_devid(__ioc)) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) BFA_REG_CT_ADDRSZ : BFA_REG_CB_ADDRSZ))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) #define BFA_REG_ADDRMSK(__ioc) (BFA_REG_ADDRSZ(__ioc) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static bfa_status_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) bfad_reg_offset_check(struct bfa_s *bfa, u32 offset, u32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u8 area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* check [16:15] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) area = (offset >> 15) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (area == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /* PCIe core register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if ((offset + (len<<2)) > 0x8000) /* 8k dwords or 32KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return BFA_STATUS_EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) } else if (area == 0x1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* CB 32 KB memory page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if ((offset + (len<<2)) > 0x10000) /* 8k dwords or 32KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return BFA_STATUS_EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* CB register space 64KB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if ((offset + (len<<2)) > BFA_REG_ADDRMSK(&bfa->ioc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return BFA_STATUS_EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return BFA_STATUS_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) bfad_debugfs_read_regrd(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) size_t nbytes, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct bfad_debug_info *regrd_debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct bfad_port_s *port = (struct bfad_port_s *)regrd_debug->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (!bfad->regdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) rc = simple_read_from_buffer(buf, nbytes, pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) bfad->regdata, bfad->reglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if ((*pos + nbytes) >= bfad->reglen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) kfree(bfad->regdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) bfad->regdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) bfad->reglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct bfad_debug_info *regrd_debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct bfad_port_s *port = (struct bfad_port_s *)regrd_debug->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct bfa_s *bfa = &bfad->bfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct bfa_ioc_s *ioc = &bfa->ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int addr, rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) u32 *regbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void __iomem *rb, *reg_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void *kern_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) kern_buf = memdup_user(buf, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (IS_ERR(kern_buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return PTR_ERR(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) rc = sscanf(kern_buf, "%x:%x", &addr, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (rc < 2 || len > (UINT_MAX >> 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) "bfad[%d]: %s failed to read user buf\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) bfad->inst_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) kfree(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) kfree(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) kfree(bfad->regdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) bfad->regdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) bfad->reglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) bfad->regdata = kzalloc(len << 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!bfad->regdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) printk(KERN_INFO "bfad[%d]: Failed to allocate regrd buffer\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) bfad->reglen = len << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) rb = bfa_ioc_bar0(ioc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) addr &= BFA_REG_ADDRMSK(ioc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* offset and len sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) rc = bfad_reg_offset_check(bfa, addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) printk(KERN_INFO "bfad[%d]: Failed reg offset check\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) kfree(bfad->regdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bfad->regdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) bfad->reglen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) reg_addr = rb + addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) regbuf = (u32 *)bfad->regdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) *regbuf = readl(reg_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) regbuf++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) reg_addr += sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct bfad_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct bfad_port_s *port = (struct bfad_port_s *)debug->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct bfa_s *bfa = &bfad->bfa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) struct bfa_ioc_s *ioc = &bfa->ioc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int addr, val, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) void __iomem *reg_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void *kern_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) kern_buf = memdup_user(buf, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (IS_ERR(kern_buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return PTR_ERR(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) rc = sscanf(kern_buf, "%x:%x", &addr, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (rc < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) "bfad[%d]: %s failed to read user buf\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) bfad->inst_no, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) kfree(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kfree(kern_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) addr &= BFA_REG_ADDRMSK(ioc); /* offset only 17 bit and word align */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* offset and len sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) rc = bfad_reg_offset_check(bfa, addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) printk(KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) "bfad[%d]: Failed reg offset check\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) bfad->inst_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) reg_addr = (bfa_ioc_bar0(ioc)) + addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) spin_lock_irqsave(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) writel(val, reg_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) spin_unlock_irqrestore(&bfad->bfad_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) bfad_debugfs_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct bfad_debug_info *debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (!debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) kfree(debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) bfad_debugfs_release_fwtrc(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct bfad_debug_info *fw_debug = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (!fw_debug)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (fw_debug->debug_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) vfree(fw_debug->debug_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) file->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) kfree(fw_debug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) static const struct file_operations bfad_debugfs_op_drvtrc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .open = bfad_debugfs_open_drvtrc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .llseek = bfad_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) .read = bfad_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .release = bfad_debugfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static const struct file_operations bfad_debugfs_op_fwtrc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .open = bfad_debugfs_open_fwtrc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .llseek = bfad_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .read = bfad_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .release = bfad_debugfs_release_fwtrc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static const struct file_operations bfad_debugfs_op_fwsave = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .open = bfad_debugfs_open_fwsave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .llseek = bfad_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) .read = bfad_debugfs_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) .release = bfad_debugfs_release_fwtrc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static const struct file_operations bfad_debugfs_op_regrd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .open = bfad_debugfs_open_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .llseek = bfad_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .read = bfad_debugfs_read_regrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .write = bfad_debugfs_write_regrd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .release = bfad_debugfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static const struct file_operations bfad_debugfs_op_regwr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) .open = bfad_debugfs_open_reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) .llseek = bfad_debugfs_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .write = bfad_debugfs_write_regwr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) .release = bfad_debugfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct bfad_debugfs_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) umode_t mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) const struct file_operations *fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static const struct bfad_debugfs_entry bfad_debugfs_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) { "drvtrc", S_IFREG|S_IRUGO, &bfad_debugfs_op_drvtrc, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) { "fwtrc", S_IFREG|S_IRUGO, &bfad_debugfs_op_fwtrc, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) { "fwsave", S_IFREG|S_IRUGO, &bfad_debugfs_op_fwsave, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) { "regrd", S_IFREG|S_IRUGO|S_IWUSR, &bfad_debugfs_op_regrd, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) { "regwr", S_IFREG|S_IWUSR, &bfad_debugfs_op_regwr, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) static struct dentry *bfa_debugfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static atomic_t bfa_debugfs_port_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) bfad_debugfs_init(struct bfad_port_s *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) const struct bfad_debugfs_entry *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) char name[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!bfa_debugfs_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* Setup the BFA debugfs root directory*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (!bfa_debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) bfa_debugfs_root = debugfs_create_dir("bfa", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) atomic_set(&bfa_debugfs_port_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) /* Setup the pci_dev debugfs directory for the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) snprintf(name, sizeof(name), "pci_dev:%s", bfad->pci_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (!port->port_debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) port->port_debugfs_root =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) debugfs_create_dir(name, bfa_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) atomic_inc(&bfa_debugfs_port_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) for (i = 0; i < ARRAY_SIZE(bfad_debugfs_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) file = &bfad_debugfs_files[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) bfad->bfad_dentry_files[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) debugfs_create_file(file->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) file->mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) port->port_debugfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) file->fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) bfad_debugfs_exit(struct bfad_port_s *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct bfad_s *bfad = port->bfad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) for (i = 0; i < ARRAY_SIZE(bfad_debugfs_files); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (bfad->bfad_dentry_files[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) debugfs_remove(bfad->bfad_dentry_files[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) bfad->bfad_dentry_files[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* Remove the pci_dev debugfs directory for the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) if (port->port_debugfs_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) debugfs_remove(port->port_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) port->port_debugfs_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) atomic_dec(&bfa_debugfs_port_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /* Remove the BFA debugfs root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (atomic_read(&bfa_debugfs_port_count) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) debugfs_remove(bfa_debugfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) bfa_debugfs_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }