[SCSI] lpfc 8.1.2: Add ERROR and WARM_START modes for diagnostic purposes.
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_attr.c
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
8 * *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21
22 #include <linux/ctype.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
25
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_tcq.h>
30 #include <scsi/scsi_transport_fc.h>
31
32 #include "lpfc_hw.h"
33 #include "lpfc_sli.h"
34 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
36 #include "lpfc.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_version.h"
39 #include "lpfc_compat.h"
40 #include "lpfc_crtn.h"
41
42
43 static void
44 lpfc_jedec_to_ascii(int incr, char hdw[])
45 {
46 int i, j;
47 for (i = 0; i < 8; i++) {
48 j = (incr & 0xf);
49 if (j <= 9)
50 hdw[7 - i] = 0x30 + j;
51 else
52 hdw[7 - i] = 0x61 + j - 10;
53 incr = (incr >> 4);
54 }
55 hdw[8] = 0;
56 return;
57 }
58
59 static ssize_t
60 lpfc_drvr_version_show(struct class_device *cdev, char *buf)
61 {
62 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
63 }
64
65 static ssize_t
66 management_version_show(struct class_device *cdev, char *buf)
67 {
68 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
69 }
70
71 static ssize_t
72 lpfc_info_show(struct class_device *cdev, char *buf)
73 {
74 struct Scsi_Host *host = class_to_shost(cdev);
75 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
76 }
77
78 static ssize_t
79 lpfc_serialnum_show(struct class_device *cdev, char *buf)
80 {
81 struct Scsi_Host *host = class_to_shost(cdev);
82 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
83 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
84 }
85
86 static ssize_t
87 lpfc_modeldesc_show(struct class_device *cdev, char *buf)
88 {
89 struct Scsi_Host *host = class_to_shost(cdev);
90 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
91 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
92 }
93
94 static ssize_t
95 lpfc_modelname_show(struct class_device *cdev, char *buf)
96 {
97 struct Scsi_Host *host = class_to_shost(cdev);
98 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
99 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
100 }
101
102 static ssize_t
103 lpfc_programtype_show(struct class_device *cdev, char *buf)
104 {
105 struct Scsi_Host *host = class_to_shost(cdev);
106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
107 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
108 }
109
110 static ssize_t
111 lpfc_portnum_show(struct class_device *cdev, char *buf)
112 {
113 struct Scsi_Host *host = class_to_shost(cdev);
114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
115 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
116 }
117
118 static ssize_t
119 lpfc_fwrev_show(struct class_device *cdev, char *buf)
120 {
121 struct Scsi_Host *host = class_to_shost(cdev);
122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
123 char fwrev[32];
124 lpfc_decode_firmware_rev(phba, fwrev, 1);
125 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
126 }
127
128 static ssize_t
129 lpfc_hdw_show(struct class_device *cdev, char *buf)
130 {
131 char hdw[9];
132 struct Scsi_Host *host = class_to_shost(cdev);
133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
134 lpfc_vpd_t *vp = &phba->vpd;
135 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
136 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
137 }
138 static ssize_t
139 lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
140 {
141 struct Scsi_Host *host = class_to_shost(cdev);
142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
143 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
144 }
145 static ssize_t
146 lpfc_state_show(struct class_device *cdev, char *buf)
147 {
148 struct Scsi_Host *host = class_to_shost(cdev);
149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
150 int len = 0;
151 switch (phba->hba_state) {
152 case LPFC_STATE_UNKNOWN:
153 case LPFC_WARM_START:
154 case LPFC_INIT_START:
155 case LPFC_INIT_MBX_CMDS:
156 case LPFC_LINK_DOWN:
157 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
158 break;
159 case LPFC_LINK_UP:
160 case LPFC_LOCAL_CFG_LINK:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
162 break;
163 case LPFC_FLOGI:
164 case LPFC_FABRIC_CFG_LINK:
165 case LPFC_NS_REG:
166 case LPFC_NS_QRY:
167 case LPFC_BUILD_DISC_LIST:
168 case LPFC_DISC_AUTH:
169 case LPFC_CLEAR_LA:
170 len += snprintf(buf + len, PAGE_SIZE-len,
171 "Link Up - Discovery\n");
172 break;
173 case LPFC_HBA_READY:
174 len += snprintf(buf + len, PAGE_SIZE-len,
175 "Link Up - Ready:\n");
176 if (phba->fc_topology == TOPOLOGY_LOOP) {
177 if (phba->fc_flag & FC_PUBLIC_LOOP)
178 len += snprintf(buf + len, PAGE_SIZE-len,
179 " Public Loop\n");
180 else
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Private Loop\n");
183 } else {
184 if (phba->fc_flag & FC_FABRIC)
185 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Fabric\n");
187 else
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Point-2-Point\n");
190 }
191 }
192 return len;
193 }
194
195 static ssize_t
196 lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
197 {
198 struct Scsi_Host *host = class_to_shost(cdev);
199 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
200 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
201 phba->fc_unmap_cnt);
202 }
203
204
205 static int
206 lpfc_issue_lip(struct Scsi_Host *host)
207 {
208 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
209 LPFC_MBOXQ_t *pmboxq;
210 int mbxstatus = MBXERR_ERROR;
211
212 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
213 (phba->hba_state != LPFC_HBA_READY))
214 return -EPERM;
215
216 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
217
218 if (!pmboxq)
219 return -ENOMEM;
220
221 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
222 lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed);
223 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
224
225 if (mbxstatus == MBX_TIMEOUT)
226 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
227 else
228 mempool_free(pmboxq, phba->mbox_mem_pool);
229
230 if (mbxstatus == MBXERR_ERROR)
231 return -EIO;
232
233 return 0;
234 }
235
236 static ssize_t
237 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
238 {
239 struct Scsi_Host *host = class_to_shost(cdev);
240 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
241 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
242 }
243
244 static ssize_t
245 lpfc_board_online_show(struct class_device *cdev, char *buf)
246 {
247 struct Scsi_Host *host = class_to_shost(cdev);
248 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
249
250 if (phba->fc_flag & FC_OFFLINE_MODE)
251 return snprintf(buf, PAGE_SIZE, "0\n");
252 else
253 return snprintf(buf, PAGE_SIZE, "1\n");
254 }
255
256 static ssize_t
257 lpfc_board_online_store(struct class_device *cdev, const char *buf,
258 size_t count)
259 {
260 struct Scsi_Host *host = class_to_shost(cdev);
261 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
262 struct completion online_compl;
263 int val=0, status=0;
264
265 if (sscanf(buf, "%d", &val) != 1)
266 return -EINVAL;
267
268 init_completion(&online_compl);
269
270 if (val)
271 lpfc_workq_post_event(phba, &status, &online_compl,
272 LPFC_EVT_ONLINE);
273 else
274 lpfc_workq_post_event(phba, &status, &online_compl,
275 LPFC_EVT_OFFLINE);
276 wait_for_completion(&online_compl);
277 if (!status)
278 return strlen(buf);
279 else
280 return -EIO;
281 }
282
283 static ssize_t
284 lpfc_board_mode_show(struct class_device *cdev, char *buf)
285 {
286 struct Scsi_Host *host = class_to_shost(cdev);
287 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
288 char * state;
289
290 if (phba->hba_state == LPFC_HBA_ERROR)
291 state = "error";
292 else if (phba->hba_state == LPFC_WARM_START)
293 state = "warm start";
294 else if (phba->hba_state == LPFC_INIT_START)
295 state = "offline";
296 else
297 state = "online";
298
299 return snprintf(buf, PAGE_SIZE, "%s\n", state);
300 }
301
302 static ssize_t
303 lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
304 {
305 struct Scsi_Host *host = class_to_shost(cdev);
306 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
307 struct completion online_compl;
308 int status=0;
309
310 init_completion(&online_compl);
311
312 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
313 lpfc_workq_post_event(phba, &status, &online_compl,
314 LPFC_EVT_ONLINE);
315 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
316 lpfc_workq_post_event(phba, &status, &online_compl,
317 LPFC_EVT_OFFLINE);
318 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
319 lpfc_workq_post_event(phba, &status, &online_compl,
320 LPFC_EVT_WARM_START);
321 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
322 lpfc_workq_post_event(phba, &status, &online_compl,
323 LPFC_EVT_KILL);
324 else
325 return -EINVAL;
326
327 wait_for_completion(&online_compl);
328
329 if (!status)
330 return strlen(buf);
331 else
332 return -EIO;
333 }
334
335 static ssize_t
336 lpfc_poll_show(struct class_device *cdev, char *buf)
337 {
338 struct Scsi_Host *host = class_to_shost(cdev);
339 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
340
341 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
342 }
343
344 static ssize_t
345 lpfc_poll_store(struct class_device *cdev, const char *buf,
346 size_t count)
347 {
348 struct Scsi_Host *host = class_to_shost(cdev);
349 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
350 uint32_t creg_val;
351 uint32_t old_val;
352 int val=0;
353
354 if (!isdigit(buf[0]))
355 return -EINVAL;
356
357 if (sscanf(buf, "%i", &val) != 1)
358 return -EINVAL;
359
360 if ((val & 0x3) != val)
361 return -EINVAL;
362
363 spin_lock_irq(phba->host->host_lock);
364
365 old_val = phba->cfg_poll;
366
367 if (val & ENABLE_FCP_RING_POLLING) {
368 if ((val & DISABLE_FCP_RING_INT) &&
369 !(old_val & DISABLE_FCP_RING_INT)) {
370 creg_val = readl(phba->HCregaddr);
371 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
372 writel(creg_val, phba->HCregaddr);
373 readl(phba->HCregaddr); /* flush */
374
375 lpfc_poll_start_timer(phba);
376 }
377 } else if (val != 0x0) {
378 spin_unlock_irq(phba->host->host_lock);
379 return -EINVAL;
380 }
381
382 if (!(val & DISABLE_FCP_RING_INT) &&
383 (old_val & DISABLE_FCP_RING_INT))
384 {
385 spin_unlock_irq(phba->host->host_lock);
386 del_timer(&phba->fcp_poll_timer);
387 spin_lock_irq(phba->host->host_lock);
388 creg_val = readl(phba->HCregaddr);
389 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
390 writel(creg_val, phba->HCregaddr);
391 readl(phba->HCregaddr); /* flush */
392 }
393
394 phba->cfg_poll = val;
395
396 spin_unlock_irq(phba->host->host_lock);
397
398 return strlen(buf);
399 }
400
401 #define lpfc_param_show(attr) \
402 static ssize_t \
403 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
404 { \
405 struct Scsi_Host *host = class_to_shost(cdev);\
406 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
407 int val = 0;\
408 val = phba->cfg_##attr;\
409 return snprintf(buf, PAGE_SIZE, "%d\n",\
410 phba->cfg_##attr);\
411 }
412
413 #define lpfc_param_hex_show(attr) \
414 static ssize_t \
415 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
416 { \
417 struct Scsi_Host *host = class_to_shost(cdev);\
418 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
419 int val = 0;\
420 val = phba->cfg_##attr;\
421 return snprintf(buf, PAGE_SIZE, "%#x\n",\
422 phba->cfg_##attr);\
423 }
424
425 #define lpfc_param_init(attr, default, minval, maxval) \
426 static int \
427 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
428 { \
429 if (val >= minval && val <= maxval) {\
430 phba->cfg_##attr = val;\
431 return 0;\
432 }\
433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
434 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
435 "allowed range is ["#minval", "#maxval"]\n", \
436 phba->brd_no, val); \
437 phba->cfg_##attr = default;\
438 return -EINVAL;\
439 }
440
441 #define lpfc_param_set(attr, default, minval, maxval) \
442 static int \
443 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
444 { \
445 if (val >= minval && val <= maxval) {\
446 phba->cfg_##attr = val;\
447 return 0;\
448 }\
449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
450 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
451 "allowed range is ["#minval", "#maxval"]\n", \
452 phba->brd_no, val); \
453 return -EINVAL;\
454 }
455
456 #define lpfc_param_store(attr) \
457 static ssize_t \
458 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
459 { \
460 struct Scsi_Host *host = class_to_shost(cdev);\
461 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
462 int val=0;\
463 if (!isdigit(buf[0]))\
464 return -EINVAL;\
465 if (sscanf(buf, "%i", &val) != 1)\
466 return -EINVAL;\
467 if (lpfc_##attr##_set(phba, val) == 0) \
468 return strlen(buf);\
469 else \
470 return -EINVAL;\
471 }
472
473 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
474 static int lpfc_##name = defval;\
475 module_param(lpfc_##name, int, 0);\
476 MODULE_PARM_DESC(lpfc_##name, desc);\
477 lpfc_param_init(name, defval, minval, maxval)
478
479 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
480 static int lpfc_##name = defval;\
481 module_param(lpfc_##name, int, 0);\
482 MODULE_PARM_DESC(lpfc_##name, desc);\
483 lpfc_param_show(name)\
484 lpfc_param_init(name, defval, minval, maxval)\
485 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
486
487 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
488 static int lpfc_##name = defval;\
489 module_param(lpfc_##name, int, 0);\
490 MODULE_PARM_DESC(lpfc_##name, desc);\
491 lpfc_param_show(name)\
492 lpfc_param_init(name, defval, minval, maxval)\
493 lpfc_param_set(name, defval, minval, maxval)\
494 lpfc_param_store(name)\
495 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
496 lpfc_##name##_show, lpfc_##name##_store)
497
498 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
499 static int lpfc_##name = defval;\
500 module_param(lpfc_##name, int, 0);\
501 MODULE_PARM_DESC(lpfc_##name, desc);\
502 lpfc_param_hex_show(name)\
503 lpfc_param_init(name, defval, minval, maxval)\
504 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
505
506 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
507 static int lpfc_##name = defval;\
508 module_param(lpfc_##name, int, 0);\
509 MODULE_PARM_DESC(lpfc_##name, desc);\
510 lpfc_param_hex_show(name)\
511 lpfc_param_init(name, defval, minval, maxval)\
512 lpfc_param_set(name, defval, minval, maxval)\
513 lpfc_param_store(name)\
514 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
515 lpfc_##name##_show, lpfc_##name##_store)
516
517 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
518 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
519 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
520 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
521 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
522 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
523 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
524 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
525 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
526 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
527 lpfc_option_rom_version_show, NULL);
528 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
529 lpfc_num_discovered_ports_show, NULL);
530 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
531 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
532 NULL);
533 static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
534 NULL);
535 static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
536 lpfc_board_online_show, lpfc_board_online_store);
537 static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
538 lpfc_board_mode_show, lpfc_board_mode_store);
539
540 static int lpfc_poll = 0;
541 module_param(lpfc_poll, int, 0);
542 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
543 " 0 - none,"
544 " 1 - poll with interrupts enabled"
545 " 3 - poll and disable FCP ring interrupts");
546
547 static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
548 lpfc_poll_show, lpfc_poll_store);
549
550 /*
551 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
552 # deluged with LOTS of information.
553 # You can set a bit mask to record specific types of verbose messages:
554 #
555 # LOG_ELS 0x1 ELS events
556 # LOG_DISCOVERY 0x2 Link discovery events
557 # LOG_MBOX 0x4 Mailbox events
558 # LOG_INIT 0x8 Initialization events
559 # LOG_LINK_EVENT 0x10 Link events
560 # LOG_IP 0x20 IP traffic history
561 # LOG_FCP 0x40 FCP traffic history
562 # LOG_NODE 0x80 Node table events
563 # LOG_MISC 0x400 Miscellaneous events
564 # LOG_SLI 0x800 SLI events
565 # LOG_CHK_COND 0x1000 FCP Check condition flag
566 # LOG_LIBDFC 0x2000 LIBDFC events
567 # LOG_ALL_MSG 0xffff LOG all messages
568 */
569 LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
570
571 /*
572 # lun_queue_depth: This parameter is used to limit the number of outstanding
573 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
574 */
575 LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
576 "Max number of FCP commands we can queue to a specific LUN");
577
578 /*
579 # hba_queue_depth: This parameter is used to limit the number of outstanding
580 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
581 # value is greater than the maximum number of exchanges supported by the HBA,
582 # then maximum number of exchanges supported by the HBA is used to determine
583 # the hba_queue_depth.
584 */
585 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
586 "Max number of FCP commands we can queue to a lpfc HBA");
587
588 /*
589 # Some disk devices have a "select ID" or "select Target" capability.
590 # From a protocol standpoint "select ID" usually means select the
591 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
592 # annex" which contains a table that maps a "select ID" (a number
593 # between 0 and 7F) to an ALPA. By default, for compatibility with
594 # older drivers, the lpfc driver scans this table from low ALPA to high
595 # ALPA.
596 #
597 # Turning on the scan-down variable (on = 1, off = 0) will
598 # cause the lpfc driver to use an inverted table, effectively
599 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
600 #
601 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
602 # and will not work across a fabric. Also this parameter will take
603 # effect only in the case when ALPA map is not available.)
604 */
605 LPFC_ATTR_R(scan_down, 1, 0, 1,
606 "Start scanning for devices from highest ALPA to lowest");
607
608 /*
609 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
610 # until the timer expires. Value range is [0,255]. Default value is 30.
611 # NOTE: this MUST be less then the SCSI Layer command timeout - 1.
612 */
613 LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
614 "Seconds driver will hold I/O waiting for a device to come back");
615
616 /*
617 # lpfc_topology: link topology for init link
618 # 0x0 = attempt loop mode then point-to-point
619 # 0x02 = attempt point-to-point mode only
620 # 0x04 = attempt loop mode only
621 # 0x06 = attempt point-to-point mode then loop
622 # Set point-to-point mode if you want to run as an N_Port.
623 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
624 # Default value is 0.
625 */
626 LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
627
628 /*
629 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
630 # connection.
631 # 0 = auto select (default)
632 # 1 = 1 Gigabaud
633 # 2 = 2 Gigabaud
634 # 4 = 4 Gigabaud
635 # Value range is [0,4]. Default value is 0.
636 */
637 LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
638
639 /*
640 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
641 # Value range is [2,3]. Default value is 3.
642 */
643 LPFC_ATTR_R(fcp_class, 3, 2, 3,
644 "Select Fibre Channel class of service for FCP sequences");
645
646 /*
647 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
648 # is [0,1]. Default value is 0.
649 */
650 LPFC_ATTR_RW(use_adisc, 0, 0, 1,
651 "Use ADISC on rediscovery to authenticate FCP devices");
652
653 /*
654 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
655 # range is [0,1]. Default value is 0.
656 */
657 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
658
659 /*
660 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
661 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
662 # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
663 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
664 # cr_delay is set to 0.
665 */
666 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an"
667 "interrupt response is generated");
668
669 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an"
670 "interrupt response is generated");
671
672 /*
673 # lpfc_fdmi_on: controls FDMI support.
674 # 0 = no FDMI support
675 # 1 = support FDMI without attribute of hostname
676 # 2 = support FDMI with attribute of hostname
677 # Value range [0,2]. Default value is 0.
678 */
679 LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
680
681 /*
682 # Specifies the maximum number of ELS cmds we can have outstanding (for
683 # discovery). Value range is [1,64]. Default value = 32.
684 */
685 LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands"
686 "during discovery");
687
688 /*
689 # lpfc_max_luns: maximum number of LUNs per target driver will support
690 # Value range is [1,32768]. Default value is 256.
691 # NOTE: The SCSI layer will scan each target for this many luns
692 */
693 LPFC_ATTR_R(max_luns, 256, 1, 32768,
694 "Maximum number of LUNs per target driver will support");
695
696 /*
697 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
698 # Value range is [1,255], default value is 10.
699 */
700 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
701 "Milliseconds driver will wait between polling FCP ring");
702
703 struct class_device_attribute *lpfc_host_attrs[] = {
704 &class_device_attr_info,
705 &class_device_attr_serialnum,
706 &class_device_attr_modeldesc,
707 &class_device_attr_modelname,
708 &class_device_attr_programtype,
709 &class_device_attr_portnum,
710 &class_device_attr_fwrev,
711 &class_device_attr_hdw,
712 &class_device_attr_option_rom_version,
713 &class_device_attr_state,
714 &class_device_attr_num_discovered_ports,
715 &class_device_attr_lpfc_drvr_version,
716 &class_device_attr_lpfc_log_verbose,
717 &class_device_attr_lpfc_lun_queue_depth,
718 &class_device_attr_lpfc_hba_queue_depth,
719 &class_device_attr_lpfc_nodev_tmo,
720 &class_device_attr_lpfc_fcp_class,
721 &class_device_attr_lpfc_use_adisc,
722 &class_device_attr_lpfc_ack0,
723 &class_device_attr_lpfc_topology,
724 &class_device_attr_lpfc_scan_down,
725 &class_device_attr_lpfc_link_speed,
726 &class_device_attr_lpfc_cr_delay,
727 &class_device_attr_lpfc_cr_count,
728 &class_device_attr_lpfc_fdmi_on,
729 &class_device_attr_lpfc_max_luns,
730 &class_device_attr_nport_evt_cnt,
731 &class_device_attr_management_version,
732 &class_device_attr_board_online,
733 &class_device_attr_board_mode,
734 &class_device_attr_lpfc_poll,
735 &class_device_attr_lpfc_poll_tmo,
736 NULL,
737 };
738
739 static ssize_t
740 sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
741 {
742 size_t buf_off;
743 struct Scsi_Host *host = class_to_shost(container_of(kobj,
744 struct class_device, kobj));
745 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
746
747 if ((off + count) > FF_REG_AREA_SIZE)
748 return -ERANGE;
749
750 if (count == 0) return 0;
751
752 if (off % 4 || count % 4 || (unsigned long)buf % 4)
753 return -EINVAL;
754
755 spin_lock_irq(phba->host->host_lock);
756
757 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
758 spin_unlock_irq(phba->host->host_lock);
759 return -EPERM;
760 }
761
762 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
763 writel(*((uint32_t *)(buf + buf_off)),
764 phba->ctrl_regs_memmap_p + off + buf_off);
765
766 spin_unlock_irq(phba->host->host_lock);
767
768 return count;
769 }
770
771 static ssize_t
772 sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
773 {
774 size_t buf_off;
775 uint32_t * tmp_ptr;
776 struct Scsi_Host *host = class_to_shost(container_of(kobj,
777 struct class_device, kobj));
778 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
779
780 if (off > FF_REG_AREA_SIZE)
781 return -ERANGE;
782
783 if ((off + count) > FF_REG_AREA_SIZE)
784 count = FF_REG_AREA_SIZE - off;
785
786 if (count == 0) return 0;
787
788 if (off % 4 || count % 4 || (unsigned long)buf % 4)
789 return -EINVAL;
790
791 spin_lock_irq(phba->host->host_lock);
792
793 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
794 tmp_ptr = (uint32_t *)(buf + buf_off);
795 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
796 }
797
798 spin_unlock_irq(phba->host->host_lock);
799
800 return count;
801 }
802
803 static struct bin_attribute sysfs_ctlreg_attr = {
804 .attr = {
805 .name = "ctlreg",
806 .mode = S_IRUSR | S_IWUSR,
807 .owner = THIS_MODULE,
808 },
809 .size = 256,
810 .read = sysfs_ctlreg_read,
811 .write = sysfs_ctlreg_write,
812 };
813
814
815 static void
816 sysfs_mbox_idle (struct lpfc_hba * phba)
817 {
818 phba->sysfs_mbox.state = SMBOX_IDLE;
819 phba->sysfs_mbox.offset = 0;
820
821 if (phba->sysfs_mbox.mbox) {
822 mempool_free(phba->sysfs_mbox.mbox,
823 phba->mbox_mem_pool);
824 phba->sysfs_mbox.mbox = NULL;
825 }
826 }
827
828 static ssize_t
829 sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
830 {
831 struct Scsi_Host * host =
832 class_to_shost(container_of(kobj, struct class_device, kobj));
833 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
834 struct lpfcMboxq * mbox = NULL;
835
836 if ((count + off) > MAILBOX_CMD_SIZE)
837 return -ERANGE;
838
839 if (off % 4 || count % 4 || (unsigned long)buf % 4)
840 return -EINVAL;
841
842 if (count == 0)
843 return 0;
844
845 if (off == 0) {
846 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
847 if (!mbox)
848 return -ENOMEM;
849
850 }
851
852 spin_lock_irq(host->host_lock);
853
854 if (off == 0) {
855 if (phba->sysfs_mbox.mbox)
856 mempool_free(mbox, phba->mbox_mem_pool);
857 else
858 phba->sysfs_mbox.mbox = mbox;
859 phba->sysfs_mbox.state = SMBOX_WRITING;
860 } else {
861 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
862 phba->sysfs_mbox.offset != off ||
863 phba->sysfs_mbox.mbox == NULL ) {
864 sysfs_mbox_idle(phba);
865 spin_unlock_irq(host->host_lock);
866 return -EINVAL;
867 }
868 }
869
870 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
871 buf, count);
872
873 phba->sysfs_mbox.offset = off + count;
874
875 spin_unlock_irq(host->host_lock);
876
877 return count;
878 }
879
880 static ssize_t
881 sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
882 {
883 struct Scsi_Host *host =
884 class_to_shost(container_of(kobj, struct class_device,
885 kobj));
886 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
887 int rc;
888
889 if (off > sizeof(MAILBOX_t))
890 return -ERANGE;
891
892 if ((count + off) > sizeof(MAILBOX_t))
893 count = sizeof(MAILBOX_t) - off;
894
895 if (off % 4 || count % 4 || (unsigned long)buf % 4)
896 return -EINVAL;
897
898 if (off && count == 0)
899 return 0;
900
901 spin_lock_irq(phba->host->host_lock);
902
903 if (off == 0 &&
904 phba->sysfs_mbox.state == SMBOX_WRITING &&
905 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
906
907 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
908 /* Offline only */
909 case MBX_WRITE_NV:
910 case MBX_INIT_LINK:
911 case MBX_DOWN_LINK:
912 case MBX_CONFIG_LINK:
913 case MBX_CONFIG_RING:
914 case MBX_RESET_RING:
915 case MBX_UNREG_LOGIN:
916 case MBX_CLEAR_LA:
917 case MBX_DUMP_CONTEXT:
918 case MBX_RUN_DIAGS:
919 case MBX_RESTART:
920 case MBX_FLASH_WR_ULA:
921 case MBX_SET_MASK:
922 case MBX_SET_SLIM:
923 case MBX_SET_DEBUG:
924 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
925 printk(KERN_WARNING "mbox_read:Command 0x%x "
926 "is illegal in on-line state\n",
927 phba->sysfs_mbox.mbox->mb.mbxCommand);
928 sysfs_mbox_idle(phba);
929 spin_unlock_irq(phba->host->host_lock);
930 return -EPERM;
931 }
932 case MBX_LOAD_SM:
933 case MBX_READ_NV:
934 case MBX_READ_CONFIG:
935 case MBX_READ_RCONFIG:
936 case MBX_READ_STATUS:
937 case MBX_READ_XRI:
938 case MBX_READ_REV:
939 case MBX_READ_LNK_STAT:
940 case MBX_DUMP_MEMORY:
941 case MBX_DOWN_LOAD:
942 case MBX_UPDATE_CFG:
943 case MBX_KILL_BOARD:
944 case MBX_LOAD_AREA:
945 case MBX_LOAD_EXP_ROM:
946 case MBX_BEACON:
947 case MBX_DEL_LD_ENTRY:
948 break;
949 case MBX_READ_SPARM64:
950 case MBX_READ_LA:
951 case MBX_READ_LA64:
952 case MBX_REG_LOGIN:
953 case MBX_REG_LOGIN64:
954 case MBX_CONFIG_PORT:
955 case MBX_RUN_BIU_DIAG:
956 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
957 phba->sysfs_mbox.mbox->mb.mbxCommand);
958 sysfs_mbox_idle(phba);
959 spin_unlock_irq(phba->host->host_lock);
960 return -EPERM;
961 default:
962 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
963 phba->sysfs_mbox.mbox->mb.mbxCommand);
964 sysfs_mbox_idle(phba);
965 spin_unlock_irq(phba->host->host_lock);
966 return -EPERM;
967 }
968
969 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
970 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
971
972 spin_unlock_irq(phba->host->host_lock);
973 rc = lpfc_sli_issue_mbox (phba,
974 phba->sysfs_mbox.mbox,
975 MBX_POLL);
976 spin_lock_irq(phba->host->host_lock);
977
978 } else {
979 spin_unlock_irq(phba->host->host_lock);
980 rc = lpfc_sli_issue_mbox_wait (phba,
981 phba->sysfs_mbox.mbox,
982 phba->fc_ratov * 2);
983 spin_lock_irq(phba->host->host_lock);
984 }
985
986 if (rc != MBX_SUCCESS) {
987 sysfs_mbox_idle(phba);
988 spin_unlock_irq(host->host_lock);
989 return -ENODEV;
990 }
991 phba->sysfs_mbox.state = SMBOX_READING;
992 }
993 else if (phba->sysfs_mbox.offset != off ||
994 phba->sysfs_mbox.state != SMBOX_READING) {
995 printk(KERN_WARNING "mbox_read: Bad State\n");
996 sysfs_mbox_idle(phba);
997 spin_unlock_irq(host->host_lock);
998 return -EINVAL;
999 }
1000
1001 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1002
1003 phba->sysfs_mbox.offset = off + count;
1004
1005 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1006 sysfs_mbox_idle(phba);
1007
1008 spin_unlock_irq(phba->host->host_lock);
1009
1010 return count;
1011 }
1012
1013 static struct bin_attribute sysfs_mbox_attr = {
1014 .attr = {
1015 .name = "mbox",
1016 .mode = S_IRUSR | S_IWUSR,
1017 .owner = THIS_MODULE,
1018 },
1019 .size = sizeof(MAILBOX_t),
1020 .read = sysfs_mbox_read,
1021 .write = sysfs_mbox_write,
1022 };
1023
1024 int
1025 lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1026 {
1027 struct Scsi_Host *host = phba->host;
1028 int error;
1029
1030 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1031 &sysfs_ctlreg_attr);
1032 if (error)
1033 goto out;
1034
1035 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1036 &sysfs_mbox_attr);
1037 if (error)
1038 goto out_remove_ctlreg_attr;
1039
1040 return 0;
1041 out_remove_ctlreg_attr:
1042 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1043 out:
1044 return error;
1045 }
1046
1047 void
1048 lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1049 {
1050 struct Scsi_Host *host = phba->host;
1051
1052 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1053 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1054 }
1055
1056
1057 /*
1058 * Dynamic FC Host Attributes Support
1059 */
1060
1061 static void
1062 lpfc_get_host_port_id(struct Scsi_Host *shost)
1063 {
1064 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1065 /* note: fc_myDID already in cpu endianness */
1066 fc_host_port_id(shost) = phba->fc_myDID;
1067 }
1068
1069 static void
1070 lpfc_get_host_port_type(struct Scsi_Host *shost)
1071 {
1072 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1073
1074 spin_lock_irq(shost->host_lock);
1075
1076 if (phba->hba_state == LPFC_HBA_READY) {
1077 if (phba->fc_topology == TOPOLOGY_LOOP) {
1078 if (phba->fc_flag & FC_PUBLIC_LOOP)
1079 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1080 else
1081 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1082 } else {
1083 if (phba->fc_flag & FC_FABRIC)
1084 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1085 else
1086 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1087 }
1088 } else
1089 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1090
1091 spin_unlock_irq(shost->host_lock);
1092 }
1093
1094 static void
1095 lpfc_get_host_port_state(struct Scsi_Host *shost)
1096 {
1097 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1098
1099 spin_lock_irq(shost->host_lock);
1100
1101 if (phba->fc_flag & FC_OFFLINE_MODE)
1102 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1103 else {
1104 switch (phba->hba_state) {
1105 case LPFC_STATE_UNKNOWN:
1106 case LPFC_WARM_START:
1107 case LPFC_INIT_START:
1108 case LPFC_INIT_MBX_CMDS:
1109 case LPFC_LINK_DOWN:
1110 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1111 break;
1112 case LPFC_LINK_UP:
1113 case LPFC_LOCAL_CFG_LINK:
1114 case LPFC_FLOGI:
1115 case LPFC_FABRIC_CFG_LINK:
1116 case LPFC_NS_REG:
1117 case LPFC_NS_QRY:
1118 case LPFC_BUILD_DISC_LIST:
1119 case LPFC_DISC_AUTH:
1120 case LPFC_CLEAR_LA:
1121 case LPFC_HBA_READY:
1122 /* Links up, beyond this port_type reports state */
1123 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1124 break;
1125 case LPFC_HBA_ERROR:
1126 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1127 break;
1128 default:
1129 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1130 break;
1131 }
1132 }
1133
1134 spin_unlock_irq(shost->host_lock);
1135 }
1136
1137 static void
1138 lpfc_get_host_speed(struct Scsi_Host *shost)
1139 {
1140 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1141
1142 spin_lock_irq(shost->host_lock);
1143
1144 if (phba->hba_state == LPFC_HBA_READY) {
1145 switch(phba->fc_linkspeed) {
1146 case LA_1GHZ_LINK:
1147 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1148 break;
1149 case LA_2GHZ_LINK:
1150 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1151 break;
1152 case LA_4GHZ_LINK:
1153 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1154 break;
1155 default:
1156 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1157 break;
1158 }
1159 }
1160
1161 spin_unlock_irq(shost->host_lock);
1162 }
1163
1164 static void
1165 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1166 {
1167 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1168 u64 node_name;
1169
1170 spin_lock_irq(shost->host_lock);
1171
1172 if ((phba->fc_flag & FC_FABRIC) ||
1173 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1174 (phba->fc_flag & FC_PUBLIC_LOOP)))
1175 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
1176 else
1177 /* fabric is local port if there is no F/FL_Port */
1178 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
1179
1180 spin_unlock_irq(shost->host_lock);
1181
1182 fc_host_fabric_name(shost) = node_name;
1183 }
1184
1185
1186 static struct fc_host_statistics *
1187 lpfc_get_stats(struct Scsi_Host *shost)
1188 {
1189 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1190 struct lpfc_sli *psli = &phba->sli;
1191 struct fc_host_statistics *hs = &phba->link_stats;
1192 LPFC_MBOXQ_t *pmboxq;
1193 MAILBOX_t *pmb;
1194 int rc = 0;
1195
1196 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1197 if (!pmboxq)
1198 return NULL;
1199 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1200
1201 pmb = &pmboxq->mb;
1202 pmb->mbxCommand = MBX_READ_STATUS;
1203 pmb->mbxOwner = OWN_HOST;
1204 pmboxq->context1 = NULL;
1205
1206 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1207 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1208 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1209 else
1210 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1211
1212 if (rc != MBX_SUCCESS) {
1213 if (rc == MBX_TIMEOUT)
1214 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1215 else
1216 mempool_free(pmboxq, phba->mbox_mem_pool);
1217 return NULL;
1218 }
1219
1220 memset(hs, 0, sizeof (struct fc_host_statistics));
1221
1222 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1223 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1224 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1225 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1226
1227 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1228 pmb->mbxCommand = MBX_READ_LNK_STAT;
1229 pmb->mbxOwner = OWN_HOST;
1230 pmboxq->context1 = NULL;
1231
1232 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1233 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1234 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1235 else
1236 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1237
1238 if (rc != MBX_SUCCESS) {
1239 if (rc == MBX_TIMEOUT)
1240 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1241 else
1242 mempool_free( pmboxq, phba->mbox_mem_pool);
1243 return NULL;
1244 }
1245
1246 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1247 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1248 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1249 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1250 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1251 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1252 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1253
1254 if (phba->fc_topology == TOPOLOGY_LOOP) {
1255 hs->lip_count = (phba->fc_eventTag >> 1);
1256 hs->nos_count = -1;
1257 } else {
1258 hs->lip_count = -1;
1259 hs->nos_count = (phba->fc_eventTag >> 1);
1260 }
1261
1262 hs->dumped_frames = -1;
1263
1264 /* FIX ME */
1265 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1266
1267 return hs;
1268 }
1269
1270
1271 /*
1272 * The LPFC driver treats linkdown handling as target loss events so there
1273 * are no sysfs handlers for link_down_tmo.
1274 */
1275 static void
1276 lpfc_get_starget_port_id(struct scsi_target *starget)
1277 {
1278 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1279 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1280 uint32_t did = -1;
1281 struct lpfc_nodelist *ndlp = NULL;
1282
1283 spin_lock_irq(shost->host_lock);
1284 /* Search the mapped list for this target ID */
1285 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1286 if (starget->id == ndlp->nlp_sid) {
1287 did = ndlp->nlp_DID;
1288 break;
1289 }
1290 }
1291 spin_unlock_irq(shost->host_lock);
1292
1293 fc_starget_port_id(starget) = did;
1294 }
1295
1296 static void
1297 lpfc_get_starget_node_name(struct scsi_target *starget)
1298 {
1299 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1300 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1301 u64 node_name = 0;
1302 struct lpfc_nodelist *ndlp = NULL;
1303
1304 spin_lock_irq(shost->host_lock);
1305 /* Search the mapped list for this target ID */
1306 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1307 if (starget->id == ndlp->nlp_sid) {
1308 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1309 break;
1310 }
1311 }
1312 spin_unlock_irq(shost->host_lock);
1313
1314 fc_starget_node_name(starget) = node_name;
1315 }
1316
1317 static void
1318 lpfc_get_starget_port_name(struct scsi_target *starget)
1319 {
1320 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1321 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1322 u64 port_name = 0;
1323 struct lpfc_nodelist *ndlp = NULL;
1324
1325 spin_lock_irq(shost->host_lock);
1326 /* Search the mapped list for this target ID */
1327 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1328 if (starget->id == ndlp->nlp_sid) {
1329 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1330 break;
1331 }
1332 }
1333 spin_unlock_irq(shost->host_lock);
1334
1335 fc_starget_port_name(starget) = port_name;
1336 }
1337
1338 static void
1339 lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1340 {
1341 /*
1342 * Return the driver's global value for device loss timeout plus
1343 * five seconds to allow the driver's nodev timer to run.
1344 */
1345 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1346 }
1347
1348 static void
1349 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1350 {
1351 /*
1352 * The driver doesn't have a per-target timeout setting. Set
1353 * this value globally. lpfc_nodev_tmo should be greater then 0.
1354 */
1355 if (timeout)
1356 lpfc_nodev_tmo = timeout;
1357 else
1358 lpfc_nodev_tmo = 1;
1359 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1360 }
1361
1362
1363 #define lpfc_rport_show_function(field, format_string, sz, cast) \
1364 static ssize_t \
1365 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1366 { \
1367 struct fc_rport *rport = transport_class_to_rport(cdev); \
1368 struct lpfc_rport_data *rdata = rport->hostdata; \
1369 return snprintf(buf, sz, format_string, \
1370 (rdata->target) ? cast rdata->target->field : 0); \
1371 }
1372
1373 #define lpfc_rport_rd_attr(field, format_string, sz) \
1374 lpfc_rport_show_function(field, format_string, sz, ) \
1375 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1376
1377
1378 struct fc_function_template lpfc_transport_functions = {
1379 /* fixed attributes the driver supports */
1380 .show_host_node_name = 1,
1381 .show_host_port_name = 1,
1382 .show_host_supported_classes = 1,
1383 .show_host_supported_fc4s = 1,
1384 .show_host_symbolic_name = 1,
1385 .show_host_supported_speeds = 1,
1386 .show_host_maxframe_size = 1,
1387
1388 /* dynamic attributes the driver supports */
1389 .get_host_port_id = lpfc_get_host_port_id,
1390 .show_host_port_id = 1,
1391
1392 .get_host_port_type = lpfc_get_host_port_type,
1393 .show_host_port_type = 1,
1394
1395 .get_host_port_state = lpfc_get_host_port_state,
1396 .show_host_port_state = 1,
1397
1398 /* active_fc4s is shown but doesn't change (thus no get function) */
1399 .show_host_active_fc4s = 1,
1400
1401 .get_host_speed = lpfc_get_host_speed,
1402 .show_host_speed = 1,
1403
1404 .get_host_fabric_name = lpfc_get_host_fabric_name,
1405 .show_host_fabric_name = 1,
1406
1407 /*
1408 * The LPFC driver treats linkdown handling as target loss events
1409 * so there are no sysfs handlers for link_down_tmo.
1410 */
1411
1412 .get_fc_host_stats = lpfc_get_stats,
1413
1414 /* the LPFC driver doesn't support resetting stats yet */
1415
1416 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1417 .show_rport_maxframe_size = 1,
1418 .show_rport_supported_classes = 1,
1419
1420 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1421 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1422 .show_rport_dev_loss_tmo = 1,
1423
1424 .get_starget_port_id = lpfc_get_starget_port_id,
1425 .show_starget_port_id = 1,
1426
1427 .get_starget_node_name = lpfc_get_starget_node_name,
1428 .show_starget_node_name = 1,
1429
1430 .get_starget_port_name = lpfc_get_starget_port_name,
1431 .show_starget_port_name = 1,
1432
1433 .issue_fc_host_lip = lpfc_issue_lip,
1434 };
1435
1436 void
1437 lpfc_get_cfgparam(struct lpfc_hba *phba)
1438 {
1439 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1440 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1441 lpfc_cr_count_init(phba, lpfc_cr_count);
1442 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1443 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1444 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1445 lpfc_ack0_init(phba, lpfc_ack0);
1446 lpfc_topology_init(phba, lpfc_topology);
1447 lpfc_scan_down_init(phba, lpfc_scan_down);
1448 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1449 lpfc_link_speed_init(phba, lpfc_link_speed);
1450 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1451 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1452 lpfc_max_luns_init(phba, lpfc_max_luns);
1453 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1454
1455 phba->cfg_poll = lpfc_poll;
1456
1457 /*
1458 * The total number of segments is the configuration value plus 2
1459 * since the IOCB need a command and response bde.
1460 */
1461 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1462
1463 /*
1464 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1465 * used to create the sg_dma_buf_pool must be dynamically calculated
1466 */
1467 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1468 sizeof(struct fcp_rsp) +
1469 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1470
1471 switch (phba->pcidev->device) {
1472 case PCI_DEVICE_ID_LP101:
1473 case PCI_DEVICE_ID_BSMB:
1474 case PCI_DEVICE_ID_ZSMB:
1475 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1476 break;
1477 case PCI_DEVICE_ID_RFLY:
1478 case PCI_DEVICE_ID_PFLY:
1479 case PCI_DEVICE_ID_BMID:
1480 case PCI_DEVICE_ID_ZMID:
1481 case PCI_DEVICE_ID_TFLY:
1482 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1483 break;
1484 default:
1485 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1486 }
1487
1488 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1489 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1490
1491 return;
1492 }
This page took 0.079164 seconds and 5 git commands to generate.