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