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