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 "lpfc_hw4.h"
41#include "lpfc_hw.h"
42#include "lpfc_sli.h"
43#include "lpfc_sli4.h"
44#include "lpfc_nl.h"
45#include "lpfc_disc.h"
46#include "lpfc.h"
47#include "lpfc_scsi.h"
48#include "lpfc_nvme.h"
49#include "lpfc_logmsg.h"
50#include "lpfc_version.h"
51#include "lpfc_compat.h"
52#include "lpfc_crtn.h"
53#include "lpfc_vport.h"
54#include "lpfc_attr.h"
55
56#define LPFC_DEF_DEVLOSS_TMO 30
57#define LPFC_MIN_DEVLOSS_TMO 1
58#define LPFC_MAX_DEVLOSS_TMO 255
59
60
61
62
63
64#define LPFC_REG_WRITE_KEY_SIZE 4
65#define LPFC_REG_WRITE_KEY "EMLX"
66
67const char *const trunk_errmsg[] = {
68 "",
69 "link negotiated speed does not match existing"
70 " trunk - link was \"low\" speed",
71 "link negotiated speed does not match"
72 " existing trunk - link was \"middle\" speed",
73 "link negotiated speed does not match existing"
74 " trunk - link was \"high\" speed",
75 "Attached to non-trunking port - F_Port",
76 "Attached to non-trunking port - N_Port",
77 "FLOGI response timeout",
78 "non-FLOGI frame received",
79 "Invalid FLOGI response",
80 "Trunking initialization protocol",
81 "Trunk peer device mismatch",
82};
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99static void
100lpfc_jedec_to_ascii(int incr, char hdw[])
101{
102 int i, j;
103 for (i = 0; i < 8; i++) {
104 j = (incr & 0xf);
105 if (j <= 9)
106 hdw[7 - i] = 0x30 + j;
107 else
108 hdw[7 - i] = 0x61 + j - 10;
109 incr = (incr >> 4);
110 }
111 hdw[8] = 0;
112 return;
113}
114
115
116
117
118
119
120
121
122
123static ssize_t
124lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126{
127 return scnprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
128}
129
130
131
132
133
134
135
136
137
138static ssize_t
139lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
140 char *buf)
141{
142 struct Scsi_Host *shost = class_to_shost(dev);
143 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
144 struct lpfc_hba *phba = vport->phba;
145
146 if (phba->hba_flag & HBA_FIP_SUPPORT)
147 return scnprintf(buf, PAGE_SIZE, "1\n");
148 else
149 return scnprintf(buf, PAGE_SIZE, "0\n");
150}
151
152static ssize_t
153lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
154 char *buf)
155{
156 struct Scsi_Host *shost = class_to_shost(dev);
157 struct lpfc_vport *vport = shost_priv(shost);
158 struct lpfc_hba *phba = vport->phba;
159 struct lpfc_nvmet_tgtport *tgtp;
160 struct nvme_fc_local_port *localport;
161 struct lpfc_nvme_lport *lport;
162 struct lpfc_nvme_rport *rport;
163 struct lpfc_nodelist *ndlp;
164 struct nvme_fc_remote_port *nrport;
165 struct lpfc_fc4_ctrl_stat *cstat;
166 uint64_t data1, data2, data3;
167 uint64_t totin, totout, tot;
168 char *statep;
169 int i;
170 int len = 0;
171 char tmp[LPFC_MAX_NVME_INFO_TMP_LEN] = {0};
172
173 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
174 len = scnprintf(buf, PAGE_SIZE, "NVME Disabled\n");
175 return len;
176 }
177 if (phba->nvmet_support) {
178 if (!phba->targetport) {
179 len = scnprintf(buf, PAGE_SIZE,
180 "NVME Target: x%llx is not allocated\n",
181 wwn_to_u64(vport->fc_portname.u.wwn));
182 return len;
183 }
184
185 if (phba->targetport->port_id)
186 statep = "REGISTERED";
187 else
188 statep = "INIT";
189 scnprintf(tmp, sizeof(tmp),
190 "NVME Target Enabled State %s\n",
191 statep);
192 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
193 goto buffer_done;
194
195 scnprintf(tmp, sizeof(tmp),
196 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
197 "NVME Target: lpfc",
198 phba->brd_no,
199 wwn_to_u64(vport->fc_portname.u.wwn),
200 wwn_to_u64(vport->fc_nodename.u.wwn),
201 phba->targetport->port_id);
202 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
203 goto buffer_done;
204
205 if (strlcat(buf, "\nNVME Target: Statistics\n", PAGE_SIZE)
206 >= PAGE_SIZE)
207 goto buffer_done;
208
209 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
210 scnprintf(tmp, sizeof(tmp),
211 "LS: Rcv %08x Drop %08x Abort %08x\n",
212 atomic_read(&tgtp->rcv_ls_req_in),
213 atomic_read(&tgtp->rcv_ls_req_drop),
214 atomic_read(&tgtp->xmt_ls_abort));
215 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
216 goto buffer_done;
217
218 if (atomic_read(&tgtp->rcv_ls_req_in) !=
219 atomic_read(&tgtp->rcv_ls_req_out)) {
220 scnprintf(tmp, sizeof(tmp),
221 "Rcv LS: in %08x != out %08x\n",
222 atomic_read(&tgtp->rcv_ls_req_in),
223 atomic_read(&tgtp->rcv_ls_req_out));
224 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
225 goto buffer_done;
226 }
227
228 scnprintf(tmp, sizeof(tmp),
229 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
230 atomic_read(&tgtp->xmt_ls_rsp),
231 atomic_read(&tgtp->xmt_ls_drop),
232 atomic_read(&tgtp->xmt_ls_rsp_cmpl));
233 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
234 goto buffer_done;
235
236 scnprintf(tmp, sizeof(tmp),
237 "LS: RSP Abort %08x xb %08x Err %08x\n",
238 atomic_read(&tgtp->xmt_ls_rsp_aborted),
239 atomic_read(&tgtp->xmt_ls_rsp_xb_set),
240 atomic_read(&tgtp->xmt_ls_rsp_error));
241 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
242 goto buffer_done;
243
244 scnprintf(tmp, sizeof(tmp),
245 "FCP: Rcv %08x Defer %08x Release %08x "
246 "Drop %08x\n",
247 atomic_read(&tgtp->rcv_fcp_cmd_in),
248 atomic_read(&tgtp->rcv_fcp_cmd_defer),
249 atomic_read(&tgtp->xmt_fcp_release),
250 atomic_read(&tgtp->rcv_fcp_cmd_drop));
251 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
252 goto buffer_done;
253
254 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
255 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
256 scnprintf(tmp, sizeof(tmp),
257 "Rcv FCP: in %08x != out %08x\n",
258 atomic_read(&tgtp->rcv_fcp_cmd_in),
259 atomic_read(&tgtp->rcv_fcp_cmd_out));
260 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
261 goto buffer_done;
262 }
263
264 scnprintf(tmp, sizeof(tmp),
265 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
266 "drop %08x\n",
267 atomic_read(&tgtp->xmt_fcp_read),
268 atomic_read(&tgtp->xmt_fcp_read_rsp),
269 atomic_read(&tgtp->xmt_fcp_write),
270 atomic_read(&tgtp->xmt_fcp_rsp),
271 atomic_read(&tgtp->xmt_fcp_drop));
272 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
273 goto buffer_done;
274
275 scnprintf(tmp, sizeof(tmp),
276 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
277 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
278 atomic_read(&tgtp->xmt_fcp_rsp_error),
279 atomic_read(&tgtp->xmt_fcp_rsp_drop));
280 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
281 goto buffer_done;
282
283 scnprintf(tmp, sizeof(tmp),
284 "FCP Rsp Abort: %08x xb %08x xricqe %08x\n",
285 atomic_read(&tgtp->xmt_fcp_rsp_aborted),
286 atomic_read(&tgtp->xmt_fcp_rsp_xb_set),
287 atomic_read(&tgtp->xmt_fcp_xri_abort_cqe));
288 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
289 goto buffer_done;
290
291 scnprintf(tmp, sizeof(tmp),
292 "ABORT: Xmt %08x Cmpl %08x\n",
293 atomic_read(&tgtp->xmt_fcp_abort),
294 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
295 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
296 goto buffer_done;
297
298 scnprintf(tmp, sizeof(tmp),
299 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x\n",
300 atomic_read(&tgtp->xmt_abort_sol),
301 atomic_read(&tgtp->xmt_abort_unsol),
302 atomic_read(&tgtp->xmt_abort_rsp),
303 atomic_read(&tgtp->xmt_abort_rsp_error));
304 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
305 goto buffer_done;
306
307 scnprintf(tmp, sizeof(tmp),
308 "DELAY: ctx %08x fod %08x wqfull %08x\n",
309 atomic_read(&tgtp->defer_ctx),
310 atomic_read(&tgtp->defer_fod),
311 atomic_read(&tgtp->defer_wqfull));
312 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
313 goto buffer_done;
314
315
316 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
317 tot += atomic_read(&tgtp->xmt_fcp_release);
318 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
319
320 scnprintf(tmp, sizeof(tmp),
321 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
322 "CTX Outstanding %08llx\n\n",
323 phba->sli4_hba.nvmet_xri_cnt,
324 phba->sli4_hba.nvmet_io_wait_cnt,
325 phba->sli4_hba.nvmet_io_wait_total,
326 tot);
327 strlcat(buf, tmp, PAGE_SIZE);
328 goto buffer_done;
329 }
330
331 localport = vport->localport;
332 if (!localport) {
333 len = scnprintf(buf, PAGE_SIZE,
334 "NVME Initiator x%llx is not allocated\n",
335 wwn_to_u64(vport->fc_portname.u.wwn));
336 return len;
337 }
338 lport = (struct lpfc_nvme_lport *)localport->private;
339 if (strlcat(buf, "\nNVME Initiator Enabled\n", PAGE_SIZE) >= PAGE_SIZE)
340 goto buffer_done;
341
342 scnprintf(tmp, sizeof(tmp),
343 "XRI Dist lpfc%d Total %d IO %d ELS %d\n",
344 phba->brd_no,
345 phba->sli4_hba.max_cfg_param.max_xri,
346 phba->sli4_hba.io_xri_max,
347 lpfc_sli4_get_els_iocb_cnt(phba));
348 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
349 goto buffer_done;
350
351
352 if (localport->port_id)
353 statep = "ONLINE";
354 else
355 statep = "UNKNOWN ";
356
357 scnprintf(tmp, sizeof(tmp),
358 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
359 "NVME LPORT lpfc",
360 phba->brd_no,
361 wwn_to_u64(vport->fc_portname.u.wwn),
362 wwn_to_u64(vport->fc_nodename.u.wwn),
363 localport->port_id, statep);
364 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
365 goto buffer_done;
366
367 spin_lock_irq(shost->host_lock);
368
369 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
370 nrport = NULL;
371 spin_lock(&ndlp->lock);
372 rport = lpfc_ndlp_get_nrport(ndlp);
373 if (rport)
374 nrport = rport->remoteport;
375 spin_unlock(&ndlp->lock);
376 if (!nrport)
377 continue;
378
379
380 switch (nrport->port_state) {
381 case FC_OBJSTATE_ONLINE:
382 statep = "ONLINE";
383 break;
384 case FC_OBJSTATE_UNKNOWN:
385 statep = "UNKNOWN ";
386 break;
387 default:
388 statep = "UNSUPPORTED";
389 break;
390 }
391
392
393 if (strlcat(buf, "NVME RPORT ", PAGE_SIZE) >= PAGE_SIZE)
394 goto unlock_buf_done;
395 if (phba->brd_no >= 10) {
396 if (strlcat(buf, " ", PAGE_SIZE) >= PAGE_SIZE)
397 goto unlock_buf_done;
398 }
399
400 scnprintf(tmp, sizeof(tmp), "WWPN x%llx ",
401 nrport->port_name);
402 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
403 goto unlock_buf_done;
404
405 scnprintf(tmp, sizeof(tmp), "WWNN x%llx ",
406 nrport->node_name);
407 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
408 goto unlock_buf_done;
409
410 scnprintf(tmp, sizeof(tmp), "DID x%06x ",
411 nrport->port_id);
412 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
413 goto unlock_buf_done;
414
415
416 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR) {
417 if (strlcat(buf, "INITIATOR ", PAGE_SIZE) >= PAGE_SIZE)
418 goto unlock_buf_done;
419 }
420 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET) {
421 if (strlcat(buf, "TARGET ", PAGE_SIZE) >= PAGE_SIZE)
422 goto unlock_buf_done;
423 }
424 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY) {
425 if (strlcat(buf, "DISCSRVC ", PAGE_SIZE) >= PAGE_SIZE)
426 goto unlock_buf_done;
427 }
428 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
429 FC_PORT_ROLE_NVME_TARGET |
430 FC_PORT_ROLE_NVME_DISCOVERY)) {
431 scnprintf(tmp, sizeof(tmp), "UNKNOWN ROLE x%x",
432 nrport->port_role);
433 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
434 goto unlock_buf_done;
435 }
436
437 scnprintf(tmp, sizeof(tmp), "%s\n", statep);
438 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
439 goto unlock_buf_done;
440 }
441 spin_unlock_irq(shost->host_lock);
442
443 if (!lport)
444 goto buffer_done;
445
446 if (strlcat(buf, "\nNVME Statistics\n", PAGE_SIZE) >= PAGE_SIZE)
447 goto buffer_done;
448
449 scnprintf(tmp, sizeof(tmp),
450 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
451 atomic_read(&lport->fc4NvmeLsRequests),
452 atomic_read(&lport->fc4NvmeLsCmpls),
453 atomic_read(&lport->xmt_ls_abort));
454 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
455 goto buffer_done;
456
457 scnprintf(tmp, sizeof(tmp),
458 "LS XMIT: Err %08x CMPL: xb %08x Err %08x\n",
459 atomic_read(&lport->xmt_ls_err),
460 atomic_read(&lport->cmpl_ls_xb),
461 atomic_read(&lport->cmpl_ls_err));
462 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
463 goto buffer_done;
464
465 totin = 0;
466 totout = 0;
467 for (i = 0; i < phba->cfg_hdw_queue; i++) {
468 cstat = &phba->sli4_hba.hdwq[i].nvme_cstat;
469 tot = cstat->io_cmpls;
470 totin += tot;
471 data1 = cstat->input_requests;
472 data2 = cstat->output_requests;
473 data3 = cstat->control_requests;
474 totout += (data1 + data2 + data3);
475 }
476 scnprintf(tmp, sizeof(tmp),
477 "Total FCP Cmpl %016llx Issue %016llx "
478 "OutIO %016llx\n",
479 totin, totout, totout - totin);
480 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
481 goto buffer_done;
482
483 scnprintf(tmp, sizeof(tmp),
484 "\tabort %08x noxri %08x nondlp %08x qdepth %08x "
485 "wqerr %08x err %08x\n",
486 atomic_read(&lport->xmt_fcp_abort),
487 atomic_read(&lport->xmt_fcp_noxri),
488 atomic_read(&lport->xmt_fcp_bad_ndlp),
489 atomic_read(&lport->xmt_fcp_qdepth),
490 atomic_read(&lport->xmt_fcp_wqerr),
491 atomic_read(&lport->xmt_fcp_err));
492 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
493 goto buffer_done;
494
495 scnprintf(tmp, sizeof(tmp),
496 "FCP CMPL: xb %08x Err %08x\n",
497 atomic_read(&lport->cmpl_fcp_xb),
498 atomic_read(&lport->cmpl_fcp_err));
499 strlcat(buf, tmp, PAGE_SIZE);
500
501
502 goto buffer_done;
503
504 unlock_buf_done:
505 spin_unlock_irq(shost->host_lock);
506
507 buffer_done:
508 len = strnlen(buf, PAGE_SIZE);
509
510 if (unlikely(len >= (PAGE_SIZE - 1))) {
511 lpfc_printf_log(phba, KERN_INFO, LOG_NVME,
512 "6314 Catching potential buffer "
513 "overflow > PAGE_SIZE = %lu bytes\n",
514 PAGE_SIZE);
515 strlcpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_NVME_INFO_MORE_STR),
516 LPFC_NVME_INFO_MORE_STR,
517 sizeof(LPFC_NVME_INFO_MORE_STR) + 1);
518 }
519
520 return len;
521}
522
523static ssize_t
524lpfc_scsi_stat_show(struct device *dev, struct device_attribute *attr,
525 char *buf)
526{
527 struct Scsi_Host *shost = class_to_shost(dev);
528 struct lpfc_vport *vport = shost_priv(shost);
529 struct lpfc_hba *phba = vport->phba;
530 int len;
531 struct lpfc_fc4_ctrl_stat *cstat;
532 u64 data1, data2, data3;
533 u64 tot, totin, totout;
534 int i;
535 char tmp[LPFC_MAX_SCSI_INFO_TMP_LEN] = {0};
536
537 if (!(vport->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ||
538 (phba->sli_rev != LPFC_SLI_REV4))
539 return 0;
540
541 scnprintf(buf, PAGE_SIZE, "SCSI HDWQ Statistics\n");
542
543 totin = 0;
544 totout = 0;
545 for (i = 0; i < phba->cfg_hdw_queue; i++) {
546 cstat = &phba->sli4_hba.hdwq[i].scsi_cstat;
547 tot = cstat->io_cmpls;
548 totin += tot;
549 data1 = cstat->input_requests;
550 data2 = cstat->output_requests;
551 data3 = cstat->control_requests;
552 totout += (data1 + data2 + data3);
553
554 scnprintf(tmp, sizeof(tmp), "HDWQ (%d): Rd %016llx Wr %016llx "
555 "IO %016llx ", i, data1, data2, data3);
556 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
557 goto buffer_done;
558
559 scnprintf(tmp, sizeof(tmp), "Cmpl %016llx OutIO %016llx\n",
560 tot, ((data1 + data2 + data3) - tot));
561 if (strlcat(buf, tmp, PAGE_SIZE) >= PAGE_SIZE)
562 goto buffer_done;
563 }
564 scnprintf(tmp, sizeof(tmp), "Total FCP Cmpl %016llx Issue %016llx "
565 "OutIO %016llx\n", totin, totout, totout - totin);
566 strlcat(buf, tmp, PAGE_SIZE);
567
568buffer_done:
569 len = strnlen(buf, PAGE_SIZE);
570
571 return len;
572}
573
574static ssize_t
575lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
576 char *buf)
577{
578 struct Scsi_Host *shost = class_to_shost(dev);
579 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
580 struct lpfc_hba *phba = vport->phba;
581
582 if (phba->cfg_enable_bg) {
583 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
584 return scnprintf(buf, PAGE_SIZE,
585 "BlockGuard Enabled\n");
586 else
587 return scnprintf(buf, PAGE_SIZE,
588 "BlockGuard Not Supported\n");
589 } else
590 return scnprintf(buf, PAGE_SIZE,
591 "BlockGuard Disabled\n");
592}
593
594static ssize_t
595lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
596 char *buf)
597{
598 struct Scsi_Host *shost = class_to_shost(dev);
599 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
600 struct lpfc_hba *phba = vport->phba;
601
602 return scnprintf(buf, PAGE_SIZE, "%llu\n",
603 (unsigned long long)phba->bg_guard_err_cnt);
604}
605
606static ssize_t
607lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
608 char *buf)
609{
610 struct Scsi_Host *shost = class_to_shost(dev);
611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
612 struct lpfc_hba *phba = vport->phba;
613
614 return scnprintf(buf, PAGE_SIZE, "%llu\n",
615 (unsigned long long)phba->bg_apptag_err_cnt);
616}
617
618static ssize_t
619lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
620 char *buf)
621{
622 struct Scsi_Host *shost = class_to_shost(dev);
623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
625
626 return scnprintf(buf, PAGE_SIZE, "%llu\n",
627 (unsigned long long)phba->bg_reftag_err_cnt);
628}
629
630
631
632
633
634
635
636
637
638static ssize_t
639lpfc_info_show(struct device *dev, struct device_attribute *attr,
640 char *buf)
641{
642 struct Scsi_Host *host = class_to_shost(dev);
643
644 return scnprintf(buf, PAGE_SIZE, "%s\n", lpfc_info(host));
645}
646
647
648
649
650
651
652
653
654
655static ssize_t
656lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
657 char *buf)
658{
659 struct Scsi_Host *shost = class_to_shost(dev);
660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
661 struct lpfc_hba *phba = vport->phba;
662
663 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->SerialNumber);
664}
665
666
667
668
669
670
671
672
673
674
675
676
677
678static ssize_t
679lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
680 char *buf)
681{
682 struct Scsi_Host *shost = class_to_shost(dev);
683 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
684 struct lpfc_hba *phba = vport->phba;
685 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->temp_sensor_support);
686}
687
688
689
690
691
692
693
694
695
696static ssize_t
697lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
698 char *buf)
699{
700 struct Scsi_Host *shost = class_to_shost(dev);
701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
702 struct lpfc_hba *phba = vport->phba;
703
704 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelDesc);
705}
706
707
708
709
710
711
712
713
714
715static ssize_t
716lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
717 char *buf)
718{
719 struct Scsi_Host *shost = class_to_shost(dev);
720 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
721 struct lpfc_hba *phba = vport->phba;
722
723 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ModelName);
724}
725
726
727
728
729
730
731
732
733
734static ssize_t
735lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
736 char *buf)
737{
738 struct Scsi_Host *shost = class_to_shost(dev);
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
740 struct lpfc_hba *phba = vport->phba;
741
742 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->ProgramType);
743}
744
745
746
747
748
749
750
751
752
753static ssize_t
754lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
755{
756 struct Scsi_Host *shost = class_to_shost(dev);
757 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
758 struct lpfc_hba *phba = vport->phba;
759
760 return scnprintf(buf, PAGE_SIZE, "%d\n",
761 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
762}
763
764
765
766
767
768
769
770
771
772static ssize_t
773lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
774 char *buf)
775{
776 struct Scsi_Host *shost = class_to_shost(dev);
777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
778 struct lpfc_hba *phba = vport->phba;
779
780 return scnprintf(buf, PAGE_SIZE, "%s\n", phba->Port);
781}
782
783
784
785
786
787
788
789
790
791static ssize_t
792lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
793 char *buf)
794{
795 struct Scsi_Host *shost = class_to_shost(dev);
796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
797 struct lpfc_hba *phba = vport->phba;
798 uint32_t if_type;
799 uint8_t sli_family;
800 char fwrev[FW_REV_STR_SIZE];
801 int len;
802
803 lpfc_decode_firmware_rev(phba, fwrev, 1);
804 if_type = phba->sli4_hba.pc_sli4_params.if_type;
805 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
806
807 if (phba->sli_rev < LPFC_SLI_REV4)
808 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
809 fwrev, phba->sli_rev);
810 else
811 len = scnprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
812 fwrev, phba->sli_rev, if_type, sli_family);
813
814 return len;
815}
816
817
818
819
820
821
822
823
824
825static ssize_t
826lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
827{
828 char hdw[9];
829 struct Scsi_Host *shost = class_to_shost(dev);
830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
831 struct lpfc_hba *phba = vport->phba;
832 lpfc_vpd_t *vp = &phba->vpd;
833
834 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
835 return scnprintf(buf, PAGE_SIZE, "%s %08x %08x\n", hdw,
836 vp->rev.smRev, vp->rev.smFwRev);
837}
838
839
840
841
842
843
844
845
846
847static ssize_t
848lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
849 char *buf)
850{
851 struct Scsi_Host *shost = class_to_shost(dev);
852 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
853 struct lpfc_hba *phba = vport->phba;
854 char fwrev[FW_REV_STR_SIZE];
855
856 if (phba->sli_rev < LPFC_SLI_REV4)
857 return scnprintf(buf, PAGE_SIZE, "%s\n",
858 phba->OptionROMVersion);
859
860 lpfc_decode_firmware_rev(phba, fwrev, 1);
861 return scnprintf(buf, PAGE_SIZE, "%s\n", fwrev);
862}
863
864
865
866
867
868
869
870
871
872
873
874
875static ssize_t
876lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
877 char *buf)
878{
879 struct Scsi_Host *shost = class_to_shost(dev);
880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
881 struct lpfc_hba *phba = vport->phba;
882 int len = 0;
883
884 switch (phba->link_state) {
885 case LPFC_LINK_UNKNOWN:
886 case LPFC_WARM_START:
887 case LPFC_INIT_START:
888 case LPFC_INIT_MBX_CMDS:
889 case LPFC_LINK_DOWN:
890 case LPFC_HBA_ERROR:
891 if (phba->hba_flag & LINK_DISABLED)
892 len += scnprintf(buf + len, PAGE_SIZE-len,
893 "Link Down - User disabled\n");
894 else
895 len += scnprintf(buf + len, PAGE_SIZE-len,
896 "Link Down\n");
897 break;
898 case LPFC_LINK_UP:
899 case LPFC_CLEAR_LA:
900 case LPFC_HBA_READY:
901 len += scnprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
902
903 switch (vport->port_state) {
904 case LPFC_LOCAL_CFG_LINK:
905 len += scnprintf(buf + len, PAGE_SIZE-len,
906 "Configuring Link\n");
907 break;
908 case LPFC_FDISC:
909 case LPFC_FLOGI:
910 case LPFC_FABRIC_CFG_LINK:
911 case LPFC_NS_REG:
912 case LPFC_NS_QRY:
913 case LPFC_BUILD_DISC_LIST:
914 case LPFC_DISC_AUTH:
915 len += scnprintf(buf + len, PAGE_SIZE - len,
916 "Discovery\n");
917 break;
918 case LPFC_VPORT_READY:
919 len += scnprintf(buf + len, PAGE_SIZE - len,
920 "Ready\n");
921 break;
922
923 case LPFC_VPORT_FAILED:
924 len += scnprintf(buf + len, PAGE_SIZE - len,
925 "Failed\n");
926 break;
927
928 case LPFC_VPORT_UNKNOWN:
929 len += scnprintf(buf + len, PAGE_SIZE - len,
930 "Unknown\n");
931 break;
932 }
933 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
934 len += scnprintf(buf + len, PAGE_SIZE-len,
935 " Menlo Maint Mode\n");
936 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
937 if (vport->fc_flag & FC_PUBLIC_LOOP)
938 len += scnprintf(buf + len, PAGE_SIZE-len,
939 " Public Loop\n");
940 else
941 len += scnprintf(buf + len, PAGE_SIZE-len,
942 " Private Loop\n");
943 } else {
944 if (vport->fc_flag & FC_FABRIC)
945 len += scnprintf(buf + len, PAGE_SIZE-len,
946 " Fabric\n");
947 else
948 len += scnprintf(buf + len, PAGE_SIZE-len,
949 " Point-2-Point\n");
950 }
951 }
952
953 if ((phba->sli_rev == LPFC_SLI_REV4) &&
954 ((bf_get(lpfc_sli_intf_if_type,
955 &phba->sli4_hba.sli_intf) ==
956 LPFC_SLI_INTF_IF_TYPE_6))) {
957 struct lpfc_trunk_link link = phba->trunk_link;
958
959 if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
960 len += scnprintf(buf + len, PAGE_SIZE - len,
961 "Trunk port 0: Link %s %s\n",
962 (link.link0.state == LPFC_LINK_UP) ?
963 "Up" : "Down. ",
964 trunk_errmsg[link.link0.fault]);
965
966 if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
967 len += scnprintf(buf + len, PAGE_SIZE - len,
968 "Trunk port 1: Link %s %s\n",
969 (link.link1.state == LPFC_LINK_UP) ?
970 "Up" : "Down. ",
971 trunk_errmsg[link.link1.fault]);
972
973 if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
974 len += scnprintf(buf + len, PAGE_SIZE - len,
975 "Trunk port 2: Link %s %s\n",
976 (link.link2.state == LPFC_LINK_UP) ?
977 "Up" : "Down. ",
978 trunk_errmsg[link.link2.fault]);
979
980 if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
981 len += scnprintf(buf + len, PAGE_SIZE - len,
982 "Trunk port 3: Link %s %s\n",
983 (link.link3.state == LPFC_LINK_UP) ?
984 "Up" : "Down. ",
985 trunk_errmsg[link.link3.fault]);
986
987 }
988
989 return len;
990}
991
992
993
994
995
996
997
998
999
1000static ssize_t
1001lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
1002 char *buf)
1003{
1004 struct Scsi_Host *shost = class_to_shost(dev);
1005 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1006 struct lpfc_hba *phba = vport->phba;
1007
1008 if (phba->sli_rev < LPFC_SLI_REV4)
1009 return scnprintf(buf, PAGE_SIZE, "fc\n");
1010
1011 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
1012 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
1013 return scnprintf(buf, PAGE_SIZE, "fcoe\n");
1014 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
1015 return scnprintf(buf, PAGE_SIZE, "fc\n");
1016 }
1017 return scnprintf(buf, PAGE_SIZE, "unknown\n");
1018}
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029static ssize_t
1030lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
1031 char *buf)
1032{
1033 struct Scsi_Host *shost = class_to_shost(dev);
1034 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
1035 struct lpfc_hba *phba = vport->phba;
1036
1037 return scnprintf(buf, PAGE_SIZE, "%d\n",
1038 phba->sli4_hba.pc_sli4_params.oas_supported);
1039}
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053static ssize_t
1054lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
1055 const char *buf, size_t count)
1056{
1057 struct Scsi_Host *shost = class_to_shost(dev);
1058 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1059 struct lpfc_hba *phba = vport->phba;
1060
1061 int status = -EINVAL;
1062
1063 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
1064 (phba->link_state == LPFC_LINK_DOWN))
1065 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
1066 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
1067 (phba->link_state >= LPFC_LINK_UP))
1068 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
1069
1070 if (status == 0)
1071 return strlen(buf);
1072 else
1073 return status;
1074}
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088static ssize_t
1089lpfc_num_discovered_ports_show(struct device *dev,
1090 struct device_attribute *attr, char *buf)
1091{
1092 struct Scsi_Host *shost = class_to_shost(dev);
1093 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1094
1095 return scnprintf(buf, PAGE_SIZE, "%d\n",
1096 vport->fc_map_cnt + vport->fc_unmap_cnt);
1097}
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113static int
1114lpfc_issue_lip(struct Scsi_Host *shost)
1115{
1116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1117 struct lpfc_hba *phba = vport->phba;
1118 LPFC_MBOXQ_t *pmboxq;
1119 int mbxstatus = MBXERR_ERROR;
1120
1121
1122
1123
1124
1125 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1126 (phba->hba_flag & LINK_DISABLED) ||
1127 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
1128 return -EPERM;
1129
1130 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
1131
1132 if (!pmboxq)
1133 return -ENOMEM;
1134
1135 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1136 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
1137 pmboxq->u.mb.mbxOwner = OWN_HOST;
1138
1139 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
1140
1141 if ((mbxstatus == MBX_SUCCESS) &&
1142 (pmboxq->u.mb.mbxStatus == 0 ||
1143 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
1144 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1145 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
1146 phba->cfg_link_speed);
1147 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
1148 phba->fc_ratov * 2);
1149 if ((mbxstatus == MBX_SUCCESS) &&
1150 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
1151 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1152 "2859 SLI authentication is required "
1153 "for INIT_LINK but has not done yet\n");
1154 }
1155
1156 lpfc_set_loopback_flag(phba);
1157 if (mbxstatus != MBX_TIMEOUT)
1158 mempool_free(pmboxq, phba->mbox_mem_pool);
1159
1160 if (mbxstatus == MBXERR_ERROR)
1161 return -EIO;
1162
1163 return 0;
1164}
1165
1166int
1167lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
1168{
1169 int cnt = 0;
1170
1171 spin_lock_irq(lock);
1172 while (!list_empty(q)) {
1173 spin_unlock_irq(lock);
1174 msleep(20);
1175 if (cnt++ > 250) {
1176 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1177 "0466 Outstanding IO when "
1178 "bringing Adapter offline\n");
1179 return 0;
1180 }
1181 spin_lock_irq(lock);
1182 }
1183 spin_unlock_irq(lock);
1184 return 1;
1185}
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202static int
1203lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
1204{
1205 struct completion online_compl;
1206 struct lpfc_queue *qp = NULL;
1207 struct lpfc_sli_ring *pring;
1208 struct lpfc_sli *psli;
1209 int status = 0;
1210 int i;
1211 int rc;
1212
1213 init_completion(&online_compl);
1214 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1215 LPFC_EVT_OFFLINE_PREP);
1216 if (rc == 0)
1217 return -ENOMEM;
1218
1219 wait_for_completion(&online_compl);
1220
1221 if (status != 0)
1222 return -EIO;
1223
1224 psli = &phba->sli;
1225
1226
1227
1228
1229
1230
1231 spin_lock_irq(&phba->hbalock);
1232 if (!(psli->sli_flag & LPFC_QUEUE_FREE_INIT)) {
1233 psli->sli_flag |= LPFC_QUEUE_FREE_WAIT;
1234 } else {
1235 spin_unlock_irq(&phba->hbalock);
1236 goto skip_wait;
1237 }
1238 spin_unlock_irq(&phba->hbalock);
1239
1240
1241
1242
1243 if (phba->sli_rev != LPFC_SLI_REV4) {
1244 for (i = 0; i < psli->num_rings; i++) {
1245 pring = &psli->sli3_ring[i];
1246 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1247 &phba->hbalock))
1248 goto out;
1249 }
1250 } else {
1251 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1252 pring = qp->pring;
1253 if (!pring)
1254 continue;
1255 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1256 &pring->ring_lock))
1257 goto out;
1258 }
1259 }
1260out:
1261 spin_lock_irq(&phba->hbalock);
1262 psli->sli_flag &= ~LPFC_QUEUE_FREE_WAIT;
1263 spin_unlock_irq(&phba->hbalock);
1264
1265skip_wait:
1266 init_completion(&online_compl);
1267 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1268 if (rc == 0)
1269 return -ENOMEM;
1270
1271 wait_for_completion(&online_compl);
1272
1273 if (status != 0)
1274 return -EIO;
1275
1276 return 0;
1277}
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299static int
1300lpfc_reset_pci_bus(struct lpfc_hba *phba)
1301{
1302 struct pci_dev *pdev = phba->pcidev;
1303 struct Scsi_Host *shost = NULL;
1304 struct lpfc_hba *phba_other = NULL;
1305 struct pci_dev *ptr = NULL;
1306 int res;
1307
1308 if (phba->cfg_enable_hba_reset != 2)
1309 return -ENOTSUPP;
1310
1311 if (!pdev) {
1312 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, "8345 pdev NULL!\n");
1313 return -ENODEV;
1314 }
1315
1316 res = lpfc_check_pci_resettable(phba);
1317 if (res)
1318 return res;
1319
1320
1321 list_for_each_entry(ptr, &pdev->bus->devices, bus_list) {
1322
1323 shost = pci_get_drvdata(ptr);
1324 if (shost) {
1325 phba_other =
1326 ((struct lpfc_vport *)shost->hostdata)->phba;
1327 if (!(phba_other->pport->fc_flag & FC_OFFLINE_MODE)) {
1328 lpfc_printf_log(phba_other, KERN_INFO, LOG_INIT,
1329 "8349 WWPN = 0x%02x%02x%02x%02x"
1330 "%02x%02x%02x%02x is not "
1331 "offline!\n",
1332 phba_other->wwpn[0],
1333 phba_other->wwpn[1],
1334 phba_other->wwpn[2],
1335 phba_other->wwpn[3],
1336 phba_other->wwpn[4],
1337 phba_other->wwpn[5],
1338 phba_other->wwpn[6],
1339 phba_other->wwpn[7]);
1340 return -EBUSY;
1341 }
1342 }
1343 }
1344
1345
1346 res = pci_reset_bus(pdev);
1347 if (res) {
1348 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1349 "8350 PCI reset bus failed: %d\n", res);
1350 }
1351
1352 return res;
1353}
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372int
1373lpfc_selective_reset(struct lpfc_hba *phba)
1374{
1375 struct completion online_compl;
1376 int status = 0;
1377 int rc;
1378
1379 if (!phba->cfg_enable_hba_reset)
1380 return -EACCES;
1381
1382 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1383 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1384
1385 if (status != 0)
1386 return status;
1387 }
1388
1389 init_completion(&online_compl);
1390 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1391 LPFC_EVT_ONLINE);
1392 if (rc == 0)
1393 return -ENOMEM;
1394
1395 wait_for_completion(&online_compl);
1396
1397 if (status != 0)
1398 return -EIO;
1399
1400 return 0;
1401}
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424static ssize_t
1425lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1426 const char *buf, size_t count)
1427{
1428 struct Scsi_Host *shost = class_to_shost(dev);
1429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1430 struct lpfc_hba *phba = vport->phba;
1431 int status = -EINVAL;
1432
1433 if (!phba->cfg_enable_hba_reset)
1434 return -EACCES;
1435
1436 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1437 status = phba->lpfc_selective_reset(phba);
1438
1439 if (status == 0)
1440 return strlen(buf);
1441 else
1442 return status;
1443}
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461int
1462lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1463{
1464 struct lpfc_register portstat_reg = {0};
1465 int i;
1466
1467 msleep(100);
1468 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1469 &portstat_reg.word0))
1470 return -EIO;
1471
1472
1473 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1474 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1475 return -EPERM;
1476
1477
1478 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1479 msleep(10);
1480 if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1481 &portstat_reg.word0))
1482 continue;
1483 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1484 continue;
1485 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1486 continue;
1487 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1488 continue;
1489 break;
1490 }
1491
1492 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1493 return 0;
1494 else
1495 return -EIO;
1496}
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510static ssize_t
1511lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1512{
1513 struct completion online_compl;
1514 struct pci_dev *pdev = phba->pcidev;
1515 uint32_t before_fc_flag;
1516 uint32_t sriov_nr_virtfn;
1517 uint32_t reg_val;
1518 int status = 0, rc = 0;
1519 int job_posted = 1, sriov_err;
1520
1521 if (!phba->cfg_enable_hba_reset)
1522 return -EACCES;
1523
1524 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1525 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
1526 LPFC_SLI_INTF_IF_TYPE_2))
1527 return -EPERM;
1528
1529
1530 before_fc_flag = phba->pport->fc_flag;
1531 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1532
1533
1534 if (phba->cfg_sriov_nr_virtfn) {
1535 pci_disable_sriov(pdev);
1536 phba->cfg_sriov_nr_virtfn = 0;
1537 }
1538
1539 if (opcode == LPFC_FW_DUMP)
1540 phba->hba_flag |= HBA_FW_DUMP_OP;
1541
1542 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1543
1544 if (status != 0) {
1545 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1546 return status;
1547 }
1548
1549
1550 msleep(100);
1551
1552 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1553 LPFC_CTL_PDEV_CTL_OFFSET);
1554
1555 if (opcode == LPFC_FW_DUMP)
1556 reg_val |= LPFC_FW_DUMP_REQUEST;
1557 else if (opcode == LPFC_FW_RESET)
1558 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1559 else if (opcode == LPFC_DV_RESET)
1560 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1561
1562 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1563 LPFC_CTL_PDEV_CTL_OFFSET);
1564
1565 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1566
1567
1568 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1569
1570 if (rc == -EPERM) {
1571
1572 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1573 "3150 No privilege to perform the requested "
1574 "access: x%x\n", reg_val);
1575 } else if (rc == -EIO) {
1576
1577 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1578 "3153 Fail to perform the requested "
1579 "access: x%x\n", reg_val);
1580 return rc;
1581 }
1582
1583
1584 if (before_fc_flag & FC_OFFLINE_MODE)
1585 goto out;
1586
1587 init_completion(&online_compl);
1588 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1589 LPFC_EVT_ONLINE);
1590 if (!job_posted)
1591 goto out;
1592
1593 wait_for_completion(&online_compl);
1594
1595out:
1596
1597 if (sriov_nr_virtfn) {
1598 sriov_err =
1599 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1600 if (!sriov_err)
1601 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1602 }
1603
1604
1605 if (!rc) {
1606 if (!job_posted)
1607 rc = -ENOMEM;
1608 else if (status)
1609 rc = -EIO;
1610 }
1611 return rc;
1612}
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622static ssize_t
1623lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1624 char *buf)
1625{
1626 struct Scsi_Host *shost = class_to_shost(dev);
1627 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1628 struct lpfc_hba *phba = vport->phba;
1629
1630 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1631}
1632
1633static int
1634lpfc_set_trunking(struct lpfc_hba *phba, char *buff_out)
1635{
1636 LPFC_MBOXQ_t *mbox = NULL;
1637 unsigned long val = 0;
1638 char *pval = NULL;
1639 int rc = 0;
1640
1641 if (!strncmp("enable", buff_out,
1642 strlen("enable"))) {
1643 pval = buff_out + strlen("enable") + 1;
1644 rc = kstrtoul(pval, 0, &val);
1645 if (rc)
1646 return rc;
1647 } else if (!strncmp("disable", buff_out,
1648 strlen("disable"))) {
1649 val = 0;
1650 } else {
1651 return -EINVAL;
1652 }
1653
1654 switch (val) {
1655 case 0:
1656 val = 0x0;
1657 break;
1658 case 2:
1659 val = 0x1;
1660 break;
1661 case 4:
1662 val = 0x2;
1663 break;
1664 default:
1665 return -EINVAL;
1666 }
1667
1668 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1669 "0070 Set trunk mode with val %ld ", val);
1670
1671 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1672 if (!mbox)
1673 return -ENOMEM;
1674
1675 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
1676 LPFC_MBOX_OPCODE_FCOE_FC_SET_TRUNK_MODE,
1677 12, LPFC_SLI4_MBX_EMBED);
1678
1679 bf_set(lpfc_mbx_set_trunk_mode,
1680 &mbox->u.mqe.un.set_trunk_mode,
1681 val);
1682 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
1683 if (rc)
1684 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1685 "0071 Set trunk mode failed with status: %d",
1686 rc);
1687 mempool_free(mbox, phba->mbox_mem_pool);
1688
1689 return 0;
1690}
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700static ssize_t
1701lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1702 char *buf)
1703{
1704 struct Scsi_Host *shost = class_to_shost(dev);
1705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1706 struct lpfc_hba *phba = vport->phba;
1707 char * state;
1708
1709 if (phba->link_state == LPFC_HBA_ERROR)
1710 state = "error";
1711 else if (phba->link_state == LPFC_WARM_START)
1712 state = "warm start";
1713 else if (phba->link_state == LPFC_INIT_START)
1714 state = "offline";
1715 else
1716 state = "online";
1717
1718 return scnprintf(buf, PAGE_SIZE, "%s\n", state);
1719}
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734static ssize_t
1735lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1736 const char *buf, size_t count)
1737{
1738 struct Scsi_Host *shost = class_to_shost(dev);
1739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1740 struct lpfc_hba *phba = vport->phba;
1741 struct completion online_compl;
1742 char *board_mode_str = NULL;
1743 int status = 0;
1744 int rc;
1745
1746 if (!phba->cfg_enable_hba_reset) {
1747 status = -EACCES;
1748 goto board_mode_out;
1749 }
1750
1751 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1752 "3050 lpfc_board_mode set to %s\n", buf);
1753
1754 init_completion(&online_compl);
1755
1756 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1757 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1758 LPFC_EVT_ONLINE);
1759 if (rc == 0) {
1760 status = -ENOMEM;
1761 goto board_mode_out;
1762 }
1763 wait_for_completion(&online_compl);
1764 if (status)
1765 status = -EIO;
1766 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1767 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1768 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1769 if (phba->sli_rev == LPFC_SLI_REV4)
1770 status = -EINVAL;
1771 else
1772 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1773 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1774 if (phba->sli_rev == LPFC_SLI_REV4)
1775 status = -EINVAL;
1776 else
1777 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1778 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1779 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1780 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1781 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1782 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1783 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1784 else if (strncmp(buf, "pci_bus_reset", sizeof("pci_bus_reset") - 1)
1785 == 0)
1786 status = lpfc_reset_pci_bus(phba);
1787 else if (strncmp(buf, "heartbeat", sizeof("heartbeat") - 1) == 0)
1788 lpfc_issue_hb_tmo(phba);
1789 else if (strncmp(buf, "trunk", sizeof("trunk") - 1) == 0)
1790 status = lpfc_set_trunking(phba, (char *)buf + sizeof("trunk"));
1791 else
1792 status = -EINVAL;
1793
1794board_mode_out:
1795 if (!status)
1796 return strlen(buf);
1797 else {
1798 board_mode_str = strchr(buf, '\n');
1799 if (board_mode_str)
1800 *board_mode_str = '\0';
1801 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1802 "3097 Failed \"%s\", status(%d), "
1803 "fc_flag(x%x)\n",
1804 buf, status, phba->pport->fc_flag);
1805 return status;
1806 }
1807}
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827static int
1828lpfc_get_hba_info(struct lpfc_hba *phba,
1829 uint32_t *mxri, uint32_t *axri,
1830 uint32_t *mrpi, uint32_t *arpi,
1831 uint32_t *mvpi, uint32_t *avpi)
1832{
1833 struct lpfc_mbx_read_config *rd_config;
1834 LPFC_MBOXQ_t *pmboxq;
1835 MAILBOX_t *pmb;
1836 int rc = 0;
1837 uint32_t max_vpi;
1838
1839
1840
1841
1842
1843 if (phba->link_state < LPFC_LINK_DOWN ||
1844 !phba->mbox_mem_pool ||
1845 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1846 return 0;
1847
1848 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1849 return 0;
1850
1851 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1852 if (!pmboxq)
1853 return 0;
1854 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1855
1856 pmb = &pmboxq->u.mb;
1857 pmb->mbxCommand = MBX_READ_CONFIG;
1858 pmb->mbxOwner = OWN_HOST;
1859 pmboxq->ctx_buf = NULL;
1860
1861 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1862 rc = MBX_NOT_FINISHED;
1863 else
1864 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1865
1866 if (rc != MBX_SUCCESS) {
1867 if (rc != MBX_TIMEOUT)
1868 mempool_free(pmboxq, phba->mbox_mem_pool);
1869 return 0;
1870 }
1871
1872 if (phba->sli_rev == LPFC_SLI_REV4) {
1873 rd_config = &pmboxq->u.mqe.un.rd_config;
1874 if (mrpi)
1875 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1876 if (arpi)
1877 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1878 phba->sli4_hba.max_cfg_param.rpi_used;
1879 if (mxri)
1880 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1881 if (axri)
1882 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1883 phba->sli4_hba.max_cfg_param.xri_used;
1884
1885
1886
1887
1888 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1889 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1890
1891
1892 if (max_vpi > LPFC_MAX_VPI)
1893 max_vpi = LPFC_MAX_VPI;
1894 if (mvpi)
1895 *mvpi = max_vpi;
1896 if (avpi)
1897 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1898 } else {
1899 if (mrpi)
1900 *mrpi = pmb->un.varRdConfig.max_rpi;
1901 if (arpi)
1902 *arpi = pmb->un.varRdConfig.avail_rpi;
1903 if (mxri)
1904 *mxri = pmb->un.varRdConfig.max_xri;
1905 if (axri)
1906 *axri = pmb->un.varRdConfig.avail_xri;
1907 if (mvpi)
1908 *mvpi = pmb->un.varRdConfig.max_vpi;
1909 if (avpi) {
1910
1911 if (phba->link_state == LPFC_HBA_READY)
1912 *avpi = pmb->un.varRdConfig.avail_vpi;
1913 else
1914 *avpi = pmb->un.varRdConfig.max_vpi;
1915 }
1916 }
1917
1918 mempool_free(pmboxq, phba->mbox_mem_pool);
1919 return 1;
1920}
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936static ssize_t
1937lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1938 char *buf)
1939{
1940 struct Scsi_Host *shost = class_to_shost(dev);
1941 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1942 struct lpfc_hba *phba = vport->phba;
1943 uint32_t cnt;
1944
1945 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1946 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
1947 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1948}
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964static ssize_t
1965lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1966 char *buf)
1967{
1968 struct Scsi_Host *shost = class_to_shost(dev);
1969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1970 struct lpfc_hba *phba = vport->phba;
1971 uint32_t cnt, acnt;
1972
1973 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1974 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1975 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
1976}
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992static ssize_t
1993lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1994 char *buf)
1995{
1996 struct Scsi_Host *shost = class_to_shost(dev);
1997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1998 struct lpfc_hba *phba = vport->phba;
1999 uint32_t cnt;
2000
2001 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
2002 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2003 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2004}
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020static ssize_t
2021lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
2022 char *buf)
2023{
2024 struct Scsi_Host *shost = class_to_shost(dev);
2025 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2026 struct lpfc_hba *phba = vport->phba;
2027 uint32_t cnt, acnt;
2028
2029 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
2030 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2031 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2032}
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048static ssize_t
2049lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
2050 char *buf)
2051{
2052 struct Scsi_Host *shost = class_to_shost(dev);
2053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2054 struct lpfc_hba *phba = vport->phba;
2055 uint32_t cnt;
2056
2057 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
2058 return scnprintf(buf, PAGE_SIZE, "%d\n", cnt);
2059 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2060}
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076static ssize_t
2077lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
2078 char *buf)
2079{
2080 struct Scsi_Host *shost = class_to_shost(dev);
2081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2082 struct lpfc_hba *phba = vport->phba;
2083 uint32_t cnt, acnt;
2084
2085 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
2086 return scnprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
2087 return scnprintf(buf, PAGE_SIZE, "Unknown\n");
2088}
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103static ssize_t
2104lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
2105 char *buf)
2106{
2107 struct Scsi_Host *shost = class_to_shost(dev);
2108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2109 struct lpfc_hba *phba = vport->phba;
2110
2111 if (!(phba->max_vpi))
2112 return scnprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
2113 if (vport->port_type == LPFC_PHYSICAL_PORT)
2114 return scnprintf(buf, PAGE_SIZE, "NPIV Physical\n");
2115 return scnprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
2116}
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129static ssize_t
2130lpfc_poll_show(struct device *dev, struct device_attribute *attr,
2131 char *buf)
2132{
2133 struct Scsi_Host *shost = class_to_shost(dev);
2134 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2135 struct lpfc_hba *phba = vport->phba;
2136
2137 return scnprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
2138}
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154static ssize_t
2155lpfc_poll_store(struct device *dev, struct device_attribute *attr,
2156 const char *buf, size_t count)
2157{
2158 struct Scsi_Host *shost = class_to_shost(dev);
2159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2160 struct lpfc_hba *phba = vport->phba;
2161 uint32_t creg_val;
2162 uint32_t old_val;
2163 int val=0;
2164
2165 if (!isdigit(buf[0]))
2166 return -EINVAL;
2167
2168 if (sscanf(buf, "%i", &val) != 1)
2169 return -EINVAL;
2170
2171 if ((val & 0x3) != val)
2172 return -EINVAL;
2173
2174 if (phba->sli_rev == LPFC_SLI_REV4)
2175 val = 0;
2176
2177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2178 "3051 lpfc_poll changed from %d to %d\n",
2179 phba->cfg_poll, val);
2180
2181 spin_lock_irq(&phba->hbalock);
2182
2183 old_val = phba->cfg_poll;
2184
2185 if (val & ENABLE_FCP_RING_POLLING) {
2186 if ((val & DISABLE_FCP_RING_INT) &&
2187 !(old_val & DISABLE_FCP_RING_INT)) {
2188 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2189 spin_unlock_irq(&phba->hbalock);
2190 return -EINVAL;
2191 }
2192 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
2193 writel(creg_val, phba->HCregaddr);
2194 readl(phba->HCregaddr);
2195
2196 lpfc_poll_start_timer(phba);
2197 }
2198 } else if (val != 0x0) {
2199 spin_unlock_irq(&phba->hbalock);
2200 return -EINVAL;
2201 }
2202
2203 if (!(val & DISABLE_FCP_RING_INT) &&
2204 (old_val & DISABLE_FCP_RING_INT))
2205 {
2206 spin_unlock_irq(&phba->hbalock);
2207 del_timer(&phba->fcp_poll_timer);
2208 spin_lock_irq(&phba->hbalock);
2209 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
2210 spin_unlock_irq(&phba->hbalock);
2211 return -EINVAL;
2212 }
2213 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
2214 writel(creg_val, phba->HCregaddr);
2215 readl(phba->HCregaddr);
2216 }
2217
2218 phba->cfg_poll = val;
2219
2220 spin_unlock_irq(&phba->hbalock);
2221
2222 return strlen(buf);
2223}
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237static ssize_t
2238lpfc_sriov_hw_max_virtfn_show(struct device *dev,
2239 struct device_attribute *attr,
2240 char *buf)
2241{
2242 struct Scsi_Host *shost = class_to_shost(dev);
2243 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2244 struct lpfc_hba *phba = vport->phba;
2245 uint16_t max_nr_virtfn;
2246
2247 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
2248 return scnprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
2249}
2250
2251static inline bool lpfc_rangecheck(uint val, uint min, uint max)
2252{
2253 return val >= min && val <= max;
2254}
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270static ssize_t
2271lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
2272{
2273 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
2274 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2275 "3068 lpfc_enable_bbcr changed from %d to "
2276 "%d\n", phba->cfg_enable_bbcr, val);
2277 phba->cfg_enable_bbcr = val;
2278 return 0;
2279 }
2280 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2281 "0451 lpfc_enable_bbcr cannot set to %d, range is 0, "
2282 "1\n", val);
2283 return -EINVAL;
2284}
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300#define lpfc_param_show(attr) \
2301static ssize_t \
2302lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2303 char *buf) \
2304{ \
2305 struct Scsi_Host *shost = class_to_shost(dev);\
2306 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2307 struct lpfc_hba *phba = vport->phba;\
2308 return scnprintf(buf, PAGE_SIZE, "%d\n",\
2309 phba->cfg_##attr);\
2310}
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326#define lpfc_param_hex_show(attr) \
2327static ssize_t \
2328lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2329 char *buf) \
2330{ \
2331 struct Scsi_Host *shost = class_to_shost(dev);\
2332 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2333 struct lpfc_hba *phba = vport->phba;\
2334 uint val = 0;\
2335 val = phba->cfg_##attr;\
2336 return scnprintf(buf, PAGE_SIZE, "%#x\n",\
2337 phba->cfg_##attr);\
2338}
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359#define lpfc_param_init(attr, default, minval, maxval) \
2360static int \
2361lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
2362{ \
2363 if (lpfc_rangecheck(val, minval, maxval)) {\
2364 phba->cfg_##attr = val;\
2365 return 0;\
2366 }\
2367 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2368 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2369 "allowed range is ["#minval", "#maxval"]\n", val); \
2370 phba->cfg_##attr = default;\
2371 return -EINVAL;\
2372}
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394#define lpfc_param_set(attr, default, minval, maxval) \
2395static int \
2396lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2397{ \
2398 if (lpfc_rangecheck(val, minval, maxval)) {\
2399 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2400 "3052 lpfc_" #attr " changed from %d to %d\n", \
2401 phba->cfg_##attr, val); \
2402 phba->cfg_##attr = val;\
2403 return 0;\
2404 }\
2405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2406 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2407 "allowed range is ["#minval", "#maxval"]\n", val); \
2408 return -EINVAL;\
2409}
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432#define lpfc_param_store(attr) \
2433static ssize_t \
2434lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2435 const char *buf, size_t count) \
2436{ \
2437 struct Scsi_Host *shost = class_to_shost(dev);\
2438 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2439 struct lpfc_hba *phba = vport->phba;\
2440 uint val = 0;\
2441 if (!isdigit(buf[0]))\
2442 return -EINVAL;\
2443 if (sscanf(buf, "%i", &val) != 1)\
2444 return -EINVAL;\
2445 if (lpfc_##attr##_set(phba, val) == 0) \
2446 return strlen(buf);\
2447 else \
2448 return -EINVAL;\
2449}
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465#define lpfc_vport_param_show(attr) \
2466static ssize_t \
2467lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2468 char *buf) \
2469{ \
2470 struct Scsi_Host *shost = class_to_shost(dev);\
2471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2472 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2473}
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490#define lpfc_vport_param_hex_show(attr) \
2491static ssize_t \
2492lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2493 char *buf) \
2494{ \
2495 struct Scsi_Host *shost = class_to_shost(dev);\
2496 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2497 return scnprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2498}
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518#define lpfc_vport_param_init(attr, default, minval, maxval) \
2519static int \
2520lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2521{ \
2522 if (lpfc_rangecheck(val, minval, maxval)) {\
2523 vport->cfg_##attr = val;\
2524 return 0;\
2525 }\
2526 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2527 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2528 "allowed range is ["#minval", "#maxval"]\n", val); \
2529 vport->cfg_##attr = default;\
2530 return -EINVAL;\
2531}
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550#define lpfc_vport_param_set(attr, default, minval, maxval) \
2551static int \
2552lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2553{ \
2554 if (lpfc_rangecheck(val, minval, maxval)) {\
2555 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2556 "3053 lpfc_" #attr \
2557 " changed from %d (x%x) to %d (x%x)\n", \
2558 vport->cfg_##attr, vport->cfg_##attr, \
2559 val, val); \
2560 vport->cfg_##attr = val;\
2561 return 0;\
2562 }\
2563 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2564 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2565 "allowed range is ["#minval", "#maxval"]\n", val); \
2566 return -EINVAL;\
2567}
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586#define lpfc_vport_param_store(attr) \
2587static ssize_t \
2588lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2589 const char *buf, size_t count) \
2590{ \
2591 struct Scsi_Host *shost = class_to_shost(dev);\
2592 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2593 uint val = 0;\
2594 if (!isdigit(buf[0]))\
2595 return -EINVAL;\
2596 if (sscanf(buf, "%i", &val) != 1)\
2597 return -EINVAL;\
2598 if (lpfc_##attr##_set(vport, val) == 0) \
2599 return strlen(buf);\
2600 else \
2601 return -EINVAL;\
2602}
2603
2604
2605static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2606static DEVICE_ATTR(scsi_stat, 0444, lpfc_scsi_stat_show, NULL);
2607static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2608static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2609static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2610static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2611static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2612static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2613static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2614static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2615static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2616static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2617static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2618static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2619static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2620 lpfc_link_state_store);
2621static DEVICE_ATTR(option_rom_version, S_IRUGO,
2622 lpfc_option_rom_version_show, NULL);
2623static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2624 lpfc_num_discovered_ports_show, NULL);
2625static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2626static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2627static DEVICE_ATTR_RO(lpfc_drvr_version);
2628static DEVICE_ATTR_RO(lpfc_enable_fip);
2629static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2630 lpfc_board_mode_show, lpfc_board_mode_store);
2631static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2632static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2633static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2634static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2635static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2636static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2637static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2638static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2639static DEVICE_ATTR_RO(lpfc_temp_sensor);
2640static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
2641static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2642static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2643 NULL);
2644
2645static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2646#define WWN_SZ 8
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657static size_t
2658lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2659{
2660 unsigned int i, j;
2661
2662
2663 if (buf[cnt-1] == '\n')
2664 cnt--;
2665
2666 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2667 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2668 return -EINVAL;
2669
2670 memset(wwn, 0, WWN_SZ);
2671
2672
2673 for (i = 0, j = 0; i < 16; i++) {
2674 if ((*buf >= 'a') && (*buf <= 'f'))
2675 j = ((j << 4) | ((*buf++ - 'a') + 10));
2676 else if ((*buf >= 'A') && (*buf <= 'F'))
2677 j = ((j << 4) | ((*buf++ - 'A') + 10));
2678 else if ((*buf >= '0') && (*buf <= '9'))
2679 j = ((j << 4) | (*buf++ - '0'));
2680 else
2681 return -EINVAL;
2682 if (i % 2) {
2683 wwn[i/2] = j & 0xff;
2684 j = 0;
2685 }
2686 }
2687 return 0;
2688}
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700static ssize_t
2701lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2702 const char *buf, size_t count)
2703{
2704 struct Scsi_Host *shost = class_to_shost(dev);
2705 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2706 struct lpfc_hba *phba = vport->phba;
2707 unsigned int cnt = count;
2708 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2709 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2724 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2725 "0051 lpfc soft wwpn can not be enabled: "
2726 "fawwpn is enabled\n");
2727 return -EINVAL;
2728 }
2729
2730
2731 if (buf[cnt-1] == '\n')
2732 cnt--;
2733
2734 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2735 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2736 return -EINVAL;
2737
2738 phba->soft_wwn_enable = 1;
2739
2740 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2741 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2742 phba->brd_no);
2743 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2744 " The soft_wwpn feature is not supported by Broadcom.");
2745
2746 return count;
2747}
2748static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758static ssize_t
2759lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2760 char *buf)
2761{
2762 struct Scsi_Host *shost = class_to_shost(dev);
2763 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2764 struct lpfc_hba *phba = vport->phba;
2765
2766 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2767 (unsigned long long)phba->cfg_soft_wwpn);
2768}
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783static ssize_t
2784lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2785 const char *buf, size_t count)
2786{
2787 struct Scsi_Host *shost = class_to_shost(dev);
2788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2789 struct lpfc_hba *phba = vport->phba;
2790 struct completion online_compl;
2791 int stat1 = 0, stat2 = 0;
2792 unsigned int cnt = count;
2793 u8 wwpn[WWN_SZ];
2794 int rc;
2795
2796 if (!phba->cfg_enable_hba_reset)
2797 return -EACCES;
2798 spin_lock_irq(&phba->hbalock);
2799 if (phba->over_temp_state == HBA_OVER_TEMP) {
2800 spin_unlock_irq(&phba->hbalock);
2801 return -EACCES;
2802 }
2803 spin_unlock_irq(&phba->hbalock);
2804
2805 if (buf[cnt-1] == '\n')
2806 cnt--;
2807
2808 if (!phba->soft_wwn_enable)
2809 return -EINVAL;
2810
2811
2812 phba->soft_wwn_enable = 0;
2813
2814 rc = lpfc_wwn_set(buf, cnt, wwpn);
2815 if (rc) {
2816
2817 phba->soft_wwn_enable = 1;
2818 return rc;
2819 }
2820
2821 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2822 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2823 if (phba->cfg_soft_wwnn)
2824 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2825
2826 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2827 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2828
2829 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2830 if (stat1)
2831 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2832 "0463 lpfc_soft_wwpn attribute set failed to "
2833 "reinit adapter - %d\n", stat1);
2834 init_completion(&online_compl);
2835 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2836 LPFC_EVT_ONLINE);
2837 if (rc == 0)
2838 return -ENOMEM;
2839
2840 wait_for_completion(&online_compl);
2841 if (stat2)
2842 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2843 "0464 lpfc_soft_wwpn attribute set failed to "
2844 "reinit adapter - %d\n", stat2);
2845 return (stat1 || stat2) ? -EIO : count;
2846}
2847static DEVICE_ATTR_RW(lpfc_soft_wwpn);
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857static ssize_t
2858lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2859 char *buf)
2860{
2861 struct Scsi_Host *shost = class_to_shost(dev);
2862 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2863 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2864 (unsigned long long)phba->cfg_soft_wwnn);
2865}
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878static ssize_t
2879lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2880 const char *buf, size_t count)
2881{
2882 struct Scsi_Host *shost = class_to_shost(dev);
2883 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2884 unsigned int cnt = count;
2885 u8 wwnn[WWN_SZ];
2886 int rc;
2887
2888
2889 if (buf[cnt-1] == '\n')
2890 cnt--;
2891
2892 if (!phba->soft_wwn_enable)
2893 return -EINVAL;
2894
2895 rc = lpfc_wwn_set(buf, cnt, wwnn);
2896 if (rc) {
2897
2898
2899
2900 return rc;
2901 }
2902
2903 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2904
2905 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2906 "lpfc%d: soft_wwnn set. Value will take effect upon "
2907 "setting of the soft_wwpn\n", phba->brd_no);
2908
2909 return count;
2910}
2911static DEVICE_ATTR_RW(lpfc_soft_wwnn);
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923static ssize_t
2924lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2925 char *buf)
2926{
2927 struct Scsi_Host *shost = class_to_shost(dev);
2928 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2929
2930 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
2931 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2932}
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947static ssize_t
2948lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2949 const char *buf, size_t count)
2950{
2951 struct Scsi_Host *shost = class_to_shost(dev);
2952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2953 unsigned int cnt = count;
2954 uint8_t wwpn[WWN_SZ];
2955 int rc;
2956
2957 if (!phba->cfg_fof)
2958 return -EPERM;
2959
2960
2961 if (buf[cnt-1] == '\n')
2962 cnt--;
2963
2964 rc = lpfc_wwn_set(buf, cnt, wwpn);
2965 if (rc)
2966 return rc;
2967
2968 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2969 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2970 if (wwn_to_u64(wwpn) == 0)
2971 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2972 else
2973 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2974 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2975 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2976 return count;
2977}
2978static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2979 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991static ssize_t
2992lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2993 char *buf)
2994{
2995 struct Scsi_Host *shost = class_to_shost(dev);
2996 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2997
2998 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2999}
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014static ssize_t
3015lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
3016 const char *buf, size_t count)
3017{
3018 struct Scsi_Host *shost = class_to_shost(dev);
3019 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3020 unsigned int cnt = count;
3021 unsigned long val;
3022 int ret;
3023
3024 if (!phba->cfg_fof)
3025 return -EPERM;
3026
3027
3028 if (buf[cnt-1] == '\n')
3029 cnt--;
3030
3031 ret = kstrtoul(buf, 0, &val);
3032 if (ret || (val > 0x7f))
3033 return -EINVAL;
3034
3035 if (val)
3036 phba->cfg_oas_priority = (uint8_t)val;
3037 else
3038 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3039 return count;
3040}
3041static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
3042 lpfc_oas_priority_show, lpfc_oas_priority_store);
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054static ssize_t
3055lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
3056 char *buf)
3057{
3058 struct Scsi_Host *shost = class_to_shost(dev);
3059 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3060
3061 return scnprintf(buf, PAGE_SIZE, "0x%llx\n",
3062 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
3063}
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078static ssize_t
3079lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
3080 const char *buf, size_t count)
3081{
3082 struct Scsi_Host *shost = class_to_shost(dev);
3083 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3084 unsigned int cnt = count;
3085 uint8_t wwpn[WWN_SZ];
3086 int rc;
3087
3088 if (!phba->cfg_fof)
3089 return -EPERM;
3090
3091
3092 if (buf[cnt-1] == '\n')
3093 cnt--;
3094
3095 rc = lpfc_wwn_set(buf, cnt, wwpn);
3096 if (rc)
3097 return rc;
3098
3099 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3100 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
3101 if (wwn_to_u64(wwpn) == 0)
3102 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
3103 else
3104 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
3105 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
3106 if (phba->cfg_oas_priority == 0)
3107 phba->cfg_oas_priority = phba->cfg_XLanePriority;
3108 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
3109 return count;
3110}
3111static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
3112 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125static ssize_t
3126lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
3127 char *buf)
3128{
3129 struct Scsi_Host *shost = class_to_shost(dev);
3130 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3131
3132 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
3133}
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149static ssize_t
3150lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
3151 const char *buf, size_t count)
3152{
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3155 int val = 0;
3156
3157 if (!phba->cfg_fof)
3158 return -EPERM;
3159
3160 if (!isdigit(buf[0]))
3161 return -EINVAL;
3162
3163 if (sscanf(buf, "%i", &val) != 1)
3164 return -EINVAL;
3165
3166 if ((val != 0) && (val != 1))
3167 return -EINVAL;
3168
3169 phba->cfg_oas_lun_state = val;
3170 return strlen(buf);
3171}
3172static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
3173 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186static ssize_t
3187lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
3188 char *buf)
3189{
3190 struct Scsi_Host *shost = class_to_shost(dev);
3191 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3192
3193 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
3194 return -EFAULT;
3195
3196 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
3197}
3198static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
3199 lpfc_oas_lun_status_show, NULL);
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217static size_t
3218lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3219 uint8_t tgt_wwpn[], uint64_t lun,
3220 uint32_t oas_state, uint8_t pri)
3221{
3222
3223 int rc = 0;
3224
3225 if (!phba->cfg_fof)
3226 return -EPERM;
3227
3228 if (oas_state) {
3229 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3230 (struct lpfc_name *)tgt_wwpn,
3231 lun, pri))
3232 rc = -ENOMEM;
3233 } else {
3234 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
3235 (struct lpfc_name *)tgt_wwpn, lun, pri);
3236 }
3237 return rc;
3238
3239}
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258static uint64_t
3259lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3260 uint8_t tgt_wwpn[], uint32_t *lun_status,
3261 uint32_t *lun_pri)
3262{
3263 uint64_t found_lun;
3264
3265 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
3266 return NOT_OAS_ENABLED_LUN;
3267 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
3268 phba->sli4_hba.oas_next_vpt_wwpn,
3269 (struct lpfc_name *)
3270 phba->sli4_hba.oas_next_tgt_wwpn,
3271 &phba->sli4_hba.oas_next_lun,
3272 (struct lpfc_name *)vpt_wwpn,
3273 (struct lpfc_name *)tgt_wwpn,
3274 &found_lun, lun_status, lun_pri))
3275 return found_lun;
3276 else
3277 return NOT_OAS_ENABLED_LUN;
3278}
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297static ssize_t
3298lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
3299 uint8_t tgt_wwpn[], uint64_t lun,
3300 uint32_t oas_state, uint8_t pri)
3301{
3302
3303 int rc;
3304
3305 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
3306 oas_state, pri);
3307 return rc;
3308}
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324static ssize_t
3325lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3326 char *buf)
3327{
3328 struct Scsi_Host *shost = class_to_shost(dev);
3329 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3330
3331 uint64_t oas_lun;
3332 int len = 0;
3333
3334 if (!phba->cfg_fof)
3335 return -EPERM;
3336
3337 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3338 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3339 return -EFAULT;
3340
3341 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3342 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3343 return -EFAULT;
3344
3345 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3346 phba->cfg_oas_tgt_wwpn,
3347 &phba->cfg_oas_lun_status,
3348 &phba->cfg_oas_priority);
3349 if (oas_lun != NOT_OAS_ENABLED_LUN)
3350 phba->cfg_oas_flags |= OAS_LUN_VALID;
3351
3352 len += scnprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3353
3354 return len;
3355}
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373static ssize_t
3374lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3375 const char *buf, size_t count)
3376{
3377 struct Scsi_Host *shost = class_to_shost(dev);
3378 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3379 uint64_t scsi_lun;
3380 uint32_t pri;
3381 ssize_t rc;
3382
3383 if (!phba->cfg_fof)
3384 return -EPERM;
3385
3386 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3387 return -EFAULT;
3388
3389 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3390 return -EFAULT;
3391
3392 if (!isdigit(buf[0]))
3393 return -EINVAL;
3394
3395 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3396 return -EINVAL;
3397
3398 pri = phba->cfg_oas_priority;
3399 if (pri == 0)
3400 pri = phba->cfg_XLanePriority;
3401
3402 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3403 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3404 "priority 0x%x with oas state %d\n",
3405 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3406 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3407 pri, phba->cfg_oas_lun_state);
3408
3409 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3410 phba->cfg_oas_tgt_wwpn, scsi_lun,
3411 phba->cfg_oas_lun_state, pri);
3412 if (rc)
3413 return rc;
3414
3415 return count;
3416}
3417static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3418 lpfc_oas_lun_show, lpfc_oas_lun_store);
3419
3420int lpfc_enable_nvmet_cnt;
3421unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3422 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3423 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3424module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3425MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3426
3427static int lpfc_poll = 0;
3428module_param(lpfc_poll, int, S_IRUGO);
3429MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3430 " 0 - none,"
3431 " 1 - poll with interrupts enabled"
3432 " 3 - poll and disable FCP ring interrupts");
3433
3434static DEVICE_ATTR_RW(lpfc_poll);
3435
3436int lpfc_no_hba_reset_cnt;
3437unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3438 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3439module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3440MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3441
3442LPFC_ATTR(sli_mode, 3, 3, 3,
3443 "SLI mode selector: 3 - select SLI-3");
3444
3445LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3446 "Enable NPIV functionality");
3447
3448LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3449 "FCF Fast failover=1 Priority failover=2");
3450
3451
3452
3453
3454
3455
3456
3457
3458LPFC_ATTR_R(fcp_wait_abts_rsp, 0, 0, 1, "Wait for FCP ABTS completion");
3459
3460
3461
3462
3463
3464
3465
3466LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3467 "Enable RRQ functionality");
3468
3469
3470
3471
3472
3473
3474
3475
3476LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3477 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3478 "Suppress Link Up at initialization");
3479
3480static ssize_t
3481lpfc_pls_show(struct device *dev, struct device_attribute *attr, char *buf)
3482{
3483 struct Scsi_Host *shost = class_to_shost(dev);
3484 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3485
3486 return scnprintf(buf, PAGE_SIZE, "%d\n",
3487 phba->sli4_hba.pc_sli4_params.pls);
3488}
3489static DEVICE_ATTR(pls, 0444,
3490 lpfc_pls_show, NULL);
3491
3492static ssize_t
3493lpfc_pt_show(struct device *dev, struct device_attribute *attr, char *buf)
3494{
3495 struct Scsi_Host *shost = class_to_shost(dev);
3496 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3497
3498 return scnprintf(buf, PAGE_SIZE, "%d\n",
3499 (phba->hba_flag & HBA_PERSISTENT_TOPO) ? 1 : 0);
3500}
3501static DEVICE_ATTR(pt, 0444,
3502 lpfc_pt_show, NULL);
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512static ssize_t
3513lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3514{
3515 struct Scsi_Host *shost = class_to_shost(dev);
3516 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3517
3518 return scnprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3519}
3520
3521static DEVICE_ATTR(iocb_hw, S_IRUGO,
3522 lpfc_iocb_hw_show, NULL);
3523static ssize_t
3524lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3525{
3526 struct Scsi_Host *shost = class_to_shost(dev);
3527 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3528 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3529
3530 return scnprintf(buf, PAGE_SIZE, "%d\n",
3531 pring ? pring->txq_max : 0);
3532}
3533
3534static DEVICE_ATTR(txq_hw, S_IRUGO,
3535 lpfc_txq_hw_show, NULL);
3536static ssize_t
3537lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3538 char *buf)
3539{
3540 struct Scsi_Host *shost = class_to_shost(dev);
3541 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3542 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3543
3544 return scnprintf(buf, PAGE_SIZE, "%d\n",
3545 pring ? pring->txcmplq_max : 0);
3546}
3547
3548static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3549 lpfc_txcmplq_hw_show, NULL);
3550
3551
3552
3553
3554
3555static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3556static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3557module_param(lpfc_nodev_tmo, int, 0);
3558MODULE_PARM_DESC(lpfc_nodev_tmo,
3559 "Seconds driver will hold I/O waiting "
3560 "for a device to come back");
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570static ssize_t
3571lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3572 char *buf)
3573{
3574 struct Scsi_Host *shost = class_to_shost(dev);
3575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3576
3577 return scnprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3578}
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595static int
3596lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3597{
3598 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3599 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3600 if (val != LPFC_DEF_DEVLOSS_TMO)
3601 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3602 "0407 Ignoring lpfc_nodev_tmo module "
3603 "parameter because lpfc_devloss_tmo "
3604 "is set.\n");
3605 return 0;
3606 }
3607
3608 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3609 vport->cfg_nodev_tmo = val;
3610 vport->cfg_devloss_tmo = val;
3611 return 0;
3612 }
3613 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3614 "0400 lpfc_nodev_tmo attribute cannot be set to"
3615 " %d, allowed range is [%d, %d]\n",
3616 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3617 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3618 return -EINVAL;
3619}
3620
3621
3622
3623
3624
3625
3626
3627
3628static void
3629lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3630{
3631 struct Scsi_Host *shost;
3632 struct lpfc_nodelist *ndlp;
3633#if (IS_ENABLED(CONFIG_NVME_FC))
3634 struct lpfc_nvme_rport *rport;
3635 struct nvme_fc_remote_port *remoteport = NULL;
3636#endif
3637
3638 shost = lpfc_shost_from_vport(vport);
3639 spin_lock_irq(shost->host_lock);
3640 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3641 if (ndlp->rport)
3642 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3643#if (IS_ENABLED(CONFIG_NVME_FC))
3644 spin_lock(&ndlp->lock);
3645 rport = lpfc_ndlp_get_nrport(ndlp);
3646 if (rport)
3647 remoteport = rport->remoteport;
3648 spin_unlock(&ndlp->lock);
3649 if (rport && remoteport)
3650 nvme_fc_set_remoteport_devloss(remoteport,
3651 vport->cfg_devloss_tmo);
3652#endif
3653 }
3654 spin_unlock_irq(shost->host_lock);
3655}
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672static int
3673lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3674{
3675 if (vport->dev_loss_tmo_changed ||
3676 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3677 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3678 "0401 Ignoring change to lpfc_nodev_tmo "
3679 "because lpfc_devloss_tmo is set.\n");
3680 return 0;
3681 }
3682 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3683 vport->cfg_nodev_tmo = val;
3684 vport->cfg_devloss_tmo = val;
3685
3686
3687
3688
3689 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3690 lpfc_update_rport_devloss_tmo(vport);
3691 return 0;
3692 }
3693 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3694 "0403 lpfc_nodev_tmo attribute cannot be set to "
3695 "%d, allowed range is [%d, %d]\n",
3696 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3697 return -EINVAL;
3698}
3699
3700lpfc_vport_param_store(nodev_tmo)
3701
3702static DEVICE_ATTR_RW(lpfc_nodev_tmo);
3703
3704
3705
3706
3707
3708
3709module_param(lpfc_devloss_tmo, int, S_IRUGO);
3710MODULE_PARM_DESC(lpfc_devloss_tmo,
3711 "Seconds driver will hold I/O waiting "
3712 "for a device to come back");
3713lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3714 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3715lpfc_vport_param_show(devloss_tmo)
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731static int
3732lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3733{
3734 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3735 vport->cfg_nodev_tmo = val;
3736 vport->cfg_devloss_tmo = val;
3737 vport->dev_loss_tmo_changed = 1;
3738 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3739 lpfc_update_rport_devloss_tmo(vport);
3740 return 0;
3741 }
3742
3743 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3744 "0404 lpfc_devloss_tmo attribute cannot be set to "
3745 "%d, allowed range is [%d, %d]\n",
3746 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3747 return -EINVAL;
3748}
3749
3750lpfc_vport_param_store(devloss_tmo)
3751static DEVICE_ATTR_RW(lpfc_devloss_tmo);
3752
3753
3754
3755
3756
3757
3758
3759LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3760 "Enable suppress rsp feature is firmware supports it");
3761
3762
3763
3764
3765
3766
3767
3768
3769LPFC_ATTR_R(nvmet_mrq,
3770 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
3771 "Specify number of RQ pairs for processing NVMET cmds");
3772
3773
3774
3775
3776
3777LPFC_ATTR_R(nvmet_mrq_post,
3778 LPFC_NVMET_RQE_DEF_POST, LPFC_NVMET_RQE_MIN_POST,
3779 LPFC_NVMET_RQE_DEF_COUNT,
3780 "Specify number of RQ buffers to initially post");
3781
3782
3783
3784
3785
3786
3787
3788LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3789 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3790 "Enable FC4 Protocol support - FCP / NVME");
3791
3792
3793
3794
3795
3796
3797
3798LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3799 "Verbose logging bit-mask");
3800
3801
3802
3803
3804
3805LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3806 "Deregister nameserver objects before LOGO");
3807
3808
3809
3810
3811
3812LPFC_VPORT_ATTR_R(lun_queue_depth, 64, 1, 512,
3813 "Max number of FCP commands we can queue to a specific LUN");
3814
3815
3816
3817
3818
3819static uint lpfc_tgt_queue_depth = LPFC_MAX_TGT_QDEPTH;
3820module_param(lpfc_tgt_queue_depth, uint, 0444);
3821MODULE_PARM_DESC(lpfc_tgt_queue_depth, "Set max Target queue depth");
3822lpfc_vport_param_show(tgt_queue_depth);
3823lpfc_vport_param_init(tgt_queue_depth, LPFC_MAX_TGT_QDEPTH,
3824 LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH);
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837static int
3838lpfc_tgt_queue_depth_set(struct lpfc_vport *vport, uint val)
3839{
3840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3841 struct lpfc_nodelist *ndlp;
3842
3843 if (!lpfc_rangecheck(val, LPFC_MIN_TGT_QDEPTH, LPFC_MAX_TGT_QDEPTH))
3844 return -EINVAL;
3845
3846 if (val == vport->cfg_tgt_queue_depth)
3847 return 0;
3848
3849 spin_lock_irq(shost->host_lock);
3850 vport->cfg_tgt_queue_depth = val;
3851
3852
3853 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
3854 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3855
3856 spin_unlock_irq(shost->host_lock);
3857 return 0;
3858}
3859
3860lpfc_vport_param_store(tgt_queue_depth);
3861static DEVICE_ATTR_RW(lpfc_tgt_queue_depth);
3862
3863
3864
3865
3866
3867
3868
3869
3870LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3871 "Max number of FCP commands we can queue to a lpfc HBA");
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3883 "Allow peer ports on the same physical port to login to each "
3884 "other.");
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897static int lpfc_restrict_login = 1;
3898module_param(lpfc_restrict_login, int, S_IRUGO);
3899MODULE_PARM_DESC(lpfc_restrict_login,
3900 "Restrict virtual ports login to remote initiators.");
3901lpfc_vport_param_show(restrict_login);
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918static int
3919lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3920{
3921 if (val < 0 || val > 1) {
3922 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3923 "0422 lpfc_restrict_login attribute cannot "
3924 "be set to %d, allowed range is [0, 1]\n",
3925 val);
3926 vport->cfg_restrict_login = 1;
3927 return -EINVAL;
3928 }
3929 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3930 vport->cfg_restrict_login = 0;
3931 return 0;
3932 }
3933 vport->cfg_restrict_login = val;
3934 return 0;
3935}
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953static int
3954lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3955{
3956 if (val < 0 || val > 1) {
3957 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3958 "0425 lpfc_restrict_login attribute cannot "
3959 "be set to %d, allowed range is [0, 1]\n",
3960 val);
3961 vport->cfg_restrict_login = 1;
3962 return -EINVAL;
3963 }
3964 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3965 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3966 "0468 lpfc_restrict_login must be 0 for "
3967 "Physical ports.\n");
3968 vport->cfg_restrict_login = 0;
3969 return 0;
3970 }
3971 vport->cfg_restrict_login = val;
3972 return 0;
3973}
3974lpfc_vport_param_store(restrict_login);
3975static DEVICE_ATTR_RW(lpfc_restrict_login);
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3995 "Start scanning for devices from highest ALPA to lowest");
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008LPFC_ATTR(topology, 0, 0, 6,
4009 "Select Fibre Channel topology");
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029static ssize_t
4030lpfc_topology_store(struct device *dev, struct device_attribute *attr,
4031 const char *buf, size_t count)
4032{
4033 struct Scsi_Host *shost = class_to_shost(dev);
4034 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4035 struct lpfc_hba *phba = vport->phba;
4036 int val = 0;
4037 int nolip = 0;
4038 const char *val_buf = buf;
4039 int err;
4040 uint32_t prev_val;
4041
4042 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4043 nolip = 1;
4044 val_buf = &buf[strlen("nolip ")];
4045 }
4046
4047 if (!isdigit(val_buf[0]))
4048 return -EINVAL;
4049 if (sscanf(val_buf, "%i", &val) != 1)
4050 return -EINVAL;
4051
4052 if (val >= 0 && val <= 6) {
4053 prev_val = phba->cfg_topology;
4054 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
4055 val == 4) {
4056 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4057 "3113 Loop mode not supported at speed %d\n",
4058 val);
4059 return -EINVAL;
4060 }
4061
4062
4063
4064
4065
4066
4067 if ((phba->hba_flag & HBA_PERSISTENT_TOPO ||
4068 (!phba->sli4_hba.pc_sli4_params.pls &&
4069 (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
4070 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC))) &&
4071 val == 4) {
4072 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4073 "3114 Loop mode not supported\n");
4074 return -EINVAL;
4075 }
4076 phba->cfg_topology = val;
4077 if (nolip)
4078 return strlen(buf);
4079
4080 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4081 "3054 lpfc_topology changed from %d to %d\n",
4082 prev_val, val);
4083 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
4084 phba->fc_topology_changed = 1;
4085 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4086 if (err) {
4087 phba->cfg_topology = prev_val;
4088 return -EINVAL;
4089 } else
4090 return strlen(buf);
4091 }
4092 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4093 "%d:0467 lpfc_topology attribute cannot be set to %d, "
4094 "allowed range is [0, 6]\n",
4095 phba->brd_no, val);
4096 return -EINVAL;
4097}
4098
4099lpfc_param_show(topology)
4100static DEVICE_ATTR_RW(lpfc_topology);
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113static ssize_t
4114lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
4115 char *buf)
4116{
4117 struct Scsi_Host *shost = class_to_shost(dev);
4118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4119 if (vport->vport_flag & STATIC_VPORT)
4120 sprintf(buf, "1\n");
4121 else
4122 sprintf(buf, "0\n");
4123
4124 return strlen(buf);
4125}
4126
4127
4128
4129
4130static DEVICE_ATTR_RO(lpfc_static_vport);
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152static ssize_t
4153lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
4154 const char *buf, size_t count)
4155{
4156 struct Scsi_Host *shost = class_to_shost(dev);
4157 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4158 struct lpfc_hba *phba = vport->phba;
4159#define LPFC_MAX_DATA_CTRL_LEN 1024
4160 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
4161 unsigned long i;
4162 char *str_ptr, *token;
4163 struct lpfc_vport **vports;
4164 struct Scsi_Host *v_shost;
4165 char *bucket_type_str, *base_str, *step_str;
4166 unsigned long base, step, bucket_type;
4167
4168 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
4169 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
4170 return -EINVAL;
4171
4172 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
4173 str_ptr = &bucket_data[0];
4174
4175 token = strsep(&str_ptr, "\t ");
4176 if (!token)
4177 return -EINVAL;
4178
4179 bucket_type_str = strsep(&str_ptr, "\t ");
4180 if (!bucket_type_str)
4181 return -EINVAL;
4182
4183 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
4184 bucket_type = LPFC_LINEAR_BUCKET;
4185 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
4186 bucket_type = LPFC_POWER2_BUCKET;
4187 else
4188 return -EINVAL;
4189
4190 base_str = strsep(&str_ptr, "\t ");
4191 if (!base_str)
4192 return -EINVAL;
4193 base = simple_strtoul(base_str, NULL, 0);
4194
4195 step_str = strsep(&str_ptr, "\t ");
4196 if (!step_str)
4197 return -EINVAL;
4198 step = simple_strtoul(step_str, NULL, 0);
4199 if (!step)
4200 return -EINVAL;
4201
4202
4203 vports = lpfc_create_vport_work_array(phba);
4204 if (vports == NULL)
4205 return -ENOMEM;
4206
4207 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4208 v_shost = lpfc_shost_from_vport(vports[i]);
4209 spin_lock_irq(v_shost->host_lock);
4210
4211 vports[i]->stat_data_blocked = 1;
4212 if (vports[i]->stat_data_enabled)
4213 lpfc_vport_reset_stat_data(vports[i]);
4214 spin_unlock_irq(v_shost->host_lock);
4215 }
4216
4217
4218 phba->bucket_type = bucket_type;
4219 phba->bucket_base = base;
4220 phba->bucket_step = step;
4221
4222 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4223 v_shost = lpfc_shost_from_vport(vports[i]);
4224
4225
4226 spin_lock_irq(v_shost->host_lock);
4227 vports[i]->stat_data_blocked = 0;
4228 spin_unlock_irq(v_shost->host_lock);
4229 }
4230 lpfc_destroy_vport_work_array(phba, vports);
4231 return strlen(buf);
4232 }
4233
4234 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
4235 vports = lpfc_create_vport_work_array(phba);
4236 if (vports == NULL)
4237 return -ENOMEM;
4238
4239 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4240 v_shost = lpfc_shost_from_vport(vports[i]);
4241 spin_lock_irq(shost->host_lock);
4242 vports[i]->stat_data_blocked = 1;
4243 lpfc_free_bucket(vport);
4244 vport->stat_data_enabled = 0;
4245 vports[i]->stat_data_blocked = 0;
4246 spin_unlock_irq(shost->host_lock);
4247 }
4248 lpfc_destroy_vport_work_array(phba, vports);
4249 phba->bucket_type = LPFC_NO_BUCKET;
4250 phba->bucket_base = 0;
4251 phba->bucket_step = 0;
4252 return strlen(buf);
4253 }
4254
4255 if (!strncmp(buf, "start", strlen("start"))) {
4256
4257 if (phba->bucket_type == LPFC_NO_BUCKET)
4258 return -EINVAL;
4259 spin_lock_irq(shost->host_lock);
4260 if (vport->stat_data_enabled) {
4261 spin_unlock_irq(shost->host_lock);
4262 return strlen(buf);
4263 }
4264 lpfc_alloc_bucket(vport);
4265 vport->stat_data_enabled = 1;
4266 spin_unlock_irq(shost->host_lock);
4267 return strlen(buf);
4268 }
4269
4270 if (!strncmp(buf, "stop", strlen("stop"))) {
4271 spin_lock_irq(shost->host_lock);
4272 if (vport->stat_data_enabled == 0) {
4273 spin_unlock_irq(shost->host_lock);
4274 return strlen(buf);
4275 }
4276 lpfc_free_bucket(vport);
4277 vport->stat_data_enabled = 0;
4278 spin_unlock_irq(shost->host_lock);
4279 return strlen(buf);
4280 }
4281
4282 if (!strncmp(buf, "reset", strlen("reset"))) {
4283 if ((phba->bucket_type == LPFC_NO_BUCKET)
4284 || !vport->stat_data_enabled)
4285 return strlen(buf);
4286 spin_lock_irq(shost->host_lock);
4287 vport->stat_data_blocked = 1;
4288 lpfc_vport_reset_stat_data(vport);
4289 vport->stat_data_blocked = 0;
4290 spin_unlock_irq(shost->host_lock);
4291 return strlen(buf);
4292 }
4293 return -EINVAL;
4294}
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307static ssize_t
4308lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
4309 char *buf)
4310{
4311 struct Scsi_Host *shost = class_to_shost(dev);
4312 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4313 struct lpfc_hba *phba = vport->phba;
4314 int index = 0;
4315 int i;
4316 char *bucket_type;
4317 unsigned long bucket_value;
4318
4319 switch (phba->bucket_type) {
4320 case LPFC_LINEAR_BUCKET:
4321 bucket_type = "linear";
4322 break;
4323 case LPFC_POWER2_BUCKET:
4324 bucket_type = "power2";
4325 break;
4326 default:
4327 bucket_type = "No Bucket";
4328 break;
4329 }
4330
4331 sprintf(&buf[index], "Statistical Data enabled :%d, "
4332 "blocked :%d, Bucket type :%s, Bucket base :%d,"
4333 " Bucket step :%d\nLatency Ranges :",
4334 vport->stat_data_enabled, vport->stat_data_blocked,
4335 bucket_type, phba->bucket_base, phba->bucket_step);
4336 index = strlen(buf);
4337 if (phba->bucket_type != LPFC_NO_BUCKET) {
4338 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4339 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
4340 bucket_value = phba->bucket_base +
4341 phba->bucket_step * i;
4342 else
4343 bucket_value = phba->bucket_base +
4344 (1 << i) * phba->bucket_step;
4345
4346 if (index + 10 > PAGE_SIZE)
4347 break;
4348 sprintf(&buf[index], "%08ld ", bucket_value);
4349 index = strlen(buf);
4350 }
4351 }
4352 sprintf(&buf[index], "\n");
4353