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