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