Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / scsi / lpfc / lpfc_attr.c
blob4ac874e02b09c34330ac40bafb90cf1329ad35da
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 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/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/aer.h>
28 #include <linux/gfp.h>
29 #include <linux/kernel.h>
31 #include <scsi/scsi.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi_tcq.h>
35 #include <scsi/scsi_transport_fc.h>
36 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_hw4.h"
39 #include "lpfc_hw.h"
40 #include "lpfc_sli.h"
41 #include "lpfc_sli4.h"
42 #include "lpfc_nl.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_version.h"
48 #include "lpfc_compat.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
52 #define LPFC_DEF_DEVLOSS_TMO 30
53 #define LPFC_MIN_DEVLOSS_TMO 1
54 #define LPFC_MAX_DEVLOSS_TMO 255
57 * Write key size should be multiple of 4. If write key is changed
58 * make sure that library write key is also changed.
60 #define LPFC_REG_WRITE_KEY_SIZE 4
61 #define LPFC_REG_WRITE_KEY "EMLX"
63 /**
64 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
65 * @incr: integer to convert.
66 * @hdw: ascii string holding converted integer plus a string terminator.
68 * Description:
69 * JEDEC Joint Electron Device Engineering Council.
70 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
71 * character string. The string is then terminated with a NULL in byte 9.
72 * Hex 0-9 becomes ascii '0' to '9'.
73 * Hex a-f becomes ascii '=' to 'B' capital B.
75 * Notes:
76 * Coded for 32 bit integers only.
77 **/
78 static void
79 lpfc_jedec_to_ascii(int incr, char hdw[])
81 int i, j;
82 for (i = 0; i < 8; i++) {
83 j = (incr & 0xf);
84 if (j <= 9)
85 hdw[7 - i] = 0x30 + j;
86 else
87 hdw[7 - i] = 0x61 + j - 10;
88 incr = (incr >> 4);
90 hdw[8] = 0;
91 return;
94 /**
95 * lpfc_drvr_version_show - Return the Emulex driver string with version number
96 * @dev: class unused variable.
97 * @attr: device attribute, not used.
98 * @buf: on return contains the module description text.
100 * Returns: size of formatted string.
102 static ssize_t
103 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
110 * lpfc_enable_fip_show - Return the fip mode of the HBA
111 * @dev: class unused variable.
112 * @attr: device attribute, not used.
113 * @buf: on return contains the module description text.
115 * Returns: size of formatted string.
117 static ssize_t
118 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
121 struct Scsi_Host *shost = class_to_shost(dev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
125 if (phba->hba_flag & HBA_FIP_SUPPORT)
126 return snprintf(buf, PAGE_SIZE, "1\n");
127 else
128 return snprintf(buf, PAGE_SIZE, "0\n");
131 static ssize_t
132 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
135 struct Scsi_Host *shost = class_to_shost(dev);
136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
137 struct lpfc_hba *phba = vport->phba;
139 if (phba->cfg_enable_bg)
140 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
141 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
142 else
143 return snprintf(buf, PAGE_SIZE,
144 "BlockGuard Not Supported\n");
145 else
146 return snprintf(buf, PAGE_SIZE,
147 "BlockGuard Disabled\n");
150 static ssize_t
151 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
154 struct Scsi_Host *shost = class_to_shost(dev);
155 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
156 struct lpfc_hba *phba = vport->phba;
158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
162 static ssize_t
163 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
166 struct Scsi_Host *shost = class_to_shost(dev);
167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
174 static ssize_t
175 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
178 struct Scsi_Host *shost = class_to_shost(dev);
179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
187 * lpfc_info_show - Return some pci info about the host in ascii
188 * @dev: class converted to a Scsi_host structure.
189 * @attr: device attribute, not used.
190 * @buf: on return contains the formatted text from lpfc_info().
192 * Returns: size of formatted string.
194 static ssize_t
195 lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
198 struct Scsi_Host *host = class_to_shost(dev);
200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
204 * lpfc_serialnum_show - Return the hba serial number in ascii
205 * @dev: class converted to a Scsi_host structure.
206 * @attr: device attribute, not used.
207 * @buf: on return contains the formatted text serial number.
209 * Returns: size of formatted string.
211 static ssize_t
212 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
215 struct Scsi_Host *shost = class_to_shost(dev);
216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
217 struct lpfc_hba *phba = vport->phba;
219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
223 * lpfc_temp_sensor_show - Return the temperature sensor level
224 * @dev: class converted to a Scsi_host structure.
225 * @attr: device attribute, not used.
226 * @buf: on return contains the formatted support level.
228 * Description:
229 * Returns a number indicating the temperature sensor level currently
230 * supported, zero or one in ascii.
232 * Returns: size of formatted string.
234 static ssize_t
235 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
238 struct Scsi_Host *shost = class_to_shost(dev);
239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240 struct lpfc_hba *phba = vport->phba;
241 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
245 * lpfc_modeldesc_show - Return the model description of the hba
246 * @dev: class converted to a Scsi_host structure.
247 * @attr: device attribute, not used.
248 * @buf: on return contains the scsi vpd model description.
250 * Returns: size of formatted string.
252 static ssize_t
253 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
256 struct Scsi_Host *shost = class_to_shost(dev);
257 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
258 struct lpfc_hba *phba = vport->phba;
260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
264 * lpfc_modelname_show - Return the model name of the hba
265 * @dev: class converted to a Scsi_host structure.
266 * @attr: device attribute, not used.
267 * @buf: on return contains the scsi vpd model name.
269 * Returns: size of formatted string.
271 static ssize_t
272 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
275 struct Scsi_Host *shost = class_to_shost(dev);
276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
277 struct lpfc_hba *phba = vport->phba;
279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
283 * lpfc_programtype_show - Return the program type of the hba
284 * @dev: class converted to a Scsi_host structure.
285 * @attr: device attribute, not used.
286 * @buf: on return contains the scsi vpd program type.
288 * Returns: size of formatted string.
290 static ssize_t
291 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
294 struct Scsi_Host *shost = class_to_shost(dev);
295 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
296 struct lpfc_hba *phba = vport->phba;
298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
302 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
303 * @dev: class converted to a Scsi_host structure.
304 * @attr: device attribute, not used.
305 * @buf: on return contains the Menlo Maintenance sli flag.
307 * Returns: size of formatted string.
309 static ssize_t
310 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
312 struct Scsi_Host *shost = class_to_shost(dev);
313 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
314 struct lpfc_hba *phba = vport->phba;
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
321 * lpfc_vportnum_show - Return the port number in ascii of the hba
322 * @dev: class converted to a Scsi_host structure.
323 * @attr: device attribute, not used.
324 * @buf: on return contains scsi vpd program type.
326 * Returns: size of formatted string.
328 static ssize_t
329 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
332 struct Scsi_Host *shost = class_to_shost(dev);
333 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
334 struct lpfc_hba *phba = vport->phba;
336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
340 * lpfc_fwrev_show - Return the firmware rev running in the hba
341 * @dev: class converted to a Scsi_host structure.
342 * @attr: device attribute, not used.
343 * @buf: on return contains the scsi vpd program type.
345 * Returns: size of formatted string.
347 static ssize_t
348 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
351 struct Scsi_Host *shost = class_to_shost(dev);
352 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
353 struct lpfc_hba *phba = vport->phba;
354 char fwrev[32];
356 lpfc_decode_firmware_rev(phba, fwrev, 1);
357 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
361 * lpfc_hdw_show - Return the jedec information about the hba
362 * @dev: class converted to a Scsi_host structure.
363 * @attr: device attribute, not used.
364 * @buf: on return contains the scsi vpd program type.
366 * Returns: size of formatted string.
368 static ssize_t
369 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
371 char hdw[9];
372 struct Scsi_Host *shost = class_to_shost(dev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
375 lpfc_vpd_t *vp = &phba->vpd;
377 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
378 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
382 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
383 * @dev: class converted to a Scsi_host structure.
384 * @attr: device attribute, not used.
385 * @buf: on return contains the ROM and FCode ascii strings.
387 * Returns: size of formatted string.
389 static ssize_t
390 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
391 char *buf)
393 struct Scsi_Host *shost = class_to_shost(dev);
394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
395 struct lpfc_hba *phba = vport->phba;
397 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
401 * lpfc_state_show - Return the link state of the port
402 * @dev: class converted to a Scsi_host structure.
403 * @attr: device attribute, not used.
404 * @buf: on return contains text describing the state of the link.
406 * Notes:
407 * The switch statement has no default so zero will be returned.
409 * Returns: size of formatted string.
411 static ssize_t
412 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
415 struct Scsi_Host *shost = class_to_shost(dev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
418 int len = 0;
420 switch (phba->link_state) {
421 case LPFC_LINK_UNKNOWN:
422 case LPFC_WARM_START:
423 case LPFC_INIT_START:
424 case LPFC_INIT_MBX_CMDS:
425 case LPFC_LINK_DOWN:
426 case LPFC_HBA_ERROR:
427 if (phba->hba_flag & LINK_DISABLED)
428 len += snprintf(buf + len, PAGE_SIZE-len,
429 "Link Down - User disabled\n");
430 else
431 len += snprintf(buf + len, PAGE_SIZE-len,
432 "Link Down\n");
433 break;
434 case LPFC_LINK_UP:
435 case LPFC_CLEAR_LA:
436 case LPFC_HBA_READY:
437 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
439 switch (vport->port_state) {
440 case LPFC_LOCAL_CFG_LINK:
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Configuring Link\n");
443 break;
444 case LPFC_FDISC:
445 case LPFC_FLOGI:
446 case LPFC_FABRIC_CFG_LINK:
447 case LPFC_NS_REG:
448 case LPFC_NS_QRY:
449 case LPFC_BUILD_DISC_LIST:
450 case LPFC_DISC_AUTH:
451 len += snprintf(buf + len, PAGE_SIZE - len,
452 "Discovery\n");
453 break;
454 case LPFC_VPORT_READY:
455 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
456 break;
458 case LPFC_VPORT_FAILED:
459 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
460 break;
462 case LPFC_VPORT_UNKNOWN:
463 len += snprintf(buf + len, PAGE_SIZE - len,
464 "Unknown\n");
465 break;
467 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
468 len += snprintf(buf + len, PAGE_SIZE-len,
469 " Menlo Maint Mode\n");
470 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
471 if (vport->fc_flag & FC_PUBLIC_LOOP)
472 len += snprintf(buf + len, PAGE_SIZE-len,
473 " Public Loop\n");
474 else
475 len += snprintf(buf + len, PAGE_SIZE-len,
476 " Private Loop\n");
477 } else {
478 if (vport->fc_flag & FC_FABRIC)
479 len += snprintf(buf + len, PAGE_SIZE-len,
480 " Fabric\n");
481 else
482 len += snprintf(buf + len, PAGE_SIZE-len,
483 " Point-2-Point\n");
487 return len;
491 * lpfc_link_state_store - Transition the link_state on an HBA port
492 * @dev: class device that is converted into a Scsi_host.
493 * @attr: device attribute, not used.
494 * @buf: one or more lpfc_polling_flags values.
495 * @count: not used.
497 * Returns:
498 * -EINVAL if the buffer is not "up" or "down"
499 * return from link state change function if non-zero
500 * length of the buf on success
502 static ssize_t
503 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
504 const char *buf, size_t count)
506 struct Scsi_Host *shost = class_to_shost(dev);
507 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
508 struct lpfc_hba *phba = vport->phba;
510 int status = -EINVAL;
512 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
513 (phba->link_state == LPFC_LINK_DOWN))
514 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
515 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
516 (phba->link_state >= LPFC_LINK_UP))
517 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
519 if (status == 0)
520 return strlen(buf);
521 else
522 return status;
526 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
527 * @dev: class device that is converted into a Scsi_host.
528 * @attr: device attribute, not used.
529 * @buf: on return contains the sum of fc mapped and unmapped.
531 * Description:
532 * Returns the ascii text number of the sum of the fc mapped and unmapped
533 * vport counts.
535 * Returns: size of formatted string.
537 static ssize_t
538 lpfc_num_discovered_ports_show(struct device *dev,
539 struct device_attribute *attr, char *buf)
541 struct Scsi_Host *shost = class_to_shost(dev);
542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
544 return snprintf(buf, PAGE_SIZE, "%d\n",
545 vport->fc_map_cnt + vport->fc_unmap_cnt);
549 * lpfc_issue_lip - Misnomer, name carried over from long ago
550 * @shost: Scsi_Host pointer.
552 * Description:
553 * Bring the link down gracefully then re-init the link. The firmware will
554 * re-init the fiber channel interface as required. Does not issue a LIP.
556 * Returns:
557 * -EPERM port offline or management commands are being blocked
558 * -ENOMEM cannot allocate memory for the mailbox command
559 * -EIO error sending the mailbox command
560 * zero for success
562 static int
563 lpfc_issue_lip(struct Scsi_Host *shost)
565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
566 struct lpfc_hba *phba = vport->phba;
567 LPFC_MBOXQ_t *pmboxq;
568 int mbxstatus = MBXERR_ERROR;
570 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
571 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
572 return -EPERM;
574 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
576 if (!pmboxq)
577 return -ENOMEM;
579 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
580 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
581 pmboxq->u.mb.mbxOwner = OWN_HOST;
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == 0 ||
587 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
588 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
589 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
590 phba->cfg_link_speed);
591 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
592 phba->fc_ratov * 2);
593 if ((mbxstatus == MBX_SUCCESS) &&
594 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
595 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
596 "2859 SLI authentication is required "
597 "for INIT_LINK but has not done yet\n");
600 lpfc_set_loopback_flag(phba);
601 if (mbxstatus != MBX_TIMEOUT)
602 mempool_free(pmboxq, phba->mbox_mem_pool);
604 if (mbxstatus == MBXERR_ERROR)
605 return -EIO;
607 return 0;
611 * lpfc_do_offline - Issues a mailbox command to bring the link down
612 * @phba: lpfc_hba pointer.
613 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
615 * Notes:
616 * Assumes any error from lpfc_do_offline() will be negative.
617 * Can wait up to 5 seconds for the port ring buffers count
618 * to reach zero, prints a warning if it is not zero and continues.
619 * lpfc_workq_post_event() returns a non-zero return code if call fails.
621 * Returns:
622 * -EIO error posting the event
623 * zero for success
625 static int
626 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
628 struct completion online_compl;
629 struct lpfc_sli_ring *pring;
630 struct lpfc_sli *psli;
631 int status = 0;
632 int cnt = 0;
633 int i;
634 int rc;
636 init_completion(&online_compl);
637 rc = lpfc_workq_post_event(phba, &status, &online_compl,
638 LPFC_EVT_OFFLINE_PREP);
639 if (rc == 0)
640 return -ENOMEM;
642 wait_for_completion(&online_compl);
644 if (status != 0)
645 return -EIO;
647 psli = &phba->sli;
649 /* Wait a little for things to settle down, but not
650 * long enough for dev loss timeout to expire.
652 for (i = 0; i < psli->num_rings; i++) {
653 pring = &psli->ring[i];
654 while (pring->txcmplq_cnt) {
655 msleep(10);
656 if (cnt++ > 500) { /* 5 secs */
657 lpfc_printf_log(phba,
658 KERN_WARNING, LOG_INIT,
659 "0466 Outstanding IO when "
660 "bringing Adapter offline\n");
661 break;
666 init_completion(&online_compl);
667 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
668 if (rc == 0)
669 return -ENOMEM;
671 wait_for_completion(&online_compl);
673 if (status != 0)
674 return -EIO;
676 return 0;
680 * lpfc_selective_reset - Offline then onlines the port
681 * @phba: lpfc_hba pointer.
683 * Description:
684 * If the port is configured to allow a reset then the hba is brought
685 * offline then online.
687 * Notes:
688 * Assumes any error from lpfc_do_offline() will be negative.
689 * Do not make this function static.
691 * Returns:
692 * lpfc_do_offline() return code if not zero
693 * -EIO reset not configured or error posting the event
694 * zero for success
697 lpfc_selective_reset(struct lpfc_hba *phba)
699 struct completion online_compl;
700 int status = 0;
701 int rc;
703 if (!phba->cfg_enable_hba_reset)
704 return -EACCES;
706 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
708 if (status != 0)
709 return status;
711 init_completion(&online_compl);
712 rc = lpfc_workq_post_event(phba, &status, &online_compl,
713 LPFC_EVT_ONLINE);
714 if (rc == 0)
715 return -ENOMEM;
717 wait_for_completion(&online_compl);
719 if (status != 0)
720 return -EIO;
722 return 0;
726 * lpfc_issue_reset - Selectively resets an adapter
727 * @dev: class device that is converted into a Scsi_host.
728 * @attr: device attribute, not used.
729 * @buf: containing the string "selective".
730 * @count: unused variable.
732 * Description:
733 * If the buf contains the string "selective" then lpfc_selective_reset()
734 * is called to perform the reset.
736 * Notes:
737 * Assumes any error from lpfc_selective_reset() will be negative.
738 * If lpfc_selective_reset() returns zero then the length of the buffer
739 * is returned which indicates success
741 * Returns:
742 * -EINVAL if the buffer does not contain the string "selective"
743 * length of buf if lpfc-selective_reset() if the call succeeds
744 * return value of lpfc_selective_reset() if the call fails
746 static ssize_t
747 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
748 const char *buf, size_t count)
750 struct Scsi_Host *shost = class_to_shost(dev);
751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
752 struct lpfc_hba *phba = vport->phba;
754 int status = -EINVAL;
756 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
757 status = phba->lpfc_selective_reset(phba);
759 if (status == 0)
760 return strlen(buf);
761 else
762 return status;
766 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
767 * @phba: lpfc_hba pointer.
769 * Description:
770 * SLI4 interface type-2 device to wait on the sliport status register for
771 * the readyness after performing a firmware reset.
773 * Returns:
774 * zero for success
776 static int
777 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
779 struct lpfc_register portstat_reg = {0};
780 int i;
782 msleep(100);
783 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
784 &portstat_reg.word0);
786 /* verify if privilaged for the request operation */
787 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
788 !bf_get(lpfc_sliport_status_err, &portstat_reg))
789 return -EPERM;
791 /* wait for the SLI port firmware ready after firmware reset */
792 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
793 msleep(10);
794 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
795 &portstat_reg.word0);
796 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
797 continue;
798 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
799 continue;
800 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
801 continue;
802 break;
805 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
806 return 0;
807 else
808 return -EIO;
812 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
813 * @phba: lpfc_hba pointer.
815 * Description:
816 * Request SLI4 interface type-2 device to perform a physical register set
817 * access.
819 * Returns:
820 * zero for success
822 static ssize_t
823 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
825 struct completion online_compl;
826 struct pci_dev *pdev = phba->pcidev;
827 uint32_t reg_val;
828 int status = 0;
829 int rc;
831 if (!phba->cfg_enable_hba_reset)
832 return -EACCES;
834 if ((phba->sli_rev < LPFC_SLI_REV4) ||
835 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
836 LPFC_SLI_INTF_IF_TYPE_2))
837 return -EPERM;
839 /* Disable SR-IOV virtual functions if enabled */
840 if (phba->cfg_sriov_nr_virtfn) {
841 pci_disable_sriov(pdev);
842 phba->cfg_sriov_nr_virtfn = 0;
844 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
846 if (status != 0)
847 return status;
849 /* wait for the device to be quiesced before firmware reset */
850 msleep(100);
852 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
853 LPFC_CTL_PDEV_CTL_OFFSET);
855 if (opcode == LPFC_FW_DUMP)
856 reg_val |= LPFC_FW_DUMP_REQUEST;
857 else if (opcode == LPFC_FW_RESET)
858 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
859 else if (opcode == LPFC_DV_RESET)
860 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
862 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
863 LPFC_CTL_PDEV_CTL_OFFSET);
864 /* flush */
865 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
867 /* delay driver action following IF_TYPE_2 reset */
868 rc = lpfc_sli4_pdev_status_reg_wait(phba);
870 if (rc)
871 return rc;
873 init_completion(&online_compl);
874 rc = lpfc_workq_post_event(phba, &status, &online_compl,
875 LPFC_EVT_ONLINE);
876 if (rc == 0)
877 return -ENOMEM;
879 wait_for_completion(&online_compl);
881 if (status != 0)
882 return -EIO;
884 return 0;
888 * lpfc_nport_evt_cnt_show - Return the number of nport events
889 * @dev: class device that is converted into a Scsi_host.
890 * @attr: device attribute, not used.
891 * @buf: on return contains the ascii number of nport events.
893 * Returns: size of formatted string.
895 static ssize_t
896 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
897 char *buf)
899 struct Scsi_Host *shost = class_to_shost(dev);
900 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
901 struct lpfc_hba *phba = vport->phba;
903 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
907 * lpfc_board_mode_show - Return the state of the board
908 * @dev: class device that is converted into a Scsi_host.
909 * @attr: device attribute, not used.
910 * @buf: on return contains the state of the adapter.
912 * Returns: size of formatted string.
914 static ssize_t
915 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
916 char *buf)
918 struct Scsi_Host *shost = class_to_shost(dev);
919 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
920 struct lpfc_hba *phba = vport->phba;
921 char * state;
923 if (phba->link_state == LPFC_HBA_ERROR)
924 state = "error";
925 else if (phba->link_state == LPFC_WARM_START)
926 state = "warm start";
927 else if (phba->link_state == LPFC_INIT_START)
928 state = "offline";
929 else
930 state = "online";
932 return snprintf(buf, PAGE_SIZE, "%s\n", state);
936 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
937 * @dev: class device that is converted into a Scsi_host.
938 * @attr: device attribute, not used.
939 * @buf: containing one of the strings "online", "offline", "warm" or "error".
940 * @count: unused variable.
942 * Returns:
943 * -EACCES if enable hba reset not enabled
944 * -EINVAL if the buffer does not contain a valid string (see above)
945 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
946 * buf length greater than zero indicates success
948 static ssize_t
949 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
950 const char *buf, size_t count)
952 struct Scsi_Host *shost = class_to_shost(dev);
953 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
954 struct lpfc_hba *phba = vport->phba;
955 struct completion online_compl;
956 int status=0;
957 int rc;
959 if (!phba->cfg_enable_hba_reset)
960 return -EACCES;
962 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
963 "3050 lpfc_board_mode set to %s\n", buf);
965 init_completion(&online_compl);
967 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
968 rc = lpfc_workq_post_event(phba, &status, &online_compl,
969 LPFC_EVT_ONLINE);
970 if (rc == 0)
971 return -ENOMEM;
972 wait_for_completion(&online_compl);
973 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
974 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
975 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
976 if (phba->sli_rev == LPFC_SLI_REV4)
977 return -EINVAL;
978 else
979 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
980 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
981 if (phba->sli_rev == LPFC_SLI_REV4)
982 return -EINVAL;
983 else
984 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
985 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
986 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
987 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
988 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
989 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
990 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
991 else
992 return -EINVAL;
994 if (!status)
995 return strlen(buf);
996 else
997 return status;
1001 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1002 * @phba: pointer to the adapter structure.
1003 * @mxri: max xri count.
1004 * @axri: available xri count.
1005 * @mrpi: max rpi count.
1006 * @arpi: available rpi count.
1007 * @mvpi: max vpi count.
1008 * @avpi: available vpi count.
1010 * Description:
1011 * If an integer pointer for an count is not null then the value for the
1012 * count is returned.
1014 * Returns:
1015 * zero on error
1016 * one for success
1018 static int
1019 lpfc_get_hba_info(struct lpfc_hba *phba,
1020 uint32_t *mxri, uint32_t *axri,
1021 uint32_t *mrpi, uint32_t *arpi,
1022 uint32_t *mvpi, uint32_t *avpi)
1024 struct lpfc_mbx_read_config *rd_config;
1025 LPFC_MBOXQ_t *pmboxq;
1026 MAILBOX_t *pmb;
1027 int rc = 0;
1028 uint32_t max_vpi;
1031 * prevent udev from issuing mailbox commands until the port is
1032 * configured.
1034 if (phba->link_state < LPFC_LINK_DOWN ||
1035 !phba->mbox_mem_pool ||
1036 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1037 return 0;
1039 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1040 return 0;
1042 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1043 if (!pmboxq)
1044 return 0;
1045 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1047 pmb = &pmboxq->u.mb;
1048 pmb->mbxCommand = MBX_READ_CONFIG;
1049 pmb->mbxOwner = OWN_HOST;
1050 pmboxq->context1 = NULL;
1052 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1053 rc = MBX_NOT_FINISHED;
1054 else
1055 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1057 if (rc != MBX_SUCCESS) {
1058 if (rc != MBX_TIMEOUT)
1059 mempool_free(pmboxq, phba->mbox_mem_pool);
1060 return 0;
1063 if (phba->sli_rev == LPFC_SLI_REV4) {
1064 rd_config = &pmboxq->u.mqe.un.rd_config;
1065 if (mrpi)
1066 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1067 if (arpi)
1068 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1069 phba->sli4_hba.max_cfg_param.rpi_used;
1070 if (mxri)
1071 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1072 if (axri)
1073 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1074 phba->sli4_hba.max_cfg_param.xri_used;
1076 /* Account for differences with SLI-3. Get vpi count from
1077 * mailbox data and subtract one for max vpi value.
1079 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1080 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1082 if (mvpi)
1083 *mvpi = max_vpi;
1084 if (avpi)
1085 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1086 } else {
1087 if (mrpi)
1088 *mrpi = pmb->un.varRdConfig.max_rpi;
1089 if (arpi)
1090 *arpi = pmb->un.varRdConfig.avail_rpi;
1091 if (mxri)
1092 *mxri = pmb->un.varRdConfig.max_xri;
1093 if (axri)
1094 *axri = pmb->un.varRdConfig.avail_xri;
1095 if (mvpi)
1096 *mvpi = pmb->un.varRdConfig.max_vpi;
1097 if (avpi)
1098 *avpi = pmb->un.varRdConfig.avail_vpi;
1101 mempool_free(pmboxq, phba->mbox_mem_pool);
1102 return 1;
1106 * lpfc_max_rpi_show - Return maximum rpi
1107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1111 * Description:
1112 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1117 * Returns: size of formatted string.
1119 static ssize_t
1120 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1121 char *buf)
1123 struct Scsi_Host *shost = class_to_shost(dev);
1124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1125 struct lpfc_hba *phba = vport->phba;
1126 uint32_t cnt;
1128 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1129 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1130 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1134 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: containing the used rpi count in decimal or "Unknown".
1139 * Description:
1140 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1141 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1142 * to "Unknown" and the buffer length is returned, therefore the caller
1143 * must check for "Unknown" in the buffer to detect a failure.
1145 * Returns: size of formatted string.
1147 static ssize_t
1148 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1149 char *buf)
1151 struct Scsi_Host *shost = class_to_shost(dev);
1152 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1153 struct lpfc_hba *phba = vport->phba;
1154 uint32_t cnt, acnt;
1156 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1157 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1158 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1162 * lpfc_max_xri_show - Return maximum xri
1163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1167 * Description:
1168 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1169 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1170 * to "Unknown" and the buffer length is returned, therefore the caller
1171 * must check for "Unknown" in the buffer to detect a failure.
1173 * Returns: size of formatted string.
1175 static ssize_t
1176 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1177 char *buf)
1179 struct Scsi_Host *shost = class_to_shost(dev);
1180 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1181 struct lpfc_hba *phba = vport->phba;
1182 uint32_t cnt;
1184 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1185 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1186 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1190 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1191 * @dev: class device that is converted into a Scsi_host.
1192 * @attr: device attribute, not used.
1193 * @buf: on return contains the used xri count in decimal or "Unknown".
1195 * Description:
1196 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1197 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1198 * to "Unknown" and the buffer length is returned, therefore the caller
1199 * must check for "Unknown" in the buffer to detect a failure.
1201 * Returns: size of formatted string.
1203 static ssize_t
1204 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1205 char *buf)
1207 struct Scsi_Host *shost = class_to_shost(dev);
1208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1209 struct lpfc_hba *phba = vport->phba;
1210 uint32_t cnt, acnt;
1212 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1213 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1214 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1218 * lpfc_max_vpi_show - Return maximum vpi
1219 * @dev: class device that is converted into a Scsi_host.
1220 * @attr: device attribute, not used.
1221 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1223 * Description:
1224 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1225 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1226 * to "Unknown" and the buffer length is returned, therefore the caller
1227 * must check for "Unknown" in the buffer to detect a failure.
1229 * Returns: size of formatted string.
1231 static ssize_t
1232 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1233 char *buf)
1235 struct Scsi_Host *shost = class_to_shost(dev);
1236 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1237 struct lpfc_hba *phba = vport->phba;
1238 uint32_t cnt;
1240 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1241 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1242 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1246 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1247 * @dev: class device that is converted into a Scsi_host.
1248 * @attr: device attribute, not used.
1249 * @buf: on return contains the used vpi count in decimal or "Unknown".
1251 * Description:
1252 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1253 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1254 * to "Unknown" and the buffer length is returned, therefore the caller
1255 * must check for "Unknown" in the buffer to detect a failure.
1257 * Returns: size of formatted string.
1259 static ssize_t
1260 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1261 char *buf)
1263 struct Scsi_Host *shost = class_to_shost(dev);
1264 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1265 struct lpfc_hba *phba = vport->phba;
1266 uint32_t cnt, acnt;
1268 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1269 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1270 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1274 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1275 * @dev: class device that is converted into a Scsi_host.
1276 * @attr: device attribute, not used.
1277 * @buf: text that must be interpreted to determine if npiv is supported.
1279 * Description:
1280 * Buffer will contain text indicating npiv is not suppoerted on the port,
1281 * the port is an NPIV physical port, or it is an npiv virtual port with
1282 * the id of the vport.
1284 * Returns: size of formatted string.
1286 static ssize_t
1287 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1288 char *buf)
1290 struct Scsi_Host *shost = class_to_shost(dev);
1291 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1292 struct lpfc_hba *phba = vport->phba;
1294 if (!(phba->max_vpi))
1295 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1296 if (vport->port_type == LPFC_PHYSICAL_PORT)
1297 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1298 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1302 * lpfc_poll_show - Return text about poll support for the adapter
1303 * @dev: class device that is converted into a Scsi_host.
1304 * @attr: device attribute, not used.
1305 * @buf: on return contains the cfg_poll in hex.
1307 * Notes:
1308 * cfg_poll should be a lpfc_polling_flags type.
1310 * Returns: size of formatted string.
1312 static ssize_t
1313 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1314 char *buf)
1316 struct Scsi_Host *shost = class_to_shost(dev);
1317 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1318 struct lpfc_hba *phba = vport->phba;
1320 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1324 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1325 * @dev: class device that is converted into a Scsi_host.
1326 * @attr: device attribute, not used.
1327 * @buf: one or more lpfc_polling_flags values.
1328 * @count: not used.
1330 * Notes:
1331 * buf contents converted to integer and checked for a valid value.
1333 * Returns:
1334 * -EINVAL if the buffer connot be converted or is out of range
1335 * length of the buf on success
1337 static ssize_t
1338 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1339 const char *buf, size_t count)
1341 struct Scsi_Host *shost = class_to_shost(dev);
1342 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1343 struct lpfc_hba *phba = vport->phba;
1344 uint32_t creg_val;
1345 uint32_t old_val;
1346 int val=0;
1348 if (!isdigit(buf[0]))
1349 return -EINVAL;
1351 if (sscanf(buf, "%i", &val) != 1)
1352 return -EINVAL;
1354 if ((val & 0x3) != val)
1355 return -EINVAL;
1357 if (phba->sli_rev == LPFC_SLI_REV4)
1358 val = 0;
1360 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1361 "3051 lpfc_poll changed from %d to %d\n",
1362 phba->cfg_poll, val);
1364 spin_lock_irq(&phba->hbalock);
1366 old_val = phba->cfg_poll;
1368 if (val & ENABLE_FCP_RING_POLLING) {
1369 if ((val & DISABLE_FCP_RING_INT) &&
1370 !(old_val & DISABLE_FCP_RING_INT)) {
1371 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1372 spin_unlock_irq(&phba->hbalock);
1373 return -EINVAL;
1375 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1376 writel(creg_val, phba->HCregaddr);
1377 readl(phba->HCregaddr); /* flush */
1379 lpfc_poll_start_timer(phba);
1381 } else if (val != 0x0) {
1382 spin_unlock_irq(&phba->hbalock);
1383 return -EINVAL;
1386 if (!(val & DISABLE_FCP_RING_INT) &&
1387 (old_val & DISABLE_FCP_RING_INT))
1389 spin_unlock_irq(&phba->hbalock);
1390 del_timer(&phba->fcp_poll_timer);
1391 spin_lock_irq(&phba->hbalock);
1392 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1393 spin_unlock_irq(&phba->hbalock);
1394 return -EINVAL;
1396 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1397 writel(creg_val, phba->HCregaddr);
1398 readl(phba->HCregaddr); /* flush */
1401 phba->cfg_poll = val;
1403 spin_unlock_irq(&phba->hbalock);
1405 return strlen(buf);
1409 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1410 * @dev: class unused variable.
1411 * @attr: device attribute, not used.
1412 * @buf: on return contains the module description text.
1414 * Returns: size of formatted string.
1416 static ssize_t
1417 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1418 char *buf)
1420 struct Scsi_Host *shost = class_to_shost(dev);
1421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1422 struct lpfc_hba *phba = vport->phba;
1424 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1428 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1429 * @dev: class unused variable.
1430 * @attr: device attribute, not used.
1431 * @buf: on return contains the module description text.
1433 * Returns: size of formatted string.
1435 static ssize_t
1436 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1437 char *buf)
1439 struct Scsi_Host *shost = class_to_shost(dev);
1440 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1441 struct lpfc_hba *phba = vport->phba;
1443 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1447 * lpfc_dss_show - Return the current state of dss and the configured state
1448 * @dev: class converted to a Scsi_host structure.
1449 * @attr: device attribute, not used.
1450 * @buf: on return contains the formatted text.
1452 * Returns: size of formatted string.
1454 static ssize_t
1455 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1456 char *buf)
1458 struct Scsi_Host *shost = class_to_shost(dev);
1459 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1460 struct lpfc_hba *phba = vport->phba;
1462 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1463 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1464 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1465 "" : "Not ");
1469 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1470 * @dev: class converted to a Scsi_host structure.
1471 * @attr: device attribute, not used.
1472 * @buf: on return contains the formatted support level.
1474 * Description:
1475 * Returns the maximum number of virtual functions a physical function can
1476 * support, 0 will be returned if called on virtual function.
1478 * Returns: size of formatted string.
1480 static ssize_t
1481 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1482 struct device_attribute *attr,
1483 char *buf)
1485 struct Scsi_Host *shost = class_to_shost(dev);
1486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1487 struct lpfc_hba *phba = vport->phba;
1488 uint16_t max_nr_virtfn;
1490 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1491 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1495 * lpfc_param_show - Return a cfg attribute value in decimal
1497 * Description:
1498 * Macro that given an attr e.g. hba_queue_depth expands
1499 * into a function with the name lpfc_hba_queue_depth_show.
1501 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1502 * @dev: class device that is converted into a Scsi_host.
1503 * @attr: device attribute, not used.
1504 * @buf: on return contains the attribute value in decimal.
1506 * Returns: size of formatted string.
1508 #define lpfc_param_show(attr) \
1509 static ssize_t \
1510 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1511 char *buf) \
1513 struct Scsi_Host *shost = class_to_shost(dev);\
1514 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1515 struct lpfc_hba *phba = vport->phba;\
1516 uint val = 0;\
1517 val = phba->cfg_##attr;\
1518 return snprintf(buf, PAGE_SIZE, "%d\n",\
1519 phba->cfg_##attr);\
1523 * lpfc_param_hex_show - Return a cfg attribute value in hex
1525 * Description:
1526 * Macro that given an attr e.g. hba_queue_depth expands
1527 * into a function with the name lpfc_hba_queue_depth_show
1529 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1530 * @dev: class device that is converted into a Scsi_host.
1531 * @attr: device attribute, not used.
1532 * @buf: on return contains the attribute value in hexadecimal.
1534 * Returns: size of formatted string.
1536 #define lpfc_param_hex_show(attr) \
1537 static ssize_t \
1538 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1539 char *buf) \
1541 struct Scsi_Host *shost = class_to_shost(dev);\
1542 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1543 struct lpfc_hba *phba = vport->phba;\
1544 uint val = 0;\
1545 val = phba->cfg_##attr;\
1546 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1547 phba->cfg_##attr);\
1551 * lpfc_param_init - Initializes a cfg attribute
1553 * Description:
1554 * Macro that given an attr e.g. hba_queue_depth expands
1555 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1556 * takes a default argument, a minimum and maximum argument.
1558 * lpfc_##attr##_init: Initializes an attribute.
1559 * @phba: pointer the the adapter structure.
1560 * @val: integer attribute value.
1562 * Validates the min and max values then sets the adapter config field
1563 * accordingly, or uses the default if out of range and prints an error message.
1565 * Returns:
1566 * zero on success
1567 * -EINVAL if default used
1569 #define lpfc_param_init(attr, default, minval, maxval) \
1570 static int \
1571 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1573 if (val >= minval && val <= maxval) {\
1574 phba->cfg_##attr = val;\
1575 return 0;\
1577 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1578 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1579 "allowed range is ["#minval", "#maxval"]\n", val); \
1580 phba->cfg_##attr = default;\
1581 return -EINVAL;\
1585 * lpfc_param_set - Set a cfg attribute value
1587 * Description:
1588 * Macro that given an attr e.g. hba_queue_depth expands
1589 * into a function with the name lpfc_hba_queue_depth_set
1591 * lpfc_##attr##_set: Sets an attribute value.
1592 * @phba: pointer the the adapter structure.
1593 * @val: integer attribute value.
1595 * Description:
1596 * Validates the min and max values then sets the
1597 * adapter config field if in the valid range. prints error message
1598 * and does not set the parameter if invalid.
1600 * Returns:
1601 * zero on success
1602 * -EINVAL if val is invalid
1604 #define lpfc_param_set(attr, default, minval, maxval) \
1605 static int \
1606 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1608 if (val >= minval && val <= maxval) {\
1609 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1610 "3052 lpfc_" #attr " changed from %d to %d\n", \
1611 phba->cfg_##attr, val); \
1612 phba->cfg_##attr = val;\
1613 return 0;\
1615 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1616 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1617 "allowed range is ["#minval", "#maxval"]\n", val); \
1618 return -EINVAL;\
1622 * lpfc_param_store - Set a vport attribute value
1624 * Description:
1625 * Macro that given an attr e.g. hba_queue_depth expands
1626 * into a function with the name lpfc_hba_queue_depth_store.
1628 * lpfc_##attr##_store: Set an sttribute value.
1629 * @dev: class device that is converted into a Scsi_host.
1630 * @attr: device attribute, not used.
1631 * @buf: contains the attribute value in ascii.
1632 * @count: not used.
1634 * Description:
1635 * Convert the ascii text number to an integer, then
1636 * use the lpfc_##attr##_set function to set the value.
1638 * Returns:
1639 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1640 * length of buffer upon success.
1642 #define lpfc_param_store(attr) \
1643 static ssize_t \
1644 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1645 const char *buf, size_t count) \
1647 struct Scsi_Host *shost = class_to_shost(dev);\
1648 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1649 struct lpfc_hba *phba = vport->phba;\
1650 uint val = 0;\
1651 if (!isdigit(buf[0]))\
1652 return -EINVAL;\
1653 if (sscanf(buf, "%i", &val) != 1)\
1654 return -EINVAL;\
1655 if (lpfc_##attr##_set(phba, val) == 0) \
1656 return strlen(buf);\
1657 else \
1658 return -EINVAL;\
1662 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1664 * Description:
1665 * Macro that given an attr e.g. hba_queue_depth expands
1666 * into a function with the name lpfc_hba_queue_depth_show
1668 * lpfc_##attr##_show: prints the attribute value in decimal.
1669 * @dev: class device that is converted into a Scsi_host.
1670 * @attr: device attribute, not used.
1671 * @buf: on return contains the attribute value in decimal.
1673 * Returns: length of formatted string.
1675 #define lpfc_vport_param_show(attr) \
1676 static ssize_t \
1677 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1678 char *buf) \
1680 struct Scsi_Host *shost = class_to_shost(dev);\
1681 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1682 uint val = 0;\
1683 val = vport->cfg_##attr;\
1684 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1688 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1690 * Description:
1691 * Macro that given an attr e.g.
1692 * hba_queue_depth expands into a function with the name
1693 * lpfc_hba_queue_depth_show
1695 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1696 * @dev: class device that is converted into a Scsi_host.
1697 * @attr: device attribute, not used.
1698 * @buf: on return contains the attribute value in hexadecimal.
1700 * Returns: length of formatted string.
1702 #define lpfc_vport_param_hex_show(attr) \
1703 static ssize_t \
1704 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1705 char *buf) \
1707 struct Scsi_Host *shost = class_to_shost(dev);\
1708 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1709 uint val = 0;\
1710 val = vport->cfg_##attr;\
1711 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1715 * lpfc_vport_param_init - Initialize a vport cfg attribute
1717 * Description:
1718 * Macro that given an attr e.g. hba_queue_depth expands
1719 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1720 * takes a default argument, a minimum and maximum argument.
1722 * lpfc_##attr##_init: validates the min and max values then sets the
1723 * adapter config field accordingly, or uses the default if out of range
1724 * and prints an error message.
1725 * @phba: pointer the the adapter structure.
1726 * @val: integer attribute value.
1728 * Returns:
1729 * zero on success
1730 * -EINVAL if default used
1732 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1733 static int \
1734 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1736 if (val >= minval && val <= maxval) {\
1737 vport->cfg_##attr = val;\
1738 return 0;\
1740 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1741 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1742 "allowed range is ["#minval", "#maxval"]\n", val); \
1743 vport->cfg_##attr = default;\
1744 return -EINVAL;\
1748 * lpfc_vport_param_set - Set a vport cfg attribute
1750 * Description:
1751 * Macro that given an attr e.g. hba_queue_depth expands
1752 * into a function with the name lpfc_hba_queue_depth_set
1754 * lpfc_##attr##_set: validates the min and max values then sets the
1755 * adapter config field if in the valid range. prints error message
1756 * and does not set the parameter if invalid.
1757 * @phba: pointer the the adapter structure.
1758 * @val: integer attribute value.
1760 * Returns:
1761 * zero on success
1762 * -EINVAL if val is invalid
1764 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1765 static int \
1766 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1768 if (val >= minval && val <= maxval) {\
1769 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1770 "3053 lpfc_" #attr " changed from %d to %d\n", \
1771 vport->cfg_##attr, val); \
1772 vport->cfg_##attr = val;\
1773 return 0;\
1775 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1776 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1777 "allowed range is ["#minval", "#maxval"]\n", val); \
1778 return -EINVAL;\
1782 * lpfc_vport_param_store - Set a vport attribute
1784 * Description:
1785 * Macro that given an attr e.g. hba_queue_depth
1786 * expands into a function with the name lpfc_hba_queue_depth_store
1788 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1789 * use the lpfc_##attr##_set function to set the value.
1790 * @cdev: class device that is converted into a Scsi_host.
1791 * @buf: contains the attribute value in decimal.
1792 * @count: not used.
1794 * Returns:
1795 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1796 * length of buffer upon success.
1798 #define lpfc_vport_param_store(attr) \
1799 static ssize_t \
1800 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1801 const char *buf, size_t count) \
1803 struct Scsi_Host *shost = class_to_shost(dev);\
1804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1805 uint val = 0;\
1806 if (!isdigit(buf[0]))\
1807 return -EINVAL;\
1808 if (sscanf(buf, "%i", &val) != 1)\
1809 return -EINVAL;\
1810 if (lpfc_##attr##_set(vport, val) == 0) \
1811 return strlen(buf);\
1812 else \
1813 return -EINVAL;\
1817 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1818 static uint lpfc_##name = defval;\
1819 module_param(lpfc_##name, uint, S_IRUGO);\
1820 MODULE_PARM_DESC(lpfc_##name, desc);\
1821 lpfc_param_init(name, defval, minval, maxval)
1823 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1824 static uint lpfc_##name = defval;\
1825 module_param(lpfc_##name, uint, S_IRUGO);\
1826 MODULE_PARM_DESC(lpfc_##name, desc);\
1827 lpfc_param_show(name)\
1828 lpfc_param_init(name, defval, minval, maxval)\
1829 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1831 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1832 static uint lpfc_##name = defval;\
1833 module_param(lpfc_##name, uint, S_IRUGO);\
1834 MODULE_PARM_DESC(lpfc_##name, desc);\
1835 lpfc_param_show(name)\
1836 lpfc_param_init(name, defval, minval, maxval)\
1837 lpfc_param_set(name, defval, minval, maxval)\
1838 lpfc_param_store(name)\
1839 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1840 lpfc_##name##_show, lpfc_##name##_store)
1842 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1843 static uint lpfc_##name = defval;\
1844 module_param(lpfc_##name, uint, S_IRUGO);\
1845 MODULE_PARM_DESC(lpfc_##name, desc);\
1846 lpfc_param_hex_show(name)\
1847 lpfc_param_init(name, defval, minval, maxval)\
1848 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1850 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1851 static uint lpfc_##name = defval;\
1852 module_param(lpfc_##name, uint, S_IRUGO);\
1853 MODULE_PARM_DESC(lpfc_##name, desc);\
1854 lpfc_param_hex_show(name)\
1855 lpfc_param_init(name, defval, minval, maxval)\
1856 lpfc_param_set(name, defval, minval, maxval)\
1857 lpfc_param_store(name)\
1858 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1859 lpfc_##name##_show, lpfc_##name##_store)
1861 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1862 static uint lpfc_##name = defval;\
1863 module_param(lpfc_##name, uint, S_IRUGO);\
1864 MODULE_PARM_DESC(lpfc_##name, desc);\
1865 lpfc_vport_param_init(name, defval, minval, maxval)
1867 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1868 static uint lpfc_##name = defval;\
1869 module_param(lpfc_##name, uint, S_IRUGO);\
1870 MODULE_PARM_DESC(lpfc_##name, desc);\
1871 lpfc_vport_param_show(name)\
1872 lpfc_vport_param_init(name, defval, minval, maxval)\
1873 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1875 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1876 static uint lpfc_##name = defval;\
1877 module_param(lpfc_##name, uint, S_IRUGO);\
1878 MODULE_PARM_DESC(lpfc_##name, desc);\
1879 lpfc_vport_param_show(name)\
1880 lpfc_vport_param_init(name, defval, minval, maxval)\
1881 lpfc_vport_param_set(name, defval, minval, maxval)\
1882 lpfc_vport_param_store(name)\
1883 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1884 lpfc_##name##_show, lpfc_##name##_store)
1886 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1887 static uint lpfc_##name = defval;\
1888 module_param(lpfc_##name, uint, S_IRUGO);\
1889 MODULE_PARM_DESC(lpfc_##name, desc);\
1890 lpfc_vport_param_hex_show(name)\
1891 lpfc_vport_param_init(name, defval, minval, maxval)\
1892 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1894 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1895 static uint lpfc_##name = defval;\
1896 module_param(lpfc_##name, uint, S_IRUGO);\
1897 MODULE_PARM_DESC(lpfc_##name, desc);\
1898 lpfc_vport_param_hex_show(name)\
1899 lpfc_vport_param_init(name, defval, minval, maxval)\
1900 lpfc_vport_param_set(name, defval, minval, maxval)\
1901 lpfc_vport_param_store(name)\
1902 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1903 lpfc_##name##_show, lpfc_##name##_store)
1905 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1906 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1907 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1908 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1909 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1910 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1911 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1912 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1913 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1914 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1915 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1916 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1917 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1918 lpfc_link_state_store);
1919 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1920 lpfc_option_rom_version_show, NULL);
1921 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1922 lpfc_num_discovered_ports_show, NULL);
1923 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1924 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1925 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1926 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1927 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1928 lpfc_board_mode_show, lpfc_board_mode_store);
1929 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1930 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1931 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1932 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1933 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1934 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1935 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1936 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1937 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1938 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1939 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1940 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1941 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
1942 lpfc_sriov_hw_max_virtfn_show, NULL);
1944 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1947 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1948 * @dev: class device that is converted into a Scsi_host.
1949 * @attr: device attribute, not used.
1950 * @buf: containing the string lpfc_soft_wwn_key.
1951 * @count: must be size of lpfc_soft_wwn_key.
1953 * Returns:
1954 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1955 * length of buf indicates success
1957 static ssize_t
1958 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1959 const char *buf, size_t count)
1961 struct Scsi_Host *shost = class_to_shost(dev);
1962 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1963 struct lpfc_hba *phba = vport->phba;
1964 unsigned int cnt = count;
1967 * We're doing a simple sanity check for soft_wwpn setting.
1968 * We require that the user write a specific key to enable
1969 * the soft_wwpn attribute to be settable. Once the attribute
1970 * is written, the enable key resets. If further updates are
1971 * desired, the key must be written again to re-enable the
1972 * attribute.
1974 * The "key" is not secret - it is a hardcoded string shown
1975 * here. The intent is to protect against the random user or
1976 * application that is just writing attributes.
1979 /* count may include a LF at end of string */
1980 if (buf[cnt-1] == '\n')
1981 cnt--;
1983 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1984 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1985 return -EINVAL;
1987 phba->soft_wwn_enable = 1;
1988 return count;
1990 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1991 lpfc_soft_wwn_enable_store);
1994 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1995 * @dev: class device that is converted into a Scsi_host.
1996 * @attr: device attribute, not used.
1997 * @buf: on return contains the wwpn in hexadecimal.
1999 * Returns: size of formatted string.
2001 static ssize_t
2002 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2003 char *buf)
2005 struct Scsi_Host *shost = class_to_shost(dev);
2006 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2007 struct lpfc_hba *phba = vport->phba;
2009 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2010 (unsigned long long)phba->cfg_soft_wwpn);
2014 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2015 * @dev class device that is converted into a Scsi_host.
2016 * @attr: device attribute, not used.
2017 * @buf: contains the wwpn in hexadecimal.
2018 * @count: number of wwpn bytes in buf
2020 * Returns:
2021 * -EACCES hba reset not enabled, adapter over temp
2022 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2023 * -EIO error taking adapter offline or online
2024 * value of count on success
2026 static ssize_t
2027 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2028 const char *buf, size_t count)
2030 struct Scsi_Host *shost = class_to_shost(dev);
2031 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2032 struct lpfc_hba *phba = vport->phba;
2033 struct completion online_compl;
2034 int stat1=0, stat2=0;
2035 unsigned int i, j, cnt=count;
2036 u8 wwpn[8];
2037 int rc;
2039 if (!phba->cfg_enable_hba_reset)
2040 return -EACCES;
2041 spin_lock_irq(&phba->hbalock);
2042 if (phba->over_temp_state == HBA_OVER_TEMP) {
2043 spin_unlock_irq(&phba->hbalock);
2044 return -EACCES;
2046 spin_unlock_irq(&phba->hbalock);
2047 /* count may include a LF at end of string */
2048 if (buf[cnt-1] == '\n')
2049 cnt--;
2051 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2052 ((cnt == 17) && (*buf++ != 'x')) ||
2053 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2054 return -EINVAL;
2056 phba->soft_wwn_enable = 0;
2058 memset(wwpn, 0, sizeof(wwpn));
2060 /* Validate and store the new name */
2061 for (i=0, j=0; i < 16; i++) {
2062 int value;
2064 value = hex_to_bin(*buf++);
2065 if (value >= 0)
2066 j = (j << 4) | value;
2067 else
2068 return -EINVAL;
2069 if (i % 2) {
2070 wwpn[i/2] = j & 0xff;
2071 j = 0;
2074 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2075 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2076 if (phba->cfg_soft_wwnn)
2077 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2079 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2080 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2082 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2083 if (stat1)
2084 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2085 "0463 lpfc_soft_wwpn attribute set failed to "
2086 "reinit adapter - %d\n", stat1);
2087 init_completion(&online_compl);
2088 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2089 LPFC_EVT_ONLINE);
2090 if (rc == 0)
2091 return -ENOMEM;
2093 wait_for_completion(&online_compl);
2094 if (stat2)
2095 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2096 "0464 lpfc_soft_wwpn attribute set failed to "
2097 "reinit adapter - %d\n", stat2);
2098 return (stat1 || stat2) ? -EIO : count;
2100 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2101 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2104 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2105 * @dev: class device that is converted into a Scsi_host.
2106 * @attr: device attribute, not used.
2107 * @buf: on return contains the wwnn in hexadecimal.
2109 * Returns: size of formatted string.
2111 static ssize_t
2112 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2113 char *buf)
2115 struct Scsi_Host *shost = class_to_shost(dev);
2116 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2117 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2118 (unsigned long long)phba->cfg_soft_wwnn);
2122 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2123 * @cdev: class device that is converted into a Scsi_host.
2124 * @buf: contains the ww node name in hexadecimal.
2125 * @count: number of wwnn bytes in buf.
2127 * Returns:
2128 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2129 * value of count on success
2131 static ssize_t
2132 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2133 const char *buf, size_t count)
2135 struct Scsi_Host *shost = class_to_shost(dev);
2136 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2137 unsigned int i, j, cnt=count;
2138 u8 wwnn[8];
2140 /* count may include a LF at end of string */
2141 if (buf[cnt-1] == '\n')
2142 cnt--;
2144 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2145 ((cnt == 17) && (*buf++ != 'x')) ||
2146 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2147 return -EINVAL;
2150 * Allow wwnn to be set many times, as long as the enable is set.
2151 * However, once the wwpn is set, everything locks.
2154 memset(wwnn, 0, sizeof(wwnn));
2156 /* Validate and store the new name */
2157 for (i=0, j=0; i < 16; i++) {
2158 int value;
2160 value = hex_to_bin(*buf++);
2161 if (value >= 0)
2162 j = (j << 4) | value;
2163 else
2164 return -EINVAL;
2165 if (i % 2) {
2166 wwnn[i/2] = j & 0xff;
2167 j = 0;
2170 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2172 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2173 "lpfc%d: soft_wwnn set. Value will take effect upon "
2174 "setting of the soft_wwpn\n", phba->brd_no);
2176 return count;
2178 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2179 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2182 static int lpfc_poll = 0;
2183 module_param(lpfc_poll, int, S_IRUGO);
2184 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2185 " 0 - none,"
2186 " 1 - poll with interrupts enabled"
2187 " 3 - poll and disable FCP ring interrupts");
2189 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2190 lpfc_poll_show, lpfc_poll_store);
2192 int lpfc_sli_mode = 0;
2193 module_param(lpfc_sli_mode, int, S_IRUGO);
2194 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2195 " 0 - auto (SLI-3 if supported),"
2196 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2197 " 3 - select SLI-3");
2199 int lpfc_enable_npiv = 1;
2200 module_param(lpfc_enable_npiv, int, S_IRUGO);
2201 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2202 lpfc_param_show(enable_npiv);
2203 lpfc_param_init(enable_npiv, 1, 0, 1);
2204 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2206 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2207 "FCF Fast failover=1 Priority failover=2");
2209 int lpfc_enable_rrq;
2210 module_param(lpfc_enable_rrq, int, S_IRUGO);
2211 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2212 lpfc_param_show(enable_rrq);
2213 lpfc_param_init(enable_rrq, 0, 0, 1);
2214 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2217 # lpfc_suppress_link_up: Bring link up at initialization
2218 # 0x0 = bring link up (issue MBX_INIT_LINK)
2219 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2220 # 0x2 = never bring up link
2221 # Default value is 0.
2223 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2224 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2225 "Suppress Link Up at initialization");
2227 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2228 # 1 - (1024)
2229 # 2 - (2048)
2230 # 3 - (3072)
2231 # 4 - (4096)
2232 # 5 - (5120)
2234 static ssize_t
2235 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2237 struct Scsi_Host *shost = class_to_shost(dev);
2238 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2240 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2243 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2244 lpfc_iocb_hw_show, NULL);
2245 static ssize_t
2246 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2248 struct Scsi_Host *shost = class_to_shost(dev);
2249 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2251 return snprintf(buf, PAGE_SIZE, "%d\n",
2252 phba->sli.ring[LPFC_ELS_RING].txq_max);
2255 static DEVICE_ATTR(txq_hw, S_IRUGO,
2256 lpfc_txq_hw_show, NULL);
2257 static ssize_t
2258 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2259 char *buf)
2261 struct Scsi_Host *shost = class_to_shost(dev);
2262 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2264 return snprintf(buf, PAGE_SIZE, "%d\n",
2265 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2268 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2269 lpfc_txcmplq_hw_show, NULL);
2271 int lpfc_iocb_cnt = 2;
2272 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2273 MODULE_PARM_DESC(lpfc_iocb_cnt,
2274 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2275 lpfc_param_show(iocb_cnt);
2276 lpfc_param_init(iocb_cnt, 2, 1, 5);
2277 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2278 lpfc_iocb_cnt_show, NULL);
2281 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2282 # until the timer expires. Value range is [0,255]. Default value is 30.
2284 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2285 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2286 module_param(lpfc_nodev_tmo, int, 0);
2287 MODULE_PARM_DESC(lpfc_nodev_tmo,
2288 "Seconds driver will hold I/O waiting "
2289 "for a device to come back");
2292 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2293 * @dev: class converted to a Scsi_host structure.
2294 * @attr: device attribute, not used.
2295 * @buf: on return contains the dev loss timeout in decimal.
2297 * Returns: size of formatted string.
2299 static ssize_t
2300 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2301 char *buf)
2303 struct Scsi_Host *shost = class_to_shost(dev);
2304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2306 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2310 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2311 * @vport: lpfc vport structure pointer.
2312 * @val: contains the nodev timeout value.
2314 * Description:
2315 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2316 * a kernel error message is printed and zero is returned.
2317 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2318 * Otherwise nodev tmo is set to the default value.
2320 * Returns:
2321 * zero if already set or if val is in range
2322 * -EINVAL val out of range
2324 static int
2325 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2327 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2328 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2329 if (val != LPFC_DEF_DEVLOSS_TMO)
2330 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2331 "0407 Ignoring nodev_tmo module "
2332 "parameter because devloss_tmo is "
2333 "set.\n");
2334 return 0;
2337 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2338 vport->cfg_nodev_tmo = val;
2339 vport->cfg_devloss_tmo = val;
2340 return 0;
2342 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2343 "0400 lpfc_nodev_tmo attribute cannot be set to"
2344 " %d, allowed range is [%d, %d]\n",
2345 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2346 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2347 return -EINVAL;
2351 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2352 * @vport: lpfc vport structure pointer.
2354 * Description:
2355 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2357 static void
2358 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2360 struct Scsi_Host *shost;
2361 struct lpfc_nodelist *ndlp;
2363 shost = lpfc_shost_from_vport(vport);
2364 spin_lock_irq(shost->host_lock);
2365 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2366 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2367 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2368 spin_unlock_irq(shost->host_lock);
2372 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2373 * @vport: lpfc vport structure pointer.
2374 * @val: contains the tmo value.
2376 * Description:
2377 * If the devloss tmo is already set or the vport dev loss tmo has changed
2378 * then a kernel error message is printed and zero is returned.
2379 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2380 * Otherwise nodev tmo is set to the default value.
2382 * Returns:
2383 * zero if already set or if val is in range
2384 * -EINVAL val out of range
2386 static int
2387 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2389 if (vport->dev_loss_tmo_changed ||
2390 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2391 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2392 "0401 Ignoring change to nodev_tmo "
2393 "because devloss_tmo is set.\n");
2394 return 0;
2396 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2397 vport->cfg_nodev_tmo = val;
2398 vport->cfg_devloss_tmo = val;
2400 * For compat: set the fc_host dev loss so new rports
2401 * will get the value.
2403 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2404 lpfc_update_rport_devloss_tmo(vport);
2405 return 0;
2407 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2408 "0403 lpfc_nodev_tmo attribute cannot be set to"
2409 "%d, allowed range is [%d, %d]\n",
2410 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2411 return -EINVAL;
2414 lpfc_vport_param_store(nodev_tmo)
2416 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2417 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2420 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2421 # disappear until the timer expires. Value range is [0,255]. Default
2422 # value is 30.
2424 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2425 MODULE_PARM_DESC(lpfc_devloss_tmo,
2426 "Seconds driver will hold I/O waiting "
2427 "for a device to come back");
2428 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2429 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2430 lpfc_vport_param_show(devloss_tmo)
2433 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2434 * @vport: lpfc vport structure pointer.
2435 * @val: contains the tmo value.
2437 * Description:
2438 * If val is in a valid range then set the vport nodev tmo,
2439 * devloss tmo, also set the vport dev loss tmo changed flag.
2440 * Else a kernel error message is printed.
2442 * Returns:
2443 * zero if val is in range
2444 * -EINVAL val out of range
2446 static int
2447 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2449 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2450 vport->cfg_nodev_tmo = val;
2451 vport->cfg_devloss_tmo = val;
2452 vport->dev_loss_tmo_changed = 1;
2453 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2454 lpfc_update_rport_devloss_tmo(vport);
2455 return 0;
2458 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2459 "0404 lpfc_devloss_tmo attribute cannot be set to"
2460 " %d, allowed range is [%d, %d]\n",
2461 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2462 return -EINVAL;
2465 lpfc_vport_param_store(devloss_tmo)
2466 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2467 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2470 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2471 # deluged with LOTS of information.
2472 # You can set a bit mask to record specific types of verbose messages:
2473 # See lpfc_logmsh.h for definitions.
2475 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2476 "Verbose logging bit-mask");
2479 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2480 # objects that have been registered with the nameserver after login.
2482 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2483 "Deregister nameserver objects before LOGO");
2486 # lun_queue_depth: This parameter is used to limit the number of outstanding
2487 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2489 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2490 "Max number of FCP commands we can queue to a specific LUN");
2493 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2494 # commands per target port. Value range is [10,65535]. Default value is 65535.
2496 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2497 "Max number of FCP commands we can queue to a specific target port");
2500 # hba_queue_depth: This parameter is used to limit the number of outstanding
2501 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2502 # value is greater than the maximum number of exchanges supported by the HBA,
2503 # then maximum number of exchanges supported by the HBA is used to determine
2504 # the hba_queue_depth.
2506 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2507 "Max number of FCP commands we can queue to a lpfc HBA");
2510 # peer_port_login: This parameter allows/prevents logins
2511 # between peer ports hosted on the same physical port.
2512 # When this parameter is set 0 peer ports of same physical port
2513 # are not allowed to login to each other.
2514 # When this parameter is set 1 peer ports of same physical port
2515 # are allowed to login to each other.
2516 # Default value of this parameter is 0.
2518 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2519 "Allow peer ports on the same physical port to login to each "
2520 "other.");
2523 # restrict_login: This parameter allows/prevents logins
2524 # between Virtual Ports and remote initiators.
2525 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2526 # other initiators and will attempt to PLOGI all remote ports.
2527 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2528 # remote ports and will not attempt to PLOGI to other initiators.
2529 # This parameter does not restrict to the physical port.
2530 # This parameter does not restrict logins to Fabric resident remote ports.
2531 # Default value of this parameter is 1.
2533 static int lpfc_restrict_login = 1;
2534 module_param(lpfc_restrict_login, int, S_IRUGO);
2535 MODULE_PARM_DESC(lpfc_restrict_login,
2536 "Restrict virtual ports login to remote initiators.");
2537 lpfc_vport_param_show(restrict_login);
2540 * lpfc_restrict_login_init - Set the vport restrict login flag
2541 * @vport: lpfc vport structure pointer.
2542 * @val: contains the restrict login value.
2544 * Description:
2545 * If val is not in a valid range then log a kernel error message and set
2546 * the vport restrict login to one.
2547 * If the port type is physical clear the restrict login flag and return.
2548 * Else set the restrict login flag to val.
2550 * Returns:
2551 * zero if val is in range
2552 * -EINVAL val out of range
2554 static int
2555 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2557 if (val < 0 || val > 1) {
2558 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2559 "0422 lpfc_restrict_login attribute cannot "
2560 "be set to %d, allowed range is [0, 1]\n",
2561 val);
2562 vport->cfg_restrict_login = 1;
2563 return -EINVAL;
2565 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2566 vport->cfg_restrict_login = 0;
2567 return 0;
2569 vport->cfg_restrict_login = val;
2570 return 0;
2574 * lpfc_restrict_login_set - Set the vport restrict login flag
2575 * @vport: lpfc vport structure pointer.
2576 * @val: contains the restrict login value.
2578 * Description:
2579 * If val is not in a valid range then log a kernel error message and set
2580 * the vport restrict login to one.
2581 * If the port type is physical and the val is not zero log a kernel
2582 * error message, clear the restrict login flag and return zero.
2583 * Else set the restrict login flag to val.
2585 * Returns:
2586 * zero if val is in range
2587 * -EINVAL val out of range
2589 static int
2590 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2592 if (val < 0 || val > 1) {
2593 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2594 "0425 lpfc_restrict_login attribute cannot "
2595 "be set to %d, allowed range is [0, 1]\n",
2596 val);
2597 vport->cfg_restrict_login = 1;
2598 return -EINVAL;
2600 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2601 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2602 "0468 lpfc_restrict_login must be 0 for "
2603 "Physical ports.\n");
2604 vport->cfg_restrict_login = 0;
2605 return 0;
2607 vport->cfg_restrict_login = val;
2608 return 0;
2610 lpfc_vport_param_store(restrict_login);
2611 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2612 lpfc_restrict_login_show, lpfc_restrict_login_store);
2615 # Some disk devices have a "select ID" or "select Target" capability.
2616 # From a protocol standpoint "select ID" usually means select the
2617 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2618 # annex" which contains a table that maps a "select ID" (a number
2619 # between 0 and 7F) to an ALPA. By default, for compatibility with
2620 # older drivers, the lpfc driver scans this table from low ALPA to high
2621 # ALPA.
2623 # Turning on the scan-down variable (on = 1, off = 0) will
2624 # cause the lpfc driver to use an inverted table, effectively
2625 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2627 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2628 # and will not work across a fabric. Also this parameter will take
2629 # effect only in the case when ALPA map is not available.)
2631 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2632 "Start scanning for devices from highest ALPA to lowest");
2635 # lpfc_topology: link topology for init link
2636 # 0x0 = attempt loop mode then point-to-point
2637 # 0x01 = internal loopback mode
2638 # 0x02 = attempt point-to-point mode only
2639 # 0x04 = attempt loop mode only
2640 # 0x06 = attempt point-to-point mode then loop
2641 # Set point-to-point mode if you want to run as an N_Port.
2642 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2643 # Default value is 0.
2647 * lpfc_topology_set - Set the adapters topology field
2648 * @phba: lpfc_hba pointer.
2649 * @val: topology value.
2651 * Description:
2652 * If val is in a valid range then set the adapter's topology field and
2653 * issue a lip; if the lip fails reset the topology to the old value.
2655 * If the value is not in range log a kernel error message and return an error.
2657 * Returns:
2658 * zero if val is in range and lip okay
2659 * non-zero return value from lpfc_issue_lip()
2660 * -EINVAL val out of range
2662 static ssize_t
2663 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2664 const char *buf, size_t count)
2666 struct Scsi_Host *shost = class_to_shost(dev);
2667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2668 struct lpfc_hba *phba = vport->phba;
2669 int val = 0;
2670 int nolip = 0;
2671 const char *val_buf = buf;
2672 int err;
2673 uint32_t prev_val;
2675 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2676 nolip = 1;
2677 val_buf = &buf[strlen("nolip ")];
2680 if (!isdigit(val_buf[0]))
2681 return -EINVAL;
2682 if (sscanf(val_buf, "%i", &val) != 1)
2683 return -EINVAL;
2685 if (val >= 0 && val <= 6) {
2686 prev_val = phba->cfg_topology;
2687 phba->cfg_topology = val;
2688 if (nolip)
2689 return strlen(buf);
2691 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2692 "3054 lpfc_topology changed from %d to %d\n",
2693 prev_val, val);
2694 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2695 if (err) {
2696 phba->cfg_topology = prev_val;
2697 return -EINVAL;
2698 } else
2699 return strlen(buf);
2701 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2702 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2703 "allowed range is [0, 6]\n",
2704 phba->brd_no, val);
2705 return -EINVAL;
2707 static int lpfc_topology = 0;
2708 module_param(lpfc_topology, int, S_IRUGO);
2709 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2710 lpfc_param_show(topology)
2711 lpfc_param_init(topology, 0, 0, 6)
2712 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2713 lpfc_topology_show, lpfc_topology_store);
2716 * lpfc_static_vport_show: Read callback function for
2717 * lpfc_static_vport sysfs file.
2718 * @dev: Pointer to class device object.
2719 * @attr: device attribute structure.
2720 * @buf: Data buffer.
2722 * This function is the read call back function for
2723 * lpfc_static_vport sysfs file. The lpfc_static_vport
2724 * sysfs file report the mageability of the vport.
2726 static ssize_t
2727 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2728 char *buf)
2730 struct Scsi_Host *shost = class_to_shost(dev);
2731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2732 if (vport->vport_flag & STATIC_VPORT)
2733 sprintf(buf, "1\n");
2734 else
2735 sprintf(buf, "0\n");
2737 return strlen(buf);
2741 * Sysfs attribute to control the statistical data collection.
2743 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2744 lpfc_static_vport_show, NULL);
2747 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2748 * @dev: Pointer to class device.
2749 * @buf: Data buffer.
2750 * @count: Size of the data buffer.
2752 * This function get called when an user write to the lpfc_stat_data_ctrl
2753 * sysfs file. This function parse the command written to the sysfs file
2754 * and take appropriate action. These commands are used for controlling
2755 * driver statistical data collection.
2756 * Following are the command this function handles.
2758 * setbucket <bucket_type> <base> <step>
2759 * = Set the latency buckets.
2760 * destroybucket = destroy all the buckets.
2761 * start = start data collection
2762 * stop = stop data collection
2763 * reset = reset the collected data
2765 static ssize_t
2766 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2767 const char *buf, size_t count)
2769 struct Scsi_Host *shost = class_to_shost(dev);
2770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2771 struct lpfc_hba *phba = vport->phba;
2772 #define LPFC_MAX_DATA_CTRL_LEN 1024
2773 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2774 unsigned long i;
2775 char *str_ptr, *token;
2776 struct lpfc_vport **vports;
2777 struct Scsi_Host *v_shost;
2778 char *bucket_type_str, *base_str, *step_str;
2779 unsigned long base, step, bucket_type;
2781 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2782 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2783 return -EINVAL;
2785 strcpy(bucket_data, buf);
2786 str_ptr = &bucket_data[0];
2787 /* Ignore this token - this is command token */
2788 token = strsep(&str_ptr, "\t ");
2789 if (!token)
2790 return -EINVAL;
2792 bucket_type_str = strsep(&str_ptr, "\t ");
2793 if (!bucket_type_str)
2794 return -EINVAL;
2796 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2797 bucket_type = LPFC_LINEAR_BUCKET;
2798 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2799 bucket_type = LPFC_POWER2_BUCKET;
2800 else
2801 return -EINVAL;
2803 base_str = strsep(&str_ptr, "\t ");
2804 if (!base_str)
2805 return -EINVAL;
2806 base = simple_strtoul(base_str, NULL, 0);
2808 step_str = strsep(&str_ptr, "\t ");
2809 if (!step_str)
2810 return -EINVAL;
2811 step = simple_strtoul(step_str, NULL, 0);
2812 if (!step)
2813 return -EINVAL;
2815 /* Block the data collection for every vport */
2816 vports = lpfc_create_vport_work_array(phba);
2817 if (vports == NULL)
2818 return -ENOMEM;
2820 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2821 v_shost = lpfc_shost_from_vport(vports[i]);
2822 spin_lock_irq(v_shost->host_lock);
2823 /* Block and reset data collection */
2824 vports[i]->stat_data_blocked = 1;
2825 if (vports[i]->stat_data_enabled)
2826 lpfc_vport_reset_stat_data(vports[i]);
2827 spin_unlock_irq(v_shost->host_lock);
2830 /* Set the bucket attributes */
2831 phba->bucket_type = bucket_type;
2832 phba->bucket_base = base;
2833 phba->bucket_step = step;
2835 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2836 v_shost = lpfc_shost_from_vport(vports[i]);
2838 /* Unblock data collection */
2839 spin_lock_irq(v_shost->host_lock);
2840 vports[i]->stat_data_blocked = 0;
2841 spin_unlock_irq(v_shost->host_lock);
2843 lpfc_destroy_vport_work_array(phba, vports);
2844 return strlen(buf);
2847 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2848 vports = lpfc_create_vport_work_array(phba);
2849 if (vports == NULL)
2850 return -ENOMEM;
2852 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2853 v_shost = lpfc_shost_from_vport(vports[i]);
2854 spin_lock_irq(shost->host_lock);
2855 vports[i]->stat_data_blocked = 1;
2856 lpfc_free_bucket(vport);
2857 vport->stat_data_enabled = 0;
2858 vports[i]->stat_data_blocked = 0;
2859 spin_unlock_irq(shost->host_lock);
2861 lpfc_destroy_vport_work_array(phba, vports);
2862 phba->bucket_type = LPFC_NO_BUCKET;
2863 phba->bucket_base = 0;
2864 phba->bucket_step = 0;
2865 return strlen(buf);
2868 if (!strncmp(buf, "start", strlen("start"))) {
2869 /* If no buckets configured return error */
2870 if (phba->bucket_type == LPFC_NO_BUCKET)
2871 return -EINVAL;
2872 spin_lock_irq(shost->host_lock);
2873 if (vport->stat_data_enabled) {
2874 spin_unlock_irq(shost->host_lock);
2875 return strlen(buf);
2877 lpfc_alloc_bucket(vport);
2878 vport->stat_data_enabled = 1;
2879 spin_unlock_irq(shost->host_lock);
2880 return strlen(buf);
2883 if (!strncmp(buf, "stop", strlen("stop"))) {
2884 spin_lock_irq(shost->host_lock);
2885 if (vport->stat_data_enabled == 0) {
2886 spin_unlock_irq(shost->host_lock);
2887 return strlen(buf);
2889 lpfc_free_bucket(vport);
2890 vport->stat_data_enabled = 0;
2891 spin_unlock_irq(shost->host_lock);
2892 return strlen(buf);
2895 if (!strncmp(buf, "reset", strlen("reset"))) {
2896 if ((phba->bucket_type == LPFC_NO_BUCKET)
2897 || !vport->stat_data_enabled)
2898 return strlen(buf);
2899 spin_lock_irq(shost->host_lock);
2900 vport->stat_data_blocked = 1;
2901 lpfc_vport_reset_stat_data(vport);
2902 vport->stat_data_blocked = 0;
2903 spin_unlock_irq(shost->host_lock);
2904 return strlen(buf);
2906 return -EINVAL;
2911 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2912 * @dev: Pointer to class device object.
2913 * @buf: Data buffer.
2915 * This function is the read call back function for
2916 * lpfc_stat_data_ctrl sysfs file. This function report the
2917 * current statistical data collection state.
2919 static ssize_t
2920 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2921 char *buf)
2923 struct Scsi_Host *shost = class_to_shost(dev);
2924 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2925 struct lpfc_hba *phba = vport->phba;
2926 int index = 0;
2927 int i;
2928 char *bucket_type;
2929 unsigned long bucket_value;
2931 switch (phba->bucket_type) {
2932 case LPFC_LINEAR_BUCKET:
2933 bucket_type = "linear";
2934 break;
2935 case LPFC_POWER2_BUCKET:
2936 bucket_type = "power2";
2937 break;
2938 default:
2939 bucket_type = "No Bucket";
2940 break;
2943 sprintf(&buf[index], "Statistical Data enabled :%d, "
2944 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2945 " Bucket step :%d\nLatency Ranges :",
2946 vport->stat_data_enabled, vport->stat_data_blocked,
2947 bucket_type, phba->bucket_base, phba->bucket_step);
2948 index = strlen(buf);
2949 if (phba->bucket_type != LPFC_NO_BUCKET) {
2950 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2951 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2952 bucket_value = phba->bucket_base +
2953 phba->bucket_step * i;
2954 else
2955 bucket_value = phba->bucket_base +
2956 (1 << i) * phba->bucket_step;
2958 if (index + 10 > PAGE_SIZE)
2959 break;
2960 sprintf(&buf[index], "%08ld ", bucket_value);
2961 index = strlen(buf);
2964 sprintf(&buf[index], "\n");
2965 return strlen(buf);
2969 * Sysfs attribute to control the statistical data collection.
2971 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2972 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2975 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2979 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2980 * for each target.
2982 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2983 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2984 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2988 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2989 * @filp: sysfs file
2990 * @kobj: Pointer to the kernel object
2991 * @bin_attr: Attribute object
2992 * @buff: Buffer pointer
2993 * @off: File offset
2994 * @count: Buffer size
2996 * This function is the read call back function for lpfc_drvr_stat_data
2997 * sysfs file. This function export the statistical data to user
2998 * applications.
3000 static ssize_t
3001 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3002 struct bin_attribute *bin_attr,
3003 char *buf, loff_t off, size_t count)
3005 struct device *dev = container_of(kobj, struct device,
3006 kobj);
3007 struct Scsi_Host *shost = class_to_shost(dev);
3008 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3009 struct lpfc_hba *phba = vport->phba;
3010 int i = 0, index = 0;
3011 unsigned long nport_index;
3012 struct lpfc_nodelist *ndlp = NULL;
3013 nport_index = (unsigned long)off /
3014 MAX_STAT_DATA_SIZE_PER_TARGET;
3016 if (!vport->stat_data_enabled || vport->stat_data_blocked
3017 || (phba->bucket_type == LPFC_NO_BUCKET))
3018 return 0;
3020 spin_lock_irq(shost->host_lock);
3021 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3022 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3023 continue;
3025 if (nport_index > 0) {
3026 nport_index--;
3027 continue;
3030 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3031 > count)
3032 break;
3034 if (!ndlp->lat_data)
3035 continue;
3037 /* Print the WWN */
3038 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3039 ndlp->nlp_portname.u.wwn[0],
3040 ndlp->nlp_portname.u.wwn[1],
3041 ndlp->nlp_portname.u.wwn[2],
3042 ndlp->nlp_portname.u.wwn[3],
3043 ndlp->nlp_portname.u.wwn[4],
3044 ndlp->nlp_portname.u.wwn[5],
3045 ndlp->nlp_portname.u.wwn[6],
3046 ndlp->nlp_portname.u.wwn[7]);
3048 index = strlen(buf);
3050 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3051 sprintf(&buf[index], "%010u,",
3052 ndlp->lat_data[i].cmd_count);
3053 index = strlen(buf);
3055 sprintf(&buf[index], "\n");
3056 index = strlen(buf);
3058 spin_unlock_irq(shost->host_lock);
3059 return index;
3062 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3063 .attr = {
3064 .name = "lpfc_drvr_stat_data",
3065 .mode = S_IRUSR,
3067 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3068 .read = sysfs_drvr_stat_data_read,
3069 .write = NULL,
3073 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3074 # connection.
3075 # Value range is [0,16]. Default value is 0.
3078 * lpfc_link_speed_set - Set the adapters link speed
3079 * @phba: lpfc_hba pointer.
3080 * @val: link speed value.
3082 * Description:
3083 * If val is in a valid range then set the adapter's link speed field and
3084 * issue a lip; if the lip fails reset the link speed to the old value.
3086 * Notes:
3087 * If the value is not in range log a kernel error message and return an error.
3089 * Returns:
3090 * zero if val is in range and lip okay.
3091 * non-zero return value from lpfc_issue_lip()
3092 * -EINVAL val out of range
3094 static ssize_t
3095 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3096 const char *buf, size_t count)
3098 struct Scsi_Host *shost = class_to_shost(dev);
3099 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3100 struct lpfc_hba *phba = vport->phba;
3101 int val = LPFC_USER_LINK_SPEED_AUTO;
3102 int nolip = 0;
3103 const char *val_buf = buf;
3104 int err;
3105 uint32_t prev_val;
3107 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3108 nolip = 1;
3109 val_buf = &buf[strlen("nolip ")];
3112 if (!isdigit(val_buf[0]))
3113 return -EINVAL;
3114 if (sscanf(val_buf, "%i", &val) != 1)
3115 return -EINVAL;
3117 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3118 "3055 lpfc_link_speed changed from %d to %d %s\n",
3119 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3121 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3122 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3123 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3124 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3125 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3126 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3127 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3128 "2879 lpfc_link_speed attribute cannot be set "
3129 "to %d. Speed is not supported by this port.\n",
3130 val);
3131 return -EINVAL;
3133 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3134 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3135 prev_val = phba->cfg_link_speed;
3136 phba->cfg_link_speed = val;
3137 if (nolip)
3138 return strlen(buf);
3140 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3141 if (err) {
3142 phba->cfg_link_speed = prev_val;
3143 return -EINVAL;
3144 } else
3145 return strlen(buf);
3147 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3148 "0469 lpfc_link_speed attribute cannot be set to %d, "
3149 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3150 return -EINVAL;
3153 static int lpfc_link_speed = 0;
3154 module_param(lpfc_link_speed, int, S_IRUGO);
3155 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3156 lpfc_param_show(link_speed)
3159 * lpfc_link_speed_init - Set the adapters link speed
3160 * @phba: lpfc_hba pointer.
3161 * @val: link speed value.
3163 * Description:
3164 * If val is in a valid range then set the adapter's link speed field.
3166 * Notes:
3167 * If the value is not in range log a kernel error message, clear the link
3168 * speed and return an error.
3170 * Returns:
3171 * zero if val saved.
3172 * -EINVAL val out of range
3174 static int
3175 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3177 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3178 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3179 phba->cfg_link_speed = val;
3180 return 0;
3182 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3183 "0405 lpfc_link_speed attribute cannot "
3184 "be set to %d, allowed values are "
3185 "["LPFC_LINK_SPEED_STRING"]\n", val);
3186 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3187 return -EINVAL;
3190 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3191 lpfc_link_speed_show, lpfc_link_speed_store);
3194 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3195 # 0 = aer disabled or not supported
3196 # 1 = aer supported and enabled (default)
3197 # Value range is [0,1]. Default value is 1.
3201 * lpfc_aer_support_store - Set the adapter for aer support
3203 * @dev: class device that is converted into a Scsi_host.
3204 * @attr: device attribute, not used.
3205 * @buf: containing enable or disable aer flag.
3206 * @count: unused variable.
3208 * Description:
3209 * If the val is 1 and currently the device's AER capability was not
3210 * enabled, invoke the kernel's enable AER helper routine, trying to
3211 * enable the device's AER capability. If the helper routine enabling
3212 * AER returns success, update the device's cfg_aer_support flag to
3213 * indicate AER is supported by the device; otherwise, if the device
3214 * AER capability is already enabled to support AER, then do nothing.
3216 * If the val is 0 and currently the device's AER support was enabled,
3217 * invoke the kernel's disable AER helper routine. After that, update
3218 * the device's cfg_aer_support flag to indicate AER is not supported
3219 * by the device; otherwise, if the device AER capability is already
3220 * disabled from supporting AER, then do nothing.
3222 * Returns:
3223 * length of the buf on success if val is in range the intended mode
3224 * is supported.
3225 * -EINVAL if val out of range or intended mode is not supported.
3227 static ssize_t
3228 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3229 const char *buf, size_t count)
3231 struct Scsi_Host *shost = class_to_shost(dev);
3232 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3233 struct lpfc_hba *phba = vport->phba;
3234 int val = 0, rc = -EINVAL;
3236 if (!isdigit(buf[0]))
3237 return -EINVAL;
3238 if (sscanf(buf, "%i", &val) != 1)
3239 return -EINVAL;
3241 switch (val) {
3242 case 0:
3243 if (phba->hba_flag & HBA_AER_ENABLED) {
3244 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3245 if (!rc) {
3246 spin_lock_irq(&phba->hbalock);
3247 phba->hba_flag &= ~HBA_AER_ENABLED;
3248 spin_unlock_irq(&phba->hbalock);
3249 phba->cfg_aer_support = 0;
3250 rc = strlen(buf);
3251 } else
3252 rc = -EPERM;
3253 } else {
3254 phba->cfg_aer_support = 0;
3255 rc = strlen(buf);
3257 break;
3258 case 1:
3259 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3260 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3261 if (!rc) {
3262 spin_lock_irq(&phba->hbalock);
3263 phba->hba_flag |= HBA_AER_ENABLED;
3264 spin_unlock_irq(&phba->hbalock);
3265 phba->cfg_aer_support = 1;
3266 rc = strlen(buf);
3267 } else
3268 rc = -EPERM;
3269 } else {
3270 phba->cfg_aer_support = 1;
3271 rc = strlen(buf);
3273 break;
3274 default:
3275 rc = -EINVAL;
3276 break;
3278 return rc;
3281 static int lpfc_aer_support = 1;
3282 module_param(lpfc_aer_support, int, S_IRUGO);
3283 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3284 lpfc_param_show(aer_support)
3287 * lpfc_aer_support_init - Set the initial adapters aer support flag
3288 * @phba: lpfc_hba pointer.
3289 * @val: enable aer or disable aer flag.
3291 * Description:
3292 * If val is in a valid range [0,1], then set the adapter's initial
3293 * cfg_aer_support field. It will be up to the driver's probe_one
3294 * routine to determine whether the device's AER support can be set
3295 * or not.
3297 * Notes:
3298 * If the value is not in range log a kernel error message, and
3299 * choose the default value of setting AER support and return.
3301 * Returns:
3302 * zero if val saved.
3303 * -EINVAL val out of range
3305 static int
3306 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3308 if (val == 0 || val == 1) {
3309 phba->cfg_aer_support = val;
3310 return 0;
3312 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3313 "2712 lpfc_aer_support attribute value %d out "
3314 "of range, allowed values are 0|1, setting it "
3315 "to default value of 1\n", val);
3316 /* By default, try to enable AER on a device */
3317 phba->cfg_aer_support = 1;
3318 return -EINVAL;
3321 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3322 lpfc_aer_support_show, lpfc_aer_support_store);
3325 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3326 * @dev: class device that is converted into a Scsi_host.
3327 * @attr: device attribute, not used.
3328 * @buf: containing flag 1 for aer cleanup state.
3329 * @count: unused variable.
3331 * Description:
3332 * If the @buf contains 1 and the device currently has the AER support
3333 * enabled, then invokes the kernel AER helper routine
3334 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3335 * error status register.
3337 * Notes:
3339 * Returns:
3340 * -EINVAL if the buf does not contain the 1 or the device is not currently
3341 * enabled with the AER support.
3343 static ssize_t
3344 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3345 const char *buf, size_t count)
3347 struct Scsi_Host *shost = class_to_shost(dev);
3348 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3349 struct lpfc_hba *phba = vport->phba;
3350 int val, rc = -1;
3352 if (!isdigit(buf[0]))
3353 return -EINVAL;
3354 if (sscanf(buf, "%i", &val) != 1)
3355 return -EINVAL;
3356 if (val != 1)
3357 return -EINVAL;
3359 if (phba->hba_flag & HBA_AER_ENABLED)
3360 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3362 if (rc == 0)
3363 return strlen(buf);
3364 else
3365 return -EPERM;
3368 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3369 lpfc_aer_cleanup_state);
3372 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
3374 * @dev: class device that is converted into a Scsi_host.
3375 * @attr: device attribute, not used.
3376 * @buf: containing the string the number of vfs to be enabled.
3377 * @count: unused variable.
3379 * Description:
3380 * When this api is called either through user sysfs, the driver shall
3381 * try to enable or disable SR-IOV virtual functions according to the
3382 * following:
3384 * If zero virtual function has been enabled to the physical function,
3385 * the driver shall invoke the pci enable virtual function api trying
3386 * to enable the virtual functions. If the nr_vfn provided is greater
3387 * than the maximum supported, the maximum virtual function number will
3388 * be used for invoking the api; otherwise, the nr_vfn provided shall
3389 * be used for invoking the api. If the api call returned success, the
3390 * actual number of virtual functions enabled will be set to the driver
3391 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
3392 * cfg_sriov_nr_virtfn remains zero.
3394 * If none-zero virtual functions have already been enabled to the
3395 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
3396 * -EINVAL will be returned and the driver does nothing;
3398 * If the nr_vfn provided is zero and none-zero virtual functions have
3399 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
3400 * disabling virtual function api shall be invoded to disable all the
3401 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
3402 * zero. Otherwise, if zero virtual function has been enabled, do
3403 * nothing.
3405 * Returns:
3406 * length of the buf on success if val is in range the intended mode
3407 * is supported.
3408 * -EINVAL if val out of range or intended mode is not supported.
3410 static ssize_t
3411 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3412 const char *buf, size_t count)
3414 struct Scsi_Host *shost = class_to_shost(dev);
3415 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3416 struct lpfc_hba *phba = vport->phba;
3417 struct pci_dev *pdev = phba->pcidev;
3418 int val = 0, rc = -EINVAL;
3420 /* Sanity check on user data */
3421 if (!isdigit(buf[0]))
3422 return -EINVAL;
3423 if (sscanf(buf, "%i", &val) != 1)
3424 return -EINVAL;
3425 if (val < 0)
3426 return -EINVAL;
3428 /* Request disabling virtual functions */
3429 if (val == 0) {
3430 if (phba->cfg_sriov_nr_virtfn > 0) {
3431 pci_disable_sriov(pdev);
3432 phba->cfg_sriov_nr_virtfn = 0;
3434 return strlen(buf);
3437 /* Request enabling virtual functions */
3438 if (phba->cfg_sriov_nr_virtfn > 0) {
3439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3440 "3018 There are %d virtual functions "
3441 "enabled on physical function.\n",
3442 phba->cfg_sriov_nr_virtfn);
3443 return -EEXIST;
3446 if (val <= LPFC_MAX_VFN_PER_PFN)
3447 phba->cfg_sriov_nr_virtfn = val;
3448 else {
3449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3450 "3019 Enabling %d virtual functions is not "
3451 "allowed.\n", val);
3452 return -EINVAL;
3455 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3456 if (rc) {
3457 phba->cfg_sriov_nr_virtfn = 0;
3458 rc = -EPERM;
3459 } else
3460 rc = strlen(buf);
3462 return rc;
3465 static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3466 module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3467 MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3468 lpfc_param_show(sriov_nr_virtfn)
3471 * lpfc_sriov_nr_virtfn_init - Set the initial sr-iov virtual function enable
3472 * @phba: lpfc_hba pointer.
3473 * @val: link speed value.
3475 * Description:
3476 * If val is in a valid range [0,255], then set the adapter's initial
3477 * cfg_sriov_nr_virtfn field. If it's greater than the maximum, the maximum
3478 * number shall be used instead. It will be up to the driver's probe_one
3479 * routine to determine whether the device's SR-IOV is supported or not.
3481 * Returns:
3482 * zero if val saved.
3483 * -EINVAL val out of range
3485 static int
3486 lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3488 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3489 phba->cfg_sriov_nr_virtfn = val;
3490 return 0;
3493 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3494 "3017 Enabling %d virtual functions is not "
3495 "allowed.\n", val);
3496 return -EINVAL;
3498 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3499 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3502 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3503 # Value range is [2,3]. Default value is 3.
3505 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3506 "Select Fibre Channel class of service for FCP sequences");
3509 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3510 # is [0,1]. Default value is 0.
3512 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3513 "Use ADISC on rediscovery to authenticate FCP devices");
3516 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3517 # depth. Default value is 0. When the value of this parameter is zero the
3518 # SCSI command completion time is not used for controlling I/O queue depth. When
3519 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3520 # to limit the I/O completion time to the parameter value.
3521 # The value is set in milliseconds.
3523 static int lpfc_max_scsicmpl_time;
3524 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3525 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3526 "Use command completion time to control queue depth");
3527 lpfc_vport_param_show(max_scsicmpl_time);
3528 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3529 static int
3530 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3533 struct lpfc_nodelist *ndlp, *next_ndlp;
3535 if (val == vport->cfg_max_scsicmpl_time)
3536 return 0;
3537 if ((val < 0) || (val > 60000))
3538 return -EINVAL;
3539 vport->cfg_max_scsicmpl_time = val;
3541 spin_lock_irq(shost->host_lock);
3542 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3543 if (!NLP_CHK_NODE_ACT(ndlp))
3544 continue;
3545 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3546 continue;
3547 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3549 spin_unlock_irq(shost->host_lock);
3550 return 0;
3552 lpfc_vport_param_store(max_scsicmpl_time);
3553 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3554 lpfc_max_scsicmpl_time_show,
3555 lpfc_max_scsicmpl_time_store);
3558 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3559 # range is [0,1]. Default value is 0.
3561 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3564 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3565 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3566 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3567 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3568 # cr_delay is set to 0.
3570 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3571 "interrupt response is generated");
3573 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3574 "interrupt response is generated");
3577 # lpfc_multi_ring_support: Determines how many rings to spread available
3578 # cmd/rsp IOCB entries across.
3579 # Value range is [1,2]. Default value is 1.
3581 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3582 "SLI rings to spread IOCB entries across");
3585 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3586 # identifies what rctl value to configure the additional ring for.
3587 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3589 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3590 255, "Identifies RCTL for additional ring configuration");
3593 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3594 # identifies what type value to configure the additional ring for.
3595 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3597 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3598 255, "Identifies TYPE for additional ring configuration");
3601 # lpfc_fdmi_on: controls FDMI support.
3602 # 0 = no FDMI support
3603 # 1 = support FDMI without attribute of hostname
3604 # 2 = support FDMI with attribute of hostname
3605 # Value range [0,2]. Default value is 0.
3607 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3610 # Specifies the maximum number of ELS cmds we can have outstanding (for
3611 # discovery). Value range is [1,64]. Default value = 32.
3613 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3614 "during discovery");
3617 # lpfc_max_luns: maximum allowed LUN.
3618 # Value range is [0,65535]. Default value is 255.
3619 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3621 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3624 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3625 # Value range is [1,255], default value is 10.
3627 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3628 "Milliseconds driver will wait between polling FCP ring");
3631 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3632 # support this feature
3633 # 0 = MSI disabled
3634 # 1 = MSI enabled
3635 # 2 = MSI-X enabled (default)
3636 # Value range is [0,2]. Default value is 2.
3638 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3639 "MSI-X (2), if possible");
3642 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3644 # Value range is [636,651042]. Default value is 10000.
3646 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3647 "Set the maximum number of fast-path FCP interrupts per second");
3650 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3652 # Value range is [1,31]. Default value is 4.
3654 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3655 "Set the number of fast-path FCP work queues, if possible");
3658 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3660 # Value range is [1,7]. Default value is 1.
3662 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3663 "Set the number of fast-path FCP event queues, if possible");
3666 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3667 # 0 = HBA resets disabled
3668 # 1 = HBA resets enabled (default)
3669 # Value range is [0,1]. Default value is 1.
3671 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3674 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3675 # 0 = HBA Heartbeat disabled
3676 # 1 = HBA Heartbeat enabled (default)
3677 # Value range is [0,1]. Default value is 1.
3679 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3682 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3683 # 0 = BlockGuard disabled (default)
3684 # 1 = BlockGuard enabled
3685 # Value range is [0,1]. Default value is 0.
3687 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3690 # lpfc_prot_mask: i
3691 # - Bit mask of host protection capabilities used to register with the
3692 # SCSI mid-layer
3693 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3694 # - Allows you to ultimately specify which profiles to use
3695 # - Default will result in registering capabilities for all profiles.
3698 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
3699 SHOST_DIX_TYPE0_PROTECTION |
3700 SHOST_DIX_TYPE1_PROTECTION;
3702 module_param(lpfc_prot_mask, uint, S_IRUGO);
3703 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3706 # lpfc_prot_guard: i
3707 # - Bit mask of protection guard types to register with the SCSI mid-layer
3708 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3709 # - Allows you to ultimately specify which profiles to use
3710 # - Default will result in registering capabilities for all guard types
3713 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3714 module_param(lpfc_prot_guard, byte, S_IRUGO);
3715 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3718 * Delay initial NPort discovery when Clean Address bit is cleared in
3719 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3720 * This parameter can have value 0 or 1.
3721 * When this parameter is set to 0, no delay is added to the initial
3722 * discovery.
3723 * When this parameter is set to non-zero value, initial Nport discovery is
3724 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3725 * accept and FCID/Fabric name/Fabric portname is changed.
3726 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3727 * when Clean Address bit is cleared in FLOGI/FDISC
3728 * accept and FCID/Fabric name/Fabric portname is changed.
3729 * Default value is 0.
3731 int lpfc_delay_discovery;
3732 module_param(lpfc_delay_discovery, int, S_IRUGO);
3733 MODULE_PARM_DESC(lpfc_delay_discovery,
3734 "Delay NPort discovery when Clean Address bit is cleared. "
3735 "Allowed values: 0,1.");
3738 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3739 * This value can be set to values between 64 and 256. The default value is
3740 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3741 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3743 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3744 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3746 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3747 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3748 "Max Protection Scatter Gather Segment Count");
3750 struct device_attribute *lpfc_hba_attrs[] = {
3751 &dev_attr_bg_info,
3752 &dev_attr_bg_guard_err,
3753 &dev_attr_bg_apptag_err,
3754 &dev_attr_bg_reftag_err,
3755 &dev_attr_info,
3756 &dev_attr_serialnum,
3757 &dev_attr_modeldesc,
3758 &dev_attr_modelname,
3759 &dev_attr_programtype,
3760 &dev_attr_portnum,
3761 &dev_attr_fwrev,
3762 &dev_attr_hdw,
3763 &dev_attr_option_rom_version,
3764 &dev_attr_link_state,
3765 &dev_attr_num_discovered_ports,
3766 &dev_attr_menlo_mgmt_mode,
3767 &dev_attr_lpfc_drvr_version,
3768 &dev_attr_lpfc_enable_fip,
3769 &dev_attr_lpfc_temp_sensor,
3770 &dev_attr_lpfc_log_verbose,
3771 &dev_attr_lpfc_lun_queue_depth,
3772 &dev_attr_lpfc_tgt_queue_depth,
3773 &dev_attr_lpfc_hba_queue_depth,
3774 &dev_attr_lpfc_peer_port_login,
3775 &dev_attr_lpfc_nodev_tmo,
3776 &dev_attr_lpfc_devloss_tmo,
3777 &dev_attr_lpfc_fcp_class,
3778 &dev_attr_lpfc_use_adisc,
3779 &dev_attr_lpfc_ack0,
3780 &dev_attr_lpfc_topology,
3781 &dev_attr_lpfc_scan_down,
3782 &dev_attr_lpfc_link_speed,
3783 &dev_attr_lpfc_cr_delay,
3784 &dev_attr_lpfc_cr_count,
3785 &dev_attr_lpfc_multi_ring_support,
3786 &dev_attr_lpfc_multi_ring_rctl,
3787 &dev_attr_lpfc_multi_ring_type,
3788 &dev_attr_lpfc_fdmi_on,
3789 &dev_attr_lpfc_max_luns,
3790 &dev_attr_lpfc_enable_npiv,
3791 &dev_attr_lpfc_fcf_failover_policy,
3792 &dev_attr_lpfc_enable_rrq,
3793 &dev_attr_nport_evt_cnt,
3794 &dev_attr_board_mode,
3795 &dev_attr_max_vpi,
3796 &dev_attr_used_vpi,
3797 &dev_attr_max_rpi,
3798 &dev_attr_used_rpi,
3799 &dev_attr_max_xri,
3800 &dev_attr_used_xri,
3801 &dev_attr_npiv_info,
3802 &dev_attr_issue_reset,
3803 &dev_attr_lpfc_poll,
3804 &dev_attr_lpfc_poll_tmo,
3805 &dev_attr_lpfc_use_msi,
3806 &dev_attr_lpfc_fcp_imax,
3807 &dev_attr_lpfc_fcp_wq_count,
3808 &dev_attr_lpfc_fcp_eq_count,
3809 &dev_attr_lpfc_enable_bg,
3810 &dev_attr_lpfc_soft_wwnn,
3811 &dev_attr_lpfc_soft_wwpn,
3812 &dev_attr_lpfc_soft_wwn_enable,
3813 &dev_attr_lpfc_enable_hba_reset,
3814 &dev_attr_lpfc_enable_hba_heartbeat,
3815 &dev_attr_lpfc_sg_seg_cnt,
3816 &dev_attr_lpfc_max_scsicmpl_time,
3817 &dev_attr_lpfc_stat_data_ctrl,
3818 &dev_attr_lpfc_prot_sg_seg_cnt,
3819 &dev_attr_lpfc_aer_support,
3820 &dev_attr_lpfc_aer_state_cleanup,
3821 &dev_attr_lpfc_sriov_nr_virtfn,
3822 &dev_attr_lpfc_suppress_link_up,
3823 &dev_attr_lpfc_iocb_cnt,
3824 &dev_attr_iocb_hw,
3825 &dev_attr_txq_hw,
3826 &dev_attr_txcmplq_hw,
3827 &dev_attr_lpfc_fips_level,
3828 &dev_attr_lpfc_fips_rev,
3829 &dev_attr_lpfc_dss,
3830 &dev_attr_lpfc_sriov_hw_max_virtfn,
3831 NULL,
3834 struct device_attribute *lpfc_vport_attrs[] = {
3835 &dev_attr_info,
3836 &dev_attr_link_state,
3837 &dev_attr_num_discovered_ports,
3838 &dev_attr_lpfc_drvr_version,
3839 &dev_attr_lpfc_log_verbose,
3840 &dev_attr_lpfc_lun_queue_depth,
3841 &dev_attr_lpfc_tgt_queue_depth,
3842 &dev_attr_lpfc_nodev_tmo,
3843 &dev_attr_lpfc_devloss_tmo,
3844 &dev_attr_lpfc_hba_queue_depth,
3845 &dev_attr_lpfc_peer_port_login,
3846 &dev_attr_lpfc_restrict_login,
3847 &dev_attr_lpfc_fcp_class,
3848 &dev_attr_lpfc_use_adisc,
3849 &dev_attr_lpfc_fdmi_on,
3850 &dev_attr_lpfc_max_luns,
3851 &dev_attr_nport_evt_cnt,
3852 &dev_attr_npiv_info,
3853 &dev_attr_lpfc_enable_da_id,
3854 &dev_attr_lpfc_max_scsicmpl_time,
3855 &dev_attr_lpfc_stat_data_ctrl,
3856 &dev_attr_lpfc_static_vport,
3857 &dev_attr_lpfc_fips_level,
3858 &dev_attr_lpfc_fips_rev,
3859 NULL,
3863 * sysfs_ctlreg_write - Write method for writing to ctlreg
3864 * @filp: open sysfs file
3865 * @kobj: kernel kobject that contains the kernel class device.
3866 * @bin_attr: kernel attributes passed to us.
3867 * @buf: contains the data to be written to the adapter IOREG space.
3868 * @off: offset into buffer to beginning of data.
3869 * @count: bytes to transfer.
3871 * Description:
3872 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3873 * Uses the adapter io control registers to send buf contents to the adapter.
3875 * Returns:
3876 * -ERANGE off and count combo out of range
3877 * -EINVAL off, count or buff address invalid
3878 * -EPERM adapter is offline
3879 * value of count, buf contents written
3881 static ssize_t
3882 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3883 struct bin_attribute *bin_attr,
3884 char *buf, loff_t off, size_t count)
3886 size_t buf_off;
3887 struct device *dev = container_of(kobj, struct device, kobj);
3888 struct Scsi_Host *shost = class_to_shost(dev);
3889 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3890 struct lpfc_hba *phba = vport->phba;
3892 if (phba->sli_rev >= LPFC_SLI_REV4)
3893 return -EPERM;
3895 if ((off + count) > FF_REG_AREA_SIZE)
3896 return -ERANGE;
3898 if (count <= LPFC_REG_WRITE_KEY_SIZE)
3899 return 0;
3901 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3902 return -EINVAL;
3904 /* This is to protect HBA registers from accidental writes. */
3905 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
3906 return -EINVAL;
3908 if (!(vport->fc_flag & FC_OFFLINE_MODE))
3909 return -EPERM;
3911 spin_lock_irq(&phba->hbalock);
3912 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
3913 buf_off += sizeof(uint32_t))
3914 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
3915 phba->ctrl_regs_memmap_p + off + buf_off);
3917 spin_unlock_irq(&phba->hbalock);
3919 return count;
3923 * sysfs_ctlreg_read - Read method for reading from ctlreg
3924 * @filp: open sysfs file
3925 * @kobj: kernel kobject that contains the kernel class device.
3926 * @bin_attr: kernel attributes passed to us.
3927 * @buf: if successful contains the data from the adapter IOREG space.
3928 * @off: offset into buffer to beginning of data.
3929 * @count: bytes to transfer.
3931 * Description:
3932 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3933 * Uses the adapter io control registers to read data into buf.
3935 * Returns:
3936 * -ERANGE off and count combo out of range
3937 * -EINVAL off, count or buff address invalid
3938 * value of count, buf contents read
3940 static ssize_t
3941 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3942 struct bin_attribute *bin_attr,
3943 char *buf, loff_t off, size_t count)
3945 size_t buf_off;
3946 uint32_t * tmp_ptr;
3947 struct device *dev = container_of(kobj, struct device, kobj);
3948 struct Scsi_Host *shost = class_to_shost(dev);
3949 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3950 struct lpfc_hba *phba = vport->phba;
3952 if (phba->sli_rev >= LPFC_SLI_REV4)
3953 return -EPERM;
3955 if (off > FF_REG_AREA_SIZE)
3956 return -ERANGE;
3958 if ((off + count) > FF_REG_AREA_SIZE)
3959 count = FF_REG_AREA_SIZE - off;
3961 if (count == 0) return 0;
3963 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3964 return -EINVAL;
3966 spin_lock_irq(&phba->hbalock);
3968 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3969 tmp_ptr = (uint32_t *)(buf + buf_off);
3970 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3973 spin_unlock_irq(&phba->hbalock);
3975 return count;
3978 static struct bin_attribute sysfs_ctlreg_attr = {
3979 .attr = {
3980 .name = "ctlreg",
3981 .mode = S_IRUSR | S_IWUSR,
3983 .size = 256,
3984 .read = sysfs_ctlreg_read,
3985 .write = sysfs_ctlreg_write,
3989 * sysfs_mbox_idle - frees the sysfs mailbox
3990 * @phba: lpfc_hba pointer
3992 static void
3993 sysfs_mbox_idle(struct lpfc_hba *phba)
3995 phba->sysfs_mbox.state = SMBOX_IDLE;
3996 phba->sysfs_mbox.offset = 0;
3998 if (phba->sysfs_mbox.mbox) {
3999 mempool_free(phba->sysfs_mbox.mbox,
4000 phba->mbox_mem_pool);
4001 phba->sysfs_mbox.mbox = NULL;
4006 * sysfs_mbox_write - Write method for writing information via mbox
4007 * @filp: open sysfs file
4008 * @kobj: kernel kobject that contains the kernel class device.
4009 * @bin_attr: kernel attributes passed to us.
4010 * @buf: contains the data to be written to sysfs mbox.
4011 * @off: offset into buffer to beginning of data.
4012 * @count: bytes to transfer.
4014 * Description:
4015 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4016 * Uses the sysfs mbox to send buf contents to the adapter.
4018 * Returns:
4019 * -ERANGE off and count combo out of range
4020 * -EINVAL off, count or buff address invalid
4021 * zero if count is zero
4022 * -EPERM adapter is offline
4023 * -ENOMEM failed to allocate memory for the mail box
4024 * -EAGAIN offset, state or mbox is NULL
4025 * count number of bytes transferred
4027 static ssize_t
4028 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4029 struct bin_attribute *bin_attr,
4030 char *buf, loff_t off, size_t count)
4032 struct device *dev = container_of(kobj, struct device, kobj);
4033 struct Scsi_Host *shost = class_to_shost(dev);
4034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4035 struct lpfc_hba *phba = vport->phba;
4036 struct lpfcMboxq *mbox = NULL;
4038 if ((count + off) > MAILBOX_CMD_SIZE)
4039 return -ERANGE;
4041 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4042 return -EINVAL;
4044 if (count == 0)
4045 return 0;
4047 if (off == 0) {
4048 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4049 if (!mbox)
4050 return -ENOMEM;
4051 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
4054 spin_lock_irq(&phba->hbalock);
4056 if (off == 0) {
4057 if (phba->sysfs_mbox.mbox)
4058 mempool_free(mbox, phba->mbox_mem_pool);
4059 else
4060 phba->sysfs_mbox.mbox = mbox;
4061 phba->sysfs_mbox.state = SMBOX_WRITING;
4062 } else {
4063 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
4064 phba->sysfs_mbox.offset != off ||
4065 phba->sysfs_mbox.mbox == NULL) {
4066 sysfs_mbox_idle(phba);
4067 spin_unlock_irq(&phba->hbalock);
4068 return -EAGAIN;
4072 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
4073 buf, count);
4075 phba->sysfs_mbox.offset = off + count;
4077 spin_unlock_irq(&phba->hbalock);
4079 return count;
4083 * sysfs_mbox_read - Read method for reading information via mbox
4084 * @filp: open sysfs file
4085 * @kobj: kernel kobject that contains the kernel class device.
4086 * @bin_attr: kernel attributes passed to us.
4087 * @buf: contains the data to be read from sysfs mbox.
4088 * @off: offset into buffer to beginning of data.
4089 * @count: bytes to transfer.
4091 * Description:
4092 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
4093 * Uses the sysfs mbox to receive data from to the adapter.
4095 * Returns:
4096 * -ERANGE off greater than mailbox command size
4097 * -EINVAL off, count or buff address invalid
4098 * zero if off and count are zero
4099 * -EACCES adapter over temp
4100 * -EPERM garbage can value to catch a multitude of errors
4101 * -EAGAIN management IO not permitted, state or off error
4102 * -ETIME mailbox timeout
4103 * -ENODEV mailbox error
4104 * count number of bytes transferred
4106 static ssize_t
4107 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4108 struct bin_attribute *bin_attr,
4109 char *buf, loff_t off, size_t count)
4111 struct device *dev = container_of(kobj, struct device, kobj);
4112 struct Scsi_Host *shost = class_to_shost(dev);
4113 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4114 struct lpfc_hba *phba = vport->phba;
4115 int rc;
4116 MAILBOX_t *pmb;
4118 if (off > MAILBOX_CMD_SIZE)
4119 return -ERANGE;
4121 if ((count + off) > MAILBOX_CMD_SIZE)
4122 count = MAILBOX_CMD_SIZE - off;
4124 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4125 return -EINVAL;
4127 if (off && count == 0)
4128 return 0;
4130 spin_lock_irq(&phba->hbalock);
4132 if (phba->over_temp_state == HBA_OVER_TEMP) {
4133 sysfs_mbox_idle(phba);
4134 spin_unlock_irq(&phba->hbalock);
4135 return -EACCES;
4138 if (off == 0 &&
4139 phba->sysfs_mbox.state == SMBOX_WRITING &&
4140 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
4141 pmb = &phba->sysfs_mbox.mbox->u.mb;
4142 switch (pmb->mbxCommand) {
4143 /* Offline only */
4144 case MBX_INIT_LINK:
4145 case MBX_DOWN_LINK:
4146 case MBX_CONFIG_LINK:
4147 case MBX_CONFIG_RING:
4148 case MBX_RESET_RING:
4149 case MBX_UNREG_LOGIN:
4150 case MBX_CLEAR_LA:
4151 case MBX_DUMP_CONTEXT:
4152 case MBX_RUN_DIAGS:
4153 case MBX_RESTART:
4154 case MBX_SET_MASK:
4155 case MBX_SET_DEBUG:
4156 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
4157 printk(KERN_WARNING "mbox_read:Command 0x%x "
4158 "is illegal in on-line state\n",
4159 pmb->mbxCommand);
4160 sysfs_mbox_idle(phba);
4161 spin_unlock_irq(&phba->hbalock);
4162 return -EPERM;
4164 case MBX_WRITE_NV:
4165 case MBX_WRITE_VPARMS:
4166 case MBX_LOAD_SM:
4167 case MBX_READ_NV:
4168 case MBX_READ_CONFIG:
4169 case MBX_READ_RCONFIG:
4170 case MBX_READ_STATUS:
4171 case MBX_READ_XRI:
4172 case MBX_READ_REV:
4173 case MBX_READ_LNK_STAT:
4174 case MBX_DUMP_MEMORY:
4175 case MBX_DOWN_LOAD:
4176 case MBX_UPDATE_CFG:
4177 case MBX_KILL_BOARD:
4178 case MBX_LOAD_AREA:
4179 case MBX_LOAD_EXP_ROM:
4180 case MBX_BEACON:
4181 case MBX_DEL_LD_ENTRY:
4182 case MBX_SET_VARIABLE:
4183 case MBX_WRITE_WWN:
4184 case MBX_PORT_CAPABILITIES:
4185 case MBX_PORT_IOV_CONTROL:
4186 break;
4187 case MBX_SECURITY_MGMT:
4188 case MBX_AUTH_PORT:
4189 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
4190 printk(KERN_WARNING "mbox_read:Command 0x%x "
4191 "is not permitted\n", pmb->mbxCommand);
4192 sysfs_mbox_idle(phba);
4193 spin_unlock_irq(&phba->hbalock);
4194 return -EPERM;
4196 break;
4197 case MBX_READ_SPARM64:
4198 case MBX_READ_TOPOLOGY:
4199 case MBX_REG_LOGIN:
4200 case MBX_REG_LOGIN64:
4201 case MBX_CONFIG_PORT:
4202 case MBX_RUN_BIU_DIAG:
4203 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
4204 pmb->mbxCommand);
4205 sysfs_mbox_idle(phba);
4206 spin_unlock_irq(&phba->hbalock);
4207 return -EPERM;
4208 default:
4209 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
4210 pmb->mbxCommand);
4211 sysfs_mbox_idle(phba);
4212 spin_unlock_irq(&phba->hbalock);
4213 return -EPERM;
4216 /* If HBA encountered an error attention, allow only DUMP
4217 * or RESTART mailbox commands until the HBA is restarted.
4219 if (phba->pport->stopped &&
4220 pmb->mbxCommand != MBX_DUMP_MEMORY &&
4221 pmb->mbxCommand != MBX_RESTART &&
4222 pmb->mbxCommand != MBX_WRITE_VPARMS &&
4223 pmb->mbxCommand != MBX_WRITE_WWN)
4224 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
4225 "1259 mbox: Issued mailbox cmd "
4226 "0x%x while in stopped state.\n",
4227 pmb->mbxCommand);
4229 phba->sysfs_mbox.mbox->vport = vport;
4231 /* Don't allow mailbox commands to be sent when blocked
4232 * or when in the middle of discovery
4234 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
4235 sysfs_mbox_idle(phba);
4236 spin_unlock_irq(&phba->hbalock);
4237 return -EAGAIN;
4240 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4241 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
4243 spin_unlock_irq(&phba->hbalock);
4244 rc = lpfc_sli_issue_mbox (phba,
4245 phba->sysfs_mbox.mbox,
4246 MBX_POLL);
4247 spin_lock_irq(&phba->hbalock);
4249 } else {
4250 spin_unlock_irq(&phba->hbalock);
4251 rc = lpfc_sli_issue_mbox_wait (phba,
4252 phba->sysfs_mbox.mbox,
4253 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
4254 spin_lock_irq(&phba->hbalock);
4257 if (rc != MBX_SUCCESS) {
4258 if (rc == MBX_TIMEOUT) {
4259 phba->sysfs_mbox.mbox = NULL;
4261 sysfs_mbox_idle(phba);
4262 spin_unlock_irq(&phba->hbalock);
4263 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
4265 phba->sysfs_mbox.state = SMBOX_READING;
4267 else if (phba->sysfs_mbox.offset != off ||
4268 phba->sysfs_mbox.state != SMBOX_READING) {
4269 printk(KERN_WARNING "mbox_read: Bad State\n");
4270 sysfs_mbox_idle(phba);
4271 spin_unlock_irq(&phba->hbalock);
4272 return -EAGAIN;
4275 memcpy(buf, (uint8_t *) &pmb + off, count);
4277 phba->sysfs_mbox.offset = off + count;
4279 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
4280 sysfs_mbox_idle(phba);
4282 spin_unlock_irq(&phba->hbalock);
4284 return count;
4287 static struct bin_attribute sysfs_mbox_attr = {
4288 .attr = {
4289 .name = "mbox",
4290 .mode = S_IRUSR | S_IWUSR,
4292 .size = MAILBOX_SYSFS_MAX,
4293 .read = sysfs_mbox_read,
4294 .write = sysfs_mbox_write,
4298 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
4299 * @vport: address of lpfc vport structure.
4301 * Return codes:
4302 * zero on success
4303 * error return code from sysfs_create_bin_file()
4306 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4308 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4309 int error;
4311 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4312 &sysfs_drvr_stat_data_attr);
4314 /* Virtual ports do not need ctrl_reg and mbox */
4315 if (error || vport->port_type == LPFC_NPIV_PORT)
4316 goto out;
4318 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4319 &sysfs_ctlreg_attr);
4320 if (error)
4321 goto out_remove_stat_attr;
4323 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4324 &sysfs_mbox_attr);
4325 if (error)
4326 goto out_remove_ctlreg_attr;
4328 return 0;
4329 out_remove_ctlreg_attr:
4330 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4331 out_remove_stat_attr:
4332 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4333 &sysfs_drvr_stat_data_attr);
4334 out:
4335 return error;
4339 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4340 * @vport: address of lpfc vport structure.
4342 void
4343 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4345 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4346 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4347 &sysfs_drvr_stat_data_attr);
4348 /* Virtual ports do not need ctrl_reg and mbox */
4349 if (vport->port_type == LPFC_NPIV_PORT)
4350 return;
4351 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4352 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4357 * Dynamic FC Host Attributes Support
4361 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4362 * @shost: kernel scsi host pointer.
4364 static void
4365 lpfc_get_host_port_id(struct Scsi_Host *shost)
4367 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4369 /* note: fc_myDID already in cpu endianness */
4370 fc_host_port_id(shost) = vport->fc_myDID;
4374 * lpfc_get_host_port_type - Set the value of the scsi host port type
4375 * @shost: kernel scsi host pointer.
4377 static void
4378 lpfc_get_host_port_type(struct Scsi_Host *shost)
4380 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4381 struct lpfc_hba *phba = vport->phba;
4383 spin_lock_irq(shost->host_lock);
4385 if (vport->port_type == LPFC_NPIV_PORT) {
4386 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4387 } else if (lpfc_is_link_up(phba)) {
4388 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4389 if (vport->fc_flag & FC_PUBLIC_LOOP)
4390 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4391 else
4392 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4393 } else {
4394 if (vport->fc_flag & FC_FABRIC)
4395 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4396 else
4397 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4399 } else
4400 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4402 spin_unlock_irq(shost->host_lock);
4406 * lpfc_get_host_port_state - Set the value of the scsi host port state
4407 * @shost: kernel scsi host pointer.
4409 static void
4410 lpfc_get_host_port_state(struct Scsi_Host *shost)
4412 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4413 struct lpfc_hba *phba = vport->phba;
4415 spin_lock_irq(shost->host_lock);
4417 if (vport->fc_flag & FC_OFFLINE_MODE)
4418 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4419 else {
4420 switch (phba->link_state) {
4421 case LPFC_LINK_UNKNOWN:
4422 case LPFC_LINK_DOWN:
4423 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4424 break;
4425 case LPFC_LINK_UP:
4426 case LPFC_CLEAR_LA:
4427 case LPFC_HBA_READY:
4428 /* Links up, beyond this port_type reports state */
4429 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4430 break;
4431 case LPFC_HBA_ERROR:
4432 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4433 break;
4434 default:
4435 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4436 break;
4440 spin_unlock_irq(shost->host_lock);
4444 * lpfc_get_host_speed - Set the value of the scsi host speed
4445 * @shost: kernel scsi host pointer.
4447 static void
4448 lpfc_get_host_speed(struct Scsi_Host *shost)
4450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4451 struct lpfc_hba *phba = vport->phba;
4453 spin_lock_irq(shost->host_lock);
4455 if (lpfc_is_link_up(phba)) {
4456 switch(phba->fc_linkspeed) {
4457 case LPFC_LINK_SPEED_1GHZ:
4458 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4459 break;
4460 case LPFC_LINK_SPEED_2GHZ:
4461 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4462 break;
4463 case LPFC_LINK_SPEED_4GHZ:
4464 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4465 break;
4466 case LPFC_LINK_SPEED_8GHZ:
4467 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4468 break;
4469 case LPFC_LINK_SPEED_10GHZ:
4470 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4471 break;
4472 case LPFC_LINK_SPEED_16GHZ:
4473 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4474 break;
4475 default:
4476 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4477 break;
4479 } else
4480 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4482 spin_unlock_irq(shost->host_lock);
4486 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4487 * @shost: kernel scsi host pointer.
4489 static void
4490 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4492 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4493 struct lpfc_hba *phba = vport->phba;
4494 u64 node_name;
4496 spin_lock_irq(shost->host_lock);
4498 if ((vport->fc_flag & FC_FABRIC) ||
4499 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4500 (vport->fc_flag & FC_PUBLIC_LOOP)))
4501 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4502 else
4503 /* fabric is local port if there is no F/FL_Port */
4504 node_name = 0;
4506 spin_unlock_irq(shost->host_lock);
4508 fc_host_fabric_name(shost) = node_name;
4512 * lpfc_get_stats - Return statistical information about the adapter
4513 * @shost: kernel scsi host pointer.
4515 * Notes:
4516 * NULL on error for link down, no mbox pool, sli2 active,
4517 * management not allowed, memory allocation error, or mbox error.
4519 * Returns:
4520 * NULL for error
4521 * address of the adapter host statistics
4523 static struct fc_host_statistics *
4524 lpfc_get_stats(struct Scsi_Host *shost)
4526 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4527 struct lpfc_hba *phba = vport->phba;
4528 struct lpfc_sli *psli = &phba->sli;
4529 struct fc_host_statistics *hs = &phba->link_stats;
4530 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4531 LPFC_MBOXQ_t *pmboxq;
4532 MAILBOX_t *pmb;
4533 unsigned long seconds;
4534 int rc = 0;
4537 * prevent udev from issuing mailbox commands until the port is
4538 * configured.
4540 if (phba->link_state < LPFC_LINK_DOWN ||
4541 !phba->mbox_mem_pool ||
4542 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4543 return NULL;
4545 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4546 return NULL;
4548 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4549 if (!pmboxq)
4550 return NULL;
4551 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4553 pmb = &pmboxq->u.mb;
4554 pmb->mbxCommand = MBX_READ_STATUS;
4555 pmb->mbxOwner = OWN_HOST;
4556 pmboxq->context1 = NULL;
4557 pmboxq->vport = vport;
4559 if (vport->fc_flag & FC_OFFLINE_MODE)
4560 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4561 else
4562 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4564 if (rc != MBX_SUCCESS) {
4565 if (rc != MBX_TIMEOUT)
4566 mempool_free(pmboxq, phba->mbox_mem_pool);
4567 return NULL;
4570 memset(hs, 0, sizeof (struct fc_host_statistics));
4572 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4573 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4574 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4575 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4577 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4578 pmb->mbxCommand = MBX_READ_LNK_STAT;
4579 pmb->mbxOwner = OWN_HOST;
4580 pmboxq->context1 = NULL;
4581 pmboxq->vport = vport;
4583 if (vport->fc_flag & FC_OFFLINE_MODE)
4584 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4585 else
4586 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4588 if (rc != MBX_SUCCESS) {
4589 if (rc != MBX_TIMEOUT)
4590 mempool_free(pmboxq, phba->mbox_mem_pool);
4591 return NULL;
4594 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4595 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4596 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4597 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4598 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4599 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4600 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4602 hs->link_failure_count -= lso->link_failure_count;
4603 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4604 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4605 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4606 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4607 hs->invalid_crc_count -= lso->invalid_crc_count;
4608 hs->error_frames -= lso->error_frames;
4610 if (phba->hba_flag & HBA_FCOE_MODE) {
4611 hs->lip_count = -1;
4612 hs->nos_count = (phba->link_events >> 1);
4613 hs->nos_count -= lso->link_events;
4614 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4615 hs->lip_count = (phba->fc_eventTag >> 1);
4616 hs->lip_count -= lso->link_events;
4617 hs->nos_count = -1;
4618 } else {
4619 hs->lip_count = -1;
4620 hs->nos_count = (phba->fc_eventTag >> 1);
4621 hs->nos_count -= lso->link_events;
4624 hs->dumped_frames = -1;
4626 seconds = get_seconds();
4627 if (seconds < psli->stats_start)
4628 hs->seconds_since_last_reset = seconds +
4629 ((unsigned long)-1 - psli->stats_start);
4630 else
4631 hs->seconds_since_last_reset = seconds - psli->stats_start;
4633 mempool_free(pmboxq, phba->mbox_mem_pool);
4635 return hs;
4639 * lpfc_reset_stats - Copy the adapter link stats information
4640 * @shost: kernel scsi host pointer.
4642 static void
4643 lpfc_reset_stats(struct Scsi_Host *shost)
4645 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4646 struct lpfc_hba *phba = vport->phba;
4647 struct lpfc_sli *psli = &phba->sli;
4648 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4649 LPFC_MBOXQ_t *pmboxq;
4650 MAILBOX_t *pmb;
4651 int rc = 0;
4653 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4654 return;
4656 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4657 if (!pmboxq)
4658 return;
4659 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4661 pmb = &pmboxq->u.mb;
4662 pmb->mbxCommand = MBX_READ_STATUS;
4663 pmb->mbxOwner = OWN_HOST;
4664 pmb->un.varWords[0] = 0x1; /* reset request */
4665 pmboxq->context1 = NULL;
4666 pmboxq->vport = vport;
4668 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4669 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4670 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4671 else
4672 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4674 if (rc != MBX_SUCCESS) {
4675 if (rc != MBX_TIMEOUT)
4676 mempool_free(pmboxq, phba->mbox_mem_pool);
4677 return;
4680 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4681 pmb->mbxCommand = MBX_READ_LNK_STAT;
4682 pmb->mbxOwner = OWN_HOST;
4683 pmboxq->context1 = NULL;
4684 pmboxq->vport = vport;
4686 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4687 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4688 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4689 else
4690 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4692 if (rc != MBX_SUCCESS) {
4693 if (rc != MBX_TIMEOUT)
4694 mempool_free( pmboxq, phba->mbox_mem_pool);
4695 return;
4698 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4699 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4700 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4701 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4702 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4703 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4704 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4705 if (phba->hba_flag & HBA_FCOE_MODE)
4706 lso->link_events = (phba->link_events >> 1);
4707 else
4708 lso->link_events = (phba->fc_eventTag >> 1);
4710 psli->stats_start = get_seconds();
4712 mempool_free(pmboxq, phba->mbox_mem_pool);
4714 return;
4718 * The LPFC driver treats linkdown handling as target loss events so there
4719 * are no sysfs handlers for link_down_tmo.
4723 * lpfc_get_node_by_target - Return the nodelist for a target
4724 * @starget: kernel scsi target pointer.
4726 * Returns:
4727 * address of the node list if found
4728 * NULL target not found
4730 static struct lpfc_nodelist *
4731 lpfc_get_node_by_target(struct scsi_target *starget)
4733 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4735 struct lpfc_nodelist *ndlp;
4737 spin_lock_irq(shost->host_lock);
4738 /* Search for this, mapped, target ID */
4739 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4740 if (NLP_CHK_NODE_ACT(ndlp) &&
4741 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4742 starget->id == ndlp->nlp_sid) {
4743 spin_unlock_irq(shost->host_lock);
4744 return ndlp;
4747 spin_unlock_irq(shost->host_lock);
4748 return NULL;
4752 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4753 * @starget: kernel scsi target pointer.
4755 static void
4756 lpfc_get_starget_port_id(struct scsi_target *starget)
4758 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4760 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4764 * lpfc_get_starget_node_name - Set the target node name
4765 * @starget: kernel scsi target pointer.
4767 * Description: Set the target node name to the ndlp node name wwn or zero.
4769 static void
4770 lpfc_get_starget_node_name(struct scsi_target *starget)
4772 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4774 fc_starget_node_name(starget) =
4775 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4779 * lpfc_get_starget_port_name - Set the target port name
4780 * @starget: kernel scsi target pointer.
4782 * Description: set the target port name to the ndlp port name wwn or zero.
4784 static void
4785 lpfc_get_starget_port_name(struct scsi_target *starget)
4787 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4789 fc_starget_port_name(starget) =
4790 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4794 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4795 * @rport: fc rport address.
4796 * @timeout: new value for dev loss tmo.
4798 * Description:
4799 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4800 * dev_loss_tmo to one.
4802 static void
4803 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4805 if (timeout)
4806 rport->dev_loss_tmo = timeout;
4807 else
4808 rport->dev_loss_tmo = 1;
4812 * lpfc_rport_show_function - Return rport target information
4814 * Description:
4815 * Macro that uses field to generate a function with the name lpfc_show_rport_
4817 * lpfc_show_rport_##field: returns the bytes formatted in buf
4818 * @cdev: class converted to an fc_rport.
4819 * @buf: on return contains the target_field or zero.
4821 * Returns: size of formatted string.
4823 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4824 static ssize_t \
4825 lpfc_show_rport_##field (struct device *dev, \
4826 struct device_attribute *attr, \
4827 char *buf) \
4829 struct fc_rport *rport = transport_class_to_rport(dev); \
4830 struct lpfc_rport_data *rdata = rport->hostdata; \
4831 return snprintf(buf, sz, format_string, \
4832 (rdata->target) ? cast rdata->target->field : 0); \
4835 #define lpfc_rport_rd_attr(field, format_string, sz) \
4836 lpfc_rport_show_function(field, format_string, sz, ) \
4837 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4840 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4841 * @fc_vport: The fc_vport who's symbolic name has been changed.
4843 * Description:
4844 * This function is called by the transport after the @fc_vport's symbolic name
4845 * has been changed. This function re-registers the symbolic name with the
4846 * switch to propagate the change into the fabric if the vport is active.
4848 static void
4849 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4851 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4853 if (vport->port_state == LPFC_VPORT_READY)
4854 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4858 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4859 * @phba: Pointer to lpfc_hba struct.
4861 * This function is called by the lpfc_get_cfgparam() routine to set the
4862 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4863 * log message according to the module's lpfc_log_verbose parameter setting
4864 * before hba port or vport created.
4866 static void
4867 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4869 phba->cfg_log_verbose = verbose;
4872 struct fc_function_template lpfc_transport_functions = {
4873 /* fixed attributes the driver supports */
4874 .show_host_node_name = 1,
4875 .show_host_port_name = 1,
4876 .show_host_supported_classes = 1,
4877 .show_host_supported_fc4s = 1,
4878 .show_host_supported_speeds = 1,
4879 .show_host_maxframe_size = 1,
4880 .show_host_symbolic_name = 1,
4882 /* dynamic attributes the driver supports */
4883 .get_host_port_id = lpfc_get_host_port_id,
4884 .show_host_port_id = 1,
4886 .get_host_port_type = lpfc_get_host_port_type,
4887 .show_host_port_type = 1,
4889 .get_host_port_state = lpfc_get_host_port_state,
4890 .show_host_port_state = 1,
4892 /* active_fc4s is shown but doesn't change (thus no get function) */
4893 .show_host_active_fc4s = 1,
4895 .get_host_speed = lpfc_get_host_speed,
4896 .show_host_speed = 1,
4898 .get_host_fabric_name = lpfc_get_host_fabric_name,
4899 .show_host_fabric_name = 1,
4902 * The LPFC driver treats linkdown handling as target loss events
4903 * so there are no sysfs handlers for link_down_tmo.
4906 .get_fc_host_stats = lpfc_get_stats,
4907 .reset_fc_host_stats = lpfc_reset_stats,
4909 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4910 .show_rport_maxframe_size = 1,
4911 .show_rport_supported_classes = 1,
4913 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4914 .show_rport_dev_loss_tmo = 1,
4916 .get_starget_port_id = lpfc_get_starget_port_id,
4917 .show_starget_port_id = 1,
4919 .get_starget_node_name = lpfc_get_starget_node_name,
4920 .show_starget_node_name = 1,
4922 .get_starget_port_name = lpfc_get_starget_port_name,
4923 .show_starget_port_name = 1,
4925 .issue_fc_host_lip = lpfc_issue_lip,
4926 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4927 .terminate_rport_io = lpfc_terminate_rport_io,
4929 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4931 .vport_disable = lpfc_vport_disable,
4933 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4935 .bsg_request = lpfc_bsg_request,
4936 .bsg_timeout = lpfc_bsg_timeout,
4939 struct fc_function_template lpfc_vport_transport_functions = {
4940 /* fixed attributes the driver supports */
4941 .show_host_node_name = 1,
4942 .show_host_port_name = 1,
4943 .show_host_supported_classes = 1,
4944 .show_host_supported_fc4s = 1,
4945 .show_host_supported_speeds = 1,
4946 .show_host_maxframe_size = 1,
4947 .show_host_symbolic_name = 1,
4949 /* dynamic attributes the driver supports */
4950 .get_host_port_id = lpfc_get_host_port_id,
4951 .show_host_port_id = 1,
4953 .get_host_port_type = lpfc_get_host_port_type,
4954 .show_host_port_type = 1,
4956 .get_host_port_state = lpfc_get_host_port_state,
4957 .show_host_port_state = 1,
4959 /* active_fc4s is shown but doesn't change (thus no get function) */
4960 .show_host_active_fc4s = 1,
4962 .get_host_speed = lpfc_get_host_speed,
4963 .show_host_speed = 1,
4965 .get_host_fabric_name = lpfc_get_host_fabric_name,
4966 .show_host_fabric_name = 1,
4969 * The LPFC driver treats linkdown handling as target loss events
4970 * so there are no sysfs handlers for link_down_tmo.
4973 .get_fc_host_stats = lpfc_get_stats,
4974 .reset_fc_host_stats = lpfc_reset_stats,
4976 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4977 .show_rport_maxframe_size = 1,
4978 .show_rport_supported_classes = 1,
4980 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4981 .show_rport_dev_loss_tmo = 1,
4983 .get_starget_port_id = lpfc_get_starget_port_id,
4984 .show_starget_port_id = 1,
4986 .get_starget_node_name = lpfc_get_starget_node_name,
4987 .show_starget_node_name = 1,
4989 .get_starget_port_name = lpfc_get_starget_port_name,
4990 .show_starget_port_name = 1,
4992 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4993 .terminate_rport_io = lpfc_terminate_rport_io,
4995 .vport_disable = lpfc_vport_disable,
4997 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5001 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
5002 * @phba: lpfc_hba pointer.
5004 void
5005 lpfc_get_cfgparam(struct lpfc_hba *phba)
5007 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5008 lpfc_cr_count_init(phba, lpfc_cr_count);
5009 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5010 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5011 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5012 lpfc_ack0_init(phba, lpfc_ack0);
5013 lpfc_topology_init(phba, lpfc_topology);
5014 lpfc_link_speed_init(phba, lpfc_link_speed);
5015 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5016 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5017 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5018 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5019 lpfc_use_msi_init(phba, lpfc_use_msi);
5020 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5021 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
5022 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
5023 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5024 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5025 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5026 if (phba->sli_rev == LPFC_SLI_REV4)
5027 phba->cfg_poll = 0;
5028 else
5029 phba->cfg_poll = lpfc_poll;
5030 phba->cfg_soft_wwnn = 0L;
5031 phba->cfg_soft_wwpn = 0L;
5032 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5033 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5034 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5035 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5036 lpfc_aer_support_init(phba, lpfc_aer_support);
5037 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5038 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5039 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5040 phba->cfg_enable_dss = 1;
5041 return;
5045 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
5046 * @vport: lpfc_vport pointer.
5048 void
5049 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5051 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5052 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5053 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5054 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5055 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5056 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5057 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5058 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5059 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5060 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5061 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5062 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5063 lpfc_max_luns_init(vport, lpfc_max_luns);
5064 lpfc_scan_down_init(vport, lpfc_scan_down);
5065 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
5066 return;