[SCSI] lpfc 8.2.2 : Rework the lpfc_printf_log() macro
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / lpfc / lpfc_attr.c
blobc1cedc3d1b70d28060842b223fc0246ed3d30bea
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_tcq.h>
31 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_hw.h"
34 #include "lpfc_sli.h"
35 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
37 #include "lpfc.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_version.h"
40 #include "lpfc_compat.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
44 #define LPFC_DEF_DEVLOSS_TMO 30
45 #define LPFC_MIN_DEVLOSS_TMO 1
46 #define LPFC_MAX_DEVLOSS_TMO 255
48 static void
49 lpfc_jedec_to_ascii(int incr, char hdw[])
51 int i, j;
52 for (i = 0; i < 8; i++) {
53 j = (incr & 0xf);
54 if (j <= 9)
55 hdw[7 - i] = 0x30 + j;
56 else
57 hdw[7 - i] = 0x61 + j - 10;
58 incr = (incr >> 4);
60 hdw[8] = 0;
61 return;
64 static ssize_t
65 lpfc_drvr_version_show(struct class_device *cdev, char *buf)
67 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
70 static ssize_t
71 management_version_show(struct class_device *cdev, char *buf)
73 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
76 static ssize_t
77 lpfc_info_show(struct class_device *cdev, char *buf)
79 struct Scsi_Host *host = class_to_shost(cdev);
81 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
84 static ssize_t
85 lpfc_serialnum_show(struct class_device *cdev, char *buf)
87 struct Scsi_Host *shost = class_to_shost(cdev);
88 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
89 struct lpfc_hba *phba = vport->phba;
91 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
94 static ssize_t
95 lpfc_modeldesc_show(struct class_device *cdev, char *buf)
97 struct Scsi_Host *shost = class_to_shost(cdev);
98 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
99 struct lpfc_hba *phba = vport->phba;
101 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
104 static ssize_t
105 lpfc_modelname_show(struct class_device *cdev, char *buf)
107 struct Scsi_Host *shost = class_to_shost(cdev);
108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
114 static ssize_t
115 lpfc_programtype_show(struct class_device *cdev, char *buf)
117 struct Scsi_Host *shost = class_to_shost(cdev);
118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
119 struct lpfc_hba *phba = vport->phba;
121 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
124 static ssize_t
125 lpfc_vportnum_show(struct class_device *cdev, char *buf)
127 struct Scsi_Host *shost = class_to_shost(cdev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
134 static ssize_t
135 lpfc_fwrev_show(struct class_device *cdev, char *buf)
137 struct Scsi_Host *shost = class_to_shost(cdev);
138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
140 char fwrev[32];
142 lpfc_decode_firmware_rev(phba, fwrev, 1);
143 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
146 static ssize_t
147 lpfc_hdw_show(struct class_device *cdev, char *buf)
149 char hdw[9];
150 struct Scsi_Host *shost = class_to_shost(cdev);
151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
153 lpfc_vpd_t *vp = &phba->vpd;
155 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
156 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
158 static ssize_t
159 lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
161 struct Scsi_Host *shost = class_to_shost(cdev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
165 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
167 static ssize_t
168 lpfc_state_show(struct class_device *cdev, char *buf)
170 struct Scsi_Host *shost = class_to_shost(cdev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173 int len = 0;
175 switch (phba->link_state) {
176 case LPFC_LINK_UNKNOWN:
177 case LPFC_WARM_START:
178 case LPFC_INIT_START:
179 case LPFC_INIT_MBX_CMDS:
180 case LPFC_LINK_DOWN:
181 case LPFC_HBA_ERROR:
182 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
183 break;
184 case LPFC_LINK_UP:
185 case LPFC_CLEAR_LA:
186 case LPFC_HBA_READY:
187 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
189 switch (vport->port_state) {
190 len += snprintf(buf + len, PAGE_SIZE-len,
191 "initializing\n");
192 break;
193 case LPFC_LOCAL_CFG_LINK:
194 len += snprintf(buf + len, PAGE_SIZE-len,
195 "Configuring Link\n");
196 break;
197 case LPFC_FDISC:
198 case LPFC_FLOGI:
199 case LPFC_FABRIC_CFG_LINK:
200 case LPFC_NS_REG:
201 case LPFC_NS_QRY:
202 case LPFC_BUILD_DISC_LIST:
203 case LPFC_DISC_AUTH:
204 len += snprintf(buf + len, PAGE_SIZE - len,
205 "Discovery\n");
206 break;
207 case LPFC_VPORT_READY:
208 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
209 break;
211 case LPFC_VPORT_FAILED:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
213 break;
215 case LPFC_VPORT_UNKNOWN:
216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "Unknown\n");
218 break;
221 if (phba->fc_topology == TOPOLOGY_LOOP) {
222 if (vport->fc_flag & FC_PUBLIC_LOOP)
223 len += snprintf(buf + len, PAGE_SIZE-len,
224 " Public Loop\n");
225 else
226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Private Loop\n");
228 } else {
229 if (vport->fc_flag & FC_FABRIC)
230 len += snprintf(buf + len, PAGE_SIZE-len,
231 " Fabric\n");
232 else
233 len += snprintf(buf + len, PAGE_SIZE-len,
234 " Point-2-Point\n");
238 return len;
241 static ssize_t
242 lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
244 struct Scsi_Host *shost = class_to_shost(cdev);
245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
247 return snprintf(buf, PAGE_SIZE, "%d\n",
248 vport->fc_map_cnt + vport->fc_unmap_cnt);
252 static int
253 lpfc_issue_lip(struct Scsi_Host *shost)
255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
256 struct lpfc_hba *phba = vport->phba;
257 LPFC_MBOXQ_t *pmboxq;
258 int mbxstatus = MBXERR_ERROR;
260 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
261 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
262 (vport->port_state != LPFC_VPORT_READY))
263 return -EPERM;
265 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
267 if (!pmboxq)
268 return -ENOMEM;
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
271 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
272 pmboxq->mb.mbxOwner = OWN_HOST;
274 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
276 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
277 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
278 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
279 phba->cfg_link_speed);
280 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
281 phba->fc_ratov * 2);
284 lpfc_set_loopback_flag(phba);
285 if (mbxstatus != MBX_TIMEOUT)
286 mempool_free(pmboxq, phba->mbox_mem_pool);
288 if (mbxstatus == MBXERR_ERROR)
289 return -EIO;
291 return 0;
294 static int
295 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
297 struct completion online_compl;
298 struct lpfc_sli_ring *pring;
299 struct lpfc_sli *psli;
300 int status = 0;
301 int cnt = 0;
302 int i;
304 init_completion(&online_compl);
305 lpfc_workq_post_event(phba, &status, &online_compl,
306 LPFC_EVT_OFFLINE_PREP);
307 wait_for_completion(&online_compl);
309 if (status != 0)
310 return -EIO;
312 psli = &phba->sli;
314 for (i = 0; i < psli->num_rings; i++) {
315 pring = &psli->ring[i];
316 /* The linkdown event takes 30 seconds to timeout. */
317 while (pring->txcmplq_cnt) {
318 msleep(10);
319 if (cnt++ > 3000) {
320 lpfc_printf_log(phba,
321 KERN_WARNING, LOG_INIT,
322 "0466 Outstanding IO when "
323 "bringing Adapter offline\n");
324 break;
329 init_completion(&online_compl);
330 lpfc_workq_post_event(phba, &status, &online_compl, type);
331 wait_for_completion(&online_compl);
333 if (status != 0)
334 return -EIO;
336 return 0;
339 static int
340 lpfc_selective_reset(struct lpfc_hba *phba)
342 struct completion online_compl;
343 int status = 0;
345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
347 if (status != 0)
348 return status;
350 init_completion(&online_compl);
351 lpfc_workq_post_event(phba, &status, &online_compl,
352 LPFC_EVT_ONLINE);
353 wait_for_completion(&online_compl);
355 if (status != 0)
356 return -EIO;
358 return 0;
361 static ssize_t
362 lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
364 struct Scsi_Host *shost = class_to_shost(cdev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
368 int status = -EINVAL;
370 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
371 status = lpfc_selective_reset(phba);
373 if (status == 0)
374 return strlen(buf);
375 else
376 return status;
379 static ssize_t
380 lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
382 struct Scsi_Host *shost = class_to_shost(cdev);
383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
384 struct lpfc_hba *phba = vport->phba;
386 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
389 static ssize_t
390 lpfc_board_mode_show(struct class_device *cdev, char *buf)
392 struct Scsi_Host *shost = class_to_shost(cdev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
395 char * state;
397 if (phba->link_state == LPFC_HBA_ERROR)
398 state = "error";
399 else if (phba->link_state == LPFC_WARM_START)
400 state = "warm start";
401 else if (phba->link_state == LPFC_INIT_START)
402 state = "offline";
403 else
404 state = "online";
406 return snprintf(buf, PAGE_SIZE, "%s\n", state);
409 static ssize_t
410 lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
412 struct Scsi_Host *shost = class_to_shost(cdev);
413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
414 struct lpfc_hba *phba = vport->phba;
415 struct completion online_compl;
416 int status=0;
418 init_completion(&online_compl);
420 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
421 lpfc_workq_post_event(phba, &status, &online_compl,
422 LPFC_EVT_ONLINE);
423 wait_for_completion(&online_compl);
424 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
425 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
426 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
427 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
428 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
429 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
430 else
431 return -EINVAL;
433 if (!status)
434 return strlen(buf);
435 else
436 return -EIO;
440 lpfc_get_hba_info(struct lpfc_hba *phba,
441 uint32_t *mxri, uint32_t *axri,
442 uint32_t *mrpi, uint32_t *arpi,
443 uint32_t *mvpi, uint32_t *avpi)
445 struct lpfc_sli *psli = &phba->sli;
446 LPFC_MBOXQ_t *pmboxq;
447 MAILBOX_t *pmb;
448 int rc = 0;
451 * prevent udev from issuing mailbox commands until the port is
452 * configured.
454 if (phba->link_state < LPFC_LINK_DOWN ||
455 !phba->mbox_mem_pool ||
456 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
457 return 0;
459 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
460 return 0;
462 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
463 if (!pmboxq)
464 return 0;
465 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
467 pmb = &pmboxq->mb;
468 pmb->mbxCommand = MBX_READ_CONFIG;
469 pmb->mbxOwner = OWN_HOST;
470 pmboxq->context1 = NULL;
472 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
473 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
474 rc = MBX_NOT_FINISHED;
475 else
476 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
478 if (rc != MBX_SUCCESS) {
479 if (rc != MBX_TIMEOUT)
480 mempool_free(pmboxq, phba->mbox_mem_pool);
481 return 0;
484 if (mrpi)
485 *mrpi = pmb->un.varRdConfig.max_rpi;
486 if (arpi)
487 *arpi = pmb->un.varRdConfig.avail_rpi;
488 if (mxri)
489 *mxri = pmb->un.varRdConfig.max_xri;
490 if (axri)
491 *axri = pmb->un.varRdConfig.avail_xri;
492 if (mvpi)
493 *mvpi = pmb->un.varRdConfig.max_vpi;
494 if (avpi)
495 *avpi = pmb->un.varRdConfig.avail_vpi;
497 mempool_free(pmboxq, phba->mbox_mem_pool);
498 return 1;
501 static ssize_t
502 lpfc_max_rpi_show(struct class_device *cdev, char *buf)
504 struct Scsi_Host *shost = class_to_shost(cdev);
505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
506 struct lpfc_hba *phba = vport->phba;
507 uint32_t cnt;
509 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
510 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
511 return snprintf(buf, PAGE_SIZE, "Unknown\n");
514 static ssize_t
515 lpfc_used_rpi_show(struct class_device *cdev, char *buf)
517 struct Scsi_Host *shost = class_to_shost(cdev);
518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
519 struct lpfc_hba *phba = vport->phba;
520 uint32_t cnt, acnt;
522 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
523 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
524 return snprintf(buf, PAGE_SIZE, "Unknown\n");
527 static ssize_t
528 lpfc_max_xri_show(struct class_device *cdev, char *buf)
530 struct Scsi_Host *shost = class_to_shost(cdev);
531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
532 struct lpfc_hba *phba = vport->phba;
533 uint32_t cnt;
535 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
536 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
537 return snprintf(buf, PAGE_SIZE, "Unknown\n");
540 static ssize_t
541 lpfc_used_xri_show(struct class_device *cdev, char *buf)
543 struct Scsi_Host *shost = class_to_shost(cdev);
544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
545 struct lpfc_hba *phba = vport->phba;
546 uint32_t cnt, acnt;
548 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
549 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
550 return snprintf(buf, PAGE_SIZE, "Unknown\n");
553 static ssize_t
554 lpfc_max_vpi_show(struct class_device *cdev, char *buf)
556 struct Scsi_Host *shost = class_to_shost(cdev);
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 uint32_t cnt;
561 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
562 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
563 return snprintf(buf, PAGE_SIZE, "Unknown\n");
566 static ssize_t
567 lpfc_used_vpi_show(struct class_device *cdev, char *buf)
569 struct Scsi_Host *shost = class_to_shost(cdev);
570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
572 uint32_t cnt, acnt;
574 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
575 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
576 return snprintf(buf, PAGE_SIZE, "Unknown\n");
579 static ssize_t
580 lpfc_npiv_info_show(struct class_device *cdev, char *buf)
582 struct Scsi_Host *shost = class_to_shost(cdev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
586 if (!(phba->max_vpi))
587 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
588 if (vport->port_type == LPFC_PHYSICAL_PORT)
589 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
590 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
593 static ssize_t
594 lpfc_poll_show(struct class_device *cdev, char *buf)
596 struct Scsi_Host *shost = class_to_shost(cdev);
597 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
598 struct lpfc_hba *phba = vport->phba;
600 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
603 static ssize_t
604 lpfc_poll_store(struct class_device *cdev, const char *buf,
605 size_t count)
607 struct Scsi_Host *shost = class_to_shost(cdev);
608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
609 struct lpfc_hba *phba = vport->phba;
610 uint32_t creg_val;
611 uint32_t old_val;
612 int val=0;
614 if (!isdigit(buf[0]))
615 return -EINVAL;
617 if (sscanf(buf, "%i", &val) != 1)
618 return -EINVAL;
620 if ((val & 0x3) != val)
621 return -EINVAL;
623 spin_lock_irq(&phba->hbalock);
625 old_val = phba->cfg_poll;
627 if (val & ENABLE_FCP_RING_POLLING) {
628 if ((val & DISABLE_FCP_RING_INT) &&
629 !(old_val & DISABLE_FCP_RING_INT)) {
630 creg_val = readl(phba->HCregaddr);
631 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
632 writel(creg_val, phba->HCregaddr);
633 readl(phba->HCregaddr); /* flush */
635 lpfc_poll_start_timer(phba);
637 } else if (val != 0x0) {
638 spin_unlock_irq(&phba->hbalock);
639 return -EINVAL;
642 if (!(val & DISABLE_FCP_RING_INT) &&
643 (old_val & DISABLE_FCP_RING_INT))
645 spin_unlock_irq(&phba->hbalock);
646 del_timer(&phba->fcp_poll_timer);
647 spin_lock_irq(&phba->hbalock);
648 creg_val = readl(phba->HCregaddr);
649 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
650 writel(creg_val, phba->HCregaddr);
651 readl(phba->HCregaddr); /* flush */
654 phba->cfg_poll = val;
656 spin_unlock_irq(&phba->hbalock);
658 return strlen(buf);
661 #define lpfc_param_show(attr) \
662 static ssize_t \
663 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
665 struct Scsi_Host *shost = class_to_shost(cdev);\
666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
667 struct lpfc_hba *phba = vport->phba;\
668 int val = 0;\
669 val = phba->cfg_##attr;\
670 return snprintf(buf, PAGE_SIZE, "%d\n",\
671 phba->cfg_##attr);\
674 #define lpfc_param_hex_show(attr) \
675 static ssize_t \
676 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
678 struct Scsi_Host *shost = class_to_shost(cdev);\
679 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
680 struct lpfc_hba *phba = vport->phba;\
681 int val = 0;\
682 val = phba->cfg_##attr;\
683 return snprintf(buf, PAGE_SIZE, "%#x\n",\
684 phba->cfg_##attr);\
687 #define lpfc_param_init(attr, default, minval, maxval) \
688 static int \
689 lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
691 if (val >= minval && val <= maxval) {\
692 phba->cfg_##attr = val;\
693 return 0;\
695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
696 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
697 "allowed range is ["#minval", "#maxval"]\n", val); \
698 phba->cfg_##attr = default;\
699 return -EINVAL;\
702 #define lpfc_param_set(attr, default, minval, maxval) \
703 static int \
704 lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
706 if (val >= minval && val <= maxval) {\
707 phba->cfg_##attr = val;\
708 return 0;\
710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
711 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
712 "allowed range is ["#minval", "#maxval"]\n", val); \
713 return -EINVAL;\
716 #define lpfc_param_store(attr) \
717 static ssize_t \
718 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
720 struct Scsi_Host *shost = class_to_shost(cdev);\
721 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
722 struct lpfc_hba *phba = vport->phba;\
723 int val=0;\
724 if (!isdigit(buf[0]))\
725 return -EINVAL;\
726 if (sscanf(buf, "%i", &val) != 1)\
727 return -EINVAL;\
728 if (lpfc_##attr##_set(phba, val) == 0) \
729 return strlen(buf);\
730 else \
731 return -EINVAL;\
734 #define lpfc_vport_param_show(attr) \
735 static ssize_t \
736 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
738 struct Scsi_Host *shost = class_to_shost(cdev);\
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
740 int val = 0;\
741 val = vport->cfg_##attr;\
742 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
745 #define lpfc_vport_param_hex_show(attr) \
746 static ssize_t \
747 lpfc_##attr##_show(struct class_device *cdev, char *buf) \
749 struct Scsi_Host *shost = class_to_shost(cdev);\
750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
751 int val = 0;\
752 val = vport->cfg_##attr;\
753 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
756 #define lpfc_vport_param_init(attr, default, minval, maxval) \
757 static int \
758 lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
760 if (val >= minval && val <= maxval) {\
761 vport->cfg_##attr = val;\
762 return 0;\
764 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
765 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
766 "allowed range is ["#minval", "#maxval"]\n", val); \
767 vport->cfg_##attr = default;\
768 return -EINVAL;\
771 #define lpfc_vport_param_set(attr, default, minval, maxval) \
772 static int \
773 lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
775 if (val >= minval && val <= maxval) {\
776 vport->cfg_##attr = val;\
777 return 0;\
779 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
780 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
781 "allowed range is ["#minval", "#maxval"]\n", val); \
782 return -EINVAL;\
785 #define lpfc_vport_param_store(attr) \
786 static ssize_t \
787 lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
789 struct Scsi_Host *shost = class_to_shost(cdev);\
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
791 int val=0;\
792 if (!isdigit(buf[0]))\
793 return -EINVAL;\
794 if (sscanf(buf, "%i", &val) != 1)\
795 return -EINVAL;\
796 if (lpfc_##attr##_set(vport, val) == 0) \
797 return strlen(buf);\
798 else \
799 return -EINVAL;\
803 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
804 static int lpfc_##name = defval;\
805 module_param(lpfc_##name, int, 0);\
806 MODULE_PARM_DESC(lpfc_##name, desc);\
807 lpfc_param_init(name, defval, minval, maxval)
809 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
810 static int lpfc_##name = defval;\
811 module_param(lpfc_##name, int, 0);\
812 MODULE_PARM_DESC(lpfc_##name, desc);\
813 lpfc_param_show(name)\
814 lpfc_param_init(name, defval, minval, maxval)\
815 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
817 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
818 static int lpfc_##name = defval;\
819 module_param(lpfc_##name, int, 0);\
820 MODULE_PARM_DESC(lpfc_##name, desc);\
821 lpfc_param_show(name)\
822 lpfc_param_init(name, defval, minval, maxval)\
823 lpfc_param_set(name, defval, minval, maxval)\
824 lpfc_param_store(name)\
825 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
826 lpfc_##name##_show, lpfc_##name##_store)
828 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
829 static int lpfc_##name = defval;\
830 module_param(lpfc_##name, int, 0);\
831 MODULE_PARM_DESC(lpfc_##name, desc);\
832 lpfc_param_hex_show(name)\
833 lpfc_param_init(name, defval, minval, maxval)\
834 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
836 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
837 static int lpfc_##name = defval;\
838 module_param(lpfc_##name, int, 0);\
839 MODULE_PARM_DESC(lpfc_##name, desc);\
840 lpfc_param_hex_show(name)\
841 lpfc_param_init(name, defval, minval, maxval)\
842 lpfc_param_set(name, defval, minval, maxval)\
843 lpfc_param_store(name)\
844 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
845 lpfc_##name##_show, lpfc_##name##_store)
847 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
848 static int lpfc_##name = defval;\
849 module_param(lpfc_##name, int, 0);\
850 MODULE_PARM_DESC(lpfc_##name, desc);\
851 lpfc_vport_param_init(name, defval, minval, maxval)
853 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
854 static int lpfc_##name = defval;\
855 module_param(lpfc_##name, int, 0);\
856 MODULE_PARM_DESC(lpfc_##name, desc);\
857 lpfc_vport_param_show(name)\
858 lpfc_vport_param_init(name, defval, minval, maxval)\
859 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
861 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
862 static int lpfc_##name = defval;\
863 module_param(lpfc_##name, int, 0);\
864 MODULE_PARM_DESC(lpfc_##name, desc);\
865 lpfc_vport_param_show(name)\
866 lpfc_vport_param_init(name, defval, minval, maxval)\
867 lpfc_vport_param_set(name, defval, minval, maxval)\
868 lpfc_vport_param_store(name)\
869 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
870 lpfc_##name##_show, lpfc_##name##_store)
872 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
873 static int lpfc_##name = defval;\
874 module_param(lpfc_##name, int, 0);\
875 MODULE_PARM_DESC(lpfc_##name, desc);\
876 lpfc_vport_param_hex_show(name)\
877 lpfc_vport_param_init(name, defval, minval, maxval)\
878 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
880 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
881 static int lpfc_##name = defval;\
882 module_param(lpfc_##name, int, 0);\
883 MODULE_PARM_DESC(lpfc_##name, desc);\
884 lpfc_vport_param_hex_show(name)\
885 lpfc_vport_param_init(name, defval, minval, maxval)\
886 lpfc_vport_param_set(name, defval, minval, maxval)\
887 lpfc_vport_param_store(name)\
888 static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
889 lpfc_##name##_show, lpfc_##name##_store)
891 static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
892 static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
893 static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
894 static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
895 static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
896 static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
897 static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
898 static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
899 static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
900 static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
901 lpfc_option_rom_version_show, NULL);
902 static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
903 lpfc_num_discovered_ports_show, NULL);
904 static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
905 static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
906 NULL);
907 static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
908 NULL);
909 static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
910 lpfc_board_mode_show, lpfc_board_mode_store);
911 static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
912 static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
913 static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
914 static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
915 static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
916 static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
917 static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
918 static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
921 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
923 static ssize_t
924 lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
925 size_t count)
927 struct Scsi_Host *shost = class_to_shost(cdev);
928 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
929 struct lpfc_hba *phba = vport->phba;
930 unsigned int cnt = count;
933 * We're doing a simple sanity check for soft_wwpn setting.
934 * We require that the user write a specific key to enable
935 * the soft_wwpn attribute to be settable. Once the attribute
936 * is written, the enable key resets. If further updates are
937 * desired, the key must be written again to re-enable the
938 * attribute.
940 * The "key" is not secret - it is a hardcoded string shown
941 * here. The intent is to protect against the random user or
942 * application that is just writing attributes.
945 /* count may include a LF at end of string */
946 if (buf[cnt-1] == '\n')
947 cnt--;
949 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
950 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
951 return -EINVAL;
953 phba->soft_wwn_enable = 1;
954 return count;
956 static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
957 lpfc_soft_wwn_enable_store);
959 static ssize_t
960 lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
962 struct Scsi_Host *shost = class_to_shost(cdev);
963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
964 struct lpfc_hba *phba = vport->phba;
966 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
967 (unsigned long long)phba->cfg_soft_wwpn);
971 static ssize_t
972 lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
974 struct Scsi_Host *shost = class_to_shost(cdev);
975 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
976 struct lpfc_hba *phba = vport->phba;
977 struct completion online_compl;
978 int stat1=0, stat2=0;
979 unsigned int i, j, cnt=count;
980 u8 wwpn[8];
982 /* count may include a LF at end of string */
983 if (buf[cnt-1] == '\n')
984 cnt--;
986 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
987 ((cnt == 17) && (*buf++ != 'x')) ||
988 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
989 return -EINVAL;
991 phba->soft_wwn_enable = 0;
993 memset(wwpn, 0, sizeof(wwpn));
995 /* Validate and store the new name */
996 for (i=0, j=0; i < 16; i++) {
997 if ((*buf >= 'a') && (*buf <= 'f'))
998 j = ((j << 4) | ((*buf++ -'a') + 10));
999 else if ((*buf >= 'A') && (*buf <= 'F'))
1000 j = ((j << 4) | ((*buf++ -'A') + 10));
1001 else if ((*buf >= '0') && (*buf <= '9'))
1002 j = ((j << 4) | (*buf++ -'0'));
1003 else
1004 return -EINVAL;
1005 if (i % 2) {
1006 wwpn[i/2] = j & 0xff;
1007 j = 0;
1010 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1011 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1012 if (phba->cfg_soft_wwnn)
1013 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1015 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1016 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1018 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1019 if (stat1)
1020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1021 "0463 lpfc_soft_wwpn attribute set failed to "
1022 "reinit adapter - %d\n", stat1);
1023 init_completion(&online_compl);
1024 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1025 wait_for_completion(&online_compl);
1026 if (stat2)
1027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1028 "0464 lpfc_soft_wwpn attribute set failed to "
1029 "reinit adapter - %d\n", stat2);
1030 return (stat1 || stat2) ? -EIO : count;
1032 static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1033 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1035 static ssize_t
1036 lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1038 struct Scsi_Host *host = class_to_shost(cdev);
1039 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1040 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1041 (unsigned long long)phba->cfg_soft_wwnn);
1045 static ssize_t
1046 lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1048 struct Scsi_Host *host = class_to_shost(cdev);
1049 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1050 unsigned int i, j, cnt=count;
1051 u8 wwnn[8];
1053 /* count may include a LF at end of string */
1054 if (buf[cnt-1] == '\n')
1055 cnt--;
1057 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1058 ((cnt == 17) && (*buf++ != 'x')) ||
1059 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1060 return -EINVAL;
1063 * Allow wwnn to be set many times, as long as the enable is set.
1064 * However, once the wwpn is set, everything locks.
1067 memset(wwnn, 0, sizeof(wwnn));
1069 /* Validate and store the new name */
1070 for (i=0, j=0; i < 16; i++) {
1071 if ((*buf >= 'a') && (*buf <= 'f'))
1072 j = ((j << 4) | ((*buf++ -'a') + 10));
1073 else if ((*buf >= 'A') && (*buf <= 'F'))
1074 j = ((j << 4) | ((*buf++ -'A') + 10));
1075 else if ((*buf >= '0') && (*buf <= '9'))
1076 j = ((j << 4) | (*buf++ -'0'));
1077 else
1078 return -EINVAL;
1079 if (i % 2) {
1080 wwnn[i/2] = j & 0xff;
1081 j = 0;
1084 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1086 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1087 "lpfc%d: soft_wwnn set. Value will take effect upon "
1088 "setting of the soft_wwpn\n", phba->brd_no);
1090 return count;
1092 static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1093 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1096 static int lpfc_poll = 0;
1097 module_param(lpfc_poll, int, 0);
1098 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1099 " 0 - none,"
1100 " 1 - poll with interrupts enabled"
1101 " 3 - poll and disable FCP ring interrupts");
1103 static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1104 lpfc_poll_show, lpfc_poll_store);
1106 int lpfc_sli_mode = 0;
1107 module_param(lpfc_sli_mode, int, 0);
1108 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1109 " 0 - auto (SLI-3 if supported),"
1110 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1111 " 3 - select SLI-3");
1113 LPFC_ATTR_R(npiv_enable, 0, 0, 1, "Enable NPIV functionality");
1116 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1117 # until the timer expires. Value range is [0,255]. Default value is 30.
1119 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1120 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1121 module_param(lpfc_nodev_tmo, int, 0);
1122 MODULE_PARM_DESC(lpfc_nodev_tmo,
1123 "Seconds driver will hold I/O waiting "
1124 "for a device to come back");
1125 static ssize_t
1126 lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1128 struct Scsi_Host *shost = class_to_shost(cdev);
1129 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1130 int val = 0;
1131 val = vport->cfg_devloss_tmo;
1132 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
1135 static int
1136 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
1138 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1139 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1140 if (val != LPFC_DEF_DEVLOSS_TMO)
1141 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1142 "0402 Ignoring nodev_tmo module "
1143 "parameter because devloss_tmo is "
1144 "set.\n");
1145 return 0;
1148 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1149 vport->cfg_nodev_tmo = val;
1150 vport->cfg_devloss_tmo = val;
1151 return 0;
1153 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1154 "0400 lpfc_nodev_tmo attribute cannot be set to"
1155 " %d, allowed range is [%d, %d]\n",
1156 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1157 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1158 return -EINVAL;
1161 static void
1162 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
1164 struct lpfc_vport **vports;
1165 struct Scsi_Host *shost;
1166 struct lpfc_nodelist *ndlp;
1167 int i;
1169 vports = lpfc_create_vport_work_array(vport->phba);
1170 if (vports != NULL)
1171 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1172 shost = lpfc_shost_from_vport(vports[i]);
1173 spin_lock_irq(shost->host_lock);
1174 list_for_each_entry(ndlp, &vports[i]->fc_nodes,
1175 nlp_listp)
1176 if (ndlp->rport)
1177 ndlp->rport->dev_loss_tmo =
1178 vport->cfg_devloss_tmo;
1179 spin_unlock_irq(shost->host_lock);
1181 lpfc_destroy_vport_work_array(vports);
1184 static int
1185 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
1187 if (vport->dev_loss_tmo_changed ||
1188 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1190 "0401 Ignoring change to nodev_tmo "
1191 "because devloss_tmo is set.\n");
1192 return 0;
1194 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1195 vport->cfg_nodev_tmo = val;
1196 vport->cfg_devloss_tmo = val;
1197 lpfc_update_rport_devloss_tmo(vport);
1198 return 0;
1200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1201 "0403 lpfc_nodev_tmo attribute cannot be set to"
1202 "%d, allowed range is [%d, %d]\n",
1203 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1204 return -EINVAL;
1207 lpfc_vport_param_store(nodev_tmo)
1209 static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1210 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1213 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1214 # disappear until the timer expires. Value range is [0,255]. Default
1215 # value is 30.
1217 module_param(lpfc_devloss_tmo, int, 0);
1218 MODULE_PARM_DESC(lpfc_devloss_tmo,
1219 "Seconds driver will hold I/O waiting "
1220 "for a device to come back");
1221 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1222 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1223 lpfc_vport_param_show(devloss_tmo)
1224 static int
1225 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
1227 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1228 vport->cfg_nodev_tmo = val;
1229 vport->cfg_devloss_tmo = val;
1230 vport->dev_loss_tmo_changed = 1;
1231 lpfc_update_rport_devloss_tmo(vport);
1232 return 0;
1235 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1236 "0404 lpfc_devloss_tmo attribute cannot be set to"
1237 " %d, allowed range is [%d, %d]\n",
1238 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1239 return -EINVAL;
1242 lpfc_vport_param_store(devloss_tmo)
1243 static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1244 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1247 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1248 # deluged with LOTS of information.
1249 # You can set a bit mask to record specific types of verbose messages:
1251 # LOG_ELS 0x1 ELS events
1252 # LOG_DISCOVERY 0x2 Link discovery events
1253 # LOG_MBOX 0x4 Mailbox events
1254 # LOG_INIT 0x8 Initialization events
1255 # LOG_LINK_EVENT 0x10 Link events
1256 # LOG_FCP 0x40 FCP traffic history
1257 # LOG_NODE 0x80 Node table events
1258 # LOG_MISC 0x400 Miscellaneous events
1259 # LOG_SLI 0x800 SLI events
1260 # LOG_FCP_ERROR 0x1000 Only log FCP errors
1261 # LOG_LIBDFC 0x2000 LIBDFC events
1262 # LOG_ALL_MSG 0xffff LOG all messages
1264 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1265 "Verbose logging bit-mask");
1268 # lun_queue_depth: This parameter is used to limit the number of outstanding
1269 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
1271 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1272 "Max number of FCP commands we can queue to a specific LUN");
1275 # hba_queue_depth: This parameter is used to limit the number of outstanding
1276 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
1277 # value is greater than the maximum number of exchanges supported by the HBA,
1278 # then maximum number of exchanges supported by the HBA is used to determine
1279 # the hba_queue_depth.
1281 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1282 "Max number of FCP commands we can queue to a lpfc HBA");
1285 # peer_port_login: This parameter allows/prevents logins
1286 # between peer ports hosted on the same physical port.
1287 # When this parameter is set 0 peer ports of same physical port
1288 # are not allowed to login to each other.
1289 # When this parameter is set 1 peer ports of same physical port
1290 # are allowed to login to each other.
1291 # Default value of this parameter is 0.
1293 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1294 "Allow peer ports on the same physical port to login to each "
1295 "other.");
1298 # restrict_login: This parameter allows/prevents logins
1299 # between Virtual Ports and remote initiators.
1300 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1301 # other initiators and will attempt to PLOGI all remote ports.
1302 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
1303 # remote ports and will not attempt to PLOGI to other initiators.
1304 # This parameter does not restrict to the physical port.
1305 # This parameter does not restrict logins to Fabric resident remote ports.
1306 # Default value of this parameter is 1.
1308 static int lpfc_restrict_login = 1;
1309 module_param(lpfc_restrict_login, int, 0);
1310 MODULE_PARM_DESC(lpfc_restrict_login,
1311 "Restrict virtual ports login to remote initiators.");
1312 lpfc_vport_param_show(restrict_login);
1314 static int
1315 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1317 if (val < 0 || val > 1) {
1318 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1319 "0449 lpfc_restrict_login attribute cannot "
1320 "be set to %d, allowed range is [0, 1]\n",
1321 val);
1322 vport->cfg_restrict_login = 1;
1323 return -EINVAL;
1325 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1326 vport->cfg_restrict_login = 0;
1327 return 0;
1329 vport->cfg_restrict_login = val;
1330 return 0;
1333 static int
1334 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1336 if (val < 0 || val > 1) {
1337 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1338 "0450 lpfc_restrict_login attribute cannot "
1339 "be set to %d, allowed range is [0, 1]\n",
1340 val);
1341 vport->cfg_restrict_login = 1;
1342 return -EINVAL;
1344 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
1345 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1346 "0468 lpfc_restrict_login must be 0 for "
1347 "Physical ports.\n");
1348 vport->cfg_restrict_login = 0;
1349 return 0;
1351 vport->cfg_restrict_login = val;
1352 return 0;
1354 lpfc_vport_param_store(restrict_login);
1355 static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1356 lpfc_restrict_login_show, lpfc_restrict_login_store);
1359 # Some disk devices have a "select ID" or "select Target" capability.
1360 # From a protocol standpoint "select ID" usually means select the
1361 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1362 # annex" which contains a table that maps a "select ID" (a number
1363 # between 0 and 7F) to an ALPA. By default, for compatibility with
1364 # older drivers, the lpfc driver scans this table from low ALPA to high
1365 # ALPA.
1367 # Turning on the scan-down variable (on = 1, off = 0) will
1368 # cause the lpfc driver to use an inverted table, effectively
1369 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1371 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
1372 # and will not work across a fabric. Also this parameter will take
1373 # effect only in the case when ALPA map is not available.)
1375 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1376 "Start scanning for devices from highest ALPA to lowest");
1379 # lpfc_topology: link topology for init link
1380 # 0x0 = attempt loop mode then point-to-point
1381 # 0x01 = internal loopback mode
1382 # 0x02 = attempt point-to-point mode only
1383 # 0x04 = attempt loop mode only
1384 # 0x06 = attempt point-to-point mode then loop
1385 # Set point-to-point mode if you want to run as an N_Port.
1386 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1387 # Default value is 0.
1389 LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
1392 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1393 # connection.
1394 # 0 = auto select (default)
1395 # 1 = 1 Gigabaud
1396 # 2 = 2 Gigabaud
1397 # 4 = 4 Gigabaud
1398 # 8 = 8 Gigabaud
1399 # Value range is [0,8]. Default value is 0.
1401 LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
1404 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1405 # Value range is [2,3]. Default value is 3.
1407 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1408 "Select Fibre Channel class of service for FCP sequences");
1411 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1412 # is [0,1]. Default value is 0.
1414 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1415 "Use ADISC on rediscovery to authenticate FCP devices");
1418 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1419 # range is [0,1]. Default value is 0.
1421 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1424 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1425 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
1426 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
1427 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1428 # cr_delay is set to 0.
1430 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
1431 "interrupt response is generated");
1433 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
1434 "interrupt response is generated");
1437 # lpfc_multi_ring_support: Determines how many rings to spread available
1438 # cmd/rsp IOCB entries across.
1439 # Value range is [1,2]. Default value is 1.
1441 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1442 "SLI rings to spread IOCB entries across");
1445 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1446 # identifies what rctl value to configure the additional ring for.
1447 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1449 LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1450 255, "Identifies RCTL for additional ring configuration");
1453 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1454 # identifies what type value to configure the additional ring for.
1455 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1457 LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1458 255, "Identifies TYPE for additional ring configuration");
1461 # lpfc_fdmi_on: controls FDMI support.
1462 # 0 = no FDMI support
1463 # 1 = support FDMI without attribute of hostname
1464 # 2 = support FDMI with attribute of hostname
1465 # Value range [0,2]. Default value is 0.
1467 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1470 # Specifies the maximum number of ELS cmds we can have outstanding (for
1471 # discovery). Value range is [1,64]. Default value = 32.
1473 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
1474 "during discovery");
1477 # lpfc_max_luns: maximum allowed LUN.
1478 # Value range is [0,65535]. Default value is 255.
1479 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
1481 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
1484 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1485 # Value range is [1,255], default value is 10.
1487 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1488 "Milliseconds driver will wait between polling FCP ring");
1491 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1492 # support this feature
1493 # 0 = MSI disabled (default)
1494 # 1 = MSI enabled
1495 # Value range is [0,1]. Default value is 0.
1497 LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1501 struct class_device_attribute *lpfc_hba_attrs[] = {
1502 &class_device_attr_info,
1503 &class_device_attr_serialnum,
1504 &class_device_attr_modeldesc,
1505 &class_device_attr_modelname,
1506 &class_device_attr_programtype,
1507 &class_device_attr_portnum,
1508 &class_device_attr_fwrev,
1509 &class_device_attr_hdw,
1510 &class_device_attr_option_rom_version,
1511 &class_device_attr_state,
1512 &class_device_attr_num_discovered_ports,
1513 &class_device_attr_lpfc_drvr_version,
1514 &class_device_attr_lpfc_log_verbose,
1515 &class_device_attr_lpfc_lun_queue_depth,
1516 &class_device_attr_lpfc_hba_queue_depth,
1517 &class_device_attr_lpfc_peer_port_login,
1518 &class_device_attr_lpfc_nodev_tmo,
1519 &class_device_attr_lpfc_devloss_tmo,
1520 &class_device_attr_lpfc_fcp_class,
1521 &class_device_attr_lpfc_use_adisc,
1522 &class_device_attr_lpfc_ack0,
1523 &class_device_attr_lpfc_topology,
1524 &class_device_attr_lpfc_scan_down,
1525 &class_device_attr_lpfc_link_speed,
1526 &class_device_attr_lpfc_cr_delay,
1527 &class_device_attr_lpfc_cr_count,
1528 &class_device_attr_lpfc_multi_ring_support,
1529 &class_device_attr_lpfc_multi_ring_rctl,
1530 &class_device_attr_lpfc_multi_ring_type,
1531 &class_device_attr_lpfc_fdmi_on,
1532 &class_device_attr_lpfc_max_luns,
1533 &class_device_attr_lpfc_npiv_enable,
1534 &class_device_attr_nport_evt_cnt,
1535 &class_device_attr_management_version,
1536 &class_device_attr_board_mode,
1537 &class_device_attr_max_vpi,
1538 &class_device_attr_used_vpi,
1539 &class_device_attr_max_rpi,
1540 &class_device_attr_used_rpi,
1541 &class_device_attr_max_xri,
1542 &class_device_attr_used_xri,
1543 &class_device_attr_npiv_info,
1544 &class_device_attr_issue_reset,
1545 &class_device_attr_lpfc_poll,
1546 &class_device_attr_lpfc_poll_tmo,
1547 &class_device_attr_lpfc_use_msi,
1548 &class_device_attr_lpfc_soft_wwnn,
1549 &class_device_attr_lpfc_soft_wwpn,
1550 &class_device_attr_lpfc_soft_wwn_enable,
1551 NULL,
1554 struct class_device_attribute *lpfc_vport_attrs[] = {
1555 &class_device_attr_info,
1556 &class_device_attr_state,
1557 &class_device_attr_num_discovered_ports,
1558 &class_device_attr_lpfc_drvr_version,
1560 &class_device_attr_lpfc_log_verbose,
1561 &class_device_attr_lpfc_lun_queue_depth,
1562 &class_device_attr_lpfc_nodev_tmo,
1563 &class_device_attr_lpfc_devloss_tmo,
1564 &class_device_attr_lpfc_hba_queue_depth,
1565 &class_device_attr_lpfc_peer_port_login,
1566 &class_device_attr_lpfc_restrict_login,
1567 &class_device_attr_lpfc_fcp_class,
1568 &class_device_attr_lpfc_use_adisc,
1569 &class_device_attr_lpfc_fdmi_on,
1570 &class_device_attr_lpfc_max_luns,
1571 &class_device_attr_nport_evt_cnt,
1572 &class_device_attr_management_version,
1573 &class_device_attr_npiv_info,
1574 NULL,
1577 static ssize_t
1578 sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1579 char *buf, loff_t off, size_t count)
1581 size_t buf_off;
1582 struct class_device *cdev = container_of(kobj, struct class_device,
1583 kobj);
1584 struct Scsi_Host *shost = class_to_shost(cdev);
1585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1586 struct lpfc_hba *phba = vport->phba;
1588 if ((off + count) > FF_REG_AREA_SIZE)
1589 return -ERANGE;
1591 if (count == 0) return 0;
1593 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1594 return -EINVAL;
1596 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1597 return -EPERM;
1600 spin_lock_irq(&phba->hbalock);
1601 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1602 writel(*((uint32_t *)(buf + buf_off)),
1603 phba->ctrl_regs_memmap_p + off + buf_off);
1605 spin_unlock_irq(&phba->hbalock);
1607 return count;
1610 static ssize_t
1611 sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1612 char *buf, loff_t off, size_t count)
1614 size_t buf_off;
1615 uint32_t * tmp_ptr;
1616 struct class_device *cdev = container_of(kobj, struct class_device,
1617 kobj);
1618 struct Scsi_Host *shost = class_to_shost(cdev);
1619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1620 struct lpfc_hba *phba = vport->phba;
1622 if (off > FF_REG_AREA_SIZE)
1623 return -ERANGE;
1625 if ((off + count) > FF_REG_AREA_SIZE)
1626 count = FF_REG_AREA_SIZE - off;
1628 if (count == 0) return 0;
1630 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1631 return -EINVAL;
1633 spin_lock_irq(&phba->hbalock);
1635 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1636 tmp_ptr = (uint32_t *)(buf + buf_off);
1637 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1640 spin_unlock_irq(&phba->hbalock);
1642 return count;
1645 static struct bin_attribute sysfs_ctlreg_attr = {
1646 .attr = {
1647 .name = "ctlreg",
1648 .mode = S_IRUSR | S_IWUSR,
1650 .size = 256,
1651 .read = sysfs_ctlreg_read,
1652 .write = sysfs_ctlreg_write,
1656 static void
1657 sysfs_mbox_idle(struct lpfc_hba *phba)
1659 phba->sysfs_mbox.state = SMBOX_IDLE;
1660 phba->sysfs_mbox.offset = 0;
1662 if (phba->sysfs_mbox.mbox) {
1663 mempool_free(phba->sysfs_mbox.mbox,
1664 phba->mbox_mem_pool);
1665 phba->sysfs_mbox.mbox = NULL;
1669 static ssize_t
1670 sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1671 char *buf, loff_t off, size_t count)
1673 struct class_device *cdev = container_of(kobj, struct class_device,
1674 kobj);
1675 struct Scsi_Host *shost = class_to_shost(cdev);
1676 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1677 struct lpfc_hba *phba = vport->phba;
1678 struct lpfcMboxq *mbox = NULL;
1680 if ((count + off) > MAILBOX_CMD_SIZE)
1681 return -ERANGE;
1683 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1684 return -EINVAL;
1686 if (count == 0)
1687 return 0;
1689 if (off == 0) {
1690 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1691 if (!mbox)
1692 return -ENOMEM;
1693 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1696 spin_lock_irq(&phba->hbalock);
1698 if (off == 0) {
1699 if (phba->sysfs_mbox.mbox)
1700 mempool_free(mbox, phba->mbox_mem_pool);
1701 else
1702 phba->sysfs_mbox.mbox = mbox;
1703 phba->sysfs_mbox.state = SMBOX_WRITING;
1704 } else {
1705 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1706 phba->sysfs_mbox.offset != off ||
1707 phba->sysfs_mbox.mbox == NULL) {
1708 sysfs_mbox_idle(phba);
1709 spin_unlock_irq(&phba->hbalock);
1710 return -EAGAIN;
1714 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1715 buf, count);
1717 phba->sysfs_mbox.offset = off + count;
1719 spin_unlock_irq(&phba->hbalock);
1721 return count;
1724 static ssize_t
1725 sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1726 char *buf, loff_t off, size_t count)
1728 struct class_device *cdev = container_of(kobj, struct class_device,
1729 kobj);
1730 struct Scsi_Host *shost = class_to_shost(cdev);
1731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1732 struct lpfc_hba *phba = vport->phba;
1733 int rc;
1735 if (off > MAILBOX_CMD_SIZE)
1736 return -ERANGE;
1738 if ((count + off) > MAILBOX_CMD_SIZE)
1739 count = MAILBOX_CMD_SIZE - off;
1741 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1742 return -EINVAL;
1744 if (off && count == 0)
1745 return 0;
1747 spin_lock_irq(&phba->hbalock);
1749 if (off == 0 &&
1750 phba->sysfs_mbox.state == SMBOX_WRITING &&
1751 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1753 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1754 /* Offline only */
1755 case MBX_WRITE_NV:
1756 case MBX_INIT_LINK:
1757 case MBX_DOWN_LINK:
1758 case MBX_CONFIG_LINK:
1759 case MBX_CONFIG_RING:
1760 case MBX_RESET_RING:
1761 case MBX_UNREG_LOGIN:
1762 case MBX_CLEAR_LA:
1763 case MBX_DUMP_CONTEXT:
1764 case MBX_RUN_DIAGS:
1765 case MBX_RESTART:
1766 case MBX_FLASH_WR_ULA:
1767 case MBX_SET_MASK:
1768 case MBX_SET_SLIM:
1769 case MBX_SET_DEBUG:
1770 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1771 printk(KERN_WARNING "mbox_read:Command 0x%x "
1772 "is illegal in on-line state\n",
1773 phba->sysfs_mbox.mbox->mb.mbxCommand);
1774 sysfs_mbox_idle(phba);
1775 spin_unlock_irq(&phba->hbalock);
1776 return -EPERM;
1778 case MBX_LOAD_SM:
1779 case MBX_READ_NV:
1780 case MBX_READ_CONFIG:
1781 case MBX_READ_RCONFIG:
1782 case MBX_READ_STATUS:
1783 case MBX_READ_XRI:
1784 case MBX_READ_REV:
1785 case MBX_READ_LNK_STAT:
1786 case MBX_DUMP_MEMORY:
1787 case MBX_DOWN_LOAD:
1788 case MBX_UPDATE_CFG:
1789 case MBX_KILL_BOARD:
1790 case MBX_LOAD_AREA:
1791 case MBX_LOAD_EXP_ROM:
1792 case MBX_BEACON:
1793 case MBX_DEL_LD_ENTRY:
1794 break;
1795 case MBX_READ_SPARM64:
1796 case MBX_READ_LA:
1797 case MBX_READ_LA64:
1798 case MBX_REG_LOGIN:
1799 case MBX_REG_LOGIN64:
1800 case MBX_CONFIG_PORT:
1801 case MBX_RUN_BIU_DIAG:
1802 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1803 phba->sysfs_mbox.mbox->mb.mbxCommand);
1804 sysfs_mbox_idle(phba);
1805 spin_unlock_irq(&phba->hbalock);
1806 return -EPERM;
1807 default:
1808 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1809 phba->sysfs_mbox.mbox->mb.mbxCommand);
1810 sysfs_mbox_idle(phba);
1811 spin_unlock_irq(&phba->hbalock);
1812 return -EPERM;
1815 phba->sysfs_mbox.mbox->vport = vport;
1817 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1818 sysfs_mbox_idle(phba);
1819 spin_unlock_irq(&phba->hbalock);
1820 return -EAGAIN;
1823 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1824 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1826 spin_unlock_irq(&phba->hbalock);
1827 rc = lpfc_sli_issue_mbox (phba,
1828 phba->sysfs_mbox.mbox,
1829 MBX_POLL);
1830 spin_lock_irq(&phba->hbalock);
1832 } else {
1833 spin_unlock_irq(&phba->hbalock);
1834 rc = lpfc_sli_issue_mbox_wait (phba,
1835 phba->sysfs_mbox.mbox,
1836 lpfc_mbox_tmo_val(phba,
1837 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1838 spin_lock_irq(&phba->hbalock);
1841 if (rc != MBX_SUCCESS) {
1842 if (rc == MBX_TIMEOUT) {
1843 phba->sysfs_mbox.mbox = NULL;
1845 sysfs_mbox_idle(phba);
1846 spin_unlock_irq(&phba->hbalock);
1847 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1849 phba->sysfs_mbox.state = SMBOX_READING;
1851 else if (phba->sysfs_mbox.offset != off ||
1852 phba->sysfs_mbox.state != SMBOX_READING) {
1853 printk(KERN_WARNING "mbox_read: Bad State\n");
1854 sysfs_mbox_idle(phba);
1855 spin_unlock_irq(&phba->hbalock);
1856 return -EAGAIN;
1859 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1861 phba->sysfs_mbox.offset = off + count;
1863 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1864 sysfs_mbox_idle(phba);
1866 spin_unlock_irq(&phba->hbalock);
1868 return count;
1871 static struct bin_attribute sysfs_mbox_attr = {
1872 .attr = {
1873 .name = "mbox",
1874 .mode = S_IRUSR | S_IWUSR,
1876 .size = MAILBOX_CMD_SIZE,
1877 .read = sysfs_mbox_read,
1878 .write = sysfs_mbox_write,
1882 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
1884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1885 int error;
1887 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1888 &sysfs_ctlreg_attr);
1889 if (error)
1890 goto out;
1892 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1893 &sysfs_mbox_attr);
1894 if (error)
1895 goto out_remove_ctlreg_attr;
1897 return 0;
1898 out_remove_ctlreg_attr:
1899 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1900 out:
1901 return error;
1904 void
1905 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
1907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1909 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1910 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1915 * Dynamic FC Host Attributes Support
1918 static void
1919 lpfc_get_host_port_id(struct Scsi_Host *shost)
1921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1923 /* note: fc_myDID already in cpu endianness */
1924 fc_host_port_id(shost) = vport->fc_myDID;
1927 static void
1928 lpfc_get_host_port_type(struct Scsi_Host *shost)
1930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1931 struct lpfc_hba *phba = vport->phba;
1933 spin_lock_irq(shost->host_lock);
1935 if (vport->port_type == LPFC_NPIV_PORT) {
1936 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1937 } else if (lpfc_is_link_up(phba)) {
1938 if (phba->fc_topology == TOPOLOGY_LOOP) {
1939 if (vport->fc_flag & FC_PUBLIC_LOOP)
1940 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1941 else
1942 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1943 } else {
1944 if (vport->fc_flag & FC_FABRIC)
1945 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1946 else
1947 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1949 } else
1950 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1952 spin_unlock_irq(shost->host_lock);
1955 static void
1956 lpfc_get_host_port_state(struct Scsi_Host *shost)
1958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1959 struct lpfc_hba *phba = vport->phba;
1961 spin_lock_irq(shost->host_lock);
1963 if (vport->fc_flag & FC_OFFLINE_MODE)
1964 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1965 else {
1966 switch (phba->link_state) {
1967 case LPFC_LINK_UNKNOWN:
1968 case LPFC_LINK_DOWN:
1969 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1970 break;
1971 case LPFC_LINK_UP:
1972 case LPFC_CLEAR_LA:
1973 case LPFC_HBA_READY:
1974 /* Links up, beyond this port_type reports state */
1975 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1976 break;
1977 case LPFC_HBA_ERROR:
1978 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1979 break;
1980 default:
1981 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1982 break;
1986 spin_unlock_irq(shost->host_lock);
1989 static void
1990 lpfc_get_host_speed(struct Scsi_Host *shost)
1992 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1993 struct lpfc_hba *phba = vport->phba;
1995 spin_lock_irq(shost->host_lock);
1997 if (lpfc_is_link_up(phba)) {
1998 switch(phba->fc_linkspeed) {
1999 case LA_1GHZ_LINK:
2000 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2001 break;
2002 case LA_2GHZ_LINK:
2003 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2004 break;
2005 case LA_4GHZ_LINK:
2006 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2007 break;
2008 case LA_8GHZ_LINK:
2009 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2010 break;
2011 default:
2012 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2013 break;
2017 spin_unlock_irq(shost->host_lock);
2020 static void
2021 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2024 struct lpfc_hba *phba = vport->phba;
2025 u64 node_name;
2027 spin_lock_irq(shost->host_lock);
2029 if ((vport->fc_flag & FC_FABRIC) ||
2030 ((phba->fc_topology == TOPOLOGY_LOOP) &&
2031 (vport->fc_flag & FC_PUBLIC_LOOP)))
2032 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
2033 else
2034 /* fabric is local port if there is no F/FL_Port */
2035 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
2037 spin_unlock_irq(shost->host_lock);
2039 fc_host_fabric_name(shost) = node_name;
2042 static struct fc_host_statistics *
2043 lpfc_get_stats(struct Scsi_Host *shost)
2045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2046 struct lpfc_hba *phba = vport->phba;
2047 struct lpfc_sli *psli = &phba->sli;
2048 struct fc_host_statistics *hs = &phba->link_stats;
2049 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
2050 LPFC_MBOXQ_t *pmboxq;
2051 MAILBOX_t *pmb;
2052 unsigned long seconds;
2053 int rc = 0;
2056 * prevent udev from issuing mailbox commands until the port is
2057 * configured.
2059 if (phba->link_state < LPFC_LINK_DOWN ||
2060 !phba->mbox_mem_pool ||
2061 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
2062 return NULL;
2064 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2065 return NULL;
2067 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2068 if (!pmboxq)
2069 return NULL;
2070 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2072 pmb = &pmboxq->mb;
2073 pmb->mbxCommand = MBX_READ_STATUS;
2074 pmb->mbxOwner = OWN_HOST;
2075 pmboxq->context1 = NULL;
2076 pmboxq->vport = vport;
2078 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2079 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2080 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2081 else
2082 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2084 if (rc != MBX_SUCCESS) {
2085 if (rc != MBX_TIMEOUT)
2086 mempool_free(pmboxq, phba->mbox_mem_pool);
2087 return NULL;
2090 memset(hs, 0, sizeof (struct fc_host_statistics));
2092 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2093 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2094 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2095 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2097 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2098 pmb->mbxCommand = MBX_READ_LNK_STAT;
2099 pmb->mbxOwner = OWN_HOST;
2100 pmboxq->context1 = NULL;
2101 pmboxq->vport = vport;
2103 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2104 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2105 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2106 else
2107 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2109 if (rc != MBX_SUCCESS) {
2110 if (rc != MBX_TIMEOUT)
2111 mempool_free(pmboxq, phba->mbox_mem_pool);
2112 return NULL;
2115 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2116 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2117 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2118 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2119 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2120 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2121 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2123 hs->link_failure_count -= lso->link_failure_count;
2124 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2125 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2126 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2127 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2128 hs->invalid_crc_count -= lso->invalid_crc_count;
2129 hs->error_frames -= lso->error_frames;
2131 if (phba->fc_topology == TOPOLOGY_LOOP) {
2132 hs->lip_count = (phba->fc_eventTag >> 1);
2133 hs->lip_count -= lso->link_events;
2134 hs->nos_count = -1;
2135 } else {
2136 hs->lip_count = -1;
2137 hs->nos_count = (phba->fc_eventTag >> 1);
2138 hs->nos_count -= lso->link_events;
2141 hs->dumped_frames = -1;
2143 seconds = get_seconds();
2144 if (seconds < psli->stats_start)
2145 hs->seconds_since_last_reset = seconds +
2146 ((unsigned long)-1 - psli->stats_start);
2147 else
2148 hs->seconds_since_last_reset = seconds - psli->stats_start;
2150 mempool_free(pmboxq, phba->mbox_mem_pool);
2152 return hs;
2155 static void
2156 lpfc_reset_stats(struct Scsi_Host *shost)
2158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2159 struct lpfc_hba *phba = vport->phba;
2160 struct lpfc_sli *psli = &phba->sli;
2161 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
2162 LPFC_MBOXQ_t *pmboxq;
2163 MAILBOX_t *pmb;
2164 int rc = 0;
2166 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
2167 return;
2169 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2170 if (!pmboxq)
2171 return;
2172 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2174 pmb = &pmboxq->mb;
2175 pmb->mbxCommand = MBX_READ_STATUS;
2176 pmb->mbxOwner = OWN_HOST;
2177 pmb->un.varWords[0] = 0x1; /* reset request */
2178 pmboxq->context1 = NULL;
2179 pmboxq->vport = vport;
2181 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2182 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2183 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2184 else
2185 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2187 if (rc != MBX_SUCCESS) {
2188 if (rc != MBX_TIMEOUT)
2189 mempool_free(pmboxq, phba->mbox_mem_pool);
2190 return;
2193 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2194 pmb->mbxCommand = MBX_READ_LNK_STAT;
2195 pmb->mbxOwner = OWN_HOST;
2196 pmboxq->context1 = NULL;
2197 pmboxq->vport = vport;
2199 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
2200 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2201 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2202 else
2203 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2205 if (rc != MBX_SUCCESS) {
2206 if (rc != MBX_TIMEOUT)
2207 mempool_free( pmboxq, phba->mbox_mem_pool);
2208 return;
2211 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2212 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2213 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2214 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2215 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2216 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2217 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2218 lso->link_events = (phba->fc_eventTag >> 1);
2220 psli->stats_start = get_seconds();
2222 mempool_free(pmboxq, phba->mbox_mem_pool);
2224 return;
2228 * The LPFC driver treats linkdown handling as target loss events so there
2229 * are no sysfs handlers for link_down_tmo.
2232 static struct lpfc_nodelist *
2233 lpfc_get_node_by_target(struct scsi_target *starget)
2235 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2236 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2237 struct lpfc_nodelist *ndlp;
2239 spin_lock_irq(shost->host_lock);
2240 /* Search for this, mapped, target ID */
2241 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2242 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2243 starget->id == ndlp->nlp_sid) {
2244 spin_unlock_irq(shost->host_lock);
2245 return ndlp;
2248 spin_unlock_irq(shost->host_lock);
2249 return NULL;
2252 static void
2253 lpfc_get_starget_port_id(struct scsi_target *starget)
2255 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2257 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
2260 static void
2261 lpfc_get_starget_node_name(struct scsi_target *starget)
2263 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2265 fc_starget_node_name(starget) =
2266 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
2269 static void
2270 lpfc_get_starget_port_name(struct scsi_target *starget)
2272 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2274 fc_starget_port_name(starget) =
2275 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
2278 static void
2279 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2281 if (timeout)
2282 rport->dev_loss_tmo = timeout;
2283 else
2284 rport->dev_loss_tmo = 1;
2288 #define lpfc_rport_show_function(field, format_string, sz, cast) \
2289 static ssize_t \
2290 lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2292 struct fc_rport *rport = transport_class_to_rport(cdev); \
2293 struct lpfc_rport_data *rdata = rport->hostdata; \
2294 return snprintf(buf, sz, format_string, \
2295 (rdata->target) ? cast rdata->target->field : 0); \
2298 #define lpfc_rport_rd_attr(field, format_string, sz) \
2299 lpfc_rport_show_function(field, format_string, sz, ) \
2300 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2303 struct fc_function_template lpfc_transport_functions = {
2304 /* fixed attributes the driver supports */
2305 .show_host_node_name = 1,
2306 .show_host_port_name = 1,
2307 .show_host_supported_classes = 1,
2308 .show_host_supported_fc4s = 1,
2309 .show_host_supported_speeds = 1,
2310 .show_host_maxframe_size = 1,
2312 /* dynamic attributes the driver supports */
2313 .get_host_port_id = lpfc_get_host_port_id,
2314 .show_host_port_id = 1,
2316 .get_host_port_type = lpfc_get_host_port_type,
2317 .show_host_port_type = 1,
2319 .get_host_port_state = lpfc_get_host_port_state,
2320 .show_host_port_state = 1,
2322 /* active_fc4s is shown but doesn't change (thus no get function) */
2323 .show_host_active_fc4s = 1,
2325 .get_host_speed = lpfc_get_host_speed,
2326 .show_host_speed = 1,
2328 .get_host_fabric_name = lpfc_get_host_fabric_name,
2329 .show_host_fabric_name = 1,
2332 * The LPFC driver treats linkdown handling as target loss events
2333 * so there are no sysfs handlers for link_down_tmo.
2336 .get_fc_host_stats = lpfc_get_stats,
2337 .reset_fc_host_stats = lpfc_reset_stats,
2339 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2340 .show_rport_maxframe_size = 1,
2341 .show_rport_supported_classes = 1,
2343 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2344 .show_rport_dev_loss_tmo = 1,
2346 .get_starget_port_id = lpfc_get_starget_port_id,
2347 .show_starget_port_id = 1,
2349 .get_starget_node_name = lpfc_get_starget_node_name,
2350 .show_starget_node_name = 1,
2352 .get_starget_port_name = lpfc_get_starget_port_name,
2353 .show_starget_port_name = 1,
2355 .issue_fc_host_lip = lpfc_issue_lip,
2356 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2357 .terminate_rport_io = lpfc_terminate_rport_io,
2359 .vport_create = lpfc_vport_create,
2360 .vport_delete = lpfc_vport_delete,
2361 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2364 struct fc_function_template lpfc_vport_transport_functions = {
2365 /* fixed attributes the driver supports */
2366 .show_host_node_name = 1,
2367 .show_host_port_name = 1,
2368 .show_host_supported_classes = 1,
2369 .show_host_supported_fc4s = 1,
2370 .show_host_supported_speeds = 1,
2371 .show_host_maxframe_size = 1,
2373 /* dynamic attributes the driver supports */
2374 .get_host_port_id = lpfc_get_host_port_id,
2375 .show_host_port_id = 1,
2377 .get_host_port_type = lpfc_get_host_port_type,
2378 .show_host_port_type = 1,
2380 .get_host_port_state = lpfc_get_host_port_state,
2381 .show_host_port_state = 1,
2383 /* active_fc4s is shown but doesn't change (thus no get function) */
2384 .show_host_active_fc4s = 1,
2386 .get_host_speed = lpfc_get_host_speed,
2387 .show_host_speed = 1,
2389 .get_host_fabric_name = lpfc_get_host_fabric_name,
2390 .show_host_fabric_name = 1,
2393 * The LPFC driver treats linkdown handling as target loss events
2394 * so there are no sysfs handlers for link_down_tmo.
2397 .get_fc_host_stats = lpfc_get_stats,
2398 .reset_fc_host_stats = lpfc_reset_stats,
2400 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2401 .show_rport_maxframe_size = 1,
2402 .show_rport_supported_classes = 1,
2404 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2405 .show_rport_dev_loss_tmo = 1,
2407 .get_starget_port_id = lpfc_get_starget_port_id,
2408 .show_starget_port_id = 1,
2410 .get_starget_node_name = lpfc_get_starget_node_name,
2411 .show_starget_node_name = 1,
2413 .get_starget_port_name = lpfc_get_starget_port_name,
2414 .show_starget_port_name = 1,
2416 .issue_fc_host_lip = lpfc_issue_lip,
2417 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2418 .terminate_rport_io = lpfc_terminate_rport_io,
2420 .vport_disable = lpfc_vport_disable,
2423 void
2424 lpfc_get_cfgparam(struct lpfc_hba *phba)
2426 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2427 lpfc_cr_count_init(phba, lpfc_cr_count);
2428 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
2429 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2430 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
2431 lpfc_ack0_init(phba, lpfc_ack0);
2432 lpfc_topology_init(phba, lpfc_topology);
2433 lpfc_link_speed_init(phba, lpfc_link_speed);
2434 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
2435 lpfc_npiv_enable_init(phba, lpfc_npiv_enable);
2436 lpfc_use_msi_init(phba, lpfc_use_msi);
2437 phba->cfg_poll = lpfc_poll;
2438 phba->cfg_soft_wwnn = 0L;
2439 phba->cfg_soft_wwpn = 0L;
2441 * The total number of segments is the configuration value plus 2
2442 * since the IOCB need a command and response bde.
2444 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
2446 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2447 * used to create the sg_dma_buf_pool must be dynamically calculated
2449 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2450 sizeof(struct fcp_rsp) +
2451 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
2452 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
2453 return;
2456 void
2457 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2459 lpfc_log_verbose_init(vport, lpfc_log_verbose);
2460 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2461 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2462 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2463 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2464 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2465 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2466 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2467 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2468 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2469 lpfc_max_luns_init(vport, lpfc_max_luns);
2470 lpfc_scan_down_init(vport, lpfc_scan_down);
2471 return;