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