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 | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 4 | * Copyright (C) 2007-2008 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> |
| 23 | #include <linux/dma-mapping.h> |
| 24 | #include <linux/idr.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/kthread.h> |
| 27 | #include <linux/pci.h> |
| 28 | #include <linux/spinlock.h> |
| 29 | #include <linux/ctype.h> |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 30 | |
| 31 | #include <scsi/scsi.h> |
| 32 | #include <scsi/scsi_device.h> |
| 33 | #include <scsi/scsi_host.h> |
| 34 | #include <scsi/scsi_transport_fc.h> |
| 35 | |
| 36 | #include "lpfc_hw.h" |
| 37 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 38 | #include "lpfc_nl.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 39 | #include "lpfc_disc.h" |
| 40 | #include "lpfc_scsi.h" |
| 41 | #include "lpfc.h" |
| 42 | #include "lpfc_logmsg.h" |
| 43 | #include "lpfc_crtn.h" |
| 44 | #include "lpfc_vport.h" |
| 45 | #include "lpfc_version.h" |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 46 | #include "lpfc_compat.h" |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 47 | #include "lpfc_debugfs.h" |
| 48 | |
| 49 | #ifdef CONFIG_LPFC_DEBUG_FS |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 50 | /** |
| 51 | * debugfs interface |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 52 | * |
| 53 | * To access this interface the user should: |
| 54 | * # mkdir /debug |
| 55 | * # mount -t debugfs none /debug |
| 56 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 57 | * The lpfc debugfs directory hierarchy is: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 58 | * lpfc/lpfcX/vportY |
| 59 | * where X is the lpfc hba unique_id |
| 60 | * where Y is the vport VPI on that hba |
| 61 | * |
| 62 | * Debugging services available per vport: |
| 63 | * discovery_trace |
| 64 | * This is an ACSII readable file that contains a trace of the last |
| 65 | * lpfc_debugfs_max_disc_trc events that happened on a specific vport. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 66 | * See lpfc_debugfs.h for different categories of discovery events. |
| 67 | * To enable the discovery trace, the following module parameters must be set: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 68 | * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support |
| 69 | * lpfc_debugfs_max_disc_trc=X Where X is the event trace depth for |
| 70 | * EACH vport. X MUST also be a power of 2. |
| 71 | * lpfc_debugfs_mask_disc_trc=Y Where Y is an event mask as defined in |
| 72 | * lpfc_debugfs.h . |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 73 | * |
| 74 | * slow_ring_trace |
| 75 | * This is an ACSII readable file that contains a trace of the last |
| 76 | * lpfc_debugfs_max_slow_ring_trc events that happened on a specific HBA. |
| 77 | * To enable the slow ring trace, the following module parameters must be set: |
| 78 | * lpfc_debugfs_enable=1 Turns on lpfc debugfs filesystem support |
| 79 | * lpfc_debugfs_max_slow_ring_trc=X Where X is the event trace depth for |
| 80 | * the HBA. X MUST also be a power of 2. |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 81 | */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 82 | static int lpfc_debugfs_enable = 1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 83 | module_param(lpfc_debugfs_enable, int, 0); |
| 84 | MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services"); |
| 85 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 86 | /* This MUST be a power of 2 */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 87 | static int lpfc_debugfs_max_disc_trc; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 88 | module_param(lpfc_debugfs_max_disc_trc, int, 0); |
| 89 | MODULE_PARM_DESC(lpfc_debugfs_max_disc_trc, |
| 90 | "Set debugfs discovery trace depth"); |
| 91 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 92 | /* This MUST be a power of 2 */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 93 | static int lpfc_debugfs_max_slow_ring_trc; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 94 | module_param(lpfc_debugfs_max_slow_ring_trc, int, 0); |
| 95 | MODULE_PARM_DESC(lpfc_debugfs_max_slow_ring_trc, |
| 96 | "Set debugfs slow ring trace depth"); |
| 97 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 98 | int lpfc_debugfs_mask_disc_trc; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 99 | module_param(lpfc_debugfs_mask_disc_trc, int, 0); |
| 100 | MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc, |
| 101 | "Set debugfs discovery trace mask"); |
| 102 | |
| 103 | #include <linux/debugfs.h> |
| 104 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 105 | /* size of output line, for discovery_trace and slow_ring_trace */ |
| 106 | #define LPFC_DEBUG_TRC_ENTRY_SIZE 100 |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 107 | |
| 108 | /* nodelist output buffer size */ |
| 109 | #define LPFC_NODELIST_SIZE 8192 |
| 110 | #define LPFC_NODELIST_ENTRY_SIZE 120 |
| 111 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 112 | /* dumpHBASlim output buffer size */ |
| 113 | #define LPFC_DUMPHBASLIM_SIZE 4096 |
| 114 | |
| 115 | /* dumpHostSlim output buffer size */ |
| 116 | #define LPFC_DUMPHOSTSLIM_SIZE 4096 |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 117 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 118 | /* hbqinfo output buffer size */ |
| 119 | #define LPFC_HBQINFO_SIZE 8192 |
| 120 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 121 | struct lpfc_debug { |
| 122 | char *buffer; |
| 123 | int len; |
| 124 | }; |
| 125 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 126 | static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); |
| 127 | static unsigned long lpfc_debugfs_start_time = 0L; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 128 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 129 | /** |
| 130 | * lpfc_debugfs_disc_trc_data - Dump discovery logging to a buffer. |
| 131 | * @vport: The vport to gather the log info from. |
| 132 | * @buf: The buffer to dump log into. |
| 133 | * @size: The maximum amount of data to process. |
| 134 | * |
| 135 | * Description: |
| 136 | * This routine gathers the lpfc discovery debugfs data from the @vport and |
| 137 | * dumps it to @buf up to @size number of bytes. It will start at the next entry |
| 138 | * in the log and process the log until the end of the buffer. Then it will |
| 139 | * gather from the beginning of the log and process until the current entry. |
| 140 | * |
| 141 | * Notes: |
| 142 | * Discovery logging will be disabled while while this routine dumps the log. |
| 143 | * |
| 144 | * Return Value: |
| 145 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 146 | * not exceed @size. |
| 147 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 148 | static int |
| 149 | lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size) |
| 150 | { |
| 151 | int i, index, len, enable; |
| 152 | uint32_t ms; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 153 | struct lpfc_debugfs_trc *dtp; |
| 154 | char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 155 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 156 | enable = lpfc_debugfs_enable; |
| 157 | lpfc_debugfs_enable = 0; |
| 158 | |
| 159 | len = 0; |
| 160 | index = (atomic_read(&vport->disc_trc_cnt) + 1) & |
| 161 | (lpfc_debugfs_max_disc_trc - 1); |
| 162 | for (i = index; i < lpfc_debugfs_max_disc_trc; i++) { |
| 163 | dtp = vport->disc_trc + i; |
| 164 | if (!dtp->fmt) |
| 165 | continue; |
| 166 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 167 | snprintf(buffer, |
| 168 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 169 | dtp->seq_cnt, ms, dtp->fmt); |
| 170 | len += snprintf(buf+len, size-len, buffer, |
| 171 | dtp->data1, dtp->data2, dtp->data3); |
| 172 | } |
| 173 | for (i = 0; i < index; i++) { |
| 174 | dtp = vport->disc_trc + i; |
| 175 | if (!dtp->fmt) |
| 176 | continue; |
| 177 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 178 | snprintf(buffer, |
| 179 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 180 | dtp->seq_cnt, ms, dtp->fmt); |
| 181 | len += snprintf(buf+len, size-len, buffer, |
| 182 | dtp->data1, dtp->data2, dtp->data3); |
| 183 | } |
| 184 | |
| 185 | lpfc_debugfs_enable = enable; |
| 186 | return len; |
| 187 | } |
| 188 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 189 | /** |
| 190 | * lpfc_debugfs_slow_ring_trc_data - Dump slow ring logging to a buffer. |
| 191 | * @phba: The HBA to gather the log info from. |
| 192 | * @buf: The buffer to dump log into. |
| 193 | * @size: The maximum amount of data to process. |
| 194 | * |
| 195 | * Description: |
| 196 | * This routine gathers the lpfc slow ring debugfs data from the @phba and |
| 197 | * dumps it to @buf up to @size number of bytes. It will start at the next entry |
| 198 | * in the log and process the log until the end of the buffer. Then it will |
| 199 | * gather from the beginning of the log and process until the current entry. |
| 200 | * |
| 201 | * Notes: |
| 202 | * Slow ring logging will be disabled while while this routine dumps the log. |
| 203 | * |
| 204 | * Return Value: |
| 205 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 206 | * not exceed @size. |
| 207 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 208 | static int |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 209 | lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size) |
| 210 | { |
| 211 | int i, index, len, enable; |
| 212 | uint32_t ms; |
| 213 | struct lpfc_debugfs_trc *dtp; |
| 214 | char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; |
| 215 | |
| 216 | |
| 217 | enable = lpfc_debugfs_enable; |
| 218 | lpfc_debugfs_enable = 0; |
| 219 | |
| 220 | len = 0; |
| 221 | index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) & |
| 222 | (lpfc_debugfs_max_slow_ring_trc - 1); |
| 223 | for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) { |
| 224 | dtp = phba->slow_ring_trc + i; |
| 225 | if (!dtp->fmt) |
| 226 | continue; |
| 227 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
| 228 | snprintf(buffer, |
| 229 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
| 230 | dtp->seq_cnt, ms, dtp->fmt); |
| 231 | len += snprintf(buf+len, size-len, buffer, |
| 232 | dtp->data1, dtp->data2, dtp->data3); |
| 233 | } |
| 234 | for (i = 0; i < index; i++) { |
| 235 | dtp = phba->slow_ring_trc + i; |
| 236 | if (!dtp->fmt) |
| 237 | continue; |
| 238 | ms = jiffies_to_msecs(dtp->jif - lpfc_debugfs_start_time); |
| 239 | snprintf(buffer, |
| 240 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", |
| 241 | dtp->seq_cnt, ms, dtp->fmt); |
| 242 | len += snprintf(buf+len, size-len, buffer, |
| 243 | dtp->data1, dtp->data2, dtp->data3); |
| 244 | } |
| 245 | |
| 246 | lpfc_debugfs_enable = enable; |
| 247 | return len; |
| 248 | } |
| 249 | |
James Smart | 311464e | 2007-08-02 11:10:37 -0400 | [diff] [blame] | 250 | static int lpfc_debugfs_last_hbq = -1; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 251 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 252 | /** |
| 253 | * lpfc_debugfs_hbqinfo_data - Dump host buffer queue info to a buffer. |
| 254 | * @phba: The HBA to gather host buffer info from. |
| 255 | * @buf: The buffer to dump log into. |
| 256 | * @size: The maximum amount of data to process. |
| 257 | * |
| 258 | * Description: |
| 259 | * This routine dumps the host buffer queue info from the @phba to @buf up to |
| 260 | * @size number of bytes. A header that describes the current hbq state will be |
| 261 | * dumped to @buf first and then info on each hbq entry will be dumped to @buf |
| 262 | * until @size bytes have been dumped or all the hbq info has been dumped. |
| 263 | * |
| 264 | * Notes: |
| 265 | * This routine will rotate through each configured HBQ each time called. |
| 266 | * |
| 267 | * Return Value: |
| 268 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 269 | * not exceed @size. |
| 270 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 271 | static int |
| 272 | lpfc_debugfs_hbqinfo_data(struct lpfc_hba *phba, char *buf, int size) |
| 273 | { |
| 274 | int len = 0; |
| 275 | int cnt, i, j, found, posted, low; |
| 276 | uint32_t phys, raw_index, getidx; |
| 277 | struct lpfc_hbq_init *hip; |
| 278 | struct hbq_s *hbqs; |
| 279 | struct lpfc_hbq_entry *hbqe; |
| 280 | struct lpfc_dmabuf *d_buf; |
| 281 | struct hbq_dmabuf *hbq_buf; |
| 282 | |
| 283 | cnt = LPFC_HBQINFO_SIZE; |
| 284 | spin_lock_irq(&phba->hbalock); |
| 285 | |
| 286 | /* toggle between multiple hbqs, if any */ |
| 287 | i = lpfc_sli_hbq_count(); |
| 288 | if (i > 1) { |
| 289 | lpfc_debugfs_last_hbq++; |
| 290 | if (lpfc_debugfs_last_hbq >= i) |
| 291 | lpfc_debugfs_last_hbq = 0; |
| 292 | } |
| 293 | else |
| 294 | lpfc_debugfs_last_hbq = 0; |
| 295 | |
| 296 | i = lpfc_debugfs_last_hbq; |
| 297 | |
| 298 | len += snprintf(buf+len, size-len, "HBQ %d Info\n", i); |
| 299 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 300 | hbqs = &phba->hbqs[i]; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 301 | posted = 0; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 302 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 303 | posted++; |
| 304 | |
| 305 | hip = lpfc_hbq_defs[i]; |
| 306 | len += snprintf(buf+len, size-len, |
| 307 | "idx:%d prof:%d rn:%d bufcnt:%d icnt:%d acnt:%d posted %d\n", |
| 308 | hip->hbq_index, hip->profile, hip->rn, |
| 309 | hip->buffer_count, hip->init_count, hip->add_count, posted); |
| 310 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 311 | raw_index = phba->hbq_get[i]; |
| 312 | getidx = le32_to_cpu(raw_index); |
| 313 | len += snprintf(buf+len, size-len, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 314 | "entrys:%d bufcnt:%d Put:%d nPut:%d localGet:%d hbaGet:%d\n", |
| 315 | hbqs->entry_count, hbqs->buffer_count, hbqs->hbqPutIdx, |
| 316 | hbqs->next_hbqPutIdx, hbqs->local_hbqGetIdx, getidx); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 317 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 318 | hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt; |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 319 | for (j=0; j<hbqs->entry_count; j++) { |
| 320 | len += snprintf(buf+len, size-len, |
| 321 | "%03d: %08x %04x %05x ", j, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 322 | le32_to_cpu(hbqe->bde.addrLow), |
| 323 | le32_to_cpu(hbqe->bde.tus.w), |
| 324 | le32_to_cpu(hbqe->buffer_tag)); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 325 | i = 0; |
| 326 | found = 0; |
| 327 | |
| 328 | /* First calculate if slot has an associated posted buffer */ |
| 329 | low = hbqs->hbqPutIdx - posted; |
| 330 | if (low >= 0) { |
| 331 | if ((j >= hbqs->hbqPutIdx) || (j < low)) { |
| 332 | len += snprintf(buf+len, size-len, "Unused\n"); |
| 333 | goto skipit; |
| 334 | } |
| 335 | } |
| 336 | else { |
| 337 | if ((j >= hbqs->hbqPutIdx) && |
| 338 | (j < (hbqs->entry_count+low))) { |
| 339 | len += snprintf(buf+len, size-len, "Unused\n"); |
| 340 | goto skipit; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* Get the Buffer info for the posted buffer */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 345 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 346 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
| 347 | phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff); |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 348 | if (phys == le32_to_cpu(hbqe->bde.addrLow)) { |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 349 | len += snprintf(buf+len, size-len, |
| 350 | "Buf%d: %p %06x\n", i, |
| 351 | hbq_buf->dbuf.virt, hbq_buf->tag); |
| 352 | found = 1; |
| 353 | break; |
| 354 | } |
| 355 | i++; |
| 356 | } |
| 357 | if (!found) { |
| 358 | len += snprintf(buf+len, size-len, "No DMAinfo?\n"); |
| 359 | } |
| 360 | skipit: |
| 361 | hbqe++; |
| 362 | if (len > LPFC_HBQINFO_SIZE - 54) |
| 363 | break; |
| 364 | } |
| 365 | spin_unlock_irq(&phba->hbalock); |
| 366 | return len; |
| 367 | } |
| 368 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 369 | static int lpfc_debugfs_last_hba_slim_off; |
| 370 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 371 | /** |
| 372 | * lpfc_debugfs_dumpHBASlim_data - Dump HBA SLIM info to a buffer. |
| 373 | * @phba: The HBA to gather SLIM info from. |
| 374 | * @buf: The buffer to dump log into. |
| 375 | * @size: The maximum amount of data to process. |
| 376 | * |
| 377 | * Description: |
| 378 | * This routine dumps the current contents of HBA SLIM for the HBA associated |
| 379 | * with @phba to @buf up to @size bytes of data. This is the raw HBA SLIM data. |
| 380 | * |
| 381 | * Notes: |
| 382 | * This routine will only dump up to 1024 bytes of data each time called and |
| 383 | * should be called multiple times to dump the entire HBA SLIM. |
| 384 | * |
| 385 | * Return Value: |
| 386 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 387 | * not exceed @size. |
| 388 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 389 | static int |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 390 | lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 391 | { |
| 392 | int len = 0; |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 393 | int i, off; |
| 394 | uint32_t *ptr; |
| 395 | char buffer[1024]; |
| 396 | |
| 397 | off = 0; |
| 398 | spin_lock_irq(&phba->hbalock); |
| 399 | |
| 400 | len += snprintf(buf+len, size-len, "HBA SLIM\n"); |
| 401 | lpfc_memcpy_from_slim(buffer, |
| 402 | ((uint8_t *)phba->MBslimaddr) + lpfc_debugfs_last_hba_slim_off, |
| 403 | 1024); |
| 404 | |
| 405 | ptr = (uint32_t *)&buffer[0]; |
| 406 | off = lpfc_debugfs_last_hba_slim_off; |
| 407 | |
| 408 | /* Set it up for the next time */ |
| 409 | lpfc_debugfs_last_hba_slim_off += 1024; |
| 410 | if (lpfc_debugfs_last_hba_slim_off >= 4096) |
| 411 | lpfc_debugfs_last_hba_slim_off = 0; |
| 412 | |
| 413 | i = 1024; |
| 414 | while (i > 0) { |
| 415 | len += snprintf(buf+len, size-len, |
| 416 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 417 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 418 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 419 | ptr += 8; |
| 420 | i -= (8 * sizeof(uint32_t)); |
| 421 | off += (8 * sizeof(uint32_t)); |
| 422 | } |
| 423 | |
| 424 | spin_unlock_irq(&phba->hbalock); |
| 425 | return len; |
| 426 | } |
| 427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 428 | /** |
| 429 | * lpfc_debugfs_dumpHostSlim_data - Dump host SLIM info to a buffer. |
| 430 | * @phba: The HBA to gather Host SLIM info from. |
| 431 | * @buf: The buffer to dump log into. |
| 432 | * @size: The maximum amount of data to process. |
| 433 | * |
| 434 | * Description: |
| 435 | * This routine dumps the current contents of host SLIM for the host associated |
| 436 | * with @phba to @buf up to @size bytes of data. The dump will contain the |
| 437 | * Mailbox, PCB, Rings, and Registers that are located in host memory. |
| 438 | * |
| 439 | * Return Value: |
| 440 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 441 | * not exceed @size. |
| 442 | **/ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 443 | static int |
| 444 | lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size) |
| 445 | { |
| 446 | int len = 0; |
| 447 | int i, off; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 448 | uint32_t word0, word1, word2, word3; |
| 449 | uint32_t *ptr; |
| 450 | struct lpfc_pgp *pgpp; |
| 451 | struct lpfc_sli *psli = &phba->sli; |
| 452 | struct lpfc_sli_ring *pring; |
| 453 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 454 | off = 0; |
| 455 | spin_lock_irq(&phba->hbalock); |
| 456 | |
| 457 | len += snprintf(buf+len, size-len, "SLIM Mailbox\n"); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 458 | ptr = (uint32_t *)phba->slim2p.virt; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 459 | i = sizeof(MAILBOX_t); |
| 460 | while (i > 0) { |
| 461 | len += snprintf(buf+len, size-len, |
| 462 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 463 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 464 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 465 | ptr += 8; |
| 466 | i -= (8 * sizeof(uint32_t)); |
| 467 | off += (8 * sizeof(uint32_t)); |
| 468 | } |
| 469 | |
| 470 | len += snprintf(buf+len, size-len, "SLIM PCB\n"); |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 471 | ptr = (uint32_t *)phba->pcb; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 472 | i = sizeof(PCB_t); |
| 473 | while (i > 0) { |
| 474 | len += snprintf(buf+len, size-len, |
| 475 | "%08x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 476 | off, *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), |
| 477 | *(ptr+5), *(ptr+6), *(ptr+7)); |
| 478 | ptr += 8; |
| 479 | i -= (8 * sizeof(uint32_t)); |
| 480 | off += (8 * sizeof(uint32_t)); |
| 481 | } |
| 482 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 483 | for (i = 0; i < 4; i++) { |
| 484 | pgpp = &phba->port_gp[i]; |
| 485 | pring = &psli->ring[i]; |
| 486 | len += snprintf(buf+len, size-len, |
| 487 | "Ring %d: CMD GetInx:%d (Max:%d Next:%d " |
| 488 | "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n", |
| 489 | i, pgpp->cmdGetInx, pring->numCiocb, |
| 490 | pring->next_cmdidx, pring->local_getidx, |
| 491 | pring->flag, pgpp->rspPutInx, pring->numRiocb); |
| 492 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 493 | word0 = readl(phba->HAregaddr); |
| 494 | word1 = readl(phba->CAregaddr); |
| 495 | word2 = readl(phba->HSregaddr); |
| 496 | word3 = readl(phba->HCregaddr); |
| 497 | len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n", |
| 498 | word0, word1, word2, word3); |
| 499 | spin_unlock_irq(&phba->hbalock); |
| 500 | return len; |
| 501 | } |
| 502 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 503 | /** |
| 504 | * lpfc_debugfs_nodelist_data - Dump target node list to a buffer. |
| 505 | * @vport: The vport to gather target node info from. |
| 506 | * @buf: The buffer to dump log into. |
| 507 | * @size: The maximum amount of data to process. |
| 508 | * |
| 509 | * Description: |
| 510 | * This routine dumps the current target node list associated with @vport to |
| 511 | * @buf up to @size bytes of data. Each node entry in the dump will contain a |
| 512 | * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields. |
| 513 | * |
| 514 | * Return Value: |
| 515 | * This routine returns the amount of bytes that were dumped into @buf and will |
| 516 | * not exceed @size. |
| 517 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 518 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 519 | lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size) |
| 520 | { |
| 521 | int len = 0; |
| 522 | int cnt; |
| 523 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 524 | struct lpfc_nodelist *ndlp; |
| 525 | unsigned char *statep, *name; |
| 526 | |
| 527 | cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE); |
| 528 | |
| 529 | spin_lock_irq(shost->host_lock); |
| 530 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
| 531 | if (!cnt) { |
| 532 | len += snprintf(buf+len, size-len, |
| 533 | "Missing Nodelist Entries\n"); |
| 534 | break; |
| 535 | } |
| 536 | cnt--; |
| 537 | switch (ndlp->nlp_state) { |
| 538 | case NLP_STE_UNUSED_NODE: |
| 539 | statep = "UNUSED"; |
| 540 | break; |
| 541 | case NLP_STE_PLOGI_ISSUE: |
| 542 | statep = "PLOGI "; |
| 543 | break; |
| 544 | case NLP_STE_ADISC_ISSUE: |
| 545 | statep = "ADISC "; |
| 546 | break; |
| 547 | case NLP_STE_REG_LOGIN_ISSUE: |
| 548 | statep = "REGLOG"; |
| 549 | break; |
| 550 | case NLP_STE_PRLI_ISSUE: |
| 551 | statep = "PRLI "; |
| 552 | break; |
| 553 | case NLP_STE_UNMAPPED_NODE: |
| 554 | statep = "UNMAP "; |
| 555 | break; |
| 556 | case NLP_STE_MAPPED_NODE: |
| 557 | statep = "MAPPED"; |
| 558 | break; |
| 559 | case NLP_STE_NPR_NODE: |
| 560 | statep = "NPR "; |
| 561 | break; |
| 562 | default: |
| 563 | statep = "UNKNOWN"; |
| 564 | } |
| 565 | len += snprintf(buf+len, size-len, "%s DID:x%06x ", |
| 566 | statep, ndlp->nlp_DID); |
| 567 | name = (unsigned char *)&ndlp->nlp_portname; |
| 568 | len += snprintf(buf+len, size-len, |
| 569 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", |
| 570 | *name, *(name+1), *(name+2), *(name+3), |
| 571 | *(name+4), *(name+5), *(name+6), *(name+7)); |
| 572 | name = (unsigned char *)&ndlp->nlp_nodename; |
| 573 | len += snprintf(buf+len, size-len, |
| 574 | "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", |
| 575 | *name, *(name+1), *(name+2), *(name+3), |
| 576 | *(name+4), *(name+5), *(name+6), *(name+7)); |
| 577 | len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ", |
| 578 | ndlp->nlp_rpi, ndlp->nlp_flag); |
| 579 | if (!ndlp->nlp_type) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 580 | len += snprintf(buf+len, size-len, "UNKNOWN_TYPE "); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 581 | if (ndlp->nlp_type & NLP_FC_NODE) |
| 582 | len += snprintf(buf+len, size-len, "FC_NODE "); |
| 583 | if (ndlp->nlp_type & NLP_FABRIC) |
| 584 | len += snprintf(buf+len, size-len, "FABRIC "); |
| 585 | if (ndlp->nlp_type & NLP_FCP_TARGET) |
| 586 | len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ", |
| 587 | ndlp->nlp_sid); |
| 588 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 589 | len += snprintf(buf+len, size-len, "FCP_INITIATOR "); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 590 | len += snprintf(buf+len, size-len, "usgmap:%x ", |
| 591 | ndlp->nlp_usg_map); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 592 | len += snprintf(buf+len, size-len, "refcnt:%x", |
| 593 | atomic_read(&ndlp->kref.refcount)); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 594 | len += snprintf(buf+len, size-len, "\n"); |
| 595 | } |
| 596 | spin_unlock_irq(shost->host_lock); |
| 597 | return len; |
| 598 | } |
| 599 | #endif |
| 600 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 601 | /** |
| 602 | * lpfc_debugfs_disc_trc - Store discovery trace log. |
| 603 | * @vport: The vport to associate this trace string with for retrieval. |
| 604 | * @mask: Log entry classification. |
| 605 | * @fmt: Format string to be displayed when dumping the log. |
| 606 | * @data1: 1st data parameter to be applied to @fmt. |
| 607 | * @data2: 2nd data parameter to be applied to @fmt. |
| 608 | * @data3: 3rd data parameter to be applied to @fmt. |
| 609 | * |
| 610 | * Description: |
| 611 | * This routine is used by the driver code to add a debugfs log entry to the |
| 612 | * discovery trace buffer associated with @vport. Only entries with a @mask that |
| 613 | * match the current debugfs discovery mask will be saved. Entries that do not |
| 614 | * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like |
| 615 | * printf when displaying the log. |
| 616 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 617 | inline void |
| 618 | lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt, |
| 619 | uint32_t data1, uint32_t data2, uint32_t data3) |
| 620 | { |
| 621 | #ifdef CONFIG_LPFC_DEBUG_FS |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 622 | struct lpfc_debugfs_trc *dtp; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 623 | int index; |
| 624 | |
| 625 | if (!(lpfc_debugfs_mask_disc_trc & mask)) |
| 626 | return; |
| 627 | |
| 628 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc || |
| 629 | !vport || !vport->disc_trc) |
| 630 | return; |
| 631 | |
| 632 | index = atomic_inc_return(&vport->disc_trc_cnt) & |
| 633 | (lpfc_debugfs_max_disc_trc - 1); |
| 634 | dtp = vport->disc_trc + index; |
| 635 | dtp->fmt = fmt; |
| 636 | dtp->data1 = data1; |
| 637 | dtp->data2 = data2; |
| 638 | dtp->data3 = data3; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 639 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); |
| 640 | dtp->jif = jiffies; |
| 641 | #endif |
| 642 | return; |
| 643 | } |
| 644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 645 | /** |
| 646 | * lpfc_debugfs_slow_ring_trc - Store slow ring trace log. |
| 647 | * @phba: The phba to associate this trace string with for retrieval. |
| 648 | * @fmt: Format string to be displayed when dumping the log. |
| 649 | * @data1: 1st data parameter to be applied to @fmt. |
| 650 | * @data2: 2nd data parameter to be applied to @fmt. |
| 651 | * @data3: 3rd data parameter to be applied to @fmt. |
| 652 | * |
| 653 | * Description: |
| 654 | * This routine is used by the driver code to add a debugfs log entry to the |
| 655 | * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and |
| 656 | * @data3 are used like printf when displaying the log. |
| 657 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 658 | inline void |
| 659 | lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt, |
| 660 | uint32_t data1, uint32_t data2, uint32_t data3) |
| 661 | { |
| 662 | #ifdef CONFIG_LPFC_DEBUG_FS |
| 663 | struct lpfc_debugfs_trc *dtp; |
| 664 | int index; |
| 665 | |
| 666 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc || |
| 667 | !phba || !phba->slow_ring_trc) |
| 668 | return; |
| 669 | |
| 670 | index = atomic_inc_return(&phba->slow_ring_trc_cnt) & |
| 671 | (lpfc_debugfs_max_slow_ring_trc - 1); |
| 672 | dtp = phba->slow_ring_trc + index; |
| 673 | dtp->fmt = fmt; |
| 674 | dtp->data1 = data1; |
| 675 | dtp->data2 = data2; |
| 676 | dtp->data3 = data3; |
| 677 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 678 | dtp->jif = jiffies; |
| 679 | #endif |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | #ifdef CONFIG_LPFC_DEBUG_FS |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 684 | /** |
| 685 | * lpfc_debugfs_disc_trc_open - Open the discovery trace log. |
| 686 | * @inode: The inode pointer that contains a vport pointer. |
| 687 | * @file: The file pointer to attach the log output. |
| 688 | * |
| 689 | * Description: |
| 690 | * This routine is the entry point for the debugfs open file operation. It gets |
| 691 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 692 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 693 | * returns a pointer to that log in the private_data field in @file. |
| 694 | * |
| 695 | * Returns: |
| 696 | * This function returns zero if successful. On error it will return an negative |
| 697 | * error value. |
| 698 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 699 | static int |
| 700 | lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file) |
| 701 | { |
| 702 | struct lpfc_vport *vport = inode->i_private; |
| 703 | struct lpfc_debug *debug; |
| 704 | int size; |
| 705 | int rc = -ENOMEM; |
| 706 | |
| 707 | if (!lpfc_debugfs_max_disc_trc) { |
| 708 | rc = -ENOSPC; |
| 709 | goto out; |
| 710 | } |
| 711 | |
| 712 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 713 | if (!debug) |
| 714 | goto out; |
| 715 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 716 | /* Round to page boundary */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 717 | size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 718 | size = PAGE_ALIGN(size); |
| 719 | |
| 720 | debug->buffer = kmalloc(size, GFP_KERNEL); |
| 721 | if (!debug->buffer) { |
| 722 | kfree(debug); |
| 723 | goto out; |
| 724 | } |
| 725 | |
| 726 | debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size); |
| 727 | file->private_data = debug; |
| 728 | |
| 729 | rc = 0; |
| 730 | out: |
| 731 | return rc; |
| 732 | } |
| 733 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 734 | /** |
| 735 | * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log. |
| 736 | * @inode: The inode pointer that contains a vport pointer. |
| 737 | * @file: The file pointer to attach the log output. |
| 738 | * |
| 739 | * Description: |
| 740 | * This routine is the entry point for the debugfs open file operation. It gets |
| 741 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 742 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 743 | * returns a pointer to that log in the private_data field in @file. |
| 744 | * |
| 745 | * Returns: |
| 746 | * This function returns zero if successful. On error it will return an negative |
| 747 | * error value. |
| 748 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 749 | static int |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 750 | lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file) |
| 751 | { |
| 752 | struct lpfc_hba *phba = inode->i_private; |
| 753 | struct lpfc_debug *debug; |
| 754 | int size; |
| 755 | int rc = -ENOMEM; |
| 756 | |
| 757 | if (!lpfc_debugfs_max_slow_ring_trc) { |
| 758 | rc = -ENOSPC; |
| 759 | goto out; |
| 760 | } |
| 761 | |
| 762 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 763 | if (!debug) |
| 764 | goto out; |
| 765 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 766 | /* Round to page boundary */ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 767 | size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
| 768 | size = PAGE_ALIGN(size); |
| 769 | |
| 770 | debug->buffer = kmalloc(size, GFP_KERNEL); |
| 771 | if (!debug->buffer) { |
| 772 | kfree(debug); |
| 773 | goto out; |
| 774 | } |
| 775 | |
| 776 | debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size); |
| 777 | file->private_data = debug; |
| 778 | |
| 779 | rc = 0; |
| 780 | out: |
| 781 | return rc; |
| 782 | } |
| 783 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 784 | /** |
| 785 | * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer. |
| 786 | * @inode: The inode pointer that contains a vport pointer. |
| 787 | * @file: The file pointer to attach the log output. |
| 788 | * |
| 789 | * Description: |
| 790 | * This routine is the entry point for the debugfs open file operation. It gets |
| 791 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 792 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 793 | * returns a pointer to that log in the private_data field in @file. |
| 794 | * |
| 795 | * Returns: |
| 796 | * This function returns zero if successful. On error it will return an negative |
| 797 | * error value. |
| 798 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 799 | static int |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 800 | lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file) |
| 801 | { |
| 802 | struct lpfc_hba *phba = inode->i_private; |
| 803 | struct lpfc_debug *debug; |
| 804 | int rc = -ENOMEM; |
| 805 | |
| 806 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 807 | if (!debug) |
| 808 | goto out; |
| 809 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 810 | /* Round to page boundary */ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 811 | debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); |
| 812 | if (!debug->buffer) { |
| 813 | kfree(debug); |
| 814 | goto out; |
| 815 | } |
| 816 | |
| 817 | debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer, |
| 818 | LPFC_HBQINFO_SIZE); |
| 819 | file->private_data = debug; |
| 820 | |
| 821 | rc = 0; |
| 822 | out: |
| 823 | return rc; |
| 824 | } |
| 825 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 826 | /** |
| 827 | * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer. |
| 828 | * @inode: The inode pointer that contains a vport pointer. |
| 829 | * @file: The file pointer to attach the log output. |
| 830 | * |
| 831 | * Description: |
| 832 | * This routine is the entry point for the debugfs open file operation. It gets |
| 833 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 834 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 835 | * returns a pointer to that log in the private_data field in @file. |
| 836 | * |
| 837 | * Returns: |
| 838 | * This function returns zero if successful. On error it will return an negative |
| 839 | * error value. |
| 840 | **/ |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 841 | static int |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 842 | lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file) |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 843 | { |
| 844 | struct lpfc_hba *phba = inode->i_private; |
| 845 | struct lpfc_debug *debug; |
| 846 | int rc = -ENOMEM; |
| 847 | |
| 848 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 849 | if (!debug) |
| 850 | goto out; |
| 851 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 852 | /* Round to page boundary */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 853 | debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 854 | if (!debug->buffer) { |
| 855 | kfree(debug); |
| 856 | goto out; |
| 857 | } |
| 858 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 859 | debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer, |
| 860 | LPFC_DUMPHBASLIM_SIZE); |
| 861 | file->private_data = debug; |
| 862 | |
| 863 | rc = 0; |
| 864 | out: |
| 865 | return rc; |
| 866 | } |
| 867 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 868 | /** |
| 869 | * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer. |
| 870 | * @inode: The inode pointer that contains a vport pointer. |
| 871 | * @file: The file pointer to attach the log output. |
| 872 | * |
| 873 | * Description: |
| 874 | * This routine is the entry point for the debugfs open file operation. It gets |
| 875 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 876 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 877 | * returns a pointer to that log in the private_data field in @file. |
| 878 | * |
| 879 | * Returns: |
| 880 | * This function returns zero if successful. On error it will return an negative |
| 881 | * error value. |
| 882 | **/ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 883 | static int |
| 884 | lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file) |
| 885 | { |
| 886 | struct lpfc_hba *phba = inode->i_private; |
| 887 | struct lpfc_debug *debug; |
| 888 | int rc = -ENOMEM; |
| 889 | |
| 890 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 891 | if (!debug) |
| 892 | goto out; |
| 893 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 894 | /* Round to page boundary */ |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 895 | debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL); |
| 896 | if (!debug->buffer) { |
| 897 | kfree(debug); |
| 898 | goto out; |
| 899 | } |
| 900 | |
| 901 | debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer, |
| 902 | LPFC_DUMPHOSTSLIM_SIZE); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 903 | file->private_data = debug; |
| 904 | |
| 905 | rc = 0; |
| 906 | out: |
| 907 | return rc; |
| 908 | } |
| 909 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 910 | /** |
| 911 | * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file. |
| 912 | * @inode: The inode pointer that contains a vport pointer. |
| 913 | * @file: The file pointer to attach the log output. |
| 914 | * |
| 915 | * Description: |
| 916 | * This routine is the entry point for the debugfs open file operation. It gets |
| 917 | * the vport from the i_private field in @inode, allocates the necessary buffer |
| 918 | * for the log, fills the buffer from the in-memory log for this vport, and then |
| 919 | * returns a pointer to that log in the private_data field in @file. |
| 920 | * |
| 921 | * Returns: |
| 922 | * This function returns zero if successful. On error it will return an negative |
| 923 | * error value. |
| 924 | **/ |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 925 | static int |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 926 | lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file) |
| 927 | { |
| 928 | struct lpfc_vport *vport = inode->i_private; |
| 929 | struct lpfc_debug *debug; |
| 930 | int rc = -ENOMEM; |
| 931 | |
| 932 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); |
| 933 | if (!debug) |
| 934 | goto out; |
| 935 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 936 | /* Round to page boundary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 937 | debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); |
| 938 | if (!debug->buffer) { |
| 939 | kfree(debug); |
| 940 | goto out; |
| 941 | } |
| 942 | |
| 943 | debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer, |
| 944 | LPFC_NODELIST_SIZE); |
| 945 | file->private_data = debug; |
| 946 | |
| 947 | rc = 0; |
| 948 | out: |
| 949 | return rc; |
| 950 | } |
| 951 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 952 | /** |
| 953 | * lpfc_debugfs_lseek - Seek through a debugfs file. |
| 954 | * @file: The file pointer to seek through. |
| 955 | * @off: The offset to seek to or the amount to seek by. |
| 956 | * @whence: Indicates how to seek. |
| 957 | * |
| 958 | * Description: |
| 959 | * This routine is the entry point for the debugfs lseek file operation. The |
| 960 | * @whence parameter indicates whether @off is the offset to directly seek to, |
| 961 | * or if it is a value to seek forward or reverse by. This function figures out |
| 962 | * what the new offset of the debugfs file will be and assigns that value to the |
| 963 | * f_pos field of @file. |
| 964 | * |
| 965 | * Returns: |
| 966 | * This function returns the new offset if successful and returns a negative |
| 967 | * error if unable to process the seek. |
| 968 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 969 | static loff_t |
| 970 | lpfc_debugfs_lseek(struct file *file, loff_t off, int whence) |
| 971 | { |
| 972 | struct lpfc_debug *debug; |
| 973 | loff_t pos = -1; |
| 974 | |
| 975 | debug = file->private_data; |
| 976 | |
| 977 | switch (whence) { |
| 978 | case 0: |
| 979 | pos = off; |
| 980 | break; |
| 981 | case 1: |
| 982 | pos = file->f_pos + off; |
| 983 | break; |
| 984 | case 2: |
| 985 | pos = debug->len - off; |
| 986 | } |
| 987 | return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos); |
| 988 | } |
| 989 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 990 | /** |
| 991 | * lpfc_debugfs_read - Read a debugfs file. |
| 992 | * @file: The file pointer to read from. |
| 993 | * @buf: The buffer to copy the data to. |
| 994 | * @nbytes: The number of bytes to read. |
| 995 | * @ppos: The position in the file to start reading from. |
| 996 | * |
| 997 | * Description: |
| 998 | * This routine reads data from from the buffer indicated in the private_data |
| 999 | * field of @file. It will start reading at @ppos and copy up to @nbytes of |
| 1000 | * data to @buf. |
| 1001 | * |
| 1002 | * Returns: |
| 1003 | * This function returns the amount of data that was read (this could be less |
| 1004 | * than @nbytes if the end of the file was reached) or a negative error value. |
| 1005 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1006 | static ssize_t |
| 1007 | lpfc_debugfs_read(struct file *file, char __user *buf, |
| 1008 | size_t nbytes, loff_t *ppos) |
| 1009 | { |
| 1010 | struct lpfc_debug *debug = file->private_data; |
| 1011 | return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, |
| 1012 | debug->len); |
| 1013 | } |
| 1014 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1015 | /** |
| 1016 | * lpfc_debugfs_release - Release the buffer used to store debugfs file data. |
| 1017 | * @inode: The inode pointer that contains a vport pointer. (unused) |
| 1018 | * @file: The file pointer that contains the buffer to release. |
| 1019 | * |
| 1020 | * Description: |
| 1021 | * This routine frees the buffer that was allocated when the debugfs file was |
| 1022 | * opened. |
| 1023 | * |
| 1024 | * Returns: |
| 1025 | * This function returns zero. |
| 1026 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1027 | static int |
| 1028 | lpfc_debugfs_release(struct inode *inode, struct file *file) |
| 1029 | { |
| 1030 | struct lpfc_debug *debug = file->private_data; |
| 1031 | |
| 1032 | kfree(debug->buffer); |
| 1033 | kfree(debug); |
| 1034 | |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
| 1038 | #undef lpfc_debugfs_op_disc_trc |
| 1039 | static struct file_operations lpfc_debugfs_op_disc_trc = { |
| 1040 | .owner = THIS_MODULE, |
| 1041 | .open = lpfc_debugfs_disc_trc_open, |
| 1042 | .llseek = lpfc_debugfs_lseek, |
| 1043 | .read = lpfc_debugfs_read, |
| 1044 | .release = lpfc_debugfs_release, |
| 1045 | }; |
| 1046 | |
| 1047 | #undef lpfc_debugfs_op_nodelist |
| 1048 | static struct file_operations lpfc_debugfs_op_nodelist = { |
| 1049 | .owner = THIS_MODULE, |
| 1050 | .open = lpfc_debugfs_nodelist_open, |
| 1051 | .llseek = lpfc_debugfs_lseek, |
| 1052 | .read = lpfc_debugfs_read, |
| 1053 | .release = lpfc_debugfs_release, |
| 1054 | }; |
| 1055 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1056 | #undef lpfc_debugfs_op_hbqinfo |
| 1057 | static struct file_operations lpfc_debugfs_op_hbqinfo = { |
| 1058 | .owner = THIS_MODULE, |
| 1059 | .open = lpfc_debugfs_hbqinfo_open, |
| 1060 | .llseek = lpfc_debugfs_lseek, |
| 1061 | .read = lpfc_debugfs_read, |
| 1062 | .release = lpfc_debugfs_release, |
| 1063 | }; |
| 1064 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1065 | #undef lpfc_debugfs_op_dumpHBASlim |
| 1066 | static struct file_operations lpfc_debugfs_op_dumpHBASlim = { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1067 | .owner = THIS_MODULE, |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1068 | .open = lpfc_debugfs_dumpHBASlim_open, |
| 1069 | .llseek = lpfc_debugfs_lseek, |
| 1070 | .read = lpfc_debugfs_read, |
| 1071 | .release = lpfc_debugfs_release, |
| 1072 | }; |
| 1073 | |
| 1074 | #undef lpfc_debugfs_op_dumpHostSlim |
| 1075 | static struct file_operations lpfc_debugfs_op_dumpHostSlim = { |
| 1076 | .owner = THIS_MODULE, |
| 1077 | .open = lpfc_debugfs_dumpHostSlim_open, |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1078 | .llseek = lpfc_debugfs_lseek, |
| 1079 | .read = lpfc_debugfs_read, |
| 1080 | .release = lpfc_debugfs_release, |
| 1081 | }; |
| 1082 | |
| 1083 | #undef lpfc_debugfs_op_slow_ring_trc |
| 1084 | static struct file_operations lpfc_debugfs_op_slow_ring_trc = { |
| 1085 | .owner = THIS_MODULE, |
| 1086 | .open = lpfc_debugfs_slow_ring_trc_open, |
| 1087 | .llseek = lpfc_debugfs_lseek, |
| 1088 | .read = lpfc_debugfs_read, |
| 1089 | .release = lpfc_debugfs_release, |
| 1090 | }; |
| 1091 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1092 | static struct dentry *lpfc_debugfs_root = NULL; |
| 1093 | static atomic_t lpfc_debugfs_hba_count; |
| 1094 | #endif |
| 1095 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1096 | /** |
| 1097 | * lpfc_debugfs_initialize - Initialize debugfs for a vport. |
| 1098 | * @vport: The vport pointer to initialize. |
| 1099 | * |
| 1100 | * Description: |
| 1101 | * When Debugfs is configured this routine sets up the lpfc debugfs file system. |
| 1102 | * If not already created, this routine will create the lpfc directory, and |
| 1103 | * lpfcX directory (for this HBA), and vportX directory for this vport. It will |
| 1104 | * also create each file used to access lpfc specific debugfs information. |
| 1105 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1106 | inline void |
| 1107 | lpfc_debugfs_initialize(struct lpfc_vport *vport) |
| 1108 | { |
| 1109 | #ifdef CONFIG_LPFC_DEBUG_FS |
| 1110 | struct lpfc_hba *phba = vport->phba; |
| 1111 | char name[64]; |
| 1112 | uint32_t num, i; |
| 1113 | |
| 1114 | if (!lpfc_debugfs_enable) |
| 1115 | return; |
| 1116 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1117 | /* Setup lpfc root directory */ |
| 1118 | if (!lpfc_debugfs_root) { |
| 1119 | lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL); |
| 1120 | atomic_set(&lpfc_debugfs_hba_count, 0); |
| 1121 | if (!lpfc_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1122 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1123 | "0408 Cannot create debugfs root\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1124 | goto debug_failed; |
| 1125 | } |
| 1126 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1127 | if (!lpfc_debugfs_start_time) |
| 1128 | lpfc_debugfs_start_time = jiffies; |
| 1129 | |
| 1130 | /* Setup lpfcX directory for specific HBA */ |
| 1131 | snprintf(name, sizeof(name), "lpfc%d", phba->brd_no); |
| 1132 | if (!phba->hba_debugfs_root) { |
| 1133 | phba->hba_debugfs_root = |
| 1134 | debugfs_create_dir(name, lpfc_debugfs_root); |
| 1135 | if (!phba->hba_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1136 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1137 | "0412 Cannot create debugfs hba\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1138 | goto debug_failed; |
| 1139 | } |
| 1140 | atomic_inc(&lpfc_debugfs_hba_count); |
| 1141 | atomic_set(&phba->debugfs_vport_count, 0); |
| 1142 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1143 | /* Setup hbqinfo */ |
| 1144 | snprintf(name, sizeof(name), "hbqinfo"); |
| 1145 | phba->debug_hbqinfo = |
| 1146 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1147 | phba->hba_debugfs_root, |
| 1148 | phba, &lpfc_debugfs_op_hbqinfo); |
| 1149 | if (!phba->debug_hbqinfo) { |
| 1150 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1151 | "0411 Cannot create debugfs hbqinfo\n"); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1152 | goto debug_failed; |
| 1153 | } |
| 1154 | |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1155 | /* Setup dumpHBASlim */ |
| 1156 | snprintf(name, sizeof(name), "dumpHBASlim"); |
| 1157 | phba->debug_dumpHBASlim = |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1158 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1159 | phba->hba_debugfs_root, |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1160 | phba, &lpfc_debugfs_op_dumpHBASlim); |
| 1161 | if (!phba->debug_dumpHBASlim) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1162 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1163 | "0413 Cannot create debugfs dumpHBASlim\n"); |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1164 | goto debug_failed; |
| 1165 | } |
| 1166 | |
| 1167 | /* Setup dumpHostSlim */ |
| 1168 | snprintf(name, sizeof(name), "dumpHostSlim"); |
| 1169 | phba->debug_dumpHostSlim = |
| 1170 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1171 | phba->hba_debugfs_root, |
| 1172 | phba, &lpfc_debugfs_op_dumpHostSlim); |
| 1173 | if (!phba->debug_dumpHostSlim) { |
| 1174 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1175 | "0414 Cannot create debugfs dumpHostSlim\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1176 | goto debug_failed; |
| 1177 | } |
| 1178 | |
| 1179 | /* Setup slow ring trace */ |
| 1180 | if (lpfc_debugfs_max_slow_ring_trc) { |
| 1181 | num = lpfc_debugfs_max_slow_ring_trc - 1; |
| 1182 | if (num & lpfc_debugfs_max_slow_ring_trc) { |
| 1183 | /* Change to be a power of 2 */ |
| 1184 | num = lpfc_debugfs_max_slow_ring_trc; |
| 1185 | i = 0; |
| 1186 | while (num > 1) { |
| 1187 | num = num >> 1; |
| 1188 | i++; |
| 1189 | } |
| 1190 | lpfc_debugfs_max_slow_ring_trc = (1 << i); |
| 1191 | printk(KERN_ERR |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1192 | "lpfc_debugfs_max_disc_trc changed to " |
| 1193 | "%d\n", lpfc_debugfs_max_disc_trc); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | |
| 1198 | snprintf(name, sizeof(name), "slow_ring_trace"); |
| 1199 | phba->debug_slow_ring_trc = |
| 1200 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1201 | phba->hba_debugfs_root, |
| 1202 | phba, &lpfc_debugfs_op_slow_ring_trc); |
| 1203 | if (!phba->debug_slow_ring_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1204 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1205 | "0415 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1206 | "slow_ring_trace\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1207 | goto debug_failed; |
| 1208 | } |
| 1209 | if (!phba->slow_ring_trc) { |
| 1210 | phba->slow_ring_trc = kmalloc( |
| 1211 | (sizeof(struct lpfc_debugfs_trc) * |
| 1212 | lpfc_debugfs_max_slow_ring_trc), |
| 1213 | GFP_KERNEL); |
| 1214 | if (!phba->slow_ring_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1215 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1216 | "0416 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1217 | "slow_ring buffer\n"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1218 | goto debug_failed; |
| 1219 | } |
| 1220 | atomic_set(&phba->slow_ring_trc_cnt, 0); |
| 1221 | memset(phba->slow_ring_trc, 0, |
| 1222 | (sizeof(struct lpfc_debugfs_trc) * |
| 1223 | lpfc_debugfs_max_slow_ring_trc)); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | snprintf(name, sizeof(name), "vport%d", vport->vpi); |
| 1228 | if (!vport->vport_debugfs_root) { |
| 1229 | vport->vport_debugfs_root = |
| 1230 | debugfs_create_dir(name, phba->hba_debugfs_root); |
| 1231 | if (!vport->vport_debugfs_root) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1232 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1233 | "0417 Cant create debugfs"); |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1234 | goto debug_failed; |
| 1235 | } |
| 1236 | atomic_inc(&phba->debugfs_vport_count); |
| 1237 | } |
| 1238 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1239 | if (lpfc_debugfs_max_disc_trc) { |
| 1240 | num = lpfc_debugfs_max_disc_trc - 1; |
| 1241 | if (num & lpfc_debugfs_max_disc_trc) { |
| 1242 | /* Change to be a power of 2 */ |
| 1243 | num = lpfc_debugfs_max_disc_trc; |
| 1244 | i = 0; |
| 1245 | while (num > 1) { |
| 1246 | num = num >> 1; |
| 1247 | i++; |
| 1248 | } |
| 1249 | lpfc_debugfs_max_disc_trc = (1 << i); |
| 1250 | printk(KERN_ERR |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1251 | "lpfc_debugfs_max_disc_trc changed to %d\n", |
| 1252 | lpfc_debugfs_max_disc_trc); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
Adrian Bunk | ff86ba5 | 2007-10-18 12:52:37 +0200 | [diff] [blame] | 1256 | vport->disc_trc = kzalloc( |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1257 | (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc), |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1258 | GFP_KERNEL); |
| 1259 | |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1260 | if (!vport->disc_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1261 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1262 | "0418 Cannot create debugfs disc trace " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1263 | "buffer\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1264 | goto debug_failed; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1265 | } |
| 1266 | atomic_set(&vport->disc_trc_cnt, 0); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1267 | |
| 1268 | snprintf(name, sizeof(name), "discovery_trace"); |
| 1269 | vport->debug_disc_trc = |
| 1270 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1271 | vport->vport_debugfs_root, |
| 1272 | vport, &lpfc_debugfs_op_disc_trc); |
| 1273 | if (!vport->debug_disc_trc) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1274 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1275 | "0419 Cannot create debugfs " |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1276 | "discovery_trace\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1277 | goto debug_failed; |
| 1278 | } |
| 1279 | snprintf(name, sizeof(name), "nodelist"); |
| 1280 | vport->debug_nodelist = |
| 1281 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
| 1282 | vport->vport_debugfs_root, |
| 1283 | vport, &lpfc_debugfs_op_nodelist); |
| 1284 | if (!vport->debug_nodelist) { |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1285 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
| 1286 | "0409 Cant create debugfs nodelist"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1287 | goto debug_failed; |
| 1288 | } |
| 1289 | debug_failed: |
| 1290 | return; |
| 1291 | #endif |
| 1292 | } |
| 1293 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1294 | /** |
| 1295 | * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport. |
| 1296 | * @vport: The vport pointer to remove from debugfs. |
| 1297 | * |
| 1298 | * Description: |
| 1299 | * When Debugfs is configured this routine removes debugfs file system elements |
| 1300 | * that are specific to this vport. It also checks to see if there are any |
| 1301 | * users left for the debugfs directories associated with the HBA and driver. If |
| 1302 | * this is the last user of the HBA directory or driver directory then it will |
| 1303 | * remove those from the debugfs infrastructure as well. |
| 1304 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1305 | inline void |
| 1306 | lpfc_debugfs_terminate(struct lpfc_vport *vport) |
| 1307 | { |
| 1308 | #ifdef CONFIG_LPFC_DEBUG_FS |
| 1309 | struct lpfc_hba *phba = vport->phba; |
| 1310 | |
| 1311 | if (vport->disc_trc) { |
| 1312 | kfree(vport->disc_trc); |
| 1313 | vport->disc_trc = NULL; |
| 1314 | } |
| 1315 | if (vport->debug_disc_trc) { |
| 1316 | debugfs_remove(vport->debug_disc_trc); /* discovery_trace */ |
| 1317 | vport->debug_disc_trc = NULL; |
| 1318 | } |
| 1319 | if (vport->debug_nodelist) { |
| 1320 | debugfs_remove(vport->debug_nodelist); /* nodelist */ |
| 1321 | vport->debug_nodelist = NULL; |
| 1322 | } |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1323 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1324 | if (vport->vport_debugfs_root) { |
| 1325 | debugfs_remove(vport->vport_debugfs_root); /* vportX */ |
| 1326 | vport->vport_debugfs_root = NULL; |
| 1327 | atomic_dec(&phba->debugfs_vport_count); |
| 1328 | } |
| 1329 | if (atomic_read(&phba->debugfs_vport_count) == 0) { |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1330 | |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1331 | if (phba->debug_hbqinfo) { |
| 1332 | debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */ |
| 1333 | phba->debug_hbqinfo = NULL; |
| 1334 | } |
James Smart | c95d6c6 | 2008-01-11 01:53:23 -0500 | [diff] [blame] | 1335 | if (phba->debug_dumpHBASlim) { |
| 1336 | debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */ |
| 1337 | phba->debug_dumpHBASlim = NULL; |
| 1338 | } |
| 1339 | if (phba->debug_dumpHostSlim) { |
| 1340 | debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */ |
| 1341 | phba->debug_dumpHostSlim = NULL; |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1342 | } |
| 1343 | if (phba->slow_ring_trc) { |
| 1344 | kfree(phba->slow_ring_trc); |
| 1345 | phba->slow_ring_trc = NULL; |
| 1346 | } |
| 1347 | if (phba->debug_slow_ring_trc) { |
| 1348 | /* slow_ring_trace */ |
| 1349 | debugfs_remove(phba->debug_slow_ring_trc); |
| 1350 | phba->debug_slow_ring_trc = NULL; |
| 1351 | } |
| 1352 | |
| 1353 | if (phba->hba_debugfs_root) { |
| 1354 | debugfs_remove(phba->hba_debugfs_root); /* lpfcX */ |
| 1355 | phba->hba_debugfs_root = NULL; |
| 1356 | atomic_dec(&lpfc_debugfs_hba_count); |
| 1357 | } |
| 1358 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1359 | if (atomic_read(&lpfc_debugfs_hba_count) == 0) { |
| 1360 | debugfs_remove(lpfc_debugfs_root); /* lpfc */ |
| 1361 | lpfc_debugfs_root = NULL; |
| 1362 | } |
| 1363 | } |
| 1364 | #endif |
James Smart | a58cbd5 | 2007-08-02 11:09:43 -0400 | [diff] [blame] | 1365 | return; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1366 | } |