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