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