1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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>
30
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>
37
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"
51
52#define LPFC_DEF_DEVLOSS_TMO 30
53#define LPFC_MIN_DEVLOSS_TMO 1
54#define LPFC_MAX_DEVLOSS_TMO 255
55
56
57
58
59
60#define LPFC_REG_WRITE_KEY_SIZE 4
61#define LPFC_REG_WRITE_KEY "EMLX"
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78static void
79lpfc_jedec_to_ascii(int incr, char hdw[])
80{
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);
89 }
90 hdw[8] = 0;
91 return;
92}
93
94
95
96
97
98
99
100
101
102static ssize_t
103lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
104 char *buf)
105{
106 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
107}
108
109
110
111
112
113
114
115
116
117static ssize_t
118lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
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;
124
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");
129}
130
131static ssize_t
132lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
133 char *buf)
134{
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;
138
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");
148}
149
150static ssize_t
151lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
152 char *buf)
153{
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;
157
158 return snprintf(buf, PAGE_SIZE, "%llu\n",
159 (unsigned long long)phba->bg_guard_err_cnt);
160}
161
162static ssize_t
163lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
164 char *buf)
165{
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;
169
170 return snprintf(buf, PAGE_SIZE, "%llu\n",
171 (unsigned long long)phba->bg_apptag_err_cnt);
172}
173
174static ssize_t
175lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
177{
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;
181
182 return snprintf(buf, PAGE_SIZE, "%llu\n",
183 (unsigned long long)phba->bg_reftag_err_cnt);
184}
185
186
187
188
189
190
191
192
193
194static ssize_t
195lpfc_info_show(struct device *dev, struct device_attribute *attr,
196 char *buf)
197{
198 struct Scsi_Host *host = class_to_shost(dev);
199
200 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
201}
202
203
204
205
206
207
208
209
210
211static ssize_t
212lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
213 char *buf)
214{
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;
218
219 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
220}
221
222
223
224
225
226
227
228
229
230
231
232
233
234static ssize_t
235lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
236 char *buf)
237{
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);
242}
243
244
245
246
247
248
249
250
251
252static ssize_t
253lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
254 char *buf)
255{
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;
259
260 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
261}
262
263
264
265
266
267
268
269
270
271static ssize_t
272lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
273 char *buf)
274{
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;
278
279 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
280}
281
282
283
284
285
286
287
288
289
290static ssize_t
291lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
292 char *buf)
293{
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;
297
298 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
299}
300
301
302
303
304
305
306
307
308
309static ssize_t
310lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
311{
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;
315
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
318}
319
320
321
322
323
324
325
326
327
328static ssize_t
329lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
330 char *buf)
331{
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;
335
336 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
337}
338
339
340
341
342
343
344
345
346
347static ssize_t
348lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
349 char *buf)
350{
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 uint32_t if_type;
355 uint8_t sli_family;
356 char fwrev[FW_REV_STR_SIZE];
357 int len;
358
359 lpfc_decode_firmware_rev(phba, fwrev, 1);
360 if_type = phba->sli4_hba.pc_sli4_params.if_type;
361 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
362
363 if (phba->sli_rev < LPFC_SLI_REV4)
364 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
365 fwrev, phba->sli_rev);
366 else
367 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
368 fwrev, phba->sli_rev, if_type, sli_family);
369
370 return len;
371}
372
373
374
375
376
377
378
379
380
381static ssize_t
382lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
383{
384 char hdw[9];
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388 lpfc_vpd_t *vp = &phba->vpd;
389
390 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
391 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
392}
393
394
395
396
397
398
399
400
401
402static ssize_t
403lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
405{
406 struct Scsi_Host *shost = class_to_shost(dev);
407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409
410 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
411}
412
413
414
415
416
417
418
419
420
421
422
423
424static ssize_t
425lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
426 char *buf)
427{
428 struct Scsi_Host *shost = class_to_shost(dev);
429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
430 struct lpfc_hba *phba = vport->phba;
431 int len = 0;
432
433 switch (phba->link_state) {
434 case LPFC_LINK_UNKNOWN:
435 case LPFC_WARM_START:
436 case LPFC_INIT_START:
437 case LPFC_INIT_MBX_CMDS:
438 case LPFC_LINK_DOWN:
439 case LPFC_HBA_ERROR:
440 if (phba->hba_flag & LINK_DISABLED)
441 len += snprintf(buf + len, PAGE_SIZE-len,
442 "Link Down - User disabled\n");
443 else
444 len += snprintf(buf + len, PAGE_SIZE-len,
445 "Link Down\n");
446 break;
447 case LPFC_LINK_UP:
448 case LPFC_CLEAR_LA:
449 case LPFC_HBA_READY:
450 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
451
452 switch (vport->port_state) {
453 case LPFC_LOCAL_CFG_LINK:
454 len += snprintf(buf + len, PAGE_SIZE-len,
455 "Configuring Link\n");
456 break;
457 case LPFC_FDISC:
458 case LPFC_FLOGI:
459 case LPFC_FABRIC_CFG_LINK:
460 case LPFC_NS_REG:
461 case LPFC_NS_QRY:
462 case LPFC_BUILD_DISC_LIST:
463 case LPFC_DISC_AUTH:
464 len += snprintf(buf + len, PAGE_SIZE - len,
465 "Discovery\n");
466 break;
467 case LPFC_VPORT_READY:
468 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
469 break;
470
471 case LPFC_VPORT_FAILED:
472 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
473 break;
474
475 case LPFC_VPORT_UNKNOWN:
476 len += snprintf(buf + len, PAGE_SIZE - len,
477 "Unknown\n");
478 break;
479 }
480 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
481 len += snprintf(buf + len, PAGE_SIZE-len,
482 " Menlo Maint Mode\n");
483 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
484 if (vport->fc_flag & FC_PUBLIC_LOOP)
485 len += snprintf(buf + len, PAGE_SIZE-len,
486 " Public Loop\n");
487 else
488 len += snprintf(buf + len, PAGE_SIZE-len,
489 " Private Loop\n");
490 } else {
491 if (vport->fc_flag & FC_FABRIC)
492 len += snprintf(buf + len, PAGE_SIZE-len,
493 " Fabric\n");
494 else
495 len += snprintf(buf + len, PAGE_SIZE-len,
496 " Point-2-Point\n");
497 }
498 }
499
500 return len;
501}
502
503
504
505
506
507
508
509
510
511static ssize_t
512lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
514{
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518
519 if (phba->sli_rev < LPFC_SLI_REV4)
520 return snprintf(buf, PAGE_SIZE, "fc\n");
521
522 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
523 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
524 return snprintf(buf, PAGE_SIZE, "fcoe\n");
525 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
526 return snprintf(buf, PAGE_SIZE, "fc\n");
527 }
528 return snprintf(buf, PAGE_SIZE, "unknown\n");
529}
530
531
532
533
534
535
536
537
538
539
540
541
542
543static ssize_t
544lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
545 const char *buf, size_t count)
546{
547 struct Scsi_Host *shost = class_to_shost(dev);
548 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
549 struct lpfc_hba *phba = vport->phba;
550
551 int status = -EINVAL;
552
553 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
554 (phba->link_state == LPFC_LINK_DOWN))
555 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
556 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
557 (phba->link_state >= LPFC_LINK_UP))
558 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
559
560 if (status == 0)
561 return strlen(buf);
562 else
563 return status;
564}
565
566
567
568
569
570
571
572
573
574
575
576
577
578static ssize_t
579lpfc_num_discovered_ports_show(struct device *dev,
580 struct device_attribute *attr, char *buf)
581{
582 struct Scsi_Host *shost = class_to_shost(dev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584
585 return snprintf(buf, PAGE_SIZE, "%d\n",
586 vport->fc_map_cnt + vport->fc_unmap_cnt);
587}
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603static int
604lpfc_issue_lip(struct Scsi_Host *shost)
605{
606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
607 struct lpfc_hba *phba = vport->phba;
608 LPFC_MBOXQ_t *pmboxq;
609 int mbxstatus = MBXERR_ERROR;
610
611 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
612 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
613 return -EPERM;
614
615 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
616
617 if (!pmboxq)
618 return -ENOMEM;
619
620 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
621 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
622 pmboxq->u.mb.mbxOwner = OWN_HOST;
623
624 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
625
626 if ((mbxstatus == MBX_SUCCESS) &&
627 (pmboxq->u.mb.mbxStatus == 0 ||
628 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
629 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
630 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
631 phba->cfg_link_speed);
632 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
633 phba->fc_ratov * 2);
634 if ((mbxstatus == MBX_SUCCESS) &&
635 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
637 "2859 SLI authentication is required "
638 "for INIT_LINK but has not done yet\n");
639 }
640
641 lpfc_set_loopback_flag(phba);
642 if (mbxstatus != MBX_TIMEOUT)
643 mempool_free(pmboxq, phba->mbox_mem_pool);
644
645 if (mbxstatus == MBXERR_ERROR)
646 return -EIO;
647
648 return 0;
649}
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666static int
667lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
668{
669 struct completion online_compl;
670 struct lpfc_sli_ring *pring;
671 struct lpfc_sli *psli;
672 int status = 0;
673 int cnt = 0;
674 int i;
675 int rc;
676
677 init_completion(&online_compl);
678 rc = lpfc_workq_post_event(phba, &status, &online_compl,
679 LPFC_EVT_OFFLINE_PREP);
680 if (rc == 0)
681 return -ENOMEM;
682
683 wait_for_completion(&online_compl);
684
685 if (status != 0)
686 return -EIO;
687
688 psli = &phba->sli;
689
690
691
692
693 for (i = 0; i < psli->num_rings; i++) {
694 pring = &psli->ring[i];
695 while (!list_empty(&pring->txcmplq)) {
696 msleep(10);
697 if (cnt++ > 500) {
698 lpfc_printf_log(phba,
699 KERN_WARNING, LOG_INIT,
700 "0466 Outstanding IO when "
701 "bringing Adapter offline\n");
702 break;
703 }
704 }
705 }
706
707 init_completion(&online_compl);
708 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
709 if (rc == 0)
710 return -ENOMEM;
711
712 wait_for_completion(&online_compl);
713
714 if (status != 0)
715 return -EIO;
716
717 return 0;
718}
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737int
738lpfc_selective_reset(struct lpfc_hba *phba)
739{
740 struct completion online_compl;
741 int status = 0;
742 int rc;
743
744 if (!phba->cfg_enable_hba_reset)
745 return -EACCES;
746
747 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
748 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
749
750 if (status != 0)
751 return status;
752 }
753
754 init_completion(&online_compl);
755 rc = lpfc_workq_post_event(phba, &status, &online_compl,
756 LPFC_EVT_ONLINE);
757 if (rc == 0)
758 return -ENOMEM;
759
760 wait_for_completion(&online_compl);
761
762 if (status != 0)
763 return -EIO;
764
765 return 0;
766}
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789static ssize_t
790lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
791 const char *buf, size_t count)
792{
793 struct Scsi_Host *shost = class_to_shost(dev);
794 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
795 struct lpfc_hba *phba = vport->phba;
796 int status = -EINVAL;
797
798 if (!phba->cfg_enable_hba_reset)
799 return -EACCES;
800
801 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
802 status = phba->lpfc_selective_reset(phba);
803
804 if (status == 0)
805 return strlen(buf);
806 else
807 return status;
808}
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826int
827lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
828{
829 struct lpfc_register portstat_reg = {0};
830 int i;
831
832 msleep(100);
833 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
834 &portstat_reg.word0);
835
836
837 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
838 !bf_get(lpfc_sliport_status_err, &portstat_reg))
839 return -EPERM;
840
841
842 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
843 msleep(10);
844 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
845 &portstat_reg.word0);
846 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
847 continue;
848 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
849 continue;
850 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
851 continue;
852 break;
853 }
854
855 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
856 return 0;
857 else
858 return -EIO;
859}
860
861
862
863
864
865
866
867
868
869
870
871
872static ssize_t
873lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
874{
875 struct completion online_compl;
876 struct pci_dev *pdev = phba->pcidev;
877 uint32_t before_fc_flag;
878 uint32_t sriov_nr_virtfn;
879 uint32_t reg_val;
880 int status = 0, rc = 0;
881 int job_posted = 1, sriov_err;
882
883 if (!phba->cfg_enable_hba_reset)
884 return -EACCES;
885
886 if ((phba->sli_rev < LPFC_SLI_REV4) ||
887 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
888 LPFC_SLI_INTF_IF_TYPE_2))
889 return -EPERM;
890
891
892 before_fc_flag = phba->pport->fc_flag;
893 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
894
895
896 if (phba->cfg_sriov_nr_virtfn) {
897 pci_disable_sriov(pdev);
898 phba->cfg_sriov_nr_virtfn = 0;
899 }
900
901 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
902
903 if (status != 0)
904 return status;
905
906
907 msleep(100);
908
909 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
910 LPFC_CTL_PDEV_CTL_OFFSET);
911
912 if (opcode == LPFC_FW_DUMP)
913 reg_val |= LPFC_FW_DUMP_REQUEST;
914 else if (opcode == LPFC_FW_RESET)
915 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
916 else if (opcode == LPFC_DV_RESET)
917 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
918
919 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
920 LPFC_CTL_PDEV_CTL_OFFSET);
921
922 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
923
924
925 rc = lpfc_sli4_pdev_status_reg_wait(phba);
926
927 if (rc == -EPERM) {
928
929 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
930 "3150 No privilege to perform the requested "
931 "access: x%x\n", reg_val);
932 } else if (rc == -EIO) {
933
934 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
935 "3153 Fail to perform the requested "
936 "access: x%x\n", reg_val);
937 return rc;
938 }
939
940
941 if (before_fc_flag & FC_OFFLINE_MODE)
942 goto out;
943
944 init_completion(&online_compl);
945 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
946 LPFC_EVT_ONLINE);
947 if (!job_posted)
948 goto out;
949
950 wait_for_completion(&online_compl);
951
952out:
953
954 if (sriov_nr_virtfn) {
955 sriov_err =
956 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
957 if (!sriov_err)
958 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
959 }
960
961
962 if (!rc) {
963 if (!job_posted)
964 rc = -ENOMEM;
965 else if (status)
966 rc = -EIO;
967 }
968 return rc;
969}
970
971
972
973
974
975
976
977
978
979static ssize_t
980lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
982{
983 struct Scsi_Host *shost = class_to_shost(dev);
984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986
987 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
988}
989
990
991
992
993
994
995
996
997
998static ssize_t
999lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1000 char *buf)
1001{
1002 struct Scsi_Host *shost = class_to_shost(dev);
1003 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1004 struct lpfc_hba *phba = vport->phba;
1005 char * state;
1006
1007 if (phba->link_state == LPFC_HBA_ERROR)
1008 state = "error";
1009 else if (phba->link_state == LPFC_WARM_START)
1010 state = "warm start";
1011 else if (phba->link_state == LPFC_INIT_START)
1012 state = "offline";
1013 else
1014 state = "online";
1015
1016 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1017}
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032static ssize_t
1033lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1034 const char *buf, size_t count)
1035{
1036 struct Scsi_Host *shost = class_to_shost(dev);
1037 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1038 struct lpfc_hba *phba = vport->phba;
1039 struct completion online_compl;
1040 char *board_mode_str = NULL;
1041 int status = 0;
1042 int rc;
1043
1044 if (!phba->cfg_enable_hba_reset) {
1045 status = -EACCES;
1046 goto board_mode_out;
1047 }
1048
1049 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1050 "3050 lpfc_board_mode set to %s\n", buf);
1051
1052 init_completion(&online_compl);
1053
1054 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1055 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1056 LPFC_EVT_ONLINE);
1057 if (rc == 0) {
1058 status = -ENOMEM;
1059 goto board_mode_out;
1060 }
1061 wait_for_completion(&online_compl);
1062 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1063 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1064 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1065 if (phba->sli_rev == LPFC_SLI_REV4)
1066 status = -EINVAL;
1067 else
1068 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1069 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1070 if (phba->sli_rev == LPFC_SLI_REV4)
1071 status = -EINVAL;
1072 else
1073 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1074 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1075 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1076 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1077 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1078 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1079 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1080 else
1081 status = -EINVAL;
1082
1083board_mode_out:
1084 if (!status)
1085 return strlen(buf);
1086 else {
1087 board_mode_str = strchr(buf, '\n');
1088 if (board_mode_str)
1089 *board_mode_str = '\0';
1090 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1091 "3097 Failed \"%s\", status(%d), "
1092 "fc_flag(x%x)\n",
1093 buf, status, phba->pport->fc_flag);
1094 return status;
1095 }
1096}
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116static int
1117lpfc_get_hba_info(struct lpfc_hba *phba,
1118 uint32_t *mxri, uint32_t *axri,
1119 uint32_t *mrpi, uint32_t *arpi,
1120 uint32_t *mvpi, uint32_t *avpi)
1121{
1122 struct lpfc_mbx_read_config *rd_config;
1123 LPFC_MBOXQ_t *pmboxq;
1124 MAILBOX_t *pmb;
1125 int rc = 0;
1126 uint32_t max_vpi;
1127
1128
1129
1130
1131
1132 if (phba->link_state < LPFC_LINK_DOWN ||
1133 !phba->mbox_mem_pool ||
1134 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1135 return 0;
1136
1137 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1138 return 0;
1139
1140 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1141 if (!pmboxq)
1142 return 0;
1143 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1144
1145 pmb = &pmboxq->u.mb;
1146 pmb->mbxCommand = MBX_READ_CONFIG;
1147 pmb->mbxOwner = OWN_HOST;
1148 pmboxq->context1 = NULL;
1149
1150 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1151 rc = MBX_NOT_FINISHED;
1152 else
1153 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1154
1155 if (rc != MBX_SUCCESS) {
1156 if (rc != MBX_TIMEOUT)
1157 mempool_free(pmboxq, phba->mbox_mem_pool);
1158 return 0;
1159 }
1160
1161 if (phba->sli_rev == LPFC_SLI_REV4) {
1162 rd_config = &pmboxq->u.mqe.un.rd_config;
1163 if (mrpi)
1164 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1165 if (arpi)
1166 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1167 phba->sli4_hba.max_cfg_param.rpi_used;
1168 if (mxri)
1169 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1170 if (axri)
1171 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1172 phba->sli4_hba.max_cfg_param.xri_used;
1173
1174
1175
1176
1177 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1178 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1179
1180 if (mvpi)
1181 *mvpi = max_vpi;
1182 if (avpi)
1183 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1184 } else {
1185 if (mrpi)
1186 *mrpi = pmb->un.varRdConfig.max_rpi;
1187 if (arpi)
1188 *arpi = pmb->un.varRdConfig.avail_rpi;
1189 if (mxri)
1190 *mxri = pmb->un.varRdConfig.max_xri;
1191 if (axri)
1192 *axri = pmb->un.varRdConfig.avail_xri;
1193 if (mvpi)
1194 *mvpi = pmb->un.varRdConfig.max_vpi;
1195 if (avpi)
1196 *avpi = pmb->un.varRdConfig.avail_vpi;
1197 }
1198
1199 mempool_free(pmboxq, phba->mbox_mem_pool);
1200 return 1;
1201}
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217static ssize_t
1218lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1219 char *buf)
1220{
1221 struct Scsi_Host *shost = class_to_shost(dev);
1222 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1223 struct lpfc_hba *phba = vport->phba;
1224 uint32_t cnt;
1225
1226 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1227 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1228 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1229}
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245static ssize_t
1246lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1247 char *buf)
1248{
1249 struct Scsi_Host *shost = class_to_shost(dev);
1250 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1251 struct lpfc_hba *phba = vport->phba;
1252 uint32_t cnt, acnt;
1253
1254 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1255 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1256 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1257}
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273static ssize_t
1274lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1275 char *buf)
1276{
1277 struct Scsi_Host *shost = class_to_shost(dev);
1278 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1279 struct lpfc_hba *phba = vport->phba;
1280 uint32_t cnt;
1281
1282 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1283 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1284 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1285}
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301static ssize_t
1302lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1303 char *buf)
1304{
1305 struct Scsi_Host *shost = class_to_shost(dev);
1306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1307 struct lpfc_hba *phba = vport->phba;
1308 uint32_t cnt, acnt;
1309
1310 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1311 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1312 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1313}
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329static ssize_t
1330lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1331 char *buf)
1332{
1333 struct Scsi_Host *shost = class_to_shost(dev);
1334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1335 struct lpfc_hba *phba = vport->phba;
1336 uint32_t cnt;
1337
1338 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1339 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1340 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1341}
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357static ssize_t
1358lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1359 char *buf)
1360{
1361 struct Scsi_Host *shost = class_to_shost(dev);
1362 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1363 struct lpfc_hba *phba = vport->phba;
1364 uint32_t cnt, acnt;
1365
1366 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1367 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1368 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1369}
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384static ssize_t
1385lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1386 char *buf)
1387{
1388 struct Scsi_Host *shost = class_to_shost(dev);
1389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1390 struct lpfc_hba *phba = vport->phba;
1391
1392 if (!(phba->max_vpi))
1393 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1394 if (vport->port_type == LPFC_PHYSICAL_PORT)
1395 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1396 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1397}
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410static ssize_t
1411lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1412 char *buf)
1413{
1414 struct Scsi_Host *shost = class_to_shost(dev);
1415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1416 struct lpfc_hba *phba = vport->phba;
1417
1418 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1419}
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435static ssize_t
1436lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1437 const char *buf, size_t count)
1438{
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;
1442 uint32_t creg_val;
1443 uint32_t old_val;
1444 int val=0;
1445
1446 if (!isdigit(buf[0]))
1447 return -EINVAL;
1448
1449 if (sscanf(buf, "%i", &val) != 1)
1450 return -EINVAL;
1451
1452 if ((val & 0x3) != val)
1453 return -EINVAL;
1454
1455 if (phba->sli_rev == LPFC_SLI_REV4)
1456 val = 0;
1457
1458 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1459 "3051 lpfc_poll changed from %d to %d\n",
1460 phba->cfg_poll, val);
1461
1462 spin_lock_irq(&phba->hbalock);
1463
1464 old_val = phba->cfg_poll;
1465
1466 if (val & ENABLE_FCP_RING_POLLING) {
1467 if ((val & DISABLE_FCP_RING_INT) &&
1468 !(old_val & DISABLE_FCP_RING_INT)) {
1469 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1470 spin_unlock_irq(&phba->hbalock);
1471 return -EINVAL;
1472 }
1473 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1474 writel(creg_val, phba->HCregaddr);
1475 readl(phba->HCregaddr);
1476
1477 lpfc_poll_start_timer(phba);
1478 }
1479 } else if (val != 0x0) {
1480 spin_unlock_irq(&phba->hbalock);
1481 return -EINVAL;
1482 }
1483
1484 if (!(val & DISABLE_FCP_RING_INT) &&
1485 (old_val & DISABLE_FCP_RING_INT))
1486 {
1487 spin_unlock_irq(&phba->hbalock);
1488 del_timer(&phba->fcp_poll_timer);
1489 spin_lock_irq(&phba->hbalock);
1490 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1491 spin_unlock_irq(&phba->hbalock);
1492 return -EINVAL;
1493 }
1494 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1495 writel(creg_val, phba->HCregaddr);
1496 readl(phba->HCregaddr);
1497 }
1498
1499 phba->cfg_poll = val;
1500
1501 spin_unlock_irq(&phba->hbalock);
1502
1503 return strlen(buf);
1504}
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514static ssize_t
1515lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1516 char *buf)
1517{
1518 struct Scsi_Host *shost = class_to_shost(dev);
1519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1520 struct lpfc_hba *phba = vport->phba;
1521
1522 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1523}
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533static ssize_t
1534lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1535 char *buf)
1536{
1537 struct Scsi_Host *shost = class_to_shost(dev);
1538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1539 struct lpfc_hba *phba = vport->phba;
1540
1541 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1542}
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552static ssize_t
1553lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1554 char *buf)
1555{
1556 struct Scsi_Host *shost = class_to_shost(dev);
1557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1558 struct lpfc_hba *phba = vport->phba;
1559
1560 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1561 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1562 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1563 "" : "Not ");
1564}
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578static ssize_t
1579lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1580 struct device_attribute *attr,
1581 char *buf)
1582{
1583 struct Scsi_Host *shost = class_to_shost(dev);
1584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1585 struct lpfc_hba *phba = vport->phba;
1586 uint16_t max_nr_virtfn;
1587
1588 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1589 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1590}
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606#define lpfc_param_show(attr) \
1607static ssize_t \
1608lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1609 char *buf) \
1610{ \
1611 struct Scsi_Host *shost = class_to_shost(dev);\
1612 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1613 struct lpfc_hba *phba = vport->phba;\
1614 uint val = 0;\
1615 val = phba->cfg_##attr;\
1616 return snprintf(buf, PAGE_SIZE, "%d\n",\
1617 phba->cfg_##attr);\
1618}
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634#define lpfc_param_hex_show(attr) \
1635static ssize_t \
1636lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1637 char *buf) \
1638{ \
1639 struct Scsi_Host *shost = class_to_shost(dev);\
1640 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1641 struct lpfc_hba *phba = vport->phba;\
1642 uint val = 0;\
1643 val = phba->cfg_##attr;\
1644 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1645 phba->cfg_##attr);\
1646}
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667#define lpfc_param_init(attr, default, minval, maxval) \
1668static int \
1669lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1670{ \
1671 if (val >= minval && val <= maxval) {\
1672 phba->cfg_##attr = val;\
1673 return 0;\
1674 }\
1675 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1676 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1677 "allowed range is ["#minval", "#maxval"]\n", val); \
1678 phba->cfg_##attr = default;\
1679 return -EINVAL;\
1680}
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702#define lpfc_param_set(attr, default, minval, maxval) \
1703static int \
1704lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1705{ \
1706 if (val >= minval && val <= maxval) {\
1707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1708 "3052 lpfc_" #attr " changed from %d to %d\n", \
1709 phba->cfg_##attr, val); \
1710 phba->cfg_##attr = val;\
1711 return 0;\
1712 }\
1713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1714 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1715 "allowed range is ["#minval", "#maxval"]\n", val); \
1716 return -EINVAL;\
1717}
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740#define lpfc_param_store(attr) \
1741static ssize_t \
1742lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1743 const char *buf, size_t count) \
1744{ \
1745 struct Scsi_Host *shost = class_to_shost(dev);\
1746 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1747 struct lpfc_hba *phba = vport->phba;\
1748 uint val = 0;\
1749 if (!isdigit(buf[0]))\
1750 return -EINVAL;\
1751 if (sscanf(buf, "%i", &val) != 1)\
1752 return -EINVAL;\
1753 if (lpfc_##attr##_set(phba, val) == 0) \
1754 return strlen(buf);\
1755 else \
1756 return -EINVAL;\
1757}
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773#define lpfc_vport_param_show(attr) \
1774static ssize_t \
1775lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1776 char *buf) \
1777{ \
1778 struct Scsi_Host *shost = class_to_shost(dev);\
1779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1780 uint val = 0;\
1781 val = vport->cfg_##attr;\
1782 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1783}
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800#define lpfc_vport_param_hex_show(attr) \
1801static ssize_t \
1802lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1803 char *buf) \
1804{ \
1805 struct Scsi_Host *shost = class_to_shost(dev);\
1806 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1807 uint val = 0;\
1808 val = vport->cfg_##attr;\
1809 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1810}
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830#define lpfc_vport_param_init(attr, default, minval, maxval) \
1831static int \
1832lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1833{ \
1834 if (val >= minval && val <= maxval) {\
1835 vport->cfg_##attr = val;\
1836 return 0;\
1837 }\
1838 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1839 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1840 "allowed range is ["#minval", "#maxval"]\n", val); \
1841 vport->cfg_##attr = default;\
1842 return -EINVAL;\
1843}
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862#define lpfc_vport_param_set(attr, default, minval, maxval) \
1863static int \
1864lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1865{ \
1866 if (val >= minval && val <= maxval) {\
1867 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1868 "3053 lpfc_" #attr \
1869 " changed from %d (x%x) to %d (x%x)\n", \
1870 vport->cfg_##attr, vport->cfg_##attr, \
1871 val, val); \
1872 vport->cfg_##attr = val;\
1873 return 0;\
1874 }\
1875 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1876 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1877 "allowed range is ["#minval", "#maxval"]\n", val); \
1878 return -EINVAL;\
1879}
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898#define lpfc_vport_param_store(attr) \
1899static ssize_t \
1900lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1901 const char *buf, size_t count) \
1902{ \
1903 struct Scsi_Host *shost = class_to_shost(dev);\
1904 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1905 uint val = 0;\
1906 if (!isdigit(buf[0]))\
1907 return -EINVAL;\
1908 if (sscanf(buf, "%i", &val) != 1)\
1909 return -EINVAL;\
1910 if (lpfc_##attr##_set(vport, val) == 0) \
1911 return strlen(buf);\
1912 else \
1913 return -EINVAL;\
1914}
1915
1916
1917#define LPFC_ATTR(name, defval, minval, maxval, desc) \
1918static uint lpfc_##name = defval;\
1919module_param(lpfc_##name, uint, S_IRUGO);\
1920MODULE_PARM_DESC(lpfc_##name, desc);\
1921lpfc_param_init(name, defval, minval, maxval)
1922
1923#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1924static uint lpfc_##name = defval;\
1925module_param(lpfc_##name, uint, S_IRUGO);\
1926MODULE_PARM_DESC(lpfc_##name, desc);\
1927lpfc_param_show(name)\
1928lpfc_param_init(name, defval, minval, maxval)\
1929static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1930
1931#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1932static uint lpfc_##name = defval;\
1933module_param(lpfc_##name, uint, S_IRUGO);\
1934MODULE_PARM_DESC(lpfc_##name, desc);\
1935lpfc_param_show(name)\
1936lpfc_param_init(name, defval, minval, maxval)\
1937lpfc_param_set(name, defval, minval, maxval)\
1938lpfc_param_store(name)\
1939static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1940 lpfc_##name##_show, lpfc_##name##_store)
1941
1942#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1943static uint lpfc_##name = defval;\
1944module_param(lpfc_##name, uint, S_IRUGO);\
1945MODULE_PARM_DESC(lpfc_##name, desc);\
1946lpfc_param_hex_show(name)\
1947lpfc_param_init(name, defval, minval, maxval)\
1948static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1949
1950#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1951static uint lpfc_##name = defval;\
1952module_param(lpfc_##name, uint, S_IRUGO);\
1953MODULE_PARM_DESC(lpfc_##name, desc);\
1954lpfc_param_hex_show(name)\
1955lpfc_param_init(name, defval, minval, maxval)\
1956lpfc_param_set(name, defval, minval, maxval)\
1957lpfc_param_store(name)\
1958static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1959 lpfc_##name##_show, lpfc_##name##_store)
1960
1961#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1962static uint lpfc_##name = defval;\
1963module_param(lpfc_##name, uint, S_IRUGO);\
1964MODULE_PARM_DESC(lpfc_##name, desc);\
1965lpfc_vport_param_init(name, defval, minval, maxval)
1966
1967#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1968static uint lpfc_##name = defval;\
1969module_param(lpfc_##name, uint, S_IRUGO);\
1970MODULE_PARM_DESC(lpfc_##name, desc);\
1971lpfc_vport_param_show(name)\
1972lpfc_vport_param_init(name, defval, minval, maxval)\
1973static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1974
1975#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1976static uint lpfc_##name = defval;\
1977module_param(lpfc_##name, uint, S_IRUGO);\
1978MODULE_PARM_DESC(lpfc_##name, desc);\
1979lpfc_vport_param_show(name)\
1980lpfc_vport_param_init(name, defval, minval, maxval)\
1981lpfc_vport_param_set(name, defval, minval, maxval)\
1982lpfc_vport_param_store(name)\
1983static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1984 lpfc_##name##_show, lpfc_##name##_store)
1985
1986#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1987static uint lpfc_##name = defval;\
1988module_param(lpfc_##name, uint, S_IRUGO);\
1989MODULE_PARM_DESC(lpfc_##name, desc);\
1990lpfc_vport_param_hex_show(name)\
1991lpfc_vport_param_init(name, defval, minval, maxval)\
1992static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1993
1994#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1995static uint lpfc_##name = defval;\
1996module_param(lpfc_##name, uint, S_IRUGO);\
1997MODULE_PARM_DESC(lpfc_##name, desc);\
1998lpfc_vport_param_hex_show(name)\
1999lpfc_vport_param_init(name, defval, minval, maxval)\
2000lpfc_vport_param_set(name, defval, minval, maxval)\
2001lpfc_vport_param_store(name)\
2002static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
2003 lpfc_##name##_show, lpfc_##name##_store)
2004
2005static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2006static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2007static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2008static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2009static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2010static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2011static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2012static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2013static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2014static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2015static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2016static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2017static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2018 lpfc_link_state_store);
2019static DEVICE_ATTR(option_rom_version, S_IRUGO,
2020 lpfc_option_rom_version_show, NULL);
2021static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2022 lpfc_num_discovered_ports_show, NULL);
2023static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2024static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2025static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2026static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2027static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2028 lpfc_board_mode_show, lpfc_board_mode_store);
2029static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2030static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2031static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2032static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2033static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2034static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2035static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2036static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2037static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2038static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2039static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2040static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2041static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2042 lpfc_sriov_hw_max_virtfn_show, NULL);
2043static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2044
2045static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058static ssize_t
2059lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2060 const char *buf, size_t count)
2061{
2062 struct Scsi_Host *shost = class_to_shost(dev);
2063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2064 struct lpfc_hba *phba = vport->phba;
2065 unsigned int cnt = count;
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081 if (buf[cnt-1] == '\n')
2082 cnt--;
2083
2084 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2085 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2086 return -EINVAL;
2087
2088 phba->soft_wwn_enable = 1;
2089 return count;
2090}
2091static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2092 lpfc_soft_wwn_enable_store);
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102static ssize_t
2103lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2104 char *buf)
2105{
2106 struct Scsi_Host *shost = class_to_shost(dev);
2107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2108 struct lpfc_hba *phba = vport->phba;
2109
2110 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2111 (unsigned long long)phba->cfg_soft_wwpn);
2112}
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127static ssize_t
2128lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2129 const char *buf, size_t count)
2130{
2131 struct Scsi_Host *shost = class_to_shost(dev);
2132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2133 struct lpfc_hba *phba = vport->phba;
2134 struct completion online_compl;
2135 int stat1=0, stat2=0;
2136 unsigned int i, j, cnt=count;
2137 u8 wwpn[8];
2138 int rc;
2139
2140 if (!phba->cfg_enable_hba_reset)
2141 return -EACCES;
2142 spin_lock_irq(&phba->hbalock);
2143 if (phba->over_temp_state == HBA_OVER_TEMP) {
2144 spin_unlock_irq(&phba->hbalock);
2145 return -EACCES;
2146 }
2147 spin_unlock_irq(&phba->hbalock);
2148
2149 if (buf[cnt-1] == '\n')
2150 cnt--;
2151
2152 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2153 ((cnt == 17) && (*buf++ != 'x')) ||
2154 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2155 return -EINVAL;
2156
2157 phba->soft_wwn_enable = 0;
2158
2159 memset(wwpn, 0, sizeof(wwpn));
2160
2161
2162 for (i=0, j=0; i < 16; i++) {
2163 int value;
2164
2165 value = hex_to_bin(*buf++);
2166 if (value >= 0)
2167 j = (j << 4) | value;
2168 else
2169 return -EINVAL;
2170 if (i % 2) {
2171 wwpn[i/2] = j & 0xff;
2172 j = 0;
2173 }
2174 }
2175 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2176 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2177 if (phba->cfg_soft_wwnn)
2178 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2179
2180 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2181 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2182
2183 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2184 if (stat1)
2185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2186 "0463 lpfc_soft_wwpn attribute set failed to "
2187 "reinit adapter - %d\n", stat1);
2188 init_completion(&online_compl);
2189 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2190 LPFC_EVT_ONLINE);
2191 if (rc == 0)
2192 return -ENOMEM;
2193
2194 wait_for_completion(&online_compl);
2195 if (stat2)
2196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2197 "0464 lpfc_soft_wwpn attribute set failed to "
2198 "reinit adapter - %d\n", stat2);
2199 return (stat1 || stat2) ? -EIO : count;
2200}
2201static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
2202 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212static ssize_t
2213lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2214 char *buf)
2215{
2216 struct Scsi_Host *shost = class_to_shost(dev);
2217 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2218 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2219 (unsigned long long)phba->cfg_soft_wwnn);
2220}
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232static ssize_t
2233lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2234 const char *buf, size_t count)
2235{
2236 struct Scsi_Host *shost = class_to_shost(dev);
2237 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2238 unsigned int i, j, cnt=count;
2239 u8 wwnn[8];
2240
2241
2242 if (buf[cnt-1] == '\n')
2243 cnt--;
2244
2245 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
2246 ((cnt == 17) && (*buf++ != 'x')) ||
2247 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2248 return -EINVAL;
2249
2250
2251
2252
2253
2254
2255 memset(wwnn, 0, sizeof(wwnn));
2256
2257
2258 for (i=0, j=0; i < 16; i++) {
2259 int value;
2260
2261 value = hex_to_bin(*buf++);
2262 if (value >= 0)
2263 j = (j << 4) | value;
2264 else
2265 return -EINVAL;
2266 if (i % 2) {
2267 wwnn[i/2] = j & 0xff;
2268 j = 0;
2269 }
2270 }
2271 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2272
2273 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2274 "lpfc%d: soft_wwnn set. Value will take effect upon "
2275 "setting of the soft_wwpn\n", phba->brd_no);
2276
2277 return count;
2278}
2279static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
2280 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2281
2282
2283static int lpfc_poll = 0;
2284module_param(lpfc_poll, int, S_IRUGO);
2285MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2286 " 0 - none,"
2287 " 1 - poll with interrupts enabled"
2288 " 3 - poll and disable FCP ring interrupts");
2289
2290static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2291 lpfc_poll_show, lpfc_poll_store);
2292
2293int lpfc_sli_mode = 0;
2294module_param(lpfc_sli_mode, int, S_IRUGO);
2295MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2296 " 0 - auto (SLI-3 if supported),"
2297 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2298 " 3 - select SLI-3");
2299
2300int lpfc_enable_npiv = 1;
2301module_param(lpfc_enable_npiv, int, S_IRUGO);
2302MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2303lpfc_param_show(enable_npiv);
2304lpfc_param_init(enable_npiv, 1, 0, 1);
2305static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2306
2307LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2308 "FCF Fast failover=1 Priority failover=2");
2309
2310int lpfc_enable_rrq = 2;
2311module_param(lpfc_enable_rrq, int, S_IRUGO);
2312MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2313lpfc_param_show(enable_rrq);
2314
2315
2316
2317
2318
2319
2320lpfc_param_init(enable_rrq, 2, 0, 2);
2321static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2322
2323
2324
2325
2326
2327
2328
2329
2330LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2331 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2332 "Suppress Link Up at initialization");
2333
2334
2335
2336
2337
2338
2339
2340
2341static ssize_t
2342lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2343{
2344 struct Scsi_Host *shost = class_to_shost(dev);
2345 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2346
2347 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2348}
2349
2350static DEVICE_ATTR(iocb_hw, S_IRUGO,
2351 lpfc_iocb_hw_show, NULL);
2352static ssize_t
2353lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2354{
2355 struct Scsi_Host *shost = class_to_shost(dev);
2356 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2357
2358 return snprintf(buf, PAGE_SIZE, "%d\n",
2359 phba->sli.ring[LPFC_ELS_RING].txq_max);
2360}
2361
2362static DEVICE_ATTR(txq_hw, S_IRUGO,
2363 lpfc_txq_hw_show, NULL);
2364static ssize_t
2365lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2366 char *buf)
2367{
2368 struct Scsi_Host *shost = class_to_shost(dev);
2369 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2370
2371 return snprintf(buf, PAGE_SIZE, "%d\n",
2372 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2373}
2374
2375static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2376 lpfc_txcmplq_hw_show, NULL);
2377
2378int lpfc_iocb_cnt = 2;
2379module_param(lpfc_iocb_cnt, int, S_IRUGO);
2380MODULE_PARM_DESC(lpfc_iocb_cnt,
2381 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2382lpfc_param_show(iocb_cnt);
2383lpfc_param_init(iocb_cnt, 2, 1, 5);
2384static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2385 lpfc_iocb_cnt_show, NULL);
2386
2387
2388
2389
2390
2391static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2392static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2393module_param(lpfc_nodev_tmo, int, 0);
2394MODULE_PARM_DESC(lpfc_nodev_tmo,
2395 "Seconds driver will hold I/O waiting "
2396 "for a device to come back");
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406static ssize_t
2407lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2408 char *buf)
2409{
2410 struct Scsi_Host *shost = class_to_shost(dev);
2411 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2412
2413 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2414}
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431static int
2432lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2433{
2434 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2435 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2436 if (val != LPFC_DEF_DEVLOSS_TMO)
2437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2438 "0407 Ignoring nodev_tmo module "
2439 "parameter because devloss_tmo is "
2440 "set.\n");
2441 return 0;
2442 }
2443
2444 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2445 vport->cfg_nodev_tmo = val;
2446 vport->cfg_devloss_tmo = val;
2447 return 0;
2448 }
2449 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2450 "0400 lpfc_nodev_tmo attribute cannot be set to"
2451 " %d, allowed range is [%d, %d]\n",
2452 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2453 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2454 return -EINVAL;
2455}
2456
2457
2458
2459
2460
2461
2462
2463
2464static void
2465lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2466{
2467 struct Scsi_Host *shost;
2468 struct lpfc_nodelist *ndlp;
2469
2470 shost = lpfc_shost_from_vport(vport);
2471 spin_lock_irq(shost->host_lock);
2472 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2473 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2474 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2475 spin_unlock_irq(shost->host_lock);
2476}
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493static int
2494lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2495{
2496 if (vport->dev_loss_tmo_changed ||
2497 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2498 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2499 "0401 Ignoring change to nodev_tmo "
2500 "because devloss_tmo is set.\n");
2501 return 0;
2502 }
2503 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2504 vport->cfg_nodev_tmo = val;
2505 vport->cfg_devloss_tmo = val;
2506
2507
2508
2509
2510 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2511 lpfc_update_rport_devloss_tmo(vport);
2512 return 0;
2513 }
2514 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2515 "0403 lpfc_nodev_tmo attribute cannot be set to"
2516 "%d, allowed range is [%d, %d]\n",
2517 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2518 return -EINVAL;
2519}
2520
2521lpfc_vport_param_store(nodev_tmo)
2522
2523static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2524 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2525
2526
2527
2528
2529
2530
2531module_param(lpfc_devloss_tmo, int, S_IRUGO);
2532MODULE_PARM_DESC(lpfc_devloss_tmo,
2533 "Seconds driver will hold I/O waiting "
2534 "for a device to come back");
2535lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2536 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2537lpfc_vport_param_show(devloss_tmo)
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553static int
2554lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2555{
2556 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2557 vport->cfg_nodev_tmo = val;
2558 vport->cfg_devloss_tmo = val;
2559 vport->dev_loss_tmo_changed = 1;
2560 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2561 lpfc_update_rport_devloss_tmo(vport);
2562 return 0;
2563 }
2564
2565 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2566 "0404 lpfc_devloss_tmo attribute cannot be set to"
2567 " %d, allowed range is [%d, %d]\n",
2568 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2569 return -EINVAL;
2570}
2571
2572lpfc_vport_param_store(devloss_tmo)
2573static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2574 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2575
2576
2577
2578
2579
2580
2581
2582LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2583 "Verbose logging bit-mask");
2584
2585
2586
2587
2588
2589LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
2590 "Deregister nameserver objects before LOGO");
2591
2592
2593
2594
2595
2596
2597
2598
2599LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
2600 "Max number of FCP commands we can queue to a specific LUN");
2601
2602
2603
2604
2605
2606LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2607 "Max number of FCP commands we can queue to a specific target port");
2608
2609
2610
2611
2612
2613
2614
2615
2616LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2617 "Max number of FCP commands we can queue to a lpfc HBA");
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2629 "Allow peer ports on the same physical port to login to each "
2630 "other.");
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643static int lpfc_restrict_login = 1;
2644module_param(lpfc_restrict_login, int, S_IRUGO);
2645MODULE_PARM_DESC(lpfc_restrict_login,
2646 "Restrict virtual ports login to remote initiators.");
2647lpfc_vport_param_show(restrict_login);
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664static int
2665lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2666{
2667 if (val < 0 || val > 1) {
2668 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2669 "0422 lpfc_restrict_login attribute cannot "
2670 "be set to %d, allowed range is [0, 1]\n",
2671 val);
2672 vport->cfg_restrict_login = 1;
2673 return -EINVAL;
2674 }
2675 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2676 vport->cfg_restrict_login = 0;
2677 return 0;
2678 }
2679 vport->cfg_restrict_login = val;
2680 return 0;
2681}
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699static int
2700lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2701{
2702 if (val < 0 || val > 1) {
2703 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2704 "0425 lpfc_restrict_login attribute cannot "
2705 "be set to %d, allowed range is [0, 1]\n",
2706 val);
2707 vport->cfg_restrict_login = 1;
2708 return -EINVAL;
2709 }
2710 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2711 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2712 "0468 lpfc_restrict_login must be 0 for "
2713 "Physical ports.\n");
2714 vport->cfg_restrict_login = 0;
2715 return 0;
2716 }
2717 vport->cfg_restrict_login = val;
2718 return 0;
2719}
2720lpfc_vport_param_store(restrict_login);
2721static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2722 lpfc_restrict_login_show, lpfc_restrict_login_store);
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2742 "Start scanning for devices from highest ALPA to lowest");
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772static ssize_t
2773lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2774 const char *buf, size_t count)
2775{
2776 struct Scsi_Host *shost = class_to_shost(dev);
2777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2778 struct lpfc_hba *phba = vport->phba;
2779 int val = 0;
2780 int nolip = 0;
2781 const char *val_buf = buf;
2782 int err;
2783 uint32_t prev_val;
2784
2785 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2786 nolip = 1;
2787 val_buf = &buf[strlen("nolip ")];
2788 }
2789
2790 if (!isdigit(val_buf[0]))
2791 return -EINVAL;
2792 if (sscanf(val_buf, "%i", &val) != 1)
2793 return -EINVAL;
2794
2795 if (val >= 0 && val <= 6) {
2796 prev_val = phba->cfg_topology;
2797 phba->cfg_topology = val;
2798 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
2799 val == 4) {
2800 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2801 "3113 Loop mode not supported at speed %d\n",
2802 phba->cfg_link_speed);
2803 phba->cfg_topology = prev_val;
2804 return -EINVAL;
2805 }
2806 if (nolip)
2807 return strlen(buf);
2808
2809 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2810 "3054 lpfc_topology changed from %d to %d\n",
2811 prev_val, val);
2812 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
2813 phba->fc_topology_changed = 1;
2814 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2815 if (err) {
2816 phba->cfg_topology = prev_val;
2817 return -EINVAL;
2818 } else
2819 return strlen(buf);
2820 }
2821 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2822 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2823 "allowed range is [0, 6]\n",
2824 phba->brd_no, val);
2825 return -EINVAL;
2826}
2827static int lpfc_topology = 0;
2828module_param(lpfc_topology, int, S_IRUGO);
2829MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2830lpfc_param_show(topology)
2831lpfc_param_init(topology, 0, 0, 6)
2832static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2833 lpfc_topology_show, lpfc_topology_store);
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846static ssize_t
2847lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2848 char *buf)
2849{
2850 struct Scsi_Host *shost = class_to_shost(dev);
2851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2852 if (vport->vport_flag & STATIC_VPORT)
2853 sprintf(buf, "1\n");
2854 else
2855 sprintf(buf, "0\n");
2856
2857 return strlen(buf);
2858}
2859
2860
2861
2862
2863static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2864 lpfc_static_vport_show, NULL);
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885static ssize_t
2886lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2887 const char *buf, size_t count)
2888{
2889 struct Scsi_Host *shost = class_to_shost(dev);
2890 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2891 struct lpfc_hba *phba = vport->phba;
2892#define LPFC_MAX_DATA_CTRL_LEN 1024
2893 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2894 unsigned long i;
2895 char *str_ptr, *token;
2896 struct lpfc_vport **vports;
2897 struct Scsi_Host *v_shost;
2898 char *bucket_type_str, *base_str, *step_str;
2899 unsigned long base, step, bucket_type;
2900
2901 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2902 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2903 return -EINVAL;
2904
2905 strcpy(bucket_data, buf);
2906 str_ptr = &bucket_data[0];
2907
2908 token = strsep(&str_ptr, "\t ");
2909 if (!token)
2910 return -EINVAL;
2911
2912 bucket_type_str = strsep(&str_ptr, "\t ");
2913 if (!bucket_type_str)
2914 return -EINVAL;
2915
2916 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2917 bucket_type = LPFC_LINEAR_BUCKET;
2918 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2919 bucket_type = LPFC_POWER2_BUCKET;
2920 else
2921 return -EINVAL;
2922
2923 base_str = strsep(&str_ptr, "\t ");
2924 if (!base_str)
2925 return -EINVAL;
2926 base = simple_strtoul(base_str, NULL, 0);
2927
2928 step_str = strsep(&str_ptr, "\t ");
2929 if (!step_str)
2930 return -EINVAL;
2931 step = simple_strtoul(step_str, NULL, 0);
2932 if (!step)
2933 return -EINVAL;
2934
2935
2936 vports = lpfc_create_vport_work_array(phba);
2937 if (vports == NULL)
2938 return -ENOMEM;
2939
2940 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2941 v_shost = lpfc_shost_from_vport(vports[i]);
2942 spin_lock_irq(v_shost->host_lock);
2943
2944 vports[i]->stat_data_blocked = 1;
2945 if (vports[i]->stat_data_enabled)
2946 lpfc_vport_reset_stat_data(vports[i]);
2947 spin_unlock_irq(v_shost->host_lock);
2948 }
2949
2950
2951 phba->bucket_type = bucket_type;
2952 phba->bucket_base = base;
2953 phba->bucket_step = step;
2954
2955 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2956 v_shost = lpfc_shost_from_vport(vports[i]);
2957
2958
2959 spin_lock_irq(v_shost->host_lock);
2960 vports[i]->stat_data_blocked = 0;
2961 spin_unlock_irq(v_shost->host_lock);
2962 }
2963 lpfc_destroy_vport_work_array(phba, vports);
2964 return strlen(buf);
2965 }
2966
2967 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2968 vports = lpfc_create_vport_work_array(phba);
2969 if (vports == NULL)
2970 return -ENOMEM;
2971
2972 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2973 v_shost = lpfc_shost_from_vport(vports[i]);
2974 spin_lock_irq(shost->host_lock);
2975 vports[i]->stat_data_blocked = 1;
2976 lpfc_free_bucket(vport);
2977 vport->stat_data_enabled = 0;
2978 vports[i]->stat_data_blocked = 0;
2979 spin_unlock_irq(shost->host_lock);
2980 }
2981 lpfc_destroy_vport_work_array(phba, vports);
2982 phba->bucket_type = LPFC_NO_BUCKET;
2983 phba->bucket_base = 0;
2984 phba->bucket_step = 0;
2985 return strlen(buf);
2986 }
2987
2988 if (!strncmp(buf, "start", strlen("start"))) {
2989
2990 if (phba->bucket_type == LPFC_NO_BUCKET)
2991 return -EINVAL;
2992 spin_lock_irq(shost->host_lock);
2993 if (vport->stat_data_enabled) {
2994 spin_unlock_irq(shost->host_lock);
2995 return strlen(buf);
2996 }
2997 lpfc_alloc_bucket(vport);
2998 vport->stat_data_enabled = 1;
2999 spin_unlock_irq(shost->host_lock);
3000 return strlen(buf);
3001 }
3002
3003 if (!strncmp(buf, "stop", strlen("stop"))) {
3004 spin_lock_irq(shost->host_lock);
3005 if (vport->stat_data_enabled == 0) {
3006 spin_unlock_irq(shost->host_lock);
3007 return strlen(buf);
3008 }
3009 lpfc_free_bucket(vport);
3010 vport->stat_data_enabled = 0;
3011 spin_unlock_irq(shost->host_lock);
3012 return strlen(buf);
3013 }
3014
3015 if (!strncmp(buf, "reset", strlen("reset"))) {
3016 if ((phba->bucket_type == LPFC_NO_BUCKET)
3017 || !vport->stat_data_enabled)
3018 return strlen(buf);
3019 spin_lock_irq(shost->host_lock);
3020 vport->stat_data_blocked = 1;
3021 lpfc_vport_reset_stat_data(vport);
3022 vport->stat_data_blocked = 0;
3023 spin_unlock_irq(shost->host_lock);
3024 return strlen(buf);
3025 }
3026 return -EINVAL;
3027}
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039static ssize_t
3040lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3041 char *buf)
3042{
3043 struct Scsi_Host *shost = class_to_shost(dev);
3044 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3045 struct lpfc_hba *phba = vport->phba;
3046 int index = 0;
3047 int i;
3048 char *bucket_type;
3049 unsigned long bucket_value;
3050
3051 switch (phba->bucket_type) {
3052 case LPFC_LINEAR_BUCKET:
3053 bucket_type = "linear";
3054 break;
3055 case LPFC_POWER2_BUCKET:
3056 bucket_type = "power2";
3057 break;
3058 default:
3059 bucket_type = "No Bucket";
3060 break;
3061 }
3062
3063 sprintf(&buf[index], "Statistical Data enabled :%d, "
3064 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3065 " Bucket step :%d\nLatency Ranges :",
3066 vport->stat_data_enabled, vport->stat_data_blocked,
3067 bucket_type, phba->bucket_base, phba->bucket_step);
3068 index = strlen(buf);
3069 if (phba->bucket_type != LPFC_NO_BUCKET) {
3070 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3071 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3072 bucket_value = phba->bucket_base +
3073 phba->bucket_step * i;
3074 else
3075 bucket_value = phba->bucket_base +
3076 (1 << i) * phba->bucket_step;
3077
3078 if (index + 10 > PAGE_SIZE)
3079 break;
3080 sprintf(&buf[index], "%08ld ", bucket_value);
3081 index = strlen(buf);
3082 }
3083 }
3084 sprintf(&buf[index], "\n");
3085 return strlen(buf);
3086}
3087
3088
3089
3090
3091static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3092 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3103#define MAX_STAT_DATA_SIZE_PER_TARGET \
3104 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120static ssize_t
3121sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3122 struct bin_attribute *bin_attr,
3123 char *buf, loff_t off, size_t count)
3124{
3125 struct device *dev = container_of(kobj, struct device,
3126 kobj);
3127 struct Scsi_Host *shost = class_to_shost(dev);
3128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3129 struct lpfc_hba *phba = vport->phba;
3130 int i = 0, index = 0;
3131 unsigned long nport_index;
3132 struct lpfc_nodelist *ndlp = NULL;
3133 nport_index = (unsigned long)off /
3134 MAX_STAT_DATA_SIZE_PER_TARGET;
3135
3136 if (!vport->stat_data_enabled || vport->stat_data_blocked
3137 || (phba->bucket_type == LPFC_NO_BUCKET))
3138 return 0;
3139
3140 spin_lock_irq(shost->host_lock);
3141 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3142 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3143 continue;
3144
3145 if (nport_index > 0) {
3146 nport_index--;
3147 continue;
3148 }
3149
3150 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3151 > count)
3152 break;
3153
3154 if (!ndlp->lat_data)
3155 continue;
3156
3157
3158 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3159 ndlp->nlp_portname.u.wwn[0],
3160 ndlp->nlp_portname.u.wwn[1],
3161 ndlp->nlp_portname.u.wwn[2],
3162 ndlp->nlp_portname.u.wwn[3],
3163 ndlp->nlp_portname.u.wwn[4],
3164 ndlp->nlp_portname.u.wwn[5],
3165 ndlp->nlp_portname.u.wwn[6],
3166 ndlp->nlp_portname.u.wwn[7]);
3167
3168 index = strlen(buf);
3169
3170 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3171 sprintf(&buf[index], "%010u,",
3172 ndlp->lat_data[i].cmd_count);
3173 index = strlen(buf);
3174 }
3175 sprintf(&buf[index], "\n");
3176 index = strlen(buf);
3177 }
3178 spin_unlock_irq(shost->host_lock);
3179 return index;
3180}
3181
3182static struct bin_attribute sysfs_drvr_stat_data_attr = {
3183 .attr = {
3184 .name = "lpfc_drvr_stat_data",
3185 .mode = S_IRUSR,
3186 },
3187 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3188 .read = sysfs_drvr_stat_data_read,
3189 .write = NULL,
3190};
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214static ssize_t
3215lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3216 const char *buf, size_t count)
3217{
3218 struct Scsi_Host *shost = class_to_shost(dev);
3219 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3220 struct lpfc_hba *phba = vport->phba;
3221 int val = LPFC_USER_LINK_SPEED_AUTO;
3222 int nolip = 0;
3223 const char *val_buf = buf;
3224 int err;
3225 uint32_t prev_val;
3226
3227 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3228 nolip = 1;
3229 val_buf = &buf[strlen("nolip ")];
3230 }
3231
3232 if (!isdigit(val_buf[0]))
3233 return -EINVAL;
3234 if (sscanf(val_buf, "%i", &val) != 1)
3235 return -EINVAL;
3236
3237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3238 "3055 lpfc_link_speed changed from %d to %d %s\n",
3239 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3240
3241 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3242 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3243 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3244 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3245 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
3246 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
3247 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3248 "2879 lpfc_link_speed attribute cannot be set "
3249 "to %d. Speed is not supported by this port.\n",
3250 val);
3251 return -EINVAL;
3252 }
3253 if (val == LPFC_USER_LINK_SPEED_16G &&
3254 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3256 "3112 lpfc_link_speed attribute cannot be set "
3257 "to %d. Speed is not supported in loop mode.\n",
3258 val);
3259 return -EINVAL;
3260 }
3261 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3262 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3263 prev_val = phba->cfg_link_speed;
3264 phba->cfg_link_speed = val;
3265 if (nolip)
3266 return strlen(buf);
3267
3268 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3269 if (err) {
3270 phba->cfg_link_speed = prev_val;
3271 return -EINVAL;
3272 } else
3273 return strlen(buf);
3274 }
3275 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3276 "0469 lpfc_link_speed attribute cannot be set to %d, "
3277 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
3278 return -EINVAL;
3279}
3280
3281static int lpfc_link_speed = 0;
3282module_param(lpfc_link_speed, int, S_IRUGO);
3283MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3284lpfc_param_show(link_speed)
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302static int
3303lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3304{
3305 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3306 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3307 "3111 lpfc_link_speed of %d cannot "
3308 "support loop mode, setting topology to default.\n",
3309 val);
3310 phba->cfg_topology = 0;
3311 }
3312 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3313 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
3314 phba->cfg_link_speed = val;
3315 return 0;
3316 }
3317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3318 "0405 lpfc_link_speed attribute cannot "
3319 "be set to %d, allowed values are "
3320 "["LPFC_LINK_SPEED_STRING"]\n", val);
3321 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
3322 return -EINVAL;
3323}
3324
3325static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
3326 lpfc_link_speed_show, lpfc_link_speed_store);
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362static ssize_t
3363lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3364 const char *buf, size_t count)
3365{
3366 struct Scsi_Host *shost = class_to_shost(dev);
3367 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3368 struct lpfc_hba *phba = vport->phba;
3369 int val = 0, rc = -EINVAL;
3370
3371 if (!isdigit(buf[0]))
3372 return -EINVAL;
3373 if (sscanf(buf, "%i", &val) != 1)
3374 return -EINVAL;
3375
3376 switch (val) {
3377 case 0:
3378 if (phba->hba_flag & HBA_AER_ENABLED) {
3379 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3380 if (!rc) {
3381 spin_lock_irq(&phba->hbalock);
3382 phba->hba_flag &= ~HBA_AER_ENABLED;
3383 spin_unlock_irq(&phba->hbalock);
3384 phba->cfg_aer_support = 0;
3385 rc = strlen(buf);
3386 } else
3387 rc = -EPERM;
3388 } else {
3389 phba->cfg_aer_support = 0;
3390 rc = strlen(buf);
3391 }
3392 break;
3393 case 1:
3394 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3395 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3396 if (!rc) {
3397 spin_lock_irq(&phba->hbalock);
3398 phba->hba_flag |= HBA_AER_ENABLED;
3399 spin_unlock_irq(&phba->hbalock);
3400 phba->cfg_aer_support = 1;
3401 rc = strlen(buf);
3402 } else
3403 rc = -EPERM;
3404 } else {
3405 phba->cfg_aer_support = 1;
3406 rc = strlen(buf);
3407 }
3408 break;
3409 default:
3410 rc = -EINVAL;
3411 break;
3412 }
3413 return rc;
3414}
3415
3416static int lpfc_aer_support = 1;
3417module_param(lpfc_aer_support, int, S_IRUGO);
3418MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3419lpfc_param_show(aer_support)
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440static int
3441lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3442{
3443 if (val == 0 || val == 1) {
3444 phba->cfg_aer_support = val;
3445 return 0;
3446 }
3447 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3448 "2712 lpfc_aer_support attribute value %d out "
3449 "of range, allowed values are 0|1, setting it "
3450 "to default value of 1\n", val);
3451
3452 phba->cfg_aer_support = 1;
3453 return -EINVAL;
3454}
3455
3456static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3457 lpfc_aer_support_show, lpfc_aer_support_store);
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478static ssize_t
3479lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3480 const char *buf, size_t count)
3481{
3482 struct Scsi_Host *shost = class_to_shost(dev);
3483 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3484 struct lpfc_hba *phba = vport->phba;
3485 int val, rc = -1;
3486
3487 if (!isdigit(buf[0]))
3488 return -EINVAL;
3489 if (sscanf(buf, "%i", &val) != 1)
3490 return -EINVAL;
3491 if (val != 1)
3492 return -EINVAL;
3493
3494 if (phba->hba_flag & HBA_AER_ENABLED)
3495 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3496
3497 if (rc == 0)
3498 return strlen(buf);
3499 else
3500 return -EPERM;
3501}
3502
3503static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3504 lpfc_aer_cleanup_state);
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545static ssize_t
3546lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
3547 const char *buf, size_t count)
3548{
3549 struct Scsi_Host *shost = class_to_shost(dev);
3550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3551 struct lpfc_hba *phba = vport->phba;
3552 struct pci_dev *pdev = phba->pcidev;
3553 int val = 0, rc = -EINVAL;
3554
3555
3556 if (!isdigit(buf[0]))
3557 return -EINVAL;
3558 if (sscanf(buf, "%i", &val) != 1)
3559 return -EINVAL;
3560 if (val < 0)
3561 return -EINVAL;
3562
3563
3564 if (val == 0) {
3565 if (phba->cfg_sriov_nr_virtfn > 0) {
3566 pci_disable_sriov(pdev);
3567 phba->cfg_sriov_nr_virtfn = 0;
3568 }
3569 return strlen(buf);
3570 }
3571
3572
3573 if (phba->cfg_sriov_nr_virtfn > 0) {
3574 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3575 "3018 There are %d virtual functions "
3576 "enabled on physical function.\n",
3577 phba->cfg_sriov_nr_virtfn);
3578 return -EEXIST;
3579 }
3580
3581 if (val <= LPFC_MAX_VFN_PER_PFN)
3582 phba->cfg_sriov_nr_virtfn = val;
3583 else {
3584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3585 "3019 Enabling %d virtual functions is not "
3586 "allowed.\n", val);
3587 return -EINVAL;
3588 }
3589
3590 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
3591 if (rc) {
3592 phba->cfg_sriov_nr_virtfn = 0;
3593 rc = -EPERM;
3594 } else
3595 rc = strlen(buf);
3596
3597 return rc;
3598}
3599
3600static int lpfc_sriov_nr_virtfn = LPFC_DEF_VFN_PER_PFN;
3601module_param(lpfc_sriov_nr_virtfn, int, S_IRUGO|S_IWUSR);
3602MODULE_PARM_DESC(lpfc_sriov_nr_virtfn, "Enable PCIe device SR-IOV virtual fn");
3603lpfc_param_show(sriov_nr_virtfn)
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620static int
3621lpfc_sriov_nr_virtfn_init(struct lpfc_hba *phba, int val)
3622{
3623 if (val >= 0 && val <= LPFC_MAX_VFN_PER_PFN) {
3624 phba->cfg_sriov_nr_virtfn = val;
3625 return 0;
3626 }
3627
3628 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3629 "3017 Enabling %d virtual functions is not "
3630 "allowed.\n", val);
3631 return -EINVAL;
3632}
3633static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
3634 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651static ssize_t
3652lpfc_request_firmware_upgrade_store(struct device *dev,
3653 struct device_attribute *attr,
3654 const char *buf, size_t count)
3655{
3656 struct Scsi_Host *shost = class_to_shost(dev);
3657 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3658 struct lpfc_hba *phba = vport->phba;
3659 int val = 0, rc = -EINVAL;
3660
3661
3662 if (!isdigit(buf[0]))
3663 return -EINVAL;
3664 if (sscanf(buf, "%i", &val) != 1)
3665 return -EINVAL;
3666 if (val != 1)
3667 return -EINVAL;
3668
3669 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
3670 if (rc)
3671 rc = -EPERM;
3672 else
3673 rc = strlen(buf);
3674 return rc;
3675}
3676
3677static int lpfc_req_fw_upgrade;
3678module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
3679MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
3680lpfc_param_show(request_firmware_upgrade)
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694static int
3695lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
3696{
3697 if (val >= 0 && val <= 1) {
3698 phba->cfg_request_firmware_upgrade = val;
3699 return 0;
3700 }
3701 return -EINVAL;
3702}
3703static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
3704 lpfc_request_firmware_upgrade_show,
3705 lpfc_request_firmware_upgrade_store);
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724static ssize_t
3725lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
3726 const char *buf, size_t count)
3727{
3728 struct Scsi_Host *shost = class_to_shost(dev);
3729 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3730 struct lpfc_hba *phba = vport->phba;
3731 int val = 0, i;
3732
3733
3734 if (phba->sli_rev != LPFC_SLI_REV4)
3735 return -EINVAL;
3736
3737
3738 if (!isdigit(buf[0]))
3739 return -EINVAL;
3740 if (sscanf(buf, "%i", &val) != 1)
3741 return -EINVAL;
3742
3743
3744
3745
3746
3747 if (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)
3748 return -EINVAL;
3749
3750 phba->cfg_fcp_imax = (uint32_t)val;
3751 for (i = 0; i < phba->cfg_fcp_io_channel; i += LPFC_MAX_EQ_DELAY)
3752 lpfc_modify_fcp_eq_delay(phba, i);
3753
3754 return strlen(buf);
3755}
3756
3757
3758
3759
3760
3761
3762
3763static int lpfc_fcp_imax = LPFC_DEF_IMAX;
3764module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
3765MODULE_PARM_DESC(lpfc_fcp_imax,
3766 "Set the maximum number of FCP interrupts per second per HBA");
3767lpfc_param_show(fcp_imax)
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782static int
3783lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
3784{
3785 if (phba->sli_rev != LPFC_SLI_REV4) {
3786 phba->cfg_fcp_imax = 0;
3787 return 0;
3788 }
3789
3790 if (val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) {
3791 phba->cfg_fcp_imax = val;
3792 return 0;
3793 }
3794
3795 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3796 "3016 fcp_imax: %d out of range, using default\n", val);
3797 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
3798
3799 return 0;
3800}
3801
3802static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
3803 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813static ssize_t
3814lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
3815 char *buf)
3816{
3817 struct Scsi_Host *shost = class_to_shost(dev);
3818 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3819 struct lpfc_hba *phba = vport->phba;
3820 struct lpfc_vector_map_info *cpup;
3821 int idx, len = 0;
3822
3823 if ((phba->sli_rev != LPFC_SLI_REV4) ||
3824 (phba->intr_type != MSIX))
3825 return len;
3826
3827 switch (phba->cfg_fcp_cpu_map) {
3828 case 0:
3829 len += snprintf(buf + len, PAGE_SIZE-len,
3830 "fcp_cpu_map: No mapping (%d)\n",
3831 phba->cfg_fcp_cpu_map);
3832 return len;
3833 case 1:
3834 len += snprintf(buf + len, PAGE_SIZE-len,
3835 "fcp_cpu_map: HBA centric mapping (%d): "
3836 "%d online CPUs\n",
3837 phba->cfg_fcp_cpu_map,
3838 phba->sli4_hba.num_online_cpu);
3839 break;
3840 case 2:
3841 len += snprintf(buf + len, PAGE_SIZE-len,
3842 "fcp_cpu_map: Driver centric mapping (%d): "
3843 "%d online CPUs\n",
3844 phba->cfg_fcp_cpu_map,
3845 phba->sli4_hba.num_online_cpu);
3846 break;
3847 }
3848
3849 cpup = phba->sli4_hba.cpu_map;
3850 for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) {
3851 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
3852 len += snprintf(buf + len, PAGE_SIZE-len,
3853 "CPU %02d io_chan %02d "
3854 "physid %d coreid %d\n",
3855 idx, cpup->channel_id, cpup->phys_id,
3856 cpup->core_id);
3857 else
3858 len += snprintf(buf + len, PAGE_SIZE-len,
3859 "CPU %02d io_chan %02d "
3860 "physid %d coreid %d IRQ %d\n",
3861 idx, cpup->channel_id, cpup->phys_id,
3862 cpup->core_id, cpup->irq);
3863
3864 cpup++;
3865 }
3866 return len;
3867}
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879static ssize_t
3880lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
3881 const char *buf, size_t count)
3882{
3883 int status = -EINVAL;
3884 return status;
3885}
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3899module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
3900MODULE_PARM_DESC(lpfc_fcp_cpu_map,
3901 "Defines how to map CPUs to IRQ vectors per HBA");
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916static int
3917lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
3918{
3919 if (phba->sli_rev != LPFC_SLI_REV4) {
3920 phba->cfg_fcp_cpu_map = 0;
3921 return 0;
3922 }
3923
3924 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
3925 phba->cfg_fcp_cpu_map = val;
3926 return 0;
3927 }
3928
3929 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3930 "3326 fcp_cpu_map: %d out of range, using default\n",
3931 val);
3932 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
3933
3934 return 0;
3935}
3936
3937static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
3938 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
3939
3940
3941
3942
3943
3944LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3945 "Select Fibre Channel class of service for FCP sequences");
3946
3947
3948
3949
3950
3951LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3952 "Use ADISC on rediscovery to authenticate FCP devices");
3953
3954
3955
3956
3957
3958
3959LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
3960 "First burst size for Targets that support first burst");
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970static int lpfc_max_scsicmpl_time;
3971module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3972MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3973 "Use command completion time to control queue depth");
3974lpfc_vport_param_show(max_scsicmpl_time);
3975lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3976static int
3977lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3978{
3979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3980 struct lpfc_nodelist *ndlp, *next_ndlp;
3981
3982 if (val == vport->cfg_max_scsicmpl_time)
3983 return 0;
3984 if ((val < 0) || (val > 60000))
3985 return -EINVAL;
3986 vport->cfg_max_scsicmpl_time = val;
3987
3988 spin_lock_irq(shost->host_lock);
3989 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3990 if (!NLP_CHK_NODE_ACT(ndlp))
3991 continue;
3992 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3993 continue;
3994 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3995 }
3996 spin_unlock_irq(shost->host_lock);
3997 return 0;
3998}
3999lpfc_vport_param_store(max_scsicmpl_time);
4000static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4001 lpfc_max_scsicmpl_time_show,
4002 lpfc_max_scsicmpl_time_store);
4003
4004
4005
4006
4007
4008LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020LPFC_ATTR_RW(fcp_io_sched, 0, 0, 1, "Determine scheduling algorithm for "
4021 "issuing commands [0] - Round Robin, [1] - Current CPU");
4022
4023
4024
4025
4026
4027
4028
4029LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4030 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4041 "interrupt response is generated");
4042
4043LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4044 "interrupt response is generated");
4045
4046
4047
4048
4049
4050
4051LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4052 "SLI rings to spread IOCB entries across");
4053
4054
4055
4056
4057
4058
4059LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4060 255, "Identifies RCTL for additional ring configuration");
4061
4062
4063
4064
4065
4066
4067LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4068 255, "Identifies TYPE for additional ring configuration");
4069
4070
4071
4072
4073
4074
4075
4076
4077LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
4078
4079
4080
4081
4082
4083LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4084 "during discovery");
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4109
4110
4111
4112
4113
4114LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4115 "Milliseconds driver will wait between polling FCP ring");
4116
4117
4118
4119
4120
4121LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4122 "Maximum time to wait for task management commands to complete");
4123
4124
4125
4126
4127
4128
4129
4130
4131LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4132 "MSI-X (2), if possible");
4133
4134
4135
4136
4137
4138
4139LPFC_ATTR_R(fcp_io_channel, LPFC_FCP_IO_CHAN_DEF, LPFC_FCP_IO_CHAN_MIN,
4140 LPFC_FCP_IO_CHAN_MAX,
4141 "Set the number of FCP I/O channels");
4142
4143
4144
4145
4146
4147
4148
4149LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
4150
4151
4152
4153
4154
4155
4156
4157LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
4158
4159
4160
4161
4162
4163
4164
4165LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION |
4193 SHOST_DIX_TYPE0_PROTECTION |
4194 SHOST_DIX_TYPE1_PROTECTION;
4195
4196module_param(lpfc_prot_mask, uint, S_IRUGO);
4197MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
4208module_param(lpfc_prot_guard, byte, S_IRUGO);
4209MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225int lpfc_delay_discovery;
4226module_param(lpfc_delay_discovery, int, S_IRUGO);
4227MODULE_PARM_DESC(lpfc_delay_discovery,
4228 "Delay NPort discovery when Clean Address bit is cleared. "
4229 "Allowed values: 0,1.");
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4241 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4242
4243
4244
4245
4246
4247LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT,
4248 LPFC_DEFAULT_SG_SEG_CNT, LPFC_MAX_SG_SEG_CNT,
4249 "Max Protection Scatter Gather Segment Count");
4250
4251struct device_attribute *lpfc_hba_attrs[] = {
4252 &dev_attr_bg_info,
4253 &dev_attr_bg_guard_err,
4254 &dev_attr_bg_apptag_err,
4255 &dev_attr_bg_reftag_err,
4256 &dev_attr_info,
4257 &dev_attr_serialnum,
4258 &dev_attr_modeldesc,
4259 &dev_attr_modelname,
4260 &dev_attr_programtype,
4261 &dev_attr_portnum,
4262 &dev_attr_fwrev,
4263 &dev_attr_hdw,
4264 &dev_attr_option_rom_version,
4265 &dev_attr_link_state,
4266 &dev_attr_num_discovered_ports,
4267 &dev_attr_menlo_mgmt_mode,
4268 &dev_attr_lpfc_drvr_version,
4269 &dev_attr_lpfc_enable_fip,
4270 &dev_attr_lpfc_temp_sensor,
4271 &dev_attr_lpfc_log_verbose,
4272 &dev_attr_lpfc_lun_queue_depth,
4273 &dev_attr_lpfc_tgt_queue_depth,
4274 &dev_attr_lpfc_hba_queue_depth,
4275 &dev_attr_lpfc_peer_port_login,
4276 &dev_attr_lpfc_nodev_tmo,
4277 &dev_attr_lpfc_devloss_tmo,
4278 &dev_attr_lpfc_fcp_class,
4279 &dev_attr_lpfc_use_adisc,
4280 &dev_attr_lpfc_first_burst_size,
4281 &dev_attr_lpfc_ack0,
4282 &dev_attr_lpfc_topology,
4283 &dev_attr_lpfc_scan_down,
4284 &dev_attr_lpfc_link_speed,
4285 &dev_attr_lpfc_fcp_io_sched,
4286 &dev_attr_lpfc_fcp2_no_tgt_reset,
4287 &dev_attr_lpfc_cr_delay,
4288 &dev_attr_lpfc_cr_count,
4289 &dev_attr_lpfc_multi_ring_support,
4290 &dev_attr_lpfc_multi_ring_rctl,
4291 &dev_attr_lpfc_multi_ring_type,
4292 &dev_attr_lpfc_fdmi_on,
4293 &dev_attr_lpfc_max_luns,
4294 &dev_attr_lpfc_enable_npiv,
4295 &dev_attr_lpfc_fcf_failover_policy,
4296 &dev_attr_lpfc_enable_rrq,
4297 &dev_attr_nport_evt_cnt,
4298 &dev_attr_board_mode,
4299 &dev_attr_max_vpi,
4300 &dev_attr_used_vpi,
4301 &dev_attr_max_rpi,
4302 &dev_attr_used_rpi,
4303 &dev_attr_max_xri,
4304 &dev_attr_used_xri,
4305 &dev_attr_npiv_info,
4306 &dev_attr_issue_reset,
4307 &dev_attr_lpfc_poll,
4308 &dev_attr_lpfc_poll_tmo,
4309 &dev_attr_lpfc_task_mgmt_tmo,
4310 &dev_attr_lpfc_use_msi,
4311 &dev_attr_lpfc_fcp_imax,
4312 &dev_attr_lpfc_fcp_cpu_map,
4313 &dev_attr_lpfc_fcp_io_channel,
4314 &dev_attr_lpfc_enable_bg,
4315 &dev_attr_lpfc_soft_wwnn,
4316 &dev_attr_lpfc_soft_wwpn,
4317 &dev_attr_lpfc_soft_wwn_enable,
4318 &dev_attr_lpfc_enable_hba_reset,
4319 &dev_attr_lpfc_enable_hba_heartbeat,
4320 &dev_attr_lpfc_sg_seg_cnt,
4321 &dev_attr_lpfc_max_scsicmpl_time,
4322 &dev_attr_lpfc_stat_data_ctrl,
4323 &dev_attr_lpfc_prot_sg_seg_cnt,
4324 &dev_attr_lpfc_aer_support,
4325 &dev_attr_lpfc_aer_state_cleanup,
4326 &dev_attr_lpfc_sriov_nr_virtfn,
4327 &dev_attr_lpfc_req_fw_upgrade,
4328 &dev_attr_lpfc_suppress_link_up,
4329 &dev_attr_lpfc_iocb_cnt,
4330 &dev_attr_iocb_hw,
4331 &dev_attr_txq_hw,
4332 &dev_attr_txcmplq_hw,
4333 &dev_attr_lpfc_fips_level,
4334 &dev_attr_lpfc_fips_rev,
4335 &dev_attr_lpfc_dss,
4336 &dev_attr_lpfc_sriov_hw_max_virtfn,
4337 &dev_attr_protocol,
4338 NULL,
4339};
4340
4341struct device_attribute *lpfc_vport_attrs[] = {
4342 &dev_attr_info,
4343 &dev_attr_link_state,
4344 &dev_attr_num_discovered_ports,
4345 &dev_attr_lpfc_drvr_version,
4346 &dev_attr_lpfc_log_verbose,
4347 &dev_attr_lpfc_lun_queue_depth,
4348 &dev_attr_lpfc_tgt_queue_depth,
4349 &dev_attr_lpfc_nodev_tmo,
4350 &dev_attr_lpfc_devloss_tmo,
4351 &dev_attr_lpfc_hba_queue_depth,
4352 &dev_attr_lpfc_peer_port_login,
4353 &dev_attr_lpfc_restrict_login,
4354 &dev_attr_lpfc_fcp_class,
4355 &dev_attr_lpfc_use_adisc,
4356 &dev_attr_lpfc_first_burst_size,
4357 &dev_attr_lpfc_fdmi_on,
4358 &dev_attr_lpfc_max_luns,
4359 &dev_attr_nport_evt_cnt,
4360 &dev_attr_npiv_info,
4361 &dev_attr_lpfc_enable_da_id,
4362 &dev_attr_lpfc_max_scsicmpl_time,
4363 &dev_attr_lpfc_stat_data_ctrl,
4364 &dev_attr_lpfc_static_vport,
4365 &dev_attr_lpfc_fips_level,
4366 &dev_attr_lpfc_fips_rev,
4367 NULL,
4368};
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389static ssize_t
4390sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
4391 struct bin_attribute *bin_attr,
4392 char *buf, loff_t off, size_t count)
4393{
4394 size_t buf_off;
4395 struct device *dev = container_of(kobj, struct device, kobj);
4396 struct Scsi_Host *shost = class_to_shost(dev);
4397 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4398 struct lpfc_hba *phba = vport->phba;
4399
4400 if (phba->sli_rev >= LPFC_SLI_REV4)
4401 return -EPERM;
4402
4403 if ((off + count) > FF_REG_AREA_SIZE)
4404 return -ERANGE;
4405
4406 if (count <= LPFC_REG_WRITE_KEY_SIZE)
4407 return 0;
4408
4409 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4410 return -EINVAL;
4411
4412
4413 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
4414 return -EINVAL;
4415
4416 if (!(vport->fc_flag & FC_OFFLINE_MODE))
4417 return -EPERM;
4418
4419 spin_lock_irq(&phba->hbalock);
4420 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
4421 buf_off += sizeof(uint32_t))
4422 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
4423 phba->ctrl_regs_memmap_p + off + buf_off);
4424
4425 spin_unlock_irq(&phba->hbalock);
4426
4427 return count;
4428}
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448static ssize_t
4449sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
4450 struct bin_attribute *bin_attr,
4451 char *buf, loff_t off, size_t count)
4452{
4453 size_t buf_off;
4454 uint32_t * tmp_ptr;
4455 struct device *dev = container_of(kobj, struct device, kobj);
4456 struct Scsi_Host *shost = class_to_shost(dev);
4457 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4458 struct lpfc_hba *phba = vport->phba;
4459
4460 if (phba->sli_rev >= LPFC_SLI_REV4)
4461 return -EPERM;
4462
4463 if (off > FF_REG_AREA_SIZE)
4464 return -ERANGE;
4465
4466 if ((off + count) > FF_REG_AREA_SIZE)
4467 count = FF_REG_AREA_SIZE - off;
4468
4469 if (count == 0) return 0;
4470
4471 if (off % 4 || count % 4 || (unsigned long)buf % 4)
4472 return -EINVAL;
4473
4474 spin_lock_irq(&phba->hbalock);
4475
4476 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
4477 tmp_ptr = (uint32_t *)(buf + buf_off);
4478 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
4479 }
4480
4481 spin_unlock_irq(&phba->hbalock);
4482
4483 return count;
4484}
4485
4486static struct bin_attribute sysfs_ctlreg_attr = {
4487 .attr = {
4488 .name = "ctlreg",
4489 .mode = S_IRUSR | S_IWUSR,
4490 },
4491 .size = 256,
4492 .read = sysfs_ctlreg_read,
4493 .write = sysfs_ctlreg_write,
4494};
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512static ssize_t
4513sysfs_mbox_write(struct file *filp, struct kobject *kobj,
4514 struct bin_attribute *bin_attr,
4515 char *buf, loff_t off, size_t count)
4516{
4517 return -EPERM;
4518}
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536static ssize_t
4537sysfs_mbox_read(struct file *filp, struct kobject *kobj,
4538 struct bin_attribute *bin_attr,
4539 char *buf, loff_t off, size_t count)
4540{
4541 return -EPERM;
4542}
4543
4544static struct bin_attribute sysfs_mbox_attr = {
4545 .attr = {
4546 .name = "mbox",
4547 .mode = S_IRUSR | S_IWUSR,
4548 },
4549 .size = MAILBOX_SYSFS_MAX,
4550 .read = sysfs_mbox_read,
4551 .write = sysfs_mbox_write,
4552};
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562int
4563lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
4564{
4565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4566 int error;
4567
4568 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4569 &sysfs_drvr_stat_data_attr);
4570
4571
4572 if (error || vport->port_type == LPFC_NPIV_PORT)
4573 goto out;
4574
4575 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4576 &sysfs_ctlreg_attr);
4577 if (error)
4578 goto out_remove_stat_attr;
4579
4580 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
4581 &sysfs_mbox_attr);
4582 if (error)
4583 goto out_remove_ctlreg_attr;
4584
4585 return 0;
4586out_remove_ctlreg_attr:
4587 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4588out_remove_stat_attr:
4589 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4590 &sysfs_drvr_stat_data_attr);
4591out:
4592 return error;
4593}
4594
4595
4596
4597
4598
4599void
4600lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4601{
4602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4603 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4604 &sysfs_drvr_stat_data_attr);
4605
4606 if (vport->port_type == LPFC_NPIV_PORT)
4607 return;
4608 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4609 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4610}
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621static void
4622lpfc_get_host_port_id(struct Scsi_Host *shost)
4623{
4624 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4625
4626
4627 fc_host_port_id(shost) = vport->fc_myDID;
4628}
4629
4630
4631
4632
4633
4634static void
4635lpfc_get_host_port_type(struct Scsi_Host *shost)
4636{
4637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4638 struct lpfc_hba *phba = vport->phba;
4639
4640 spin_lock_irq(shost->host_lock);
4641
4642 if (vport->port_type == LPFC_NPIV_PORT) {
4643 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4644 } else if (lpfc_is_link_up(phba)) {
4645 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4646 if (vport->fc_flag & FC_PUBLIC_LOOP)
4647 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4648 else
4649 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4650 } else {
4651 if (vport->fc_flag & FC_FABRIC)
4652 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4653 else
4654 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4655 }
4656 } else
4657 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4658
4659 spin_unlock_irq(shost->host_lock);
4660}
4661
4662
4663
4664
4665
4666static void
4667lpfc_get_host_port_state(struct Scsi_Host *shost)
4668{
4669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4670 struct lpfc_hba *phba = vport->phba;
4671
4672 spin_lock_irq(shost->host_lock);
4673
4674 if (vport->fc_flag & FC_OFFLINE_MODE)
4675 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4676 else {
4677 switch (phba->link_state) {
4678 case LPFC_LINK_UNKNOWN:
4679 case LPFC_LINK_DOWN:
4680 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4681 break;
4682 case LPFC_LINK_UP:
4683 case LPFC_CLEAR_LA:
4684 case LPFC_HBA_READY:
4685
4686 if (vport->port_state < LPFC_VPORT_READY)
4687 fc_host_port_state(shost) =
4688 FC_PORTSTATE_BYPASSED;
4689 else
4690 fc_host_port_state(shost) =
4691 FC_PORTSTATE_ONLINE;
4692 break;
4693 case LPFC_HBA_ERROR:
4694 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4695 break;
4696 default:
4697 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4698 break;
4699 }
4700 }
4701
4702 spin_unlock_irq(shost->host_lock);
4703}
4704
4705
4706
4707
4708
4709static void
4710lpfc_get_host_speed(struct Scsi_Host *shost)
4711{
4712 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4713 struct lpfc_hba *phba = vport->phba;
4714
4715 spin_lock_irq(shost->host_lock);
4716
4717 if (lpfc_is_link_up(phba)) {
4718 switch(phba->fc_linkspeed) {
4719 case LPFC_LINK_SPEED_1GHZ:
4720 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4721 break;
4722 case LPFC_LINK_SPEED_2GHZ:
4723 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4724 break;
4725 case LPFC_LINK_SPEED_4GHZ:
4726 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4727 break;
4728 case LPFC_LINK_SPEED_8GHZ:
4729 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4730 break;
4731 case LPFC_LINK_SPEED_10GHZ:
4732 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4733 break;
4734 case LPFC_LINK_SPEED_16GHZ:
4735 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4736 break;
4737 default:
4738 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4739 break;
4740 }
4741 } else
4742 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4743
4744 spin_unlock_irq(shost->host_lock);
4745}
4746
4747
4748
4749
4750
4751static void
4752lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4753{
4754 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4755 struct lpfc_hba *phba = vport->phba;
4756 u64 node_name;
4757
4758 spin_lock_irq(shost->host_lock);
4759
4760 if ((vport->port_state > LPFC_FLOGI) &&
4761 ((vport->fc_flag & FC_FABRIC) ||
4762 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4763 (vport->fc_flag & FC_PUBLIC_LOOP))))
4764 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4765 else
4766
4767 node_name = 0;
4768
4769 spin_unlock_irq(shost->host_lock);
4770
4771 fc_host_fabric_name(shost) = node_name;
4772}
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786static struct fc_host_statistics *
4787lpfc_get_stats(struct Scsi_Host *shost)
4788{
4789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4790 struct lpfc_hba *phba = vport->phba;
4791 struct lpfc_sli *psli = &phba->sli;
4792 struct fc_host_statistics *hs = &phba->link_stats;
4793 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4794 LPFC_MBOXQ_t *pmboxq;
4795 MAILBOX_t *pmb;
4796 unsigned long seconds;
4797 int rc = 0;
4798
4799
4800
4801
4802
4803 if (phba->link_state < LPFC_LINK_DOWN ||
4804 !phba->mbox_mem_pool ||
4805 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4806 return NULL;
4807
4808 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4809 return NULL;
4810
4811 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4812 if (!pmboxq)
4813 return NULL;
4814 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4815
4816 pmb = &pmboxq->u.mb;
4817 pmb->mbxCommand = MBX_READ_STATUS;
4818 pmb->mbxOwner = OWN_HOST;
4819 pmboxq->context1 = NULL;
4820 pmboxq->vport = vport;
4821
4822 if (vport->fc_flag & FC_OFFLINE_MODE)
4823 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4824 else
4825 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4826
4827 if (rc != MBX_SUCCESS) {
4828 if (rc != MBX_TIMEOUT)
4829 mempool_free(pmboxq, phba->mbox_mem_pool);
4830 return NULL;
4831 }
4832
4833 memset(hs, 0, sizeof (struct fc_host_statistics));
4834
4835 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4836
4837
4838
4839
4840 hs->tx_words = (uint64_t)
4841 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
4842 * (uint64_t)256);
4843 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4844 hs->rx_words = (uint64_t)
4845 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
4846 * (uint64_t)256);
4847
4848 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4849 pmb->mbxCommand = MBX_READ_LNK_STAT;
4850 pmb->mbxOwner = OWN_HOST;
4851 pmboxq->context1 = NULL;
4852 pmboxq->vport = vport;
4853
4854 if (vport->fc_flag & FC_OFFLINE_MODE)
4855 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4856 else
4857 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4858
4859 if (rc != MBX_SUCCESS) {
4860 if (rc != MBX_TIMEOUT)
4861 mempool_free(pmboxq, phba->mbox_mem_pool);
4862 return NULL;
4863 }
4864
4865 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4866 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4867 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4868 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4869 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4870 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4871 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4872
4873 hs->link_failure_count -= lso->link_failure_count;
4874 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4875 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4876 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4877 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4878 hs->invalid_crc_count -= lso->invalid_crc_count;
4879 hs->error_frames -= lso->error_frames;
4880
4881 if (phba->hba_flag & HBA_FCOE_MODE) {
4882 hs->lip_count = -1;
4883 hs->nos_count = (phba->link_events >> 1);
4884 hs->nos_count -= lso->link_events;
4885 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4886 hs->lip_count = (phba->fc_eventTag >> 1);
4887 hs->lip_count -= lso->link_events;
4888 hs->nos_count = -1;
4889 } else {
4890 hs->lip_count = -1;
4891 hs->nos_count = (phba->fc_eventTag >> 1);
4892 hs->nos_count -= lso->link_events;
4893 }
4894
4895 hs->dumped_frames = -1;
4896
4897 seconds = get_seconds();
4898 if (seconds < psli->stats_start)
4899 hs->seconds_since_last_reset = seconds +
4900 ((unsigned long)-1 - psli->stats_start);
4901 else
4902 hs->seconds_since_last_reset = seconds - psli->stats_start;
4903
4904 mempool_free(pmboxq, phba->mbox_mem_pool);
4905
4906 return hs;
4907}
4908
4909
4910
4911
4912
4913static void
4914lpfc_reset_stats(struct Scsi_Host *shost)
4915{
4916 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4917 struct lpfc_hba *phba = vport->phba;
4918 struct lpfc_sli *psli = &phba->sli;
4919 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4920 LPFC_MBOXQ_t *pmboxq;
4921 MAILBOX_t *pmb;
4922 int rc = 0;
4923
4924 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4925 return;
4926
4927 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4928 if (!pmboxq)
4929 return;
4930 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4931
4932 pmb = &pmboxq->u.mb;
4933 pmb->mbxCommand = MBX_READ_STATUS;
4934 pmb->mbxOwner = OWN_HOST;
4935 pmb->un.varWords[0] = 0x1;
4936 pmboxq->context1 = NULL;
4937 pmboxq->vport = vport;
4938
4939 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4940 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4941 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4942 else
4943 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4944
4945 if (rc != MBX_SUCCESS) {
4946 if (rc != MBX_TIMEOUT)
4947 mempool_free(pmboxq, phba->mbox_mem_pool);
4948 return;
4949 }
4950
4951 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4952 pmb->mbxCommand = MBX_READ_LNK_STAT;
4953 pmb->mbxOwner = OWN_HOST;
4954 pmboxq->context1 = NULL;
4955 pmboxq->vport = vport;
4956
4957 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4958 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4959 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4960 else
4961 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4962
4963 if (rc != MBX_SUCCESS) {
4964 if (rc != MBX_TIMEOUT)
4965 mempool_free( pmboxq, phba->mbox_mem_pool);
4966 return;
4967 }
4968
4969 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4970 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4971 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4972 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4973 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4974 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4975 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4976 if (phba->hba_flag & HBA_FCOE_MODE)
4977 lso->link_events = (phba->link_events >> 1);
4978 else
4979 lso->link_events = (phba->fc_eventTag >> 1);
4980
4981 psli->stats_start = get_seconds();
4982
4983 mempool_free(pmboxq, phba->mbox_mem_pool);
4984
4985 return;
4986}
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001static struct lpfc_nodelist *
5002lpfc_get_node_by_target(struct scsi_target *starget)
5003{
5004 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5006 struct lpfc_nodelist *ndlp;
5007
5008 spin_lock_irq(shost->host_lock);
5009
5010 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5011 if (NLP_CHK_NODE_ACT(ndlp) &&
5012 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5013 starget->id == ndlp->nlp_sid) {
5014 spin_unlock_irq(shost->host_lock);
5015 return ndlp;
5016 }
5017 }
5018 spin_unlock_irq(shost->host_lock);
5019 return NULL;
5020}
5021
5022
5023
5024
5025
5026static void
5027lpfc_get_starget_port_id(struct scsi_target *starget)
5028{
5029 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5030
5031 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5032}
5033
5034
5035
5036
5037
5038
5039
5040static void
5041lpfc_get_starget_node_name(struct scsi_target *starget)
5042{
5043 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5044
5045 fc_starget_node_name(starget) =
5046 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5047}
5048
5049
5050
5051
5052
5053
5054
5055static void
5056lpfc_get_starget_port_name(struct scsi_target *starget)
5057{
5058 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5059
5060 fc_starget_port_name(starget) =
5061 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5062}
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073static void
5074lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5075{
5076 if (timeout)
5077 rport->dev_loss_tmo = timeout;
5078 else
5079 rport->dev_loss_tmo = 1;
5080}
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094#define lpfc_rport_show_function(field, format_string, sz, cast) \
5095static ssize_t \
5096lpfc_show_rport_##field (struct device *dev, \
5097 struct device_attribute *attr, \
5098 char *buf) \
5099{ \
5100 struct fc_rport *rport = transport_class_to_rport(dev); \
5101 struct lpfc_rport_data *rdata = rport->hostdata; \
5102 return snprintf(buf, sz, format_string, \
5103 (rdata->target) ? cast rdata->target->field : 0); \
5104}
5105
5106#define lpfc_rport_rd_attr(field, format_string, sz) \
5107 lpfc_rport_show_function(field, format_string, sz, ) \
5108static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119static void
5120lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5121{
5122 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5123
5124 if (vport->port_state == LPFC_VPORT_READY)
5125 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5126}
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137static void
5138lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5139{
5140 phba->cfg_log_verbose = verbose;
5141}
5142
5143struct fc_function_template lpfc_transport_functions = {
5144
5145 .show_host_node_name = 1,
5146 .show_host_port_name = 1,
5147 .show_host_supported_classes = 1,
5148 .show_host_supported_fc4s = 1,
5149 .show_host_supported_speeds = 1,
5150 .show_host_maxframe_size = 1,
5151 .show_host_symbolic_name = 1,
5152
5153
5154 .get_host_port_id = lpfc_get_host_port_id,
5155 .show_host_port_id = 1,
5156
5157 .get_host_port_type = lpfc_get_host_port_type,
5158 .show_host_port_type = 1,
5159
5160 .get_host_port_state = lpfc_get_host_port_state,
5161 .show_host_port_state = 1,
5162
5163
5164 .show_host_active_fc4s = 1,
5165
5166 .get_host_speed = lpfc_get_host_speed,
5167 .show_host_speed = 1,
5168
5169 .get_host_fabric_name = lpfc_get_host_fabric_name,
5170 .show_host_fabric_name = 1,
5171
5172
5173
5174
5175
5176
5177 .get_fc_host_stats = lpfc_get_stats,
5178 .reset_fc_host_stats = lpfc_reset_stats,
5179
5180 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5181 .show_rport_maxframe_size = 1,
5182 .show_rport_supported_classes = 1,
5183
5184 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5185 .show_rport_dev_loss_tmo = 1,
5186
5187 .get_starget_port_id = lpfc_get_starget_port_id,
5188 .show_starget_port_id = 1,
5189
5190 .get_starget_node_name = lpfc_get_starget_node_name,
5191 .show_starget_node_name = 1,
5192
5193 .get_starget_port_name = lpfc_get_starget_port_name,
5194 .show_starget_port_name = 1,
5195
5196 .issue_fc_host_lip = lpfc_issue_lip,
5197 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5198 .terminate_rport_io = lpfc_terminate_rport_io,
5199
5200 .dd_fcvport_size = sizeof(struct lpfc_vport *),
5201
5202 .vport_disable = lpfc_vport_disable,
5203
5204 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5205
5206 .bsg_request = lpfc_bsg_request,
5207 .bsg_timeout = lpfc_bsg_timeout,
5208};
5209
5210struct fc_function_template lpfc_vport_transport_functions = {
5211
5212 .show_host_node_name = 1,
5213 .show_host_port_name = 1,
5214 .show_host_supported_classes = 1,
5215 .show_host_supported_fc4s = 1,
5216 .show_host_supported_speeds = 1,
5217 .show_host_maxframe_size = 1,
5218 .show_host_symbolic_name = 1,
5219
5220
5221 .get_host_port_id = lpfc_get_host_port_id,
5222 .show_host_port_id = 1,
5223
5224 .get_host_port_type = lpfc_get_host_port_type,
5225 .show_host_port_type = 1,
5226
5227 .get_host_port_state = lpfc_get_host_port_state,
5228 .show_host_port_state = 1,
5229
5230
5231 .show_host_active_fc4s = 1,
5232
5233 .get_host_speed = lpfc_get_host_speed,
5234 .show_host_speed = 1,
5235
5236 .get_host_fabric_name = lpfc_get_host_fabric_name,
5237 .show_host_fabric_name = 1,
5238
5239
5240
5241
5242
5243
5244 .get_fc_host_stats = lpfc_get_stats,
5245 .reset_fc_host_stats = lpfc_reset_stats,
5246
5247 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5248 .show_rport_maxframe_size = 1,
5249 .show_rport_supported_classes = 1,
5250
5251 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5252 .show_rport_dev_loss_tmo = 1,
5253
5254 .get_starget_port_id = lpfc_get_starget_port_id,
5255 .show_starget_port_id = 1,
5256
5257 .get_starget_node_name = lpfc_get_starget_node_name,
5258 .show_starget_node_name = 1,
5259
5260 .get_starget_port_name = lpfc_get_starget_port_name,
5261 .show_starget_port_name = 1,
5262
5263 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5264 .terminate_rport_io = lpfc_terminate_rport_io,
5265
5266 .vport_disable = lpfc_vport_disable,
5267
5268 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
5269};
5270
5271
5272
5273
5274
5275void
5276lpfc_get_cfgparam(struct lpfc_hba *phba)
5277{
5278 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
5279 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
5280 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5281 lpfc_cr_count_init(phba, lpfc_cr_count);
5282 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
5283 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5284 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
5285 lpfc_ack0_init(phba, lpfc_ack0);
5286 lpfc_topology_init(phba, lpfc_topology);
5287 lpfc_link_speed_init(phba, lpfc_link_speed);
5288 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
5289 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
5290 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
5291 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
5292 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
5293 lpfc_use_msi_init(phba, lpfc_use_msi);
5294 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
5295 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
5296 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
5297 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
5298 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
5299 lpfc_enable_bg_init(phba, lpfc_enable_bg);
5300 if (phba->sli_rev == LPFC_SLI_REV4)
5301 phba->cfg_poll = 0;
5302 else
5303 phba->cfg_poll = lpfc_poll;
5304 phba->cfg_soft_wwnn = 0L;
5305 phba->cfg_soft_wwpn = 0L;
5306 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
5307 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
5308 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
5309 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
5310 lpfc_aer_support_init(phba, lpfc_aer_support);
5311 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
5312 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
5313 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
5314 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
5315 phba->cfg_enable_dss = 1;
5316 return;
5317}
5318
5319
5320
5321
5322
5323void
5324lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
5325{
5326 lpfc_log_verbose_init(vport, lpfc_log_verbose);
5327 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
5328 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
5329 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
5330 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
5331 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
5332 lpfc_restrict_login_init(vport, lpfc_restrict_login);
5333 lpfc_fcp_class_init(vport, lpfc_fcp_class);
5334 lpfc_use_adisc_init(vport, lpfc_use_adisc);
5335 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
5336 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
5337 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
5338 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
5339 lpfc_max_luns_init(vport, lpfc_max_luns);
5340 lpfc_scan_down_init(vport, lpfc_scan_down);
5341 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
5342 return;
5343}
5344