Commit | Line | Data |
---|---|---|
858c9f6c JS |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
3 | * Fibre Channel Host Bus Adapters. * | |
e59058c4 | 4 | * Copyright (C) 2007-2008 Emulex. All rights reserved. * |
858c9f6c JS |
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> | |
858c9f6c JS |
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" | |
c95d6c6c | 45 | #include "lpfc_compat.h" |
858c9f6c JS |
46 | #include "lpfc_debugfs.h" |
47 | ||
48 | #ifdef CONFIG_LPFC_DEBUG_FS | |
e59058c4 JS |
49 | /** |
50 | * debugfs interface | |
858c9f6c JS |
51 | * |
52 | * To access this interface the user should: | |
53 | * # mkdir /debug | |
54 | * # mount -t debugfs none /debug | |
55 | * | |
e59058c4 | 56 | * The lpfc debugfs directory hierarchy is: |
858c9f6c JS |
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. | |
e59058c4 JS |
65 | * See lpfc_debugfs.h for different categories of discovery events. |
66 | * To enable the discovery trace, the following module parameters must be set: | |
858c9f6c JS |
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 . | |
e59058c4 JS |
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. | |
858c9f6c | 80 | */ |
51ef4c26 | 81 | static int lpfc_debugfs_enable = 1; |
858c9f6c JS |
82 | module_param(lpfc_debugfs_enable, int, 0); |
83 | MODULE_PARM_DESC(lpfc_debugfs_enable, "Enable debugfs services"); | |
84 | ||
a58cbd52 | 85 | /* This MUST be a power of 2 */ |
c95d6c6c | 86 | static int lpfc_debugfs_max_disc_trc; |
858c9f6c JS |
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 | ||
a58cbd52 | 91 | /* This MUST be a power of 2 */ |
c95d6c6c | 92 | static int lpfc_debugfs_max_slow_ring_trc; |
a58cbd52 JS |
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 | ||
c95d6c6c | 97 | int lpfc_debugfs_mask_disc_trc; |
858c9f6c JS |
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 | ||
a58cbd52 JS |
104 | /* size of output line, for discovery_trace and slow_ring_trace */ |
105 | #define LPFC_DEBUG_TRC_ENTRY_SIZE 100 | |
858c9f6c JS |
106 | |
107 | /* nodelist output buffer size */ | |
108 | #define LPFC_NODELIST_SIZE 8192 | |
109 | #define LPFC_NODELIST_ENTRY_SIZE 120 | |
110 | ||
c95d6c6c JS |
111 | /* dumpHBASlim output buffer size */ |
112 | #define LPFC_DUMPHBASLIM_SIZE 4096 | |
113 | ||
114 | /* dumpHostSlim output buffer size */ | |
115 | #define LPFC_DUMPHOSTSLIM_SIZE 4096 | |
a58cbd52 | 116 | |
78b2d852 JS |
117 | /* hbqinfo output buffer size */ |
118 | #define LPFC_HBQINFO_SIZE 8192 | |
119 | ||
858c9f6c JS |
120 | struct lpfc_debug { |
121 | char *buffer; | |
122 | int len; | |
123 | }; | |
124 | ||
311464ec JS |
125 | static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0); |
126 | static unsigned long lpfc_debugfs_start_time = 0L; | |
858c9f6c | 127 | |
e59058c4 JS |
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 | **/ | |
858c9f6c JS |
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; | |
a58cbd52 JS |
152 | struct lpfc_debugfs_trc *dtp; |
153 | char buffer[LPFC_DEBUG_TRC_ENTRY_SIZE]; | |
858c9f6c | 154 | |
858c9f6c JS |
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); | |
a58cbd52 JS |
166 | snprintf(buffer, |
167 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", | |
858c9f6c JS |
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); | |
a58cbd52 JS |
177 | snprintf(buffer, |
178 | LPFC_DEBUG_TRC_ENTRY_SIZE, "%010d:%010d ms:%s\n", | |
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 | ||
e59058c4 JS |
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 | **/ | |
a58cbd52 JS |
207 | static int |
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", | |
858c9f6c JS |
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 | ||
311464ec | 249 | static int lpfc_debugfs_last_hbq = -1; |
78b2d852 | 250 | |
e59058c4 JS |
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 | **/ | |
78b2d852 JS |
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 | ||
51ef4c26 | 299 | hbqs = &phba->hbqs[i]; |
78b2d852 | 300 | posted = 0; |
51ef4c26 | 301 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) |
78b2d852 JS |
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 | ||
78b2d852 JS |
310 | raw_index = phba->hbq_get[i]; |
311 | getidx = le32_to_cpu(raw_index); | |
312 | len += snprintf(buf+len, size-len, | |
a8adb832 JS |
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); | |
78b2d852 | 316 | |
51ef4c26 | 317 | hbqe = (struct lpfc_hbq_entry *) phba->hbqs[i].hbq_virt; |
78b2d852 JS |
318 | for (j=0; j<hbqs->entry_count; j++) { |
319 | len += snprintf(buf+len, size-len, | |
320 | "%03d: %08x %04x %05x ", j, | |
a8adb832 JS |
321 | le32_to_cpu(hbqe->bde.addrLow), |
322 | le32_to_cpu(hbqe->bde.tus.w), | |
323 | le32_to_cpu(hbqe->buffer_tag)); | |
78b2d852 JS |
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 */ | |
51ef4c26 | 344 | list_for_each_entry(d_buf, &hbqs->hbq_buffer_list, list) { |
78b2d852 JS |
345 | hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf); |
346 | phys = ((uint64_t)hbq_buf->dbuf.phys & 0xffffffff); | |
a8adb832 | 347 | if (phys == le32_to_cpu(hbqe->bde.addrLow)) { |
78b2d852 JS |
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 | ||
c95d6c6c JS |
368 | static int lpfc_debugfs_last_hba_slim_off; |
369 | ||
e59058c4 JS |
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 | **/ | |
c95d6c6c JS |
388 | static int |
389 | lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size) | |
390 | { | |
391 | int len = 0; | |
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 | ||
e59058c4 JS |
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 | **/ | |
a58cbd52 | 442 | static int |
c95d6c6c | 443 | lpfc_debugfs_dumpHostSlim_data(struct lpfc_hba *phba, char *buf, int size) |
a58cbd52 JS |
444 | { |
445 | int len = 0; | |
c95d6c6c | 446 | int i, off; |
a58cbd52 JS |
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 | ||
a58cbd52 JS |
453 | off = 0; |
454 | spin_lock_irq(&phba->hbalock); | |
455 | ||
456 | len += snprintf(buf+len, size-len, "SLIM Mailbox\n"); | |
34b02dcd | 457 | ptr = (uint32_t *)phba->slim2p.virt; |
a58cbd52 JS |
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"); | |
34b02dcd | 470 | ptr = (uint32_t *)phba->pcb; |
a58cbd52 JS |
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 | ||
34b02dcd JS |
482 | for (i = 0; i < 4; i++) { |
483 | pgpp = &phba->port_gp[i]; | |
484 | pring = &psli->ring[i]; | |
485 | len += snprintf(buf+len, size-len, | |
486 | "Ring %d: CMD GetInx:%d (Max:%d Next:%d " | |
487 | "Local:%d flg:x%x) RSP PutInx:%d Max:%d\n", | |
488 | i, pgpp->cmdGetInx, pring->numCiocb, | |
489 | pring->next_cmdidx, pring->local_getidx, | |
490 | pring->flag, pgpp->rspPutInx, pring->numRiocb); | |
491 | } | |
a58cbd52 JS |
492 | word0 = readl(phba->HAregaddr); |
493 | word1 = readl(phba->CAregaddr); | |
494 | word2 = readl(phba->HSregaddr); | |
495 | word3 = readl(phba->HCregaddr); | |
496 | len += snprintf(buf+len, size-len, "HA:%08x CA:%08x HS:%08x HC:%08x\n", | |
497 | word0, word1, word2, word3); | |
498 | spin_unlock_irq(&phba->hbalock); | |
499 | return len; | |
500 | } | |
501 | ||
e59058c4 JS |
502 | /** |
503 | * lpfc_debugfs_nodelist_data - Dump target node list to a buffer. | |
504 | * @vport: The vport to gather target node info from. | |
505 | * @buf: The buffer to dump log into. | |
506 | * @size: The maximum amount of data to process. | |
507 | * | |
508 | * Description: | |
509 | * This routine dumps the current target node list associated with @vport to | |
510 | * @buf up to @size bytes of data. Each node entry in the dump will contain a | |
511 | * node state, DID, WWPN, WWNN, RPI, flags, type, and other useful fields. | |
512 | * | |
513 | * Return Value: | |
514 | * This routine returns the amount of bytes that were dumped into @buf and will | |
515 | * not exceed @size. | |
516 | **/ | |
858c9f6c JS |
517 | static int |
518 | lpfc_debugfs_nodelist_data(struct lpfc_vport *vport, char *buf, int size) | |
519 | { | |
520 | int len = 0; | |
521 | int cnt; | |
522 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
523 | struct lpfc_nodelist *ndlp; | |
524 | unsigned char *statep, *name; | |
525 | ||
526 | cnt = (LPFC_NODELIST_SIZE / LPFC_NODELIST_ENTRY_SIZE); | |
527 | ||
528 | spin_lock_irq(shost->host_lock); | |
529 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
530 | if (!cnt) { | |
531 | len += snprintf(buf+len, size-len, | |
532 | "Missing Nodelist Entries\n"); | |
533 | break; | |
534 | } | |
535 | cnt--; | |
536 | switch (ndlp->nlp_state) { | |
537 | case NLP_STE_UNUSED_NODE: | |
538 | statep = "UNUSED"; | |
539 | break; | |
540 | case NLP_STE_PLOGI_ISSUE: | |
541 | statep = "PLOGI "; | |
542 | break; | |
543 | case NLP_STE_ADISC_ISSUE: | |
544 | statep = "ADISC "; | |
545 | break; | |
546 | case NLP_STE_REG_LOGIN_ISSUE: | |
547 | statep = "REGLOG"; | |
548 | break; | |
549 | case NLP_STE_PRLI_ISSUE: | |
550 | statep = "PRLI "; | |
551 | break; | |
552 | case NLP_STE_UNMAPPED_NODE: | |
553 | statep = "UNMAP "; | |
554 | break; | |
555 | case NLP_STE_MAPPED_NODE: | |
556 | statep = "MAPPED"; | |
557 | break; | |
558 | case NLP_STE_NPR_NODE: | |
559 | statep = "NPR "; | |
560 | break; | |
561 | default: | |
562 | statep = "UNKNOWN"; | |
563 | } | |
564 | len += snprintf(buf+len, size-len, "%s DID:x%06x ", | |
565 | statep, ndlp->nlp_DID); | |
566 | name = (unsigned char *)&ndlp->nlp_portname; | |
567 | len += snprintf(buf+len, size-len, | |
568 | "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", | |
569 | *name, *(name+1), *(name+2), *(name+3), | |
570 | *(name+4), *(name+5), *(name+6), *(name+7)); | |
571 | name = (unsigned char *)&ndlp->nlp_nodename; | |
572 | len += snprintf(buf+len, size-len, | |
573 | "WWNN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ", | |
574 | *name, *(name+1), *(name+2), *(name+3), | |
575 | *(name+4), *(name+5), *(name+6), *(name+7)); | |
576 | len += snprintf(buf+len, size-len, "RPI:%03d flag:x%08x ", | |
577 | ndlp->nlp_rpi, ndlp->nlp_flag); | |
578 | if (!ndlp->nlp_type) | |
a58cbd52 | 579 | len += snprintf(buf+len, size-len, "UNKNOWN_TYPE "); |
858c9f6c JS |
580 | if (ndlp->nlp_type & NLP_FC_NODE) |
581 | len += snprintf(buf+len, size-len, "FC_NODE "); | |
582 | if (ndlp->nlp_type & NLP_FABRIC) | |
583 | len += snprintf(buf+len, size-len, "FABRIC "); | |
584 | if (ndlp->nlp_type & NLP_FCP_TARGET) | |
585 | len += snprintf(buf+len, size-len, "FCP_TGT sid:%d ", | |
586 | ndlp->nlp_sid); | |
587 | if (ndlp->nlp_type & NLP_FCP_INITIATOR) | |
a58cbd52 | 588 | len += snprintf(buf+len, size-len, "FCP_INITIATOR "); |
58da1ffb JS |
589 | len += snprintf(buf+len, size-len, "usgmap:%x ", |
590 | ndlp->nlp_usg_map); | |
a58cbd52 JS |
591 | len += snprintf(buf+len, size-len, "refcnt:%x", |
592 | atomic_read(&ndlp->kref.refcount)); | |
858c9f6c JS |
593 | len += snprintf(buf+len, size-len, "\n"); |
594 | } | |
595 | spin_unlock_irq(shost->host_lock); | |
596 | return len; | |
597 | } | |
598 | #endif | |
599 | ||
e59058c4 JS |
600 | /** |
601 | * lpfc_debugfs_disc_trc - Store discovery trace log. | |
602 | * @vport: The vport to associate this trace string with for retrieval. | |
603 | * @mask: Log entry classification. | |
604 | * @fmt: Format string to be displayed when dumping the log. | |
605 | * @data1: 1st data parameter to be applied to @fmt. | |
606 | * @data2: 2nd data parameter to be applied to @fmt. | |
607 | * @data3: 3rd data parameter to be applied to @fmt. | |
608 | * | |
609 | * Description: | |
610 | * This routine is used by the driver code to add a debugfs log entry to the | |
611 | * discovery trace buffer associated with @vport. Only entries with a @mask that | |
612 | * match the current debugfs discovery mask will be saved. Entries that do not | |
613 | * match will be thrown away. @fmt, @data1, @data2, and @data3 are used like | |
614 | * printf when displaying the log. | |
615 | **/ | |
858c9f6c JS |
616 | inline void |
617 | lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt, | |
618 | uint32_t data1, uint32_t data2, uint32_t data3) | |
619 | { | |
620 | #ifdef CONFIG_LPFC_DEBUG_FS | |
a58cbd52 | 621 | struct lpfc_debugfs_trc *dtp; |
858c9f6c JS |
622 | int index; |
623 | ||
624 | if (!(lpfc_debugfs_mask_disc_trc & mask)) | |
625 | return; | |
626 | ||
627 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_disc_trc || | |
628 | !vport || !vport->disc_trc) | |
629 | return; | |
630 | ||
631 | index = atomic_inc_return(&vport->disc_trc_cnt) & | |
632 | (lpfc_debugfs_max_disc_trc - 1); | |
633 | dtp = vport->disc_trc + index; | |
634 | dtp->fmt = fmt; | |
635 | dtp->data1 = data1; | |
636 | dtp->data2 = data2; | |
637 | dtp->data3 = data3; | |
a58cbd52 JS |
638 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); |
639 | dtp->jif = jiffies; | |
640 | #endif | |
641 | return; | |
642 | } | |
643 | ||
e59058c4 JS |
644 | /** |
645 | * lpfc_debugfs_slow_ring_trc - Store slow ring trace log. | |
646 | * @phba: The phba to associate this trace string with for retrieval. | |
647 | * @fmt: Format string to be displayed when dumping the log. | |
648 | * @data1: 1st data parameter to be applied to @fmt. | |
649 | * @data2: 2nd data parameter to be applied to @fmt. | |
650 | * @data3: 3rd data parameter to be applied to @fmt. | |
651 | * | |
652 | * Description: | |
653 | * This routine is used by the driver code to add a debugfs log entry to the | |
654 | * discovery trace buffer associated with @vport. @fmt, @data1, @data2, and | |
655 | * @data3 are used like printf when displaying the log. | |
656 | **/ | |
a58cbd52 JS |
657 | inline void |
658 | lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt, | |
659 | uint32_t data1, uint32_t data2, uint32_t data3) | |
660 | { | |
661 | #ifdef CONFIG_LPFC_DEBUG_FS | |
662 | struct lpfc_debugfs_trc *dtp; | |
663 | int index; | |
664 | ||
665 | if (!lpfc_debugfs_enable || !lpfc_debugfs_max_slow_ring_trc || | |
666 | !phba || !phba->slow_ring_trc) | |
667 | return; | |
668 | ||
669 | index = atomic_inc_return(&phba->slow_ring_trc_cnt) & | |
670 | (lpfc_debugfs_max_slow_ring_trc - 1); | |
671 | dtp = phba->slow_ring_trc + index; | |
672 | dtp->fmt = fmt; | |
673 | dtp->data1 = data1; | |
674 | dtp->data2 = data2; | |
675 | dtp->data3 = data3; | |
676 | dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt); | |
858c9f6c JS |
677 | dtp->jif = jiffies; |
678 | #endif | |
679 | return; | |
680 | } | |
681 | ||
682 | #ifdef CONFIG_LPFC_DEBUG_FS | |
e59058c4 JS |
683 | /** |
684 | * lpfc_debugfs_disc_trc_open - Open the discovery trace log. | |
685 | * @inode: The inode pointer that contains a vport pointer. | |
686 | * @file: The file pointer to attach the log output. | |
687 | * | |
688 | * Description: | |
689 | * This routine is the entry point for the debugfs open file operation. It gets | |
690 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
691 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
692 | * returns a pointer to that log in the private_data field in @file. | |
693 | * | |
694 | * Returns: | |
695 | * This function returns zero if successful. On error it will return an negative | |
696 | * error value. | |
697 | **/ | |
858c9f6c JS |
698 | static int |
699 | lpfc_debugfs_disc_trc_open(struct inode *inode, struct file *file) | |
700 | { | |
701 | struct lpfc_vport *vport = inode->i_private; | |
702 | struct lpfc_debug *debug; | |
703 | int size; | |
704 | int rc = -ENOMEM; | |
705 | ||
706 | if (!lpfc_debugfs_max_disc_trc) { | |
707 | rc = -ENOSPC; | |
708 | goto out; | |
709 | } | |
710 | ||
711 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
712 | if (!debug) | |
713 | goto out; | |
714 | ||
e59058c4 | 715 | /* Round to page boundary */ |
a58cbd52 | 716 | size = (lpfc_debugfs_max_disc_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
858c9f6c JS |
717 | size = PAGE_ALIGN(size); |
718 | ||
719 | debug->buffer = kmalloc(size, GFP_KERNEL); | |
720 | if (!debug->buffer) { | |
721 | kfree(debug); | |
722 | goto out; | |
723 | } | |
724 | ||
725 | debug->len = lpfc_debugfs_disc_trc_data(vport, debug->buffer, size); | |
726 | file->private_data = debug; | |
727 | ||
728 | rc = 0; | |
729 | out: | |
730 | return rc; | |
731 | } | |
732 | ||
e59058c4 JS |
733 | /** |
734 | * lpfc_debugfs_slow_ring_trc_open - Open the Slow Ring trace log. | |
735 | * @inode: The inode pointer that contains a vport pointer. | |
736 | * @file: The file pointer to attach the log output. | |
737 | * | |
738 | * Description: | |
739 | * This routine is the entry point for the debugfs open file operation. It gets | |
740 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
741 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
742 | * returns a pointer to that log in the private_data field in @file. | |
743 | * | |
744 | * Returns: | |
745 | * This function returns zero if successful. On error it will return an negative | |
746 | * error value. | |
747 | **/ | |
a58cbd52 JS |
748 | static int |
749 | lpfc_debugfs_slow_ring_trc_open(struct inode *inode, struct file *file) | |
750 | { | |
751 | struct lpfc_hba *phba = inode->i_private; | |
752 | struct lpfc_debug *debug; | |
753 | int size; | |
754 | int rc = -ENOMEM; | |
755 | ||
756 | if (!lpfc_debugfs_max_slow_ring_trc) { | |
757 | rc = -ENOSPC; | |
758 | goto out; | |
759 | } | |
760 | ||
761 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
762 | if (!debug) | |
763 | goto out; | |
764 | ||
e59058c4 | 765 | /* Round to page boundary */ |
a58cbd52 JS |
766 | size = (lpfc_debugfs_max_slow_ring_trc * LPFC_DEBUG_TRC_ENTRY_SIZE); |
767 | size = PAGE_ALIGN(size); | |
768 | ||
769 | debug->buffer = kmalloc(size, GFP_KERNEL); | |
770 | if (!debug->buffer) { | |
771 | kfree(debug); | |
772 | goto out; | |
773 | } | |
774 | ||
775 | debug->len = lpfc_debugfs_slow_ring_trc_data(phba, debug->buffer, size); | |
776 | file->private_data = debug; | |
777 | ||
778 | rc = 0; | |
779 | out: | |
780 | return rc; | |
781 | } | |
782 | ||
e59058c4 JS |
783 | /** |
784 | * lpfc_debugfs_hbqinfo_open - Open the hbqinfo debugfs buffer. | |
785 | * @inode: The inode pointer that contains a vport pointer. | |
786 | * @file: The file pointer to attach the log output. | |
787 | * | |
788 | * Description: | |
789 | * This routine is the entry point for the debugfs open file operation. It gets | |
790 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
791 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
792 | * returns a pointer to that log in the private_data field in @file. | |
793 | * | |
794 | * Returns: | |
795 | * This function returns zero if successful. On error it will return an negative | |
796 | * error value. | |
797 | **/ | |
78b2d852 JS |
798 | static int |
799 | lpfc_debugfs_hbqinfo_open(struct inode *inode, struct file *file) | |
800 | { | |
801 | struct lpfc_hba *phba = inode->i_private; | |
802 | struct lpfc_debug *debug; | |
803 | int rc = -ENOMEM; | |
804 | ||
805 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
806 | if (!debug) | |
807 | goto out; | |
808 | ||
e59058c4 | 809 | /* Round to page boundary */ |
78b2d852 JS |
810 | debug->buffer = kmalloc(LPFC_HBQINFO_SIZE, GFP_KERNEL); |
811 | if (!debug->buffer) { | |
812 | kfree(debug); | |
813 | goto out; | |
814 | } | |
815 | ||
816 | debug->len = lpfc_debugfs_hbqinfo_data(phba, debug->buffer, | |
817 | LPFC_HBQINFO_SIZE); | |
818 | file->private_data = debug; | |
819 | ||
820 | rc = 0; | |
821 | out: | |
822 | return rc; | |
823 | } | |
824 | ||
e59058c4 JS |
825 | /** |
826 | * lpfc_debugfs_dumpHBASlim_open - Open the Dump HBA SLIM debugfs buffer. | |
827 | * @inode: The inode pointer that contains a vport pointer. | |
828 | * @file: The file pointer to attach the log output. | |
829 | * | |
830 | * Description: | |
831 | * This routine is the entry point for the debugfs open file operation. It gets | |
832 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
833 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
834 | * returns a pointer to that log in the private_data field in @file. | |
835 | * | |
836 | * Returns: | |
837 | * This function returns zero if successful. On error it will return an negative | |
838 | * error value. | |
839 | **/ | |
a58cbd52 | 840 | static int |
c95d6c6c | 841 | lpfc_debugfs_dumpHBASlim_open(struct inode *inode, struct file *file) |
a58cbd52 JS |
842 | { |
843 | struct lpfc_hba *phba = inode->i_private; | |
844 | struct lpfc_debug *debug; | |
845 | int rc = -ENOMEM; | |
846 | ||
847 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
848 | if (!debug) | |
849 | goto out; | |
850 | ||
e59058c4 | 851 | /* Round to page boundary */ |
c95d6c6c | 852 | debug->buffer = kmalloc(LPFC_DUMPHBASLIM_SIZE, GFP_KERNEL); |
a58cbd52 JS |
853 | if (!debug->buffer) { |
854 | kfree(debug); | |
855 | goto out; | |
856 | } | |
857 | ||
c95d6c6c JS |
858 | debug->len = lpfc_debugfs_dumpHBASlim_data(phba, debug->buffer, |
859 | LPFC_DUMPHBASLIM_SIZE); | |
860 | file->private_data = debug; | |
861 | ||
862 | rc = 0; | |
863 | out: | |
864 | return rc; | |
865 | } | |
866 | ||
e59058c4 JS |
867 | /** |
868 | * lpfc_debugfs_dumpHostSlim_open - Open the Dump Host SLIM debugfs buffer. | |
869 | * @inode: The inode pointer that contains a vport pointer. | |
870 | * @file: The file pointer to attach the log output. | |
871 | * | |
872 | * Description: | |
873 | * This routine is the entry point for the debugfs open file operation. It gets | |
874 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
875 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
876 | * returns a pointer to that log in the private_data field in @file. | |
877 | * | |
878 | * Returns: | |
879 | * This function returns zero if successful. On error it will return an negative | |
880 | * error value. | |
881 | **/ | |
c95d6c6c JS |
882 | static int |
883 | lpfc_debugfs_dumpHostSlim_open(struct inode *inode, struct file *file) | |
884 | { | |
885 | struct lpfc_hba *phba = inode->i_private; | |
886 | struct lpfc_debug *debug; | |
887 | int rc = -ENOMEM; | |
888 | ||
889 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
890 | if (!debug) | |
891 | goto out; | |
892 | ||
e59058c4 | 893 | /* Round to page boundary */ |
c95d6c6c JS |
894 | debug->buffer = kmalloc(LPFC_DUMPHOSTSLIM_SIZE, GFP_KERNEL); |
895 | if (!debug->buffer) { | |
896 | kfree(debug); | |
897 | goto out; | |
898 | } | |
899 | ||
900 | debug->len = lpfc_debugfs_dumpHostSlim_data(phba, debug->buffer, | |
901 | LPFC_DUMPHOSTSLIM_SIZE); | |
a58cbd52 JS |
902 | file->private_data = debug; |
903 | ||
904 | rc = 0; | |
905 | out: | |
906 | return rc; | |
907 | } | |
908 | ||
e59058c4 JS |
909 | /** |
910 | * lpfc_debugfs_nodelist_open - Open the nodelist debugfs file. | |
911 | * @inode: The inode pointer that contains a vport pointer. | |
912 | * @file: The file pointer to attach the log output. | |
913 | * | |
914 | * Description: | |
915 | * This routine is the entry point for the debugfs open file operation. It gets | |
916 | * the vport from the i_private field in @inode, allocates the necessary buffer | |
917 | * for the log, fills the buffer from the in-memory log for this vport, and then | |
918 | * returns a pointer to that log in the private_data field in @file. | |
919 | * | |
920 | * Returns: | |
921 | * This function returns zero if successful. On error it will return an negative | |
922 | * error value. | |
923 | **/ | |
858c9f6c JS |
924 | static int |
925 | lpfc_debugfs_nodelist_open(struct inode *inode, struct file *file) | |
926 | { | |
927 | struct lpfc_vport *vport = inode->i_private; | |
928 | struct lpfc_debug *debug; | |
929 | int rc = -ENOMEM; | |
930 | ||
931 | debug = kmalloc(sizeof(*debug), GFP_KERNEL); | |
932 | if (!debug) | |
933 | goto out; | |
934 | ||
e59058c4 | 935 | /* Round to page boundary */ |
858c9f6c JS |
936 | debug->buffer = kmalloc(LPFC_NODELIST_SIZE, GFP_KERNEL); |
937 | if (!debug->buffer) { | |
938 | kfree(debug); | |
939 | goto out; | |
940 | } | |
941 | ||
942 | debug->len = lpfc_debugfs_nodelist_data(vport, debug->buffer, | |
943 | LPFC_NODELIST_SIZE); | |
944 | file->private_data = debug; | |
945 | ||
946 | rc = 0; | |
947 | out: | |
948 | return rc; | |
949 | } | |
950 | ||
e59058c4 JS |
951 | /** |
952 | * lpfc_debugfs_lseek - Seek through a debugfs file. | |
953 | * @file: The file pointer to seek through. | |
954 | * @off: The offset to seek to or the amount to seek by. | |
955 | * @whence: Indicates how to seek. | |
956 | * | |
957 | * Description: | |
958 | * This routine is the entry point for the debugfs lseek file operation. The | |
959 | * @whence parameter indicates whether @off is the offset to directly seek to, | |
960 | * or if it is a value to seek forward or reverse by. This function figures out | |
961 | * what the new offset of the debugfs file will be and assigns that value to the | |
962 | * f_pos field of @file. | |
963 | * | |
964 | * Returns: | |
965 | * This function returns the new offset if successful and returns a negative | |
966 | * error if unable to process the seek. | |
967 | **/ | |
858c9f6c JS |
968 | static loff_t |
969 | lpfc_debugfs_lseek(struct file *file, loff_t off, int whence) | |
970 | { | |
971 | struct lpfc_debug *debug; | |
972 | loff_t pos = -1; | |
973 | ||
974 | debug = file->private_data; | |
975 | ||
976 | switch (whence) { | |
977 | case 0: | |
978 | pos = off; | |
979 | break; | |
980 | case 1: | |
981 | pos = file->f_pos + off; | |
982 | break; | |
983 | case 2: | |
984 | pos = debug->len - off; | |
985 | } | |
986 | return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos); | |
987 | } | |
988 | ||
e59058c4 JS |
989 | /** |
990 | * lpfc_debugfs_read - Read a debugfs file. | |
991 | * @file: The file pointer to read from. | |
992 | * @buf: The buffer to copy the data to. | |
993 | * @nbytes: The number of bytes to read. | |
994 | * @ppos: The position in the file to start reading from. | |
995 | * | |
996 | * Description: | |
997 | * This routine reads data from from the buffer indicated in the private_data | |
998 | * field of @file. It will start reading at @ppos and copy up to @nbytes of | |
999 | * data to @buf. | |
1000 | * | |
1001 | * Returns: | |
1002 | * This function returns the amount of data that was read (this could be less | |
1003 | * than @nbytes if the end of the file was reached) or a negative error value. | |
1004 | **/ | |
858c9f6c JS |
1005 | static ssize_t |
1006 | lpfc_debugfs_read(struct file *file, char __user *buf, | |
1007 | size_t nbytes, loff_t *ppos) | |
1008 | { | |
1009 | struct lpfc_debug *debug = file->private_data; | |
1010 | return simple_read_from_buffer(buf, nbytes, ppos, debug->buffer, | |
1011 | debug->len); | |
1012 | } | |
1013 | ||
e59058c4 JS |
1014 | /** |
1015 | * lpfc_debugfs_release - Release the buffer used to store debugfs file data. | |
1016 | * @inode: The inode pointer that contains a vport pointer. (unused) | |
1017 | * @file: The file pointer that contains the buffer to release. | |
1018 | * | |
1019 | * Description: | |
1020 | * This routine frees the buffer that was allocated when the debugfs file was | |
1021 | * opened. | |
1022 | * | |
1023 | * Returns: | |
1024 | * This function returns zero. | |
1025 | **/ | |
858c9f6c JS |
1026 | static int |
1027 | lpfc_debugfs_release(struct inode *inode, struct file *file) | |
1028 | { | |
1029 | struct lpfc_debug *debug = file->private_data; | |
1030 | ||
1031 | kfree(debug->buffer); | |
1032 | kfree(debug); | |
1033 | ||
1034 | return 0; | |
1035 | } | |
1036 | ||
1037 | #undef lpfc_debugfs_op_disc_trc | |
1038 | static struct file_operations lpfc_debugfs_op_disc_trc = { | |
1039 | .owner = THIS_MODULE, | |
1040 | .open = lpfc_debugfs_disc_trc_open, | |
1041 | .llseek = lpfc_debugfs_lseek, | |
1042 | .read = lpfc_debugfs_read, | |
1043 | .release = lpfc_debugfs_release, | |
1044 | }; | |
1045 | ||
1046 | #undef lpfc_debugfs_op_nodelist | |
1047 | static struct file_operations lpfc_debugfs_op_nodelist = { | |
1048 | .owner = THIS_MODULE, | |
1049 | .open = lpfc_debugfs_nodelist_open, | |
1050 | .llseek = lpfc_debugfs_lseek, | |
1051 | .read = lpfc_debugfs_read, | |
1052 | .release = lpfc_debugfs_release, | |
1053 | }; | |
1054 | ||
78b2d852 JS |
1055 | #undef lpfc_debugfs_op_hbqinfo |
1056 | static struct file_operations lpfc_debugfs_op_hbqinfo = { | |
1057 | .owner = THIS_MODULE, | |
1058 | .open = lpfc_debugfs_hbqinfo_open, | |
1059 | .llseek = lpfc_debugfs_lseek, | |
1060 | .read = lpfc_debugfs_read, | |
1061 | .release = lpfc_debugfs_release, | |
1062 | }; | |
1063 | ||
c95d6c6c JS |
1064 | #undef lpfc_debugfs_op_dumpHBASlim |
1065 | static struct file_operations lpfc_debugfs_op_dumpHBASlim = { | |
1066 | .owner = THIS_MODULE, | |
1067 | .open = lpfc_debugfs_dumpHBASlim_open, | |
1068 | .llseek = lpfc_debugfs_lseek, | |
1069 | .read = lpfc_debugfs_read, | |
1070 | .release = lpfc_debugfs_release, | |
1071 | }; | |
1072 | ||
1073 | #undef lpfc_debugfs_op_dumpHostSlim | |
1074 | static struct file_operations lpfc_debugfs_op_dumpHostSlim = { | |
a58cbd52 | 1075 | .owner = THIS_MODULE, |
c95d6c6c | 1076 | .open = lpfc_debugfs_dumpHostSlim_open, |
a58cbd52 JS |
1077 | .llseek = lpfc_debugfs_lseek, |
1078 | .read = lpfc_debugfs_read, | |
1079 | .release = lpfc_debugfs_release, | |
1080 | }; | |
1081 | ||
1082 | #undef lpfc_debugfs_op_slow_ring_trc | |
1083 | static struct file_operations lpfc_debugfs_op_slow_ring_trc = { | |
1084 | .owner = THIS_MODULE, | |
1085 | .open = lpfc_debugfs_slow_ring_trc_open, | |
1086 | .llseek = lpfc_debugfs_lseek, | |
1087 | .read = lpfc_debugfs_read, | |
1088 | .release = lpfc_debugfs_release, | |
1089 | }; | |
1090 | ||
858c9f6c JS |
1091 | static struct dentry *lpfc_debugfs_root = NULL; |
1092 | static atomic_t lpfc_debugfs_hba_count; | |
1093 | #endif | |
1094 | ||
e59058c4 JS |
1095 | /** |
1096 | * lpfc_debugfs_initialize - Initialize debugfs for a vport. | |
1097 | * @vport: The vport pointer to initialize. | |
1098 | * | |
1099 | * Description: | |
1100 | * When Debugfs is configured this routine sets up the lpfc debugfs file system. | |
1101 | * If not already created, this routine will create the lpfc directory, and | |
1102 | * lpfcX directory (for this HBA), and vportX directory for this vport. It will | |
1103 | * also create each file used to access lpfc specific debugfs information. | |
1104 | **/ | |
858c9f6c JS |
1105 | inline void |
1106 | lpfc_debugfs_initialize(struct lpfc_vport *vport) | |
1107 | { | |
1108 | #ifdef CONFIG_LPFC_DEBUG_FS | |
1109 | struct lpfc_hba *phba = vport->phba; | |
1110 | char name[64]; | |
1111 | uint32_t num, i; | |
1112 | ||
1113 | if (!lpfc_debugfs_enable) | |
1114 | return; | |
1115 | ||
a58cbd52 | 1116 | /* Setup lpfc root directory */ |
858c9f6c JS |
1117 | if (!lpfc_debugfs_root) { |
1118 | lpfc_debugfs_root = debugfs_create_dir("lpfc", NULL); | |
1119 | atomic_set(&lpfc_debugfs_hba_count, 0); | |
a58cbd52 | 1120 | if (!lpfc_debugfs_root) { |
e8b62011 | 1121 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1122 | "0408 Cannot create debugfs root\n"); |
858c9f6c | 1123 | goto debug_failed; |
a58cbd52 | 1124 | } |
858c9f6c | 1125 | } |
a58cbd52 JS |
1126 | if (!lpfc_debugfs_start_time) |
1127 | lpfc_debugfs_start_time = jiffies; | |
1128 | ||
1129 | /* Setup lpfcX directory for specific HBA */ | |
858c9f6c JS |
1130 | snprintf(name, sizeof(name), "lpfc%d", phba->brd_no); |
1131 | if (!phba->hba_debugfs_root) { | |
1132 | phba->hba_debugfs_root = | |
1133 | debugfs_create_dir(name, lpfc_debugfs_root); | |
a58cbd52 | 1134 | if (!phba->hba_debugfs_root) { |
e8b62011 | 1135 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1136 | "0412 Cannot create debugfs hba\n"); |
858c9f6c | 1137 | goto debug_failed; |
a58cbd52 | 1138 | } |
858c9f6c JS |
1139 | atomic_inc(&lpfc_debugfs_hba_count); |
1140 | atomic_set(&phba->debugfs_vport_count, 0); | |
a58cbd52 | 1141 | |
78b2d852 JS |
1142 | /* Setup hbqinfo */ |
1143 | snprintf(name, sizeof(name), "hbqinfo"); | |
1144 | phba->debug_hbqinfo = | |
1145 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, | |
1146 | phba->hba_debugfs_root, | |
1147 | phba, &lpfc_debugfs_op_hbqinfo); | |
1148 | if (!phba->debug_hbqinfo) { | |
1149 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1150 | "0411 Cannot create debugfs hbqinfo\n"); |
78b2d852 JS |
1151 | goto debug_failed; |
1152 | } | |
1153 | ||
c95d6c6c JS |
1154 | /* Setup dumpHBASlim */ |
1155 | snprintf(name, sizeof(name), "dumpHBASlim"); | |
1156 | phba->debug_dumpHBASlim = | |
a58cbd52 JS |
1157 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, |
1158 | phba->hba_debugfs_root, | |
c95d6c6c JS |
1159 | phba, &lpfc_debugfs_op_dumpHBASlim); |
1160 | if (!phba->debug_dumpHBASlim) { | |
e8b62011 | 1161 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1162 | "0413 Cannot create debugfs dumpHBASlim\n"); |
c95d6c6c JS |
1163 | goto debug_failed; |
1164 | } | |
1165 | ||
1166 | /* Setup dumpHostSlim */ | |
1167 | snprintf(name, sizeof(name), "dumpHostSlim"); | |
1168 | phba->debug_dumpHostSlim = | |
1169 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, | |
1170 | phba->hba_debugfs_root, | |
1171 | phba, &lpfc_debugfs_op_dumpHostSlim); | |
1172 | if (!phba->debug_dumpHostSlim) { | |
1173 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1174 | "0414 Cannot create debugfs dumpHostSlim\n"); |
a58cbd52 JS |
1175 | goto debug_failed; |
1176 | } | |
1177 | ||
1178 | /* Setup slow ring trace */ | |
1179 | if (lpfc_debugfs_max_slow_ring_trc) { | |
1180 | num = lpfc_debugfs_max_slow_ring_trc - 1; | |
1181 | if (num & lpfc_debugfs_max_slow_ring_trc) { | |
1182 | /* Change to be a power of 2 */ | |
1183 | num = lpfc_debugfs_max_slow_ring_trc; | |
1184 | i = 0; | |
1185 | while (num > 1) { | |
1186 | num = num >> 1; | |
1187 | i++; | |
1188 | } | |
1189 | lpfc_debugfs_max_slow_ring_trc = (1 << i); | |
1190 | printk(KERN_ERR | |
e8b62011 JS |
1191 | "lpfc_debugfs_max_disc_trc changed to " |
1192 | "%d\n", lpfc_debugfs_max_disc_trc); | |
a58cbd52 JS |
1193 | } |
1194 | } | |
1195 | ||
1196 | ||
1197 | snprintf(name, sizeof(name), "slow_ring_trace"); | |
1198 | phba->debug_slow_ring_trc = | |
1199 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, | |
1200 | phba->hba_debugfs_root, | |
1201 | phba, &lpfc_debugfs_op_slow_ring_trc); | |
1202 | if (!phba->debug_slow_ring_trc) { | |
e8b62011 | 1203 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1204 | "0415 Cannot create debugfs " |
e8b62011 | 1205 | "slow_ring_trace\n"); |
a58cbd52 JS |
1206 | goto debug_failed; |
1207 | } | |
1208 | if (!phba->slow_ring_trc) { | |
1209 | phba->slow_ring_trc = kmalloc( | |
1210 | (sizeof(struct lpfc_debugfs_trc) * | |
1211 | lpfc_debugfs_max_slow_ring_trc), | |
1212 | GFP_KERNEL); | |
1213 | if (!phba->slow_ring_trc) { | |
e8b62011 | 1214 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1215 | "0416 Cannot create debugfs " |
e8b62011 | 1216 | "slow_ring buffer\n"); |
a58cbd52 JS |
1217 | goto debug_failed; |
1218 | } | |
1219 | atomic_set(&phba->slow_ring_trc_cnt, 0); | |
1220 | memset(phba->slow_ring_trc, 0, | |
1221 | (sizeof(struct lpfc_debugfs_trc) * | |
1222 | lpfc_debugfs_max_slow_ring_trc)); | |
1223 | } | |
858c9f6c JS |
1224 | } |
1225 | ||
1226 | snprintf(name, sizeof(name), "vport%d", vport->vpi); | |
1227 | if (!vport->vport_debugfs_root) { | |
1228 | vport->vport_debugfs_root = | |
1229 | debugfs_create_dir(name, phba->hba_debugfs_root); | |
a58cbd52 | 1230 | if (!vport->vport_debugfs_root) { |
e8b62011 | 1231 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1232 | "0417 Cant create debugfs"); |
858c9f6c | 1233 | goto debug_failed; |
a58cbd52 | 1234 | } |
858c9f6c JS |
1235 | atomic_inc(&phba->debugfs_vport_count); |
1236 | } | |
1237 | ||
a58cbd52 JS |
1238 | if (lpfc_debugfs_max_disc_trc) { |
1239 | num = lpfc_debugfs_max_disc_trc - 1; | |
1240 | if (num & lpfc_debugfs_max_disc_trc) { | |
1241 | /* Change to be a power of 2 */ | |
1242 | num = lpfc_debugfs_max_disc_trc; | |
1243 | i = 0; | |
1244 | while (num > 1) { | |
1245 | num = num >> 1; | |
1246 | i++; | |
1247 | } | |
1248 | lpfc_debugfs_max_disc_trc = (1 << i); | |
1249 | printk(KERN_ERR | |
e8b62011 JS |
1250 | "lpfc_debugfs_max_disc_trc changed to %d\n", |
1251 | lpfc_debugfs_max_disc_trc); | |
a58cbd52 JS |
1252 | } |
1253 | } | |
858c9f6c | 1254 | |
ff86ba59 | 1255 | vport->disc_trc = kzalloc( |
a58cbd52 | 1256 | (sizeof(struct lpfc_debugfs_trc) * lpfc_debugfs_max_disc_trc), |
858c9f6c JS |
1257 | GFP_KERNEL); |
1258 | ||
a58cbd52 | 1259 | if (!vport->disc_trc) { |
e8b62011 | 1260 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1261 | "0418 Cannot create debugfs disc trace " |
e8b62011 | 1262 | "buffer\n"); |
858c9f6c | 1263 | goto debug_failed; |
a58cbd52 JS |
1264 | } |
1265 | atomic_set(&vport->disc_trc_cnt, 0); | |
858c9f6c JS |
1266 | |
1267 | snprintf(name, sizeof(name), "discovery_trace"); | |
1268 | vport->debug_disc_trc = | |
1269 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, | |
1270 | vport->vport_debugfs_root, | |
1271 | vport, &lpfc_debugfs_op_disc_trc); | |
1272 | if (!vport->debug_disc_trc) { | |
e8b62011 | 1273 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1274 | "0419 Cannot create debugfs " |
e8b62011 | 1275 | "discovery_trace\n"); |
858c9f6c JS |
1276 | goto debug_failed; |
1277 | } | |
1278 | snprintf(name, sizeof(name), "nodelist"); | |
1279 | vport->debug_nodelist = | |
1280 | debugfs_create_file(name, S_IFREG|S_IRUGO|S_IWUSR, | |
1281 | vport->vport_debugfs_root, | |
1282 | vport, &lpfc_debugfs_op_nodelist); | |
1283 | if (!vport->debug_nodelist) { | |
e8b62011 JS |
1284 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1285 | "0409 Cant create debugfs nodelist"); | |
858c9f6c JS |
1286 | goto debug_failed; |
1287 | } | |
1288 | debug_failed: | |
1289 | return; | |
1290 | #endif | |
1291 | } | |
1292 | ||
e59058c4 JS |
1293 | /** |
1294 | * lpfc_debugfs_terminate - Tear down debugfs infrastructure for this vport. | |
1295 | * @vport: The vport pointer to remove from debugfs. | |
1296 | * | |
1297 | * Description: | |
1298 | * When Debugfs is configured this routine removes debugfs file system elements | |
1299 | * that are specific to this vport. It also checks to see if there are any | |
1300 | * users left for the debugfs directories associated with the HBA and driver. If | |
1301 | * this is the last user of the HBA directory or driver directory then it will | |
1302 | * remove those from the debugfs infrastructure as well. | |
1303 | **/ | |
858c9f6c JS |
1304 | inline void |
1305 | lpfc_debugfs_terminate(struct lpfc_vport *vport) | |
1306 | { | |
1307 | #ifdef CONFIG_LPFC_DEBUG_FS | |
1308 | struct lpfc_hba *phba = vport->phba; | |
1309 | ||
1310 | if (vport->disc_trc) { | |
1311 | kfree(vport->disc_trc); | |
1312 | vport->disc_trc = NULL; | |
1313 | } | |
1314 | if (vport->debug_disc_trc) { | |
1315 | debugfs_remove(vport->debug_disc_trc); /* discovery_trace */ | |
1316 | vport->debug_disc_trc = NULL; | |
1317 | } | |
1318 | if (vport->debug_nodelist) { | |
1319 | debugfs_remove(vport->debug_nodelist); /* nodelist */ | |
1320 | vport->debug_nodelist = NULL; | |
1321 | } | |
a58cbd52 | 1322 | |
858c9f6c JS |
1323 | if (vport->vport_debugfs_root) { |
1324 | debugfs_remove(vport->vport_debugfs_root); /* vportX */ | |
1325 | vport->vport_debugfs_root = NULL; | |
1326 | atomic_dec(&phba->debugfs_vport_count); | |
1327 | } | |
1328 | if (atomic_read(&phba->debugfs_vport_count) == 0) { | |
a58cbd52 | 1329 | |
78b2d852 JS |
1330 | if (phba->debug_hbqinfo) { |
1331 | debugfs_remove(phba->debug_hbqinfo); /* hbqinfo */ | |
1332 | phba->debug_hbqinfo = NULL; | |
1333 | } | |
c95d6c6c JS |
1334 | if (phba->debug_dumpHBASlim) { |
1335 | debugfs_remove(phba->debug_dumpHBASlim); /* HBASlim */ | |
1336 | phba->debug_dumpHBASlim = NULL; | |
1337 | } | |
1338 | if (phba->debug_dumpHostSlim) { | |
1339 | debugfs_remove(phba->debug_dumpHostSlim); /* HostSlim */ | |
1340 | phba->debug_dumpHostSlim = NULL; | |
a58cbd52 JS |
1341 | } |
1342 | if (phba->slow_ring_trc) { | |
1343 | kfree(phba->slow_ring_trc); | |
1344 | phba->slow_ring_trc = NULL; | |
1345 | } | |
1346 | if (phba->debug_slow_ring_trc) { | |
1347 | /* slow_ring_trace */ | |
1348 | debugfs_remove(phba->debug_slow_ring_trc); | |
1349 | phba->debug_slow_ring_trc = NULL; | |
1350 | } | |
1351 | ||
1352 | if (phba->hba_debugfs_root) { | |
1353 | debugfs_remove(phba->hba_debugfs_root); /* lpfcX */ | |
1354 | phba->hba_debugfs_root = NULL; | |
1355 | atomic_dec(&lpfc_debugfs_hba_count); | |
1356 | } | |
1357 | ||
858c9f6c JS |
1358 | if (atomic_read(&lpfc_debugfs_hba_count) == 0) { |
1359 | debugfs_remove(lpfc_debugfs_root); /* lpfc */ | |
1360 | lpfc_debugfs_root = NULL; | |
1361 | } | |
1362 | } | |
1363 | #endif | |
a58cbd52 | 1364 | return; |
858c9f6c | 1365 | } |