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