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