James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
| 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | f25e8e7 | 2015-04-07 15:07:28 -0400 | [diff] [blame] | 4 | * Copyright (C) 2007-2015 Emulex. All rights reserved. * |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| 6 | * www.emulex.com * |
| 7 | * * |
| 8 | * This program is free software; you can redistribute it and/or * |
| 9 | * modify it under the terms of version 2 of the GNU General * |
| 10 | * Public License as published by the Free Software Foundation. * |
| 11 | * This program is distributed in the hope that it will be useful. * |
| 12 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * |
| 13 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * |
| 15 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * |
| 16 | * TO BE LEGALLY INVALID. See the GNU General Public License for * |
| 17 | * more details, a copy of which can be found in the file COPYING * |
| 18 | * included with this package. * |
| 19 | *******************************************************************/ |
| 20 | |
| 21 | #include <linux/blkdev.h> |
| 22 | #include <linux/delay.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 24 | #include <linux/dma-mapping.h> |
| 25 | #include <linux/idr.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/kthread.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 29 | #include <linux/pci.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/ctype.h> |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 32 | |
| 33 | #include <scsi/scsi.h> |
| 34 | #include <scsi/scsi_device.h> |
| 35 | #include <scsi/scsi_host.h> |
| 36 | #include <scsi/scsi_transport_fc.h> |
| 37 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 38 | #include "lpfc_hw4.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 39 | #include "lpfc_hw.h" |
| 40 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 41 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 42 | #include "lpfc_nl.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 43 | #include "lpfc_disc.h" |
| 44 | #include "lpfc_scsi.h" |
| 45 | #include "lpfc.h" |
| 46 | #include "lpfc_logmsg.h" |
| 47 | #include "lpfc_crtn.h" |
| 48 | #include "lpfc_vport.h" |
| 49 | #include "lpfc_version.h" |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 50 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 51 | #include "lpfc_debugfs.h" |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 52 | #include "lpfc_bsg.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 53 | |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 54 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 55 | /* |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 56 | * debugfs interface |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 57 | * |
| 58 | * To access this interface the user should: |
GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 59 | * # mount -t debugfs none /sys/kernel/debug |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 60 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 61 | * The lpfc debugfs directory hierarchy is: |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 62 | * /sys/kernel/debug/lpfc/fnX/vportY |
| 63 | * where X is the lpfc hba function unique_id |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 64 | * where Y is the vport VPI on that hba |
| 65 | * |
| 66 | * Debugging services available per vport: |
| 67 | * discovery_trace |
| 68 | * This is an ACSII readable file that contains a trace of the last |
| 69 | * lpfc_debugfs_max_disc_trc events that happened on a specific vport. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 70 | * See lpfc_debugfs.h for different categories of discovery events. |
| 71 | * To enable the discovery trace, the following module parameters must be set: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 72 | * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support |
| 73 | * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for |
| 74 | * EACH vport. X MUST also be a power of 2. |
| 75 | * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in |
| 76 | * lpfc_debugfs.h . |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 77 | * |
| 78 | * slow_ring_trace |
| 79 | * This is an ACSII readable file that contains a trace of the last |
| 80 | * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA. |
| 81 | * To enable the slow ring trace, the following module parameters must be set: |
| 82 | * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support |
| 83 | * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for |
| 84 | * the HBA. X MUST also be a power of 2. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 85 | */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 86 | static int lpfc_debugfs_enable = 1; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 87 | module_param(lpfc_debugfs_enable, int, S_IRUGO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 88 | MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services"); |
| 89 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 90 | /* This MUST be a power of 2 */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 91 | static int lpfc_debugfs_max_disc_trc; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 92 | module_param(lpfc_debugfs_max_disc_trc, int, S_IRUGO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 93 | MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc, |
| 94 | "Set debugfs discovery trace depth"); |
| 95 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 96 | /* This MUST be a power of 2 */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 97 | static int lpfc_debugfs_max_slow_ring_trc; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 98 | module_param(lpfc_debugfs_max_slow_ring_trc, int, S_IRUGO); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 99 | MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc, |
| 100 | "Set debugfs slow ring trace depth"); |
| 101 | |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 102 | static int lpfc_debugfs_mask_disc_trc; |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 103 | module_param(lpfc_debugfs_mask_disc_trc, int, S_IRUGO); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 104 | MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc, |
| 105 | "Set debugfs discovery trace mask"); |
| 106 | |
| 107 | #include <linux/debugfs.h> |
| 108 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 109 | static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); |
| 110 | static unsigned long lpfc_debugfs_start_time = 0L; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 111 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 112 | /* iDiag */ |
| 113 | static struct lpfc_idiag idiag; |
| 114 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 115 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 116 | * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 117 | * @vport: The vport to gather the log info from. |
| 118 | * @buf: The buffer to dump log into. |
| 119 | * @size: The maximum amount of data to process. |
| 120 | * |
| 121 | * Description: |
| 122 | * This routine gathers the lpfc discovery debugfs data from the @vport and |
| 123 | * dumps it to @buf up to @size number of bytes. It will start at the next entry |
| 124 | * in the log and process the log until the end of the buffer. Then it will |
| 125 | * gather from the beginning of the log and process until the current entry. |
| 126 | * |
| 127 | * Notes: |
| 128 | * Discovery logging will be disabled while while this routine dumps the log. |
| 129 | * |
| 130 | * Return Value: |
| 131 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 132 | * not exceed @size. |
| 133 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 134 | static int |
| 135 | lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size) |
| 136 | { |
| 137 | int i, index, len, enable; |
| 138 | uint32_t ms; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 139 | struct lpfc_debugfs_trc *dtp; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 140 | char *buffer; |
| 141 | |
| 142 | buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL); |
| 143 | if (!buffer) |
| 144 | return 0; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 145 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 146 | enable = lpfc_debugfs_enable; |
| 147 | lpfc_debugfs_enable = 0; |
| 148 | |
| 149 | len = 0; |
| 150 | index = (atomic_read(&vport->disc_trc_cnt) + 1) & |
| 151 | (lpfc_debugfs_max_disc_trc - 1); |
| 152 | for (i = index; i < lpfc_debugfs_max_disc_trc; i++) { |
| 153 | dtp = vport->disc_trc + i; |
| 154 | if (!dtp->fmt) |
| 155 | continue; |
| 156 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 157 | snprintf(buffer, |
| 158 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 159 | dtp->seq_cnt, ms, dtp->fmt); |
| 160 | len += snprintf(buf+len, size-len, buffer, |
| 161 | dtp->data1, dtp->data2, dtp->data3); |
| 162 | } |
| 163 | for (i = 0; i < index; i++) { |
| 164 | dtp = vport->disc_trc + i; |
| 165 | if (!dtp->fmt) |
| 166 | continue; |
| 167 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 168 | snprintf(buffer, |
| 169 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 170 | dtp->seq_cnt, ms, dtp->fmt); |
| 171 | len += snprintf(buf+len, size-len, buffer, |
| 172 | dtp->data1, dtp->data2, dtp->data3); |
| 173 | } |
| 174 | |
| 175 | lpfc_debugfs_enable = enable; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 176 | kfree(buffer); |
| 177 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 178 | return len; |
| 179 | } |
| 180 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 181 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 182 | * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 183 | * @phba: The HBA to gather the log info from. |
| 184 | * @buf: The buffer to dump log into. |
| 185 | * @size: The maximum amount of data to process. |
| 186 | * |
| 187 | * Description: |
| 188 | * This routine gathers the lpfc slow ring debugfs data from the @phba and |
| 189 | * dumps it to @buf up to @size number of bytes. It will start at the next entry |
| 190 | * in the log and process the log until the end of the buffer. Then it will |
| 191 | * gather from the beginning of the log and process until the current entry. |
| 192 | * |
| 193 | * Notes: |
| 194 | * Slow ring logging will be disabled while while this routine dumps the log. |
| 195 | * |
| 196 | * Return Value: |
| 197 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 198 | * not exceed @size. |
| 199 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 200 | static int |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 201 | lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size) |
| 202 | { |
| 203 | int i, index, len, enable; |
| 204 | uint32_t ms; |
| 205 | struct lpfc_debugfs_trc *dtp; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 206 | char *buffer; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 207 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 208 | buffer = kmalloc(LPFC_DEBUG_TRC_ENTRY_SIZE, GFP_KERNEL); |
| 209 | if (!buffer) |
| 210 | return 0; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 211 | |
| 212 | enable = lpfc_debugfs_enable; |
| 213 | lpfc_debugfs_enable = 0; |
| 214 | |
| 215 | len = 0; |
| 216 | index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) & |
| 217 | (lpfc_debugfs_max_slow_ring_trc - 1); |
| 218 | for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) { |
| 219 | dtp = phba->slow_ring_trc + i; |
| 220 | if (!dtp->fmt) |
| 221 | continue; |
| 222 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
| 223 | snprintf(buffer, |
| 224 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
| 225 | dtp->seq_cnt, ms, dtp->fmt); |
| 226 | len += snprintf(buf+len, size-len, buffer, |
| 227 | dtp->data1, dtp->data2, dtp->data3); |
| 228 | } |
| 229 | for (i = 0; i < index; i++) { |
| 230 | dtp = phba->slow_ring_trc + i; |
| 231 | if (!dtp->fmt) |
| 232 | continue; |
| 233 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
| 234 | snprintf(buffer, |
| 235 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
| 236 | dtp->seq_cnt, ms, dtp->fmt); |
| 237 | len += snprintf(buf+len, size-len, buffer, |
| 238 | dtp->data1, dtp->data2, dtp->data3); |
| 239 | } |
| 240 | |
| 241 | lpfc_debugfs_enable = enable; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 242 | kfree(buffer); |
| 243 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 244 | return len; |
| 245 | } |
| 246 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 247 | static int lpfc_debugfs_last_hbq = -1; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 248 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 249 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 250 | * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 251 | * @phba: The HBA to gather host buffer info from. |
| 252 | * @buf: The buffer to dump log into. |
| 253 | * @size: The maximum amount of data to process. |
| 254 | * |
| 255 | * Description: |
| 256 | * This routine dumps the host buffer queue info from the @phba to @buf up to |
| 257 | * @size number of bytes. A header that describes the current hbq state will be |
| 258 | * dumped to @buf first and then info on each hbq entry will be dumped to @buf |
| 259 | * until @size bytes have been dumped or all the hbq info has been dumped. |
| 260 | * |
| 261 | * Notes: |
| 262 | * This routine will rotate through each configured HBQ each time called. |
| 263 | * |
| 264 | * Return Value: |
| 265 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 266 | * not exceed @size. |
| 267 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 268 | static int |
| 269 | lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size) |
| 270 | { |
| 271 | int len = 0; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 272 | int i, j, found, posted, low; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 273 | uint32_t phys, raw_index, getidx; |
| 274 | struct lpfc_hbq_init *hip; |
| 275 | struct hbq_s *hbqs; |
| 276 | struct lpfc_hbq_entry *hbqe; |
| 277 | struct lpfc_dmabuf *d_buf; |
| 278 | struct hbq_dmabuf *hbq_buf; |
| 279 | |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 280 | if (phba->sli_rev != 3) |
| 281 | return 0; |
James Smart | eb01656 | 2014-09-03 12:58:06 -0400 | [diff] [blame] | 282 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 283 | spin_lock_irq(&phba->hbalock); |
| 284 | |
| 285 | /* toggle between multiple hbqs, if any */ |
| 286 | i = lpfc_sli_hbq_count(); |
| 287 | if (i > 1) { |
| 288 | lpfc_debugfs_last_hbq++; |
| 289 | if (lpfc_debugfs_last_hbq >= i) |
| 290 | lpfc_debugfs_last_hbq = 0; |
| 291 | } |
| 292 | else |
| 293 | lpfc_debugfs_last_hbq = 0; |
| 294 | |
| 295 | i = lpfc_debugfs_last_hbq; |
| 296 | |
| 297 | len += snprintf(buf+len, size-len, "HBQ %d Info\n", i); |
| 298 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 299 | hbqs = &phba->hbqs[i]; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 300 | posted = 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 301 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 302 | posted++; |
| 303 | |
| 304 | hip = lpfc_hbq_defs[i]; |
| 305 | len += snprintf(buf+len, size-len, |
| 306 | "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n", |
| 307 | hip->hbq_index, hip->profile, hip->rn, |
| 308 | hip->buffer_count, hip->init_count, hip->add_count, posted); |
| 309 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 310 | raw_index = phba->hbq_get[i]; |
| 311 | getidx = le32_to_cpu(raw_index); |
| 312 | len += snprintf(buf+len, size-len, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 313 | "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n", |
| 314 | hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx, |
| 315 | hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 316 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 317 | hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 318 | for (j=0; j<hbqs->entry_count; j++) { |
| 319 | len += snprintf(buf+len, size-len, |
| 320 | "%03d: %08x %04x %05x ", j, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 321 | le32_to_cpu(hbqe->bde.addrLow), |
| 322 | le32_to_cpu(hbqe->bde.tus.w), |
| 323 | le32_to_cpu(hbqe->buffer_tag)); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 324 | i = 0; |
| 325 | found = 0; |
| 326 | |
| 327 | /* First calculate if slot has an associated posted buffer */ |
| 328 | low = hbqs->hbqPutIdx - posted; |
| 329 | if (low >= 0) { |
| 330 | if ((j >= hbqs->hbqPutIdx) || (j < low)) { |
| 331 | len += snprintf(buf+len, size-len, "Unused\n"); |
| 332 | goto skipit; |
| 333 | } |
| 334 | } |
| 335 | else { |
| 336 | if ((j >= hbqs->hbqPutIdx) && |
| 337 | (j < (hbqs->entry_count+low))) { |
| 338 | len += snprintf(buf+len, size-len, "Unused\n"); |
| 339 | goto skipit; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /* Get the Buffer info for the posted buffer */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 344 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 345 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 346 | phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 347 | if (phys == le32_to_cpu(hbqe->bde.addrLow)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 348 | len += snprintf(buf+len, size-len, |
| 349 | "Buf%d: %p %06x\n", i, |
| 350 | hbq_buf->dbuf.virt, hbq_buf->tag); |
| 351 | found = 1; |
| 352 | break; |
| 353 | } |
| 354 | i++; |
| 355 | } |
| 356 | if (!found) { |
| 357 | len += snprintf(buf+len, size-len, "No DMAinfo?\n"); |
| 358 | } |
| 359 | skipit: |
| 360 | hbqe++; |
| 361 | if (len > LPFC_HBQINFO_SIZE - 54) |
| 362 | break; |
| 363 | } |
| 364 | spin_unlock_irq(&phba->hbalock); |
| 365 | return len; |
| 366 | } |
| 367 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 368 | static int lpfc_debugfs_last_hba_slim_off; |
| 369 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 370 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 371 | * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 372 | * @phba: The HBA to gather SLIM info from. |
| 373 | * @buf: The buffer to dump log into. |
| 374 | * @size: The maximum amount of data to process. |
| 375 | * |
| 376 | * Description: |
| 377 | * This routine dumps the current contents of HBA SLIM for the HBA associated |
| 378 | * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data. |
| 379 | * |
| 380 | * Notes: |
| 381 | * This routine will only dump up to 1024 bytes of data each time called and |
| 382 | * should be called multiple times to dump the entire HBA SLIM. |
| 383 | * |
| 384 | * Return Value: |
| 385 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 386 | * not exceed @size. |
| 387 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 388 | static int |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 389 | lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 390 | { |
| 391 | int len = 0; |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 392 | int i, off; |
| 393 | uint32_t *ptr; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 394 | char *buffer; |
| 395 | |
| 396 | buffer = kmalloc(1024, GFP_KERNEL); |
| 397 | if (!buffer) |
| 398 | return 0; |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 399 | |
| 400 | off = 0; |
| 401 | spin_lock_irq(&phba->hbalock); |
| 402 | |
| 403 | len += snprintf(buf+len, size-len, "HBA SLIM\n"); |
| 404 | lpfc_memcpy_from_slim(buffer, |
James Smart | a257bf9 | 2009-04-06 18:48:10 -0400 | [diff] [blame] | 405 | phba->MBslimaddr + lpfc_debugfs_last_hba_slim_off, 1024); |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 406 | |
| 407 | ptr = (uint32_t *)&buffer[0]; |
| 408 | off = lpfc_debugfs_last_hba_slim_off; |
| 409 | |
| 410 | /* Set it up for the next time */ |
| 411 | lpfc_debugfs_last_hba_slim_off += 1024; |
| 412 | if (lpfc_debugfs_last_hba_slim_off >= 4096) |
| 413 | lpfc_debugfs_last_hba_slim_off = 0; |
| 414 | |
| 415 | i = 1024; |
| 416 | while (i > 0) { |
| 417 | len += snprintf(buf+len, size-len, |
| 418 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 419 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 420 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 421 | ptr += 8; |
| 422 | i -= (8 * sizeof(uint32_t)); |
| 423 | off += (8 * sizeof(uint32_t)); |
| 424 | } |
| 425 | |
| 426 | spin_unlock_irq(&phba->hbalock); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 427 | kfree(buffer); |
| 428 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 429 | return len; |
| 430 | } |
| 431 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 432 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 433 | * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 434 | * @phba: The HBA to gather Host SLIM info from. |
| 435 | * @buf: The buffer to dump log into. |
| 436 | * @size: The maximum amount of data to process. |
| 437 | * |
| 438 | * Description: |
| 439 | * This routine dumps the current contents of host SLIM for the host associated |
| 440 | * with @phba to @buf up to @size bytes of data. The dump will contain the |
| 441 | * Mailbox, PCB, Rings, and Registers that are located in host memory. |
| 442 | * |
| 443 | * Return Value: |
| 444 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 445 | * not exceed @size. |
| 446 | **/ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 447 | static int |
| 448 | lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size) |
| 449 | { |
| 450 | int len = 0; |
| 451 | int i, off; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 452 | uint32_t word0, word1, word2, word3; |
| 453 | uint32_t *ptr; |
| 454 | struct lpfc_pgp *pgpp; |
| 455 | struct lpfc_sli *psli = &phba->sli; |
| 456 | struct lpfc_sli_ring *pring; |
| 457 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 458 | off = 0; |
| 459 | spin_lock_irq(&phba->hbalock); |
| 460 | |
| 461 | len += snprintf(buf+len, size-len, "SLIM Mailbox\n"); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 462 | ptr = (uint32_t *)phba->slim2p.virt; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 463 | i = sizeof(MAILBOX_t); |
| 464 | while (i > 0) { |
| 465 | len += snprintf(buf+len, size-len, |
| 466 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 467 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 468 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 469 | ptr += 8; |
| 470 | i -= (8 * sizeof(uint32_t)); |
| 471 | off += (8 * sizeof(uint32_t)); |
| 472 | } |
| 473 | |
| 474 | len += snprintf(buf+len, size-len, "SLIM PCB\n"); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 475 | ptr = (uint32_t *)phba->pcb; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 476 | i = sizeof(PCB_t); |
| 477 | while (i > 0) { |
| 478 | len += snprintf(buf+len, size-len, |
| 479 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 480 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 481 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 482 | ptr += 8; |
| 483 | i -= (8 * sizeof(uint32_t)); |
| 484 | off += (8 * sizeof(uint32_t)); |
| 485 | } |
| 486 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 487 | for (i = 0; i < 4; i++) { |
| 488 | pgpp = &phba->port_gp[i]; |
| 489 | pring = &psli->ring[i]; |
| 490 | len += snprintf(buf+len, size-len, |
| 491 | "Ring %d: CMD GetInx:%d (Max:%d Next:%d " |
| 492 | "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n", |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 493 | i, pgpp->cmdGetInx, pring->sli.sli3.numCiocb, |
| 494 | pring->sli.sli3.next_cmdidx, |
| 495 | pring->sli.sli3.local_getidx, |
| 496 | pring->flag, pgpp->rspPutInx, |
| 497 | pring->sli.sli3.numRiocb); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 498 | } |
James Smart | 3772a99 | 2009-05-22 14:50:54 -0400 | [diff] [blame] | 499 | |
| 500 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
| 501 | word0 = readl(phba->HAregaddr); |
| 502 | word1 = readl(phba->CAregaddr); |
| 503 | word2 = readl(phba->HSregaddr); |
| 504 | word3 = readl(phba->HCregaddr); |
| 505 | len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x " |
| 506 | "HC:%08x\n", word0, word1, word2, word3); |
| 507 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 508 | spin_unlock_irq(&phba->hbalock); |
| 509 | return len; |
| 510 | } |
| 511 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 512 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 513 | * lpfc_debugfs_nodelist_data - Dump target node list to a buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 514 | * @vport: The vport to gather target node info from. |
| 515 | * @buf: The buffer to dump log into. |
| 516 | * @size: The maximum amount of data to process. |
| 517 | * |
| 518 | * Description: |
| 519 | * This routine dumps the current target node list associated with @vport to |
| 520 | * @buf up to @size bytes of data. Each node entry in the dump will contain a |
| 521 | * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields. |
| 522 | * |
| 523 | * Return Value: |
| 524 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 525 | * not exceed @size. |
| 526 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 527 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 528 | lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size) |
| 529 | { |
| 530 | int len = 0; |
| 531 | int cnt; |
| 532 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 533 | struct lpfc_nodelist *ndlp; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 534 | unsigned char *statep; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 535 | |
| 536 | cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE); |
| 537 | |
| 538 | spin_lock_irq(shost->host_lock); |
| 539 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 540 | if (!cnt) { |
| 541 | len += snprintf(buf+len, size-len, |
| 542 | "Missing Nodelist Entries\n"); |
| 543 | break; |
| 544 | } |
| 545 | cnt--; |
| 546 | switch (ndlp->nlp_state) { |
| 547 | case NLP_STE_UNUSED_NODE: |
| 548 | statep = "UNUSED"; |
| 549 | break; |
| 550 | case NLP_STE_PLOGI_ISSUE: |
| 551 | statep = "PLOGI "; |
| 552 | break; |
| 553 | case NLP_STE_ADISC_ISSUE: |
| 554 | statep = "ADISC "; |
| 555 | break; |
| 556 | case NLP_STE_REG_LOGIN_ISSUE: |
| 557 | statep = "REGLOG"; |
| 558 | break; |
| 559 | case NLP_STE_PRLI_ISSUE: |
| 560 | statep = "PRLI "; |
| 561 | break; |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 562 | case NLP_STE_LOGO_ISSUE: |
| 563 | statep = "LOGO "; |
| 564 | break; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 565 | case NLP_STE_UNMAPPED_NODE: |
| 566 | statep = "UNMAP "; |
| 567 | break; |
| 568 | case NLP_STE_MAPPED_NODE: |
| 569 | statep = "MAPPED"; |
| 570 | break; |
| 571 | case NLP_STE_NPR_NODE: |
| 572 | statep = "NPR "; |
| 573 | break; |
| 574 | default: |
| 575 | statep = "UNKNOWN"; |
| 576 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 577 | len += snprintf(buf+len, size-len, "%s DID:x%06x ", |
| 578 | statep, ndlp->nlp_DID); |
| 579 | len += snprintf(buf+len, size-len, |
| 580 | "WWPN x%llx ", |
| 581 | wwn_to_u64(ndlp->nlp_portname.u.wwn)); |
| 582 | len += snprintf(buf+len, size-len, |
| 583 | "WWNN x%llx ", |
| 584 | wwn_to_u64(ndlp->nlp_nodename.u.wwn)); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 585 | if (ndlp->nlp_flag & NLP_RPI_REGISTERED) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 586 | len += snprintf(buf+len, size-len, "RPI:%03d ", |
| 587 | ndlp->nlp_rpi); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 588 | else |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 589 | len += snprintf(buf+len, size-len, "RPI:none "); |
James Smart | 086a345 | 2012-08-14 14:25:21 -0400 | [diff] [blame] | 590 | len += snprintf(buf+len, size-len, "flag:x%08x ", |
| 591 | ndlp->nlp_flag); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 592 | if (!ndlp->nlp_type) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 593 | len += snprintf(buf+len, size-len, "UNKNOWN_TYPE "); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 594 | if (ndlp->nlp_type & NLP_FC_NODE) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 595 | len += snprintf(buf+len, size-len, "FC_NODE "); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 596 | if (ndlp->nlp_type & NLP_FABRIC) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 597 | len += snprintf(buf+len, size-len, "FABRIC "); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 598 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 599 | len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 600 | ndlp->nlp_sid); |
| 601 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 602 | len += snprintf(buf+len, size-len, "FCP_INITIATOR "); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 603 | len += snprintf(buf+len, size-len, "usgmap:%x ", |
| 604 | ndlp->nlp_usg_map); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 605 | len += snprintf(buf+len, size-len, "refcnt:%x", |
Peter Zijlstra | 2c935bc | 2016-11-14 17:29:48 +0100 | [diff] [blame] | 606 | kref_read(&ndlp->kref)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 607 | len += snprintf(buf+len, size-len, "\n"); |
| 608 | } |
| 609 | spin_unlock_irq(shost->host_lock); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 610 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 611 | return len; |
| 612 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 613 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 614 | #endif |
| 615 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 616 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 617 | * lpfc_debugfs_disc_trc - Store discovery trace log |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 618 | * @vport: The vport to associate this trace string with for retrieval. |
| 619 | * @mask: Log entry classification. |
| 620 | * @fmt: Format string to be displayed when dumping the log. |
| 621 | * @data1: 1st data parameter to be applied to @fmt. |
| 622 | * @data2: 2nd data parameter to be applied to @fmt. |
| 623 | * @data3: 3rd data parameter to be applied to @fmt. |
| 624 | * |
| 625 | * Description: |
| 626 | * This routine is used by the driver code to add a debugfs log entry to the |
| 627 | * discovery trace buffer associated with @vport. Only entries with a @mask that |
| 628 | * match the current debugfs discovery mask will be saved. Entries that do not |
| 629 | * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like |
| 630 | * printf when displaying the log. |
| 631 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 632 | inline void |
| 633 | lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt, |
| 634 | uint32_t data1, uint32_t data2, uint32_t data3) |
| 635 | { |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 636 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 637 | struct lpfc_debugfs_trc *dtp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 638 | int index; |
| 639 | |
| 640 | if (!(lpfc_debugfs_mask_disc_trc & mask)) |
| 641 | return; |
| 642 | |
| 643 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc || |
| 644 | !vport || !vport->disc_trc) |
| 645 | return; |
| 646 | |
| 647 | index = atomic_inc_return(&vport->disc_trc_cnt) & |
| 648 | (lpfc_debugfs_max_disc_trc - 1); |
| 649 | dtp = vport->disc_trc + index; |
| 650 | dtp->fmt = fmt; |
| 651 | dtp->data1 = data1; |
| 652 | dtp->data2 = data2; |
| 653 | dtp->data3 = data3; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 654 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); |
| 655 | dtp->jif = jiffies; |
| 656 | #endif |
| 657 | return; |
| 658 | } |
| 659 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 660 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 661 | * lpfc_debugfs_slow_ring_trc - Store slow ring trace log |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 662 | * @phba: The phba to associate this trace string with for retrieval. |
| 663 | * @fmt: Format string to be displayed when dumping the log. |
| 664 | * @data1: 1st data parameter to be applied to @fmt. |
| 665 | * @data2: 2nd data parameter to be applied to @fmt. |
| 666 | * @data3: 3rd data parameter to be applied to @fmt. |
| 667 | * |
| 668 | * Description: |
| 669 | * This routine is used by the driver code to add a debugfs log entry to the |
| 670 | * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and |
| 671 | * @data3 are used like printf when displaying the log. |
| 672 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 673 | inline void |
| 674 | lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt, |
| 675 | uint32_t data1, uint32_t data2, uint32_t data3) |
| 676 | { |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 677 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 678 | struct lpfc_debugfs_trc *dtp; |
| 679 | int index; |
| 680 | |
| 681 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc || |
| 682 | !phba || !phba->slow_ring_trc) |
| 683 | return; |
| 684 | |
| 685 | index = atomic_inc_return(&phba->slow_ring_trc_cnt) & |
| 686 | (lpfc_debugfs_max_slow_ring_trc - 1); |
| 687 | dtp = phba->slow_ring_trc + index; |
| 688 | dtp->fmt = fmt; |
| 689 | dtp->data1 = data1; |
| 690 | dtp->data2 = data2; |
| 691 | dtp->data3 = data3; |
| 692 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 693 | dtp->jif = jiffies; |
| 694 | #endif |
| 695 | return; |
| 696 | } |
| 697 | |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 698 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 699 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 700 | * lpfc_debugfs_disc_trc_open - Open the discovery trace log |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 701 | * @inode: The inode pointer that contains a vport pointer. |
| 702 | * @file: The file pointer to attach the log output. |
| 703 | * |
| 704 | * Description: |
| 705 | * This routine is the entry point for the debugfs open file operation. It gets |
| 706 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 707 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 708 | * returns a pointer to that log in the private_data field in @file. |
| 709 | * |
| 710 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 711 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 712 | * error value. |
| 713 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 714 | static int |
| 715 | lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file) |
| 716 | { |
| 717 | struct lpfc_vport *vport = inode->i_private; |
| 718 | struct lpfc_debug *debug; |
| 719 | int size; |
| 720 | int rc = -ENOMEM; |
| 721 | |
| 722 | if (!lpfc_debugfs_max_disc_trc) { |
| 723 | rc = -ENOSPC; |
| 724 | goto out; |
| 725 | } |
| 726 | |
| 727 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 728 | if (!debug) |
| 729 | goto out; |
| 730 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 731 | /* Round to page boundary */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 732 | size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 733 | size = PAGE_ALIGN(size); |
| 734 | |
| 735 | debug->buffer = kmalloc(size, GFP_KERNEL); |
| 736 | if (!debug->buffer) { |
| 737 | kfree(debug); |
| 738 | goto out; |
| 739 | } |
| 740 | |
| 741 | debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size); |
| 742 | file->private_data = debug; |
| 743 | |
| 744 | rc = 0; |
| 745 | out: |
| 746 | return rc; |
| 747 | } |
| 748 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 749 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 750 | * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 751 | * @inode: The inode pointer that contains a vport pointer. |
| 752 | * @file: The file pointer to attach the log output. |
| 753 | * |
| 754 | * Description: |
| 755 | * This routine is the entry point for the debugfs open file operation. It gets |
| 756 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 757 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 758 | * returns a pointer to that log in the private_data field in @file. |
| 759 | * |
| 760 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 761 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 762 | * error value. |
| 763 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 764 | static int |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 765 | lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file) |
| 766 | { |
| 767 | struct lpfc_hba *phba = inode->i_private; |
| 768 | struct lpfc_debug *debug; |
| 769 | int size; |
| 770 | int rc = -ENOMEM; |
| 771 | |
| 772 | if (!lpfc_debugfs_max_slow_ring_trc) { |
| 773 | rc = -ENOSPC; |
| 774 | goto out; |
| 775 | } |
| 776 | |
| 777 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 778 | if (!debug) |
| 779 | goto out; |
| 780 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 781 | /* Round to page boundary */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 782 | size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
| 783 | size = PAGE_ALIGN(size); |
| 784 | |
| 785 | debug->buffer = kmalloc(size, GFP_KERNEL); |
| 786 | if (!debug->buffer) { |
| 787 | kfree(debug); |
| 788 | goto out; |
| 789 | } |
| 790 | |
| 791 | debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size); |
| 792 | file->private_data = debug; |
| 793 | |
| 794 | rc = 0; |
| 795 | out: |
| 796 | return rc; |
| 797 | } |
| 798 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 799 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 800 | * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 801 | * @inode: The inode pointer that contains a vport pointer. |
| 802 | * @file: The file pointer to attach the log output. |
| 803 | * |
| 804 | * Description: |
| 805 | * This routine is the entry point for the debugfs open file operation. It gets |
| 806 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 807 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 808 | * returns a pointer to that log in the private_data field in @file. |
| 809 | * |
| 810 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 811 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 812 | * error value. |
| 813 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 814 | static int |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 815 | lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file) |
| 816 | { |
| 817 | struct lpfc_hba *phba = inode->i_private; |
| 818 | struct lpfc_debug *debug; |
| 819 | int rc = -ENOMEM; |
| 820 | |
| 821 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 822 | if (!debug) |
| 823 | goto out; |
| 824 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 825 | /* Round to page boundary */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 826 | debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); |
| 827 | if (!debug->buffer) { |
| 828 | kfree(debug); |
| 829 | goto out; |
| 830 | } |
| 831 | |
| 832 | debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer, |
| 833 | LPFC_HBQINFO_SIZE); |
| 834 | file->private_data = debug; |
| 835 | |
| 836 | rc = 0; |
| 837 | out: |
| 838 | return rc; |
| 839 | } |
| 840 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 841 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 842 | * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 843 | * @inode: The inode pointer that contains a vport pointer. |
| 844 | * @file: The file pointer to attach the log output. |
| 845 | * |
| 846 | * Description: |
| 847 | * This routine is the entry point for the debugfs open file operation. It gets |
| 848 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 849 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 850 | * returns a pointer to that log in the private_data field in @file. |
| 851 | * |
| 852 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 853 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 854 | * error value. |
| 855 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 856 | static int |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 857 | lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 858 | { |
| 859 | struct lpfc_hba *phba = inode->i_private; |
| 860 | struct lpfc_debug *debug; |
| 861 | int rc = -ENOMEM; |
| 862 | |
| 863 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 864 | if (!debug) |
| 865 | goto out; |
| 866 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 867 | /* Round to page boundary */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 868 | debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 869 | if (!debug->buffer) { |
| 870 | kfree(debug); |
| 871 | goto out; |
| 872 | } |
| 873 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 874 | debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer, |
| 875 | LPFC_DUMPHBASLIM_SIZE); |
| 876 | file->private_data = debug; |
| 877 | |
| 878 | rc = 0; |
| 879 | out: |
| 880 | return rc; |
| 881 | } |
| 882 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 883 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 884 | * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 885 | * @inode: The inode pointer that contains a vport pointer. |
| 886 | * @file: The file pointer to attach the log output. |
| 887 | * |
| 888 | * Description: |
| 889 | * This routine is the entry point for the debugfs open file operation. It gets |
| 890 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 891 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 892 | * returns a pointer to that log in the private_data field in @file. |
| 893 | * |
| 894 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 895 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 896 | * error value. |
| 897 | **/ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 898 | static int |
| 899 | lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file) |
| 900 | { |
| 901 | struct lpfc_hba *phba = inode->i_private; |
| 902 | struct lpfc_debug *debug; |
| 903 | int rc = -ENOMEM; |
| 904 | |
| 905 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 906 | if (!debug) |
| 907 | goto out; |
| 908 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 909 | /* Round to page boundary */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 910 | debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL); |
| 911 | if (!debug->buffer) { |
| 912 | kfree(debug); |
| 913 | goto out; |
| 914 | } |
| 915 | |
| 916 | debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer, |
| 917 | LPFC_DUMPHOSTSLIM_SIZE); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 918 | file->private_data = debug; |
| 919 | |
| 920 | rc = 0; |
| 921 | out: |
| 922 | return rc; |
| 923 | } |
| 924 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 925 | static int |
| 926 | lpfc_debugfs_dumpData_open(struct inode *inode, struct file *file) |
| 927 | { |
| 928 | struct lpfc_debug *debug; |
| 929 | int rc = -ENOMEM; |
| 930 | |
| 931 | if (!_dump_buf_data) |
| 932 | return -EBUSY; |
| 933 | |
| 934 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 935 | if (!debug) |
| 936 | goto out; |
| 937 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 938 | /* Round to page boundary */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 939 | pr_err("9059 BLKGRD: %s: _dump_buf_data=0x%p\n", |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 940 | __func__, _dump_buf_data); |
| 941 | debug->buffer = _dump_buf_data; |
| 942 | if (!debug->buffer) { |
| 943 | kfree(debug); |
| 944 | goto out; |
| 945 | } |
| 946 | |
| 947 | debug->len = (1 << _dump_buf_data_order) << PAGE_SHIFT; |
| 948 | file->private_data = debug; |
| 949 | |
| 950 | rc = 0; |
| 951 | out: |
| 952 | return rc; |
| 953 | } |
| 954 | |
| 955 | static int |
| 956 | lpfc_debugfs_dumpDif_open(struct inode *inode, struct file *file) |
| 957 | { |
| 958 | struct lpfc_debug *debug; |
| 959 | int rc = -ENOMEM; |
| 960 | |
| 961 | if (!_dump_buf_dif) |
| 962 | return -EBUSY; |
| 963 | |
| 964 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 965 | if (!debug) |
| 966 | goto out; |
| 967 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 968 | /* Round to page boundary */ |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 969 | pr_err("9060 BLKGRD: %s: _dump_buf_dif=0x%p file=%pD\n", |
| 970 | __func__, _dump_buf_dif, file); |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 971 | debug->buffer = _dump_buf_dif; |
| 972 | if (!debug->buffer) { |
| 973 | kfree(debug); |
| 974 | goto out; |
| 975 | } |
| 976 | |
| 977 | debug->len = (1 << _dump_buf_dif_order) << PAGE_SHIFT; |
| 978 | file->private_data = debug; |
| 979 | |
| 980 | rc = 0; |
| 981 | out: |
| 982 | return rc; |
| 983 | } |
| 984 | |
| 985 | static ssize_t |
| 986 | lpfc_debugfs_dumpDataDif_write(struct file *file, const char __user *buf, |
| 987 | size_t nbytes, loff_t *ppos) |
| 988 | { |
| 989 | /* |
| 990 | * The Data/DIF buffers only save one failing IO |
| 991 | * The write op is used as a reset mechanism after an IO has |
| 992 | * already been saved to the next one can be saved |
| 993 | */ |
| 994 | spin_lock(&_dump_buf_lock); |
| 995 | |
| 996 | memset((void *)_dump_buf_data, 0, |
| 997 | ((1 << PAGE_SHIFT) << _dump_buf_data_order)); |
| 998 | memset((void *)_dump_buf_dif, 0, |
| 999 | ((1 << PAGE_SHIFT) << _dump_buf_dif_order)); |
| 1000 | |
| 1001 | _dump_buf_done = 0; |
| 1002 | |
| 1003 | spin_unlock(&_dump_buf_lock); |
| 1004 | |
| 1005 | return nbytes; |
| 1006 | } |
| 1007 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1008 | static ssize_t |
| 1009 | lpfc_debugfs_dif_err_read(struct file *file, char __user *buf, |
| 1010 | size_t nbytes, loff_t *ppos) |
| 1011 | { |
Al Viro | b583043 | 2014-10-31 01:22:04 -0400 | [diff] [blame] | 1012 | struct dentry *dent = file->f_path.dentry; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1013 | struct lpfc_hba *phba = file->private_data; |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1014 | char cbuf[32]; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1015 | uint64_t tmp = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1016 | int cnt = 0; |
| 1017 | |
| 1018 | if (dent == phba->debug_writeGuard) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1019 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wgrd_cnt); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1020 | else if (dent == phba->debug_writeApp) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1021 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wapp_cnt); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1022 | else if (dent == phba->debug_writeRef) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1023 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_wref_cnt); |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1024 | else if (dent == phba->debug_readGuard) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1025 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rgrd_cnt); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1026 | else if (dent == phba->debug_readApp) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1027 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rapp_cnt); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1028 | else if (dent == phba->debug_readRef) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1029 | cnt = snprintf(cbuf, 32, "%u\n", phba->lpfc_injerr_rref_cnt); |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1030 | else if (dent == phba->debug_InjErrNPortID) |
| 1031 | cnt = snprintf(cbuf, 32, "0x%06x\n", phba->lpfc_injerr_nportid); |
| 1032 | else if (dent == phba->debug_InjErrWWPN) { |
| 1033 | memcpy(&tmp, &phba->lpfc_injerr_wwpn, sizeof(struct lpfc_name)); |
| 1034 | tmp = cpu_to_be64(tmp); |
| 1035 | cnt = snprintf(cbuf, 32, "0x%016llx\n", tmp); |
| 1036 | } else if (dent == phba->debug_InjErrLBA) { |
| 1037 | if (phba->lpfc_injerr_lba == (sector_t)(-1)) |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1038 | cnt = snprintf(cbuf, 32, "off\n"); |
| 1039 | else |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1040 | cnt = snprintf(cbuf, 32, "0x%llx\n", |
| 1041 | (uint64_t) phba->lpfc_injerr_lba); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1042 | } else |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1043 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1044 | "0547 Unknown debugfs error injection entry\n"); |
| 1045 | |
| 1046 | return simple_read_from_buffer(buf, nbytes, ppos, &cbuf, cnt); |
| 1047 | } |
| 1048 | |
| 1049 | static ssize_t |
| 1050 | lpfc_debugfs_dif_err_write(struct file *file, const char __user *buf, |
| 1051 | size_t nbytes, loff_t *ppos) |
| 1052 | { |
Al Viro | b583043 | 2014-10-31 01:22:04 -0400 | [diff] [blame] | 1053 | struct dentry *dent = file->f_path.dentry; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1054 | struct lpfc_hba *phba = file->private_data; |
Alan | 0872774d | 2016-02-15 19:11:56 +0000 | [diff] [blame] | 1055 | char dstbuf[33]; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1056 | uint64_t tmp = 0; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1057 | int size; |
| 1058 | |
Alan | 0872774d | 2016-02-15 19:11:56 +0000 | [diff] [blame] | 1059 | memset(dstbuf, 0, 33); |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1060 | size = (nbytes < 32) ? nbytes : 32; |
| 1061 | if (copy_from_user(dstbuf, buf, size)) |
| 1062 | return 0; |
| 1063 | |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1064 | if (dent == phba->debug_InjErrLBA) { |
| 1065 | if ((buf[0] == 'o') && (buf[1] == 'f') && (buf[2] == 'f')) |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1066 | tmp = (uint64_t)(-1); |
James Smart | 9a6b09c | 2012-03-01 22:37:42 -0500 | [diff] [blame] | 1067 | } |
| 1068 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1069 | if ((tmp == 0) && (kstrtoull(dstbuf, 0, &tmp))) |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1070 | return 0; |
| 1071 | |
| 1072 | if (dent == phba->debug_writeGuard) |
| 1073 | phba->lpfc_injerr_wgrd_cnt = (uint32_t)tmp; |
| 1074 | else if (dent == phba->debug_writeApp) |
| 1075 | phba->lpfc_injerr_wapp_cnt = (uint32_t)tmp; |
| 1076 | else if (dent == phba->debug_writeRef) |
| 1077 | phba->lpfc_injerr_wref_cnt = (uint32_t)tmp; |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 1078 | else if (dent == phba->debug_readGuard) |
| 1079 | phba->lpfc_injerr_rgrd_cnt = (uint32_t)tmp; |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1080 | else if (dent == phba->debug_readApp) |
| 1081 | phba->lpfc_injerr_rapp_cnt = (uint32_t)tmp; |
| 1082 | else if (dent == phba->debug_readRef) |
| 1083 | phba->lpfc_injerr_rref_cnt = (uint32_t)tmp; |
| 1084 | else if (dent == phba->debug_InjErrLBA) |
| 1085 | phba->lpfc_injerr_lba = (sector_t)tmp; |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 1086 | else if (dent == phba->debug_InjErrNPortID) |
| 1087 | phba->lpfc_injerr_nportid = (uint32_t)(tmp & Mask_DID); |
| 1088 | else if (dent == phba->debug_InjErrWWPN) { |
| 1089 | tmp = cpu_to_be64(tmp); |
| 1090 | memcpy(&phba->lpfc_injerr_wwpn, &tmp, sizeof(struct lpfc_name)); |
| 1091 | } else |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 1092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 1093 | "0548 Unknown debugfs error injection entry\n"); |
| 1094 | |
| 1095 | return nbytes; |
| 1096 | } |
| 1097 | |
| 1098 | static int |
| 1099 | lpfc_debugfs_dif_err_release(struct inode *inode, struct file *file) |
| 1100 | { |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1104 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1105 | * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1106 | * @inode: The inode pointer that contains a vport pointer. |
| 1107 | * @file: The file pointer to attach the log output. |
| 1108 | * |
| 1109 | * Description: |
| 1110 | * This routine is the entry point for the debugfs open file operation. It gets |
| 1111 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 1112 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 1113 | * returns a pointer to that log in the private_data field in @file. |
| 1114 | * |
| 1115 | * Returns: |
Geert Uytterhoeven | 79ce48d | 2015-05-21 14:11:33 +0200 | [diff] [blame] | 1116 | * This function returns zero if successful. On error it will return a negative |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1117 | * error value. |
| 1118 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1119 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1120 | lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file) |
| 1121 | { |
| 1122 | struct lpfc_vport *vport = inode->i_private; |
| 1123 | struct lpfc_debug *debug; |
| 1124 | int rc = -ENOMEM; |
| 1125 | |
| 1126 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 1127 | if (!debug) |
| 1128 | goto out; |
| 1129 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1130 | /* Round to page boundary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1131 | debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); |
| 1132 | if (!debug->buffer) { |
| 1133 | kfree(debug); |
| 1134 | goto out; |
| 1135 | } |
| 1136 | |
| 1137 | debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer, |
| 1138 | LPFC_NODELIST_SIZE); |
| 1139 | file->private_data = debug; |
| 1140 | |
| 1141 | rc = 0; |
| 1142 | out: |
| 1143 | return rc; |
| 1144 | } |
| 1145 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1146 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1147 | * lpfc_debugfs_lseek - Seek through a debugfs file |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1148 | * @file: The file pointer to seek through. |
| 1149 | * @off: The offset to seek to or the amount to seek by. |
| 1150 | * @whence: Indicates how to seek. |
| 1151 | * |
| 1152 | * Description: |
| 1153 | * This routine is the entry point for the debugfs lseek file operation. The |
| 1154 | * @whence parameter indicates whether @off is the offset to directly seek to, |
| 1155 | * or if it is a value to seek forward or reverse by. This function figures out |
| 1156 | * what the new offset of the debugfs file will be and assigns that value to the |
| 1157 | * f_pos field of @file. |
| 1158 | * |
| 1159 | * Returns: |
| 1160 | * This function returns the new offset if successful and returns a negative |
| 1161 | * error if unable to process the seek. |
| 1162 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1163 | static loff_t |
| 1164 | lpfc_debugfs_lseek(struct file *file, loff_t off, int whence) |
| 1165 | { |
Al Viro | 7233c77 | 2013-06-23 12:08:05 +0400 | [diff] [blame] | 1166 | struct lpfc_debug *debug = file->private_data; |
| 1167 | return fixed_size_llseek(file, off, whence, debug->len); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1168 | } |
| 1169 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1170 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1171 | * lpfc_debugfs_read - Read a debugfs file |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1172 | * @file: The file pointer to read from. |
| 1173 | * @buf: The buffer to copy the data to. |
| 1174 | * @nbytes: The number of bytes to read. |
| 1175 | * @ppos: The position in the file to start reading from. |
| 1176 | * |
| 1177 | * Description: |
| 1178 | * This routine reads data from from the buffer indicated in the private_data |
| 1179 | * field of @file. It will start reading at @ppos and copy up to @nbytes of |
| 1180 | * data to @buf. |
| 1181 | * |
| 1182 | * Returns: |
| 1183 | * This function returns the amount of data that was read (this could be less |
| 1184 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 1185 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1186 | static ssize_t |
| 1187 | lpfc_debugfs_read(struct file *file, char __user *buf, |
| 1188 | size_t nbytes, loff_t *ppos) |
| 1189 | { |
| 1190 | struct lpfc_debug *debug = file->private_data; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1191 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1192 | return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, |
| 1193 | debug->len); |
| 1194 | } |
| 1195 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1196 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1197 | * lpfc_debugfs_release - Release the buffer used to store debugfs file data |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1198 | * @inode: The inode pointer that contains a vport pointer. (unused) |
| 1199 | * @file: The file pointer that contains the buffer to release. |
| 1200 | * |
| 1201 | * Description: |
| 1202 | * This routine frees the buffer that was allocated when the debugfs file was |
| 1203 | * opened. |
| 1204 | * |
| 1205 | * Returns: |
| 1206 | * This function returns zero. |
| 1207 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1208 | static int |
| 1209 | lpfc_debugfs_release(struct inode *inode, struct file *file) |
| 1210 | { |
| 1211 | struct lpfc_debug *debug = file->private_data; |
| 1212 | |
| 1213 | kfree(debug->buffer); |
| 1214 | kfree(debug); |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1219 | static int |
| 1220 | lpfc_debugfs_dumpDataDif_release(struct inode *inode, struct file *file) |
| 1221 | { |
| 1222 | struct lpfc_debug *debug = file->private_data; |
| 1223 | |
| 1224 | debug->buffer = NULL; |
| 1225 | kfree(debug); |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1230 | /* |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1231 | * --------------------------------- |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1232 | * iDiag debugfs file access methods |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1233 | * --------------------------------- |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1234 | * |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1235 | * All access methods are through the proper SLI4 PCI function's debugfs |
| 1236 | * iDiag directory: |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1237 | * |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1238 | * /sys/kernel/debug/lpfc/fn<#>/iDiag |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1239 | */ |
| 1240 | |
| 1241 | /** |
| 1242 | * lpfc_idiag_cmd_get - Get and parse idiag debugfs comands from user space |
| 1243 | * @buf: The pointer to the user space buffer. |
| 1244 | * @nbytes: The number of bytes in the user space buffer. |
| 1245 | * @idiag_cmd: pointer to the idiag command struct. |
| 1246 | * |
| 1247 | * This routine reads data from debugfs user space buffer and parses the |
| 1248 | * buffer for getting the idiag command and arguments. The while space in |
| 1249 | * between the set of data is used as the parsing separator. |
| 1250 | * |
| 1251 | * This routine returns 0 when successful, it returns proper error code |
| 1252 | * back to the user space in error conditions. |
| 1253 | */ |
| 1254 | static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes, |
| 1255 | struct lpfc_idiag_cmd *idiag_cmd) |
| 1256 | { |
| 1257 | char mybuf[64]; |
| 1258 | char *pbuf, *step_str; |
Stephen Boyd | b11d48e | 2011-05-12 16:50:06 -0700 | [diff] [blame] | 1259 | int i; |
| 1260 | size_t bsize; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1261 | |
| 1262 | /* Protect copy from user */ |
| 1263 | if (!access_ok(VERIFY_READ, buf, nbytes)) |
| 1264 | return -EFAULT; |
| 1265 | |
| 1266 | memset(mybuf, 0, sizeof(mybuf)); |
| 1267 | memset(idiag_cmd, 0, sizeof(*idiag_cmd)); |
| 1268 | bsize = min(nbytes, (sizeof(mybuf)-1)); |
| 1269 | |
| 1270 | if (copy_from_user(mybuf, buf, bsize)) |
| 1271 | return -EFAULT; |
| 1272 | pbuf = &mybuf[0]; |
| 1273 | step_str = strsep(&pbuf, "\t "); |
| 1274 | |
| 1275 | /* The opcode must present */ |
| 1276 | if (!step_str) |
| 1277 | return -EINVAL; |
| 1278 | |
| 1279 | idiag_cmd->opcode = simple_strtol(step_str, NULL, 0); |
| 1280 | if (idiag_cmd->opcode == 0) |
| 1281 | return -EINVAL; |
| 1282 | |
| 1283 | for (i = 0; i < LPFC_IDIAG_CMD_DATA_SIZE; i++) { |
| 1284 | step_str = strsep(&pbuf, "\t "); |
| 1285 | if (!step_str) |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1286 | return i; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1287 | idiag_cmd->data[i] = simple_strtol(step_str, NULL, 0); |
| 1288 | } |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1289 | return i; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * lpfc_idiag_open - idiag open debugfs |
| 1294 | * @inode: The inode pointer that contains a pointer to phba. |
| 1295 | * @file: The file pointer to attach the file operation. |
| 1296 | * |
| 1297 | * Description: |
| 1298 | * This routine is the entry point for the debugfs open file operation. It |
| 1299 | * gets the reference to phba from the i_private field in @inode, it then |
| 1300 | * allocates buffer for the file operation, performs the necessary PCI config |
| 1301 | * space read into the allocated buffer according to the idiag user command |
| 1302 | * setup, and then returns a pointer to buffer in the private_data field in |
| 1303 | * @file. |
| 1304 | * |
| 1305 | * Returns: |
| 1306 | * This function returns zero if successful. On error it will return an |
| 1307 | * negative error value. |
| 1308 | **/ |
| 1309 | static int |
| 1310 | lpfc_idiag_open(struct inode *inode, struct file *file) |
| 1311 | { |
| 1312 | struct lpfc_debug *debug; |
| 1313 | |
| 1314 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 1315 | if (!debug) |
| 1316 | return -ENOMEM; |
| 1317 | |
| 1318 | debug->i_private = inode->i_private; |
| 1319 | debug->buffer = NULL; |
| 1320 | file->private_data = debug; |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * lpfc_idiag_release - Release idiag access file operation |
| 1327 | * @inode: The inode pointer that contains a vport pointer. (unused) |
| 1328 | * @file: The file pointer that contains the buffer to release. |
| 1329 | * |
| 1330 | * Description: |
| 1331 | * This routine is the generic release routine for the idiag access file |
| 1332 | * operation, it frees the buffer that was allocated when the debugfs file |
| 1333 | * was opened. |
| 1334 | * |
| 1335 | * Returns: |
| 1336 | * This function returns zero. |
| 1337 | **/ |
| 1338 | static int |
| 1339 | lpfc_idiag_release(struct inode *inode, struct file *file) |
| 1340 | { |
| 1341 | struct lpfc_debug *debug = file->private_data; |
| 1342 | |
| 1343 | /* Free the buffers to the file operation */ |
| 1344 | kfree(debug->buffer); |
| 1345 | kfree(debug); |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * lpfc_idiag_cmd_release - Release idiag cmd access file operation |
| 1352 | * @inode: The inode pointer that contains a vport pointer. (unused) |
| 1353 | * @file: The file pointer that contains the buffer to release. |
| 1354 | * |
| 1355 | * Description: |
| 1356 | * This routine frees the buffer that was allocated when the debugfs file |
| 1357 | * was opened. It also reset the fields in the idiag command struct in the |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1358 | * case of command for write operation. |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1359 | * |
| 1360 | * Returns: |
| 1361 | * This function returns zero. |
| 1362 | **/ |
| 1363 | static int |
| 1364 | lpfc_idiag_cmd_release(struct inode *inode, struct file *file) |
| 1365 | { |
| 1366 | struct lpfc_debug *debug = file->private_data; |
| 1367 | |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1368 | if (debug->op == LPFC_IDIAG_OP_WR) { |
| 1369 | switch (idiag.cmd.opcode) { |
| 1370 | case LPFC_IDIAG_CMD_PCICFG_WR: |
| 1371 | case LPFC_IDIAG_CMD_PCICFG_ST: |
| 1372 | case LPFC_IDIAG_CMD_PCICFG_CL: |
| 1373 | case LPFC_IDIAG_CMD_QUEACC_WR: |
| 1374 | case LPFC_IDIAG_CMD_QUEACC_ST: |
| 1375 | case LPFC_IDIAG_CMD_QUEACC_CL: |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1376 | memset(&idiag, 0, sizeof(idiag)); |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1377 | break; |
| 1378 | default: |
| 1379 | break; |
| 1380 | } |
| 1381 | } |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1382 | |
| 1383 | /* Free the buffers to the file operation */ |
| 1384 | kfree(debug->buffer); |
| 1385 | kfree(debug); |
| 1386 | |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * lpfc_idiag_pcicfg_read - idiag debugfs read pcicfg |
| 1392 | * @file: The file pointer to read from. |
| 1393 | * @buf: The buffer to copy the data to. |
| 1394 | * @nbytes: The number of bytes to read. |
| 1395 | * @ppos: The position in the file to start reading from. |
| 1396 | * |
| 1397 | * Description: |
| 1398 | * This routine reads data from the @phba pci config space according to the |
| 1399 | * idiag command, and copies to user @buf. Depending on the PCI config space |
| 1400 | * read command setup, it does either a single register read of a byte |
| 1401 | * (8 bits), a word (16 bits), or a dword (32 bits) or browsing through all |
| 1402 | * registers from the 4K extended PCI config space. |
| 1403 | * |
| 1404 | * Returns: |
| 1405 | * This function returns the amount of data that was read (this could be less |
| 1406 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 1407 | **/ |
| 1408 | static ssize_t |
| 1409 | lpfc_idiag_pcicfg_read(struct file *file, char __user *buf, size_t nbytes, |
| 1410 | loff_t *ppos) |
| 1411 | { |
| 1412 | struct lpfc_debug *debug = file->private_data; |
| 1413 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 1414 | int offset_label, offset, len = 0, index = LPFC_PCI_CFG_RD_SIZE; |
| 1415 | int where, count; |
| 1416 | char *pbuffer; |
| 1417 | struct pci_dev *pdev; |
| 1418 | uint32_t u32val; |
| 1419 | uint16_t u16val; |
| 1420 | uint8_t u8val; |
| 1421 | |
| 1422 | pdev = phba->pcidev; |
| 1423 | if (!pdev) |
| 1424 | return 0; |
| 1425 | |
| 1426 | /* This is a user read operation */ |
| 1427 | debug->op = LPFC_IDIAG_OP_RD; |
| 1428 | |
| 1429 | if (!debug->buffer) |
| 1430 | debug->buffer = kmalloc(LPFC_PCI_CFG_SIZE, GFP_KERNEL); |
| 1431 | if (!debug->buffer) |
| 1432 | return 0; |
| 1433 | pbuffer = debug->buffer; |
| 1434 | |
| 1435 | if (*ppos) |
| 1436 | return 0; |
| 1437 | |
| 1438 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) { |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1439 | where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX]; |
| 1440 | count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX]; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1441 | } else |
| 1442 | return 0; |
| 1443 | |
| 1444 | /* Read single PCI config space register */ |
| 1445 | switch (count) { |
| 1446 | case SIZE_U8: /* byte (8 bits) */ |
| 1447 | pci_read_config_byte(pdev, where, &u8val); |
| 1448 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1449 | "%03x: %02x\n", where, u8val); |
| 1450 | break; |
| 1451 | case SIZE_U16: /* word (16 bits) */ |
| 1452 | pci_read_config_word(pdev, where, &u16val); |
| 1453 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1454 | "%03x: %04x\n", where, u16val); |
| 1455 | break; |
| 1456 | case SIZE_U32: /* double word (32 bits) */ |
| 1457 | pci_read_config_dword(pdev, where, &u32val); |
| 1458 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1459 | "%03x: %08x\n", where, u32val); |
| 1460 | break; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1461 | case LPFC_PCI_CFG_BROWSE: /* browse all */ |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1462 | goto pcicfg_browse; |
| 1463 | break; |
| 1464 | default: |
| 1465 | /* illegal count */ |
| 1466 | len = 0; |
| 1467 | break; |
| 1468 | } |
| 1469 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 1470 | |
| 1471 | pcicfg_browse: |
| 1472 | |
| 1473 | /* Browse all PCI config space registers */ |
| 1474 | offset_label = idiag.offset.last_rd; |
| 1475 | offset = offset_label; |
| 1476 | |
| 1477 | /* Read PCI config space */ |
| 1478 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1479 | "%03x: ", offset_label); |
| 1480 | while (index > 0) { |
| 1481 | pci_read_config_dword(pdev, offset, &u32val); |
| 1482 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1483 | "%08x ", u32val); |
| 1484 | offset += sizeof(uint32_t); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1485 | if (offset >= LPFC_PCI_CFG_SIZE) { |
| 1486 | len += snprintf(pbuffer+len, |
| 1487 | LPFC_PCI_CFG_SIZE-len, "\n"); |
| 1488 | break; |
| 1489 | } |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1490 | index -= sizeof(uint32_t); |
| 1491 | if (!index) |
| 1492 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1493 | "\n"); |
| 1494 | else if (!(index % (8 * sizeof(uint32_t)))) { |
| 1495 | offset_label += (8 * sizeof(uint32_t)); |
| 1496 | len += snprintf(pbuffer+len, LPFC_PCI_CFG_SIZE-len, |
| 1497 | "\n%03x: ", offset_label); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | /* Set up the offset for next portion of pci cfg read */ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1502 | if (index == 0) { |
| 1503 | idiag.offset.last_rd += LPFC_PCI_CFG_RD_SIZE; |
| 1504 | if (idiag.offset.last_rd >= LPFC_PCI_CFG_SIZE) |
| 1505 | idiag.offset.last_rd = 0; |
| 1506 | } else |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1507 | idiag.offset.last_rd = 0; |
| 1508 | |
| 1509 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 1510 | } |
| 1511 | |
| 1512 | /** |
| 1513 | * lpfc_idiag_pcicfg_write - Syntax check and set up idiag pcicfg commands |
| 1514 | * @file: The file pointer to read from. |
| 1515 | * @buf: The buffer to copy the user data from. |
| 1516 | * @nbytes: The number of bytes to get. |
| 1517 | * @ppos: The position in the file to start reading from. |
| 1518 | * |
| 1519 | * This routine get the debugfs idiag command struct from user space and |
| 1520 | * then perform the syntax check for PCI config space read or write command |
| 1521 | * accordingly. In the case of PCI config space read command, it sets up |
| 1522 | * the command in the idiag command struct for the debugfs read operation. |
| 1523 | * In the case of PCI config space write operation, it executes the write |
| 1524 | * operation into the PCI config space accordingly. |
| 1525 | * |
| 1526 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 1527 | * In case of error conditions, it returns proper error code back to the user |
| 1528 | * space. |
| 1529 | */ |
| 1530 | static ssize_t |
| 1531 | lpfc_idiag_pcicfg_write(struct file *file, const char __user *buf, |
| 1532 | size_t nbytes, loff_t *ppos) |
| 1533 | { |
| 1534 | struct lpfc_debug *debug = file->private_data; |
| 1535 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 1536 | uint32_t where, value, count; |
| 1537 | uint32_t u32val; |
| 1538 | uint16_t u16val; |
| 1539 | uint8_t u8val; |
| 1540 | struct pci_dev *pdev; |
| 1541 | int rc; |
| 1542 | |
| 1543 | pdev = phba->pcidev; |
| 1544 | if (!pdev) |
| 1545 | return -EFAULT; |
| 1546 | |
| 1547 | /* This is a user write operation */ |
| 1548 | debug->op = LPFC_IDIAG_OP_WR; |
| 1549 | |
| 1550 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1551 | if (rc < 0) |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1552 | return rc; |
| 1553 | |
| 1554 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_RD) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1555 | /* Sanity check on PCI config read command line arguments */ |
| 1556 | if (rc != LPFC_PCI_CFG_RD_CMD_ARG) |
| 1557 | goto error_out; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1558 | /* Read command from PCI config space, set up command fields */ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1559 | where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX]; |
| 1560 | count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX]; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1561 | if (count == LPFC_PCI_CFG_BROWSE) { |
| 1562 | if (where % sizeof(uint32_t)) |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1563 | goto error_out; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1564 | /* Starting offset to browse */ |
| 1565 | idiag.offset.last_rd = where; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1566 | } else if ((count != sizeof(uint8_t)) && |
| 1567 | (count != sizeof(uint16_t)) && |
| 1568 | (count != sizeof(uint32_t))) |
| 1569 | goto error_out; |
| 1570 | if (count == sizeof(uint8_t)) { |
| 1571 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t)) |
| 1572 | goto error_out; |
| 1573 | if (where % sizeof(uint8_t)) |
| 1574 | goto error_out; |
| 1575 | } |
| 1576 | if (count == sizeof(uint16_t)) { |
| 1577 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t)) |
| 1578 | goto error_out; |
| 1579 | if (where % sizeof(uint16_t)) |
| 1580 | goto error_out; |
| 1581 | } |
| 1582 | if (count == sizeof(uint32_t)) { |
| 1583 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t)) |
| 1584 | goto error_out; |
| 1585 | if (where % sizeof(uint32_t)) |
| 1586 | goto error_out; |
| 1587 | } |
| 1588 | } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR || |
| 1589 | idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST || |
| 1590 | idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 1591 | /* Sanity check on PCI config write command line arguments */ |
| 1592 | if (rc != LPFC_PCI_CFG_WR_CMD_ARG) |
| 1593 | goto error_out; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1594 | /* Write command to PCI config space, read-modify-write */ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1595 | where = idiag.cmd.data[IDIAG_PCICFG_WHERE_INDX]; |
| 1596 | count = idiag.cmd.data[IDIAG_PCICFG_COUNT_INDX]; |
| 1597 | value = idiag.cmd.data[IDIAG_PCICFG_VALUE_INDX]; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 1598 | /* Sanity checks */ |
| 1599 | if ((count != sizeof(uint8_t)) && |
| 1600 | (count != sizeof(uint16_t)) && |
| 1601 | (count != sizeof(uint32_t))) |
| 1602 | goto error_out; |
| 1603 | if (count == sizeof(uint8_t)) { |
| 1604 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint8_t)) |
| 1605 | goto error_out; |
| 1606 | if (where % sizeof(uint8_t)) |
| 1607 | goto error_out; |
| 1608 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR) |
| 1609 | pci_write_config_byte(pdev, where, |
| 1610 | (uint8_t)value); |
| 1611 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) { |
| 1612 | rc = pci_read_config_byte(pdev, where, &u8val); |
| 1613 | if (!rc) { |
| 1614 | u8val |= (uint8_t)value; |
| 1615 | pci_write_config_byte(pdev, where, |
| 1616 | u8val); |
| 1617 | } |
| 1618 | } |
| 1619 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) { |
| 1620 | rc = pci_read_config_byte(pdev, where, &u8val); |
| 1621 | if (!rc) { |
| 1622 | u8val &= (uint8_t)(~value); |
| 1623 | pci_write_config_byte(pdev, where, |
| 1624 | u8val); |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | if (count == sizeof(uint16_t)) { |
| 1629 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint16_t)) |
| 1630 | goto error_out; |
| 1631 | if (where % sizeof(uint16_t)) |
| 1632 | goto error_out; |
| 1633 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR) |
| 1634 | pci_write_config_word(pdev, where, |
| 1635 | (uint16_t)value); |
| 1636 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) { |
| 1637 | rc = pci_read_config_word(pdev, where, &u16val); |
| 1638 | if (!rc) { |
| 1639 | u16val |= (uint16_t)value; |
| 1640 | pci_write_config_word(pdev, where, |
| 1641 | u16val); |
| 1642 | } |
| 1643 | } |
| 1644 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) { |
| 1645 | rc = pci_read_config_word(pdev, where, &u16val); |
| 1646 | if (!rc) { |
| 1647 | u16val &= (uint16_t)(~value); |
| 1648 | pci_write_config_word(pdev, where, |
| 1649 | u16val); |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | if (count == sizeof(uint32_t)) { |
| 1654 | if (where > LPFC_PCI_CFG_SIZE - sizeof(uint32_t)) |
| 1655 | goto error_out; |
| 1656 | if (where % sizeof(uint32_t)) |
| 1657 | goto error_out; |
| 1658 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_WR) |
| 1659 | pci_write_config_dword(pdev, where, value); |
| 1660 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_ST) { |
| 1661 | rc = pci_read_config_dword(pdev, where, |
| 1662 | &u32val); |
| 1663 | if (!rc) { |
| 1664 | u32val |= value; |
| 1665 | pci_write_config_dword(pdev, where, |
| 1666 | u32val); |
| 1667 | } |
| 1668 | } |
| 1669 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_PCICFG_CL) { |
| 1670 | rc = pci_read_config_dword(pdev, where, |
| 1671 | &u32val); |
| 1672 | if (!rc) { |
| 1673 | u32val &= ~value; |
| 1674 | pci_write_config_dword(pdev, where, |
| 1675 | u32val); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | } else |
| 1680 | /* All other opecodes are illegal for now */ |
| 1681 | goto error_out; |
| 1682 | |
| 1683 | return nbytes; |
| 1684 | error_out: |
| 1685 | memset(&idiag, 0, sizeof(idiag)); |
| 1686 | return -EINVAL; |
| 1687 | } |
| 1688 | |
| 1689 | /** |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 1690 | * lpfc_idiag_baracc_read - idiag debugfs pci bar access read |
| 1691 | * @file: The file pointer to read from. |
| 1692 | * @buf: The buffer to copy the data to. |
| 1693 | * @nbytes: The number of bytes to read. |
| 1694 | * @ppos: The position in the file to start reading from. |
| 1695 | * |
| 1696 | * Description: |
| 1697 | * This routine reads data from the @phba pci bar memory mapped space |
| 1698 | * according to the idiag command, and copies to user @buf. |
| 1699 | * |
| 1700 | * Returns: |
| 1701 | * This function returns the amount of data that was read (this could be less |
| 1702 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 1703 | **/ |
| 1704 | static ssize_t |
| 1705 | lpfc_idiag_baracc_read(struct file *file, char __user *buf, size_t nbytes, |
| 1706 | loff_t *ppos) |
| 1707 | { |
| 1708 | struct lpfc_debug *debug = file->private_data; |
| 1709 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 1710 | int offset_label, offset, offset_run, len = 0, index; |
| 1711 | int bar_num, acc_range, bar_size; |
| 1712 | char *pbuffer; |
| 1713 | void __iomem *mem_mapped_bar; |
| 1714 | uint32_t if_type; |
| 1715 | struct pci_dev *pdev; |
| 1716 | uint32_t u32val; |
| 1717 | |
| 1718 | pdev = phba->pcidev; |
| 1719 | if (!pdev) |
| 1720 | return 0; |
| 1721 | |
| 1722 | /* This is a user read operation */ |
| 1723 | debug->op = LPFC_IDIAG_OP_RD; |
| 1724 | |
| 1725 | if (!debug->buffer) |
| 1726 | debug->buffer = kmalloc(LPFC_PCI_BAR_RD_BUF_SIZE, GFP_KERNEL); |
| 1727 | if (!debug->buffer) |
| 1728 | return 0; |
| 1729 | pbuffer = debug->buffer; |
| 1730 | |
| 1731 | if (*ppos) |
| 1732 | return 0; |
| 1733 | |
| 1734 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) { |
| 1735 | bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX]; |
| 1736 | offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX]; |
| 1737 | acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX]; |
| 1738 | bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX]; |
| 1739 | } else |
| 1740 | return 0; |
| 1741 | |
| 1742 | if (acc_range == 0) |
| 1743 | return 0; |
| 1744 | |
| 1745 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1746 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 1747 | if (bar_num == IDIAG_BARACC_BAR_0) |
| 1748 | mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p; |
| 1749 | else if (bar_num == IDIAG_BARACC_BAR_1) |
| 1750 | mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p; |
| 1751 | else if (bar_num == IDIAG_BARACC_BAR_2) |
| 1752 | mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p; |
| 1753 | else |
| 1754 | return 0; |
| 1755 | } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 1756 | if (bar_num == IDIAG_BARACC_BAR_0) |
| 1757 | mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p; |
| 1758 | else |
| 1759 | return 0; |
| 1760 | } else |
| 1761 | return 0; |
| 1762 | |
| 1763 | /* Read single PCI bar space register */ |
| 1764 | if (acc_range == SINGLE_WORD) { |
| 1765 | offset_run = offset; |
| 1766 | u32val = readl(mem_mapped_bar + offset_run); |
| 1767 | len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len, |
| 1768 | "%05x: %08x\n", offset_run, u32val); |
| 1769 | } else |
| 1770 | goto baracc_browse; |
| 1771 | |
| 1772 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 1773 | |
| 1774 | baracc_browse: |
| 1775 | |
| 1776 | /* Browse all PCI bar space registers */ |
| 1777 | offset_label = idiag.offset.last_rd; |
| 1778 | offset_run = offset_label; |
| 1779 | |
| 1780 | /* Read PCI bar memory mapped space */ |
| 1781 | len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len, |
| 1782 | "%05x: ", offset_label); |
| 1783 | index = LPFC_PCI_BAR_RD_SIZE; |
| 1784 | while (index > 0) { |
| 1785 | u32val = readl(mem_mapped_bar + offset_run); |
| 1786 | len += snprintf(pbuffer+len, LPFC_PCI_BAR_RD_BUF_SIZE-len, |
| 1787 | "%08x ", u32val); |
| 1788 | offset_run += sizeof(uint32_t); |
| 1789 | if (acc_range == LPFC_PCI_BAR_BROWSE) { |
| 1790 | if (offset_run >= bar_size) { |
| 1791 | len += snprintf(pbuffer+len, |
| 1792 | LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n"); |
| 1793 | break; |
| 1794 | } |
| 1795 | } else { |
| 1796 | if (offset_run >= offset + |
| 1797 | (acc_range * sizeof(uint32_t))) { |
| 1798 | len += snprintf(pbuffer+len, |
| 1799 | LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n"); |
| 1800 | break; |
| 1801 | } |
| 1802 | } |
| 1803 | index -= sizeof(uint32_t); |
| 1804 | if (!index) |
| 1805 | len += snprintf(pbuffer+len, |
| 1806 | LPFC_PCI_BAR_RD_BUF_SIZE-len, "\n"); |
| 1807 | else if (!(index % (8 * sizeof(uint32_t)))) { |
| 1808 | offset_label += (8 * sizeof(uint32_t)); |
| 1809 | len += snprintf(pbuffer+len, |
| 1810 | LPFC_PCI_BAR_RD_BUF_SIZE-len, |
| 1811 | "\n%05x: ", offset_label); |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | /* Set up the offset for next portion of pci bar read */ |
| 1816 | if (index == 0) { |
| 1817 | idiag.offset.last_rd += LPFC_PCI_BAR_RD_SIZE; |
| 1818 | if (acc_range == LPFC_PCI_BAR_BROWSE) { |
| 1819 | if (idiag.offset.last_rd >= bar_size) |
| 1820 | idiag.offset.last_rd = 0; |
| 1821 | } else { |
| 1822 | if (offset_run >= offset + |
| 1823 | (acc_range * sizeof(uint32_t))) |
| 1824 | idiag.offset.last_rd = offset; |
| 1825 | } |
| 1826 | } else { |
| 1827 | if (acc_range == LPFC_PCI_BAR_BROWSE) |
| 1828 | idiag.offset.last_rd = 0; |
| 1829 | else |
| 1830 | idiag.offset.last_rd = offset; |
| 1831 | } |
| 1832 | |
| 1833 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 1834 | } |
| 1835 | |
| 1836 | /** |
| 1837 | * lpfc_idiag_baracc_write - Syntax check and set up idiag bar access commands |
| 1838 | * @file: The file pointer to read from. |
| 1839 | * @buf: The buffer to copy the user data from. |
| 1840 | * @nbytes: The number of bytes to get. |
| 1841 | * @ppos: The position in the file to start reading from. |
| 1842 | * |
| 1843 | * This routine get the debugfs idiag command struct from user space and |
| 1844 | * then perform the syntax check for PCI bar memory mapped space read or |
| 1845 | * write command accordingly. In the case of PCI bar memory mapped space |
| 1846 | * read command, it sets up the command in the idiag command struct for |
| 1847 | * the debugfs read operation. In the case of PCI bar memorpy mapped space |
| 1848 | * write operation, it executes the write operation into the PCI bar memory |
| 1849 | * mapped space accordingly. |
| 1850 | * |
| 1851 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 1852 | * In case of error conditions, it returns proper error code back to the user |
| 1853 | * space. |
| 1854 | */ |
| 1855 | static ssize_t |
| 1856 | lpfc_idiag_baracc_write(struct file *file, const char __user *buf, |
| 1857 | size_t nbytes, loff_t *ppos) |
| 1858 | { |
| 1859 | struct lpfc_debug *debug = file->private_data; |
| 1860 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 1861 | uint32_t bar_num, bar_size, offset, value, acc_range; |
| 1862 | struct pci_dev *pdev; |
| 1863 | void __iomem *mem_mapped_bar; |
| 1864 | uint32_t if_type; |
| 1865 | uint32_t u32val; |
| 1866 | int rc; |
| 1867 | |
| 1868 | pdev = phba->pcidev; |
| 1869 | if (!pdev) |
| 1870 | return -EFAULT; |
| 1871 | |
| 1872 | /* This is a user write operation */ |
| 1873 | debug->op = LPFC_IDIAG_OP_WR; |
| 1874 | |
| 1875 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 1876 | if (rc < 0) |
| 1877 | return rc; |
| 1878 | |
| 1879 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
| 1880 | bar_num = idiag.cmd.data[IDIAG_BARACC_BAR_NUM_INDX]; |
| 1881 | |
| 1882 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 1883 | if ((bar_num != IDIAG_BARACC_BAR_0) && |
| 1884 | (bar_num != IDIAG_BARACC_BAR_1) && |
| 1885 | (bar_num != IDIAG_BARACC_BAR_2)) |
| 1886 | goto error_out; |
| 1887 | } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 1888 | if (bar_num != IDIAG_BARACC_BAR_0) |
| 1889 | goto error_out; |
| 1890 | } else |
| 1891 | goto error_out; |
| 1892 | |
| 1893 | if (if_type == LPFC_SLI_INTF_IF_TYPE_0) { |
| 1894 | if (bar_num == IDIAG_BARACC_BAR_0) { |
| 1895 | idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] = |
| 1896 | LPFC_PCI_IF0_BAR0_SIZE; |
| 1897 | mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p; |
| 1898 | } else if (bar_num == IDIAG_BARACC_BAR_1) { |
| 1899 | idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] = |
| 1900 | LPFC_PCI_IF0_BAR1_SIZE; |
| 1901 | mem_mapped_bar = phba->sli4_hba.ctrl_regs_memmap_p; |
| 1902 | } else if (bar_num == IDIAG_BARACC_BAR_2) { |
| 1903 | idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] = |
| 1904 | LPFC_PCI_IF0_BAR2_SIZE; |
| 1905 | mem_mapped_bar = phba->sli4_hba.drbl_regs_memmap_p; |
| 1906 | } else |
| 1907 | goto error_out; |
| 1908 | } else if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
| 1909 | if (bar_num == IDIAG_BARACC_BAR_0) { |
| 1910 | idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX] = |
| 1911 | LPFC_PCI_IF2_BAR0_SIZE; |
| 1912 | mem_mapped_bar = phba->sli4_hba.conf_regs_memmap_p; |
| 1913 | } else |
| 1914 | goto error_out; |
| 1915 | } else |
| 1916 | goto error_out; |
| 1917 | |
| 1918 | offset = idiag.cmd.data[IDIAG_BARACC_OFF_SET_INDX]; |
| 1919 | if (offset % sizeof(uint32_t)) |
| 1920 | goto error_out; |
| 1921 | |
| 1922 | bar_size = idiag.cmd.data[IDIAG_BARACC_BAR_SZE_INDX]; |
| 1923 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_RD) { |
| 1924 | /* Sanity check on PCI config read command line arguments */ |
| 1925 | if (rc != LPFC_PCI_BAR_RD_CMD_ARG) |
| 1926 | goto error_out; |
| 1927 | acc_range = idiag.cmd.data[IDIAG_BARACC_ACC_MOD_INDX]; |
| 1928 | if (acc_range == LPFC_PCI_BAR_BROWSE) { |
| 1929 | if (offset > bar_size - sizeof(uint32_t)) |
| 1930 | goto error_out; |
| 1931 | /* Starting offset to browse */ |
| 1932 | idiag.offset.last_rd = offset; |
| 1933 | } else if (acc_range > SINGLE_WORD) { |
| 1934 | if (offset + acc_range * sizeof(uint32_t) > bar_size) |
| 1935 | goto error_out; |
| 1936 | /* Starting offset to browse */ |
| 1937 | idiag.offset.last_rd = offset; |
| 1938 | } else if (acc_range != SINGLE_WORD) |
| 1939 | goto error_out; |
| 1940 | } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR || |
| 1941 | idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST || |
| 1942 | idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) { |
| 1943 | /* Sanity check on PCI bar write command line arguments */ |
| 1944 | if (rc != LPFC_PCI_BAR_WR_CMD_ARG) |
| 1945 | goto error_out; |
| 1946 | /* Write command to PCI bar space, read-modify-write */ |
| 1947 | acc_range = SINGLE_WORD; |
| 1948 | value = idiag.cmd.data[IDIAG_BARACC_REG_VAL_INDX]; |
| 1949 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_WR) { |
| 1950 | writel(value, mem_mapped_bar + offset); |
| 1951 | readl(mem_mapped_bar + offset); |
| 1952 | } |
| 1953 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_ST) { |
| 1954 | u32val = readl(mem_mapped_bar + offset); |
| 1955 | u32val |= value; |
| 1956 | writel(u32val, mem_mapped_bar + offset); |
| 1957 | readl(mem_mapped_bar + offset); |
| 1958 | } |
| 1959 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_BARACC_CL) { |
| 1960 | u32val = readl(mem_mapped_bar + offset); |
| 1961 | u32val &= ~value; |
| 1962 | writel(u32val, mem_mapped_bar + offset); |
| 1963 | readl(mem_mapped_bar + offset); |
| 1964 | } |
| 1965 | } else |
| 1966 | /* All other opecodes are illegal for now */ |
| 1967 | goto error_out; |
| 1968 | |
| 1969 | return nbytes; |
| 1970 | error_out: |
| 1971 | memset(&idiag, 0, sizeof(idiag)); |
| 1972 | return -EINVAL; |
| 1973 | } |
| 1974 | |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 1975 | static int |
| 1976 | __lpfc_idiag_print_wq(struct lpfc_queue *qp, char *wqtype, |
| 1977 | char *pbuffer, int len) |
| 1978 | { |
| 1979 | if (!qp) |
| 1980 | return len; |
| 1981 | |
| 1982 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 1983 | "\t\t%s WQ info: ", wqtype); |
| 1984 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 1985 | "AssocCQID[%04d]: WQ-STAT[oflow:x%x posted:x%llx]\n", |
| 1986 | qp->assoc_qid, qp->q_cnt_1, |
| 1987 | (unsigned long long)qp->q_cnt_4); |
| 1988 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 1989 | "\t\tWQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], " |
| 1990 | "HOST-IDX[%04d], PORT-IDX[%04d]", |
| 1991 | qp->queue_id, qp->entry_count, |
| 1992 | qp->entry_size, qp->host_index, |
| 1993 | qp->hba_index); |
| 1994 | len += snprintf(pbuffer + len, |
| 1995 | LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n"); |
| 1996 | return len; |
| 1997 | } |
| 1998 | |
| 1999 | static int |
| 2000 | lpfc_idiag_wqs_for_cq(struct lpfc_hba *phba, char *wqtype, char *pbuffer, |
| 2001 | int *len, int max_cnt, int cq_id) |
| 2002 | { |
| 2003 | struct lpfc_queue *qp; |
| 2004 | int qidx; |
| 2005 | |
| 2006 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) { |
| 2007 | qp = phba->sli4_hba.fcp_wq[qidx]; |
| 2008 | if (qp->assoc_qid != cq_id) |
| 2009 | continue; |
| 2010 | *len = __lpfc_idiag_print_wq(qp, wqtype, pbuffer, *len); |
| 2011 | if (*len >= max_cnt) |
| 2012 | return 1; |
| 2013 | } |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | static int |
| 2018 | __lpfc_idiag_print_cq(struct lpfc_queue *qp, char *cqtype, |
| 2019 | char *pbuffer, int len) |
| 2020 | { |
| 2021 | if (!qp) |
| 2022 | return len; |
| 2023 | |
| 2024 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2025 | "\t%s CQ info: ", cqtype); |
| 2026 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2027 | "AssocEQID[%02d]: CQ STAT[max:x%x relw:x%x " |
| 2028 | "xabt:x%x wq:x%llx]\n", |
| 2029 | qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2, |
| 2030 | qp->q_cnt_3, (unsigned long long)qp->q_cnt_4); |
| 2031 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2032 | "\tCQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], " |
| 2033 | "HOST-IDX[%04d], PORT-IDX[%04d]", |
| 2034 | qp->queue_id, qp->entry_count, |
| 2035 | qp->entry_size, qp->host_index, |
| 2036 | qp->hba_index); |
| 2037 | |
| 2038 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n"); |
| 2039 | |
| 2040 | return len; |
| 2041 | } |
| 2042 | |
| 2043 | static int |
| 2044 | __lpfc_idiag_print_rqpair(struct lpfc_queue *qp, struct lpfc_queue *datqp, |
| 2045 | char *rqtype, char *pbuffer, int len) |
| 2046 | { |
| 2047 | if (!qp || !datqp) |
| 2048 | return len; |
| 2049 | |
| 2050 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2051 | "\t\t%s RQ info: ", rqtype); |
| 2052 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2053 | "AssocCQID[%02d]: RQ-STAT[nopost:x%x nobuf:x%x " |
| 2054 | "trunc:x%x rcv:x%llx]\n", |
| 2055 | qp->assoc_qid, qp->q_cnt_1, qp->q_cnt_2, |
| 2056 | qp->q_cnt_3, (unsigned long long)qp->q_cnt_4); |
| 2057 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2058 | "\t\tHQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], " |
| 2059 | "HOST-IDX[%04d], PORT-IDX[%04d]\n", |
| 2060 | qp->queue_id, qp->entry_count, qp->entry_size, |
| 2061 | qp->host_index, qp->hba_index); |
| 2062 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2063 | "\t\tDQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], " |
| 2064 | "HOST-IDX[%04d], PORT-IDX[%04d]\n", |
| 2065 | datqp->queue_id, datqp->entry_count, |
| 2066 | datqp->entry_size, datqp->host_index, |
| 2067 | datqp->hba_index); |
| 2068 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n"); |
| 2069 | |
| 2070 | return len; |
| 2071 | } |
| 2072 | |
| 2073 | static int |
| 2074 | lpfc_idiag_cqs_for_eq(struct lpfc_hba *phba, char *pbuffer, |
| 2075 | int *len, int max_cnt, int eq_id) |
| 2076 | { |
| 2077 | struct lpfc_queue *qp; |
| 2078 | int qidx, rc; |
| 2079 | |
| 2080 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) { |
| 2081 | qp = phba->sli4_hba.fcp_cq[qidx]; |
| 2082 | if (qp->assoc_qid != eq_id) |
| 2083 | continue; |
| 2084 | |
| 2085 | *len = __lpfc_idiag_print_cq(qp, "FCP", pbuffer, *len); |
| 2086 | |
| 2087 | /* Reset max counter */ |
| 2088 | qp->CQ_max_cqe = 0; |
| 2089 | |
| 2090 | if (*len >= max_cnt) |
| 2091 | return 1; |
| 2092 | |
| 2093 | rc = lpfc_idiag_wqs_for_cq(phba, "FCP", pbuffer, len, |
| 2094 | max_cnt, qp->queue_id); |
| 2095 | if (rc) |
| 2096 | return 1; |
| 2097 | } |
| 2098 | |
| 2099 | return 0; |
| 2100 | } |
| 2101 | |
| 2102 | static int |
| 2103 | __lpfc_idiag_print_eq(struct lpfc_queue *qp, char *eqtype, |
| 2104 | char *pbuffer, int len) |
| 2105 | { |
| 2106 | if (!qp) |
| 2107 | return len; |
| 2108 | |
| 2109 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2110 | "\n%s EQ info: EQ-STAT[max:x%x noE:x%x " |
| 2111 | "bs:x%x proc:x%llx]\n", |
| 2112 | eqtype, qp->q_cnt_1, qp->q_cnt_2, qp->q_cnt_3, |
| 2113 | (unsigned long long)qp->q_cnt_4); |
| 2114 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2115 | "EQID[%02d], QE-CNT[%04d], QE-SIZE[%04d], " |
| 2116 | "HOST-IDX[%04d], PORT-IDX[%04d]", |
| 2117 | qp->queue_id, qp->entry_count, qp->entry_size, |
| 2118 | qp->host_index, qp->hba_index); |
| 2119 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, "\n"); |
| 2120 | |
| 2121 | return len; |
| 2122 | } |
| 2123 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2124 | /** |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2125 | * lpfc_idiag_queinfo_read - idiag debugfs read queue information |
| 2126 | * @file: The file pointer to read from. |
| 2127 | * @buf: The buffer to copy the data to. |
| 2128 | * @nbytes: The number of bytes to read. |
| 2129 | * @ppos: The position in the file to start reading from. |
| 2130 | * |
| 2131 | * Description: |
| 2132 | * This routine reads data from the @phba SLI4 PCI function queue information, |
| 2133 | * and copies to user @buf. |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2134 | * This routine only returns 1 EQs worth of information. It remembers the last |
| 2135 | * EQ read and jumps to the next EQ. Thus subsequent calls to queInfo will |
| 2136 | * retrieve all EQs allocated for the phba. |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2137 | * |
| 2138 | * Returns: |
| 2139 | * This function returns the amount of data that was read (this could be less |
| 2140 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 2141 | **/ |
| 2142 | static ssize_t |
| 2143 | lpfc_idiag_queinfo_read(struct file *file, char __user *buf, size_t nbytes, |
| 2144 | loff_t *ppos) |
| 2145 | { |
| 2146 | struct lpfc_debug *debug = file->private_data; |
| 2147 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2148 | char *pbuffer; |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2149 | int max_cnt, rc, x, len = 0; |
James Smart | c85a65a | 2012-08-03 12:37:00 -0400 | [diff] [blame] | 2150 | struct lpfc_queue *qp = NULL; |
| 2151 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2152 | if (!debug->buffer) |
| 2153 | debug->buffer = kmalloc(LPFC_QUE_INFO_GET_BUF_SIZE, GFP_KERNEL); |
| 2154 | if (!debug->buffer) |
| 2155 | return 0; |
| 2156 | pbuffer = debug->buffer; |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2157 | max_cnt = LPFC_QUE_INFO_GET_BUF_SIZE - 256; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2158 | |
| 2159 | if (*ppos) |
| 2160 | return 0; |
| 2161 | |
James Smart | c85a65a | 2012-08-03 12:37:00 -0400 | [diff] [blame] | 2162 | spin_lock_irq(&phba->hbalock); |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2163 | |
James Smart | c85a65a | 2012-08-03 12:37:00 -0400 | [diff] [blame] | 2164 | /* Fast-path event queue */ |
| 2165 | if (phba->sli4_hba.hba_eq && phba->cfg_fcp_io_channel) { |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2166 | |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2167 | x = phba->lpfc_idiag_last_eq; |
| 2168 | if (phba->cfg_fof && (x >= phba->cfg_fcp_io_channel)) { |
| 2169 | phba->lpfc_idiag_last_eq = 0; |
| 2170 | goto fof; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2171 | } |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2172 | phba->lpfc_idiag_last_eq++; |
| 2173 | if (phba->lpfc_idiag_last_eq >= phba->cfg_fcp_io_channel) |
| 2174 | if (phba->cfg_fof == 0) |
| 2175 | phba->lpfc_idiag_last_eq = 0; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2176 | |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2177 | len += snprintf(pbuffer + len, LPFC_QUE_INFO_GET_BUF_SIZE - len, |
| 2178 | "EQ %d out of %d HBA EQs\n", |
| 2179 | x, phba->cfg_fcp_io_channel); |
| 2180 | |
| 2181 | /* Fast-path EQ */ |
| 2182 | qp = phba->sli4_hba.hba_eq[x]; |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 2183 | if (!qp) |
| 2184 | goto out; |
| 2185 | |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2186 | len = __lpfc_idiag_print_eq(qp, "HBA", pbuffer, len); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 2187 | |
| 2188 | /* Reset max counter */ |
| 2189 | qp->EQ_max_eqe = 0; |
| 2190 | |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2191 | if (len >= max_cnt) |
| 2192 | goto too_big; |
| 2193 | |
| 2194 | rc = lpfc_idiag_cqs_for_eq(phba, pbuffer, &len, |
| 2195 | max_cnt, qp->queue_id); |
| 2196 | if (rc) |
| 2197 | goto too_big; |
| 2198 | |
| 2199 | /* Only EQ 0 has slow path CQs configured */ |
| 2200 | if (x) |
| 2201 | goto out; |
| 2202 | |
| 2203 | /* Slow-path mailbox CQ */ |
| 2204 | qp = phba->sli4_hba.mbx_cq; |
| 2205 | len = __lpfc_idiag_print_cq(qp, "MBX", pbuffer, len); |
| 2206 | if (len >= max_cnt) |
| 2207 | goto too_big; |
| 2208 | |
| 2209 | /* Slow-path MBOX MQ */ |
| 2210 | qp = phba->sli4_hba.mbx_wq; |
| 2211 | len = __lpfc_idiag_print_wq(qp, "MBX", pbuffer, len); |
| 2212 | if (len >= max_cnt) |
| 2213 | goto too_big; |
| 2214 | |
| 2215 | /* Slow-path ELS response CQ */ |
| 2216 | qp = phba->sli4_hba.els_cq; |
| 2217 | len = __lpfc_idiag_print_cq(qp, "ELS", pbuffer, len); |
| 2218 | /* Reset max counter */ |
| 2219 | if (qp) |
| 2220 | qp->CQ_max_cqe = 0; |
| 2221 | if (len >= max_cnt) |
| 2222 | goto too_big; |
| 2223 | |
| 2224 | /* Slow-path ELS WQ */ |
| 2225 | qp = phba->sli4_hba.els_wq; |
| 2226 | len = __lpfc_idiag_print_wq(qp, "ELS", pbuffer, len); |
| 2227 | if (len >= max_cnt) |
| 2228 | goto too_big; |
| 2229 | |
| 2230 | qp = phba->sli4_hba.hdr_rq; |
| 2231 | len = __lpfc_idiag_print_rqpair(qp, phba->sli4_hba.dat_rq, |
| 2232 | "RQpair", pbuffer, len); |
| 2233 | if (len >= max_cnt) |
| 2234 | goto too_big; |
| 2235 | |
| 2236 | goto out; |
| 2237 | } |
| 2238 | |
| 2239 | fof: |
| 2240 | if (phba->cfg_fof) { |
| 2241 | /* FOF EQ */ |
| 2242 | qp = phba->sli4_hba.fof_eq; |
| 2243 | len = __lpfc_idiag_print_eq(qp, "FOF", pbuffer, len); |
| 2244 | |
| 2245 | /* Reset max counter */ |
| 2246 | if (qp) |
| 2247 | qp->EQ_max_eqe = 0; |
| 2248 | |
| 2249 | if (len >= max_cnt) |
| 2250 | goto too_big; |
| 2251 | |
| 2252 | /* OAS CQ */ |
| 2253 | qp = phba->sli4_hba.oas_cq; |
| 2254 | len = __lpfc_idiag_print_cq(qp, "OAS", pbuffer, len); |
| 2255 | /* Reset max counter */ |
| 2256 | if (qp) |
| 2257 | qp->CQ_max_cqe = 0; |
| 2258 | if (len >= max_cnt) |
| 2259 | goto too_big; |
| 2260 | |
| 2261 | /* OAS WQ */ |
| 2262 | qp = phba->sli4_hba.oas_wq; |
| 2263 | len = __lpfc_idiag_print_wq(qp, "OAS", pbuffer, len); |
James Smart | 1ba981f | 2014-02-20 09:56:45 -0500 | [diff] [blame] | 2264 | if (len >= max_cnt) |
| 2265 | goto too_big; |
| 2266 | } |
| 2267 | |
James Smart | c85a65a | 2012-08-03 12:37:00 -0400 | [diff] [blame] | 2268 | spin_unlock_irq(&phba->hbalock); |
| 2269 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2270 | |
| 2271 | too_big: |
James Smart | 07bcd98 | 2017-02-12 13:52:28 -0800 | [diff] [blame^] | 2272 | len += snprintf(pbuffer + len, |
| 2273 | LPFC_QUE_INFO_GET_BUF_SIZE - len, "Truncated ...\n"); |
| 2274 | out: |
James Smart | c85a65a | 2012-08-03 12:37:00 -0400 | [diff] [blame] | 2275 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 2276 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2277 | } |
| 2278 | |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2279 | /** |
| 2280 | * lpfc_idiag_que_param_check - queue access command parameter sanity check |
| 2281 | * @q: The pointer to queue structure. |
| 2282 | * @index: The index into a queue entry. |
| 2283 | * @count: The number of queue entries to access. |
| 2284 | * |
| 2285 | * Description: |
| 2286 | * The routine performs sanity check on device queue access method commands. |
| 2287 | * |
| 2288 | * Returns: |
| 2289 | * This function returns -EINVAL when fails the sanity check, otherwise, it |
| 2290 | * returns 0. |
| 2291 | **/ |
| 2292 | static int |
| 2293 | lpfc_idiag_que_param_check(struct lpfc_queue *q, int index, int count) |
| 2294 | { |
| 2295 | /* Only support single entry read or browsing */ |
| 2296 | if ((count != 1) && (count != LPFC_QUE_ACC_BROWSE)) |
| 2297 | return -EINVAL; |
| 2298 | if (index > q->entry_count - 1) |
| 2299 | return -EINVAL; |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | /** |
| 2304 | * lpfc_idiag_queacc_read_qe - read a single entry from the given queue index |
| 2305 | * @pbuffer: The pointer to buffer to copy the read data into. |
| 2306 | * @pque: The pointer to the queue to be read. |
| 2307 | * @index: The index into the queue entry. |
| 2308 | * |
| 2309 | * Description: |
| 2310 | * This routine reads out a single entry from the given queue's index location |
| 2311 | * and copies it into the buffer provided. |
| 2312 | * |
| 2313 | * Returns: |
| 2314 | * This function returns 0 when it fails, otherwise, it returns the length of |
| 2315 | * the data read into the buffer provided. |
| 2316 | **/ |
| 2317 | static int |
| 2318 | lpfc_idiag_queacc_read_qe(char *pbuffer, int len, struct lpfc_queue *pque, |
| 2319 | uint32_t index) |
| 2320 | { |
| 2321 | int offset, esize; |
| 2322 | uint32_t *pentry; |
| 2323 | |
| 2324 | if (!pbuffer || !pque) |
| 2325 | return 0; |
| 2326 | |
| 2327 | esize = pque->entry_size; |
| 2328 | len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, |
| 2329 | "QE-INDEX[%04d]:\n", index); |
| 2330 | |
| 2331 | offset = 0; |
| 2332 | pentry = pque->qe[index].address; |
| 2333 | while (esize > 0) { |
| 2334 | len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, |
| 2335 | "%08x ", *pentry); |
| 2336 | pentry++; |
| 2337 | offset += sizeof(uint32_t); |
| 2338 | esize -= sizeof(uint32_t); |
| 2339 | if (esize > 0 && !(offset % (4 * sizeof(uint32_t)))) |
| 2340 | len += snprintf(pbuffer+len, |
| 2341 | LPFC_QUE_ACC_BUF_SIZE-len, "\n"); |
| 2342 | } |
| 2343 | len += snprintf(pbuffer+len, LPFC_QUE_ACC_BUF_SIZE-len, "\n"); |
| 2344 | |
| 2345 | return len; |
| 2346 | } |
| 2347 | |
| 2348 | /** |
| 2349 | * lpfc_idiag_queacc_read - idiag debugfs read port queue |
| 2350 | * @file: The file pointer to read from. |
| 2351 | * @buf: The buffer to copy the data to. |
| 2352 | * @nbytes: The number of bytes to read. |
| 2353 | * @ppos: The position in the file to start reading from. |
| 2354 | * |
| 2355 | * Description: |
| 2356 | * This routine reads data from the @phba device queue memory according to the |
| 2357 | * idiag command, and copies to user @buf. Depending on the queue dump read |
| 2358 | * command setup, it does either a single queue entry read or browing through |
| 2359 | * all entries of the queue. |
| 2360 | * |
| 2361 | * Returns: |
| 2362 | * This function returns the amount of data that was read (this could be less |
| 2363 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 2364 | **/ |
| 2365 | static ssize_t |
| 2366 | lpfc_idiag_queacc_read(struct file *file, char __user *buf, size_t nbytes, |
| 2367 | loff_t *ppos) |
| 2368 | { |
| 2369 | struct lpfc_debug *debug = file->private_data; |
| 2370 | uint32_t last_index, index, count; |
| 2371 | struct lpfc_queue *pque = NULL; |
| 2372 | char *pbuffer; |
| 2373 | int len = 0; |
| 2374 | |
| 2375 | /* This is a user read operation */ |
| 2376 | debug->op = LPFC_IDIAG_OP_RD; |
| 2377 | |
| 2378 | if (!debug->buffer) |
| 2379 | debug->buffer = kmalloc(LPFC_QUE_ACC_BUF_SIZE, GFP_KERNEL); |
| 2380 | if (!debug->buffer) |
| 2381 | return 0; |
| 2382 | pbuffer = debug->buffer; |
| 2383 | |
| 2384 | if (*ppos) |
| 2385 | return 0; |
| 2386 | |
| 2387 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) { |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2388 | index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX]; |
| 2389 | count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX]; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2390 | pque = (struct lpfc_queue *)idiag.ptr_private; |
| 2391 | } else |
| 2392 | return 0; |
| 2393 | |
| 2394 | /* Browse the queue starting from index */ |
| 2395 | if (count == LPFC_QUE_ACC_BROWSE) |
| 2396 | goto que_browse; |
| 2397 | |
| 2398 | /* Read a single entry from the queue */ |
| 2399 | len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index); |
| 2400 | |
| 2401 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2402 | |
| 2403 | que_browse: |
| 2404 | |
| 2405 | /* Browse all entries from the queue */ |
| 2406 | last_index = idiag.offset.last_rd; |
| 2407 | index = last_index; |
| 2408 | |
| 2409 | while (len < LPFC_QUE_ACC_SIZE - pque->entry_size) { |
| 2410 | len = lpfc_idiag_queacc_read_qe(pbuffer, len, pque, index); |
| 2411 | index++; |
| 2412 | if (index > pque->entry_count - 1) |
| 2413 | break; |
| 2414 | } |
| 2415 | |
| 2416 | /* Set up the offset for next portion of pci cfg read */ |
| 2417 | if (index > pque->entry_count - 1) |
| 2418 | index = 0; |
| 2419 | idiag.offset.last_rd = index; |
| 2420 | |
| 2421 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * lpfc_idiag_queacc_write - Syntax check and set up idiag queacc commands |
| 2426 | * @file: The file pointer to read from. |
| 2427 | * @buf: The buffer to copy the user data from. |
| 2428 | * @nbytes: The number of bytes to get. |
| 2429 | * @ppos: The position in the file to start reading from. |
| 2430 | * |
| 2431 | * This routine get the debugfs idiag command struct from user space and then |
| 2432 | * perform the syntax check for port queue read (dump) or write (set) command |
| 2433 | * accordingly. In the case of port queue read command, it sets up the command |
| 2434 | * in the idiag command struct for the following debugfs read operation. In |
| 2435 | * the case of port queue write operation, it executes the write operation |
| 2436 | * into the port queue entry accordingly. |
| 2437 | * |
| 2438 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 2439 | * In case of error conditions, it returns proper error code back to the user |
| 2440 | * space. |
| 2441 | **/ |
| 2442 | static ssize_t |
| 2443 | lpfc_idiag_queacc_write(struct file *file, const char __user *buf, |
| 2444 | size_t nbytes, loff_t *ppos) |
| 2445 | { |
| 2446 | struct lpfc_debug *debug = file->private_data; |
| 2447 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 2448 | uint32_t qidx, quetp, queid, index, count, offset, value; |
| 2449 | uint32_t *pentry; |
| 2450 | struct lpfc_queue *pque; |
| 2451 | int rc; |
| 2452 | |
| 2453 | /* This is a user write operation */ |
| 2454 | debug->op = LPFC_IDIAG_OP_WR; |
| 2455 | |
| 2456 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 2457 | if (rc < 0) |
| 2458 | return rc; |
| 2459 | |
| 2460 | /* Get and sanity check on command feilds */ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2461 | quetp = idiag.cmd.data[IDIAG_QUEACC_QUETP_INDX]; |
| 2462 | queid = idiag.cmd.data[IDIAG_QUEACC_QUEID_INDX]; |
| 2463 | index = idiag.cmd.data[IDIAG_QUEACC_INDEX_INDX]; |
| 2464 | count = idiag.cmd.data[IDIAG_QUEACC_COUNT_INDX]; |
| 2465 | offset = idiag.cmd.data[IDIAG_QUEACC_OFFST_INDX]; |
| 2466 | value = idiag.cmd.data[IDIAG_QUEACC_VALUE_INDX]; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2467 | |
| 2468 | /* Sanity check on command line arguments */ |
| 2469 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR || |
| 2470 | idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST || |
| 2471 | idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) { |
| 2472 | if (rc != LPFC_QUE_ACC_WR_CMD_ARG) |
| 2473 | goto error_out; |
| 2474 | if (count != 1) |
| 2475 | goto error_out; |
| 2476 | } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) { |
| 2477 | if (rc != LPFC_QUE_ACC_RD_CMD_ARG) |
| 2478 | goto error_out; |
| 2479 | } else |
| 2480 | goto error_out; |
| 2481 | |
| 2482 | switch (quetp) { |
| 2483 | case LPFC_IDIAG_EQ: |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 2484 | /* HBA event queue */ |
| 2485 | if (phba->sli4_hba.hba_eq) { |
| 2486 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; |
| 2487 | qidx++) { |
| 2488 | if (phba->sli4_hba.hba_eq[qidx] && |
| 2489 | phba->sli4_hba.hba_eq[qidx]->queue_id == |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2490 | queid) { |
| 2491 | /* Sanity check */ |
| 2492 | rc = lpfc_idiag_que_param_check( |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 2493 | phba->sli4_hba.hba_eq[qidx], |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2494 | index, count); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2495 | if (rc) |
| 2496 | goto error_out; |
| 2497 | idiag.ptr_private = |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 2498 | phba->sli4_hba.hba_eq[qidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2499 | goto pass_check; |
| 2500 | } |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2501 | } |
| 2502 | } |
| 2503 | goto error_out; |
| 2504 | break; |
| 2505 | case LPFC_IDIAG_CQ: |
| 2506 | /* MBX complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2507 | if (phba->sli4_hba.mbx_cq && |
| 2508 | phba->sli4_hba.mbx_cq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2509 | /* Sanity check */ |
| 2510 | rc = lpfc_idiag_que_param_check( |
| 2511 | phba->sli4_hba.mbx_cq, index, count); |
| 2512 | if (rc) |
| 2513 | goto error_out; |
| 2514 | idiag.ptr_private = phba->sli4_hba.mbx_cq; |
| 2515 | goto pass_check; |
| 2516 | } |
| 2517 | /* ELS complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2518 | if (phba->sli4_hba.els_cq && |
| 2519 | phba->sli4_hba.els_cq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2520 | /* Sanity check */ |
| 2521 | rc = lpfc_idiag_que_param_check( |
| 2522 | phba->sli4_hba.els_cq, index, count); |
| 2523 | if (rc) |
| 2524 | goto error_out; |
| 2525 | idiag.ptr_private = phba->sli4_hba.els_cq; |
| 2526 | goto pass_check; |
| 2527 | } |
| 2528 | /* FCP complete queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2529 | if (phba->sli4_hba.fcp_cq) { |
| 2530 | qidx = 0; |
| 2531 | do { |
| 2532 | if (phba->sli4_hba.fcp_cq[qidx] && |
| 2533 | phba->sli4_hba.fcp_cq[qidx]->queue_id == |
| 2534 | queid) { |
| 2535 | /* Sanity check */ |
| 2536 | rc = lpfc_idiag_que_param_check( |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2537 | phba->sli4_hba.fcp_cq[qidx], |
| 2538 | index, count); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2539 | if (rc) |
| 2540 | goto error_out; |
| 2541 | idiag.ptr_private = |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2542 | phba->sli4_hba.fcp_cq[qidx]; |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2543 | goto pass_check; |
| 2544 | } |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 2545 | } while (++qidx < phba->cfg_fcp_io_channel); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2546 | } |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2547 | goto error_out; |
| 2548 | break; |
| 2549 | case LPFC_IDIAG_MQ: |
| 2550 | /* MBX work queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2551 | if (phba->sli4_hba.mbx_wq && |
| 2552 | phba->sli4_hba.mbx_wq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2553 | /* Sanity check */ |
| 2554 | rc = lpfc_idiag_que_param_check( |
| 2555 | phba->sli4_hba.mbx_wq, index, count); |
| 2556 | if (rc) |
| 2557 | goto error_out; |
| 2558 | idiag.ptr_private = phba->sli4_hba.mbx_wq; |
| 2559 | goto pass_check; |
| 2560 | } |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2561 | goto error_out; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2562 | break; |
| 2563 | case LPFC_IDIAG_WQ: |
| 2564 | /* ELS work queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2565 | if (phba->sli4_hba.els_wq && |
| 2566 | phba->sli4_hba.els_wq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2567 | /* Sanity check */ |
| 2568 | rc = lpfc_idiag_que_param_check( |
| 2569 | phba->sli4_hba.els_wq, index, count); |
| 2570 | if (rc) |
| 2571 | goto error_out; |
| 2572 | idiag.ptr_private = phba->sli4_hba.els_wq; |
| 2573 | goto pass_check; |
| 2574 | } |
| 2575 | /* FCP work queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2576 | if (phba->sli4_hba.fcp_wq) { |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 2577 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; |
| 2578 | qidx++) { |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2579 | if (!phba->sli4_hba.fcp_wq[qidx]) |
| 2580 | continue; |
| 2581 | if (phba->sli4_hba.fcp_wq[qidx]->queue_id == |
| 2582 | queid) { |
| 2583 | /* Sanity check */ |
| 2584 | rc = lpfc_idiag_que_param_check( |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2585 | phba->sli4_hba.fcp_wq[qidx], |
| 2586 | index, count); |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2587 | if (rc) |
| 2588 | goto error_out; |
| 2589 | idiag.ptr_private = |
| 2590 | phba->sli4_hba.fcp_wq[qidx]; |
| 2591 | goto pass_check; |
| 2592 | } |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2593 | } |
| 2594 | } |
| 2595 | goto error_out; |
| 2596 | break; |
| 2597 | case LPFC_IDIAG_RQ: |
| 2598 | /* HDR queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2599 | if (phba->sli4_hba.hdr_rq && |
| 2600 | phba->sli4_hba.hdr_rq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2601 | /* Sanity check */ |
| 2602 | rc = lpfc_idiag_que_param_check( |
| 2603 | phba->sli4_hba.hdr_rq, index, count); |
| 2604 | if (rc) |
| 2605 | goto error_out; |
| 2606 | idiag.ptr_private = phba->sli4_hba.hdr_rq; |
| 2607 | goto pass_check; |
| 2608 | } |
| 2609 | /* DAT queue */ |
James Smart | 2e90f4b | 2011-12-13 13:22:37 -0500 | [diff] [blame] | 2610 | if (phba->sli4_hba.dat_rq && |
| 2611 | phba->sli4_hba.dat_rq->queue_id == queid) { |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2612 | /* Sanity check */ |
| 2613 | rc = lpfc_idiag_que_param_check( |
| 2614 | phba->sli4_hba.dat_rq, index, count); |
| 2615 | if (rc) |
| 2616 | goto error_out; |
| 2617 | idiag.ptr_private = phba->sli4_hba.dat_rq; |
| 2618 | goto pass_check; |
| 2619 | } |
| 2620 | goto error_out; |
| 2621 | break; |
| 2622 | default: |
| 2623 | goto error_out; |
| 2624 | break; |
| 2625 | } |
| 2626 | |
| 2627 | pass_check: |
| 2628 | |
| 2629 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_RD) { |
| 2630 | if (count == LPFC_QUE_ACC_BROWSE) |
| 2631 | idiag.offset.last_rd = index; |
| 2632 | } |
| 2633 | |
| 2634 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR || |
| 2635 | idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST || |
| 2636 | idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) { |
| 2637 | /* Additional sanity checks on write operation */ |
| 2638 | pque = (struct lpfc_queue *)idiag.ptr_private; |
| 2639 | if (offset > pque->entry_size/sizeof(uint32_t) - 1) |
| 2640 | goto error_out; |
| 2641 | pentry = pque->qe[index].address; |
| 2642 | pentry += offset; |
| 2643 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_WR) |
| 2644 | *pentry = value; |
| 2645 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_ST) |
| 2646 | *pentry |= value; |
| 2647 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_QUEACC_CL) |
| 2648 | *pentry &= ~value; |
| 2649 | } |
| 2650 | return nbytes; |
| 2651 | |
| 2652 | error_out: |
| 2653 | /* Clean out command structure on command error out */ |
| 2654 | memset(&idiag, 0, sizeof(idiag)); |
| 2655 | return -EINVAL; |
| 2656 | } |
| 2657 | |
| 2658 | /** |
| 2659 | * lpfc_idiag_drbacc_read_reg - idiag debugfs read a doorbell register |
| 2660 | * @phba: The pointer to hba structure. |
| 2661 | * @pbuffer: The pointer to the buffer to copy the data to. |
| 2662 | * @len: The lenght of bytes to copied. |
| 2663 | * @drbregid: The id to doorbell registers. |
| 2664 | * |
| 2665 | * Description: |
| 2666 | * This routine reads a doorbell register and copies its content to the |
| 2667 | * user buffer pointed to by @pbuffer. |
| 2668 | * |
| 2669 | * Returns: |
| 2670 | * This function returns the amount of data that was copied into @pbuffer. |
| 2671 | **/ |
| 2672 | static int |
| 2673 | lpfc_idiag_drbacc_read_reg(struct lpfc_hba *phba, char *pbuffer, |
| 2674 | int len, uint32_t drbregid) |
| 2675 | { |
| 2676 | |
| 2677 | if (!pbuffer) |
| 2678 | return 0; |
| 2679 | |
| 2680 | switch (drbregid) { |
| 2681 | case LPFC_DRB_EQCQ: |
| 2682 | len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len, |
| 2683 | "EQCQ-DRB-REG: 0x%08x\n", |
| 2684 | readl(phba->sli4_hba.EQCQDBregaddr)); |
| 2685 | break; |
| 2686 | case LPFC_DRB_MQ: |
| 2687 | len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len, |
| 2688 | "MQ-DRB-REG: 0x%08x\n", |
| 2689 | readl(phba->sli4_hba.MQDBregaddr)); |
| 2690 | break; |
| 2691 | case LPFC_DRB_WQ: |
| 2692 | len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len, |
| 2693 | "WQ-DRB-REG: 0x%08x\n", |
| 2694 | readl(phba->sli4_hba.WQDBregaddr)); |
| 2695 | break; |
| 2696 | case LPFC_DRB_RQ: |
| 2697 | len += snprintf(pbuffer+len, LPFC_DRB_ACC_BUF_SIZE-len, |
| 2698 | "RQ-DRB-REG: 0x%08x\n", |
| 2699 | readl(phba->sli4_hba.RQDBregaddr)); |
| 2700 | break; |
| 2701 | default: |
| 2702 | break; |
| 2703 | } |
| 2704 | |
| 2705 | return len; |
| 2706 | } |
| 2707 | |
| 2708 | /** |
| 2709 | * lpfc_idiag_drbacc_read - idiag debugfs read port doorbell |
| 2710 | * @file: The file pointer to read from. |
| 2711 | * @buf: The buffer to copy the data to. |
| 2712 | * @nbytes: The number of bytes to read. |
| 2713 | * @ppos: The position in the file to start reading from. |
| 2714 | * |
| 2715 | * Description: |
| 2716 | * This routine reads data from the @phba device doorbell register according |
| 2717 | * to the idiag command, and copies to user @buf. Depending on the doorbell |
| 2718 | * register read command setup, it does either a single doorbell register |
| 2719 | * read or dump all doorbell registers. |
| 2720 | * |
| 2721 | * Returns: |
| 2722 | * This function returns the amount of data that was read (this could be less |
| 2723 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 2724 | **/ |
| 2725 | static ssize_t |
| 2726 | lpfc_idiag_drbacc_read(struct file *file, char __user *buf, size_t nbytes, |
| 2727 | loff_t *ppos) |
| 2728 | { |
| 2729 | struct lpfc_debug *debug = file->private_data; |
| 2730 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 2731 | uint32_t drb_reg_id, i; |
| 2732 | char *pbuffer; |
| 2733 | int len = 0; |
| 2734 | |
| 2735 | /* This is a user read operation */ |
| 2736 | debug->op = LPFC_IDIAG_OP_RD; |
| 2737 | |
| 2738 | if (!debug->buffer) |
| 2739 | debug->buffer = kmalloc(LPFC_DRB_ACC_BUF_SIZE, GFP_KERNEL); |
| 2740 | if (!debug->buffer) |
| 2741 | return 0; |
| 2742 | pbuffer = debug->buffer; |
| 2743 | |
| 2744 | if (*ppos) |
| 2745 | return 0; |
| 2746 | |
| 2747 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2748 | drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX]; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2749 | else |
| 2750 | return 0; |
| 2751 | |
| 2752 | if (drb_reg_id == LPFC_DRB_ACC_ALL) |
| 2753 | for (i = 1; i <= LPFC_DRB_MAX; i++) |
| 2754 | len = lpfc_idiag_drbacc_read_reg(phba, |
| 2755 | pbuffer, len, i); |
| 2756 | else |
| 2757 | len = lpfc_idiag_drbacc_read_reg(phba, |
| 2758 | pbuffer, len, drb_reg_id); |
| 2759 | |
| 2760 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2761 | } |
| 2762 | |
| 2763 | /** |
| 2764 | * lpfc_idiag_drbacc_write - Syntax check and set up idiag drbacc commands |
| 2765 | * @file: The file pointer to read from. |
| 2766 | * @buf: The buffer to copy the user data from. |
| 2767 | * @nbytes: The number of bytes to get. |
| 2768 | * @ppos: The position in the file to start reading from. |
| 2769 | * |
| 2770 | * This routine get the debugfs idiag command struct from user space and then |
| 2771 | * perform the syntax check for port doorbell register read (dump) or write |
| 2772 | * (set) command accordingly. In the case of port queue read command, it sets |
| 2773 | * up the command in the idiag command struct for the following debugfs read |
| 2774 | * operation. In the case of port doorbell register write operation, it |
| 2775 | * executes the write operation into the port doorbell register accordingly. |
| 2776 | * |
| 2777 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 2778 | * In case of error conditions, it returns proper error code back to the user |
| 2779 | * space. |
| 2780 | **/ |
| 2781 | static ssize_t |
| 2782 | lpfc_idiag_drbacc_write(struct file *file, const char __user *buf, |
| 2783 | size_t nbytes, loff_t *ppos) |
| 2784 | { |
| 2785 | struct lpfc_debug *debug = file->private_data; |
| 2786 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2787 | uint32_t drb_reg_id, value, reg_val = 0; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2788 | void __iomem *drb_reg; |
| 2789 | int rc; |
| 2790 | |
| 2791 | /* This is a user write operation */ |
| 2792 | debug->op = LPFC_IDIAG_OP_WR; |
| 2793 | |
| 2794 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 2795 | if (rc < 0) |
| 2796 | return rc; |
| 2797 | |
| 2798 | /* Sanity check on command line arguments */ |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2799 | drb_reg_id = idiag.cmd.data[IDIAG_DRBACC_REGID_INDX]; |
| 2800 | value = idiag.cmd.data[IDIAG_DRBACC_VALUE_INDX]; |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 2801 | |
| 2802 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR || |
| 2803 | idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST || |
| 2804 | idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) { |
| 2805 | if (rc != LPFC_DRB_ACC_WR_CMD_ARG) |
| 2806 | goto error_out; |
| 2807 | if (drb_reg_id > LPFC_DRB_MAX) |
| 2808 | goto error_out; |
| 2809 | } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_RD) { |
| 2810 | if (rc != LPFC_DRB_ACC_RD_CMD_ARG) |
| 2811 | goto error_out; |
| 2812 | if ((drb_reg_id > LPFC_DRB_MAX) && |
| 2813 | (drb_reg_id != LPFC_DRB_ACC_ALL)) |
| 2814 | goto error_out; |
| 2815 | } else |
| 2816 | goto error_out; |
| 2817 | |
| 2818 | /* Perform the write access operation */ |
| 2819 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR || |
| 2820 | idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST || |
| 2821 | idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) { |
| 2822 | switch (drb_reg_id) { |
| 2823 | case LPFC_DRB_EQCQ: |
| 2824 | drb_reg = phba->sli4_hba.EQCQDBregaddr; |
| 2825 | break; |
| 2826 | case LPFC_DRB_MQ: |
| 2827 | drb_reg = phba->sli4_hba.MQDBregaddr; |
| 2828 | break; |
| 2829 | case LPFC_DRB_WQ: |
| 2830 | drb_reg = phba->sli4_hba.WQDBregaddr; |
| 2831 | break; |
| 2832 | case LPFC_DRB_RQ: |
| 2833 | drb_reg = phba->sli4_hba.RQDBregaddr; |
| 2834 | break; |
| 2835 | default: |
| 2836 | goto error_out; |
| 2837 | } |
| 2838 | |
| 2839 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_WR) |
| 2840 | reg_val = value; |
| 2841 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_ST) { |
| 2842 | reg_val = readl(drb_reg); |
| 2843 | reg_val |= value; |
| 2844 | } |
| 2845 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_DRBACC_CL) { |
| 2846 | reg_val = readl(drb_reg); |
| 2847 | reg_val &= ~value; |
| 2848 | } |
| 2849 | writel(reg_val, drb_reg); |
| 2850 | readl(drb_reg); /* flush */ |
| 2851 | } |
| 2852 | return nbytes; |
| 2853 | |
| 2854 | error_out: |
| 2855 | /* Clean out command structure on command error out */ |
| 2856 | memset(&idiag, 0, sizeof(idiag)); |
| 2857 | return -EINVAL; |
| 2858 | } |
| 2859 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 2860 | /** |
| 2861 | * lpfc_idiag_ctlacc_read_reg - idiag debugfs read a control registers |
| 2862 | * @phba: The pointer to hba structure. |
| 2863 | * @pbuffer: The pointer to the buffer to copy the data to. |
| 2864 | * @len: The lenght of bytes to copied. |
| 2865 | * @drbregid: The id to doorbell registers. |
| 2866 | * |
| 2867 | * Description: |
| 2868 | * This routine reads a control register and copies its content to the |
| 2869 | * user buffer pointed to by @pbuffer. |
| 2870 | * |
| 2871 | * Returns: |
| 2872 | * This function returns the amount of data that was copied into @pbuffer. |
| 2873 | **/ |
| 2874 | static int |
| 2875 | lpfc_idiag_ctlacc_read_reg(struct lpfc_hba *phba, char *pbuffer, |
| 2876 | int len, uint32_t ctlregid) |
| 2877 | { |
| 2878 | |
| 2879 | if (!pbuffer) |
| 2880 | return 0; |
| 2881 | |
| 2882 | switch (ctlregid) { |
| 2883 | case LPFC_CTL_PORT_SEM: |
| 2884 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2885 | "Port SemReg: 0x%08x\n", |
| 2886 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2887 | LPFC_CTL_PORT_SEM_OFFSET)); |
| 2888 | break; |
| 2889 | case LPFC_CTL_PORT_STA: |
| 2890 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2891 | "Port StaReg: 0x%08x\n", |
| 2892 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2893 | LPFC_CTL_PORT_STA_OFFSET)); |
| 2894 | break; |
| 2895 | case LPFC_CTL_PORT_CTL: |
| 2896 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2897 | "Port CtlReg: 0x%08x\n", |
| 2898 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2899 | LPFC_CTL_PORT_CTL_OFFSET)); |
| 2900 | break; |
| 2901 | case LPFC_CTL_PORT_ER1: |
| 2902 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2903 | "Port Er1Reg: 0x%08x\n", |
| 2904 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2905 | LPFC_CTL_PORT_ER1_OFFSET)); |
| 2906 | break; |
| 2907 | case LPFC_CTL_PORT_ER2: |
| 2908 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2909 | "Port Er2Reg: 0x%08x\n", |
| 2910 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2911 | LPFC_CTL_PORT_ER2_OFFSET)); |
| 2912 | break; |
| 2913 | case LPFC_CTL_PDEV_CTL: |
| 2914 | len += snprintf(pbuffer+len, LPFC_CTL_ACC_BUF_SIZE-len, |
| 2915 | "PDev CtlReg: 0x%08x\n", |
| 2916 | readl(phba->sli4_hba.conf_regs_memmap_p + |
| 2917 | LPFC_CTL_PDEV_CTL_OFFSET)); |
| 2918 | break; |
| 2919 | default: |
| 2920 | break; |
| 2921 | } |
| 2922 | return len; |
| 2923 | } |
| 2924 | |
| 2925 | /** |
| 2926 | * lpfc_idiag_ctlacc_read - idiag debugfs read port and device control register |
| 2927 | * @file: The file pointer to read from. |
| 2928 | * @buf: The buffer to copy the data to. |
| 2929 | * @nbytes: The number of bytes to read. |
| 2930 | * @ppos: The position in the file to start reading from. |
| 2931 | * |
| 2932 | * Description: |
| 2933 | * This routine reads data from the @phba port and device registers according |
| 2934 | * to the idiag command, and copies to user @buf. |
| 2935 | * |
| 2936 | * Returns: |
| 2937 | * This function returns the amount of data that was read (this could be less |
| 2938 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 2939 | **/ |
| 2940 | static ssize_t |
| 2941 | lpfc_idiag_ctlacc_read(struct file *file, char __user *buf, size_t nbytes, |
| 2942 | loff_t *ppos) |
| 2943 | { |
| 2944 | struct lpfc_debug *debug = file->private_data; |
| 2945 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 2946 | uint32_t ctl_reg_id, i; |
| 2947 | char *pbuffer; |
| 2948 | int len = 0; |
| 2949 | |
| 2950 | /* This is a user read operation */ |
| 2951 | debug->op = LPFC_IDIAG_OP_RD; |
| 2952 | |
| 2953 | if (!debug->buffer) |
| 2954 | debug->buffer = kmalloc(LPFC_CTL_ACC_BUF_SIZE, GFP_KERNEL); |
| 2955 | if (!debug->buffer) |
| 2956 | return 0; |
| 2957 | pbuffer = debug->buffer; |
| 2958 | |
| 2959 | if (*ppos) |
| 2960 | return 0; |
| 2961 | |
| 2962 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) |
| 2963 | ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX]; |
| 2964 | else |
| 2965 | return 0; |
| 2966 | |
| 2967 | if (ctl_reg_id == LPFC_CTL_ACC_ALL) |
| 2968 | for (i = 1; i <= LPFC_CTL_MAX; i++) |
| 2969 | len = lpfc_idiag_ctlacc_read_reg(phba, |
| 2970 | pbuffer, len, i); |
| 2971 | else |
| 2972 | len = lpfc_idiag_ctlacc_read_reg(phba, |
| 2973 | pbuffer, len, ctl_reg_id); |
| 2974 | |
| 2975 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 2976 | } |
| 2977 | |
| 2978 | /** |
| 2979 | * lpfc_idiag_ctlacc_write - Syntax check and set up idiag ctlacc commands |
| 2980 | * @file: The file pointer to read from. |
| 2981 | * @buf: The buffer to copy the user data from. |
| 2982 | * @nbytes: The number of bytes to get. |
| 2983 | * @ppos: The position in the file to start reading from. |
| 2984 | * |
| 2985 | * This routine get the debugfs idiag command struct from user space and then |
| 2986 | * perform the syntax check for port and device control register read (dump) |
| 2987 | * or write (set) command accordingly. |
| 2988 | * |
| 2989 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 2990 | * In case of error conditions, it returns proper error code back to the user |
| 2991 | * space. |
| 2992 | **/ |
| 2993 | static ssize_t |
| 2994 | lpfc_idiag_ctlacc_write(struct file *file, const char __user *buf, |
| 2995 | size_t nbytes, loff_t *ppos) |
| 2996 | { |
| 2997 | struct lpfc_debug *debug = file->private_data; |
| 2998 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 2999 | uint32_t ctl_reg_id, value, reg_val = 0; |
| 3000 | void __iomem *ctl_reg; |
| 3001 | int rc; |
| 3002 | |
| 3003 | /* This is a user write operation */ |
| 3004 | debug->op = LPFC_IDIAG_OP_WR; |
| 3005 | |
| 3006 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 3007 | if (rc < 0) |
| 3008 | return rc; |
| 3009 | |
| 3010 | /* Sanity check on command line arguments */ |
| 3011 | ctl_reg_id = idiag.cmd.data[IDIAG_CTLACC_REGID_INDX]; |
| 3012 | value = idiag.cmd.data[IDIAG_CTLACC_VALUE_INDX]; |
| 3013 | |
| 3014 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR || |
| 3015 | idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST || |
| 3016 | idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) { |
| 3017 | if (rc != LPFC_CTL_ACC_WR_CMD_ARG) |
| 3018 | goto error_out; |
| 3019 | if (ctl_reg_id > LPFC_CTL_MAX) |
| 3020 | goto error_out; |
| 3021 | } else if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_RD) { |
| 3022 | if (rc != LPFC_CTL_ACC_RD_CMD_ARG) |
| 3023 | goto error_out; |
| 3024 | if ((ctl_reg_id > LPFC_CTL_MAX) && |
| 3025 | (ctl_reg_id != LPFC_CTL_ACC_ALL)) |
| 3026 | goto error_out; |
| 3027 | } else |
| 3028 | goto error_out; |
| 3029 | |
| 3030 | /* Perform the write access operation */ |
| 3031 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR || |
| 3032 | idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST || |
| 3033 | idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) { |
| 3034 | switch (ctl_reg_id) { |
| 3035 | case LPFC_CTL_PORT_SEM: |
| 3036 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3037 | LPFC_CTL_PORT_SEM_OFFSET; |
| 3038 | break; |
| 3039 | case LPFC_CTL_PORT_STA: |
| 3040 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3041 | LPFC_CTL_PORT_STA_OFFSET; |
| 3042 | break; |
| 3043 | case LPFC_CTL_PORT_CTL: |
| 3044 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3045 | LPFC_CTL_PORT_CTL_OFFSET; |
| 3046 | break; |
| 3047 | case LPFC_CTL_PORT_ER1: |
| 3048 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3049 | LPFC_CTL_PORT_ER1_OFFSET; |
| 3050 | break; |
| 3051 | case LPFC_CTL_PORT_ER2: |
| 3052 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3053 | LPFC_CTL_PORT_ER2_OFFSET; |
| 3054 | break; |
| 3055 | case LPFC_CTL_PDEV_CTL: |
| 3056 | ctl_reg = phba->sli4_hba.conf_regs_memmap_p + |
| 3057 | LPFC_CTL_PDEV_CTL_OFFSET; |
| 3058 | break; |
| 3059 | default: |
| 3060 | goto error_out; |
| 3061 | } |
| 3062 | |
| 3063 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_WR) |
| 3064 | reg_val = value; |
| 3065 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_ST) { |
| 3066 | reg_val = readl(ctl_reg); |
| 3067 | reg_val |= value; |
| 3068 | } |
| 3069 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_CTLACC_CL) { |
| 3070 | reg_val = readl(ctl_reg); |
| 3071 | reg_val &= ~value; |
| 3072 | } |
| 3073 | writel(reg_val, ctl_reg); |
| 3074 | readl(ctl_reg); /* flush */ |
| 3075 | } |
| 3076 | return nbytes; |
| 3077 | |
| 3078 | error_out: |
| 3079 | /* Clean out command structure on command error out */ |
| 3080 | memset(&idiag, 0, sizeof(idiag)); |
| 3081 | return -EINVAL; |
| 3082 | } |
| 3083 | |
| 3084 | /** |
| 3085 | * lpfc_idiag_mbxacc_get_setup - idiag debugfs get mailbox access setup |
| 3086 | * @phba: Pointer to HBA context object. |
| 3087 | * @pbuffer: Pointer to data buffer. |
| 3088 | * |
| 3089 | * Description: |
| 3090 | * This routine gets the driver mailbox access debugfs setup information. |
| 3091 | * |
| 3092 | * Returns: |
| 3093 | * This function returns the amount of data that was read (this could be less |
| 3094 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 3095 | **/ |
| 3096 | static int |
| 3097 | lpfc_idiag_mbxacc_get_setup(struct lpfc_hba *phba, char *pbuffer) |
| 3098 | { |
| 3099 | uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd; |
| 3100 | int len = 0; |
| 3101 | |
| 3102 | mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX]; |
| 3103 | mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX]; |
| 3104 | mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX]; |
| 3105 | mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX]; |
| 3106 | |
| 3107 | len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len, |
| 3108 | "mbx_dump_map: 0x%08x\n", mbx_dump_map); |
| 3109 | len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len, |
| 3110 | "mbx_dump_cnt: %04d\n", mbx_dump_cnt); |
| 3111 | len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len, |
| 3112 | "mbx_word_cnt: %04d\n", mbx_word_cnt); |
| 3113 | len += snprintf(pbuffer+len, LPFC_MBX_ACC_BUF_SIZE-len, |
| 3114 | "mbx_mbox_cmd: 0x%02x\n", mbx_mbox_cmd); |
| 3115 | |
| 3116 | return len; |
| 3117 | } |
| 3118 | |
| 3119 | /** |
| 3120 | * lpfc_idiag_mbxacc_read - idiag debugfs read on mailbox access |
| 3121 | * @file: The file pointer to read from. |
| 3122 | * @buf: The buffer to copy the data to. |
| 3123 | * @nbytes: The number of bytes to read. |
| 3124 | * @ppos: The position in the file to start reading from. |
| 3125 | * |
| 3126 | * Description: |
| 3127 | * This routine reads data from the @phba driver mailbox access debugfs setup |
| 3128 | * information. |
| 3129 | * |
| 3130 | * Returns: |
| 3131 | * This function returns the amount of data that was read (this could be less |
| 3132 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 3133 | **/ |
| 3134 | static ssize_t |
| 3135 | lpfc_idiag_mbxacc_read(struct file *file, char __user *buf, size_t nbytes, |
| 3136 | loff_t *ppos) |
| 3137 | { |
| 3138 | struct lpfc_debug *debug = file->private_data; |
| 3139 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 3140 | char *pbuffer; |
| 3141 | int len = 0; |
| 3142 | |
| 3143 | /* This is a user read operation */ |
| 3144 | debug->op = LPFC_IDIAG_OP_RD; |
| 3145 | |
| 3146 | if (!debug->buffer) |
| 3147 | debug->buffer = kmalloc(LPFC_MBX_ACC_BUF_SIZE, GFP_KERNEL); |
| 3148 | if (!debug->buffer) |
| 3149 | return 0; |
| 3150 | pbuffer = debug->buffer; |
| 3151 | |
| 3152 | if (*ppos) |
| 3153 | return 0; |
| 3154 | |
| 3155 | if ((idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) && |
| 3156 | (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP)) |
| 3157 | return 0; |
| 3158 | |
| 3159 | len = lpfc_idiag_mbxacc_get_setup(phba, pbuffer); |
| 3160 | |
| 3161 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 3162 | } |
| 3163 | |
| 3164 | /** |
| 3165 | * lpfc_idiag_mbxacc_write - Syntax check and set up idiag mbxacc commands |
| 3166 | * @file: The file pointer to read from. |
| 3167 | * @buf: The buffer to copy the user data from. |
| 3168 | * @nbytes: The number of bytes to get. |
| 3169 | * @ppos: The position in the file to start reading from. |
| 3170 | * |
| 3171 | * This routine get the debugfs idiag command struct from user space and then |
| 3172 | * perform the syntax check for driver mailbox command (dump) and sets up the |
| 3173 | * necessary states in the idiag command struct accordingly. |
| 3174 | * |
| 3175 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 3176 | * In case of error conditions, it returns proper error code back to the user |
| 3177 | * space. |
| 3178 | **/ |
| 3179 | static ssize_t |
| 3180 | lpfc_idiag_mbxacc_write(struct file *file, const char __user *buf, |
| 3181 | size_t nbytes, loff_t *ppos) |
| 3182 | { |
| 3183 | struct lpfc_debug *debug = file->private_data; |
| 3184 | uint32_t mbx_dump_map, mbx_dump_cnt, mbx_word_cnt, mbx_mbox_cmd; |
| 3185 | int rc; |
| 3186 | |
| 3187 | /* This is a user write operation */ |
| 3188 | debug->op = LPFC_IDIAG_OP_WR; |
| 3189 | |
| 3190 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 3191 | if (rc < 0) |
| 3192 | return rc; |
| 3193 | |
| 3194 | /* Sanity check on command line arguments */ |
| 3195 | mbx_mbox_cmd = idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX]; |
| 3196 | mbx_dump_map = idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX]; |
| 3197 | mbx_dump_cnt = idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX]; |
| 3198 | mbx_word_cnt = idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX]; |
| 3199 | |
| 3200 | if (idiag.cmd.opcode == LPFC_IDIAG_CMD_MBXACC_DP) { |
| 3201 | if (!(mbx_dump_map & LPFC_MBX_DMP_MBX_ALL)) |
| 3202 | goto error_out; |
| 3203 | if ((mbx_dump_map & ~LPFC_MBX_DMP_MBX_ALL) && |
| 3204 | (mbx_dump_map != LPFC_MBX_DMP_ALL)) |
| 3205 | goto error_out; |
| 3206 | if (mbx_word_cnt > sizeof(MAILBOX_t)) |
| 3207 | goto error_out; |
| 3208 | } else if (idiag.cmd.opcode == LPFC_IDIAG_BSG_MBXACC_DP) { |
| 3209 | if (!(mbx_dump_map & LPFC_BSG_DMP_MBX_ALL)) |
| 3210 | goto error_out; |
| 3211 | if ((mbx_dump_map & ~LPFC_BSG_DMP_MBX_ALL) && |
| 3212 | (mbx_dump_map != LPFC_MBX_DMP_ALL)) |
| 3213 | goto error_out; |
| 3214 | if (mbx_word_cnt > (BSG_MBOX_SIZE)/4) |
| 3215 | goto error_out; |
| 3216 | if (mbx_mbox_cmd != 0x9b) |
| 3217 | goto error_out; |
| 3218 | } else |
| 3219 | goto error_out; |
| 3220 | |
| 3221 | if (mbx_word_cnt == 0) |
| 3222 | goto error_out; |
| 3223 | if (rc != LPFC_MBX_DMP_ARG) |
| 3224 | goto error_out; |
| 3225 | if (mbx_mbox_cmd & ~0xff) |
| 3226 | goto error_out; |
| 3227 | |
| 3228 | /* condition for stop mailbox dump */ |
| 3229 | if (mbx_dump_cnt == 0) |
| 3230 | goto reset_out; |
| 3231 | |
| 3232 | return nbytes; |
| 3233 | |
| 3234 | reset_out: |
| 3235 | /* Clean out command structure on command error out */ |
| 3236 | memset(&idiag, 0, sizeof(idiag)); |
| 3237 | return nbytes; |
| 3238 | |
| 3239 | error_out: |
| 3240 | /* Clean out command structure on command error out */ |
| 3241 | memset(&idiag, 0, sizeof(idiag)); |
| 3242 | return -EINVAL; |
| 3243 | } |
| 3244 | |
| 3245 | /** |
| 3246 | * lpfc_idiag_extacc_avail_get - get the available extents information |
| 3247 | * @phba: pointer to lpfc hba data structure. |
| 3248 | * @pbuffer: pointer to internal buffer. |
| 3249 | * @len: length into the internal buffer data has been copied. |
| 3250 | * |
| 3251 | * Description: |
| 3252 | * This routine is to get the available extent information. |
| 3253 | * |
| 3254 | * Returns: |
| 3255 | * overall lenth of the data read into the internal buffer. |
| 3256 | **/ |
| 3257 | static int |
| 3258 | lpfc_idiag_extacc_avail_get(struct lpfc_hba *phba, char *pbuffer, int len) |
| 3259 | { |
| 3260 | uint16_t ext_cnt, ext_size; |
| 3261 | |
| 3262 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3263 | "\nAvailable Extents Information:\n"); |
| 3264 | |
| 3265 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3266 | "\tPort Available VPI extents: "); |
| 3267 | lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VPI, |
| 3268 | &ext_cnt, &ext_size); |
| 3269 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3270 | "Count %3d, Size %3d\n", ext_cnt, ext_size); |
| 3271 | |
| 3272 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3273 | "\tPort Available VFI extents: "); |
| 3274 | lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_VFI, |
| 3275 | &ext_cnt, &ext_size); |
| 3276 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3277 | "Count %3d, Size %3d\n", ext_cnt, ext_size); |
| 3278 | |
| 3279 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3280 | "\tPort Available RPI extents: "); |
| 3281 | lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_RPI, |
| 3282 | &ext_cnt, &ext_size); |
| 3283 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3284 | "Count %3d, Size %3d\n", ext_cnt, ext_size); |
| 3285 | |
| 3286 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3287 | "\tPort Available XRI extents: "); |
| 3288 | lpfc_sli4_get_avail_extnt_rsrc(phba, LPFC_RSC_TYPE_FCOE_XRI, |
| 3289 | &ext_cnt, &ext_size); |
| 3290 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3291 | "Count %3d, Size %3d\n", ext_cnt, ext_size); |
| 3292 | |
| 3293 | return len; |
| 3294 | } |
| 3295 | |
| 3296 | /** |
| 3297 | * lpfc_idiag_extacc_alloc_get - get the allocated extents information |
| 3298 | * @phba: pointer to lpfc hba data structure. |
| 3299 | * @pbuffer: pointer to internal buffer. |
| 3300 | * @len: length into the internal buffer data has been copied. |
| 3301 | * |
| 3302 | * Description: |
| 3303 | * This routine is to get the allocated extent information. |
| 3304 | * |
| 3305 | * Returns: |
| 3306 | * overall lenth of the data read into the internal buffer. |
| 3307 | **/ |
| 3308 | static int |
| 3309 | lpfc_idiag_extacc_alloc_get(struct lpfc_hba *phba, char *pbuffer, int len) |
| 3310 | { |
| 3311 | uint16_t ext_cnt, ext_size; |
| 3312 | int rc; |
| 3313 | |
| 3314 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3315 | "\nAllocated Extents Information:\n"); |
| 3316 | |
| 3317 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3318 | "\tHost Allocated VPI extents: "); |
| 3319 | rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VPI, |
| 3320 | &ext_cnt, &ext_size); |
| 3321 | if (!rc) |
| 3322 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3323 | "Port %d Extent %3d, Size %3d\n", |
| 3324 | phba->brd_no, ext_cnt, ext_size); |
| 3325 | else |
| 3326 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3327 | "N/A\n"); |
| 3328 | |
| 3329 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3330 | "\tHost Allocated VFI extents: "); |
| 3331 | rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_VFI, |
| 3332 | &ext_cnt, &ext_size); |
| 3333 | if (!rc) |
| 3334 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3335 | "Port %d Extent %3d, Size %3d\n", |
| 3336 | phba->brd_no, ext_cnt, ext_size); |
| 3337 | else |
| 3338 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3339 | "N/A\n"); |
| 3340 | |
| 3341 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3342 | "\tHost Allocated RPI extents: "); |
| 3343 | rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_RPI, |
| 3344 | &ext_cnt, &ext_size); |
| 3345 | if (!rc) |
| 3346 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3347 | "Port %d Extent %3d, Size %3d\n", |
| 3348 | phba->brd_no, ext_cnt, ext_size); |
| 3349 | else |
| 3350 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3351 | "N/A\n"); |
| 3352 | |
| 3353 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3354 | "\tHost Allocated XRI extents: "); |
| 3355 | rc = lpfc_sli4_get_allocated_extnts(phba, LPFC_RSC_TYPE_FCOE_XRI, |
| 3356 | &ext_cnt, &ext_size); |
| 3357 | if (!rc) |
| 3358 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3359 | "Port %d Extent %3d, Size %3d\n", |
| 3360 | phba->brd_no, ext_cnt, ext_size); |
| 3361 | else |
| 3362 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3363 | "N/A\n"); |
| 3364 | |
| 3365 | return len; |
| 3366 | } |
| 3367 | |
| 3368 | /** |
| 3369 | * lpfc_idiag_extacc_drivr_get - get driver extent information |
| 3370 | * @phba: pointer to lpfc hba data structure. |
| 3371 | * @pbuffer: pointer to internal buffer. |
| 3372 | * @len: length into the internal buffer data has been copied. |
| 3373 | * |
| 3374 | * Description: |
| 3375 | * This routine is to get the driver extent information. |
| 3376 | * |
| 3377 | * Returns: |
| 3378 | * overall lenth of the data read into the internal buffer. |
| 3379 | **/ |
| 3380 | static int |
| 3381 | lpfc_idiag_extacc_drivr_get(struct lpfc_hba *phba, char *pbuffer, int len) |
| 3382 | { |
| 3383 | struct lpfc_rsrc_blks *rsrc_blks; |
| 3384 | int index; |
| 3385 | |
| 3386 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3387 | "\nDriver Extents Information:\n"); |
| 3388 | |
| 3389 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3390 | "\tVPI extents:\n"); |
| 3391 | index = 0; |
| 3392 | list_for_each_entry(rsrc_blks, &phba->lpfc_vpi_blk_list, list) { |
| 3393 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3394 | "\t\tBlock %3d: Start %4d, Count %4d\n", |
| 3395 | index, rsrc_blks->rsrc_start, |
| 3396 | rsrc_blks->rsrc_size); |
| 3397 | index++; |
| 3398 | } |
| 3399 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3400 | "\tVFI extents:\n"); |
| 3401 | index = 0; |
| 3402 | list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_vfi_blk_list, |
| 3403 | list) { |
| 3404 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3405 | "\t\tBlock %3d: Start %4d, Count %4d\n", |
| 3406 | index, rsrc_blks->rsrc_start, |
| 3407 | rsrc_blks->rsrc_size); |
| 3408 | index++; |
| 3409 | } |
| 3410 | |
| 3411 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3412 | "\tRPI extents:\n"); |
| 3413 | index = 0; |
| 3414 | list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_rpi_blk_list, |
| 3415 | list) { |
| 3416 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3417 | "\t\tBlock %3d: Start %4d, Count %4d\n", |
| 3418 | index, rsrc_blks->rsrc_start, |
| 3419 | rsrc_blks->rsrc_size); |
| 3420 | index++; |
| 3421 | } |
| 3422 | |
| 3423 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3424 | "\tXRI extents:\n"); |
| 3425 | index = 0; |
| 3426 | list_for_each_entry(rsrc_blks, &phba->sli4_hba.lpfc_xri_blk_list, |
| 3427 | list) { |
| 3428 | len += snprintf(pbuffer+len, LPFC_EXT_ACC_BUF_SIZE-len, |
| 3429 | "\t\tBlock %3d: Start %4d, Count %4d\n", |
| 3430 | index, rsrc_blks->rsrc_start, |
| 3431 | rsrc_blks->rsrc_size); |
| 3432 | index++; |
| 3433 | } |
| 3434 | |
| 3435 | return len; |
| 3436 | } |
| 3437 | |
| 3438 | /** |
| 3439 | * lpfc_idiag_extacc_write - Syntax check and set up idiag extacc commands |
| 3440 | * @file: The file pointer to read from. |
| 3441 | * @buf: The buffer to copy the user data from. |
| 3442 | * @nbytes: The number of bytes to get. |
| 3443 | * @ppos: The position in the file to start reading from. |
| 3444 | * |
| 3445 | * This routine get the debugfs idiag command struct from user space and then |
| 3446 | * perform the syntax check for extent information access commands and sets |
| 3447 | * up the necessary states in the idiag command struct accordingly. |
| 3448 | * |
| 3449 | * It returns the @nbytges passing in from debugfs user space when successful. |
| 3450 | * In case of error conditions, it returns proper error code back to the user |
| 3451 | * space. |
| 3452 | **/ |
| 3453 | static ssize_t |
| 3454 | lpfc_idiag_extacc_write(struct file *file, const char __user *buf, |
| 3455 | size_t nbytes, loff_t *ppos) |
| 3456 | { |
| 3457 | struct lpfc_debug *debug = file->private_data; |
| 3458 | uint32_t ext_map; |
| 3459 | int rc; |
| 3460 | |
| 3461 | /* This is a user write operation */ |
| 3462 | debug->op = LPFC_IDIAG_OP_WR; |
| 3463 | |
| 3464 | rc = lpfc_idiag_cmd_get(buf, nbytes, &idiag.cmd); |
| 3465 | if (rc < 0) |
| 3466 | return rc; |
| 3467 | |
| 3468 | ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX]; |
| 3469 | |
| 3470 | if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD) |
| 3471 | goto error_out; |
| 3472 | if (rc != LPFC_EXT_ACC_CMD_ARG) |
| 3473 | goto error_out; |
| 3474 | if (!(ext_map & LPFC_EXT_ACC_ALL)) |
| 3475 | goto error_out; |
| 3476 | |
| 3477 | return nbytes; |
| 3478 | error_out: |
| 3479 | /* Clean out command structure on command error out */ |
| 3480 | memset(&idiag, 0, sizeof(idiag)); |
| 3481 | return -EINVAL; |
| 3482 | } |
| 3483 | |
| 3484 | /** |
| 3485 | * lpfc_idiag_extacc_read - idiag debugfs read access to extent information |
| 3486 | * @file: The file pointer to read from. |
| 3487 | * @buf: The buffer to copy the data to. |
| 3488 | * @nbytes: The number of bytes to read. |
| 3489 | * @ppos: The position in the file to start reading from. |
| 3490 | * |
| 3491 | * Description: |
| 3492 | * This routine reads data from the proper extent information according to |
| 3493 | * the idiag command, and copies to user @buf. |
| 3494 | * |
| 3495 | * Returns: |
| 3496 | * This function returns the amount of data that was read (this could be less |
| 3497 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 3498 | **/ |
| 3499 | static ssize_t |
| 3500 | lpfc_idiag_extacc_read(struct file *file, char __user *buf, size_t nbytes, |
| 3501 | loff_t *ppos) |
| 3502 | { |
| 3503 | struct lpfc_debug *debug = file->private_data; |
| 3504 | struct lpfc_hba *phba = (struct lpfc_hba *)debug->i_private; |
| 3505 | char *pbuffer; |
| 3506 | uint32_t ext_map; |
| 3507 | int len = 0; |
| 3508 | |
| 3509 | /* This is a user read operation */ |
| 3510 | debug->op = LPFC_IDIAG_OP_RD; |
| 3511 | |
| 3512 | if (!debug->buffer) |
| 3513 | debug->buffer = kmalloc(LPFC_EXT_ACC_BUF_SIZE, GFP_KERNEL); |
| 3514 | if (!debug->buffer) |
| 3515 | return 0; |
| 3516 | pbuffer = debug->buffer; |
| 3517 | if (*ppos) |
| 3518 | return 0; |
| 3519 | if (idiag.cmd.opcode != LPFC_IDIAG_CMD_EXTACC_RD) |
| 3520 | return 0; |
| 3521 | |
| 3522 | ext_map = idiag.cmd.data[IDIAG_EXTACC_EXMAP_INDX]; |
| 3523 | if (ext_map & LPFC_EXT_ACC_AVAIL) |
| 3524 | len = lpfc_idiag_extacc_avail_get(phba, pbuffer, len); |
| 3525 | if (ext_map & LPFC_EXT_ACC_ALLOC) |
| 3526 | len = lpfc_idiag_extacc_alloc_get(phba, pbuffer, len); |
| 3527 | if (ext_map & LPFC_EXT_ACC_DRIVR) |
| 3528 | len = lpfc_idiag_extacc_drivr_get(phba, pbuffer, len); |
| 3529 | |
| 3530 | return simple_read_from_buffer(buf, nbytes, ppos, pbuffer, len); |
| 3531 | } |
| 3532 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3533 | #undef lpfc_debugfs_op_disc_trc |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3534 | static const struct file_operations lpfc_debugfs_op_disc_trc = { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3535 | .owner = THIS_MODULE, |
| 3536 | .open = lpfc_debugfs_disc_trc_open, |
| 3537 | .llseek = lpfc_debugfs_lseek, |
| 3538 | .read = lpfc_debugfs_read, |
| 3539 | .release = lpfc_debugfs_release, |
| 3540 | }; |
| 3541 | |
| 3542 | #undef lpfc_debugfs_op_nodelist |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3543 | static const struct file_operations lpfc_debugfs_op_nodelist = { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3544 | .owner = THIS_MODULE, |
| 3545 | .open = lpfc_debugfs_nodelist_open, |
| 3546 | .llseek = lpfc_debugfs_lseek, |
| 3547 | .read = lpfc_debugfs_read, |
| 3548 | .release = lpfc_debugfs_release, |
| 3549 | }; |
| 3550 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3551 | #undef lpfc_debugfs_op_hbqinfo |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3552 | static const struct file_operations lpfc_debugfs_op_hbqinfo = { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3553 | .owner = THIS_MODULE, |
| 3554 | .open = lpfc_debugfs_hbqinfo_open, |
| 3555 | .llseek = lpfc_debugfs_lseek, |
| 3556 | .read = lpfc_debugfs_read, |
| 3557 | .release = lpfc_debugfs_release, |
| 3558 | }; |
| 3559 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 3560 | #undef lpfc_debugfs_op_dumpHBASlim |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3561 | static const struct file_operations lpfc_debugfs_op_dumpHBASlim = { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3562 | .owner = THIS_MODULE, |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 3563 | .open = lpfc_debugfs_dumpHBASlim_open, |
| 3564 | .llseek = lpfc_debugfs_lseek, |
| 3565 | .read = lpfc_debugfs_read, |
| 3566 | .release = lpfc_debugfs_release, |
| 3567 | }; |
| 3568 | |
| 3569 | #undef lpfc_debugfs_op_dumpHostSlim |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3570 | static const struct file_operations lpfc_debugfs_op_dumpHostSlim = { |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 3571 | .owner = THIS_MODULE, |
| 3572 | .open = lpfc_debugfs_dumpHostSlim_open, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3573 | .llseek = lpfc_debugfs_lseek, |
| 3574 | .read = lpfc_debugfs_read, |
| 3575 | .release = lpfc_debugfs_release, |
| 3576 | }; |
| 3577 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3578 | #undef lpfc_debugfs_op_dumpData |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3579 | static const struct file_operations lpfc_debugfs_op_dumpData = { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3580 | .owner = THIS_MODULE, |
| 3581 | .open = lpfc_debugfs_dumpData_open, |
| 3582 | .llseek = lpfc_debugfs_lseek, |
| 3583 | .read = lpfc_debugfs_read, |
| 3584 | .write = lpfc_debugfs_dumpDataDif_write, |
| 3585 | .release = lpfc_debugfs_dumpDataDif_release, |
| 3586 | }; |
| 3587 | |
| 3588 | #undef lpfc_debugfs_op_dumpDif |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3589 | static const struct file_operations lpfc_debugfs_op_dumpDif = { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3590 | .owner = THIS_MODULE, |
| 3591 | .open = lpfc_debugfs_dumpDif_open, |
| 3592 | .llseek = lpfc_debugfs_lseek, |
| 3593 | .read = lpfc_debugfs_read, |
| 3594 | .write = lpfc_debugfs_dumpDataDif_write, |
| 3595 | .release = lpfc_debugfs_dumpDataDif_release, |
| 3596 | }; |
| 3597 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3598 | #undef lpfc_debugfs_op_dif_err |
| 3599 | static const struct file_operations lpfc_debugfs_op_dif_err = { |
| 3600 | .owner = THIS_MODULE, |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 3601 | .open = simple_open, |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 3602 | .llseek = lpfc_debugfs_lseek, |
| 3603 | .read = lpfc_debugfs_dif_err_read, |
| 3604 | .write = lpfc_debugfs_dif_err_write, |
| 3605 | .release = lpfc_debugfs_dif_err_release, |
| 3606 | }; |
| 3607 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3608 | #undef lpfc_debugfs_op_slow_ring_trc |
Jan Engelhardt | 71fa742 | 2009-01-11 10:38:59 +0100 | [diff] [blame] | 3609 | static const struct file_operations lpfc_debugfs_op_slow_ring_trc = { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3610 | .owner = THIS_MODULE, |
| 3611 | .open = lpfc_debugfs_slow_ring_trc_open, |
| 3612 | .llseek = lpfc_debugfs_lseek, |
| 3613 | .read = lpfc_debugfs_read, |
| 3614 | .release = lpfc_debugfs_release, |
| 3615 | }; |
| 3616 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3617 | static struct dentry *lpfc_debugfs_root = NULL; |
| 3618 | static atomic_t lpfc_debugfs_hba_count; |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 3619 | |
| 3620 | /* |
| 3621 | * File operations for the iDiag debugfs |
| 3622 | */ |
| 3623 | #undef lpfc_idiag_op_pciCfg |
| 3624 | static const struct file_operations lpfc_idiag_op_pciCfg = { |
| 3625 | .owner = THIS_MODULE, |
| 3626 | .open = lpfc_idiag_open, |
| 3627 | .llseek = lpfc_debugfs_lseek, |
| 3628 | .read = lpfc_idiag_pcicfg_read, |
| 3629 | .write = lpfc_idiag_pcicfg_write, |
| 3630 | .release = lpfc_idiag_cmd_release, |
| 3631 | }; |
| 3632 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3633 | #undef lpfc_idiag_op_barAcc |
| 3634 | static const struct file_operations lpfc_idiag_op_barAcc = { |
| 3635 | .owner = THIS_MODULE, |
| 3636 | .open = lpfc_idiag_open, |
| 3637 | .llseek = lpfc_debugfs_lseek, |
| 3638 | .read = lpfc_idiag_baracc_read, |
| 3639 | .write = lpfc_idiag_baracc_write, |
| 3640 | .release = lpfc_idiag_cmd_release, |
| 3641 | }; |
| 3642 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 3643 | #undef lpfc_idiag_op_queInfo |
| 3644 | static const struct file_operations lpfc_idiag_op_queInfo = { |
| 3645 | .owner = THIS_MODULE, |
| 3646 | .open = lpfc_idiag_open, |
| 3647 | .read = lpfc_idiag_queinfo_read, |
| 3648 | .release = lpfc_idiag_release, |
| 3649 | }; |
| 3650 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3651 | #undef lpfc_idiag_op_queAcc |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 3652 | static const struct file_operations lpfc_idiag_op_queAcc = { |
| 3653 | .owner = THIS_MODULE, |
| 3654 | .open = lpfc_idiag_open, |
| 3655 | .llseek = lpfc_debugfs_lseek, |
| 3656 | .read = lpfc_idiag_queacc_read, |
| 3657 | .write = lpfc_idiag_queacc_write, |
| 3658 | .release = lpfc_idiag_cmd_release, |
| 3659 | }; |
| 3660 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3661 | #undef lpfc_idiag_op_drbAcc |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 3662 | static const struct file_operations lpfc_idiag_op_drbAcc = { |
| 3663 | .owner = THIS_MODULE, |
| 3664 | .open = lpfc_idiag_open, |
| 3665 | .llseek = lpfc_debugfs_lseek, |
| 3666 | .read = lpfc_idiag_drbacc_read, |
| 3667 | .write = lpfc_idiag_drbacc_write, |
| 3668 | .release = lpfc_idiag_cmd_release, |
| 3669 | }; |
| 3670 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3671 | #undef lpfc_idiag_op_ctlAcc |
| 3672 | static const struct file_operations lpfc_idiag_op_ctlAcc = { |
| 3673 | .owner = THIS_MODULE, |
| 3674 | .open = lpfc_idiag_open, |
| 3675 | .llseek = lpfc_debugfs_lseek, |
| 3676 | .read = lpfc_idiag_ctlacc_read, |
| 3677 | .write = lpfc_idiag_ctlacc_write, |
| 3678 | .release = lpfc_idiag_cmd_release, |
| 3679 | }; |
| 3680 | |
| 3681 | #undef lpfc_idiag_op_mbxAcc |
| 3682 | static const struct file_operations lpfc_idiag_op_mbxAcc = { |
| 3683 | .owner = THIS_MODULE, |
| 3684 | .open = lpfc_idiag_open, |
| 3685 | .llseek = lpfc_debugfs_lseek, |
| 3686 | .read = lpfc_idiag_mbxacc_read, |
| 3687 | .write = lpfc_idiag_mbxacc_write, |
| 3688 | .release = lpfc_idiag_cmd_release, |
| 3689 | }; |
| 3690 | |
| 3691 | #undef lpfc_idiag_op_extAcc |
| 3692 | static const struct file_operations lpfc_idiag_op_extAcc = { |
| 3693 | .owner = THIS_MODULE, |
| 3694 | .open = lpfc_idiag_open, |
| 3695 | .llseek = lpfc_debugfs_lseek, |
| 3696 | .read = lpfc_idiag_extacc_read, |
| 3697 | .write = lpfc_idiag_extacc_write, |
| 3698 | .release = lpfc_idiag_cmd_release, |
| 3699 | }; |
| 3700 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3701 | #endif |
| 3702 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3703 | /* lpfc_idiag_mbxacc_dump_bsg_mbox - idiag debugfs dump bsg mailbox command |
| 3704 | * @phba: Pointer to HBA context object. |
| 3705 | * @dmabuf: Pointer to a DMA buffer descriptor. |
| 3706 | * |
| 3707 | * Description: |
| 3708 | * This routine dump a bsg pass-through non-embedded mailbox command with |
| 3709 | * external buffer. |
| 3710 | **/ |
| 3711 | void |
| 3712 | lpfc_idiag_mbxacc_dump_bsg_mbox(struct lpfc_hba *phba, enum nemb_type nemb_tp, |
| 3713 | enum mbox_type mbox_tp, enum dma_type dma_tp, |
| 3714 | enum sta_type sta_tp, |
| 3715 | struct lpfc_dmabuf *dmabuf, uint32_t ext_buf) |
| 3716 | { |
| 3717 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3718 | uint32_t *mbx_mbox_cmd, *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt; |
| 3719 | char line_buf[LPFC_MBX_ACC_LBUF_SZ]; |
| 3720 | int len = 0; |
| 3721 | uint32_t do_dump = 0; |
| 3722 | uint32_t *pword; |
| 3723 | uint32_t i; |
| 3724 | |
| 3725 | if (idiag.cmd.opcode != LPFC_IDIAG_BSG_MBXACC_DP) |
| 3726 | return; |
| 3727 | |
| 3728 | mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX]; |
| 3729 | mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX]; |
| 3730 | mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX]; |
| 3731 | mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX]; |
| 3732 | |
| 3733 | if (!(*mbx_dump_map & LPFC_MBX_DMP_ALL) || |
| 3734 | (*mbx_dump_cnt == 0) || |
| 3735 | (*mbx_word_cnt == 0)) |
| 3736 | return; |
| 3737 | |
| 3738 | if (*mbx_mbox_cmd != 0x9B) |
| 3739 | return; |
| 3740 | |
| 3741 | if ((mbox_tp == mbox_rd) && (dma_tp == dma_mbox)) { |
| 3742 | if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_MBX) { |
| 3743 | do_dump |= LPFC_BSG_DMP_MBX_RD_MBX; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3744 | pr_err("\nRead mbox command (x%x), " |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3745 | "nemb:0x%x, extbuf_cnt:%d:\n", |
| 3746 | sta_tp, nemb_tp, ext_buf); |
| 3747 | } |
| 3748 | } |
| 3749 | if ((mbox_tp == mbox_rd) && (dma_tp == dma_ebuf)) { |
| 3750 | if (*mbx_dump_map & LPFC_BSG_DMP_MBX_RD_BUF) { |
| 3751 | do_dump |= LPFC_BSG_DMP_MBX_RD_BUF; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3752 | pr_err("\nRead mbox buffer (x%x), " |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3753 | "nemb:0x%x, extbuf_seq:%d:\n", |
| 3754 | sta_tp, nemb_tp, ext_buf); |
| 3755 | } |
| 3756 | } |
| 3757 | if ((mbox_tp == mbox_wr) && (dma_tp == dma_mbox)) { |
| 3758 | if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_MBX) { |
| 3759 | do_dump |= LPFC_BSG_DMP_MBX_WR_MBX; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3760 | pr_err("\nWrite mbox command (x%x), " |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3761 | "nemb:0x%x, extbuf_cnt:%d:\n", |
| 3762 | sta_tp, nemb_tp, ext_buf); |
| 3763 | } |
| 3764 | } |
| 3765 | if ((mbox_tp == mbox_wr) && (dma_tp == dma_ebuf)) { |
| 3766 | if (*mbx_dump_map & LPFC_BSG_DMP_MBX_WR_BUF) { |
| 3767 | do_dump |= LPFC_BSG_DMP_MBX_WR_BUF; |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3768 | pr_err("\nWrite mbox buffer (x%x), " |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3769 | "nemb:0x%x, extbuf_seq:%d:\n", |
| 3770 | sta_tp, nemb_tp, ext_buf); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | /* dump buffer content */ |
| 3775 | if (do_dump) { |
| 3776 | pword = (uint32_t *)dmabuf->virt; |
| 3777 | for (i = 0; i < *mbx_word_cnt; i++) { |
| 3778 | if (!(i % 8)) { |
| 3779 | if (i != 0) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3780 | pr_err("%s\n", line_buf); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3781 | len = 0; |
| 3782 | len += snprintf(line_buf+len, |
| 3783 | LPFC_MBX_ACC_LBUF_SZ-len, |
| 3784 | "%03d: ", i); |
| 3785 | } |
| 3786 | len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len, |
| 3787 | "%08x ", (uint32_t)*pword); |
| 3788 | pword++; |
| 3789 | } |
| 3790 | if ((i - 1) % 8) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3791 | pr_err("%s\n", line_buf); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3792 | (*mbx_dump_cnt)--; |
| 3793 | } |
| 3794 | |
| 3795 | /* Clean out command structure on reaching dump count */ |
| 3796 | if (*mbx_dump_cnt == 0) |
| 3797 | memset(&idiag, 0, sizeof(idiag)); |
| 3798 | return; |
| 3799 | #endif |
| 3800 | } |
| 3801 | |
| 3802 | /* lpfc_idiag_mbxacc_dump_issue_mbox - idiag debugfs dump issue mailbox command |
| 3803 | * @phba: Pointer to HBA context object. |
| 3804 | * @dmabuf: Pointer to a DMA buffer descriptor. |
| 3805 | * |
| 3806 | * Description: |
| 3807 | * This routine dump a pass-through non-embedded mailbox command from issue |
| 3808 | * mailbox command. |
| 3809 | **/ |
| 3810 | void |
| 3811 | lpfc_idiag_mbxacc_dump_issue_mbox(struct lpfc_hba *phba, MAILBOX_t *pmbox) |
| 3812 | { |
| 3813 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
| 3814 | uint32_t *mbx_dump_map, *mbx_dump_cnt, *mbx_word_cnt, *mbx_mbox_cmd; |
| 3815 | char line_buf[LPFC_MBX_ACC_LBUF_SZ]; |
| 3816 | int len = 0; |
| 3817 | uint32_t *pword; |
| 3818 | uint8_t *pbyte; |
| 3819 | uint32_t i, j; |
| 3820 | |
| 3821 | if (idiag.cmd.opcode != LPFC_IDIAG_CMD_MBXACC_DP) |
| 3822 | return; |
| 3823 | |
| 3824 | mbx_mbox_cmd = &idiag.cmd.data[IDIAG_MBXACC_MBCMD_INDX]; |
| 3825 | mbx_dump_map = &idiag.cmd.data[IDIAG_MBXACC_DPMAP_INDX]; |
| 3826 | mbx_dump_cnt = &idiag.cmd.data[IDIAG_MBXACC_DPCNT_INDX]; |
| 3827 | mbx_word_cnt = &idiag.cmd.data[IDIAG_MBXACC_WDCNT_INDX]; |
| 3828 | |
| 3829 | if (!(*mbx_dump_map & LPFC_MBX_DMP_MBX_ALL) || |
| 3830 | (*mbx_dump_cnt == 0) || |
| 3831 | (*mbx_word_cnt == 0)) |
| 3832 | return; |
| 3833 | |
| 3834 | if ((*mbx_mbox_cmd != LPFC_MBX_ALL_CMD) && |
| 3835 | (*mbx_mbox_cmd != pmbox->mbxCommand)) |
| 3836 | return; |
| 3837 | |
| 3838 | /* dump buffer content */ |
| 3839 | if (*mbx_dump_map & LPFC_MBX_DMP_MBX_WORD) { |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3840 | pr_err("Mailbox command:0x%x dump by word:\n", |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3841 | pmbox->mbxCommand); |
| 3842 | pword = (uint32_t *)pmbox; |
| 3843 | for (i = 0; i < *mbx_word_cnt; i++) { |
| 3844 | if (!(i % 8)) { |
| 3845 | if (i != 0) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3846 | pr_err("%s\n", line_buf); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3847 | len = 0; |
| 3848 | memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ); |
| 3849 | len += snprintf(line_buf+len, |
| 3850 | LPFC_MBX_ACC_LBUF_SZ-len, |
| 3851 | "%03d: ", i); |
| 3852 | } |
| 3853 | len += snprintf(line_buf+len, LPFC_MBX_ACC_LBUF_SZ-len, |
| 3854 | "%08x ", |
| 3855 | ((uint32_t)*pword) & 0xffffffff); |
| 3856 | pword++; |
| 3857 | } |
| 3858 | if ((i - 1) % 8) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3859 | pr_err("%s\n", line_buf); |
| 3860 | pr_err("\n"); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3861 | } |
| 3862 | if (*mbx_dump_map & LPFC_MBX_DMP_MBX_BYTE) { |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3863 | pr_err("Mailbox command:0x%x dump by byte:\n", |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3864 | pmbox->mbxCommand); |
| 3865 | pbyte = (uint8_t *)pmbox; |
| 3866 | for (i = 0; i < *mbx_word_cnt; i++) { |
| 3867 | if (!(i % 8)) { |
| 3868 | if (i != 0) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3869 | pr_err("%s\n", line_buf); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3870 | len = 0; |
| 3871 | memset(line_buf, 0, LPFC_MBX_ACC_LBUF_SZ); |
| 3872 | len += snprintf(line_buf+len, |
| 3873 | LPFC_MBX_ACC_LBUF_SZ-len, |
| 3874 | "%03d: ", i); |
| 3875 | } |
| 3876 | for (j = 0; j < 4; j++) { |
| 3877 | len += snprintf(line_buf+len, |
| 3878 | LPFC_MBX_ACC_LBUF_SZ-len, |
| 3879 | "%02x", |
| 3880 | ((uint8_t)*pbyte) & 0xff); |
| 3881 | pbyte++; |
| 3882 | } |
| 3883 | len += snprintf(line_buf+len, |
| 3884 | LPFC_MBX_ACC_LBUF_SZ-len, " "); |
| 3885 | } |
| 3886 | if ((i - 1) % 8) |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 3887 | pr_err("%s\n", line_buf); |
| 3888 | pr_err("\n"); |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 3889 | } |
| 3890 | (*mbx_dump_cnt)--; |
| 3891 | |
| 3892 | /* Clean out command structure on reaching dump count */ |
| 3893 | if (*mbx_dump_cnt == 0) |
| 3894 | memset(&idiag, 0, sizeof(idiag)); |
| 3895 | return; |
| 3896 | #endif |
| 3897 | } |
| 3898 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3899 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 3900 | * lpfc_debugfs_initialize - Initialize debugfs for a vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3901 | * @vport: The vport pointer to initialize. |
| 3902 | * |
| 3903 | * Description: |
| 3904 | * When Debugfs is configured this routine sets up the lpfc debugfs file system. |
| 3905 | * If not already created, this routine will create the lpfc directory, and |
| 3906 | * lpfcX directory (for this HBA), and vportX directory for this vport. It will |
| 3907 | * also create each file used to access lpfc specific debugfs information. |
| 3908 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3909 | inline void |
| 3910 | lpfc_debugfs_initialize(struct lpfc_vport *vport) |
| 3911 | { |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 3912 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3913 | struct lpfc_hba *phba = vport->phba; |
| 3914 | char name[64]; |
| 3915 | uint32_t num, i; |
James Smart | f6c3bdf | 2013-12-17 20:29:59 -0500 | [diff] [blame] | 3916 | bool pport_setup = false; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 3917 | |
| 3918 | if (!lpfc_debugfs_enable) |
| 3919 | return; |
| 3920 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3921 | /* Setup lpfc root directory */ |
| 3922 | if (!lpfc_debugfs_root) { |
| 3923 | lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL); |
| 3924 | atomic_set(&lpfc_debugfs_hba_count, 0); |
| 3925 | if (!lpfc_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3926 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3927 | "0408 Cannot create debugfs root\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3928 | goto debug_failed; |
| 3929 | } |
| 3930 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3931 | if (!lpfc_debugfs_start_time) |
| 3932 | lpfc_debugfs_start_time = jiffies; |
| 3933 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 3934 | /* Setup funcX directory for specific HBA PCI function */ |
| 3935 | snprintf(name, sizeof(name), "fn%d", phba->brd_no); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3936 | if (!phba->hba_debugfs_root) { |
James Smart | f6c3bdf | 2013-12-17 20:29:59 -0500 | [diff] [blame] | 3937 | pport_setup = true; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3938 | phba->hba_debugfs_root = |
| 3939 | debugfs_create_dir(name, lpfc_debugfs_root); |
| 3940 | if (!phba->hba_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 3941 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3942 | "0412 Cannot create debugfs hba\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3943 | goto debug_failed; |
| 3944 | } |
| 3945 | atomic_inc(&lpfc_debugfs_hba_count); |
| 3946 | atomic_set(&phba->debugfs_vport_count, 0); |
| 3947 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3948 | /* Setup hbqinfo */ |
| 3949 | snprintf(name, sizeof(name), "hbqinfo"); |
| 3950 | phba->debug_hbqinfo = |
| 3951 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 3952 | phba->hba_debugfs_root, |
| 3953 | phba, &lpfc_debugfs_op_hbqinfo); |
| 3954 | if (!phba->debug_hbqinfo) { |
| 3955 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3956 | "0411 Cannot create debugfs hbqinfo\n"); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 3957 | goto debug_failed; |
| 3958 | } |
| 3959 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 3960 | /* Setup dumpHBASlim */ |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 3961 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3962 | snprintf(name, sizeof(name), "dumpHBASlim"); |
| 3963 | phba->debug_dumpHBASlim = |
| 3964 | debugfs_create_file(name, |
| 3965 | S_IFREG|S_IRUGO|S_IWUSR, |
| 3966 | phba->hba_debugfs_root, |
| 3967 | phba, &lpfc_debugfs_op_dumpHBASlim); |
| 3968 | if (!phba->debug_dumpHBASlim) { |
| 3969 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 3970 | "0413 Cannot create debugfs " |
| 3971 | "dumpHBASlim\n"); |
| 3972 | goto debug_failed; |
| 3973 | } |
| 3974 | } else |
| 3975 | phba->debug_dumpHBASlim = NULL; |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 3976 | |
| 3977 | /* Setup dumpHostSlim */ |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 3978 | if (phba->sli_rev < LPFC_SLI_REV4) { |
| 3979 | snprintf(name, sizeof(name), "dumpHostSlim"); |
| 3980 | phba->debug_dumpHostSlim = |
| 3981 | debugfs_create_file(name, |
| 3982 | S_IFREG|S_IRUGO|S_IWUSR, |
| 3983 | phba->hba_debugfs_root, |
| 3984 | phba, &lpfc_debugfs_op_dumpHostSlim); |
| 3985 | if (!phba->debug_dumpHostSlim) { |
| 3986 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 3987 | "0414 Cannot create debugfs " |
| 3988 | "dumpHostSlim\n"); |
| 3989 | goto debug_failed; |
| 3990 | } |
| 3991 | } else |
Felipe Pena | b28d108 | 2013-10-18 20:15:37 -0300 | [diff] [blame] | 3992 | phba->debug_dumpHostSlim = NULL; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 3993 | |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 3994 | /* Setup dumpData */ |
| 3995 | snprintf(name, sizeof(name), "dumpData"); |
| 3996 | phba->debug_dumpData = |
| 3997 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 3998 | phba->hba_debugfs_root, |
| 3999 | phba, &lpfc_debugfs_op_dumpData); |
| 4000 | if (!phba->debug_dumpData) { |
| 4001 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4002 | "0800 Cannot create debugfs dumpData\n"); |
| 4003 | goto debug_failed; |
| 4004 | } |
| 4005 | |
| 4006 | /* Setup dumpDif */ |
| 4007 | snprintf(name, sizeof(name), "dumpDif"); |
| 4008 | phba->debug_dumpDif = |
| 4009 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4010 | phba->hba_debugfs_root, |
| 4011 | phba, &lpfc_debugfs_op_dumpDif); |
| 4012 | if (!phba->debug_dumpDif) { |
| 4013 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4014 | "0801 Cannot create debugfs dumpDif\n"); |
| 4015 | goto debug_failed; |
| 4016 | } |
| 4017 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4018 | /* Setup DIF Error Injections */ |
| 4019 | snprintf(name, sizeof(name), "InjErrLBA"); |
| 4020 | phba->debug_InjErrLBA = |
| 4021 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4022 | phba->hba_debugfs_root, |
| 4023 | phba, &lpfc_debugfs_op_dif_err); |
| 4024 | if (!phba->debug_InjErrLBA) { |
| 4025 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4026 | "0807 Cannot create debugfs InjErrLBA\n"); |
| 4027 | goto debug_failed; |
| 4028 | } |
| 4029 | phba->lpfc_injerr_lba = LPFC_INJERR_LBA_OFF; |
| 4030 | |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 4031 | snprintf(name, sizeof(name), "InjErrNPortID"); |
| 4032 | phba->debug_InjErrNPortID = |
| 4033 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4034 | phba->hba_debugfs_root, |
| 4035 | phba, &lpfc_debugfs_op_dif_err); |
| 4036 | if (!phba->debug_InjErrNPortID) { |
| 4037 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4038 | "0809 Cannot create debugfs InjErrNPortID\n"); |
| 4039 | goto debug_failed; |
| 4040 | } |
| 4041 | |
| 4042 | snprintf(name, sizeof(name), "InjErrWWPN"); |
| 4043 | phba->debug_InjErrWWPN = |
| 4044 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4045 | phba->hba_debugfs_root, |
| 4046 | phba, &lpfc_debugfs_op_dif_err); |
| 4047 | if (!phba->debug_InjErrWWPN) { |
| 4048 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4049 | "0810 Cannot create debugfs InjErrWWPN\n"); |
| 4050 | goto debug_failed; |
| 4051 | } |
| 4052 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4053 | snprintf(name, sizeof(name), "writeGuardInjErr"); |
| 4054 | phba->debug_writeGuard = |
| 4055 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4056 | phba->hba_debugfs_root, |
| 4057 | phba, &lpfc_debugfs_op_dif_err); |
| 4058 | if (!phba->debug_writeGuard) { |
| 4059 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4060 | "0802 Cannot create debugfs writeGuard\n"); |
| 4061 | goto debug_failed; |
| 4062 | } |
| 4063 | |
| 4064 | snprintf(name, sizeof(name), "writeAppInjErr"); |
| 4065 | phba->debug_writeApp = |
| 4066 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4067 | phba->hba_debugfs_root, |
| 4068 | phba, &lpfc_debugfs_op_dif_err); |
| 4069 | if (!phba->debug_writeApp) { |
| 4070 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4071 | "0803 Cannot create debugfs writeApp\n"); |
| 4072 | goto debug_failed; |
| 4073 | } |
| 4074 | |
| 4075 | snprintf(name, sizeof(name), "writeRefInjErr"); |
| 4076 | phba->debug_writeRef = |
| 4077 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4078 | phba->hba_debugfs_root, |
| 4079 | phba, &lpfc_debugfs_op_dif_err); |
| 4080 | if (!phba->debug_writeRef) { |
| 4081 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4082 | "0804 Cannot create debugfs writeRef\n"); |
| 4083 | goto debug_failed; |
| 4084 | } |
| 4085 | |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4086 | snprintf(name, sizeof(name), "readGuardInjErr"); |
| 4087 | phba->debug_readGuard = |
| 4088 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4089 | phba->hba_debugfs_root, |
| 4090 | phba, &lpfc_debugfs_op_dif_err); |
| 4091 | if (!phba->debug_readGuard) { |
| 4092 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4093 | "0808 Cannot create debugfs readGuard\n"); |
| 4094 | goto debug_failed; |
| 4095 | } |
| 4096 | |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4097 | snprintf(name, sizeof(name), "readAppInjErr"); |
| 4098 | phba->debug_readApp = |
| 4099 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4100 | phba->hba_debugfs_root, |
| 4101 | phba, &lpfc_debugfs_op_dif_err); |
| 4102 | if (!phba->debug_readApp) { |
| 4103 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4104 | "0805 Cannot create debugfs readApp\n"); |
| 4105 | goto debug_failed; |
| 4106 | } |
| 4107 | |
| 4108 | snprintf(name, sizeof(name), "readRefInjErr"); |
| 4109 | phba->debug_readRef = |
| 4110 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4111 | phba->hba_debugfs_root, |
| 4112 | phba, &lpfc_debugfs_op_dif_err); |
| 4113 | if (!phba->debug_readRef) { |
| 4114 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4115 | "0806 Cannot create debugfs readApp\n"); |
| 4116 | goto debug_failed; |
| 4117 | } |
| 4118 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4119 | /* Setup slow ring trace */ |
| 4120 | if (lpfc_debugfs_max_slow_ring_trc) { |
| 4121 | num = lpfc_debugfs_max_slow_ring_trc - 1; |
| 4122 | if (num & lpfc_debugfs_max_slow_ring_trc) { |
| 4123 | /* Change to be a power of 2 */ |
| 4124 | num = lpfc_debugfs_max_slow_ring_trc; |
| 4125 | i = 0; |
| 4126 | while (num > 1) { |
| 4127 | num = num >> 1; |
| 4128 | i++; |
| 4129 | } |
| 4130 | lpfc_debugfs_max_slow_ring_trc = (1 << i); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4131 | pr_err("lpfc_debugfs_max_disc_trc changed to " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4132 | "%d\n", lpfc_debugfs_max_disc_trc); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4136 | snprintf(name, sizeof(name), "slow_ring_trace"); |
| 4137 | phba->debug_slow_ring_trc = |
| 4138 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4139 | phba->hba_debugfs_root, |
| 4140 | phba, &lpfc_debugfs_op_slow_ring_trc); |
| 4141 | if (!phba->debug_slow_ring_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4142 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4143 | "0415 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4144 | "slow_ring_trace\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4145 | goto debug_failed; |
| 4146 | } |
| 4147 | if (!phba->slow_ring_trc) { |
| 4148 | phba->slow_ring_trc = kmalloc( |
| 4149 | (sizeof(struct lpfc_debugfs_trc) * |
| 4150 | lpfc_debugfs_max_slow_ring_trc), |
| 4151 | GFP_KERNEL); |
| 4152 | if (!phba->slow_ring_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4153 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4154 | "0416 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4155 | "slow_ring buffer\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4156 | goto debug_failed; |
| 4157 | } |
| 4158 | atomic_set(&phba->slow_ring_trc_cnt, 0); |
| 4159 | memset(phba->slow_ring_trc, 0, |
| 4160 | (sizeof(struct lpfc_debugfs_trc) * |
| 4161 | lpfc_debugfs_max_slow_ring_trc)); |
| 4162 | } |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4163 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | snprintf(name, sizeof(name), "vport%d", vport->vpi); |
| 4167 | if (!vport->vport_debugfs_root) { |
| 4168 | vport->vport_debugfs_root = |
| 4169 | debugfs_create_dir(name, phba->hba_debugfs_root); |
| 4170 | if (!vport->vport_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4171 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4172 | "0417 Can't create debugfs\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4173 | goto debug_failed; |
| 4174 | } |
| 4175 | atomic_inc(&phba->debugfs_vport_count); |
| 4176 | } |
| 4177 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4178 | if (lpfc_debugfs_max_disc_trc) { |
| 4179 | num = lpfc_debugfs_max_disc_trc - 1; |
| 4180 | if (num & lpfc_debugfs_max_disc_trc) { |
| 4181 | /* Change to be a power of 2 */ |
| 4182 | num = lpfc_debugfs_max_disc_trc; |
| 4183 | i = 0; |
| 4184 | while (num > 1) { |
| 4185 | num = num >> 1; |
| 4186 | i++; |
| 4187 | } |
| 4188 | lpfc_debugfs_max_disc_trc = (1 << i); |
James Smart | 2ea259e | 2017-02-12 13:52:27 -0800 | [diff] [blame] | 4189 | pr_err("lpfc_debugfs_max_disc_trc changed to %d\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4190 | lpfc_debugfs_max_disc_trc); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4191 | } |
| 4192 | } |
| 4193 | |
Adrian Bunk | ff86ba5 | 2007-10-18 12:52:37 +0200 | [diff] [blame] | 4194 | vport->disc_trc = kzalloc( |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4195 | (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc), |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4196 | GFP_KERNEL); |
| 4197 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4198 | if (!vport->disc_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4199 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4200 | "0418 Cannot create debugfs disc trace " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4201 | "buffer\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4202 | goto debug_failed; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4203 | } |
| 4204 | atomic_set(&vport->disc_trc_cnt, 0); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4205 | |
| 4206 | snprintf(name, sizeof(name), "discovery_trace"); |
| 4207 | vport->debug_disc_trc = |
| 4208 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4209 | vport->vport_debugfs_root, |
| 4210 | vport, &lpfc_debugfs_op_disc_trc); |
| 4211 | if (!vport->debug_disc_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4212 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 4213 | "0419 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4214 | "discovery_trace\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4215 | goto debug_failed; |
| 4216 | } |
| 4217 | snprintf(name, sizeof(name), "nodelist"); |
| 4218 | vport->debug_nodelist = |
| 4219 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4220 | vport->vport_debugfs_root, |
| 4221 | vport, &lpfc_debugfs_op_nodelist); |
| 4222 | if (!vport->debug_nodelist) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 4223 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4224 | "2985 Can't create debugfs nodelist\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4225 | goto debug_failed; |
| 4226 | } |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4227 | |
| 4228 | /* |
James Smart | f6c3bdf | 2013-12-17 20:29:59 -0500 | [diff] [blame] | 4229 | * The following section is for additional directories/files for the |
| 4230 | * physical port. |
| 4231 | */ |
| 4232 | |
| 4233 | if (!pport_setup) |
| 4234 | goto debug_failed; |
| 4235 | |
| 4236 | /* |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4237 | * iDiag debugfs root entry points for SLI4 device only |
| 4238 | */ |
| 4239 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 4240 | goto debug_failed; |
| 4241 | |
| 4242 | snprintf(name, sizeof(name), "iDiag"); |
| 4243 | if (!phba->idiag_root) { |
| 4244 | phba->idiag_root = |
| 4245 | debugfs_create_dir(name, phba->hba_debugfs_root); |
| 4246 | if (!phba->idiag_root) { |
| 4247 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4248 | "2922 Can't create idiag debugfs\n"); |
| 4249 | goto debug_failed; |
| 4250 | } |
| 4251 | /* Initialize iDiag data structure */ |
| 4252 | memset(&idiag, 0, sizeof(idiag)); |
| 4253 | } |
| 4254 | |
| 4255 | /* iDiag read PCI config space */ |
| 4256 | snprintf(name, sizeof(name), "pciCfg"); |
| 4257 | if (!phba->idiag_pci_cfg) { |
| 4258 | phba->idiag_pci_cfg = |
| 4259 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4260 | phba->idiag_root, phba, &lpfc_idiag_op_pciCfg); |
| 4261 | if (!phba->idiag_pci_cfg) { |
| 4262 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4263 | "2923 Can't create idiag debugfs\n"); |
| 4264 | goto debug_failed; |
| 4265 | } |
| 4266 | idiag.offset.last_rd = 0; |
| 4267 | } |
| 4268 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4269 | /* iDiag PCI BAR access */ |
| 4270 | snprintf(name, sizeof(name), "barAcc"); |
| 4271 | if (!phba->idiag_bar_acc) { |
| 4272 | phba->idiag_bar_acc = |
| 4273 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4274 | phba->idiag_root, phba, &lpfc_idiag_op_barAcc); |
| 4275 | if (!phba->idiag_bar_acc) { |
| 4276 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4277 | "3056 Can't create idiag debugfs\n"); |
| 4278 | goto debug_failed; |
| 4279 | } |
| 4280 | idiag.offset.last_rd = 0; |
| 4281 | } |
| 4282 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4283 | /* iDiag get PCI function queue information */ |
| 4284 | snprintf(name, sizeof(name), "queInfo"); |
| 4285 | if (!phba->idiag_que_info) { |
| 4286 | phba->idiag_que_info = |
| 4287 | debugfs_create_file(name, S_IFREG|S_IRUGO, |
| 4288 | phba->idiag_root, phba, &lpfc_idiag_op_queInfo); |
| 4289 | if (!phba->idiag_que_info) { |
| 4290 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4291 | "2924 Can't create idiag debugfs\n"); |
| 4292 | goto debug_failed; |
| 4293 | } |
| 4294 | } |
| 4295 | |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 4296 | /* iDiag access PCI function queue */ |
| 4297 | snprintf(name, sizeof(name), "queAcc"); |
| 4298 | if (!phba->idiag_que_acc) { |
| 4299 | phba->idiag_que_acc = |
| 4300 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4301 | phba->idiag_root, phba, &lpfc_idiag_op_queAcc); |
| 4302 | if (!phba->idiag_que_acc) { |
| 4303 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4304 | "2926 Can't create idiag debugfs\n"); |
| 4305 | goto debug_failed; |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | /* iDiag access PCI function doorbell registers */ |
| 4310 | snprintf(name, sizeof(name), "drbAcc"); |
| 4311 | if (!phba->idiag_drb_acc) { |
| 4312 | phba->idiag_drb_acc = |
| 4313 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4314 | phba->idiag_root, phba, &lpfc_idiag_op_drbAcc); |
| 4315 | if (!phba->idiag_drb_acc) { |
| 4316 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4317 | "2927 Can't create idiag debugfs\n"); |
| 4318 | goto debug_failed; |
| 4319 | } |
| 4320 | } |
| 4321 | |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4322 | /* iDiag access PCI function control registers */ |
| 4323 | snprintf(name, sizeof(name), "ctlAcc"); |
| 4324 | if (!phba->idiag_ctl_acc) { |
| 4325 | phba->idiag_ctl_acc = |
| 4326 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4327 | phba->idiag_root, phba, &lpfc_idiag_op_ctlAcc); |
| 4328 | if (!phba->idiag_ctl_acc) { |
| 4329 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4330 | "2981 Can't create idiag debugfs\n"); |
| 4331 | goto debug_failed; |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | /* iDiag access mbox commands */ |
| 4336 | snprintf(name, sizeof(name), "mbxAcc"); |
| 4337 | if (!phba->idiag_mbx_acc) { |
| 4338 | phba->idiag_mbx_acc = |
| 4339 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 4340 | phba->idiag_root, phba, &lpfc_idiag_op_mbxAcc); |
| 4341 | if (!phba->idiag_mbx_acc) { |
| 4342 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4343 | "2980 Can't create idiag debugfs\n"); |
| 4344 | goto debug_failed; |
| 4345 | } |
| 4346 | } |
| 4347 | |
| 4348 | /* iDiag extents access commands */ |
| 4349 | if (phba->sli4_hba.extents_in_use) { |
| 4350 | snprintf(name, sizeof(name), "extAcc"); |
| 4351 | if (!phba->idiag_ext_acc) { |
| 4352 | phba->idiag_ext_acc = |
| 4353 | debugfs_create_file(name, |
| 4354 | S_IFREG|S_IRUGO|S_IWUSR, |
| 4355 | phba->idiag_root, phba, |
| 4356 | &lpfc_idiag_op_extAcc); |
| 4357 | if (!phba->idiag_ext_acc) { |
| 4358 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 4359 | "2986 Cant create " |
| 4360 | "idiag debugfs\n"); |
| 4361 | goto debug_failed; |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4366 | debug_failed: |
| 4367 | return; |
| 4368 | #endif |
| 4369 | } |
| 4370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4371 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 4372 | * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4373 | * @vport: The vport pointer to remove from debugfs. |
| 4374 | * |
| 4375 | * Description: |
| 4376 | * When Debugfs is configured this routine removes debugfs file system elements |
| 4377 | * that are specific to this vport. It also checks to see if there are any |
| 4378 | * users left for the debugfs directories associated with the HBA and driver. If |
| 4379 | * this is the last user of the HBA directory or driver directory then it will |
| 4380 | * remove those from the debugfs infrastructure as well. |
| 4381 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4382 | inline void |
| 4383 | lpfc_debugfs_terminate(struct lpfc_vport *vport) |
| 4384 | { |
James Smart | 923e4b6 | 2008-12-04 22:40:07 -0500 | [diff] [blame] | 4385 | #ifdef CONFIG_SCSI_LPFC_DEBUG_FS |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4386 | struct lpfc_hba *phba = vport->phba; |
| 4387 | |
| 4388 | if (vport->disc_trc) { |
| 4389 | kfree(vport->disc_trc); |
| 4390 | vport->disc_trc = NULL; |
| 4391 | } |
| 4392 | if (vport->debug_disc_trc) { |
| 4393 | debugfs_remove(vport->debug_disc_trc); /* discovery_trace */ |
| 4394 | vport->debug_disc_trc = NULL; |
| 4395 | } |
| 4396 | if (vport->debug_nodelist) { |
| 4397 | debugfs_remove(vport->debug_nodelist); /* nodelist */ |
| 4398 | vport->debug_nodelist = NULL; |
| 4399 | } |
| 4400 | if (vport->vport_debugfs_root) { |
| 4401 | debugfs_remove(vport->vport_debugfs_root); /* vportX */ |
| 4402 | vport->vport_debugfs_root = NULL; |
| 4403 | atomic_dec(&phba->debugfs_vport_count); |
| 4404 | } |
| 4405 | if (atomic_read(&phba->debugfs_vport_count) == 0) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4406 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 4407 | if (phba->debug_hbqinfo) { |
| 4408 | debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */ |
| 4409 | phba->debug_hbqinfo = NULL; |
| 4410 | } |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 4411 | if (phba->debug_dumpHBASlim) { |
| 4412 | debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */ |
| 4413 | phba->debug_dumpHBASlim = NULL; |
| 4414 | } |
| 4415 | if (phba->debug_dumpHostSlim) { |
| 4416 | debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */ |
| 4417 | phba->debug_dumpHostSlim = NULL; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4418 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4419 | if (phba->debug_dumpData) { |
| 4420 | debugfs_remove(phba->debug_dumpData); /* dumpData */ |
| 4421 | phba->debug_dumpData = NULL; |
| 4422 | } |
| 4423 | |
| 4424 | if (phba->debug_dumpDif) { |
| 4425 | debugfs_remove(phba->debug_dumpDif); /* dumpDif */ |
| 4426 | phba->debug_dumpDif = NULL; |
| 4427 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4428 | if (phba->debug_InjErrLBA) { |
| 4429 | debugfs_remove(phba->debug_InjErrLBA); /* InjErrLBA */ |
| 4430 | phba->debug_InjErrLBA = NULL; |
| 4431 | } |
James Smart | 4ac9b22 | 2012-03-01 22:38:29 -0500 | [diff] [blame] | 4432 | if (phba->debug_InjErrNPortID) { /* InjErrNPortID */ |
| 4433 | debugfs_remove(phba->debug_InjErrNPortID); |
| 4434 | phba->debug_InjErrNPortID = NULL; |
| 4435 | } |
| 4436 | if (phba->debug_InjErrWWPN) { |
| 4437 | debugfs_remove(phba->debug_InjErrWWPN); /* InjErrWWPN */ |
| 4438 | phba->debug_InjErrWWPN = NULL; |
| 4439 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4440 | if (phba->debug_writeGuard) { |
| 4441 | debugfs_remove(phba->debug_writeGuard); /* writeGuard */ |
| 4442 | phba->debug_writeGuard = NULL; |
| 4443 | } |
| 4444 | if (phba->debug_writeApp) { |
| 4445 | debugfs_remove(phba->debug_writeApp); /* writeApp */ |
| 4446 | phba->debug_writeApp = NULL; |
| 4447 | } |
| 4448 | if (phba->debug_writeRef) { |
| 4449 | debugfs_remove(phba->debug_writeRef); /* writeRef */ |
| 4450 | phba->debug_writeRef = NULL; |
| 4451 | } |
James Smart | acd6859 | 2012-01-18 16:25:09 -0500 | [diff] [blame] | 4452 | if (phba->debug_readGuard) { |
| 4453 | debugfs_remove(phba->debug_readGuard); /* readGuard */ |
| 4454 | phba->debug_readGuard = NULL; |
| 4455 | } |
James Smart | f9bb2da | 2011-10-10 21:34:11 -0400 | [diff] [blame] | 4456 | if (phba->debug_readApp) { |
| 4457 | debugfs_remove(phba->debug_readApp); /* readApp */ |
| 4458 | phba->debug_readApp = NULL; |
| 4459 | } |
| 4460 | if (phba->debug_readRef) { |
| 4461 | debugfs_remove(phba->debug_readRef); /* readRef */ |
| 4462 | phba->debug_readRef = NULL; |
| 4463 | } |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 4464 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4465 | if (phba->slow_ring_trc) { |
| 4466 | kfree(phba->slow_ring_trc); |
| 4467 | phba->slow_ring_trc = NULL; |
| 4468 | } |
| 4469 | if (phba->debug_slow_ring_trc) { |
| 4470 | /* slow_ring_trace */ |
| 4471 | debugfs_remove(phba->debug_slow_ring_trc); |
| 4472 | phba->debug_slow_ring_trc = NULL; |
| 4473 | } |
| 4474 | |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4475 | /* |
| 4476 | * iDiag release |
| 4477 | */ |
| 4478 | if (phba->sli_rev == LPFC_SLI_REV4) { |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4479 | if (phba->idiag_ext_acc) { |
| 4480 | /* iDiag extAcc */ |
| 4481 | debugfs_remove(phba->idiag_ext_acc); |
| 4482 | phba->idiag_ext_acc = NULL; |
| 4483 | } |
| 4484 | if (phba->idiag_mbx_acc) { |
| 4485 | /* iDiag mbxAcc */ |
| 4486 | debugfs_remove(phba->idiag_mbx_acc); |
| 4487 | phba->idiag_mbx_acc = NULL; |
| 4488 | } |
| 4489 | if (phba->idiag_ctl_acc) { |
| 4490 | /* iDiag ctlAcc */ |
| 4491 | debugfs_remove(phba->idiag_ctl_acc); |
| 4492 | phba->idiag_ctl_acc = NULL; |
| 4493 | } |
James Smart | 86a8084 | 2011-04-16 11:03:04 -0400 | [diff] [blame] | 4494 | if (phba->idiag_drb_acc) { |
| 4495 | /* iDiag drbAcc */ |
| 4496 | debugfs_remove(phba->idiag_drb_acc); |
| 4497 | phba->idiag_drb_acc = NULL; |
| 4498 | } |
| 4499 | if (phba->idiag_que_acc) { |
| 4500 | /* iDiag queAcc */ |
| 4501 | debugfs_remove(phba->idiag_que_acc); |
| 4502 | phba->idiag_que_acc = NULL; |
| 4503 | } |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4504 | if (phba->idiag_que_info) { |
| 4505 | /* iDiag queInfo */ |
| 4506 | debugfs_remove(phba->idiag_que_info); |
| 4507 | phba->idiag_que_info = NULL; |
| 4508 | } |
James Smart | b76f2dc | 2011-07-22 18:37:42 -0400 | [diff] [blame] | 4509 | if (phba->idiag_bar_acc) { |
| 4510 | /* iDiag barAcc */ |
| 4511 | debugfs_remove(phba->idiag_bar_acc); |
| 4512 | phba->idiag_bar_acc = NULL; |
| 4513 | } |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4514 | if (phba->idiag_pci_cfg) { |
| 4515 | /* iDiag pciCfg */ |
| 4516 | debugfs_remove(phba->idiag_pci_cfg); |
| 4517 | phba->idiag_pci_cfg = NULL; |
| 4518 | } |
| 4519 | |
| 4520 | /* Finally remove the iDiag debugfs root */ |
| 4521 | if (phba->idiag_root) { |
| 4522 | /* iDiag root */ |
| 4523 | debugfs_remove(phba->idiag_root); |
| 4524 | phba->idiag_root = NULL; |
| 4525 | } |
| 4526 | } |
| 4527 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4528 | if (phba->hba_debugfs_root) { |
James Smart | 2a622bf | 2011-02-16 12:40:06 -0500 | [diff] [blame] | 4529 | debugfs_remove(phba->hba_debugfs_root); /* fnX */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4530 | phba->hba_debugfs_root = NULL; |
| 4531 | atomic_dec(&lpfc_debugfs_hba_count); |
| 4532 | } |
| 4533 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4534 | if (atomic_read(&lpfc_debugfs_hba_count) == 0) { |
| 4535 | debugfs_remove(lpfc_debugfs_root); /* lpfc */ |
| 4536 | lpfc_debugfs_root = NULL; |
| 4537 | } |
| 4538 | } |
| 4539 | #endif |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 4540 | return; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 4541 | } |
James Smart | 809c753 | 2012-05-09 21:19:25 -0400 | [diff] [blame] | 4542 | |
| 4543 | /* |
| 4544 | * Driver debug utility routines outside of debugfs. The debug utility |
| 4545 | * routines implemented here is intended to be used in the instrumented |
| 4546 | * debug driver for debugging host or port issues. |
| 4547 | */ |
| 4548 | |
| 4549 | /** |
| 4550 | * lpfc_debug_dump_all_queues - dump all the queues with a hba |
| 4551 | * @phba: Pointer to HBA context object. |
| 4552 | * |
| 4553 | * This function dumps entries of all the queues asociated with the @phba. |
| 4554 | **/ |
| 4555 | void |
| 4556 | lpfc_debug_dump_all_queues(struct lpfc_hba *phba) |
| 4557 | { |
| 4558 | int fcp_wqidx; |
| 4559 | |
| 4560 | /* |
| 4561 | * Dump Work Queues (WQs) |
| 4562 | */ |
| 4563 | lpfc_debug_dump_mbx_wq(phba); |
| 4564 | lpfc_debug_dump_els_wq(phba); |
| 4565 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4566 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) |
James Smart | 809c753 | 2012-05-09 21:19:25 -0400 | [diff] [blame] | 4567 | lpfc_debug_dump_fcp_wq(phba, fcp_wqidx); |
| 4568 | |
| 4569 | lpfc_debug_dump_hdr_rq(phba); |
| 4570 | lpfc_debug_dump_dat_rq(phba); |
| 4571 | /* |
| 4572 | * Dump Complete Queues (CQs) |
| 4573 | */ |
| 4574 | lpfc_debug_dump_mbx_cq(phba); |
| 4575 | lpfc_debug_dump_els_cq(phba); |
| 4576 | |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4577 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) |
James Smart | 809c753 | 2012-05-09 21:19:25 -0400 | [diff] [blame] | 4578 | lpfc_debug_dump_fcp_cq(phba, fcp_wqidx); |
| 4579 | |
| 4580 | /* |
| 4581 | * Dump Event Queues (EQs) |
| 4582 | */ |
James Smart | 67d1273 | 2012-08-03 12:36:13 -0400 | [diff] [blame] | 4583 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) |
| 4584 | lpfc_debug_dump_hba_eq(phba, fcp_wqidx); |
James Smart | 809c753 | 2012-05-09 21:19:25 -0400 | [diff] [blame] | 4585 | } |