[SCSI] lpfc 8.1.11 : Add MSI (Message Signalled Interrupts) support
[linux-2.6/kvm.git] / drivers / scsi / lpfc / lpfc_attr.c
blobe2ac7ba3d8ada0249517121f160c0d0e02ecf8bd
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 *******************************************************************/
22 #include <linux/ctype.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
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>
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"
42 #define LPFC_DEF_DEVLOSS_TMO 30
43 #define LPFC_MIN_DEVLOSS_TMO 1
44 #define LPFC_MAX_DEVLOSS_TMO 255
46 static void
47 lpfc_jedec_to_ascii(int incr, char hdw[])
49 int i, j;
50 for (i = 0; i < 8; i++) {
51 j = (incr & 0xf);
52 if (j <= 9)
53 hdw[7 - i] = 0x30 + j;
54 else
55 hdw[7 - i] = 0x61 + j - 10;
56 incr = (incr >> 4);
58 hdw[8] = 0;
59 return;
62 static ssize_t
63 lpfc_drvr_version_show(struct class_device *cdev, char *buf)
65 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
68 static ssize_t
69 management_version_show(struct class_device *cdev, char *buf)
71 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
74 static ssize_t
75 lpfc_info_show(struct class_device *cdev, char *buf)
77 struct Scsi_Host *host = class_to_shost(cdev);
78 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
81 static ssize_t
82 lpfc_serialnum_show(struct class_device *cdev, char *buf)
84 struct Scsi_Host *host = class_to_shost(cdev);
85 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
86 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
89 static ssize_t
90 lpfc_modeldesc_show(struct class_device *cdev, char *buf)
92 struct Scsi_Host *host = class_to_shost(cdev);
93 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
94 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
97 static ssize_t
98 lpfc_modelname_show(struct class_device *cdev, char *buf)
100 struct Scsi_Host *host = class_to_shost(cdev);
101 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
102 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
105 static ssize_t
106 lpfc_programtype_show(struct class_device *cdev, char *buf)
108 struct Scsi_Host *host = class_to_shost(cdev);
109 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
113 static ssize_t
114 lpfc_portnum_show(struct class_device *cdev, char *buf)
116 struct Scsi_Host *host = class_to_shost(cdev);
117 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
118 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
121 static ssize_t
122 lpfc_fwrev_show(struct class_device *cdev, char *buf)
124 struct Scsi_Host *host = class_to_shost(cdev);
125 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
126 char fwrev[32];
127 lpfc_decode_firmware_rev(phba, fwrev, 1);
128 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
131 static ssize_t
132 lpfc_hdw_show(struct class_device *cdev, char *buf)
134 char hdw[9];
135 struct Scsi_Host *host = class_to_shost(cdev);
136 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
137 lpfc_vpd_t *vp = &phba->vpd;
138 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
139 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
141 static ssize_t
142 lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
144 struct Scsi_Host *host = class_to_shost(cdev);
145 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
146 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
148 static ssize_t
149 lpfc_state_show(struct class_device *cdev, char *buf)
151 struct Scsi_Host *host = class_to_shost(cdev);
152 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
153 int len = 0;
154 switch (phba->hba_state) {
155 case LPFC_STATE_UNKNOWN:
156 case LPFC_WARM_START:
157 case LPFC_INIT_START:
158 case LPFC_INIT_MBX_CMDS:
159 case LPFC_LINK_DOWN:
160 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
161 break;
162 case LPFC_LINK_UP:
163 case LPFC_LOCAL_CFG_LINK:
164 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
165 break;
166 case LPFC_FLOGI:
167 case LPFC_FABRIC_CFG_LINK:
168 case LPFC_NS_REG:
169 case LPFC_NS_QRY:
170 case LPFC_BUILD_DISC_LIST:
171 case LPFC_DISC_AUTH:
172 case LPFC_CLEAR_LA:
173 len += snprintf(buf + len, PAGE_SIZE-len,
174 "Link Up - Discovery\n");
175 break;
176 case LPFC_HBA_READY:
177 len += snprintf(buf + len, PAGE_SIZE-len,
178 "Link Up - Ready:\n");
179 if (phba->fc_topology == TOPOLOGY_LOOP) {
180 if (phba->fc_flag & FC_PUBLIC_LOOP)
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Public Loop\n");
183 else
184 len += snprintf(buf + len, PAGE_SIZE-len,
185 " Private Loop\n");
186 } else {
187 if (phba->fc_flag & FC_FABRIC)
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Fabric\n");
190 else
191 len += snprintf(buf + len, PAGE_SIZE-len,
192 " Point-2-Point\n");
195 return len;
198 static ssize_t
199 lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
201 struct Scsi_Host *host = class_to_shost(cdev);
202 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
203 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
204 phba->fc_unmap_cnt);
208 static int
209 lpfc_issue_lip(struct Scsi_Host *host)
211 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
212 LPFC_MBOXQ_t *pmboxq;
213 int mbxstatus = MBXERR_ERROR;
215 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
216 (phba->hba_state != LPFC_HBA_READY))
217 return -EPERM;
219 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
221 if (!pmboxq)
222 return -ENOMEM;
224 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
225 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
226 pmboxq->mb.mbxOwner = OWN_HOST;
228 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
230 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
231 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
232 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
233 phba->cfg_link_speed);
234 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
235 phba->fc_ratov * 2);
238 if (mbxstatus == MBX_TIMEOUT)
239 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
240 else
241 mempool_free(pmboxq, phba->mbox_mem_pool);
243 if (mbxstatus == MBXERR_ERROR)
244 return -EIO;
246 return 0;
249 static int
250 lpfc_selective_reset(struct lpfc_hba *phba)
252 struct completion online_compl;
253 int status = 0;
255 init_completion(&online_compl);
256 lpfc_workq_post_event(phba, &status, &online_compl,
257 LPFC_EVT_OFFLINE);
258 wait_for_completion(&online_compl);
260 if (status != 0)
261 return -EIO;
263 init_completion(&online_compl);
264 lpfc_workq_post_event(phba, &status, &online_compl,
265 LPFC_EVT_ONLINE);
266 wait_for_completion(&online_compl);
268 if (status != 0)
269 return -EIO;
271 return 0;
274 static ssize_t
275 lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
277 struct Scsi_Host *host = class_to_shost(cdev);
278 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
279 int status = -EINVAL;
281 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
282 status = lpfc_selective_reset(phba);
284 if (status == 0)
285 return strlen(buf);
286 else
287 return status;
290 static ssize_t
291 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
293 struct Scsi_Host *host = class_to_shost(cdev);
294 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
295 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
298 static ssize_t
299 lpfc_board_mode_show(struct class_device *cdev, char *buf)
301 struct Scsi_Host *host = class_to_shost(cdev);
302 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
303 char * state;
305 if (phba->hba_state == LPFC_HBA_ERROR)
306 state = "error";
307 else if (phba->hba_state == LPFC_WARM_START)
308 state = "warm start";
309 else if (phba->hba_state == LPFC_INIT_START)
310 state = "offline";
311 else
312 state = "online";
314 return snprintf(buf, PAGE_SIZE, "%s\n", state);
317 static ssize_t
318 lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
320 struct Scsi_Host *host = class_to_shost(cdev);
321 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
322 struct completion online_compl;
323 int status=0;
325 init_completion(&online_compl);
327 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
328 lpfc_workq_post_event(phba, &status, &online_compl,
329 LPFC_EVT_ONLINE);
330 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
331 lpfc_workq_post_event(phba, &status, &online_compl,
332 LPFC_EVT_OFFLINE);
333 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
334 lpfc_workq_post_event(phba, &status, &online_compl,
335 LPFC_EVT_WARM_START);
336 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
337 lpfc_workq_post_event(phba, &status, &online_compl,
338 LPFC_EVT_KILL);
339 else
340 return -EINVAL;
342 wait_for_completion(&online_compl);
344 if (!status)
345 return strlen(buf);
346 else
347 return -EIO;
350 static ssize_t
351 lpfc_poll_show(struct class_device *cdev, char *buf)
353 struct Scsi_Host *host = class_to_shost(cdev);
354 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
356 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
359 static ssize_t
360 lpfc_poll_store(struct class_device *cdev, const char *buf,
361 size_t count)
363 struct Scsi_Host *host = class_to_shost(cdev);
364 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
365 uint32_t creg_val;
366 uint32_t old_val;
367 int val=0;
369 if (!isdigit(buf[0]))
370 return -EINVAL;
372 if (sscanf(buf, "%i", &val) != 1)
373 return -EINVAL;
375 if ((val & 0x3) != val)
376 return -EINVAL;
378 spin_lock_irq(phba->host->host_lock);
380 old_val = phba->cfg_poll;
382 if (val & ENABLE_FCP_RING_POLLING) {
383 if ((val & DISABLE_FCP_RING_INT) &&
384 !(old_val & DISABLE_FCP_RING_INT)) {
385 creg_val = readl(phba->HCregaddr);
386 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
387 writel(creg_val, phba->HCregaddr);
388 readl(phba->HCregaddr); /* flush */
390 lpfc_poll_start_timer(phba);
392 } else if (val != 0x0) {
393 spin_unlock_irq(phba->host->host_lock);
394 return -EINVAL;
397 if (!(val & DISABLE_FCP_RING_INT) &&
398 (old_val & DISABLE_FCP_RING_INT))
400 spin_unlock_irq(phba->host->host_lock);
401 del_timer(&phba->fcp_poll_timer);
402 spin_lock_irq(phba->host->host_lock);
403 creg_val = readl(phba->HCregaddr);
404 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
405 writel(creg_val, phba->HCregaddr);
406 readl(phba->HCregaddr); /* flush */
409 phba->cfg_poll = val;
411 spin_unlock_irq(phba->host->host_lock);
413 return strlen(buf);
416 #define lpfc_param_show(attr) \
417 static ssize_t \
418 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
420 struct Scsi_Host *host = class_to_shost(cdev);\
421 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
422 int val = 0;\
423 val = phba->cfg_##attr;\
424 return snprintf(buf, PAGE_SIZE, "%d\n",\
425 phba->cfg_##attr);\
428 #define lpfc_param_hex_show(attr) \
429 static ssize_t \
430 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
432 struct Scsi_Host *host = class_to_shost(cdev);\
433 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
434 int val = 0;\
435 val = phba->cfg_##attr;\
436 return snprintf(buf, PAGE_SIZE, "%#x\n",\
437 phba->cfg_##attr);\
440 #define lpfc_param_init(attr, default, minval, maxval) \
441 static int \
442 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
444 if (val >= minval && val <= maxval) {\
445 phba->cfg_##attr = val;\
446 return 0;\
448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
449 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
450 "allowed range is ["#minval", "#maxval"]\n", \
451 phba->brd_no, val); \
452 phba->cfg_##attr = default;\
453 return -EINVAL;\
456 #define lpfc_param_set(attr, default, minval, maxval) \
457 static int \
458 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
460 if (val >= minval && val <= maxval) {\
461 phba->cfg_##attr = val;\
462 return 0;\
464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
465 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
466 "allowed range is ["#minval", "#maxval"]\n", \
467 phba->brd_no, val); \
468 return -EINVAL;\
471 #define lpfc_param_store(attr) \
472 static ssize_t \
473 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
475 struct Scsi_Host *host = class_to_shost(cdev);\
476 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
477 int val=0;\
478 if (!isdigit(buf[0]))\
479 return -EINVAL;\
480 if (sscanf(buf, "%i", &val) != 1)\
481 return -EINVAL;\
482 if (lpfc_##attr##_set(phba, val) == 0) \
483 return strlen(buf);\
484 else \
485 return -EINVAL;\
488 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
489 static int lpfc_##name = defval;\
490 module_param(lpfc_##name, int, 0);\
491 MODULE_PARM_DESC(lpfc_##name, desc);\
492 lpfc_param_init(name, defval, minval, maxval)
494 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
495 static int lpfc_##name = defval;\
496 module_param(lpfc_##name, int, 0);\
497 MODULE_PARM_DESC(lpfc_##name, desc);\
498 lpfc_param_show(name)\
499 lpfc_param_init(name, defval, minval, maxval)\
500 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
502 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
503 static int lpfc_##name = defval;\
504 module_param(lpfc_##name, int, 0);\
505 MODULE_PARM_DESC(lpfc_##name, desc);\
506 lpfc_param_show(name)\
507 lpfc_param_init(name, defval, minval, maxval)\
508 lpfc_param_set(name, defval, minval, maxval)\
509 lpfc_param_store(name)\
510 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
511 lpfc_##name##_show, lpfc_##name##_store)
513 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
514 static int lpfc_##name = defval;\
515 module_param(lpfc_##name, int, 0);\
516 MODULE_PARM_DESC(lpfc_##name, desc);\
517 lpfc_param_hex_show(name)\
518 lpfc_param_init(name, defval, minval, maxval)\
519 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
521 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
522 static int lpfc_##name = defval;\
523 module_param(lpfc_##name, int, 0);\
524 MODULE_PARM_DESC(lpfc_##name, desc);\
525 lpfc_param_hex_show(name)\
526 lpfc_param_init(name, defval, minval, maxval)\
527 lpfc_param_set(name, defval, minval, maxval)\
528 lpfc_param_store(name)\
529 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
530 lpfc_##name##_show, lpfc_##name##_store)
532 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
533 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
534 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
535 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
536 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
537 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
538 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
539 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
540 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
541 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
542 lpfc_option_rom_version_show, NULL);
543 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
544 lpfc_num_discovered_ports_show, NULL);
545 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
546 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
547 NULL);
548 static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
549 NULL);
550 static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
551 lpfc_board_mode_show, lpfc_board_mode_store);
552 static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
555 static char *lpfc_soft_wwpn_key = "C99G71SL8032A";
557 static ssize_t
558 lpfc_soft_wwpn_enable_store(struct class_device *cdev, const char *buf,
559 size_t count)
561 struct Scsi_Host *host = class_to_shost(cdev);
562 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
563 unsigned int cnt = count;
566 * We're doing a simple sanity check for soft_wwpn setting.
567 * We require that the user write a specific key to enable
568 * the soft_wwpn attribute to be settable. Once the attribute
569 * is written, the enable key resets. If further updates are
570 * desired, the key must be written again to re-enable the
571 * attribute.
573 * The "key" is not secret - it is a hardcoded string shown
574 * here. The intent is to protect against the random user or
575 * application that is just writing attributes.
578 /* count may include a LF at end of string */
579 if (buf[cnt-1] == '\n')
580 cnt--;
582 if ((cnt != strlen(lpfc_soft_wwpn_key)) ||
583 (strncmp(buf, lpfc_soft_wwpn_key, strlen(lpfc_soft_wwpn_key)) != 0))
584 return -EINVAL;
586 phba->soft_wwpn_enable = 1;
587 return count;
589 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn_enable, S_IWUSR, NULL,
590 lpfc_soft_wwpn_enable_store);
592 static ssize_t
593 lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
595 struct Scsi_Host *host = class_to_shost(cdev);
596 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
597 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
598 (unsigned long long)phba->cfg_soft_wwpn);
602 static ssize_t
603 lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
605 struct Scsi_Host *host = class_to_shost(cdev);
606 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
607 struct completion online_compl;
608 int stat1=0, stat2=0;
609 unsigned int i, j, cnt=count;
610 u8 wwpn[8];
612 /* count may include a LF at end of string */
613 if (buf[cnt-1] == '\n')
614 cnt--;
616 if (!phba->soft_wwpn_enable || (cnt < 16) || (cnt > 18) ||
617 ((cnt == 17) && (*buf++ != 'x')) ||
618 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
619 return -EINVAL;
621 phba->soft_wwpn_enable = 0;
623 memset(wwpn, 0, sizeof(wwpn));
625 /* Validate and store the new name */
626 for (i=0, j=0; i < 16; i++) {
627 if ((*buf >= 'a') && (*buf <= 'f'))
628 j = ((j << 4) | ((*buf++ -'a') + 10));
629 else if ((*buf >= 'A') && (*buf <= 'F'))
630 j = ((j << 4) | ((*buf++ -'A') + 10));
631 else if ((*buf >= '0') && (*buf <= '9'))
632 j = ((j << 4) | (*buf++ -'0'));
633 else
634 return -EINVAL;
635 if (i % 2) {
636 wwpn[i/2] = j & 0xff;
637 j = 0;
640 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
641 fc_host_port_name(host) = phba->cfg_soft_wwpn;
643 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
644 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
646 init_completion(&online_compl);
647 lpfc_workq_post_event(phba, &stat1, &online_compl, LPFC_EVT_OFFLINE);
648 wait_for_completion(&online_compl);
649 if (stat1)
650 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
651 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
652 "adapter - %d\n", phba->brd_no, stat1);
654 init_completion(&online_compl);
655 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
656 wait_for_completion(&online_compl);
657 if (stat2)
658 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
659 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
660 "adapter - %d\n", phba->brd_no, stat2);
662 return (stat1 || stat2) ? -EIO : count;
664 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
665 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
668 static int lpfc_poll = 0;
669 module_param(lpfc_poll, int, 0);
670 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
671 " 0 - none,"
672 " 1 - poll with interrupts enabled"
673 " 3 - poll and disable FCP ring interrupts");
675 static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
676 lpfc_poll_show, lpfc_poll_store);
679 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
680 # until the timer expires. Value range is [0,255]. Default value is 30.
682 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
683 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
684 module_param(lpfc_nodev_tmo, int, 0);
685 MODULE_PARM_DESC(lpfc_nodev_tmo,
686 "Seconds driver will hold I/O waiting "
687 "for a device to come back");
688 static ssize_t
689 lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
691 struct Scsi_Host *host = class_to_shost(cdev);
692 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
693 int val = 0;
694 val = phba->cfg_devloss_tmo;
695 return snprintf(buf, PAGE_SIZE, "%d\n",
696 phba->cfg_devloss_tmo);
699 static int
700 lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
702 static int warned;
703 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
704 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
705 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
706 warned = 1;
707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
708 "%d:0402 Ignoring nodev_tmo module "
709 "parameter because devloss_tmo is"
710 " set.\n",
711 phba->brd_no);
713 return 0;
716 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
717 phba->cfg_nodev_tmo = val;
718 phba->cfg_devloss_tmo = val;
719 return 0;
721 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
722 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
723 "allowed range is [%d, %d]\n",
724 phba->brd_no, val,
725 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
726 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
727 return -EINVAL;
730 static int
731 lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
733 if (phba->dev_loss_tmo_changed ||
734 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
735 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
736 "%d:0401 Ignoring change to nodev_tmo "
737 "because devloss_tmo is set.\n",
738 phba->brd_no);
739 return 0;
742 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
743 phba->cfg_nodev_tmo = val;
744 phba->cfg_devloss_tmo = val;
745 return 0;
748 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
749 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
750 "allowed range is [%d, %d]\n",
751 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
752 LPFC_MAX_DEVLOSS_TMO);
753 return -EINVAL;
756 lpfc_param_store(nodev_tmo)
758 static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
759 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
762 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
763 # disappear until the timer expires. Value range is [0,255]. Default
764 # value is 30.
766 module_param(lpfc_devloss_tmo, int, 0);
767 MODULE_PARM_DESC(lpfc_devloss_tmo,
768 "Seconds driver will hold I/O waiting "
769 "for a device to come back");
770 lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
771 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
772 lpfc_param_show(devloss_tmo)
773 static int
774 lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
776 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
777 phba->cfg_nodev_tmo = val;
778 phba->cfg_devloss_tmo = val;
779 phba->dev_loss_tmo_changed = 1;
780 return 0;
783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
784 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
785 " %d, allowed range is [%d, %d]\n",
786 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
787 LPFC_MAX_DEVLOSS_TMO);
788 return -EINVAL;
791 lpfc_param_store(devloss_tmo)
792 static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
793 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
796 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
797 # deluged with LOTS of information.
798 # You can set a bit mask to record specific types of verbose messages:
800 # LOG_ELS 0x1 ELS events
801 # LOG_DISCOVERY 0x2 Link discovery events
802 # LOG_MBOX 0x4 Mailbox events
803 # LOG_INIT 0x8 Initialization events
804 # LOG_LINK_EVENT 0x10 Link events
805 # LOG_FCP 0x40 FCP traffic history
806 # LOG_NODE 0x80 Node table events
807 # LOG_MISC 0x400 Miscellaneous events
808 # LOG_SLI 0x800 SLI events
809 # LOG_FCP_ERROR 0x1000 Only log FCP errors
810 # LOG_LIBDFC 0x2000 LIBDFC events
811 # LOG_ALL_MSG 0xffff LOG all messages
813 LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
816 # lun_queue_depth: This parameter is used to limit the number of outstanding
817 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
819 LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
820 "Max number of FCP commands we can queue to a specific LUN");
823 # hba_queue_depth: This parameter is used to limit the number of outstanding
824 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
825 # value is greater than the maximum number of exchanges supported by the HBA,
826 # then maximum number of exchanges supported by the HBA is used to determine
827 # the hba_queue_depth.
829 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
830 "Max number of FCP commands we can queue to a lpfc HBA");
833 # Some disk devices have a "select ID" or "select Target" capability.
834 # From a protocol standpoint "select ID" usually means select the
835 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
836 # annex" which contains a table that maps a "select ID" (a number
837 # between 0 and 7F) to an ALPA. By default, for compatibility with
838 # older drivers, the lpfc driver scans this table from low ALPA to high
839 # ALPA.
841 # Turning on the scan-down variable (on = 1, off = 0) will
842 # cause the lpfc driver to use an inverted table, effectively
843 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
845 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
846 # and will not work across a fabric. Also this parameter will take
847 # effect only in the case when ALPA map is not available.)
849 LPFC_ATTR_R(scan_down, 1, 0, 1,
850 "Start scanning for devices from highest ALPA to lowest");
853 # lpfc_topology: link topology for init link
854 # 0x0 = attempt loop mode then point-to-point
855 # 0x01 = internal loopback mode
856 # 0x02 = attempt point-to-point mode only
857 # 0x04 = attempt loop mode only
858 # 0x06 = attempt point-to-point mode then loop
859 # Set point-to-point mode if you want to run as an N_Port.
860 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
861 # Default value is 0.
863 LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
866 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
867 # connection.
868 # 0 = auto select (default)
869 # 1 = 1 Gigabaud
870 # 2 = 2 Gigabaud
871 # 4 = 4 Gigabaud
872 # Value range is [0,4]. Default value is 0.
874 LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
877 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
878 # Value range is [2,3]. Default value is 3.
880 LPFC_ATTR_R(fcp_class, 3, 2, 3,
881 "Select Fibre Channel class of service for FCP sequences");
884 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
885 # is [0,1]. Default value is 0.
887 LPFC_ATTR_RW(use_adisc, 0, 0, 1,
888 "Use ADISC on rediscovery to authenticate FCP devices");
891 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
892 # range is [0,1]. Default value is 0.
894 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
897 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
898 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
899 # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
900 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
901 # cr_delay is set to 0.
903 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
904 "interrupt response is generated");
906 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
907 "interrupt response is generated");
910 # lpfc_multi_ring_support: Determines how many rings to spread available
911 # cmd/rsp IOCB entries across.
912 # Value range is [1,2]. Default value is 1.
914 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
915 "SLI rings to spread IOCB entries across");
918 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
919 # identifies what rctl value to configure the additional ring for.
920 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
922 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
923 255, "Identifies RCTL for additional ring configuration");
926 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
927 # identifies what type value to configure the additional ring for.
928 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
930 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
931 255, "Identifies TYPE for additional ring configuration");
934 # lpfc_fdmi_on: controls FDMI support.
935 # 0 = no FDMI support
936 # 1 = support FDMI without attribute of hostname
937 # 2 = support FDMI with attribute of hostname
938 # Value range [0,2]. Default value is 0.
940 LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
943 # Specifies the maximum number of ELS cmds we can have outstanding (for
944 # discovery). Value range is [1,64]. Default value = 32.
946 LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
947 "during discovery");
950 # lpfc_max_luns: maximum allowed LUN.
951 # Value range is [0,65535]. Default value is 255.
952 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
954 LPFC_ATTR_R(max_luns, 255, 0, 65535,
955 "Maximum allowed LUN");
958 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
959 # Value range is [1,255], default value is 10.
961 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
962 "Milliseconds driver will wait between polling FCP ring");
965 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
966 # support this feature
967 # 0 = MSI disabled (default)
968 # 1 = MSI enabled
969 # Value range is [0,1]. Default value is 0.
971 LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
974 struct class_device_attribute *lpfc_host_attrs[] = {
975 &class_device_attr_info,
976 &class_device_attr_serialnum,
977 &class_device_attr_modeldesc,
978 &class_device_attr_modelname,
979 &class_device_attr_programtype,
980 &class_device_attr_portnum,
981 &class_device_attr_fwrev,
982 &class_device_attr_hdw,
983 &class_device_attr_option_rom_version,
984 &class_device_attr_state,
985 &class_device_attr_num_discovered_ports,
986 &class_device_attr_lpfc_drvr_version,
987 &class_device_attr_lpfc_log_verbose,
988 &class_device_attr_lpfc_lun_queue_depth,
989 &class_device_attr_lpfc_hba_queue_depth,
990 &class_device_attr_lpfc_nodev_tmo,
991 &class_device_attr_lpfc_devloss_tmo,
992 &class_device_attr_lpfc_fcp_class,
993 &class_device_attr_lpfc_use_adisc,
994 &class_device_attr_lpfc_ack0,
995 &class_device_attr_lpfc_topology,
996 &class_device_attr_lpfc_scan_down,
997 &class_device_attr_lpfc_link_speed,
998 &class_device_attr_lpfc_cr_delay,
999 &class_device_attr_lpfc_cr_count,
1000 &class_device_attr_lpfc_multi_ring_support,
1001 &class_device_attr_lpfc_multi_ring_rctl,
1002 &class_device_attr_lpfc_multi_ring_type,
1003 &class_device_attr_lpfc_fdmi_on,
1004 &class_device_attr_lpfc_max_luns,
1005 &class_device_attr_nport_evt_cnt,
1006 &class_device_attr_management_version,
1007 &class_device_attr_board_mode,
1008 &class_device_attr_issue_reset,
1009 &class_device_attr_lpfc_poll,
1010 &class_device_attr_lpfc_poll_tmo,
1011 &class_device_attr_lpfc_use_msi,
1012 &class_device_attr_lpfc_soft_wwpn,
1013 &class_device_attr_lpfc_soft_wwpn_enable,
1014 NULL,
1017 static ssize_t
1018 sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1020 size_t buf_off;
1021 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1022 struct class_device, kobj));
1023 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1025 if ((off + count) > FF_REG_AREA_SIZE)
1026 return -ERANGE;
1028 if (count == 0) return 0;
1030 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1031 return -EINVAL;
1033 spin_lock_irq(phba->host->host_lock);
1035 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1036 spin_unlock_irq(phba->host->host_lock);
1037 return -EPERM;
1040 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1041 writel(*((uint32_t *)(buf + buf_off)),
1042 phba->ctrl_regs_memmap_p + off + buf_off);
1044 spin_unlock_irq(phba->host->host_lock);
1046 return count;
1049 static ssize_t
1050 sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1052 size_t buf_off;
1053 uint32_t * tmp_ptr;
1054 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1055 struct class_device, kobj));
1056 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1058 if (off > FF_REG_AREA_SIZE)
1059 return -ERANGE;
1061 if ((off + count) > FF_REG_AREA_SIZE)
1062 count = FF_REG_AREA_SIZE - off;
1064 if (count == 0) return 0;
1066 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1067 return -EINVAL;
1069 spin_lock_irq(phba->host->host_lock);
1071 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1072 tmp_ptr = (uint32_t *)(buf + buf_off);
1073 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1076 spin_unlock_irq(phba->host->host_lock);
1078 return count;
1081 static struct bin_attribute sysfs_ctlreg_attr = {
1082 .attr = {
1083 .name = "ctlreg",
1084 .mode = S_IRUSR | S_IWUSR,
1085 .owner = THIS_MODULE,
1087 .size = 256,
1088 .read = sysfs_ctlreg_read,
1089 .write = sysfs_ctlreg_write,
1093 static void
1094 sysfs_mbox_idle (struct lpfc_hba * phba)
1096 phba->sysfs_mbox.state = SMBOX_IDLE;
1097 phba->sysfs_mbox.offset = 0;
1099 if (phba->sysfs_mbox.mbox) {
1100 mempool_free(phba->sysfs_mbox.mbox,
1101 phba->mbox_mem_pool);
1102 phba->sysfs_mbox.mbox = NULL;
1106 static ssize_t
1107 sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1109 struct Scsi_Host * host =
1110 class_to_shost(container_of(kobj, struct class_device, kobj));
1111 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
1112 struct lpfcMboxq * mbox = NULL;
1114 if ((count + off) > MAILBOX_CMD_SIZE)
1115 return -ERANGE;
1117 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1118 return -EINVAL;
1120 if (count == 0)
1121 return 0;
1123 if (off == 0) {
1124 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1125 if (!mbox)
1126 return -ENOMEM;
1127 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1130 spin_lock_irq(host->host_lock);
1132 if (off == 0) {
1133 if (phba->sysfs_mbox.mbox)
1134 mempool_free(mbox, phba->mbox_mem_pool);
1135 else
1136 phba->sysfs_mbox.mbox = mbox;
1137 phba->sysfs_mbox.state = SMBOX_WRITING;
1138 } else {
1139 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1140 phba->sysfs_mbox.offset != off ||
1141 phba->sysfs_mbox.mbox == NULL ) {
1142 sysfs_mbox_idle(phba);
1143 spin_unlock_irq(host->host_lock);
1144 return -EAGAIN;
1148 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1149 buf, count);
1151 phba->sysfs_mbox.offset = off + count;
1153 spin_unlock_irq(host->host_lock);
1155 return count;
1158 static ssize_t
1159 sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1161 struct Scsi_Host *host =
1162 class_to_shost(container_of(kobj, struct class_device,
1163 kobj));
1164 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1165 int rc;
1167 if (off > sizeof(MAILBOX_t))
1168 return -ERANGE;
1170 if ((count + off) > sizeof(MAILBOX_t))
1171 count = sizeof(MAILBOX_t) - off;
1173 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1174 return -EINVAL;
1176 if (off && count == 0)
1177 return 0;
1179 spin_lock_irq(phba->host->host_lock);
1181 if (off == 0 &&
1182 phba->sysfs_mbox.state == SMBOX_WRITING &&
1183 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1185 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1186 /* Offline only */
1187 case MBX_WRITE_NV:
1188 case MBX_INIT_LINK:
1189 case MBX_DOWN_LINK:
1190 case MBX_CONFIG_LINK:
1191 case MBX_CONFIG_RING:
1192 case MBX_RESET_RING:
1193 case MBX_UNREG_LOGIN:
1194 case MBX_CLEAR_LA:
1195 case MBX_DUMP_CONTEXT:
1196 case MBX_RUN_DIAGS:
1197 case MBX_RESTART:
1198 case MBX_FLASH_WR_ULA:
1199 case MBX_SET_MASK:
1200 case MBX_SET_SLIM:
1201 case MBX_SET_DEBUG:
1202 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1203 printk(KERN_WARNING "mbox_read:Command 0x%x "
1204 "is illegal in on-line state\n",
1205 phba->sysfs_mbox.mbox->mb.mbxCommand);
1206 sysfs_mbox_idle(phba);
1207 spin_unlock_irq(phba->host->host_lock);
1208 return -EPERM;
1210 case MBX_LOAD_SM:
1211 case MBX_READ_NV:
1212 case MBX_READ_CONFIG:
1213 case MBX_READ_RCONFIG:
1214 case MBX_READ_STATUS:
1215 case MBX_READ_XRI:
1216 case MBX_READ_REV:
1217 case MBX_READ_LNK_STAT:
1218 case MBX_DUMP_MEMORY:
1219 case MBX_DOWN_LOAD:
1220 case MBX_UPDATE_CFG:
1221 case MBX_KILL_BOARD:
1222 case MBX_LOAD_AREA:
1223 case MBX_LOAD_EXP_ROM:
1224 case MBX_BEACON:
1225 case MBX_DEL_LD_ENTRY:
1226 break;
1227 case MBX_READ_SPARM64:
1228 case MBX_READ_LA:
1229 case MBX_READ_LA64:
1230 case MBX_REG_LOGIN:
1231 case MBX_REG_LOGIN64:
1232 case MBX_CONFIG_PORT:
1233 case MBX_RUN_BIU_DIAG:
1234 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1235 phba->sysfs_mbox.mbox->mb.mbxCommand);
1236 sysfs_mbox_idle(phba);
1237 spin_unlock_irq(phba->host->host_lock);
1238 return -EPERM;
1239 default:
1240 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1241 phba->sysfs_mbox.mbox->mb.mbxCommand);
1242 sysfs_mbox_idle(phba);
1243 spin_unlock_irq(phba->host->host_lock);
1244 return -EPERM;
1247 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1248 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1250 spin_unlock_irq(phba->host->host_lock);
1251 rc = lpfc_sli_issue_mbox (phba,
1252 phba->sysfs_mbox.mbox,
1253 MBX_POLL);
1254 spin_lock_irq(phba->host->host_lock);
1256 } else {
1257 spin_unlock_irq(phba->host->host_lock);
1258 rc = lpfc_sli_issue_mbox_wait (phba,
1259 phba->sysfs_mbox.mbox,
1260 lpfc_mbox_tmo_val(phba,
1261 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1262 spin_lock_irq(phba->host->host_lock);
1265 if (rc != MBX_SUCCESS) {
1266 sysfs_mbox_idle(phba);
1267 spin_unlock_irq(host->host_lock);
1268 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1270 phba->sysfs_mbox.state = SMBOX_READING;
1272 else if (phba->sysfs_mbox.offset != off ||
1273 phba->sysfs_mbox.state != SMBOX_READING) {
1274 printk(KERN_WARNING "mbox_read: Bad State\n");
1275 sysfs_mbox_idle(phba);
1276 spin_unlock_irq(host->host_lock);
1277 return -EAGAIN;
1280 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1282 phba->sysfs_mbox.offset = off + count;
1284 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1285 sysfs_mbox_idle(phba);
1287 spin_unlock_irq(phba->host->host_lock);
1289 return count;
1292 static struct bin_attribute sysfs_mbox_attr = {
1293 .attr = {
1294 .name = "mbox",
1295 .mode = S_IRUSR | S_IWUSR,
1296 .owner = THIS_MODULE,
1298 .size = sizeof(MAILBOX_t),
1299 .read = sysfs_mbox_read,
1300 .write = sysfs_mbox_write,
1304 lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1306 struct Scsi_Host *host = phba->host;
1307 int error;
1309 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1310 &sysfs_ctlreg_attr);
1311 if (error)
1312 goto out;
1314 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1315 &sysfs_mbox_attr);
1316 if (error)
1317 goto out_remove_ctlreg_attr;
1319 return 0;
1320 out_remove_ctlreg_attr:
1321 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1322 out:
1323 return error;
1326 void
1327 lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1329 struct Scsi_Host *host = phba->host;
1331 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1332 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1337 * Dynamic FC Host Attributes Support
1340 static void
1341 lpfc_get_host_port_id(struct Scsi_Host *shost)
1343 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1344 /* note: fc_myDID already in cpu endianness */
1345 fc_host_port_id(shost) = phba->fc_myDID;
1348 static void
1349 lpfc_get_host_port_type(struct Scsi_Host *shost)
1351 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1353 spin_lock_irq(shost->host_lock);
1355 if (phba->hba_state == LPFC_HBA_READY) {
1356 if (phba->fc_topology == TOPOLOGY_LOOP) {
1357 if (phba->fc_flag & FC_PUBLIC_LOOP)
1358 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1359 else
1360 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1361 } else {
1362 if (phba->fc_flag & FC_FABRIC)
1363 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1364 else
1365 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1367 } else
1368 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1370 spin_unlock_irq(shost->host_lock);
1373 static void
1374 lpfc_get_host_port_state(struct Scsi_Host *shost)
1376 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1378 spin_lock_irq(shost->host_lock);
1380 if (phba->fc_flag & FC_OFFLINE_MODE)
1381 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1382 else {
1383 switch (phba->hba_state) {
1384 case LPFC_STATE_UNKNOWN:
1385 case LPFC_WARM_START:
1386 case LPFC_INIT_START:
1387 case LPFC_INIT_MBX_CMDS:
1388 case LPFC_LINK_DOWN:
1389 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1390 break;
1391 case LPFC_LINK_UP:
1392 case LPFC_LOCAL_CFG_LINK:
1393 case LPFC_FLOGI:
1394 case LPFC_FABRIC_CFG_LINK:
1395 case LPFC_NS_REG:
1396 case LPFC_NS_QRY:
1397 case LPFC_BUILD_DISC_LIST:
1398 case LPFC_DISC_AUTH:
1399 case LPFC_CLEAR_LA:
1400 case LPFC_HBA_READY:
1401 /* Links up, beyond this port_type reports state */
1402 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1403 break;
1404 case LPFC_HBA_ERROR:
1405 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1406 break;
1407 default:
1408 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1409 break;
1413 spin_unlock_irq(shost->host_lock);
1416 static void
1417 lpfc_get_host_speed(struct Scsi_Host *shost)
1419 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1421 spin_lock_irq(shost->host_lock);
1423 if (phba->hba_state == LPFC_HBA_READY) {
1424 switch(phba->fc_linkspeed) {
1425 case LA_1GHZ_LINK:
1426 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1427 break;
1428 case LA_2GHZ_LINK:
1429 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1430 break;
1431 case LA_4GHZ_LINK:
1432 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1433 break;
1434 default:
1435 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1436 break;
1440 spin_unlock_irq(shost->host_lock);
1443 static void
1444 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1446 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1447 u64 node_name;
1449 spin_lock_irq(shost->host_lock);
1451 if ((phba->fc_flag & FC_FABRIC) ||
1452 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1453 (phba->fc_flag & FC_PUBLIC_LOOP)))
1454 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
1455 else
1456 /* fabric is local port if there is no F/FL_Port */
1457 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
1459 spin_unlock_irq(shost->host_lock);
1461 fc_host_fabric_name(shost) = node_name;
1464 static void
1465 lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1467 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1469 spin_lock_irq(shost->host_lock);
1470 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1471 spin_unlock_irq(shost->host_lock);
1474 static struct fc_host_statistics *
1475 lpfc_get_stats(struct Scsi_Host *shost)
1477 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1478 struct lpfc_sli *psli = &phba->sli;
1479 struct fc_host_statistics *hs = &phba->link_stats;
1480 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1481 LPFC_MBOXQ_t *pmboxq;
1482 MAILBOX_t *pmb;
1483 unsigned long seconds;
1484 int rc = 0;
1486 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1487 if (!pmboxq)
1488 return NULL;
1489 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1491 pmb = &pmboxq->mb;
1492 pmb->mbxCommand = MBX_READ_STATUS;
1493 pmb->mbxOwner = OWN_HOST;
1494 pmboxq->context1 = NULL;
1496 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1497 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1498 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1499 else
1500 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1502 if (rc != MBX_SUCCESS) {
1503 if (rc == MBX_TIMEOUT)
1504 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1505 else
1506 mempool_free(pmboxq, phba->mbox_mem_pool);
1507 return NULL;
1510 memset(hs, 0, sizeof (struct fc_host_statistics));
1512 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1513 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1514 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1515 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1517 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1518 pmb->mbxCommand = MBX_READ_LNK_STAT;
1519 pmb->mbxOwner = OWN_HOST;
1520 pmboxq->context1 = NULL;
1522 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1523 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1524 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1525 else
1526 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1528 if (rc != MBX_SUCCESS) {
1529 if (rc == MBX_TIMEOUT)
1530 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1531 else
1532 mempool_free( pmboxq, phba->mbox_mem_pool);
1533 return NULL;
1536 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1537 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1538 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1539 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1540 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1541 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1542 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1544 hs->link_failure_count -= lso->link_failure_count;
1545 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1546 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1547 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1548 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1549 hs->invalid_crc_count -= lso->invalid_crc_count;
1550 hs->error_frames -= lso->error_frames;
1552 if (phba->fc_topology == TOPOLOGY_LOOP) {
1553 hs->lip_count = (phba->fc_eventTag >> 1);
1554 hs->lip_count -= lso->link_events;
1555 hs->nos_count = -1;
1556 } else {
1557 hs->lip_count = -1;
1558 hs->nos_count = (phba->fc_eventTag >> 1);
1559 hs->nos_count -= lso->link_events;
1562 hs->dumped_frames = -1;
1564 seconds = get_seconds();
1565 if (seconds < psli->stats_start)
1566 hs->seconds_since_last_reset = seconds +
1567 ((unsigned long)-1 - psli->stats_start);
1568 else
1569 hs->seconds_since_last_reset = seconds - psli->stats_start;
1571 return hs;
1574 static void
1575 lpfc_reset_stats(struct Scsi_Host *shost)
1577 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1578 struct lpfc_sli *psli = &phba->sli;
1579 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1580 LPFC_MBOXQ_t *pmboxq;
1581 MAILBOX_t *pmb;
1582 int rc = 0;
1584 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1585 if (!pmboxq)
1586 return;
1587 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1589 pmb = &pmboxq->mb;
1590 pmb->mbxCommand = MBX_READ_STATUS;
1591 pmb->mbxOwner = OWN_HOST;
1592 pmb->un.varWords[0] = 0x1; /* reset request */
1593 pmboxq->context1 = NULL;
1595 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1596 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1597 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1598 else
1599 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1601 if (rc != MBX_SUCCESS) {
1602 if (rc == MBX_TIMEOUT)
1603 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1604 else
1605 mempool_free(pmboxq, phba->mbox_mem_pool);
1606 return;
1609 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1610 pmb->mbxCommand = MBX_READ_LNK_STAT;
1611 pmb->mbxOwner = OWN_HOST;
1612 pmboxq->context1 = NULL;
1614 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1615 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1616 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1617 else
1618 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1620 if (rc != MBX_SUCCESS) {
1621 if (rc == MBX_TIMEOUT)
1622 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1623 else
1624 mempool_free( pmboxq, phba->mbox_mem_pool);
1625 return;
1628 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1629 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1630 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1631 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1632 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1633 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1634 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1635 lso->link_events = (phba->fc_eventTag >> 1);
1637 psli->stats_start = get_seconds();
1639 return;
1643 * The LPFC driver treats linkdown handling as target loss events so there
1644 * are no sysfs handlers for link_down_tmo.
1646 static void
1647 lpfc_get_starget_port_id(struct scsi_target *starget)
1649 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1650 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1651 uint32_t did = -1;
1652 struct lpfc_nodelist *ndlp = NULL;
1654 spin_lock_irq(shost->host_lock);
1655 /* Search the mapped list for this target ID */
1656 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1657 if (starget->id == ndlp->nlp_sid) {
1658 did = ndlp->nlp_DID;
1659 break;
1662 spin_unlock_irq(shost->host_lock);
1664 fc_starget_port_id(starget) = did;
1667 static void
1668 lpfc_get_starget_node_name(struct scsi_target *starget)
1670 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1671 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1672 u64 node_name = 0;
1673 struct lpfc_nodelist *ndlp = NULL;
1675 spin_lock_irq(shost->host_lock);
1676 /* Search the mapped list for this target ID */
1677 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1678 if (starget->id == ndlp->nlp_sid) {
1679 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1680 break;
1683 spin_unlock_irq(shost->host_lock);
1685 fc_starget_node_name(starget) = node_name;
1688 static void
1689 lpfc_get_starget_port_name(struct scsi_target *starget)
1691 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1692 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1693 u64 port_name = 0;
1694 struct lpfc_nodelist *ndlp = NULL;
1696 spin_lock_irq(shost->host_lock);
1697 /* Search the mapped list for this target ID */
1698 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1699 if (starget->id == ndlp->nlp_sid) {
1700 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1701 break;
1704 spin_unlock_irq(shost->host_lock);
1706 fc_starget_port_name(starget) = port_name;
1709 static void
1710 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1712 if (timeout)
1713 rport->dev_loss_tmo = timeout;
1714 else
1715 rport->dev_loss_tmo = 1;
1719 #define lpfc_rport_show_function(field, format_string, sz, cast) \
1720 static ssize_t \
1721 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1723 struct fc_rport *rport = transport_class_to_rport(cdev); \
1724 struct lpfc_rport_data *rdata = rport->hostdata; \
1725 return snprintf(buf, sz, format_string, \
1726 (rdata->target) ? cast rdata->target->field : 0); \
1729 #define lpfc_rport_rd_attr(field, format_string, sz) \
1730 lpfc_rport_show_function(field, format_string, sz, ) \
1731 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1734 struct fc_function_template lpfc_transport_functions = {
1735 /* fixed attributes the driver supports */
1736 .show_host_node_name = 1,
1737 .show_host_port_name = 1,
1738 .show_host_supported_classes = 1,
1739 .show_host_supported_fc4s = 1,
1740 .show_host_supported_speeds = 1,
1741 .show_host_maxframe_size = 1,
1743 /* dynamic attributes the driver supports */
1744 .get_host_port_id = lpfc_get_host_port_id,
1745 .show_host_port_id = 1,
1747 .get_host_port_type = lpfc_get_host_port_type,
1748 .show_host_port_type = 1,
1750 .get_host_port_state = lpfc_get_host_port_state,
1751 .show_host_port_state = 1,
1753 /* active_fc4s is shown but doesn't change (thus no get function) */
1754 .show_host_active_fc4s = 1,
1756 .get_host_speed = lpfc_get_host_speed,
1757 .show_host_speed = 1,
1759 .get_host_fabric_name = lpfc_get_host_fabric_name,
1760 .show_host_fabric_name = 1,
1762 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1763 .show_host_symbolic_name = 1,
1766 * The LPFC driver treats linkdown handling as target loss events
1767 * so there are no sysfs handlers for link_down_tmo.
1770 .get_fc_host_stats = lpfc_get_stats,
1771 .reset_fc_host_stats = lpfc_reset_stats,
1773 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1774 .show_rport_maxframe_size = 1,
1775 .show_rport_supported_classes = 1,
1777 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1778 .show_rport_dev_loss_tmo = 1,
1780 .get_starget_port_id = lpfc_get_starget_port_id,
1781 .show_starget_port_id = 1,
1783 .get_starget_node_name = lpfc_get_starget_node_name,
1784 .show_starget_node_name = 1,
1786 .get_starget_port_name = lpfc_get_starget_port_name,
1787 .show_starget_port_name = 1,
1789 .issue_fc_host_lip = lpfc_issue_lip,
1790 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1791 .terminate_rport_io = lpfc_terminate_rport_io,
1794 void
1795 lpfc_get_cfgparam(struct lpfc_hba *phba)
1797 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1798 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1799 lpfc_cr_count_init(phba, lpfc_cr_count);
1800 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
1801 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1802 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
1803 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1804 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1805 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1806 lpfc_ack0_init(phba, lpfc_ack0);
1807 lpfc_topology_init(phba, lpfc_topology);
1808 lpfc_scan_down_init(phba, lpfc_scan_down);
1809 lpfc_link_speed_init(phba, lpfc_link_speed);
1810 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1811 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1812 lpfc_max_luns_init(phba, lpfc_max_luns);
1813 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1814 lpfc_use_msi_init(phba, lpfc_use_msi);
1815 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1816 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1817 phba->cfg_poll = lpfc_poll;
1818 phba->cfg_soft_wwpn = 0L;
1821 * The total number of segments is the configuration value plus 2
1822 * since the IOCB need a command and response bde.
1824 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1827 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1828 * used to create the sg_dma_buf_pool must be dynamically calculated
1830 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1831 sizeof(struct fcp_rsp) +
1832 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1834 switch (phba->pcidev->device) {
1835 case PCI_DEVICE_ID_LP101:
1836 case PCI_DEVICE_ID_BSMB:
1837 case PCI_DEVICE_ID_ZSMB:
1838 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1839 break;
1840 case PCI_DEVICE_ID_RFLY:
1841 case PCI_DEVICE_ID_PFLY:
1842 case PCI_DEVICE_ID_BMID:
1843 case PCI_DEVICE_ID_ZMID:
1844 case PCI_DEVICE_ID_TFLY:
1845 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1846 break;
1847 default:
1848 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1851 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1852 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1854 return;