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