blob: c63a028385ab70fef1c981aaa46875d3ef511244 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * 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. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040025#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050026#include <linux/pci.h>
27#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040028#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040029#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070031#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050032
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050034#include <scsi/scsi_device.h>
35#include <scsi/scsi_host.h>
36#include <scsi/scsi_tcq.h>
37#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040038#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050039
James Smart895427b2017-02-12 13:52:30 -080040#include <linux/nvme-fc-driver.h>
41
James Smartda0436e2009-05-22 14:51:39 -040042#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050043#include "lpfc_hw.h"
44#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040045#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040046#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050047#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050048#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080049#include "lpfc_scsi.h"
50#include "lpfc_nvme.h"
James Smartf358dd02017-02-12 13:52:34 -080051#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050052#include "lpfc_logmsg.h"
53#include "lpfc_version.h"
54#include "lpfc_compat.h"
55#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050056#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070057#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050058
James Smart2ea259e2017-02-12 13:52:27 -080059#define LPFC_DEF_DEVLOSS_TMO 30
60#define LPFC_MIN_DEVLOSS_TMO 1
61#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050062
James Smart61f3d4b2017-05-15 15:20:41 -070063#define LPFC_DEF_MRQ_POST 512
64#define LPFC_MIN_MRQ_POST 512
65#define LPFC_MAX_MRQ_POST 2048
dea31012005-04-17 16:05:31 -050066
James Smartf7a919b2011-08-21 21:49:16 -040067/*
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
James Smarte59058c2008-08-24 21:49:00 -040074/**
James Smart3621a712009-04-06 18:47:14 -040075 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040076 * @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 **/
dea31012005-04-17 16:05:31 -050089static 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
James Smarte59058c2008-08-24 21:49:00 -0400105/**
James Smart3621a712009-04-06 18:47:14 -0400106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400107 * @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 **/
dea31012005-04-17 16:05:31 -0500113static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100114lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
115 char *buf)
dea31012005-04-17 16:05:31 -0500116{
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
118}
119
James Smart45ed1192009-10-02 15:17:02 -0400120/**
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
125 *
126 * Returns: size of formatted string.
127 **/
128static ssize_t
129lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
130 char *buf)
131{
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
135
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
138 else
139 return snprintf(buf, PAGE_SIZE, "0\n");
140}
141
James Smart81301a92008-12-04 22:39:46 -0500142static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800143lpfc_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;
James Smartf358dd02017-02-12 13:52:34 -0800149 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800150 struct nvme_fc_local_port *localport;
James Smart4b056682017-12-08 17:18:10 -0800151 struct lpfc_nvme_lport *lport;
James Smart80cc0042017-06-01 21:06:56 -0700152 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800153 struct nvme_fc_remote_port *nrport;
James Smart2cee7802017-06-01 21:07:02 -0700154 uint64_t data1, data2, data3, tot;
James Smart895427b2017-02-12 13:52:30 -0800155 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 }
James Smartf358dd02017-02-12 13:52:34 -0800162 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,
James Smartb4fd6812017-06-15 22:56:42 -0700175 "NVME Target Enabled State %s\n",
James Smartf358dd02017-02-12 13:52:34 -0800176 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
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200185 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartf358dd02017-02-12 13:52:34 -0800186 "\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,
James Smart4b056682017-12-08 17:18:10 -0800202 "LS: Xmt %08x Drop %08x Cmpl %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800203 atomic_read(&tgtp->xmt_ls_rsp),
204 atomic_read(&tgtp->xmt_ls_drop),
James Smart4b056682017-12-08 17:18:10 -0800205 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),
James Smartf358dd02017-02-12 13:52:34 -0800211 atomic_read(&tgtp->xmt_ls_rsp_error));
212
213 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart50738422017-08-01 15:12:40 -0700214 "FCP: Rcv %08x Defer %08x Release %08x "
215 "Drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800216 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -0700217 atomic_read(&tgtp->rcv_fcp_cmd_defer),
James Smart547077a2017-05-15 15:20:40 -0700218 atomic_read(&tgtp->xmt_fcp_release),
James Smartf358dd02017-02-12 13:52:34 -0800219 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,
James Smart547077a2017-05-15 15:20:40 -0700230 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
231 "drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800232 atomic_read(&tgtp->xmt_fcp_read),
233 atomic_read(&tgtp->xmt_fcp_read_rsp),
234 atomic_read(&tgtp->xmt_fcp_write),
James Smart547077a2017-05-15 15:20:40 -0700235 atomic_read(&tgtp->xmt_fcp_rsp),
James Smartf358dd02017-02-12 13:52:34 -0800236 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,
James Smart4b056682017-12-08 17:18:10 -0800245 "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,
James Smart547077a2017-05-15 15:20:40 -0700251 "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),
James Smartf358dd02017-02-12 13:52:34 -0800259 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -0700260 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smartf358dd02017-02-12 13:52:34 -0800261
James Smart411de512018-01-30 15:58:52 -0800262 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
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700268 /* 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;
James Smart2cee7802017-06-01 21:07:02 -0700272
James Smarta8cf5df2017-05-15 15:20:46 -0700273 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart2cee7802017-06-01 21:07:02 -0700274 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
275 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -0700276 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -0700277 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -0700278 phba->sli4_hba.nvmet_io_wait_total,
279 tot);
James Smarta8cf5df2017-05-15 15:20:46 -0700280
James Smartf358dd02017-02-12 13:52:34 -0800281 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
282 return len;
283 }
James Smart895427b2017-02-12 13:52:30 -0800284
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 }
Colin Ian King5c665ae2017-12-22 00:28:52 +0000292 lport = (struct lpfc_nvme_lport *)localport->private;
James Smart895427b2017-02-12 13:52:30 -0800293 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
294
295 spin_lock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800296
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
James Smart80cc0042017-06-01 21:06:56 -0700311 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
312 if (!ndlp->nrport)
313 continue;
314
James Smart895427b2017-02-12 13:52:30 -0800315 /* local short-hand pointer. */
James Smart80cc0042017-06-01 21:06:56 -0700316 nrport = ndlp->nrport->remoteport;
James Smart895427b2017-02-12 13:52:30 -0800317
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
James Smart7d790f02017-06-01 21:06:57 -0700344 /* An NVME rport can have multiple roles. */
345 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
James Smart895427b2017-02-12 13:52:30 -0800346 len += snprintf(buf + len, PAGE_SIZE - len,
347 "INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700348 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
James Smart895427b2017-02-12 13:52:30 -0800349 len += snprintf(buf + len, PAGE_SIZE - len,
350 "TARGET ");
James Smart7d790f02017-06-01 21:06:57 -0700351 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
James Smart895427b2017-02-12 13:52:30 -0800352 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700353 "DISCSRVC ");
354 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
355 FC_PORT_ROLE_NVME_TARGET |
356 FC_PORT_ROLE_NVME_DISCOVERY))
James Smart895427b2017-02-12 13:52:30 -0800357 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700358 "UNKNOWN ROLE x%x",
James Smart895427b2017-02-12 13:52:30 -0800359 nrport->port_role);
James Smart7d790f02017-06-01 21:06:57 -0700360
James Smart895427b2017-02-12 13:52:30 -0800361 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
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200367 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
James Smart895427b2017-02-12 13:52:30 -0800368 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800369 "LS: Xmt %010x Cmpl %010x Abort %08x\n",
James Smart2cee7802017-06-01 21:07:02 -0700370 atomic_read(&phba->fc4NvmeLsRequests),
James Smart4b056682017-12-08 17:18:10 -0800371 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));
James Smart895427b2017-02-12 13:52:30 -0800379
James Smart2cee7802017-06-01 21:07:02 -0700380 tot = atomic_read(&phba->fc4NvmeIoCmpls);
381 data1 = atomic_read(&phba->fc4NvmeInputRequests);
382 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
383 data3 = atomic_read(&phba->fc4NvmeControlRequests);
James Smart895427b2017-02-12 13:52:30 -0800384 len += snprintf(buf+len, PAGE_SIZE-len,
385 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
James Smart2cee7802017-06-01 21:07:02 -0700386 data1, data2, data3);
James Smart895427b2017-02-12 13:52:30 -0800387
388 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart4b056682017-12-08 17:18:10 -0800389 " 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));
James Smart895427b2017-02-12 13:52:30 -0800405 return len;
406}
407
408static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500409lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
410 char *buf)
411{
412 struct Scsi_Host *shost = class_to_shost(dev);
413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
414 struct lpfc_hba *phba = vport->phba;
415
416 if (phba->cfg_enable_bg)
417 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
418 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
419 else
420 return snprintf(buf, PAGE_SIZE,
421 "BlockGuard Not Supported\n");
422 else
423 return snprintf(buf, PAGE_SIZE,
424 "BlockGuard Disabled\n");
425}
426
427static ssize_t
428lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
429 char *buf)
430{
431 struct Scsi_Host *shost = class_to_shost(dev);
432 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
433 struct lpfc_hba *phba = vport->phba;
434
James Smart87b5c322008-12-16 10:34:09 -0500435 return snprintf(buf, PAGE_SIZE, "%llu\n",
436 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500437}
438
439static ssize_t
440lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
441 char *buf)
442{
443 struct Scsi_Host *shost = class_to_shost(dev);
444 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
445 struct lpfc_hba *phba = vport->phba;
446
James Smart87b5c322008-12-16 10:34:09 -0500447 return snprintf(buf, PAGE_SIZE, "%llu\n",
448 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500449}
450
451static ssize_t
452lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
453 char *buf)
454{
455 struct Scsi_Host *shost = class_to_shost(dev);
456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
457 struct lpfc_hba *phba = vport->phba;
458
James Smart87b5c322008-12-16 10:34:09 -0500459 return snprintf(buf, PAGE_SIZE, "%llu\n",
460 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500461}
462
James Smarte59058c2008-08-24 21:49:00 -0400463/**
James Smart3621a712009-04-06 18:47:14 -0400464 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400465 * @dev: class converted to a Scsi_host structure.
466 * @attr: device attribute, not used.
467 * @buf: on return contains the formatted text from lpfc_info().
468 *
469 * Returns: size of formatted string.
470 **/
dea31012005-04-17 16:05:31 -0500471static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100472lpfc_info_show(struct device *dev, struct device_attribute *attr,
473 char *buf)
dea31012005-04-17 16:05:31 -0500474{
Tony Jonesee959b02008-02-22 00:13:36 +0100475 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500476
dea31012005-04-17 16:05:31 -0500477 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
478}
479
James Smarte59058c2008-08-24 21:49:00 -0400480/**
James Smart3621a712009-04-06 18:47:14 -0400481 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400482 * @dev: class converted to a Scsi_host structure.
483 * @attr: device attribute, not used.
484 * @buf: on return contains the formatted text serial number.
485 *
486 * Returns: size of formatted string.
487 **/
dea31012005-04-17 16:05:31 -0500488static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100489lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
490 char *buf)
dea31012005-04-17 16:05:31 -0500491{
Tony Jonesee959b02008-02-22 00:13:36 +0100492 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
494 struct lpfc_hba *phba = vport->phba;
495
dea31012005-04-17 16:05:31 -0500496 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
497}
498
James Smarte59058c2008-08-24 21:49:00 -0400499/**
James Smart3621a712009-04-06 18:47:14 -0400500 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400501 * @dev: class converted to a Scsi_host structure.
502 * @attr: device attribute, not used.
503 * @buf: on return contains the formatted support level.
504 *
505 * Description:
506 * Returns a number indicating the temperature sensor level currently
507 * supported, zero or one in ascii.
508 *
509 * Returns: size of formatted string.
510 **/
dea31012005-04-17 16:05:31 -0500511static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100512lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400514{
Tony Jonesee959b02008-02-22 00:13:36 +0100515 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
519}
520
James Smarte59058c2008-08-24 21:49:00 -0400521/**
James Smart3621a712009-04-06 18:47:14 -0400522 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400523 * @dev: class converted to a Scsi_host structure.
524 * @attr: device attribute, not used.
525 * @buf: on return contains the scsi vpd model description.
526 *
527 * Returns: size of formatted string.
528 **/
James Smart57127f12007-10-27 13:37:05 -0400529static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100530lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
531 char *buf)
dea31012005-04-17 16:05:31 -0500532{
Tony Jonesee959b02008-02-22 00:13:36 +0100533 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535 struct lpfc_hba *phba = vport->phba;
536
dea31012005-04-17 16:05:31 -0500537 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
538}
539
James Smarte59058c2008-08-24 21:49:00 -0400540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400542 * @dev: class converted to a Scsi_host structure.
543 * @attr: device attribute, not used.
544 * @buf: on return contains the scsi vpd model name.
545 *
546 * Returns: size of formatted string.
547 **/
dea31012005-04-17 16:05:31 -0500548static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100549lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
550 char *buf)
dea31012005-04-17 16:05:31 -0500551{
Tony Jonesee959b02008-02-22 00:13:36 +0100552 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500553 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
554 struct lpfc_hba *phba = vport->phba;
555
dea31012005-04-17 16:05:31 -0500556 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
557}
558
James Smarte59058c2008-08-24 21:49:00 -0400559/**
James Smart3621a712009-04-06 18:47:14 -0400560 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400561 * @dev: class converted to a Scsi_host structure.
562 * @attr: device attribute, not used.
563 * @buf: on return contains the scsi vpd program type.
564 *
565 * Returns: size of formatted string.
566 **/
dea31012005-04-17 16:05:31 -0500567static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100568lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
569 char *buf)
dea31012005-04-17 16:05:31 -0500570{
Tony Jonesee959b02008-02-22 00:13:36 +0100571 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
573 struct lpfc_hba *phba = vport->phba;
574
dea31012005-04-17 16:05:31 -0500575 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
576}
577
James Smarte59058c2008-08-24 21:49:00 -0400578/**
James Smart3621a712009-04-06 18:47:14 -0400579 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400580 * @dev: class converted to a Scsi_host structure.
581 * @attr: device attribute, not used.
582 * @buf: on return contains the Menlo Maintenance sli flag.
583 *
584 * Returns: size of formatted string.
585 **/
586static ssize_t
587lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
588{
589 struct Scsi_Host *shost = class_to_shost(dev);
590 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
591 struct lpfc_hba *phba = vport->phba;
592
593 return snprintf(buf, PAGE_SIZE, "%d\n",
594 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
595}
596
597/**
James Smart3621a712009-04-06 18:47:14 -0400598 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400599 * @dev: class converted to a Scsi_host structure.
600 * @attr: device attribute, not used.
601 * @buf: on return contains scsi vpd program type.
602 *
603 * Returns: size of formatted string.
604 **/
dea31012005-04-17 16:05:31 -0500605static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100606lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
607 char *buf)
dea31012005-04-17 16:05:31 -0500608{
Tony Jonesee959b02008-02-22 00:13:36 +0100609 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500610 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
611 struct lpfc_hba *phba = vport->phba;
612
dea31012005-04-17 16:05:31 -0500613 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
614}
615
James Smarte59058c2008-08-24 21:49:00 -0400616/**
James Smart3621a712009-04-06 18:47:14 -0400617 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400618 * @dev: class converted to a Scsi_host structure.
619 * @attr: device attribute, not used.
620 * @buf: on return contains the scsi vpd program type.
621 *
622 * Returns: size of formatted string.
623 **/
dea31012005-04-17 16:05:31 -0500624static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100625lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
626 char *buf)
dea31012005-04-17 16:05:31 -0500627{
Tony Jonesee959b02008-02-22 00:13:36 +0100628 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
630 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500631 uint32_t if_type;
632 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500633 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500634 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500635
dea31012005-04-17 16:05:31 -0500636 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500637 if_type = phba->sli4_hba.pc_sli4_params.if_type;
638 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
639
640 if (phba->sli_rev < LPFC_SLI_REV4)
641 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
642 fwrev, phba->sli_rev);
643 else
644 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
645 fwrev, phba->sli_rev, if_type, sli_family);
646
647 return len;
dea31012005-04-17 16:05:31 -0500648}
649
James Smarte59058c2008-08-24 21:49:00 -0400650/**
James Smart3621a712009-04-06 18:47:14 -0400651 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400652 * @dev: class converted to a Scsi_host structure.
653 * @attr: device attribute, not used.
654 * @buf: on return contains the scsi vpd program type.
655 *
656 * Returns: size of formatted string.
657 **/
dea31012005-04-17 16:05:31 -0500658static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100659lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500660{
661 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100662 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500663 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
664 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500665 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500666
dea31012005-04-17 16:05:31 -0500667 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
668 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
669}
James Smarte59058c2008-08-24 21:49:00 -0400670
671/**
James Smart3621a712009-04-06 18:47:14 -0400672 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400673 * @dev: class converted to a Scsi_host structure.
674 * @attr: device attribute, not used.
675 * @buf: on return contains the ROM and FCode ascii strings.
676 *
677 * Returns: size of formatted string.
678 **/
dea31012005-04-17 16:05:31 -0500679static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100680lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
681 char *buf)
dea31012005-04-17 16:05:31 -0500682{
Tony Jonesee959b02008-02-22 00:13:36 +0100683 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400686 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500687
James Smarta0683bf2015-04-07 15:07:16 -0400688 if (phba->sli_rev < LPFC_SLI_REV4)
689 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
690
691 lpfc_decode_firmware_rev(phba, fwrev, 1);
692 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500693}
James Smarte59058c2008-08-24 21:49:00 -0400694
695/**
James Smart3621a712009-04-06 18:47:14 -0400696 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400697 * @dev: class converted to a Scsi_host structure.
698 * @attr: device attribute, not used.
699 * @buf: on return contains text describing the state of the link.
700 *
701 * Notes:
702 * The switch statement has no default so zero will be returned.
703 *
704 * Returns: size of formatted string.
705 **/
dea31012005-04-17 16:05:31 -0500706static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100707lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
708 char *buf)
dea31012005-04-17 16:05:31 -0500709{
Tony Jonesee959b02008-02-22 00:13:36 +0100710 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
712 struct lpfc_hba *phba = vport->phba;
713 int len = 0;
714
715 switch (phba->link_state) {
716 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500717 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500718 case LPFC_INIT_START:
719 case LPFC_INIT_MBX_CMDS:
720 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500721 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400722 if (phba->hba_flag & LINK_DISABLED)
723 len += snprintf(buf + len, PAGE_SIZE-len,
724 "Link Down - User disabled\n");
725 else
726 len += snprintf(buf + len, PAGE_SIZE-len,
727 "Link Down\n");
dea31012005-04-17 16:05:31 -0500728 break;
729 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500730 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500731 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400732 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500733
734 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500735 case LPFC_LOCAL_CFG_LINK:
736 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500737 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500738 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500739 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500740 case LPFC_FLOGI:
741 case LPFC_FABRIC_CFG_LINK:
742 case LPFC_NS_REG:
743 case LPFC_NS_QRY:
744 case LPFC_BUILD_DISC_LIST:
745 case LPFC_DISC_AUTH:
746 len += snprintf(buf + len, PAGE_SIZE - len,
747 "Discovery\n");
748 break;
749 case LPFC_VPORT_READY:
750 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
751 break;
752
James Smart92d7f7b2007-06-17 19:56:38 -0500753 case LPFC_VPORT_FAILED:
754 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
755 break;
756
757 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500758 len += snprintf(buf + len, PAGE_SIZE - len,
759 "Unknown\n");
760 break;
761 }
James Smart84774a42008-08-24 21:50:06 -0400762 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
763 len += snprintf(buf + len, PAGE_SIZE-len,
764 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500765 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500766 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500767 len += snprintf(buf + len, PAGE_SIZE-len,
768 " Public Loop\n");
769 else
770 len += snprintf(buf + len, PAGE_SIZE-len,
771 " Private Loop\n");
772 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500773 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500774 len += snprintf(buf + len, PAGE_SIZE-len,
775 " Fabric\n");
776 else
777 len += snprintf(buf + len, PAGE_SIZE-len,
778 " Point-2-Point\n");
779 }
780 }
James Smart2e0fef82007-06-17 19:56:36 -0500781
dea31012005-04-17 16:05:31 -0500782 return len;
783}
784
James Smarte59058c2008-08-24 21:49:00 -0400785/**
James Smart026abb82011-12-13 13:20:45 -0500786 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
787 * @dev: class unused variable.
788 * @attr: device attribute, not used.
789 * @buf: on return contains the module description text.
790 *
791 * Returns: size of formatted string.
792 **/
793static ssize_t
794lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
795 char *buf)
796{
797 struct Scsi_Host *shost = class_to_shost(dev);
798 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
799 struct lpfc_hba *phba = vport->phba;
800
801 if (phba->sli_rev < LPFC_SLI_REV4)
802 return snprintf(buf, PAGE_SIZE, "fc\n");
803
804 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
805 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
806 return snprintf(buf, PAGE_SIZE, "fcoe\n");
807 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
808 return snprintf(buf, PAGE_SIZE, "fc\n");
809 }
810 return snprintf(buf, PAGE_SIZE, "unknown\n");
811}
812
813/**
James Smart1ba981f2014-02-20 09:56:45 -0500814 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
815 * (OAS) is supported.
816 * @dev: class unused variable.
817 * @attr: device attribute, not used.
818 * @buf: on return contains the module description text.
819 *
820 * Returns: size of formatted string.
821 **/
822static ssize_t
823lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
824 char *buf)
825{
826 struct Scsi_Host *shost = class_to_shost(dev);
827 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
828 struct lpfc_hba *phba = vport->phba;
829
830 return snprintf(buf, PAGE_SIZE, "%d\n",
831 phba->sli4_hba.pc_sli4_params.oas_supported);
832}
833
834/**
James Smart84d1b002010-02-12 14:42:33 -0500835 * lpfc_link_state_store - Transition the link_state on an HBA port
836 * @dev: class device that is converted into a Scsi_host.
837 * @attr: device attribute, not used.
838 * @buf: one or more lpfc_polling_flags values.
839 * @count: not used.
840 *
841 * Returns:
842 * -EINVAL if the buffer is not "up" or "down"
843 * return from link state change function if non-zero
844 * length of the buf on success
845 **/
846static ssize_t
847lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
848 const char *buf, size_t count)
849{
850 struct Scsi_Host *shost = class_to_shost(dev);
851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
852 struct lpfc_hba *phba = vport->phba;
853
854 int status = -EINVAL;
855
856 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
857 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400858 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500859 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
860 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400861 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500862
863 if (status == 0)
864 return strlen(buf);
865 else
866 return status;
867}
868
869/**
James Smart3621a712009-04-06 18:47:14 -0400870 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400871 * @dev: class device that is converted into a Scsi_host.
872 * @attr: device attribute, not used.
873 * @buf: on return contains the sum of fc mapped and unmapped.
874 *
875 * Description:
876 * Returns the ascii text number of the sum of the fc mapped and unmapped
877 * vport counts.
878 *
879 * Returns: size of formatted string.
880 **/
dea31012005-04-17 16:05:31 -0500881static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100882lpfc_num_discovered_ports_show(struct device *dev,
883 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500884{
Tony Jonesee959b02008-02-22 00:13:36 +0100885 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500886 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
887
888 return snprintf(buf, PAGE_SIZE, "%d\n",
889 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500890}
891
James Smarte59058c2008-08-24 21:49:00 -0400892/**
James Smart3621a712009-04-06 18:47:14 -0400893 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400894 * @shost: Scsi_Host pointer.
895 *
896 * Description:
897 * Bring the link down gracefully then re-init the link. The firmware will
898 * re-init the fiber channel interface as required. Does not issue a LIP.
899 *
900 * Returns:
901 * -EPERM port offline or management commands are being blocked
902 * -ENOMEM cannot allocate memory for the mailbox command
903 * -EIO error sending the mailbox command
904 * zero for success
905 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700906static int
James Smart2e0fef82007-06-17 19:56:36 -0500907lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500908{
James Smart2e0fef82007-06-17 19:56:36 -0500909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500911 LPFC_MBOXQ_t *pmboxq;
912 int mbxstatus = MBXERR_ERROR;
913
James Smart2e0fef82007-06-17 19:56:36 -0500914 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500915 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500916 return -EPERM;
917
918 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
919
920 if (!pmboxq)
921 return -ENOMEM;
922
923 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400924 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
925 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400926
James Smart33ccf8d2006-08-17 11:57:58 -0400927 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500928
James Smart04c68492009-05-22 14:52:52 -0400929 if ((mbxstatus == MBX_SUCCESS) &&
930 (pmboxq->u.mb.mbxStatus == 0 ||
931 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400932 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
933 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
934 phba->cfg_link_speed);
935 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
936 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400937 if ((mbxstatus == MBX_SUCCESS) &&
938 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
939 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
940 "2859 SLI authentication is required "
941 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400942 }
943
James Smart5b8bd0c2007-04-25 09:52:49 -0400944 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500945 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400946 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500947
948 if (mbxstatus == MBXERR_ERROR)
949 return -EIO;
950
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700951 return 0;
dea31012005-04-17 16:05:31 -0500952}
953
James Smart895427b2017-02-12 13:52:30 -0800954int
955lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
956{
957 int cnt = 0;
958
959 spin_lock_irq(lock);
960 while (!list_empty(q)) {
961 spin_unlock_irq(lock);
962 msleep(20);
963 if (cnt++ > 250) { /* 5 secs */
964 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
965 "0466 %s %s\n",
966 "Outstanding IO when ",
967 "bringing Adapter offline\n");
968 return 0;
969 }
970 spin_lock_irq(lock);
971 }
972 spin_unlock_irq(lock);
973 return 1;
974}
975
James Smarte59058c2008-08-24 21:49:00 -0400976/**
James Smart3621a712009-04-06 18:47:14 -0400977 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400978 * @phba: lpfc_hba pointer.
979 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
980 *
981 * Notes:
982 * Assumes any error from lpfc_do_offline() will be negative.
983 * Can wait up to 5 seconds for the port ring buffers count
984 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400985 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400986 *
987 * Returns:
988 * -EIO error posting the event
989 * zero for success
990 **/
James Smart40496f02006-07-06 15:50:22 -0400991static int
James Smart46fa3112007-04-25 09:51:45 -0400992lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
993{
994 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800995 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400996 struct lpfc_sli_ring *pring;
997 struct lpfc_sli *psli;
998 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400999 int i;
James Smartfedd3b72011-02-16 12:39:24 -05001000 int rc;
James Smart46fa3112007-04-25 09:51:45 -04001001
1002 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001003 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -04001004 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -05001005 if (rc == 0)
1006 return -ENOMEM;
1007
James Smart46fa3112007-04-25 09:51:45 -04001008 wait_for_completion(&online_compl);
1009
1010 if (status != 0)
1011 return -EIO;
1012
1013 psli = &phba->sli;
1014
James Smart09372822008-01-11 01:52:54 -05001015 /* Wait a little for things to settle down, but not
1016 * long enough for dev loss timeout to expire.
1017 */
James Smart895427b2017-02-12 13:52:30 -08001018 if (phba->sli_rev != LPFC_SLI_REV4) {
1019 for (i = 0; i < psli->num_rings; i++) {
1020 pring = &psli->sli3_ring[i];
1021 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1022 &phba->hbalock))
1023 goto out;
1024 }
1025 } else {
1026 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
1027 pring = qp->pring;
1028 if (!pring)
1029 continue;
1030 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
1031 &pring->ring_lock))
1032 goto out;
James Smart46fa3112007-04-25 09:51:45 -04001033 }
1034 }
James Smart895427b2017-02-12 13:52:30 -08001035out:
James Smart46fa3112007-04-25 09:51:45 -04001036 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001037 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1038 if (rc == 0)
1039 return -ENOMEM;
1040
James Smart46fa3112007-04-25 09:51:45 -04001041 wait_for_completion(&online_compl);
1042
1043 if (status != 0)
1044 return -EIO;
1045
1046 return 0;
1047}
1048
James Smarte59058c2008-08-24 21:49:00 -04001049/**
James Smart3621a712009-04-06 18:47:14 -04001050 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001051 * @phba: lpfc_hba pointer.
1052 *
1053 * Description:
1054 * If the port is configured to allow a reset then the hba is brought
1055 * offline then online.
1056 *
1057 * Notes:
1058 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001059 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001060 *
1061 * Returns:
1062 * lpfc_do_offline() return code if not zero
1063 * -EIO reset not configured or error posting the event
1064 * zero for success
1065 **/
James Smart7f860592011-03-11 16:05:52 -05001066int
James Smart40496f02006-07-06 15:50:22 -04001067lpfc_selective_reset(struct lpfc_hba *phba)
1068{
1069 struct completion online_compl;
1070 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001071 int rc;
James Smart40496f02006-07-06 15:50:22 -04001072
James Smart71157c92013-07-15 18:34:36 -04001073 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001074 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001075
James Smart71157c92013-07-15 18:34:36 -04001076 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1077 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001078
James Smart71157c92013-07-15 18:34:36 -04001079 if (status != 0)
1080 return status;
1081 }
James Smart40496f02006-07-06 15:50:22 -04001082
1083 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001084 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001085 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001086 if (rc == 0)
1087 return -ENOMEM;
1088
James Smart40496f02006-07-06 15:50:22 -04001089 wait_for_completion(&online_compl);
1090
1091 if (status != 0)
1092 return -EIO;
1093
1094 return 0;
1095}
1096
James Smarte59058c2008-08-24 21:49:00 -04001097/**
James Smart3621a712009-04-06 18:47:14 -04001098 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001099 * @dev: class device that is converted into a Scsi_host.
1100 * @attr: device attribute, not used.
1101 * @buf: containing the string "selective".
1102 * @count: unused variable.
1103 *
1104 * Description:
1105 * If the buf contains the string "selective" then lpfc_selective_reset()
1106 * is called to perform the reset.
1107 *
1108 * Notes:
1109 * Assumes any error from lpfc_selective_reset() will be negative.
1110 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001111 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001112 *
1113 * Returns:
1114 * -EINVAL if the buffer does not contain the string "selective"
1115 * length of buf if lpfc-selective_reset() if the call succeeds
1116 * return value of lpfc_selective_reset() if the call fails
1117**/
James Smart40496f02006-07-06 15:50:22 -04001118static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001119lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1120 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001121{
Tony Jonesee959b02008-02-22 00:13:36 +01001122 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001123 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1124 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001125 int status = -EINVAL;
1126
James Smart73d91e52011-10-10 21:32:10 -04001127 if (!phba->cfg_enable_hba_reset)
1128 return -EACCES;
1129
James Smart40496f02006-07-06 15:50:22 -04001130 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001131 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001132
1133 if (status == 0)
1134 return strlen(buf);
1135 else
1136 return status;
1137}
1138
James Smarte59058c2008-08-24 21:49:00 -04001139/**
James Smart88a2cfb2011-07-22 18:36:33 -04001140 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1141 * @phba: lpfc_hba pointer.
1142 *
1143 * Description:
1144 * SLI4 interface type-2 device to wait on the sliport status register for
1145 * the readyness after performing a firmware reset.
1146 *
1147 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001148 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001149 * reset, -EIO when port timeout from recovering from the reset.
1150 *
1151 * Note:
1152 * As the caller will interpret the return code by value, be careful in making
1153 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001154 **/
James Smart73d91e52011-10-10 21:32:10 -04001155int
James Smart88a2cfb2011-07-22 18:36:33 -04001156lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1157{
James Smartf7a919b2011-08-21 21:49:16 -04001158 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001159 int i;
1160
James Smartf7a919b2011-08-21 21:49:16 -04001161 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001162 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1163 &portstat_reg.word0);
1164
Masanari Iida0b1587b2013-07-17 04:37:44 +09001165 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001166 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1167 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1168 return -EPERM;
1169
James Smart88a2cfb2011-07-22 18:36:33 -04001170 /* wait for the SLI port firmware ready after firmware reset */
1171 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1172 msleep(10);
1173 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1174 &portstat_reg.word0);
1175 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1176 continue;
1177 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1178 continue;
1179 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1180 continue;
1181 break;
1182 }
1183
1184 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1185 return 0;
1186 else
1187 return -EIO;
1188}
1189
1190/**
James Smart52d52442011-05-24 11:42:45 -04001191 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001192 * @phba: lpfc_hba pointer.
1193 *
1194 * Description:
James Smart52d52442011-05-24 11:42:45 -04001195 * Request SLI4 interface type-2 device to perform a physical register set
1196 * access.
James Smartc0c11512011-05-24 11:41:34 -04001197 *
1198 * Returns:
1199 * zero for success
1200 **/
1201static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001202lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001203{
1204 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001205 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001206 uint32_t before_fc_flag;
1207 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001208 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001209 int status = 0, rc = 0;
1210 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001211
1212 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001213 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001214
James Smart52d52442011-05-24 11:42:45 -04001215 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1216 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1217 LPFC_SLI_INTF_IF_TYPE_2))
1218 return -EPERM;
1219
James Smart026abb82011-12-13 13:20:45 -05001220 /* Keep state if we need to restore back */
1221 before_fc_flag = phba->pport->fc_flag;
1222 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1223
James Smartb76f2dc2011-07-22 18:37:42 -04001224 /* Disable SR-IOV virtual functions if enabled */
1225 if (phba->cfg_sriov_nr_virtfn) {
1226 pci_disable_sriov(pdev);
1227 phba->cfg_sriov_nr_virtfn = 0;
1228 }
James Smart229adb02013-04-17 20:16:51 -04001229
James Smart02936352014-04-04 13:52:12 -04001230 if (opcode == LPFC_FW_DUMP)
1231 phba->hba_flag |= HBA_FW_DUMP_OP;
1232
James Smartc0c11512011-05-24 11:41:34 -04001233 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1234
James Smart02936352014-04-04 13:52:12 -04001235 if (status != 0) {
1236 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001237 return status;
James Smart02936352014-04-04 13:52:12 -04001238 }
James Smartc0c11512011-05-24 11:41:34 -04001239
1240 /* wait for the device to be quiesced before firmware reset */
1241 msleep(100);
1242
1243 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1244 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001245
1246 if (opcode == LPFC_FW_DUMP)
1247 reg_val |= LPFC_FW_DUMP_REQUEST;
1248 else if (opcode == LPFC_FW_RESET)
1249 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1250 else if (opcode == LPFC_DV_RESET)
1251 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1252
James Smartc0c11512011-05-24 11:41:34 -04001253 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1254 LPFC_CTL_PDEV_CTL_OFFSET);
1255 /* flush */
1256 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1257
1258 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001259 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1260
James Smart026abb82011-12-13 13:20:45 -05001261 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001262 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001263 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001264 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001265 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001266 } else if (rc == -EIO) {
1267 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001268 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1269 "3153 Fail to perform the requested "
1270 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001271 return rc;
James Smart026abb82011-12-13 13:20:45 -05001272 }
1273
1274 /* keep the original port state */
1275 if (before_fc_flag & FC_OFFLINE_MODE)
1276 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001277
1278 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001279 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1280 LPFC_EVT_ONLINE);
1281 if (!job_posted)
1282 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001283
1284 wait_for_completion(&online_compl);
1285
James Smart026abb82011-12-13 13:20:45 -05001286out:
1287 /* in any case, restore the virtual functions enabled as before */
1288 if (sriov_nr_virtfn) {
1289 sriov_err =
1290 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1291 if (!sriov_err)
1292 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1293 }
James Smartc0c11512011-05-24 11:41:34 -04001294
James Smart026abb82011-12-13 13:20:45 -05001295 /* return proper error code */
1296 if (!rc) {
1297 if (!job_posted)
1298 rc = -ENOMEM;
1299 else if (status)
1300 rc = -EIO;
1301 }
1302 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001303}
1304
1305/**
James Smart3621a712009-04-06 18:47:14 -04001306 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001307 * @dev: class device that is converted into a Scsi_host.
1308 * @attr: device attribute, not used.
1309 * @buf: on return contains the ascii number of nport events.
1310 *
1311 * Returns: size of formatted string.
1312 **/
dea31012005-04-17 16:05:31 -05001313static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001314lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1315 char *buf)
dea31012005-04-17 16:05:31 -05001316{
Tony Jonesee959b02008-02-22 00:13:36 +01001317 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1319 struct lpfc_hba *phba = vport->phba;
1320
dea31012005-04-17 16:05:31 -05001321 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: on return contains the state of the adapter.
1329 *
1330 * Returns: size of formatted string.
1331 **/
dea31012005-04-17 16:05:31 -05001332static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001333lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1334 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001335{
Tony Jonesee959b02008-02-22 00:13:36 +01001336 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001337 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1338 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001339 char * state;
1340
James Smart2e0fef82007-06-17 19:56:36 -05001341 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001342 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001343 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001344 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001345 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001346 state = "offline";
1347 else
1348 state = "online";
1349
1350 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1351}
1352
James Smarte59058c2008-08-24 21:49:00 -04001353/**
James Smart3621a712009-04-06 18:47:14 -04001354 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001355 * @dev: class device that is converted into a Scsi_host.
1356 * @attr: device attribute, not used.
1357 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1358 * @count: unused variable.
1359 *
1360 * Returns:
1361 * -EACCES if enable hba reset not enabled
1362 * -EINVAL if the buffer does not contain a valid string (see above)
1363 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1364 * buf length greater than zero indicates success
1365 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001366static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001367lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1368 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001369{
Tony Jonesee959b02008-02-22 00:13:36 +01001370 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001371 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1372 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001373 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001374 char *board_mode_str = NULL;
1375 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001376 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001377
James Smart026abb82011-12-13 13:20:45 -05001378 if (!phba->cfg_enable_hba_reset) {
1379 status = -EACCES;
1380 goto board_mode_out;
1381 }
James Smart88a2cfb2011-07-22 18:36:33 -04001382
1383 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001384 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001385
Jamie Wellnitz41415862006-02-28 19:25:27 -05001386 init_completion(&online_compl);
1387
James Smart46fa3112007-04-25 09:51:45 -04001388 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001389 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001390 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001391 if (rc == 0) {
1392 status = -ENOMEM;
1393 goto board_mode_out;
1394 }
James Smart46fa3112007-04-25 09:51:45 -04001395 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001396 if (status)
1397 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001398 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1399 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001400 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001401 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001402 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001403 else
1404 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001405 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001406 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001407 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001408 else
1409 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001410 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001411 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1412 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1413 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1414 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1415 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001416 else
James Smart026abb82011-12-13 13:20:45 -05001417 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001418
James Smart026abb82011-12-13 13:20:45 -05001419board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001420 if (!status)
1421 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001422 else {
1423 board_mode_str = strchr(buf, '\n');
1424 if (board_mode_str)
1425 *board_mode_str = '\0';
1426 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1427 "3097 Failed \"%s\", status(%d), "
1428 "fc_flag(x%x)\n",
1429 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001430 return status;
James Smart026abb82011-12-13 13:20:45 -05001431 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001432}
1433
James Smarte59058c2008-08-24 21:49:00 -04001434/**
James Smart3621a712009-04-06 18:47:14 -04001435 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001436 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001437 * @mxri: max xri count.
1438 * @axri: available xri count.
1439 * @mrpi: max rpi count.
1440 * @arpi: available rpi count.
1441 * @mvpi: max vpi count.
1442 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001443 *
1444 * Description:
1445 * If an integer pointer for an count is not null then the value for the
1446 * count is returned.
1447 *
1448 * Returns:
1449 * zero on error
1450 * one for success
1451 **/
James Smart311464e2007-08-02 11:10:37 -04001452static int
James Smart858c9f62007-06-17 19:56:39 -05001453lpfc_get_hba_info(struct lpfc_hba *phba,
1454 uint32_t *mxri, uint32_t *axri,
1455 uint32_t *mrpi, uint32_t *arpi,
1456 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001457{
James Smart04c68492009-05-22 14:52:52 -04001458 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001459 LPFC_MBOXQ_t *pmboxq;
1460 MAILBOX_t *pmb;
1461 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001462 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001463
1464 /*
1465 * prevent udev from issuing mailbox commands until the port is
1466 * configured.
1467 */
1468 if (phba->link_state < LPFC_LINK_DOWN ||
1469 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001470 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001471 return 0;
1472
1473 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1474 return 0;
1475
1476 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1477 if (!pmboxq)
1478 return 0;
1479 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1480
James Smart04c68492009-05-22 14:52:52 -04001481 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001482 pmb->mbxCommand = MBX_READ_CONFIG;
1483 pmb->mbxOwner = OWN_HOST;
1484 pmboxq->context1 = NULL;
1485
James Smart75baf692010-06-08 18:31:21 -04001486 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001487 rc = MBX_NOT_FINISHED;
1488 else
1489 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1490
1491 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001492 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001493 mempool_free(pmboxq, phba->mbox_mem_pool);
1494 return 0;
1495 }
1496
James Smartda0436e2009-05-22 14:51:39 -04001497 if (phba->sli_rev == LPFC_SLI_REV4) {
1498 rd_config = &pmboxq->u.mqe.un.rd_config;
1499 if (mrpi)
1500 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1501 if (arpi)
1502 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1503 phba->sli4_hba.max_cfg_param.rpi_used;
1504 if (mxri)
1505 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1506 if (axri)
1507 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1508 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001509
1510 /* Account for differences with SLI-3. Get vpi count from
1511 * mailbox data and subtract one for max vpi value.
1512 */
1513 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1514 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1515
James Smartda0436e2009-05-22 14:51:39 -04001516 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001517 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001518 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001519 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001520 } else {
1521 if (mrpi)
1522 *mrpi = pmb->un.varRdConfig.max_rpi;
1523 if (arpi)
1524 *arpi = pmb->un.varRdConfig.avail_rpi;
1525 if (mxri)
1526 *mxri = pmb->un.varRdConfig.max_xri;
1527 if (axri)
1528 *axri = pmb->un.varRdConfig.avail_xri;
1529 if (mvpi)
1530 *mvpi = pmb->un.varRdConfig.max_vpi;
1531 if (avpi)
1532 *avpi = pmb->un.varRdConfig.avail_vpi;
1533 }
James Smart92d7f7b2007-06-17 19:56:38 -05001534
1535 mempool_free(pmboxq, phba->mbox_mem_pool);
1536 return 1;
1537}
1538
James Smarte59058c2008-08-24 21:49:00 -04001539/**
James Smart3621a712009-04-06 18:47:14 -04001540 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001541 * @dev: class device that is converted into a Scsi_host.
1542 * @attr: device attribute, not used.
1543 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1544 *
1545 * Description:
1546 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1547 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1548 * to "Unknown" and the buffer length is returned, therefore the caller
1549 * must check for "Unknown" in the buffer to detect a failure.
1550 *
1551 * Returns: size of formatted string.
1552 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001553static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001554lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1555 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001556{
Tony Jonesee959b02008-02-22 00:13:36 +01001557 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001558 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1559 struct lpfc_hba *phba = vport->phba;
1560 uint32_t cnt;
1561
James Smart858c9f62007-06-17 19:56:39 -05001562 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001563 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1564 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1565}
1566
James Smarte59058c2008-08-24 21:49:00 -04001567/**
James Smart3621a712009-04-06 18:47:14 -04001568 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001569 * @dev: class device that is converted into a Scsi_host.
1570 * @attr: device attribute, not used.
1571 * @buf: containing the used rpi count in decimal or "Unknown".
1572 *
1573 * Description:
1574 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1575 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1576 * to "Unknown" and the buffer length is returned, therefore the caller
1577 * must check for "Unknown" in the buffer to detect a failure.
1578 *
1579 * Returns: size of formatted string.
1580 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001581static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001582lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1583 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001584{
Tony Jonesee959b02008-02-22 00:13:36 +01001585 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1587 struct lpfc_hba *phba = vport->phba;
1588 uint32_t cnt, acnt;
1589
James Smart858c9f62007-06-17 19:56:39 -05001590 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001591 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1592 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1593}
1594
James Smarte59058c2008-08-24 21:49:00 -04001595/**
James Smart3621a712009-04-06 18:47:14 -04001596 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001597 * @dev: class device that is converted into a Scsi_host.
1598 * @attr: device attribute, not used.
1599 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1600 *
1601 * Description:
1602 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1603 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1604 * to "Unknown" and the buffer length is returned, therefore the caller
1605 * must check for "Unknown" in the buffer to detect a failure.
1606 *
1607 * Returns: size of formatted string.
1608 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001609static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001610lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1611 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001612{
Tony Jonesee959b02008-02-22 00:13:36 +01001613 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001614 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1615 struct lpfc_hba *phba = vport->phba;
1616 uint32_t cnt;
1617
James Smart858c9f62007-06-17 19:56:39 -05001618 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001619 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1620 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1621}
1622
James Smarte59058c2008-08-24 21:49:00 -04001623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001625 * @dev: class device that is converted into a Scsi_host.
1626 * @attr: device attribute, not used.
1627 * @buf: on return contains the used xri count in decimal or "Unknown".
1628 *
1629 * Description:
1630 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1631 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1632 * to "Unknown" and the buffer length is returned, therefore the caller
1633 * must check for "Unknown" in the buffer to detect a failure.
1634 *
1635 * Returns: size of formatted string.
1636 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001637static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001638lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1639 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001640{
Tony Jonesee959b02008-02-22 00:13:36 +01001641 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1643 struct lpfc_hba *phba = vport->phba;
1644 uint32_t cnt, acnt;
1645
James Smart858c9f62007-06-17 19:56:39 -05001646 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1647 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1648 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1649}
1650
James Smarte59058c2008-08-24 21:49:00 -04001651/**
James Smart3621a712009-04-06 18:47:14 -04001652 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001653 * @dev: class device that is converted into a Scsi_host.
1654 * @attr: device attribute, not used.
1655 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1656 *
1657 * Description:
1658 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1659 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1660 * to "Unknown" and the buffer length is returned, therefore the caller
1661 * must check for "Unknown" in the buffer to detect a failure.
1662 *
1663 * Returns: size of formatted string.
1664 **/
James Smart858c9f62007-06-17 19:56:39 -05001665static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001666lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1667 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001668{
Tony Jonesee959b02008-02-22 00:13:36 +01001669 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001670 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1671 struct lpfc_hba *phba = vport->phba;
1672 uint32_t cnt;
1673
1674 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1675 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1676 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1677}
1678
James Smarte59058c2008-08-24 21:49:00 -04001679/**
James Smart3621a712009-04-06 18:47:14 -04001680 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001681 * @dev: class device that is converted into a Scsi_host.
1682 * @attr: device attribute, not used.
1683 * @buf: on return contains the used vpi count in decimal or "Unknown".
1684 *
1685 * Description:
1686 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1687 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1688 * to "Unknown" and the buffer length is returned, therefore the caller
1689 * must check for "Unknown" in the buffer to detect a failure.
1690 *
1691 * Returns: size of formatted string.
1692 **/
James Smart858c9f62007-06-17 19:56:39 -05001693static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001694lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1695 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001696{
Tony Jonesee959b02008-02-22 00:13:36 +01001697 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1699 struct lpfc_hba *phba = vport->phba;
1700 uint32_t cnt, acnt;
1701
1702 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001703 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1704 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1705}
1706
James Smarte59058c2008-08-24 21:49:00 -04001707/**
James Smart3621a712009-04-06 18:47:14 -04001708 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001709 * @dev: class device that is converted into a Scsi_host.
1710 * @attr: device attribute, not used.
1711 * @buf: text that must be interpreted to determine if npiv is supported.
1712 *
1713 * Description:
1714 * Buffer will contain text indicating npiv is not suppoerted on the port,
1715 * the port is an NPIV physical port, or it is an npiv virtual port with
1716 * the id of the vport.
1717 *
1718 * Returns: size of formatted string.
1719 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001720static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001721lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1722 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001723{
Tony Jonesee959b02008-02-22 00:13:36 +01001724 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001725 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1726 struct lpfc_hba *phba = vport->phba;
1727
1728 if (!(phba->max_vpi))
1729 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1730 if (vport->port_type == LPFC_PHYSICAL_PORT)
1731 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1732 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1733}
1734
James Smarte59058c2008-08-24 21:49:00 -04001735/**
James Smart3621a712009-04-06 18:47:14 -04001736 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001737 * @dev: class device that is converted into a Scsi_host.
1738 * @attr: device attribute, not used.
1739 * @buf: on return contains the cfg_poll in hex.
1740 *
1741 * Notes:
1742 * cfg_poll should be a lpfc_polling_flags type.
1743 *
1744 * Returns: size of formatted string.
1745 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001746static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001747lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1748 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001749{
Tony Jonesee959b02008-02-22 00:13:36 +01001750 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1752 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001753
1754 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1755}
1756
James Smarte59058c2008-08-24 21:49:00 -04001757/**
James Smart3621a712009-04-06 18:47:14 -04001758 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001759 * @dev: class device that is converted into a Scsi_host.
1760 * @attr: device attribute, not used.
1761 * @buf: one or more lpfc_polling_flags values.
1762 * @count: not used.
1763 *
1764 * Notes:
1765 * buf contents converted to integer and checked for a valid value.
1766 *
1767 * Returns:
1768 * -EINVAL if the buffer connot be converted or is out of range
1769 * length of the buf on success
1770 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001771static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001772lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1773 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001774{
Tony Jonesee959b02008-02-22 00:13:36 +01001775 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001776 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1777 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001778 uint32_t creg_val;
1779 uint32_t old_val;
1780 int val=0;
1781
1782 if (!isdigit(buf[0]))
1783 return -EINVAL;
1784
1785 if (sscanf(buf, "%i", &val) != 1)
1786 return -EINVAL;
1787
1788 if ((val & 0x3) != val)
1789 return -EINVAL;
1790
James Smart45ed1192009-10-02 15:17:02 -04001791 if (phba->sli_rev == LPFC_SLI_REV4)
1792 val = 0;
1793
James Smart88a2cfb2011-07-22 18:36:33 -04001794 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1795 "3051 lpfc_poll changed from %d to %d\n",
1796 phba->cfg_poll, val);
1797
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001799
1800 old_val = phba->cfg_poll;
1801
1802 if (val & ENABLE_FCP_RING_POLLING) {
1803 if ((val & DISABLE_FCP_RING_INT) &&
1804 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001805 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1806 spin_unlock_irq(&phba->hbalock);
1807 return -EINVAL;
1808 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001809 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1810 writel(creg_val, phba->HCregaddr);
1811 readl(phba->HCregaddr); /* flush */
1812
1813 lpfc_poll_start_timer(phba);
1814 }
1815 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001817 return -EINVAL;
1818 }
1819
1820 if (!(val & DISABLE_FCP_RING_INT) &&
1821 (old_val & DISABLE_FCP_RING_INT))
1822 {
James Smart2e0fef82007-06-17 19:56:36 -05001823 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001824 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001825 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001826 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1827 spin_unlock_irq(&phba->hbalock);
1828 return -EINVAL;
1829 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001830 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1831 writel(creg_val, phba->HCregaddr);
1832 readl(phba->HCregaddr); /* flush */
1833 }
1834
1835 phba->cfg_poll = val;
1836
James Smart2e0fef82007-06-17 19:56:36 -05001837 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001838
1839 return strlen(buf);
1840}
dea31012005-04-17 16:05:31 -05001841
James Smarte59058c2008-08-24 21:49:00 -04001842/**
James Smartbc739052010-08-04 16:11:18 -04001843 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1844 * @dev: class unused variable.
1845 * @attr: device attribute, not used.
1846 * @buf: on return contains the module description text.
1847 *
1848 * Returns: size of formatted string.
1849 **/
1850static ssize_t
1851lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1852 char *buf)
1853{
1854 struct Scsi_Host *shost = class_to_shost(dev);
1855 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1856 struct lpfc_hba *phba = vport->phba;
1857
1858 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1859}
1860
1861/**
1862 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1863 * @dev: class unused variable.
1864 * @attr: device attribute, not used.
1865 * @buf: on return contains the module description text.
1866 *
1867 * Returns: size of formatted string.
1868 **/
1869static ssize_t
1870lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1871 char *buf)
1872{
1873 struct Scsi_Host *shost = class_to_shost(dev);
1874 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1875 struct lpfc_hba *phba = vport->phba;
1876
1877 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1878}
1879
1880/**
James Smartab56dc22011-02-16 12:39:57 -05001881 * lpfc_dss_show - Return the current state of dss and the configured state
1882 * @dev: class converted to a Scsi_host structure.
1883 * @attr: device attribute, not used.
1884 * @buf: on return contains the formatted text.
1885 *
1886 * Returns: size of formatted string.
1887 **/
1888static ssize_t
1889lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1890 char *buf)
1891{
1892 struct Scsi_Host *shost = class_to_shost(dev);
1893 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1894 struct lpfc_hba *phba = vport->phba;
1895
1896 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1897 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1898 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1899 "" : "Not ");
1900}
1901
1902/**
James Smart912e3ac2011-05-24 11:42:11 -04001903 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1904 * @dev: class converted to a Scsi_host structure.
1905 * @attr: device attribute, not used.
1906 * @buf: on return contains the formatted support level.
1907 *
1908 * Description:
1909 * Returns the maximum number of virtual functions a physical function can
1910 * support, 0 will be returned if called on virtual function.
1911 *
1912 * Returns: size of formatted string.
1913 **/
1914static ssize_t
1915lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1916 struct device_attribute *attr,
1917 char *buf)
1918{
1919 struct Scsi_Host *shost = class_to_shost(dev);
1920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1921 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001922 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001923
James Smart0a96e972011-07-22 18:37:28 -04001924 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1925 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001926}
1927
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001928static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1929{
1930 return val >= min && val <= max;
1931}
1932
James Smart912e3ac2011-05-24 11:42:11 -04001933/**
James Smart44fd7fe2017-08-23 16:55:47 -07001934 * lpfc_enable_bbcr_set: Sets an attribute value.
1935 * @phba: pointer the the adapter structure.
1936 * @val: integer attribute value.
1937 *
1938 * Description:
1939 * Validates the min and max values then sets the
1940 * adapter config field if in the valid range. prints error message
1941 * and does not set the parameter if invalid.
1942 *
1943 * Returns:
1944 * zero on success
1945 * -EINVAL if val is invalid
1946 */
1947static ssize_t
1948lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1949{
1950 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1951 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1952 "3068 %s_enable_bbcr changed from %d to %d\n",
1953 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1954 phba->cfg_enable_bbcr = val;
1955 return 0;
1956 }
1957 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1958 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1959 LPFC_DRIVER_NAME, val);
1960 return -EINVAL;
1961}
1962
1963/**
James Smart3621a712009-04-06 18:47:14 -04001964 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001965 *
1966 * Description:
1967 * Macro that given an attr e.g. hba_queue_depth expands
1968 * into a function with the name lpfc_hba_queue_depth_show.
1969 *
1970 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1971 * @dev: class device that is converted into a Scsi_host.
1972 * @attr: device attribute, not used.
1973 * @buf: on return contains the attribute value in decimal.
1974 *
1975 * Returns: size of formatted string.
1976 **/
dea31012005-04-17 16:05:31 -05001977#define lpfc_param_show(attr) \
1978static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001979lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1980 char *buf) \
dea31012005-04-17 16:05:31 -05001981{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001982 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001983 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1984 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001985 return snprintf(buf, PAGE_SIZE, "%d\n",\
1986 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001987}
1988
James Smarte59058c2008-08-24 21:49:00 -04001989/**
James Smart3621a712009-04-06 18:47:14 -04001990 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001991 *
1992 * Description:
1993 * Macro that given an attr e.g. hba_queue_depth expands
1994 * into a function with the name lpfc_hba_queue_depth_show
1995 *
1996 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1997 * @dev: class device that is converted into a Scsi_host.
1998 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001999 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002000 *
2001 * Returns: size of formatted string.
2002 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002003#define lpfc_param_hex_show(attr) \
2004static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002005lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2006 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002007{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002008 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002009 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2010 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002011 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002012 val = phba->cfg_##attr;\
2013 return snprintf(buf, PAGE_SIZE, "%#x\n",\
2014 phba->cfg_##attr);\
2015}
2016
James Smarte59058c2008-08-24 21:49:00 -04002017/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04002018 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002019 *
2020 * Description:
2021 * Macro that given an attr e.g. hba_queue_depth expands
2022 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2023 * takes a default argument, a minimum and maximum argument.
2024 *
2025 * lpfc_##attr##_init: Initializes an attribute.
2026 * @phba: pointer the the adapter structure.
2027 * @val: integer attribute value.
2028 *
2029 * Validates the min and max values then sets the adapter config field
2030 * accordingly, or uses the default if out of range and prints an error message.
2031 *
2032 * Returns:
2033 * zero on success
2034 * -EINVAL if default used
2035 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002036#define lpfc_param_init(attr, default, minval, maxval) \
2037static int \
James Smart84d1b002010-02-12 14:42:33 -05002038lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002039{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002040 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002041 phba->cfg_##attr = val;\
2042 return 0;\
2043 }\
2044 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002045 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2046 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002047 phba->cfg_##attr = default;\
2048 return -EINVAL;\
2049}
2050
James Smarte59058c2008-08-24 21:49:00 -04002051/**
James Smart3621a712009-04-06 18:47:14 -04002052 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002053 *
2054 * Description:
2055 * Macro that given an attr e.g. hba_queue_depth expands
2056 * into a function with the name lpfc_hba_queue_depth_set
2057 *
2058 * lpfc_##attr##_set: Sets an attribute value.
2059 * @phba: pointer the the adapter structure.
2060 * @val: integer attribute value.
2061 *
2062 * Description:
2063 * Validates the min and max values then sets the
2064 * adapter config field if in the valid range. prints error message
2065 * and does not set the parameter if invalid.
2066 *
2067 * Returns:
2068 * zero on success
2069 * -EINVAL if val is invalid
2070 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002071#define lpfc_param_set(attr, default, minval, maxval) \
2072static int \
James Smart84d1b002010-02-12 14:42:33 -05002073lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002074{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002075 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002076 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2077 "3052 lpfc_" #attr " changed from %d to %d\n", \
2078 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002079 phba->cfg_##attr = val;\
2080 return 0;\
2081 }\
2082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002083 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2084 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002085 return -EINVAL;\
2086}
2087
James Smarte59058c2008-08-24 21:49:00 -04002088/**
James Smart3621a712009-04-06 18:47:14 -04002089 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002090 *
2091 * Description:
2092 * Macro that given an attr e.g. hba_queue_depth expands
2093 * into a function with the name lpfc_hba_queue_depth_store.
2094 *
2095 * lpfc_##attr##_store: Set an sttribute value.
2096 * @dev: class device that is converted into a Scsi_host.
2097 * @attr: device attribute, not used.
2098 * @buf: contains the attribute value in ascii.
2099 * @count: not used.
2100 *
2101 * Description:
2102 * Convert the ascii text number to an integer, then
2103 * use the lpfc_##attr##_set function to set the value.
2104 *
2105 * Returns:
2106 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2107 * length of buffer upon success.
2108 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002109#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002110static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002111lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2112 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002113{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002114 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2116 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002117 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002118 if (!isdigit(buf[0]))\
2119 return -EINVAL;\
2120 if (sscanf(buf, "%i", &val) != 1)\
2121 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002122 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002123 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002124 else \
2125 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002126}
2127
James Smarte59058c2008-08-24 21:49:00 -04002128/**
James Smart3621a712009-04-06 18:47:14 -04002129 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002130 *
2131 * Description:
2132 * Macro that given an attr e.g. hba_queue_depth expands
2133 * into a function with the name lpfc_hba_queue_depth_show
2134 *
2135 * lpfc_##attr##_show: prints the attribute value in decimal.
2136 * @dev: class device that is converted into a Scsi_host.
2137 * @attr: device attribute, not used.
2138 * @buf: on return contains the attribute value in decimal.
2139 *
2140 * Returns: length of formatted string.
2141 **/
James Smart3de2a652007-08-02 11:09:59 -04002142#define lpfc_vport_param_show(attr) \
2143static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002144lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2145 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002146{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002147 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002148 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002149 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2150}
2151
James Smarte59058c2008-08-24 21:49:00 -04002152/**
James Smart3621a712009-04-06 18:47:14 -04002153 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002154 *
2155 * Description:
2156 * Macro that given an attr e.g.
2157 * hba_queue_depth expands into a function with the name
2158 * lpfc_hba_queue_depth_show
2159 *
James Smart3621a712009-04-06 18:47:14 -04002160 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002161 * @dev: class device that is converted into a Scsi_host.
2162 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002163 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002164 *
2165 * Returns: length of formatted string.
2166 **/
James Smart3de2a652007-08-02 11:09:59 -04002167#define lpfc_vport_param_hex_show(attr) \
2168static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002169lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2170 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002171{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002172 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002173 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002174 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2175}
2176
James Smarte59058c2008-08-24 21:49:00 -04002177/**
James Smart3621a712009-04-06 18:47:14 -04002178 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002179 *
2180 * Description:
2181 * Macro that given an attr e.g. hba_queue_depth expands
2182 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2183 * takes a default argument, a minimum and maximum argument.
2184 *
2185 * lpfc_##attr##_init: validates the min and max values then sets the
2186 * adapter config field accordingly, or uses the default if out of range
2187 * and prints an error message.
2188 * @phba: pointer the the adapter structure.
2189 * @val: integer attribute value.
2190 *
2191 * Returns:
2192 * zero on success
2193 * -EINVAL if default used
2194 **/
James Smart3de2a652007-08-02 11:09:59 -04002195#define lpfc_vport_param_init(attr, default, minval, maxval) \
2196static int \
James Smart84d1b002010-02-12 14:42:33 -05002197lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002198{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002199 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002200 vport->cfg_##attr = val;\
2201 return 0;\
2202 }\
James Smarte8b62012007-08-02 11:10:09 -04002203 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002204 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002205 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002206 vport->cfg_##attr = default;\
2207 return -EINVAL;\
2208}
2209
James Smarte59058c2008-08-24 21:49:00 -04002210/**
James Smart3621a712009-04-06 18:47:14 -04002211 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002212 *
2213 * Description:
2214 * Macro that given an attr e.g. hba_queue_depth expands
2215 * into a function with the name lpfc_hba_queue_depth_set
2216 *
2217 * lpfc_##attr##_set: validates the min and max values then sets the
2218 * adapter config field if in the valid range. prints error message
2219 * and does not set the parameter if invalid.
2220 * @phba: pointer the the adapter structure.
2221 * @val: integer attribute value.
2222 *
2223 * Returns:
2224 * zero on success
2225 * -EINVAL if val is invalid
2226 **/
James Smart3de2a652007-08-02 11:09:59 -04002227#define lpfc_vport_param_set(attr, default, minval, maxval) \
2228static int \
James Smart84d1b002010-02-12 14:42:33 -05002229lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002230{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002231 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002232 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002233 "3053 lpfc_" #attr \
2234 " changed from %d (x%x) to %d (x%x)\n", \
2235 vport->cfg_##attr, vport->cfg_##attr, \
2236 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002237 vport->cfg_##attr = val;\
2238 return 0;\
2239 }\
James Smarte8b62012007-08-02 11:10:09 -04002240 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002241 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002242 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002243 return -EINVAL;\
2244}
2245
James Smarte59058c2008-08-24 21:49:00 -04002246/**
James Smart3621a712009-04-06 18:47:14 -04002247 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002248 *
2249 * Description:
2250 * Macro that given an attr e.g. hba_queue_depth
2251 * expands into a function with the name lpfc_hba_queue_depth_store
2252 *
2253 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2254 * use the lpfc_##attr##_set function to set the value.
2255 * @cdev: class device that is converted into a Scsi_host.
2256 * @buf: contains the attribute value in decimal.
2257 * @count: not used.
2258 *
2259 * Returns:
2260 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2261 * length of buffer upon success.
2262 **/
James Smart3de2a652007-08-02 11:09:59 -04002263#define lpfc_vport_param_store(attr) \
2264static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002265lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2266 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002267{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002268 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002269 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002270 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002271 if (!isdigit(buf[0]))\
2272 return -EINVAL;\
2273 if (sscanf(buf, "%i", &val) != 1)\
2274 return -EINVAL;\
2275 if (lpfc_##attr##_set(vport, val) == 0) \
2276 return strlen(buf);\
2277 else \
2278 return -EINVAL;\
2279}
2280
2281
James Smart895427b2017-02-12 13:52:30 -08002282static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002283static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2284static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2285static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2286static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002287static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2288static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2289static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2290static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2291static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2292static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2293static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2294static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002295static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2296 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002297static DEVICE_ATTR(option_rom_version, S_IRUGO,
2298 lpfc_option_rom_version_show, NULL);
2299static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2300 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002301static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002302static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002303static DEVICE_ATTR_RO(lpfc_drvr_version);
2304static DEVICE_ATTR_RO(lpfc_enable_fip);
Tony Jonesee959b02008-02-22 00:13:36 +01002305static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2306 lpfc_board_mode_show, lpfc_board_mode_store);
2307static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2308static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2309static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2310static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2311static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2312static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2313static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2314static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
Joe Perchesc828a892017-12-19 10:15:08 -08002315static DEVICE_ATTR_RO(lpfc_temp_sensor);
2316static DEVICE_ATTR_RO(lpfc_fips_level);
2317static DEVICE_ATTR_RO(lpfc_fips_rev);
2318static DEVICE_ATTR_RO(lpfc_dss);
2319static DEVICE_ATTR_RO(lpfc_sriov_hw_max_virtfn);
James Smart026abb82011-12-13 13:20:45 -05002320static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002321static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2322 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002323
James Smart352e5fd2016-12-30 06:57:47 -08002324static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002325#define WWN_SZ 8
2326/**
2327 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2328 * @buf: WWN string.
2329 * @cnt: Length of string.
2330 * @wwn: Array to receive converted wwn value.
2331 *
2332 * Returns:
2333 * -EINVAL if the buffer does not contain a valid wwn
2334 * 0 success
2335 **/
2336static size_t
2337lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2338{
2339 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002340
James Smart1ba981f2014-02-20 09:56:45 -05002341 /* Count may include a LF at end of string */
2342 if (buf[cnt-1] == '\n')
2343 cnt--;
2344
2345 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2346 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2347 return -EINVAL;
2348
2349 memset(wwn, 0, WWN_SZ);
2350
2351 /* Validate and store the new name */
2352 for (i = 0, j = 0; i < 16; i++) {
2353 if ((*buf >= 'a') && (*buf <= 'f'))
2354 j = ((j << 4) | ((*buf++ - 'a') + 10));
2355 else if ((*buf >= 'A') && (*buf <= 'F'))
2356 j = ((j << 4) | ((*buf++ - 'A') + 10));
2357 else if ((*buf >= '0') && (*buf <= '9'))
2358 j = ((j << 4) | (*buf++ - '0'));
2359 else
2360 return -EINVAL;
2361 if (i % 2) {
2362 wwn[i/2] = j & 0xff;
2363 j = 0;
2364 }
2365 }
2366 return 0;
2367}
James Smart352e5fd2016-12-30 06:57:47 -08002368/**
2369 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2370 * @dev: class device that is converted into a Scsi_host.
2371 * @attr: device attribute, not used.
2372 * @buf: containing the string lpfc_soft_wwn_key.
2373 * @count: must be size of lpfc_soft_wwn_key.
2374 *
2375 * Returns:
2376 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2377 * length of buf indicates success
2378 **/
2379static ssize_t
2380lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2381 const char *buf, size_t count)
2382{
2383 struct Scsi_Host *shost = class_to_shost(dev);
2384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2385 struct lpfc_hba *phba = vport->phba;
2386 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002387 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2388 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002389
2390 /*
2391 * We're doing a simple sanity check for soft_wwpn setting.
2392 * We require that the user write a specific key to enable
2393 * the soft_wwpn attribute to be settable. Once the attribute
2394 * is written, the enable key resets. If further updates are
2395 * desired, the key must be written again to re-enable the
2396 * attribute.
2397 *
2398 * The "key" is not secret - it is a hardcoded string shown
2399 * here. The intent is to protect against the random user or
2400 * application that is just writing attributes.
2401 */
James Smartaeb3c812017-04-21 16:05:02 -07002402 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2403 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2404 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2405 " be enabled: fawwpn is enabled\n");
2406 return -EINVAL;
2407 }
James Smart352e5fd2016-12-30 06:57:47 -08002408
2409 /* count may include a LF at end of string */
2410 if (buf[cnt-1] == '\n')
2411 cnt--;
2412
2413 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2414 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2415 return -EINVAL;
2416
2417 phba->soft_wwn_enable = 1;
2418
2419 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2420 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2421 phba->brd_no);
2422 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2423 " The soft_wwpn feature is not supported by Broadcom.");
2424
2425 return count;
2426}
Joe Perches6cbaefb2017-12-19 10:15:09 -08002427static DEVICE_ATTR_WO(lpfc_soft_wwn_enable);
James Smart352e5fd2016-12-30 06:57:47 -08002428
2429/**
2430 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2431 * @dev: class device that is converted into a Scsi_host.
2432 * @attr: device attribute, not used.
2433 * @buf: on return contains the wwpn in hexadecimal.
2434 *
2435 * Returns: size of formatted string.
2436 **/
2437static ssize_t
2438lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2439 char *buf)
2440{
2441 struct Scsi_Host *shost = class_to_shost(dev);
2442 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2443 struct lpfc_hba *phba = vport->phba;
2444
2445 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2446 (unsigned long long)phba->cfg_soft_wwpn);
2447}
2448
2449/**
2450 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2451 * @dev class device that is converted into a Scsi_host.
2452 * @attr: device attribute, not used.
2453 * @buf: contains the wwpn in hexadecimal.
2454 * @count: number of wwpn bytes in buf
2455 *
2456 * Returns:
2457 * -EACCES hba reset not enabled, adapter over temp
2458 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2459 * -EIO error taking adapter offline or online
2460 * value of count on success
2461 **/
2462static ssize_t
2463lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2464 const char *buf, size_t count)
2465{
2466 struct Scsi_Host *shost = class_to_shost(dev);
2467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2468 struct lpfc_hba *phba = vport->phba;
2469 struct completion online_compl;
2470 int stat1 = 0, stat2 = 0;
2471 unsigned int cnt = count;
2472 u8 wwpn[WWN_SZ];
2473 int rc;
2474
2475 if (!phba->cfg_enable_hba_reset)
2476 return -EACCES;
2477 spin_lock_irq(&phba->hbalock);
2478 if (phba->over_temp_state == HBA_OVER_TEMP) {
2479 spin_unlock_irq(&phba->hbalock);
2480 return -EACCES;
2481 }
2482 spin_unlock_irq(&phba->hbalock);
2483 /* count may include a LF at end of string */
2484 if (buf[cnt-1] == '\n')
2485 cnt--;
2486
2487 if (!phba->soft_wwn_enable)
2488 return -EINVAL;
2489
2490 /* lock setting wwpn, wwnn down */
2491 phba->soft_wwn_enable = 0;
2492
2493 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002494 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002495 /* not able to set wwpn, unlock it */
2496 phba->soft_wwn_enable = 1;
2497 return rc;
2498 }
2499
2500 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2501 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2502 if (phba->cfg_soft_wwnn)
2503 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2504
2505 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2506 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2507
2508 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2509 if (stat1)
2510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2511 "0463 lpfc_soft_wwpn attribute set failed to "
2512 "reinit adapter - %d\n", stat1);
2513 init_completion(&online_compl);
2514 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2515 LPFC_EVT_ONLINE);
2516 if (rc == 0)
2517 return -ENOMEM;
2518
2519 wait_for_completion(&online_compl);
2520 if (stat2)
2521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2522 "0464 lpfc_soft_wwpn attribute set failed to "
2523 "reinit adapter - %d\n", stat2);
2524 return (stat1 || stat2) ? -EIO : count;
2525}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002526static DEVICE_ATTR_RW(lpfc_soft_wwpn);
James Smart352e5fd2016-12-30 06:57:47 -08002527
2528/**
2529 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2530 * @dev: class device that is converted into a Scsi_host.
2531 * @attr: device attribute, not used.
2532 * @buf: on return contains the wwnn in hexadecimal.
2533 *
2534 * Returns: size of formatted string.
2535 **/
2536static ssize_t
2537lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2538 char *buf)
2539{
2540 struct Scsi_Host *shost = class_to_shost(dev);
2541 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2542 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2543 (unsigned long long)phba->cfg_soft_wwnn);
2544}
2545
2546/**
2547 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2548 * @cdev: class device that is converted into a Scsi_host.
2549 * @buf: contains the ww node name in hexadecimal.
2550 * @count: number of wwnn bytes in buf.
2551 *
2552 * Returns:
2553 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2554 * value of count on success
2555 **/
2556static ssize_t
2557lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2558 const char *buf, size_t count)
2559{
2560 struct Scsi_Host *shost = class_to_shost(dev);
2561 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2562 unsigned int cnt = count;
2563 u8 wwnn[WWN_SZ];
2564 int rc;
2565
2566 /* count may include a LF at end of string */
2567 if (buf[cnt-1] == '\n')
2568 cnt--;
2569
2570 if (!phba->soft_wwn_enable)
2571 return -EINVAL;
2572
2573 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002574 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002575 /* Allow wwnn to be set many times, as long as the enable
2576 * is set. However, once the wwpn is set, everything locks.
2577 */
2578 return rc;
2579 }
2580
2581 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2582
2583 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2584 "lpfc%d: soft_wwnn set. Value will take effect upon "
2585 "setting of the soft_wwpn\n", phba->brd_no);
2586
2587 return count;
2588}
Joe Perchesb6b996b2017-12-19 10:15:07 -08002589static DEVICE_ATTR_RW(lpfc_soft_wwnn);
James Smarta12e07b2006-12-02 13:35:30 -05002590
James Smart1ba981f2014-02-20 09:56:45 -05002591/**
2592 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2593 * Optimized Access Storage (OAS) operations.
2594 * @dev: class device that is converted into a Scsi_host.
2595 * @attr: device attribute, not used.
2596 * @buf: buffer for passing information.
2597 *
2598 * Returns:
2599 * value of count
2600 **/
2601static ssize_t
2602lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2603 char *buf)
2604{
2605 struct Scsi_Host *shost = class_to_shost(dev);
2606 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2607
2608 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2609 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2610}
2611
2612/**
2613 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2614 * Optimized Access Storage (OAS) operations.
2615 * @dev: class device that is converted into a Scsi_host.
2616 * @attr: device attribute, not used.
2617 * @buf: buffer for passing information.
2618 * @count: Size of the data buffer.
2619 *
2620 * Returns:
2621 * -EINVAL count is invalid, invalid wwpn byte invalid
2622 * -EPERM oas is not supported by hba
2623 * value of count on success
2624 **/
2625static ssize_t
2626lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2627 const char *buf, size_t count)
2628{
2629 struct Scsi_Host *shost = class_to_shost(dev);
2630 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2631 unsigned int cnt = count;
2632 uint8_t wwpn[WWN_SZ];
2633 int rc;
2634
James Smartf38fa0b2014-04-04 13:52:21 -04002635 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002636 return -EPERM;
2637
2638 /* count may include a LF at end of string */
2639 if (buf[cnt-1] == '\n')
2640 cnt--;
2641
2642 rc = lpfc_wwn_set(buf, cnt, wwpn);
2643 if (rc)
2644 return rc;
2645
2646 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2647 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2648 if (wwn_to_u64(wwpn) == 0)
2649 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2650 else
2651 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2652 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2653 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2654 return count;
2655}
2656static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2657 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2658
2659/**
James Smartc92c8412016-07-06 12:36:05 -07002660 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2661 * Optimized Access Storage (OAS) operations.
2662 * @dev: class device that is converted into a Scsi_host.
2663 * @attr: device attribute, not used.
2664 * @buf: buffer for passing information.
2665 *
2666 * Returns:
2667 * value of count
2668 **/
2669static ssize_t
2670lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2671 char *buf)
2672{
2673 struct Scsi_Host *shost = class_to_shost(dev);
2674 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2675
2676 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2677}
2678
2679/**
2680 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2681 * Optimized Access Storage (OAS) operations.
2682 * @dev: class device that is converted into a Scsi_host.
2683 * @attr: device attribute, not used.
2684 * @buf: buffer for passing information.
2685 * @count: Size of the data buffer.
2686 *
2687 * Returns:
2688 * -EINVAL count is invalid, invalid wwpn byte invalid
2689 * -EPERM oas is not supported by hba
2690 * value of count on success
2691 **/
2692static ssize_t
2693lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2694 const char *buf, size_t count)
2695{
2696 struct Scsi_Host *shost = class_to_shost(dev);
2697 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2698 unsigned int cnt = count;
2699 unsigned long val;
2700 int ret;
2701
2702 if (!phba->cfg_fof)
2703 return -EPERM;
2704
2705 /* count may include a LF at end of string */
2706 if (buf[cnt-1] == '\n')
2707 cnt--;
2708
2709 ret = kstrtoul(buf, 0, &val);
2710 if (ret || (val > 0x7f))
2711 return -EINVAL;
2712
2713 if (val)
2714 phba->cfg_oas_priority = (uint8_t)val;
2715 else
2716 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2717 return count;
2718}
2719static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2720 lpfc_oas_priority_show, lpfc_oas_priority_store);
2721
2722/**
James Smart1ba981f2014-02-20 09:56:45 -05002723 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2724 * for Optimized Access Storage (OAS) operations.
2725 * @dev: class device that is converted into a Scsi_host.
2726 * @attr: device attribute, not used.
2727 * @buf: buffer for passing information.
2728 *
2729 * Returns:
2730 * value of count on success
2731 **/
2732static ssize_t
2733lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2734 char *buf)
2735{
2736 struct Scsi_Host *shost = class_to_shost(dev);
2737 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2738
2739 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2740 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2741}
2742
2743/**
2744 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2745 * for Optimized Access Storage (OAS) operations.
2746 * @dev: class device that is converted into a Scsi_host.
2747 * @attr: device attribute, not used.
2748 * @buf: buffer for passing information.
2749 * @count: Size of the data buffer.
2750 *
2751 * Returns:
2752 * -EINVAL count is invalid, invalid wwpn byte invalid
2753 * -EPERM oas is not supported by hba
2754 * value of count on success
2755 **/
2756static ssize_t
2757lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2758 const char *buf, size_t count)
2759{
2760 struct Scsi_Host *shost = class_to_shost(dev);
2761 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2762 unsigned int cnt = count;
2763 uint8_t wwpn[WWN_SZ];
2764 int rc;
2765
James Smartf38fa0b2014-04-04 13:52:21 -04002766 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002767 return -EPERM;
2768
2769 /* count may include a LF at end of string */
2770 if (buf[cnt-1] == '\n')
2771 cnt--;
2772
2773 rc = lpfc_wwn_set(buf, cnt, wwpn);
2774 if (rc)
2775 return rc;
2776
2777 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2778 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2779 if (wwn_to_u64(wwpn) == 0)
2780 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2781 else
2782 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2783 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002784 if (phba->cfg_oas_priority == 0)
2785 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002786 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2787 return count;
2788}
2789static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2790 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2791
2792/**
2793 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2794 * of whether luns will be enabled or disabled
2795 * for Optimized Access Storage (OAS) operations.
2796 * @dev: class device that is converted into a Scsi_host.
2797 * @attr: device attribute, not used.
2798 * @buf: buffer for passing information.
2799 *
2800 * Returns:
2801 * size of formatted string.
2802 **/
2803static ssize_t
2804lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2805 char *buf)
2806{
2807 struct Scsi_Host *shost = class_to_shost(dev);
2808 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2809
2810 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2811}
2812
2813/**
2814 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2815 * of whether luns will be enabled or disabled
2816 * for Optimized Access Storage (OAS) operations.
2817 * @dev: class device that is converted into a Scsi_host.
2818 * @attr: device attribute, not used.
2819 * @buf: buffer for passing information.
2820 * @count: Size of the data buffer.
2821 *
2822 * Returns:
2823 * -EINVAL count is invalid, invalid wwpn byte invalid
2824 * -EPERM oas is not supported by hba
2825 * value of count on success
2826 **/
2827static ssize_t
2828lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2829 const char *buf, size_t count)
2830{
2831 struct Scsi_Host *shost = class_to_shost(dev);
2832 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2833 int val = 0;
2834
James Smartf38fa0b2014-04-04 13:52:21 -04002835 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002836 return -EPERM;
2837
2838 if (!isdigit(buf[0]))
2839 return -EINVAL;
2840
2841 if (sscanf(buf, "%i", &val) != 1)
2842 return -EINVAL;
2843
2844 if ((val != 0) && (val != 1))
2845 return -EINVAL;
2846
2847 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002848 return strlen(buf);
2849}
2850static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2851 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2852
2853/**
2854 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2855 * Storage (OAS) lun returned by the
2856 * lpfc_oas_lun_show function.
2857 * @dev: class device that is converted into a Scsi_host.
2858 * @attr: device attribute, not used.
2859 * @buf: buffer for passing information.
2860 *
2861 * Returns:
2862 * size of formatted string.
2863 **/
2864static ssize_t
2865lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2866 char *buf)
2867{
2868 struct Scsi_Host *shost = class_to_shost(dev);
2869 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2870
2871 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2872 return -EFAULT;
2873
2874 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2875}
2876static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2877 lpfc_oas_lun_status_show, NULL);
2878
2879
2880/**
2881 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2882 * (OAS) operations.
2883 * @phba: lpfc_hba pointer.
2884 * @ndlp: pointer to fcp target node.
2885 * @lun: the fc lun for setting oas state.
2886 * @oas_state: the oas state to be set to the lun.
2887 *
2888 * Returns:
2889 * SUCCESS : 0
2890 * -EPERM OAS is not enabled or not supported by this port.
2891 *
2892 */
2893static size_t
2894lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002895 uint8_t tgt_wwpn[], uint64_t lun,
2896 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002897{
2898
2899 int rc = 0;
2900
James Smartf38fa0b2014-04-04 13:52:21 -04002901 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002902 return -EPERM;
2903
2904 if (oas_state) {
2905 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002906 (struct lpfc_name *)tgt_wwpn,
2907 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002908 rc = -ENOMEM;
2909 } else {
2910 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002911 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002912 }
2913 return rc;
2914
2915}
2916
2917/**
2918 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2919 * Access Storage (OAS) operations.
2920 * @phba: lpfc_hba pointer.
2921 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2922 * @tgt_wwpn: wwpn of the target associated with the returned lun
2923 * @lun_status: status of the lun returned lun
2924 *
2925 * Returns the first or next lun enabled for OAS operations for the vport/target
2926 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2927 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2928 *
2929 * Return:
2930 * lun that is OAS enabled for the vport/target
2931 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2932 */
2933static uint64_t
2934lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002935 uint8_t tgt_wwpn[], uint32_t *lun_status,
2936 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002937{
2938 uint64_t found_lun;
2939
2940 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2941 return NOT_OAS_ENABLED_LUN;
2942 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2943 phba->sli4_hba.oas_next_vpt_wwpn,
2944 (struct lpfc_name *)
2945 phba->sli4_hba.oas_next_tgt_wwpn,
2946 &phba->sli4_hba.oas_next_lun,
2947 (struct lpfc_name *)vpt_wwpn,
2948 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002949 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002950 return found_lun;
2951 else
2952 return NOT_OAS_ENABLED_LUN;
2953}
2954
2955/**
2956 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2957 * @phba: lpfc_hba pointer.
2958 * @vpt_wwpn: vport wwpn by reference.
2959 * @tgt_wwpn: target wwpn by reference.
2960 * @lun: the fc lun for setting oas state.
2961 * @oas_state: the oas state to be set to the oas_lun.
2962 *
2963 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2964 * a lun for OAS operations.
2965 *
2966 * Return:
2967 * SUCCESS: 0
2968 * -ENOMEM: failed to enable an lun for OAS operations
2969 * -EPERM: OAS is not enabled
2970 */
2971static ssize_t
2972lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2973 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002974 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002975{
2976
2977 int rc;
2978
2979 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002980 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002981 return rc;
2982}
2983
2984/**
2985 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2986 * @dev: class device that is converted into a Scsi_host.
2987 * @attr: device attribute, not used.
2988 * @buf: buffer for passing information.
2989 *
2990 * This routine returns a lun enabled for OAS each time the function
2991 * is called.
2992 *
2993 * Returns:
2994 * SUCCESS: size of formatted string.
2995 * -EFAULT: target or vport wwpn was not set properly.
2996 * -EPERM: oas is not enabled.
2997 **/
2998static ssize_t
2999lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
3000 char *buf)
3001{
3002 struct Scsi_Host *shost = class_to_shost(dev);
3003 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3004
3005 uint64_t oas_lun;
3006 int len = 0;
3007
James Smartf38fa0b2014-04-04 13:52:21 -04003008 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003009 return -EPERM;
3010
3011 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3012 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
3013 return -EFAULT;
3014
3015 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3016 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
3017 return -EFAULT;
3018
3019 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
3020 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08003021 &phba->cfg_oas_lun_status,
3022 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05003023 if (oas_lun != NOT_OAS_ENABLED_LUN)
3024 phba->cfg_oas_flags |= OAS_LUN_VALID;
3025
3026 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
3027
3028 return len;
3029}
3030
3031/**
3032 * lpfc_oas_lun_store - Sets the OAS state for lun
3033 * @dev: class device that is converted into a Scsi_host.
3034 * @attr: device attribute, not used.
3035 * @buf: buffer for passing information.
3036 *
3037 * This function sets the OAS state for lun. Before this function is called,
3038 * the vport wwpn, target wwpn, and oas state need to be set.
3039 *
3040 * Returns:
3041 * SUCCESS: size of formatted string.
3042 * -EFAULT: target or vport wwpn was not set properly.
3043 * -EPERM: oas is not enabled.
3044 * size of formatted string.
3045 **/
3046static ssize_t
3047lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3048 const char *buf, size_t count)
3049{
3050 struct Scsi_Host *shost = class_to_shost(dev);
3051 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3052 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003053 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003054 ssize_t rc;
3055
James Smartf38fa0b2014-04-04 13:52:21 -04003056 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003057 return -EPERM;
3058
3059 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3060 return -EFAULT;
3061
3062 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3063 return -EFAULT;
3064
3065 if (!isdigit(buf[0]))
3066 return -EINVAL;
3067
3068 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3069 return -EINVAL;
3070
James Smartb5749fe2016-12-19 15:07:26 -08003071 pri = phba->cfg_oas_priority;
3072 if (pri == 0)
3073 pri = phba->cfg_XLanePriority;
3074
James Smart1ba981f2014-02-20 09:56:45 -05003075 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003076 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3077 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003078 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3079 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003080 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003081
3082 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003083 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003084 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003085 if (rc)
3086 return rc;
3087
3088 return count;
3089}
3090static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3091 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003092
James Smartf358dd02017-02-12 13:52:34 -08003093int lpfc_enable_nvmet_cnt;
3094unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3095 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3096 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3097module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3098MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3099
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003100static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003101module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003102MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3103 " 0 - none,"
3104 " 1 - poll with interrupts enabled"
3105 " 3 - poll and disable FCP ring interrupts");
3106
Joe Perchesb6b996b2017-12-19 10:15:07 -08003107static DEVICE_ATTR_RW(lpfc_poll);
dea31012005-04-17 16:05:31 -05003108
James Smart96418b52017-03-04 09:30:31 -08003109int lpfc_no_hba_reset_cnt;
3110unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3112module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3113MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3114
James Smart12247e82016-07-06 12:36:09 -07003115LPFC_ATTR(sli_mode, 0, 0, 3,
3116 "SLI mode selector:"
3117 " 0 - auto (SLI-3 if supported),"
3118 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3119 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003120
James Smart458c0832016-07-06 12:36:07 -07003121LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3122 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003123
James Smart7d791df2011-07-22 18:37:52 -04003124LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3125 "FCF Fast failover=1 Priority failover=2");
3126
James Smarte5771b42013-03-01 16:37:14 -05003127/*
3128# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3129# 0x0 = disabled, XRI/OXID use not tracked.
3130# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3131# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3132*/
James Smart31202b02016-10-13 15:06:08 -07003133LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3134 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003135
dea31012005-04-17 16:05:31 -05003136/*
James Smart84d1b002010-02-12 14:42:33 -05003137# lpfc_suppress_link_up: Bring link up at initialization
3138# 0x0 = bring link up (issue MBX_INIT_LINK)
3139# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3140# 0x2 = never bring up link
3141# Default value is 0.
3142*/
James Smarte40a02c2010-02-26 14:13:54 -05003143LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3144 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3145 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003146/*
3147# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3148# 1 - (1024)
3149# 2 - (2048)
3150# 3 - (3072)
3151# 4 - (4096)
3152# 5 - (5120)
3153*/
3154static ssize_t
3155lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3156{
3157 struct Scsi_Host *shost = class_to_shost(dev);
3158 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3159
3160 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3161}
3162
3163static DEVICE_ATTR(iocb_hw, S_IRUGO,
3164 lpfc_iocb_hw_show, NULL);
3165static ssize_t
3166lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3167{
3168 struct Scsi_Host *shost = class_to_shost(dev);
3169 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003170 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003171
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003172 return snprintf(buf, PAGE_SIZE, "%d\n",
3173 pring ? pring->txq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003174}
3175
3176static DEVICE_ATTR(txq_hw, S_IRUGO,
3177 lpfc_txq_hw_show, NULL);
3178static ssize_t
3179lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3180 char *buf)
3181{
3182 struct Scsi_Host *shost = class_to_shost(dev);
3183 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003184 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003185
Dick Kennedy1234a6d2017-09-29 17:34:29 -07003186 return snprintf(buf, PAGE_SIZE, "%d\n",
3187 pring ? pring->txcmplq_max : 0);
James Smart2a9bf3d2010-06-07 15:24:45 -04003188}
3189
3190static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3191 lpfc_txcmplq_hw_show, NULL);
3192
James Smart0d8c8ba2016-10-13 15:06:07 -07003193LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003194 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003195
3196/*
James Smartc01f3202006-08-18 17:47:08 -04003197# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3198# until the timer expires. Value range is [0,255]. Default value is 30.
3199*/
3200static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3201static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3202module_param(lpfc_nodev_tmo, int, 0);
3203MODULE_PARM_DESC(lpfc_nodev_tmo,
3204 "Seconds driver will hold I/O waiting "
3205 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003206
3207/**
James Smart3621a712009-04-06 18:47:14 -04003208 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003209 * @dev: class converted to a Scsi_host structure.
3210 * @attr: device attribute, not used.
3211 * @buf: on return contains the dev loss timeout in decimal.
3212 *
3213 * Returns: size of formatted string.
3214 **/
James Smartc01f3202006-08-18 17:47:08 -04003215static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003216lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3217 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003218{
Tony Jonesee959b02008-02-22 00:13:36 +01003219 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003220 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003221
James Smart3de2a652007-08-02 11:09:59 -04003222 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003223}
3224
James Smarte59058c2008-08-24 21:49:00 -04003225/**
James Smart3621a712009-04-06 18:47:14 -04003226 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003227 * @vport: lpfc vport structure pointer.
3228 * @val: contains the nodev timeout value.
3229 *
3230 * Description:
3231 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3232 * a kernel error message is printed and zero is returned.
3233 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3234 * Otherwise nodev tmo is set to the default value.
3235 *
3236 * Returns:
3237 * zero if already set or if val is in range
3238 * -EINVAL val out of range
3239 **/
James Smartc01f3202006-08-18 17:47:08 -04003240static int
James Smart3de2a652007-08-02 11:09:59 -04003241lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003242{
James Smart3de2a652007-08-02 11:09:59 -04003243 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3244 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3245 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003246 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003247 "0407 Ignoring lpfc_nodev_tmo module "
3248 "parameter because lpfc_devloss_tmo "
3249 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003250 return 0;
3251 }
3252
3253 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003254 vport->cfg_nodev_tmo = val;
3255 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003256 return 0;
3257 }
James Smarte8b62012007-08-02 11:10:09 -04003258 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3259 "0400 lpfc_nodev_tmo attribute cannot be set to"
3260 " %d, allowed range is [%d, %d]\n",
3261 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003262 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003263 return -EINVAL;
3264}
3265
James Smarte59058c2008-08-24 21:49:00 -04003266/**
James Smart3621a712009-04-06 18:47:14 -04003267 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003268 * @vport: lpfc vport structure pointer.
3269 *
3270 * Description:
3271 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3272 **/
James Smart7054a602007-04-25 09:52:34 -04003273static void
James Smart3de2a652007-08-02 11:09:59 -04003274lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003275{
James Smart858c9f62007-06-17 19:56:39 -05003276 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003277 struct lpfc_nodelist *ndlp;
3278
James Smart51ef4c22007-08-02 11:10:31 -04003279 shost = lpfc_shost_from_vport(vport);
3280 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003281 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3282 if (!NLP_CHK_NODE_ACT(ndlp))
3283 continue;
3284 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003285 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003286#if (IS_ENABLED(CONFIG_NVME_FC))
3287 if (ndlp->nrport)
3288 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport,
3289 vport->cfg_devloss_tmo);
3290#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003291 }
James Smart51ef4c22007-08-02 11:10:31 -04003292 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003293}
3294
James Smarte59058c2008-08-24 21:49:00 -04003295/**
James Smart3621a712009-04-06 18:47:14 -04003296 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003297 * @vport: lpfc vport structure pointer.
3298 * @val: contains the tmo value.
3299 *
3300 * Description:
3301 * If the devloss tmo is already set or the vport dev loss tmo has changed
3302 * then a kernel error message is printed and zero is returned.
3303 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3304 * Otherwise nodev tmo is set to the default value.
3305 *
3306 * Returns:
3307 * zero if already set or if val is in range
3308 * -EINVAL val out of range
3309 **/
James Smartc01f3202006-08-18 17:47:08 -04003310static int
James Smart3de2a652007-08-02 11:09:59 -04003311lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003312{
James Smart3de2a652007-08-02 11:09:59 -04003313 if (vport->dev_loss_tmo_changed ||
3314 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003315 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003316 "0401 Ignoring change to lpfc_nodev_tmo "
3317 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003318 return 0;
3319 }
James Smartc01f3202006-08-18 17:47:08 -04003320 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003321 vport->cfg_nodev_tmo = val;
3322 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003323 /*
3324 * For compat: set the fc_host dev loss so new rports
3325 * will get the value.
3326 */
3327 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003328 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003329 return 0;
3330 }
James Smarte8b62012007-08-02 11:10:09 -04003331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003332 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003333 "%d, allowed range is [%d, %d]\n",
3334 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003335 return -EINVAL;
3336}
3337
James Smart3de2a652007-08-02 11:09:59 -04003338lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003339
Joe Perchesb6b996b2017-12-19 10:15:07 -08003340static DEVICE_ATTR_RW(lpfc_nodev_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003341
3342/*
3343# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3344# disappear until the timer expires. Value range is [0,255]. Default
3345# value is 30.
3346*/
James Smartab56dc22011-02-16 12:39:57 -05003347module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003348MODULE_PARM_DESC(lpfc_devloss_tmo,
3349 "Seconds driver will hold I/O waiting "
3350 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003351lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3352 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3353lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003354
3355/**
James Smart3621a712009-04-06 18:47:14 -04003356 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003357 * @vport: lpfc vport structure pointer.
3358 * @val: contains the tmo value.
3359 *
3360 * Description:
3361 * If val is in a valid range then set the vport nodev tmo,
3362 * devloss tmo, also set the vport dev loss tmo changed flag.
3363 * Else a kernel error message is printed.
3364 *
3365 * Returns:
3366 * zero if val is in range
3367 * -EINVAL val out of range
3368 **/
James Smartc01f3202006-08-18 17:47:08 -04003369static int
James Smart3de2a652007-08-02 11:09:59 -04003370lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003371{
3372 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003373 vport->cfg_nodev_tmo = val;
3374 vport->cfg_devloss_tmo = val;
3375 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003376 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003377 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003378 return 0;
3379 }
3380
James Smarte8b62012007-08-02 11:10:09 -04003381 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003382 "0404 lpfc_devloss_tmo attribute cannot be set to "
3383 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003384 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003385 return -EINVAL;
3386}
3387
James Smart3de2a652007-08-02 11:09:59 -04003388lpfc_vport_param_store(devloss_tmo)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003389static DEVICE_ATTR_RW(lpfc_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003390
3391/*
James Smartf358dd02017-02-12 13:52:34 -08003392 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3393 * lpfc_suppress_rsp = 0 Disable
3394 * lpfc_suppress_rsp = 1 Enable (default)
3395 *
3396 */
3397LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3398 "Enable suppress rsp feature is firmware supports it");
3399
3400/*
James Smart2d7dbc42017-02-12 13:52:35 -08003401 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
James Smartbcb24f62017-11-20 16:00:36 -08003402 * lpfc_nvmet_mrq = 0 driver will calcualte optimal number of RQ pairs
James Smart2d7dbc42017-02-12 13:52:35 -08003403 * lpfc_nvmet_mrq = 1 use a single RQ pair
3404 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3405 *
3406 */
3407LPFC_ATTR_R(nvmet_mrq,
James Smartbcb24f62017-11-20 16:00:36 -08003408 LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_AUTO, LPFC_NVMET_MRQ_MAX,
James Smart2d7dbc42017-02-12 13:52:35 -08003409 "Specify number of RQ pairs for processing NVMET cmds");
3410
3411/*
James Smart895427b2017-02-12 13:52:30 -08003412 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3413 * Supported Values: 1 - register just FCP
3414 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003415 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003416 */
James Smart7d708032017-03-08 14:36:01 -08003417LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003418 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003419 "Enable FC4 Protocol support - FCP / NVME");
James Smart895427b2017-02-12 13:52:30 -08003420
3421/*
3422 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3423 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003424 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3425 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003426 *
3427 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3428 * The remaining XRIs get split up based on lpfc_xri_split per port:
3429 *
3430 * Supported Values are in percentages
3431 * the xri_split value is the percentage the SCSI port will get. The remaining
3432 * percentage will go to NVME.
3433 */
3434LPFC_ATTR_R(xri_split, 50, 10, 90,
Dick Kennedycf4c8c82017-09-29 17:34:38 -07003435 "Percentage of FCP XRI resources versus NVME");
James Smart895427b2017-02-12 13:52:30 -08003436
3437/*
dea31012005-04-17 16:05:31 -05003438# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3439# deluged with LOTS of information.
3440# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003441# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003442*/
James Smartf4b4c682009-05-22 14:53:12 -04003443LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003444 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003445
3446/*
James Smart7ee5d432007-10-27 13:37:17 -04003447# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3448# objects that have been registered with the nameserver after login.
3449*/
James Smartcf971242012-03-01 22:37:32 -05003450LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003451 "Deregister nameserver objects before LOGO");
3452
3453/*
dea31012005-04-17 16:05:31 -05003454# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003455# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3456# If this parameter value is greater than 1/8th the maximum number of exchanges
3457# supported by the HBA port, then the lun queue depth will be reduced to
3458# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003459*/
James Smart572709e2013-07-15 18:32:43 -04003460LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003461 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003462
3463/*
James Smart7dc517d2010-07-14 15:32:10 -04003464# tgt_queue_depth: This parameter is used to limit the number of outstanding
3465# commands per target port. Value range is [10,65535]. Default value is 65535.
3466*/
3467LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003468 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003469
3470/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003471# hba_queue_depth: This parameter is used to limit the number of outstanding
3472# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3473# value is greater than the maximum number of exchanges supported by the HBA,
3474# then maximum number of exchanges supported by the HBA is used to determine
3475# the hba_queue_depth.
3476*/
3477LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3478 "Max number of FCP commands we can queue to a lpfc HBA");
3479
3480/*
James Smart92d7f7b2007-06-17 19:56:38 -05003481# peer_port_login: This parameter allows/prevents logins
3482# between peer ports hosted on the same physical port.
3483# When this parameter is set 0 peer ports of same physical port
3484# are not allowed to login to each other.
3485# When this parameter is set 1 peer ports of same physical port
3486# are allowed to login to each other.
3487# Default value of this parameter is 0.
3488*/
James Smart3de2a652007-08-02 11:09:59 -04003489LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3490 "Allow peer ports on the same physical port to login to each "
3491 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003492
3493/*
James Smart3de2a652007-08-02 11:09:59 -04003494# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003495# between Virtual Ports and remote initiators.
3496# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3497# other initiators and will attempt to PLOGI all remote ports.
3498# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3499# remote ports and will not attempt to PLOGI to other initiators.
3500# This parameter does not restrict to the physical port.
3501# This parameter does not restrict logins to Fabric resident remote ports.
3502# Default value of this parameter is 1.
3503*/
James Smart3de2a652007-08-02 11:09:59 -04003504static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003505module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003506MODULE_PARM_DESC(lpfc_restrict_login,
3507 "Restrict virtual ports login to remote initiators.");
3508lpfc_vport_param_show(restrict_login);
3509
James Smarte59058c2008-08-24 21:49:00 -04003510/**
James Smart3621a712009-04-06 18:47:14 -04003511 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003512 * @vport: lpfc vport structure pointer.
3513 * @val: contains the restrict login value.
3514 *
3515 * Description:
3516 * If val is not in a valid range then log a kernel error message and set
3517 * the vport restrict login to one.
3518 * If the port type is physical clear the restrict login flag and return.
3519 * Else set the restrict login flag to val.
3520 *
3521 * Returns:
3522 * zero if val is in range
3523 * -EINVAL val out of range
3524 **/
James Smart3de2a652007-08-02 11:09:59 -04003525static int
3526lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3527{
3528 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003529 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003530 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003531 "be set to %d, allowed range is [0, 1]\n",
3532 val);
James Smart3de2a652007-08-02 11:09:59 -04003533 vport->cfg_restrict_login = 1;
3534 return -EINVAL;
3535 }
3536 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3537 vport->cfg_restrict_login = 0;
3538 return 0;
3539 }
3540 vport->cfg_restrict_login = val;
3541 return 0;
3542}
3543
James Smarte59058c2008-08-24 21:49:00 -04003544/**
James Smart3621a712009-04-06 18:47:14 -04003545 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003546 * @vport: lpfc vport structure pointer.
3547 * @val: contains the restrict login value.
3548 *
3549 * Description:
3550 * If val is not in a valid range then log a kernel error message and set
3551 * the vport restrict login to one.
3552 * If the port type is physical and the val is not zero log a kernel
3553 * error message, clear the restrict login flag and return zero.
3554 * Else set the restrict login flag to val.
3555 *
3556 * Returns:
3557 * zero if val is in range
3558 * -EINVAL val out of range
3559 **/
James Smart3de2a652007-08-02 11:09:59 -04003560static int
3561lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3562{
3563 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003564 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003565 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003566 "be set to %d, allowed range is [0, 1]\n",
3567 val);
James Smart3de2a652007-08-02 11:09:59 -04003568 vport->cfg_restrict_login = 1;
3569 return -EINVAL;
3570 }
3571 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003572 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3573 "0468 lpfc_restrict_login must be 0 for "
3574 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003575 vport->cfg_restrict_login = 0;
3576 return 0;
3577 }
3578 vport->cfg_restrict_login = val;
3579 return 0;
3580}
3581lpfc_vport_param_store(restrict_login);
Joe Perchesb6b996b2017-12-19 10:15:07 -08003582static DEVICE_ATTR_RW(lpfc_restrict_login);
James Smart92d7f7b2007-06-17 19:56:38 -05003583
3584/*
dea31012005-04-17 16:05:31 -05003585# Some disk devices have a "select ID" or "select Target" capability.
3586# From a protocol standpoint "select ID" usually means select the
3587# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3588# annex" which contains a table that maps a "select ID" (a number
3589# between 0 and 7F) to an ALPA. By default, for compatibility with
3590# older drivers, the lpfc driver scans this table from low ALPA to high
3591# ALPA.
3592#
3593# Turning on the scan-down variable (on = 1, off = 0) will
3594# cause the lpfc driver to use an inverted table, effectively
3595# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3596#
3597# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3598# and will not work across a fabric. Also this parameter will take
3599# effect only in the case when ALPA map is not available.)
3600*/
James Smart3de2a652007-08-02 11:09:59 -04003601LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3602 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003603
3604/*
dea31012005-04-17 16:05:31 -05003605# lpfc_topology: link topology for init link
3606# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003607# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003608# 0x02 = attempt point-to-point mode only
3609# 0x04 = attempt loop mode only
3610# 0x06 = attempt point-to-point mode then loop
3611# Set point-to-point mode if you want to run as an N_Port.
3612# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3613# Default value is 0.
3614*/
James Smart0a035432016-10-13 15:06:10 -07003615LPFC_ATTR(topology, 0, 0, 6,
3616 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003617
3618/**
James Smart3621a712009-04-06 18:47:14 -04003619 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003620 * @phba: lpfc_hba pointer.
3621 * @val: topology value.
3622 *
3623 * Description:
3624 * If val is in a valid range then set the adapter's topology field and
3625 * issue a lip; if the lip fails reset the topology to the old value.
3626 *
3627 * If the value is not in range log a kernel error message and return an error.
3628 *
3629 * Returns:
3630 * zero if val is in range and lip okay
3631 * non-zero return value from lpfc_issue_lip()
3632 * -EINVAL val out of range
3633 **/
James Smarta257bf92009-04-06 18:48:10 -04003634static ssize_t
3635lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3636 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003637{
James Smarta257bf92009-04-06 18:48:10 -04003638 struct Scsi_Host *shost = class_to_shost(dev);
3639 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3640 struct lpfc_hba *phba = vport->phba;
3641 int val = 0;
3642 int nolip = 0;
3643 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003644 int err;
3645 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003646
3647 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3648 nolip = 1;
3649 val_buf = &buf[strlen("nolip ")];
3650 }
3651
3652 if (!isdigit(val_buf[0]))
3653 return -EINVAL;
3654 if (sscanf(val_buf, "%i", &val) != 1)
3655 return -EINVAL;
3656
James Smart83108bd2008-01-11 01:53:09 -05003657 if (val >= 0 && val <= 6) {
3658 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003659 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3660 val == 4) {
3661 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3662 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003663 val);
James Smartff78d8f2011-12-13 13:21:35 -05003664 return -EINVAL;
3665 }
James Smartd38dd522015-08-31 16:48:17 -04003666 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3667 val == 4) {
3668 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3669 "3114 Loop mode not supported\n");
3670 return -EINVAL;
3671 }
3672 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003673 if (nolip)
3674 return strlen(buf);
3675
James Smart88a2cfb2011-07-22 18:36:33 -04003676 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3677 "3054 lpfc_topology changed from %d to %d\n",
3678 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003679 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3680 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003681 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003682 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003683 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003684 return -EINVAL;
3685 } else
3686 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003687 }
3688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3689 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3690 "allowed range is [0, 6]\n",
3691 phba->brd_no, val);
3692 return -EINVAL;
3693}
James Smart0a035432016-10-13 15:06:10 -07003694
James Smart83108bd2008-01-11 01:53:09 -05003695lpfc_param_show(topology)
Joe Perchesb6b996b2017-12-19 10:15:07 -08003696static DEVICE_ATTR_RW(lpfc_topology);
dea31012005-04-17 16:05:31 -05003697
James Smart21e9a0a2009-05-22 14:53:21 -04003698/**
3699 * lpfc_static_vport_show: Read callback function for
3700 * lpfc_static_vport sysfs file.
3701 * @dev: Pointer to class device object.
3702 * @attr: device attribute structure.
3703 * @buf: Data buffer.
3704 *
3705 * This function is the read call back function for
3706 * lpfc_static_vport sysfs file. The lpfc_static_vport
3707 * sysfs file report the mageability of the vport.
3708 **/
3709static ssize_t
3710lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3711 char *buf)
3712{
3713 struct Scsi_Host *shost = class_to_shost(dev);
3714 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3715 if (vport->vport_flag & STATIC_VPORT)
3716 sprintf(buf, "1\n");
3717 else
3718 sprintf(buf, "0\n");
3719
3720 return strlen(buf);
3721}
3722
3723/*
3724 * Sysfs attribute to control the statistical data collection.
3725 */
Joe Perchesc828a892017-12-19 10:15:08 -08003726static DEVICE_ATTR_RO(lpfc_static_vport);
James Smartea2151b2008-09-07 11:52:10 -04003727
3728/**
James Smart3621a712009-04-06 18:47:14 -04003729 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003730 * @dev: Pointer to class device.
3731 * @buf: Data buffer.
3732 * @count: Size of the data buffer.
3733 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08003734 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04003735 * sysfs file. This function parse the command written to the sysfs file
3736 * and take appropriate action. These commands are used for controlling
3737 * driver statistical data collection.
3738 * Following are the command this function handles.
3739 *
3740 * setbucket <bucket_type> <base> <step>
3741 * = Set the latency buckets.
3742 * destroybucket = destroy all the buckets.
3743 * start = start data collection
3744 * stop = stop data collection
3745 * reset = reset the collected data
3746 **/
3747static ssize_t
3748lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3749 const char *buf, size_t count)
3750{
3751 struct Scsi_Host *shost = class_to_shost(dev);
3752 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3753 struct lpfc_hba *phba = vport->phba;
3754#define LPFC_MAX_DATA_CTRL_LEN 1024
3755 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3756 unsigned long i;
3757 char *str_ptr, *token;
3758 struct lpfc_vport **vports;
3759 struct Scsi_Host *v_shost;
3760 char *bucket_type_str, *base_str, *step_str;
3761 unsigned long base, step, bucket_type;
3762
3763 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003764 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003765 return -EINVAL;
3766
James Smarteb016562014-09-03 12:58:06 -04003767 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003768 str_ptr = &bucket_data[0];
3769 /* Ignore this token - this is command token */
3770 token = strsep(&str_ptr, "\t ");
3771 if (!token)
3772 return -EINVAL;
3773
3774 bucket_type_str = strsep(&str_ptr, "\t ");
3775 if (!bucket_type_str)
3776 return -EINVAL;
3777
3778 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3779 bucket_type = LPFC_LINEAR_BUCKET;
3780 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3781 bucket_type = LPFC_POWER2_BUCKET;
3782 else
3783 return -EINVAL;
3784
3785 base_str = strsep(&str_ptr, "\t ");
3786 if (!base_str)
3787 return -EINVAL;
3788 base = simple_strtoul(base_str, NULL, 0);
3789
3790 step_str = strsep(&str_ptr, "\t ");
3791 if (!step_str)
3792 return -EINVAL;
3793 step = simple_strtoul(step_str, NULL, 0);
3794 if (!step)
3795 return -EINVAL;
3796
3797 /* Block the data collection for every vport */
3798 vports = lpfc_create_vport_work_array(phba);
3799 if (vports == NULL)
3800 return -ENOMEM;
3801
James Smartf4b4c682009-05-22 14:53:12 -04003802 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003803 v_shost = lpfc_shost_from_vport(vports[i]);
3804 spin_lock_irq(v_shost->host_lock);
3805 /* Block and reset data collection */
3806 vports[i]->stat_data_blocked = 1;
3807 if (vports[i]->stat_data_enabled)
3808 lpfc_vport_reset_stat_data(vports[i]);
3809 spin_unlock_irq(v_shost->host_lock);
3810 }
3811
3812 /* Set the bucket attributes */
3813 phba->bucket_type = bucket_type;
3814 phba->bucket_base = base;
3815 phba->bucket_step = step;
3816
James Smartf4b4c682009-05-22 14:53:12 -04003817 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003818 v_shost = lpfc_shost_from_vport(vports[i]);
3819
3820 /* Unblock data collection */
3821 spin_lock_irq(v_shost->host_lock);
3822 vports[i]->stat_data_blocked = 0;
3823 spin_unlock_irq(v_shost->host_lock);
3824 }
3825 lpfc_destroy_vport_work_array(phba, vports);
3826 return strlen(buf);
3827 }
3828
3829 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3830 vports = lpfc_create_vport_work_array(phba);
3831 if (vports == NULL)
3832 return -ENOMEM;
3833
James Smartf4b4c682009-05-22 14:53:12 -04003834 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003835 v_shost = lpfc_shost_from_vport(vports[i]);
3836 spin_lock_irq(shost->host_lock);
3837 vports[i]->stat_data_blocked = 1;
3838 lpfc_free_bucket(vport);
3839 vport->stat_data_enabled = 0;
3840 vports[i]->stat_data_blocked = 0;
3841 spin_unlock_irq(shost->host_lock);
3842 }
3843 lpfc_destroy_vport_work_array(phba, vports);
3844 phba->bucket_type = LPFC_NO_BUCKET;
3845 phba->bucket_base = 0;
3846 phba->bucket_step = 0;
3847 return strlen(buf);
3848 }
3849
3850 if (!strncmp(buf, "start", strlen("start"))) {
3851 /* If no buckets configured return error */
3852 if (phba->bucket_type == LPFC_NO_BUCKET)
3853 return -EINVAL;
3854 spin_lock_irq(shost->host_lock);
3855 if (vport->stat_data_enabled) {
3856 spin_unlock_irq(shost->host_lock);
3857 return strlen(buf);
3858 }
3859 lpfc_alloc_bucket(vport);
3860 vport->stat_data_enabled = 1;
3861 spin_unlock_irq(shost->host_lock);
3862 return strlen(buf);
3863 }
3864
3865 if (!strncmp(buf, "stop", strlen("stop"))) {
3866 spin_lock_irq(shost->host_lock);
3867 if (vport->stat_data_enabled == 0) {
3868 spin_unlock_irq(shost->host_lock);
3869 return strlen(buf);
3870 }
3871 lpfc_free_bucket(vport);
3872 vport->stat_data_enabled = 0;
3873 spin_unlock_irq(shost->host_lock);
3874 return strlen(buf);
3875 }
3876
3877 if (!strncmp(buf, "reset", strlen("reset"))) {
3878 if ((phba->bucket_type == LPFC_NO_BUCKET)
3879 || !vport->stat_data_enabled)
3880 return strlen(buf);
3881 spin_lock_irq(shost->host_lock);
3882 vport->stat_data_blocked = 1;
3883 lpfc_vport_reset_stat_data(vport);
3884 vport->stat_data_blocked = 0;
3885 spin_unlock_irq(shost->host_lock);
3886 return strlen(buf);
3887 }
3888 return -EINVAL;
3889}
3890
3891
3892/**
James Smart3621a712009-04-06 18:47:14 -04003893 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003894 * @dev: Pointer to class device object.
3895 * @buf: Data buffer.
3896 *
3897 * This function is the read call back function for
3898 * lpfc_stat_data_ctrl sysfs file. This function report the
3899 * current statistical data collection state.
3900 **/
3901static ssize_t
3902lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3903 char *buf)
3904{
3905 struct Scsi_Host *shost = class_to_shost(dev);
3906 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3907 struct lpfc_hba *phba = vport->phba;
3908 int index = 0;
3909 int i;
3910 char *bucket_type;
3911 unsigned long bucket_value;
3912
3913 switch (phba->bucket_type) {
3914 case LPFC_LINEAR_BUCKET:
3915 bucket_type = "linear";
3916 break;
3917 case LPFC_POWER2_BUCKET:
3918 bucket_type = "power2";
3919 break;
3920 default:
3921 bucket_type = "No Bucket";
3922 break;
3923 }
3924
3925 sprintf(&buf[index], "Statistical Data enabled :%d, "
3926 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3927 " Bucket step :%d\nLatency Ranges :",
3928 vport->stat_data_enabled, vport->stat_data_blocked,
3929 bucket_type, phba->bucket_base, phba->bucket_step);
3930 index = strlen(buf);
3931 if (phba->bucket_type != LPFC_NO_BUCKET) {
3932 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3933 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3934 bucket_value = phba->bucket_base +
3935 phba->bucket_step * i;
3936 else
3937 bucket_value = phba->bucket_base +
3938 (1 << i) * phba->bucket_step;
3939
3940 if (index + 10 > PAGE_SIZE)
3941 break;
3942 sprintf(&buf[index], "%08ld ", bucket_value);
3943 index = strlen(buf);
3944 }
3945 }
3946 sprintf(&buf[index], "\n");
3947 return strlen(buf);
3948}
3949
3950/*
3951 * Sysfs attribute to control the statistical data collection.
3952 */
Joe Perchesb6b996b2017-12-19 10:15:07 -08003953static DEVICE_ATTR_RW(lpfc_stat_data_ctrl);
James Smartea2151b2008-09-07 11:52:10 -04003954
3955/*
3956 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3957 */
3958
3959/*
3960 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3961 * for each target.
3962 */
3963#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3964#define MAX_STAT_DATA_SIZE_PER_TARGET \
3965 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3966
3967
3968/**
James Smart3621a712009-04-06 18:47:14 -04003969 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003970 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003971 * @kobj: Pointer to the kernel object
3972 * @bin_attr: Attribute object
3973 * @buff: Buffer pointer
3974 * @off: File offset
3975 * @count: Buffer size
3976 *
3977 * This function is the read call back function for lpfc_drvr_stat_data
3978 * sysfs file. This function export the statistical data to user
3979 * applications.
3980 **/
3981static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003982sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3983 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003984 char *buf, loff_t off, size_t count)
3985{
3986 struct device *dev = container_of(kobj, struct device,
3987 kobj);
3988 struct Scsi_Host *shost = class_to_shost(dev);
3989 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3990 struct lpfc_hba *phba = vport->phba;
3991 int i = 0, index = 0;
3992 unsigned long nport_index;
3993 struct lpfc_nodelist *ndlp = NULL;
3994 nport_index = (unsigned long)off /
3995 MAX_STAT_DATA_SIZE_PER_TARGET;
3996
3997 if (!vport->stat_data_enabled || vport->stat_data_blocked
3998 || (phba->bucket_type == LPFC_NO_BUCKET))
3999 return 0;
4000
4001 spin_lock_irq(shost->host_lock);
4002 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4003 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
4004 continue;
4005
4006 if (nport_index > 0) {
4007 nport_index--;
4008 continue;
4009 }
4010
4011 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
4012 > count)
4013 break;
4014
4015 if (!ndlp->lat_data)
4016 continue;
4017
4018 /* Print the WWN */
4019 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
4020 ndlp->nlp_portname.u.wwn[0],
4021 ndlp->nlp_portname.u.wwn[1],
4022 ndlp->nlp_portname.u.wwn[2],
4023 ndlp->nlp_portname.u.wwn[3],
4024 ndlp->nlp_portname.u.wwn[4],
4025 ndlp->nlp_portname.u.wwn[5],
4026 ndlp->nlp_portname.u.wwn[6],
4027 ndlp->nlp_portname.u.wwn[7]);
4028
4029 index = strlen(buf);
4030
4031 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4032 sprintf(&buf[index], "%010u,",
4033 ndlp->lat_data[i].cmd_count);
4034 index = strlen(buf);
4035 }
4036 sprintf(&buf[index], "\n");
4037 index = strlen(buf);
4038 }
4039 spin_unlock_irq(shost->host_lock);
4040 return index;
4041}
4042
4043static struct bin_attribute sysfs_drvr_stat_data_attr = {
4044 .attr = {
4045 .name = "lpfc_drvr_stat_data",
4046 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004047 },
4048 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4049 .read = sysfs_drvr_stat_data_read,
4050 .write = NULL,
4051};
4052
dea31012005-04-17 16:05:31 -05004053/*
4054# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4055# connection.
James Smart76a95d72010-11-20 23:11:48 -05004056# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004057*/
James Smarte59058c2008-08-24 21:49:00 -04004058/**
James Smart3621a712009-04-06 18:47:14 -04004059 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004060 * @phba: lpfc_hba pointer.
4061 * @val: link speed value.
4062 *
4063 * Description:
4064 * If val is in a valid range then set the adapter's link speed field and
4065 * issue a lip; if the lip fails reset the link speed to the old value.
4066 *
4067 * Notes:
4068 * If the value is not in range log a kernel error message and return an error.
4069 *
4070 * Returns:
4071 * zero if val is in range and lip okay.
4072 * non-zero return value from lpfc_issue_lip()
4073 * -EINVAL val out of range
4074 **/
James Smarta257bf92009-04-06 18:48:10 -04004075static ssize_t
4076lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4077 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004078{
James Smarta257bf92009-04-06 18:48:10 -04004079 struct Scsi_Host *shost = class_to_shost(dev);
4080 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4081 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004082 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004083 int nolip = 0;
4084 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004085 int err;
James Smartc6918162016-10-13 15:06:16 -07004086 uint32_t prev_val, if_type;
4087
4088 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4089 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4090 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4091 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004092
James Smarta257bf92009-04-06 18:48:10 -04004093 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4094 nolip = 1;
4095 val_buf = &buf[strlen("nolip ")];
4096 }
4097
4098 if (!isdigit(val_buf[0]))
4099 return -EINVAL;
4100 if (sscanf(val_buf, "%i", &val) != 1)
4101 return -EINVAL;
4102
James Smart88a2cfb2011-07-22 18:36:33 -04004103 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4104 "3055 lpfc_link_speed changed from %d to %d %s\n",
4105 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4106
James Smart76a95d72010-11-20 23:11:48 -05004107 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4108 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4109 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4110 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4111 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004112 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4113 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004114 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4115 "2879 lpfc_link_speed attribute cannot be set "
4116 "to %d. Speed is not supported by this port.\n",
4117 val);
James Smart83108bd2008-01-11 01:53:09 -05004118 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004119 }
James Smartff78d8f2011-12-13 13:21:35 -05004120 if (val == LPFC_USER_LINK_SPEED_16G &&
4121 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4122 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4123 "3112 lpfc_link_speed attribute cannot be set "
4124 "to %d. Speed is not supported in loop mode.\n",
4125 val);
4126 return -EINVAL;
4127 }
James Smart76a95d72010-11-20 23:11:48 -05004128 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4129 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004130 prev_val = phba->cfg_link_speed;
4131 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004132 if (nolip)
4133 return strlen(buf);
4134
James Smart83108bd2008-01-11 01:53:09 -05004135 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004136 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004137 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004138 return -EINVAL;
4139 } else
4140 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004141 }
James Smart83108bd2008-01-11 01:53:09 -05004142 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004143 "0469 lpfc_link_speed attribute cannot be set to %d, "
4144 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004145 return -EINVAL;
4146}
4147
4148static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004149module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004150MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4151lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004152
4153/**
James Smart3621a712009-04-06 18:47:14 -04004154 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004155 * @phba: lpfc_hba pointer.
4156 * @val: link speed value.
4157 *
4158 * Description:
4159 * If val is in a valid range then set the adapter's link speed field.
4160 *
4161 * Notes:
4162 * If the value is not in range log a kernel error message, clear the link
4163 * speed and return an error.
4164 *
4165 * Returns:
4166 * zero if val saved.
4167 * -EINVAL val out of range
4168 **/
James Smart83108bd2008-01-11 01:53:09 -05004169static int
4170lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4171{
James Smartff78d8f2011-12-13 13:21:35 -05004172 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4173 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4174 "3111 lpfc_link_speed of %d cannot "
4175 "support loop mode, setting topology to default.\n",
4176 val);
4177 phba->cfg_topology = 0;
4178 }
James Smart76a95d72010-11-20 23:11:48 -05004179 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4180 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004181 phba->cfg_link_speed = val;
4182 return 0;
4183 }
4184 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004185 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004186 "be set to %d, allowed values are "
4187 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004188 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004189 return -EINVAL;
4190}
4191
Joe Perchesb6b996b2017-12-19 10:15:07 -08004192static DEVICE_ATTR_RW(lpfc_link_speed);
dea31012005-04-17 16:05:31 -05004193
4194/*
James Smart0d878412009-10-02 15:16:56 -04004195# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4196# 0 = aer disabled or not supported
4197# 1 = aer supported and enabled (default)
4198# Value range is [0,1]. Default value is 1.
4199*/
James Smart506139a2016-10-13 15:06:09 -07004200LPFC_ATTR(aer_support, 1, 0, 1,
4201 "Enable PCIe device AER support");
4202lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004203
4204/**
4205 * lpfc_aer_support_store - Set the adapter for aer support
4206 *
4207 * @dev: class device that is converted into a Scsi_host.
4208 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004209 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004210 * @count: unused variable.
4211 *
4212 * Description:
4213 * If the val is 1 and currently the device's AER capability was not
4214 * enabled, invoke the kernel's enable AER helper routine, trying to
4215 * enable the device's AER capability. If the helper routine enabling
4216 * AER returns success, update the device's cfg_aer_support flag to
4217 * indicate AER is supported by the device; otherwise, if the device
4218 * AER capability is already enabled to support AER, then do nothing.
4219 *
4220 * If the val is 0 and currently the device's AER support was enabled,
4221 * invoke the kernel's disable AER helper routine. After that, update
4222 * the device's cfg_aer_support flag to indicate AER is not supported
4223 * by the device; otherwise, if the device AER capability is already
4224 * disabled from supporting AER, then do nothing.
4225 *
4226 * Returns:
4227 * length of the buf on success if val is in range the intended mode
4228 * is supported.
4229 * -EINVAL if val out of range or intended mode is not supported.
4230 **/
4231static ssize_t
4232lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4233 const char *buf, size_t count)
4234{
4235 struct Scsi_Host *shost = class_to_shost(dev);
4236 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4237 struct lpfc_hba *phba = vport->phba;
4238 int val = 0, rc = -EINVAL;
4239
4240 if (!isdigit(buf[0]))
4241 return -EINVAL;
4242 if (sscanf(buf, "%i", &val) != 1)
4243 return -EINVAL;
4244
4245 switch (val) {
4246 case 0:
4247 if (phba->hba_flag & HBA_AER_ENABLED) {
4248 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4249 if (!rc) {
4250 spin_lock_irq(&phba->hbalock);
4251 phba->hba_flag &= ~HBA_AER_ENABLED;
4252 spin_unlock_irq(&phba->hbalock);
4253 phba->cfg_aer_support = 0;
4254 rc = strlen(buf);
4255 } else
James Smart891478a2009-11-18 15:40:23 -05004256 rc = -EPERM;
4257 } else {
James Smart0d878412009-10-02 15:16:56 -04004258 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004259 rc = strlen(buf);
4260 }
James Smart0d878412009-10-02 15:16:56 -04004261 break;
4262 case 1:
4263 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4264 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4265 if (!rc) {
4266 spin_lock_irq(&phba->hbalock);
4267 phba->hba_flag |= HBA_AER_ENABLED;
4268 spin_unlock_irq(&phba->hbalock);
4269 phba->cfg_aer_support = 1;
4270 rc = strlen(buf);
4271 } else
James Smart891478a2009-11-18 15:40:23 -05004272 rc = -EPERM;
4273 } else {
James Smart0d878412009-10-02 15:16:56 -04004274 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004275 rc = strlen(buf);
4276 }
James Smart0d878412009-10-02 15:16:56 -04004277 break;
4278 default:
4279 rc = -EINVAL;
4280 break;
4281 }
4282 return rc;
4283}
4284
Joe Perchesb6b996b2017-12-19 10:15:07 -08004285static DEVICE_ATTR_RW(lpfc_aer_support);
James Smart0d878412009-10-02 15:16:56 -04004286
4287/**
4288 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4289 * @dev: class device that is converted into a Scsi_host.
4290 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004291 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004292 * @count: unused variable.
4293 *
4294 * Description:
4295 * If the @buf contains 1 and the device currently has the AER support
4296 * enabled, then invokes the kernel AER helper routine
4297 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4298 * error status register.
4299 *
4300 * Notes:
4301 *
4302 * Returns:
4303 * -EINVAL if the buf does not contain the 1 or the device is not currently
4304 * enabled with the AER support.
4305 **/
4306static ssize_t
4307lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4308 const char *buf, size_t count)
4309{
4310 struct Scsi_Host *shost = class_to_shost(dev);
4311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4312 struct lpfc_hba *phba = vport->phba;
4313 int val, rc = -1;
4314
4315 if (!isdigit(buf[0]))
4316 return -EINVAL;
4317 if (sscanf(buf, "%i", &val) != 1)
4318 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004319 if (val != 1)
4320 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004321
James Smart891478a2009-11-18 15:40:23 -05004322 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004323 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4324
4325 if (rc == 0)
4326 return strlen(buf);
4327 else
James Smart891478a2009-11-18 15:40:23 -05004328 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004329}
4330
4331static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4332 lpfc_aer_cleanup_state);
4333
James Smart912e3ac2011-05-24 11:42:11 -04004334/**
4335 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4336 *
4337 * @dev: class device that is converted into a Scsi_host.
4338 * @attr: device attribute, not used.
4339 * @buf: containing the string the number of vfs to be enabled.
4340 * @count: unused variable.
4341 *
4342 * Description:
4343 * When this api is called either through user sysfs, the driver shall
4344 * try to enable or disable SR-IOV virtual functions according to the
4345 * following:
4346 *
4347 * If zero virtual function has been enabled to the physical function,
4348 * the driver shall invoke the pci enable virtual function api trying
4349 * to enable the virtual functions. If the nr_vfn provided is greater
4350 * than the maximum supported, the maximum virtual function number will
4351 * be used for invoking the api; otherwise, the nr_vfn provided shall
4352 * be used for invoking the api. If the api call returned success, the
4353 * actual number of virtual functions enabled will be set to the driver
4354 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4355 * cfg_sriov_nr_virtfn remains zero.
4356 *
4357 * If none-zero virtual functions have already been enabled to the
4358 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4359 * -EINVAL will be returned and the driver does nothing;
4360 *
4361 * If the nr_vfn provided is zero and none-zero virtual functions have
4362 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4363 * disabling virtual function api shall be invoded to disable all the
4364 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4365 * zero. Otherwise, if zero virtual function has been enabled, do
4366 * nothing.
4367 *
4368 * Returns:
4369 * length of the buf on success if val is in range the intended mode
4370 * is supported.
4371 * -EINVAL if val out of range or intended mode is not supported.
4372 **/
4373static ssize_t
4374lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4375 const char *buf, size_t count)
4376{
4377 struct Scsi_Host *shost = class_to_shost(dev);
4378 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4379 struct lpfc_hba *phba = vport->phba;
4380 struct pci_dev *pdev = phba->pcidev;
4381 int val = 0, rc = -EINVAL;
4382
4383 /* Sanity check on user data */
4384 if (!isdigit(buf[0]))
4385 return -EINVAL;
4386 if (sscanf(buf, "%i", &val) != 1)
4387 return -EINVAL;
4388 if (val < 0)
4389 return -EINVAL;
4390
4391 /* Request disabling virtual functions */
4392 if (val == 0) {
4393 if (phba->cfg_sriov_nr_virtfn > 0) {
4394 pci_disable_sriov(pdev);
4395 phba->cfg_sriov_nr_virtfn = 0;
4396 }
4397 return strlen(buf);
4398 }
4399
4400 /* Request enabling virtual functions */
4401 if (phba->cfg_sriov_nr_virtfn > 0) {
4402 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4403 "3018 There are %d virtual functions "
4404 "enabled on physical function.\n",
4405 phba->cfg_sriov_nr_virtfn);
4406 return -EEXIST;
4407 }
4408
4409 if (val <= LPFC_MAX_VFN_PER_PFN)
4410 phba->cfg_sriov_nr_virtfn = val;
4411 else {
4412 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4413 "3019 Enabling %d virtual functions is not "
4414 "allowed.\n", val);
4415 return -EINVAL;
4416 }
4417
4418 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4419 if (rc) {
4420 phba->cfg_sriov_nr_virtfn = 0;
4421 rc = -EPERM;
4422 } else
4423 rc = strlen(buf);
4424
4425 return rc;
4426}
4427
James Smart0cfbbf22016-10-13 15:06:12 -07004428LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4429 "Enable PCIe device SR-IOV virtual fn");
4430
James Smart912e3ac2011-05-24 11:42:11 -04004431lpfc_param_show(sriov_nr_virtfn)
Joe Perchesb6b996b2017-12-19 10:15:07 -08004432static DEVICE_ATTR_RW(lpfc_sriov_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04004433
James Smart173edbb2012-06-12 13:54:50 -04004434/**
James Smartc71ab862012-10-31 14:44:33 -04004435 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4436 *
4437 * @dev: class device that is converted into a Scsi_host.
4438 * @attr: device attribute, not used.
4439 * @buf: containing the string the number of vfs to be enabled.
4440 * @count: unused variable.
4441 *
4442 * Description:
4443 *
4444 * Returns:
4445 * length of the buf on success if val is in range the intended mode
4446 * is supported.
4447 * -EINVAL if val out of range or intended mode is not supported.
4448 **/
4449static ssize_t
4450lpfc_request_firmware_upgrade_store(struct device *dev,
4451 struct device_attribute *attr,
4452 const char *buf, size_t count)
4453{
4454 struct Scsi_Host *shost = class_to_shost(dev);
4455 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4456 struct lpfc_hba *phba = vport->phba;
4457 int val = 0, rc = -EINVAL;
4458
4459 /* Sanity check on user data */
4460 if (!isdigit(buf[0]))
4461 return -EINVAL;
4462 if (sscanf(buf, "%i", &val) != 1)
4463 return -EINVAL;
4464 if (val != 1)
4465 return -EINVAL;
4466
4467 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4468 if (rc)
4469 rc = -EPERM;
4470 else
4471 rc = strlen(buf);
4472 return rc;
4473}
4474
4475static int lpfc_req_fw_upgrade;
4476module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4477MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4478lpfc_param_show(request_firmware_upgrade)
4479
4480/**
4481 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4482 * @phba: lpfc_hba pointer.
4483 * @val: 0 or 1.
4484 *
4485 * Description:
4486 * Set the initial Linux generic firmware upgrade enable or disable flag.
4487 *
4488 * Returns:
4489 * zero if val saved.
4490 * -EINVAL val out of range
4491 **/
4492static int
4493lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4494{
4495 if (val >= 0 && val <= 1) {
4496 phba->cfg_request_firmware_upgrade = val;
4497 return 0;
4498 }
4499 return -EINVAL;
4500}
4501static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4502 lpfc_request_firmware_upgrade_show,
4503 lpfc_request_firmware_upgrade_store);
4504
4505/**
James Smart173edbb2012-06-12 13:54:50 -04004506 * lpfc_fcp_imax_store
4507 *
4508 * @dev: class device that is converted into a Scsi_host.
4509 * @attr: device attribute, not used.
4510 * @buf: string with the number of fast-path FCP interrupts per second.
4511 * @count: unused variable.
4512 *
4513 * Description:
4514 * If val is in a valid range [636,651042], then set the adapter's
4515 * maximum number of fast-path FCP interrupts per second.
4516 *
4517 * Returns:
4518 * length of the buf on success if val is in range the intended mode
4519 * is supported.
4520 * -EINVAL if val out of range or intended mode is not supported.
4521 **/
4522static ssize_t
4523lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4524 const char *buf, size_t count)
4525{
4526 struct Scsi_Host *shost = class_to_shost(dev);
4527 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4528 struct lpfc_hba *phba = vport->phba;
4529 int val = 0, i;
4530
James Smartbf8dae82012-08-03 12:36:24 -04004531 /* fcp_imax is only valid for SLI4 */
4532 if (phba->sli_rev != LPFC_SLI_REV4)
4533 return -EINVAL;
4534
James Smart173edbb2012-06-12 13:54:50 -04004535 /* Sanity check on user data */
4536 if (!isdigit(buf[0]))
4537 return -EINVAL;
4538 if (sscanf(buf, "%i", &val) != 1)
4539 return -EINVAL;
4540
James Smartbf8dae82012-08-03 12:36:24 -04004541 /*
4542 * Value range for the HBA is [5000,5000000]
4543 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004544 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004545 */
James Smart895427b2017-02-12 13:52:30 -08004546 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004547 return -EINVAL;
4548
4549 phba->cfg_fcp_imax = (uint32_t)val;
James Smart0cf07f842017-06-01 21:07:10 -07004550 phba->initial_imax = phba->cfg_fcp_imax;
James Smart43140ca2017-03-04 09:30:34 -08004551
4552 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004553 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4554 val);
James Smart173edbb2012-06-12 13:54:50 -04004555
4556 return strlen(buf);
4557}
4558
4559/*
4560# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004561# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004562#
James Smartbf8dae82012-08-03 12:36:24 -04004563# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004564*/
James Smartbf8dae82012-08-03 12:36:24 -04004565static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004566module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4567MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004568 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004569lpfc_param_show(fcp_imax)
4570
4571/**
4572 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4573 * @phba: lpfc_hba pointer.
4574 * @val: link speed value.
4575 *
4576 * Description:
4577 * If val is in a valid range [636,651042], then initialize the adapter's
4578 * maximum number of fast-path FCP interrupts per second.
4579 *
4580 * Returns:
4581 * zero if val saved.
4582 * -EINVAL val out of range
4583 **/
4584static int
4585lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4586{
James Smartbf8dae82012-08-03 12:36:24 -04004587 if (phba->sli_rev != LPFC_SLI_REV4) {
4588 phba->cfg_fcp_imax = 0;
4589 return 0;
4590 }
4591
James Smart895427b2017-02-12 13:52:30 -08004592 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4593 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004594 phba->cfg_fcp_imax = val;
4595 return 0;
4596 }
4597
4598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004599 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4600 val);
James Smartbf8dae82012-08-03 12:36:24 -04004601 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004602
4603 return 0;
4604}
4605
Joe Perchesb6b996b2017-12-19 10:15:07 -08004606static DEVICE_ATTR_RW(lpfc_fcp_imax);
James Smart173edbb2012-06-12 13:54:50 -04004607
James Smart0cf07f842017-06-01 21:07:10 -07004608/*
4609 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4610 * 0 No auto_imax support
4611 * 1 auto imax on
4612 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4613 * the EQ Delay Multiplier, depending on the activity for that EQ.
4614 * Value range [0,1]. Default value is 1.
4615 */
4616LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4617
James Smart7bb03bb2013-04-17 20:19:16 -04004618/**
4619 * lpfc_state_show - Display current driver CPU affinity
4620 * @dev: class converted to a Scsi_host structure.
4621 * @attr: device attribute, not used.
4622 * @buf: on return contains text describing the state of the link.
4623 *
4624 * Returns: size of formatted string.
4625 **/
4626static ssize_t
4627lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4628 char *buf)
4629{
4630 struct Scsi_Host *shost = class_to_shost(dev);
4631 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4632 struct lpfc_hba *phba = vport->phba;
4633 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004634 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004635
4636 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4637 (phba->intr_type != MSIX))
4638 return len;
4639
4640 switch (phba->cfg_fcp_cpu_map) {
4641 case 0:
4642 len += snprintf(buf + len, PAGE_SIZE-len,
4643 "fcp_cpu_map: No mapping (%d)\n",
4644 phba->cfg_fcp_cpu_map);
4645 return len;
4646 case 1:
4647 len += snprintf(buf + len, PAGE_SIZE-len,
4648 "fcp_cpu_map: HBA centric mapping (%d): "
4649 "%d online CPUs\n",
4650 phba->cfg_fcp_cpu_map,
4651 phba->sli4_hba.num_online_cpu);
4652 break;
4653 case 2:
4654 len += snprintf(buf + len, PAGE_SIZE-len,
4655 "fcp_cpu_map: Driver centric mapping (%d): "
4656 "%d online CPUs\n",
4657 phba->cfg_fcp_cpu_map,
4658 phba->sli4_hba.num_online_cpu);
4659 break;
4660 }
4661
James Smart76fd07a2014-02-20 09:57:18 -05004662 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4663 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4664
4665 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004666 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4667 len += snprintf(buf + len, PAGE_SIZE-len,
4668 "CPU %02d io_chan %02d "
4669 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004670 phba->sli4_hba.curr_disp_cpu,
4671 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004672 cpup->core_id);
4673 else
4674 len += snprintf(buf + len, PAGE_SIZE-len,
4675 "CPU %02d io_chan %02d "
4676 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004677 phba->sli4_hba.curr_disp_cpu,
4678 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004679 cpup->core_id, cpup->irq);
4680
James Smart76fd07a2014-02-20 09:57:18 -05004681 phba->sli4_hba.curr_disp_cpu++;
4682
4683 /* display max number of CPUs keeping some margin */
4684 if (phba->sli4_hba.curr_disp_cpu <
4685 phba->sli4_hba.num_present_cpu &&
4686 (len >= (PAGE_SIZE - 64))) {
4687 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4688 break;
4689 }
James Smart7bb03bb2013-04-17 20:19:16 -04004690 }
James Smart76fd07a2014-02-20 09:57:18 -05004691
4692 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4693 phba->sli4_hba.curr_disp_cpu = 0;
4694
James Smart7bb03bb2013-04-17 20:19:16 -04004695 return len;
4696}
4697
4698/**
4699 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4700 * @dev: class device that is converted into a Scsi_host.
4701 * @attr: device attribute, not used.
4702 * @buf: one or more lpfc_polling_flags values.
4703 * @count: not used.
4704 *
4705 * Returns:
4706 * -EINVAL - Not implemented yet.
4707 **/
4708static ssize_t
4709lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4710 const char *buf, size_t count)
4711{
4712 int status = -EINVAL;
4713 return status;
4714}
4715
4716/*
4717# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4718# for the HBA.
4719#
4720# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4721# 0 - Do not affinitze IRQ vectors
4722# 1 - Affintize HBA vectors with respect to each HBA
4723# (start with CPU0 for each HBA)
4724# 2 - Affintize HBA vectors with respect to the entire driver
4725# (round robin thru all CPUs across all HBAs)
4726*/
4727static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4728module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4729MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4730 "Defines how to map CPUs to IRQ vectors per HBA");
4731
4732/**
4733 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4734 * @phba: lpfc_hba pointer.
4735 * @val: link speed value.
4736 *
4737 * Description:
4738 * If val is in a valid range [0-2], then affinitze the adapter's
4739 * MSIX vectors.
4740 *
4741 * Returns:
4742 * zero if val saved.
4743 * -EINVAL val out of range
4744 **/
4745static int
4746lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4747{
4748 if (phba->sli_rev != LPFC_SLI_REV4) {
4749 phba->cfg_fcp_cpu_map = 0;
4750 return 0;
4751 }
4752
4753 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4754 phba->cfg_fcp_cpu_map = val;
4755 return 0;
4756 }
4757
4758 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004759 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4760 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004761 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4762
4763 return 0;
4764}
4765
Joe Perchesb6b996b2017-12-19 10:15:07 -08004766static DEVICE_ATTR_RW(lpfc_fcp_cpu_map);
James Smart7bb03bb2013-04-17 20:19:16 -04004767
James Smart0d878412009-10-02 15:16:56 -04004768/*
dea31012005-04-17 16:05:31 -05004769# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4770# Value range is [2,3]. Default value is 3.
4771*/
James Smart3de2a652007-08-02 11:09:59 -04004772LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4773 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004774
4775/*
4776# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4777# is [0,1]. Default value is 0.
4778*/
James Smart3de2a652007-08-02 11:09:59 -04004779LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4780 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004781
4782/*
James Smart3cb01c52013-07-15 18:35:04 -04004783# lpfc_first_burst_size: First burst size to use on the NPorts
4784# that support first burst.
4785# Value range is [0,65536]. Default value is 0.
4786*/
4787LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4788 "First burst size for Targets that support first burst");
4789
4790/*
James Smart2d7dbc42017-02-12 13:52:35 -08004791* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4792* When the driver is configured as an NVME target, this value is
4793* communicated to the NVME initiator in the PRLI response. It is
4794* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4795* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004796* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004797* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004798*/
James Smart2d7dbc42017-02-12 13:52:35 -08004799LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4800 "NVME Target mode first burst size in 512B increments.");
4801
4802/*
4803 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4804 * For the Initiator (I), enabling this parameter means that an NVMET
4805 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4806 * processed by the initiator for subsequent NVME FCP IO. For the target
4807 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4808 * driver parameter as the target function's first burst size returned to the
4809 * initiator in the target's NVME PRLI response. Parameter supported on physical
4810 * port only - no NPIV support.
4811 * Value range is [0,1]. Default value is 0 (disabled).
4812 */
James Smart895427b2017-02-12 13:52:30 -08004813LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4814 "Enable First Burst feature on I and T functions.");
4815
4816/*
James Smart977b5a02008-09-07 11:52:04 -04004817# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4818# depth. Default value is 0. When the value of this parameter is zero the
4819# SCSI command completion time is not used for controlling I/O queue depth. When
4820# the parameter is set to a non-zero value, the I/O queue depth is controlled
4821# to limit the I/O completion time to the parameter value.
4822# The value is set in milliseconds.
4823*/
James Smarted5b1522016-10-13 15:06:11 -07004824LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004825 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004826
James Smart977b5a02008-09-07 11:52:04 -04004827lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004828static int
4829lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4830{
4831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4832 struct lpfc_nodelist *ndlp, *next_ndlp;
4833
4834 if (val == vport->cfg_max_scsicmpl_time)
4835 return 0;
4836 if ((val < 0) || (val > 60000))
4837 return -EINVAL;
4838 vport->cfg_max_scsicmpl_time = val;
4839
4840 spin_lock_irq(shost->host_lock);
4841 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4842 if (!NLP_CHK_NODE_ACT(ndlp))
4843 continue;
4844 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4845 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004846 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004847 }
4848 spin_unlock_irq(shost->host_lock);
4849 return 0;
4850}
4851lpfc_vport_param_store(max_scsicmpl_time);
Joe Perchesb6b996b2017-12-19 10:15:07 -08004852static DEVICE_ATTR_RW(lpfc_max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004853
4854/*
dea31012005-04-17 16:05:31 -05004855# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4856# range is [0,1]. Default value is 0.
4857*/
4858LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4859
4860/*
James Smart895427b2017-02-12 13:52:30 -08004861 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4862 * range is [0,1]. Default value is 0.
4863 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4864 * For [1], FCP commands are issued to a Work Queue associated with the
4865 * current CPU.
4866 *
4867 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4868 * LPFC_FCP_SCHED_BY_CPU == 1
4869 *
4870 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4871 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4872 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4873 * through WQs will be used.
4874 */
4875LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4876 LPFC_FCP_SCHED_ROUND_ROBIN,
4877 LPFC_FCP_SCHED_BY_CPU,
4878 "Determine scheduling algorithm for "
4879 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004880
4881/*
James Smarta6571c62012-10-31 14:44:42 -04004882# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4883# range is [0,1]. Default value is 0.
4884# For [0], bus reset issues target reset to ALL devices
4885# For [1], bus reset issues target reset to non-FCP2 devices
4886*/
4887LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4888 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4889
4890
4891/*
dea31012005-04-17 16:05:31 -05004892# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4893# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004894# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004895# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4896# cr_delay is set to 0.
4897*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004898LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004899 "interrupt response is generated");
4900
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004901LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004902 "interrupt response is generated");
4903
4904/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004905# lpfc_multi_ring_support: Determines how many rings to spread available
4906# cmd/rsp IOCB entries across.
4907# Value range is [1,2]. Default value is 1.
4908*/
4909LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4910 "SLI rings to spread IOCB entries across");
4911
4912/*
James Smarta4bc3372006-12-02 13:34:16 -05004913# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4914# identifies what rctl value to configure the additional ring for.
4915# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4916*/
James Smart6a9c52c2009-10-02 15:16:51 -04004917LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004918 255, "Identifies RCTL for additional ring configuration");
4919
4920/*
4921# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4922# identifies what type value to configure the additional ring for.
4923# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4924*/
James Smart6a9c52c2009-10-02 15:16:51 -04004925LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004926 255, "Identifies TYPE for additional ring configuration");
4927
4928/*
James Smart4258e982015-12-16 18:11:58 -05004929# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4930# 0 = SmartSAN functionality disabled (default)
4931# 1 = SmartSAN functionality enabled
4932# This parameter will override the value of lpfc_fdmi_on module parameter.
4933# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004934*/
James Smart4258e982015-12-16 18:11:58 -05004935LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4936
4937/*
4938# lpfc_fdmi_on: Controls FDMI support.
4939# 0 No FDMI support (default)
4940# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004941# Traditional FDMI support means the driver will assume FDMI-2 support;
4942# however, if that fails, it will fallback to FDMI-1.
4943# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4944# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4945# lpfc_fdmi_on.
4946# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004947*/
James Smart8663cbb2016-03-31 14:12:33 -07004948LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004949
4950/*
4951# Specifies the maximum number of ELS cmds we can have outstanding (for
4952# discovery). Value range is [1,64]. Default value = 32.
4953*/
James Smart3de2a652007-08-02 11:09:59 -04004954LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004955 "during discovery");
4956
4957/*
James Smartc4a7c922013-05-31 17:04:59 -04004958# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4959# will be scanned by the SCSI midlayer when sequential scanning is
4960# used; and is also the highest LUN ID allowed when the SCSI midlayer
4961# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4962# LUN ID limit, but the SCSI midlayer requires this field for the uses
4963# above. The lpfc driver limits the default value to 255 for two reasons.
4964# As it bounds the sequential scan loop, scanning for thousands of luns
4965# on a target can take minutes of wall clock time. Additionally,
4966# there are FC targets, such as JBODs, that only recognize 8-bits of
4967# LUN ID. When they receive a value greater than 8 bits, they chop off
4968# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4969# and so on all as LUN ID 0. This causes the linux kernel, which sees
4970# valid responses at each of the LUN IDs, to believe there are multiple
4971# devices present, when in fact, there is only 1.
4972# A customer that is aware of their target behaviors, and the results as
4973# indicated above, is welcome to increase the lpfc_max_luns value.
4974# As mentioned, this value is not used by the lpfc driver, only the
4975# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004976# Value range is [0,65535]. Default value is 255.
4977# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004978*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004979LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004980
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004981/*
4982# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4983# Value range is [1,255], default value is 10.
4984*/
4985LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4986 "Milliseconds driver will wait between polling FCP ring");
4987
James Smart4ff43242006-12-02 13:34:56 -05004988/*
James Smart0c411222013-09-06 12:22:46 -04004989# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4990# to complete in seconds. Value range is [5,180], default value is 60.
4991*/
4992LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4993 "Maximum time to wait for task management commands to complete");
4994/*
James Smart4ff43242006-12-02 13:34:56 -05004995# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4996# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004997# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004998# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004999# 2 = MSI-X enabled (default)
5000# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05005001*/
George Kadianakis8605c462010-01-17 21:19:31 +02005002LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05005003 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05005004
James Smart13815c82008-01-11 01:52:48 -05005005/*
James Smartf358dd02017-02-12 13:52:34 -08005006 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08005007 *
5008 * 0 = NVME OAS disabled
5009 * 1 = NVME OAS enabled
5010 *
5011 * Value range is [0,1]. Default value is 0.
5012 */
5013LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
5014 "Use OAS bit on NVME IOs");
5015
5016/*
5017 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
5018 * will advertise it supports to the SCSI layer. This also will map to
5019 * the number of WQs the driver will create.
5020 *
5021 * 0 = Configure the number of io channels to the number of active CPUs.
5022 * 1,32 = Manually specify how many io channels to use.
5023 *
5024 * Value range is [0,32]. Default value is 4.
5025 */
5026LPFC_ATTR_R(fcp_io_channel,
5027 LPFC_FCP_IO_CHAN_DEF,
5028 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04005029 "Set the number of FCP I/O channels");
5030
5031/*
James Smart895427b2017-02-12 13:52:30 -08005032 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5033 * will advertise it supports to the NVME layer. This also will map to
5034 * the number of WQs the driver will create.
5035 *
5036 * This module parameter is valid when lpfc_enable_fc4_type is set
5037 * to support NVME.
5038 *
5039 * The NVME Layer will try to create this many, plus 1 administrative
5040 * hardware queue. The administrative queue will always map to WQ 0
5041 * A hardware IO queue maps (qidx) to a specific driver WQ.
5042 *
5043 * 0 = Configure the number of io channels to the number of active CPUs.
5044 * 1,32 = Manually specify how many io channels to use.
5045 *
5046 * Value range is [0,32]. Default value is 0.
5047 */
5048LPFC_ATTR_R(nvme_io_channel,
5049 LPFC_NVME_IO_CHAN_DEF,
5050 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5051 "Set the number of NVME I/O channels");
5052
5053/*
James Smart13815c82008-01-11 01:52:48 -05005054# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5055# 0 = HBA resets disabled
5056# 1 = HBA resets enabled (default)
5057# Value range is [0,1]. Default value is 1.
5058*/
5059LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005060
James Smart13815c82008-01-11 01:52:48 -05005061/*
James Smarteb7a3392010-11-20 23:12:02 -05005062# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005063# 0 = HBA Heartbeat disabled
5064# 1 = HBA Heartbeat enabled (default)
5065# Value range is [0,1]. Default value is 1.
5066*/
James Smarteb7a3392010-11-20 23:12:02 -05005067LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005068
James Smart83108bd2008-01-11 01:53:09 -05005069/*
James Smart1ba981f2014-02-20 09:56:45 -05005070# lpfc_EnableXLane: Enable Express Lane Feature
5071# 0x0 Express Lane Feature disabled
5072# 0x1 Express Lane Feature enabled
5073# Value range is [0,1]. Default value is 0.
5074*/
5075LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5076
5077/*
5078# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5079# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5080# Value range is [0x0,0x7f]. Default value is 0
5081*/
James Smart28d7f3d2014-05-21 08:05:28 -04005082LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005083
5084/*
James Smart81301a92008-12-04 22:39:46 -05005085# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5086# 0 = BlockGuard disabled (default)
5087# 1 = BlockGuard enabled
5088# Value range is [0,1]. Default value is 0.
5089*/
5090LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5091
James Smart6fb120a2009-05-22 14:52:59 -04005092/*
James Smartba20c852012-08-03 12:36:52 -04005093# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5094# 0 = disabled (default)
5095# 1 = enabled
5096# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005097#
5098# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005099*/
5100unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5101
James Smartba20c852012-08-03 12:36:52 -04005102/*
James Smart81301a92008-12-04 22:39:46 -05005103# lpfc_prot_mask: i
5104# - Bit mask of host protection capabilities used to register with the
5105# SCSI mid-layer
5106# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5107# - Allows you to ultimately specify which profiles to use
5108# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005109# - SHOST_DIF_TYPE1_PROTECTION 1
5110# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5111# - SHOST_DIX_TYPE0_PROTECTION 8
5112# HBA supports DIX Type 0: Host to HBA protection only
5113# - SHOST_DIX_TYPE1_PROTECTION 16
5114# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005115#
5116*/
James Smartb3b98b72016-10-13 15:06:06 -07005117LPFC_ATTR(prot_mask,
5118 (SHOST_DIF_TYPE1_PROTECTION |
5119 SHOST_DIX_TYPE0_PROTECTION |
5120 SHOST_DIX_TYPE1_PROTECTION),
5121 0,
5122 (SHOST_DIF_TYPE1_PROTECTION |
5123 SHOST_DIX_TYPE0_PROTECTION |
5124 SHOST_DIX_TYPE1_PROTECTION),
5125 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005126
5127/*
5128# lpfc_prot_guard: i
5129# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005130# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005131# - Allows you to ultimately specify which profiles to use
5132# - Default will result in registering capabilities for all guard types
5133#
5134*/
James Smartb3b98b72016-10-13 15:06:06 -07005135LPFC_ATTR(prot_guard,
5136 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5137 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005138
James Smart92494142011-02-16 12:39:44 -05005139/*
5140 * Delay initial NPort discovery when Clean Address bit is cleared in
5141 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5142 * This parameter can have value 0 or 1.
5143 * When this parameter is set to 0, no delay is added to the initial
5144 * discovery.
5145 * When this parameter is set to non-zero value, initial Nport discovery is
5146 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5147 * accept and FCID/Fabric name/Fabric portname is changed.
5148 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5149 * when Clean Address bit is cleared in FLOGI/FDISC
5150 * accept and FCID/Fabric name/Fabric portname is changed.
5151 * Default value is 0.
5152 */
James Smart8eb8b962016-07-06 12:36:08 -07005153LPFC_ATTR(delay_discovery, 0, 0, 1,
5154 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005155
5156/*
James Smart3621a712009-04-06 18:47:14 -04005157 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005158 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005159 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5160 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005161 * Because of the additional overhead involved in setting up T10-DIF,
5162 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5163 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005164 */
James Smartb996ce32017-12-19 10:57:50 -08005165LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_MIN_SG_SEG_CNT,
James Smart83108bd2008-01-11 01:53:09 -05005166 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5167
James Smart96f70772013-04-17 20:16:15 -04005168/*
James Smart7bdedb32016-07-06 12:36:00 -07005169 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5170 * 0 = MDS Diagnostics disabled (default)
5171 * 1 = MDS Diagnostics enabled
5172 * Value range is [0,1]. Default value is 0.
5173 */
5174LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5175
James Smart44fd7fe2017-08-23 16:55:47 -07005176/*
5177 * lpfc_enable_bbcr: Enable BB Credit Recovery
5178 * 0 = BB Credit Recovery disabled
5179 * 1 = BB Credit Recovery enabled (default)
5180 * Value range is [0,1]. Default value is 1.
5181 */
5182LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5183
Tony Jonesee959b02008-02-22 00:13:36 +01005184struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005185 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005186 &dev_attr_bg_info,
5187 &dev_attr_bg_guard_err,
5188 &dev_attr_bg_apptag_err,
5189 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005190 &dev_attr_info,
5191 &dev_attr_serialnum,
5192 &dev_attr_modeldesc,
5193 &dev_attr_modelname,
5194 &dev_attr_programtype,
5195 &dev_attr_portnum,
5196 &dev_attr_fwrev,
5197 &dev_attr_hdw,
5198 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005199 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005200 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005201 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005202 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005203 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005204 &dev_attr_lpfc_temp_sensor,
5205 &dev_attr_lpfc_log_verbose,
5206 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005207 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005208 &dev_attr_lpfc_hba_queue_depth,
5209 &dev_attr_lpfc_peer_port_login,
5210 &dev_attr_lpfc_nodev_tmo,
5211 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005212 &dev_attr_lpfc_enable_fc4_type,
5213 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005214 &dev_attr_lpfc_fcp_class,
5215 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005216 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005217 &dev_attr_lpfc_ack0,
5218 &dev_attr_lpfc_topology,
5219 &dev_attr_lpfc_scan_down,
5220 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005221 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005222 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005223 &dev_attr_lpfc_cr_delay,
5224 &dev_attr_lpfc_cr_count,
5225 &dev_attr_lpfc_multi_ring_support,
5226 &dev_attr_lpfc_multi_ring_rctl,
5227 &dev_attr_lpfc_multi_ring_type,
5228 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005229 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005230 &dev_attr_lpfc_max_luns,
5231 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005232 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005233 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005234 &dev_attr_nport_evt_cnt,
5235 &dev_attr_board_mode,
5236 &dev_attr_max_vpi,
5237 &dev_attr_used_vpi,
5238 &dev_attr_max_rpi,
5239 &dev_attr_used_rpi,
5240 &dev_attr_max_xri,
5241 &dev_attr_used_xri,
5242 &dev_attr_npiv_info,
5243 &dev_attr_issue_reset,
5244 &dev_attr_lpfc_poll,
5245 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005246 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005247 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005248 &dev_attr_lpfc_nvme_oas,
James Smart0cf07f842017-06-01 21:07:10 -07005249 &dev_attr_lpfc_auto_imax,
James Smartda0436e2009-05-22 14:51:39 -04005250 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005251 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005252 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005253 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005254 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005255 &dev_attr_lpfc_nvmet_mrq,
James Smart895427b2017-02-12 13:52:30 -08005256 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005257 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005258 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005259 &dev_attr_lpfc_soft_wwnn,
5260 &dev_attr_lpfc_soft_wwpn,
5261 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005262 &dev_attr_lpfc_enable_hba_reset,
5263 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005264 &dev_attr_lpfc_EnableXLane,
5265 &dev_attr_lpfc_XLanePriority,
5266 &dev_attr_lpfc_xlane_lun,
5267 &dev_attr_lpfc_xlane_tgt,
5268 &dev_attr_lpfc_xlane_vpt,
5269 &dev_attr_lpfc_xlane_lun_state,
5270 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005271 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005272 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005273 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005274 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005275 &dev_attr_lpfc_aer_support,
5276 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005277 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005278 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005279 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005280 &dev_attr_lpfc_iocb_cnt,
5281 &dev_attr_iocb_hw,
5282 &dev_attr_txq_hw,
5283 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005284 &dev_attr_lpfc_fips_level,
5285 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005286 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005287 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005288 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005289 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005290 &dev_attr_lpfc_enable_mds_diags,
James Smart44fd7fe2017-08-23 16:55:47 -07005291 &dev_attr_lpfc_enable_bbcr,
dea31012005-04-17 16:05:31 -05005292 NULL,
5293};
5294
Tony Jonesee959b02008-02-22 00:13:36 +01005295struct device_attribute *lpfc_vport_attrs[] = {
5296 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005297 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005298 &dev_attr_num_discovered_ports,
5299 &dev_attr_lpfc_drvr_version,
5300 &dev_attr_lpfc_log_verbose,
5301 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005302 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005303 &dev_attr_lpfc_nodev_tmo,
5304 &dev_attr_lpfc_devloss_tmo,
5305 &dev_attr_lpfc_hba_queue_depth,
5306 &dev_attr_lpfc_peer_port_login,
5307 &dev_attr_lpfc_restrict_login,
5308 &dev_attr_lpfc_fcp_class,
5309 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005310 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005311 &dev_attr_lpfc_max_luns,
5312 &dev_attr_nport_evt_cnt,
5313 &dev_attr_npiv_info,
5314 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005315 &dev_attr_lpfc_max_scsicmpl_time,
5316 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005317 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005318 &dev_attr_lpfc_fips_level,
5319 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005320 NULL,
5321};
5322
James Smarte59058c2008-08-24 21:49:00 -04005323/**
James Smart3621a712009-04-06 18:47:14 -04005324 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005325 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005326 * @kobj: kernel kobject that contains the kernel class device.
5327 * @bin_attr: kernel attributes passed to us.
5328 * @buf: contains the data to be written to the adapter IOREG space.
5329 * @off: offset into buffer to beginning of data.
5330 * @count: bytes to transfer.
5331 *
5332 * Description:
5333 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5334 * Uses the adapter io control registers to send buf contents to the adapter.
5335 *
5336 * Returns:
5337 * -ERANGE off and count combo out of range
5338 * -EINVAL off, count or buff address invalid
5339 * -EPERM adapter is offline
5340 * value of count, buf contents written
5341 **/
dea31012005-04-17 16:05:31 -05005342static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005343sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5344 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005345 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005346{
5347 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005348 struct device *dev = container_of(kobj, struct device, kobj);
5349 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5351 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005352
James Smartf1126682009-06-10 17:22:44 -04005353 if (phba->sli_rev >= LPFC_SLI_REV4)
5354 return -EPERM;
5355
dea31012005-04-17 16:05:31 -05005356 if ((off + count) > FF_REG_AREA_SIZE)
5357 return -ERANGE;
5358
James Smartf7a919b2011-08-21 21:49:16 -04005359 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5360 return 0;
dea31012005-04-17 16:05:31 -05005361
5362 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5363 return -EINVAL;
5364
James Smartf7a919b2011-08-21 21:49:16 -04005365 /* This is to protect HBA registers from accidental writes. */
5366 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5367 return -EINVAL;
5368
5369 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005370 return -EPERM;
dea31012005-04-17 16:05:31 -05005371
James Smart2e0fef82007-06-17 19:56:36 -05005372 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005373 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5374 buf_off += sizeof(uint32_t))
5375 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005376 phba->ctrl_regs_memmap_p + off + buf_off);
5377
James Smart2e0fef82007-06-17 19:56:36 -05005378 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005379
5380 return count;
5381}
5382
James Smarte59058c2008-08-24 21:49:00 -04005383/**
James Smart3621a712009-04-06 18:47:14 -04005384 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005385 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005386 * @kobj: kernel kobject that contains the kernel class device.
5387 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005388 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005389 * @off: offset into buffer to beginning of data.
5390 * @count: bytes to transfer.
5391 *
5392 * Description:
5393 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5394 * Uses the adapter io control registers to read data into buf.
5395 *
5396 * Returns:
5397 * -ERANGE off and count combo out of range
5398 * -EINVAL off, count or buff address invalid
5399 * value of count, buf contents read
5400 **/
dea31012005-04-17 16:05:31 -05005401static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005402sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5403 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005404 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005405{
5406 size_t buf_off;
5407 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005408 struct device *dev = container_of(kobj, struct device, kobj);
5409 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005410 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5411 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005412
James Smartf1126682009-06-10 17:22:44 -04005413 if (phba->sli_rev >= LPFC_SLI_REV4)
5414 return -EPERM;
5415
dea31012005-04-17 16:05:31 -05005416 if (off > FF_REG_AREA_SIZE)
5417 return -ERANGE;
5418
5419 if ((off + count) > FF_REG_AREA_SIZE)
5420 count = FF_REG_AREA_SIZE - off;
5421
5422 if (count == 0) return 0;
5423
5424 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5425 return -EINVAL;
5426
James Smart2e0fef82007-06-17 19:56:36 -05005427 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005428
5429 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5430 tmp_ptr = (uint32_t *)(buf + buf_off);
5431 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5432 }
5433
James Smart2e0fef82007-06-17 19:56:36 -05005434 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005435
5436 return count;
5437}
5438
5439static struct bin_attribute sysfs_ctlreg_attr = {
5440 .attr = {
5441 .name = "ctlreg",
5442 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005443 },
5444 .size = 256,
5445 .read = sysfs_ctlreg_read,
5446 .write = sysfs_ctlreg_write,
5447};
5448
James Smarte59058c2008-08-24 21:49:00 -04005449/**
James Smart3621a712009-04-06 18:47:14 -04005450 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005451 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005452 * @kobj: kernel kobject that contains the kernel class device.
5453 * @bin_attr: kernel attributes passed to us.
5454 * @buf: contains the data to be written to sysfs mbox.
5455 * @off: offset into buffer to beginning of data.
5456 * @count: bytes to transfer.
5457 *
5458 * Description:
James Smart026abb82011-12-13 13:20:45 -05005459 * Deprecated function. All mailbox access from user space is performed via the
5460 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005461 *
5462 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005463 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005464 **/
dea31012005-04-17 16:05:31 -05005465static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005466sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5467 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005468 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005469{
James Smart026abb82011-12-13 13:20:45 -05005470 return -EPERM;
dea31012005-04-17 16:05:31 -05005471}
5472
James Smarte59058c2008-08-24 21:49:00 -04005473/**
James Smart3621a712009-04-06 18:47:14 -04005474 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005475 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005476 * @kobj: kernel kobject that contains the kernel class device.
5477 * @bin_attr: kernel attributes passed to us.
5478 * @buf: contains the data to be read from sysfs mbox.
5479 * @off: offset into buffer to beginning of data.
5480 * @count: bytes to transfer.
5481 *
5482 * Description:
James Smart026abb82011-12-13 13:20:45 -05005483 * Deprecated function. All mailbox access from user space is performed via the
5484 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005485 *
5486 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005487 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005488 **/
dea31012005-04-17 16:05:31 -05005489static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005490sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5491 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005492 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005493{
James Smart026abb82011-12-13 13:20:45 -05005494 return -EPERM;
dea31012005-04-17 16:05:31 -05005495}
5496
5497static struct bin_attribute sysfs_mbox_attr = {
5498 .attr = {
5499 .name = "mbox",
5500 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005501 },
James Smartc0c11512011-05-24 11:41:34 -04005502 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005503 .read = sysfs_mbox_read,
5504 .write = sysfs_mbox_write,
5505};
5506
James Smarte59058c2008-08-24 21:49:00 -04005507/**
James Smart3621a712009-04-06 18:47:14 -04005508 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005509 * @vport: address of lpfc vport structure.
5510 *
5511 * Return codes:
5512 * zero on success
5513 * error return code from sysfs_create_bin_file()
5514 **/
dea31012005-04-17 16:05:31 -05005515int
James Smart2e0fef82007-06-17 19:56:36 -05005516lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005517{
James Smart2e0fef82007-06-17 19:56:36 -05005518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005519 int error;
5520
Tony Jonesee959b02008-02-22 00:13:36 +01005521 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005522 &sysfs_drvr_stat_data_attr);
5523
5524 /* Virtual ports do not need ctrl_reg and mbox */
5525 if (error || vport->port_type == LPFC_NPIV_PORT)
5526 goto out;
5527
5528 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005529 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005530 if (error)
James Smarteada2722008-12-04 22:39:13 -05005531 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005532
Tony Jonesee959b02008-02-22 00:13:36 +01005533 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005534 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005535 if (error)
5536 goto out_remove_ctlreg_attr;
5537
5538 return 0;
5539out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005540 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005541out_remove_stat_attr:
5542 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5543 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005544out:
5545 return error;
5546}
5547
James Smarte59058c2008-08-24 21:49:00 -04005548/**
James Smart3621a712009-04-06 18:47:14 -04005549 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005550 * @vport: address of lpfc vport structure.
5551 **/
dea31012005-04-17 16:05:31 -05005552void
James Smart2e0fef82007-06-17 19:56:36 -05005553lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005554{
James Smart2e0fef82007-06-17 19:56:36 -05005555 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005556 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5557 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005558 /* Virtual ports do not need ctrl_reg and mbox */
5559 if (vport->port_type == LPFC_NPIV_PORT)
5560 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005561 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5562 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005563}
5564
dea31012005-04-17 16:05:31 -05005565/*
5566 * Dynamic FC Host Attributes Support
5567 */
5568
James Smarte59058c2008-08-24 21:49:00 -04005569/**
James Smart6c9231f2016-12-19 15:07:24 -08005570 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5571 * @shost: kernel scsi host pointer.
5572 **/
5573static void
5574lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5575{
5576 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5577
5578 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5579 sizeof fc_host_symbolic_name(shost));
5580}
5581
5582/**
James Smart3621a712009-04-06 18:47:14 -04005583 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005584 * @shost: kernel scsi host pointer.
5585 **/
dea31012005-04-17 16:05:31 -05005586static void
5587lpfc_get_host_port_id(struct Scsi_Host *shost)
5588{
James Smart2e0fef82007-06-17 19:56:36 -05005589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5590
dea31012005-04-17 16:05:31 -05005591 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005592 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005593}
5594
James Smarte59058c2008-08-24 21:49:00 -04005595/**
James Smart3621a712009-04-06 18:47:14 -04005596 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005597 * @shost: kernel scsi host pointer.
5598 **/
dea31012005-04-17 16:05:31 -05005599static void
5600lpfc_get_host_port_type(struct Scsi_Host *shost)
5601{
James Smart2e0fef82007-06-17 19:56:36 -05005602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5603 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005604
5605 spin_lock_irq(shost->host_lock);
5606
James Smart92d7f7b2007-06-17 19:56:38 -05005607 if (vport->port_type == LPFC_NPIV_PORT) {
5608 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5609 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005610 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005611 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005612 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5613 else
5614 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5615 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005616 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005617 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5618 else
5619 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5620 }
5621 } else
5622 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5623
5624 spin_unlock_irq(shost->host_lock);
5625}
5626
James Smarte59058c2008-08-24 21:49:00 -04005627/**
James Smart3621a712009-04-06 18:47:14 -04005628 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005629 * @shost: kernel scsi host pointer.
5630 **/
dea31012005-04-17 16:05:31 -05005631static void
5632lpfc_get_host_port_state(struct Scsi_Host *shost)
5633{
James Smart2e0fef82007-06-17 19:56:36 -05005634 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5635 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005636
5637 spin_lock_irq(shost->host_lock);
5638
James Smart2e0fef82007-06-17 19:56:36 -05005639 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005640 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5641 else {
James Smart2e0fef82007-06-17 19:56:36 -05005642 switch (phba->link_state) {
5643 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005644 case LPFC_LINK_DOWN:
5645 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5646 break;
5647 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005648 case LPFC_CLEAR_LA:
5649 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005650 /* Links up, reports port state accordingly */
5651 if (vport->port_state < LPFC_VPORT_READY)
5652 fc_host_port_state(shost) =
5653 FC_PORTSTATE_BYPASSED;
5654 else
5655 fc_host_port_state(shost) =
5656 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005657 break;
5658 case LPFC_HBA_ERROR:
5659 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5660 break;
5661 default:
5662 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5663 break;
5664 }
5665 }
5666
5667 spin_unlock_irq(shost->host_lock);
5668}
5669
James Smarte59058c2008-08-24 21:49:00 -04005670/**
James Smart3621a712009-04-06 18:47:14 -04005671 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005672 * @shost: kernel scsi host pointer.
5673 **/
dea31012005-04-17 16:05:31 -05005674static void
5675lpfc_get_host_speed(struct Scsi_Host *shost)
5676{
James Smart2e0fef82007-06-17 19:56:36 -05005677 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5678 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005679
5680 spin_lock_irq(shost->host_lock);
5681
James Smarta085e872015-12-16 18:12:02 -05005682 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005683 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005684 case LPFC_LINK_SPEED_1GHZ:
5685 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005686 break;
James Smart76a95d72010-11-20 23:11:48 -05005687 case LPFC_LINK_SPEED_2GHZ:
5688 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005689 break;
James Smart76a95d72010-11-20 23:11:48 -05005690 case LPFC_LINK_SPEED_4GHZ:
5691 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005692 break;
James Smart76a95d72010-11-20 23:11:48 -05005693 case LPFC_LINK_SPEED_8GHZ:
5694 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005695 break;
James Smart76a95d72010-11-20 23:11:48 -05005696 case LPFC_LINK_SPEED_10GHZ:
5697 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005698 break;
James Smart76a95d72010-11-20 23:11:48 -05005699 case LPFC_LINK_SPEED_16GHZ:
5700 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5701 break;
James Smartd38dd522015-08-31 16:48:17 -04005702 case LPFC_LINK_SPEED_32GHZ:
5703 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5704 break;
James Smart76a95d72010-11-20 23:11:48 -05005705 default:
5706 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005707 break;
5708 }
James Smart09372822008-01-11 01:52:54 -05005709 } else
5710 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005711
5712 spin_unlock_irq(shost->host_lock);
5713}
5714
James Smarte59058c2008-08-24 21:49:00 -04005715/**
James Smart3621a712009-04-06 18:47:14 -04005716 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005717 * @shost: kernel scsi host pointer.
5718 **/
dea31012005-04-17 16:05:31 -05005719static void
5720lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5721{
James Smart2e0fef82007-06-17 19:56:36 -05005722 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5723 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005724 u64 node_name;
dea31012005-04-17 16:05:31 -05005725
5726 spin_lock_irq(shost->host_lock);
5727
James Smart73d91e52011-10-10 21:32:10 -04005728 if ((vport->port_state > LPFC_FLOGI) &&
5729 ((vport->fc_flag & FC_FABRIC) ||
5730 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5731 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005732 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005733 else
5734 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005735 node_name = 0;
dea31012005-04-17 16:05:31 -05005736
5737 spin_unlock_irq(shost->host_lock);
5738
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005739 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005740}
5741
James Smarte59058c2008-08-24 21:49:00 -04005742/**
James Smart3621a712009-04-06 18:47:14 -04005743 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005744 * @shost: kernel scsi host pointer.
5745 *
5746 * Notes:
5747 * NULL on error for link down, no mbox pool, sli2 active,
5748 * management not allowed, memory allocation error, or mbox error.
5749 *
5750 * Returns:
5751 * NULL for error
5752 * address of the adapter host statistics
5753 **/
dea31012005-04-17 16:05:31 -05005754static struct fc_host_statistics *
5755lpfc_get_stats(struct Scsi_Host *shost)
5756{
James Smart2e0fef82007-06-17 19:56:36 -05005757 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5758 struct lpfc_hba *phba = vport->phba;
5759 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005760 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005761 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005762 LPFC_MBOXQ_t *pmboxq;
5763 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005764 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005765 int rc = 0;
dea31012005-04-17 16:05:31 -05005766
James Smart92d7f7b2007-06-17 19:56:38 -05005767 /*
5768 * prevent udev from issuing mailbox commands until the port is
5769 * configured.
5770 */
James Smart2e0fef82007-06-17 19:56:36 -05005771 if (phba->link_state < LPFC_LINK_DOWN ||
5772 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005773 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005774 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005775
5776 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005777 return NULL;
5778
dea31012005-04-17 16:05:31 -05005779 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5780 if (!pmboxq)
5781 return NULL;
5782 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5783
James Smart04c68492009-05-22 14:52:52 -04005784 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005785 pmb->mbxCommand = MBX_READ_STATUS;
5786 pmb->mbxOwner = OWN_HOST;
5787 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005788 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005789
James Smart75baf692010-06-08 18:31:21 -04005790 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005791 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005792 else
dea31012005-04-17 16:05:31 -05005793 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5794
5795 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005796 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005797 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005798 return NULL;
5799 }
5800
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005801 memset(hs, 0, sizeof (struct fc_host_statistics));
5802
dea31012005-04-17 16:05:31 -05005803 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005804 /*
5805 * The MBX_READ_STATUS returns tx_k_bytes which has to
5806 * converted to words
5807 */
5808 hs->tx_words = (uint64_t)
5809 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5810 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005811 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005812 hs->rx_words = (uint64_t)
5813 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5814 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005815
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005816 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005817 pmb->mbxCommand = MBX_READ_LNK_STAT;
5818 pmb->mbxOwner = OWN_HOST;
5819 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005820 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005821
James Smart75baf692010-06-08 18:31:21 -04005822 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005823 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005824 else
dea31012005-04-17 16:05:31 -05005825 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5826
5827 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005828 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005829 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005830 return NULL;
5831 }
5832
5833 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5834 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5835 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5836 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5837 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5838 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5839 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5840
James Smart64ba8812006-08-02 15:24:34 -04005841 hs->link_failure_count -= lso->link_failure_count;
5842 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5843 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5844 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5845 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5846 hs->invalid_crc_count -= lso->invalid_crc_count;
5847 hs->error_frames -= lso->error_frames;
5848
James Smart76a95d72010-11-20 23:11:48 -05005849 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005850 hs->lip_count = -1;
5851 hs->nos_count = (phba->link_events >> 1);
5852 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005853 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005854 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005855 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005856 hs->nos_count = -1;
5857 } else {
5858 hs->lip_count = -1;
5859 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005860 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005861 }
5862
5863 hs->dumped_frames = -1;
5864
James Smart64ba8812006-08-02 15:24:34 -04005865 seconds = get_seconds();
5866 if (seconds < psli->stats_start)
5867 hs->seconds_since_last_reset = seconds +
5868 ((unsigned long)-1 - psli->stats_start);
5869 else
5870 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005871
James Smart1dcb58e2007-04-25 09:51:30 -04005872 mempool_free(pmboxq, phba->mbox_mem_pool);
5873
dea31012005-04-17 16:05:31 -05005874 return hs;
5875}
5876
James Smarte59058c2008-08-24 21:49:00 -04005877/**
James Smart3621a712009-04-06 18:47:14 -04005878 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005879 * @shost: kernel scsi host pointer.
5880 **/
James Smart64ba8812006-08-02 15:24:34 -04005881static void
5882lpfc_reset_stats(struct Scsi_Host *shost)
5883{
James Smart2e0fef82007-06-17 19:56:36 -05005884 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5885 struct lpfc_hba *phba = vport->phba;
5886 struct lpfc_sli *psli = &phba->sli;
5887 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005888 LPFC_MBOXQ_t *pmboxq;
5889 MAILBOX_t *pmb;
5890 int rc = 0;
5891
James Smart2e0fef82007-06-17 19:56:36 -05005892 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005893 return;
5894
James Smart64ba8812006-08-02 15:24:34 -04005895 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5896 if (!pmboxq)
5897 return;
5898 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5899
James Smart04c68492009-05-22 14:52:52 -04005900 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005901 pmb->mbxCommand = MBX_READ_STATUS;
5902 pmb->mbxOwner = OWN_HOST;
5903 pmb->un.varWords[0] = 0x1; /* reset request */
5904 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005905 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005906
James Smart2e0fef82007-06-17 19:56:36 -05005907 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005908 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005909 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5910 else
5911 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5912
5913 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005914 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005915 mempool_free(pmboxq, phba->mbox_mem_pool);
5916 return;
5917 }
5918
5919 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5920 pmb->mbxCommand = MBX_READ_LNK_STAT;
5921 pmb->mbxOwner = OWN_HOST;
5922 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005923 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005924
James Smart2e0fef82007-06-17 19:56:36 -05005925 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005926 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005927 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5928 else
5929 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5930
5931 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005932 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005933 mempool_free( pmboxq, phba->mbox_mem_pool);
5934 return;
5935 }
5936
5937 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5938 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5939 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5940 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5941 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5942 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5943 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005944 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005945 lso->link_events = (phba->link_events >> 1);
5946 else
5947 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005948
5949 psli->stats_start = get_seconds();
5950
James Smart1dcb58e2007-04-25 09:51:30 -04005951 mempool_free(pmboxq, phba->mbox_mem_pool);
5952
James Smart64ba8812006-08-02 15:24:34 -04005953 return;
5954}
dea31012005-04-17 16:05:31 -05005955
5956/*
5957 * The LPFC driver treats linkdown handling as target loss events so there
5958 * are no sysfs handlers for link_down_tmo.
5959 */
James Smart685f0bf2007-04-25 09:53:08 -04005960
James Smarte59058c2008-08-24 21:49:00 -04005961/**
James Smart3621a712009-04-06 18:47:14 -04005962 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005963 * @starget: kernel scsi target pointer.
5964 *
5965 * Returns:
5966 * address of the node list if found
5967 * NULL target not found
5968 **/
James Smart685f0bf2007-04-25 09:53:08 -04005969static struct lpfc_nodelist *
5970lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005971{
James Smart2e0fef82007-06-17 19:56:36 -05005972 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5973 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005974 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005975
5976 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005977 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005978 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005979 if (NLP_CHK_NODE_ACT(ndlp) &&
5980 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005981 starget->id == ndlp->nlp_sid) {
5982 spin_unlock_irq(shost->host_lock);
5983 return ndlp;
dea31012005-04-17 16:05:31 -05005984 }
5985 }
5986 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005987 return NULL;
5988}
dea31012005-04-17 16:05:31 -05005989
James Smarte59058c2008-08-24 21:49:00 -04005990/**
James Smart3621a712009-04-06 18:47:14 -04005991 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005992 * @starget: kernel scsi target pointer.
5993 **/
James Smart685f0bf2007-04-25 09:53:08 -04005994static void
5995lpfc_get_starget_port_id(struct scsi_target *starget)
5996{
5997 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5998
5999 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05006000}
6001
James Smarte59058c2008-08-24 21:49:00 -04006002/**
James Smart3621a712009-04-06 18:47:14 -04006003 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04006004 * @starget: kernel scsi target pointer.
6005 *
6006 * Description: Set the target node name to the ndlp node name wwn or zero.
6007 **/
dea31012005-04-17 16:05:31 -05006008static void
6009lpfc_get_starget_node_name(struct scsi_target *starget)
6010{
James Smart685f0bf2007-04-25 09:53:08 -04006011 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006012
James Smart685f0bf2007-04-25 09:53:08 -04006013 fc_starget_node_name(starget) =
6014 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006015}
6016
James Smarte59058c2008-08-24 21:49:00 -04006017/**
James Smart3621a712009-04-06 18:47:14 -04006018 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04006019 * @starget: kernel scsi target pointer.
6020 *
6021 * Description: set the target port name to the ndlp port name wwn or zero.
6022 **/
dea31012005-04-17 16:05:31 -05006023static void
6024lpfc_get_starget_port_name(struct scsi_target *starget)
6025{
James Smart685f0bf2007-04-25 09:53:08 -04006026 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006027
James Smart685f0bf2007-04-25 09:53:08 -04006028 fc_starget_port_name(starget) =
6029 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006030}
6031
James Smarte59058c2008-08-24 21:49:00 -04006032/**
James Smart3621a712009-04-06 18:47:14 -04006033 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04006034 * @rport: fc rport address.
6035 * @timeout: new value for dev loss tmo.
6036 *
6037 * Description:
6038 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6039 * dev_loss_tmo to one.
6040 **/
dea31012005-04-17 16:05:31 -05006041static void
dea31012005-04-17 16:05:31 -05006042lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6043{
dea31012005-04-17 16:05:31 -05006044 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006045 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006046 else
James Smartc01f3202006-08-18 17:47:08 -04006047 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006048}
6049
James Smarte59058c2008-08-24 21:49:00 -04006050/**
James Smart3621a712009-04-06 18:47:14 -04006051 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006052 *
6053 * Description:
6054 * Macro that uses field to generate a function with the name lpfc_show_rport_
6055 *
6056 * lpfc_show_rport_##field: returns the bytes formatted in buf
6057 * @cdev: class converted to an fc_rport.
6058 * @buf: on return contains the target_field or zero.
6059 *
6060 * Returns: size of formatted string.
6061 **/
dea31012005-04-17 16:05:31 -05006062#define lpfc_rport_show_function(field, format_string, sz, cast) \
6063static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006064lpfc_show_rport_##field (struct device *dev, \
6065 struct device_attribute *attr, \
6066 char *buf) \
dea31012005-04-17 16:05:31 -05006067{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006068 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006069 struct lpfc_rport_data *rdata = rport->hostdata; \
6070 return snprintf(buf, sz, format_string, \
6071 (rdata->target) ? cast rdata->target->field : 0); \
6072}
6073
6074#define lpfc_rport_rd_attr(field, format_string, sz) \
6075 lpfc_rport_show_function(field, format_string, sz, ) \
6076static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6077
James Smarteada2722008-12-04 22:39:13 -05006078/**
James Smart3621a712009-04-06 18:47:14 -04006079 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006080 * @fc_vport: The fc_vport who's symbolic name has been changed.
6081 *
6082 * Description:
6083 * This function is called by the transport after the @fc_vport's symbolic name
6084 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006085 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006086 **/
6087static void
6088lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6089{
6090 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6091
6092 if (vport->port_state == LPFC_VPORT_READY)
6093 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6094}
dea31012005-04-17 16:05:31 -05006095
James Smartf4b4c682009-05-22 14:53:12 -04006096/**
6097 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6098 * @phba: Pointer to lpfc_hba struct.
6099 *
6100 * This function is called by the lpfc_get_cfgparam() routine to set the
6101 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006102 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006103 * before hba port or vport created.
6104 **/
6105static void
6106lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6107{
6108 phba->cfg_log_verbose = verbose;
6109}
6110
dea31012005-04-17 16:05:31 -05006111struct fc_function_template lpfc_transport_functions = {
6112 /* fixed attributes the driver supports */
6113 .show_host_node_name = 1,
6114 .show_host_port_name = 1,
6115 .show_host_supported_classes = 1,
6116 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006117 .show_host_supported_speeds = 1,
6118 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006119
6120 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006121 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006122
6123 /* dynamic attributes the driver supports */
6124 .get_host_port_id = lpfc_get_host_port_id,
6125 .show_host_port_id = 1,
6126
6127 .get_host_port_type = lpfc_get_host_port_type,
6128 .show_host_port_type = 1,
6129
6130 .get_host_port_state = lpfc_get_host_port_state,
6131 .show_host_port_state = 1,
6132
6133 /* active_fc4s is shown but doesn't change (thus no get function) */
6134 .show_host_active_fc4s = 1,
6135
6136 .get_host_speed = lpfc_get_host_speed,
6137 .show_host_speed = 1,
6138
6139 .get_host_fabric_name = lpfc_get_host_fabric_name,
6140 .show_host_fabric_name = 1,
6141
6142 /*
6143 * The LPFC driver treats linkdown handling as target loss events
6144 * so there are no sysfs handlers for link_down_tmo.
6145 */
6146
6147 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006148 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006149
6150 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6151 .show_rport_maxframe_size = 1,
6152 .show_rport_supported_classes = 1,
6153
dea31012005-04-17 16:05:31 -05006154 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6155 .show_rport_dev_loss_tmo = 1,
6156
6157 .get_starget_port_id = lpfc_get_starget_port_id,
6158 .show_starget_port_id = 1,
6159
6160 .get_starget_node_name = lpfc_get_starget_node_name,
6161 .show_starget_node_name = 1,
6162
6163 .get_starget_port_name = lpfc_get_starget_port_name,
6164 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006165
6166 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006167 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6168 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006169
James Smart92d7f7b2007-06-17 19:56:38 -05006170 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006171
6172 .vport_disable = lpfc_vport_disable,
6173
6174 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006175
6176 .bsg_request = lpfc_bsg_request,
6177 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006178};
6179
James Smart98c9ea52007-10-27 13:37:33 -04006180struct fc_function_template lpfc_vport_transport_functions = {
6181 /* fixed attributes the driver supports */
6182 .show_host_node_name = 1,
6183 .show_host_port_name = 1,
6184 .show_host_supported_classes = 1,
6185 .show_host_supported_fc4s = 1,
6186 .show_host_supported_speeds = 1,
6187 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006188
6189 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006190 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006191
6192 /* dynamic attributes the driver supports */
6193 .get_host_port_id = lpfc_get_host_port_id,
6194 .show_host_port_id = 1,
6195
6196 .get_host_port_type = lpfc_get_host_port_type,
6197 .show_host_port_type = 1,
6198
6199 .get_host_port_state = lpfc_get_host_port_state,
6200 .show_host_port_state = 1,
6201
6202 /* active_fc4s is shown but doesn't change (thus no get function) */
6203 .show_host_active_fc4s = 1,
6204
6205 .get_host_speed = lpfc_get_host_speed,
6206 .show_host_speed = 1,
6207
6208 .get_host_fabric_name = lpfc_get_host_fabric_name,
6209 .show_host_fabric_name = 1,
6210
6211 /*
6212 * The LPFC driver treats linkdown handling as target loss events
6213 * so there are no sysfs handlers for link_down_tmo.
6214 */
6215
6216 .get_fc_host_stats = lpfc_get_stats,
6217 .reset_fc_host_stats = lpfc_reset_stats,
6218
6219 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6220 .show_rport_maxframe_size = 1,
6221 .show_rport_supported_classes = 1,
6222
6223 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6224 .show_rport_dev_loss_tmo = 1,
6225
6226 .get_starget_port_id = lpfc_get_starget_port_id,
6227 .show_starget_port_id = 1,
6228
6229 .get_starget_node_name = lpfc_get_starget_node_name,
6230 .show_starget_node_name = 1,
6231
6232 .get_starget_port_name = lpfc_get_starget_port_name,
6233 .show_starget_port_name = 1,
6234
6235 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6236 .terminate_rport_io = lpfc_terminate_rport_io,
6237
6238 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006239
6240 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006241};
6242
James Smarte59058c2008-08-24 21:49:00 -04006243/**
James Smart3621a712009-04-06 18:47:14 -04006244 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006245 * @phba: lpfc_hba pointer.
6246 **/
dea31012005-04-17 16:05:31 -05006247void
6248lpfc_get_cfgparam(struct lpfc_hba *phba)
6249{
James Smart49aa1432012-08-03 12:36:42 -04006250 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006251 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006252 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6253 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006254 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006255 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6256 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006257 lpfc_ack0_init(phba, lpfc_ack0);
6258 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006259 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006260 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006261 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006262 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006263 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006264 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006265 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6266 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006267 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006268 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart0cf07f842017-06-01 21:07:10 -07006269 lpfc_auto_imax_init(phba, lpfc_auto_imax);
James Smartda0436e2009-05-22 14:51:39 -04006270 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006271 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006272 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6273 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006274
James Smart1ba981f2014-02-20 09:56:45 -05006275 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6276 if (phba->sli_rev != LPFC_SLI_REV4)
6277 phba->cfg_EnableXLane = 0;
6278 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006279
James Smart1ba981f2014-02-20 09:56:45 -05006280 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6281 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6282 phba->cfg_oas_lun_state = 0;
6283 phba->cfg_oas_lun_status = 0;
6284 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006285 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006286 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006287 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6288 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006289 if (phba->sli_rev == LPFC_SLI_REV4)
6290 phba->cfg_poll = 0;
6291 else
James Smart1ba981f2014-02-20 09:56:45 -05006292 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006293 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006294
James Smart895427b2017-02-12 13:52:30 -08006295 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006296 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart895427b2017-02-12 13:52:30 -08006297
6298 /* Initialize first burst. Target vs Initiator are different. */
6299 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006300 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006301 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6302 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
James Smart44fd7fe2017-08-23 16:55:47 -07006303 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart895427b2017-02-12 13:52:30 -08006304
6305 if (phba->sli_rev != LPFC_SLI_REV4) {
6306 /* NVME only supported on SLI4 */
6307 phba->nvmet_support = 0;
6308 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07006309 phba->cfg_enable_bbcr = 0;
James Smart895427b2017-02-12 13:52:30 -08006310 } else {
6311 /* We MUST have FCP support */
6312 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6313 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6314 }
6315
James Smart0cf07f842017-06-01 21:07:10 -07006316 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6317 phba->cfg_auto_imax = 0;
6318 phba->initial_imax = phba->cfg_fcp_imax;
6319
James Smart895427b2017-02-12 13:52:30 -08006320 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006321 if (phba->cfg_fcp_io_channel == 0)
6322 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006323 if (phba->cfg_nvme_io_channel == 0)
6324 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006325
6326 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6327 phba->cfg_fcp_io_channel = 0;
6328
James Smartf358dd02017-02-12 13:52:34 -08006329 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6330 phba->cfg_nvme_io_channel = 0;
6331
James Smart895427b2017-02-12 13:52:30 -08006332 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6333 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6334 else
6335 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006336
James Smart352e5fd2016-12-30 06:57:47 -08006337 phba->cfg_soft_wwnn = 0L;
6338 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006339 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006340 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006341 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006342 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006343 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006344 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006345 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006346 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006347 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006348 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006349 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006350 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006351 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006352 return;
6353}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006354
James Smarte59058c2008-08-24 21:49:00 -04006355/**
James Smart895427b2017-02-12 13:52:30 -08006356 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6357 * dependencies between protocols and roles.
6358 * @phba: lpfc_hba pointer.
6359 **/
6360void
6361lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6362{
James Smart895427b2017-02-12 13:52:30 -08006363 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6364 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006365
James Smart895427b2017-02-12 13:52:30 -08006366 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6367 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6368
James Smartf358dd02017-02-12 13:52:34 -08006369 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6370 phba->nvmet_support) {
6371 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6372 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006373
6374 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6375 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6376 "NVME Target PRLI ACC enable_fb ",
6377 phba->cfg_nvme_enable_fb,
6378 phba->cfg_nvmet_fb_size,
6379 LPFC_NVMET_FB_SZ_MAX);
6380
6381 if (phba->cfg_nvme_enable_fb == 0)
6382 phba->cfg_nvmet_fb_size = 0;
6383 else {
6384 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6385 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6386 }
6387
James Smartbcb24f62017-11-20 16:00:36 -08006388 if (!phba->cfg_nvmet_mrq)
6389 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6390
James Smart2d7dbc42017-02-12 13:52:35 -08006391 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6392 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6393 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6394 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6395 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6396 phba->cfg_nvmet_mrq);
6397 }
James Smartbcb24f62017-11-20 16:00:36 -08006398 if (phba->cfg_nvmet_mrq > LPFC_NVMET_MRQ_MAX)
6399 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_MAX;
6400
James Smart2d7dbc42017-02-12 13:52:35 -08006401 } else {
James Smartf358dd02017-02-12 13:52:34 -08006402 /* Not NVME Target mode. Turn off Target parameters. */
6403 phba->nvmet_support = 0;
James Smartbcb24f62017-11-20 16:00:36 -08006404 phba->cfg_nvmet_mrq = LPFC_NVMET_MRQ_OFF;
James Smart2d7dbc42017-02-12 13:52:35 -08006405 phba->cfg_nvmet_fb_size = 0;
6406 }
James Smartf358dd02017-02-12 13:52:34 -08006407
James Smart895427b2017-02-12 13:52:30 -08006408 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6409 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6410 else
6411 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6412}
6413
6414/**
James Smart3621a712009-04-06 18:47:14 -04006415 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006416 * @vport: lpfc_vport pointer.
6417 **/
James Smart3de2a652007-08-02 11:09:59 -04006418void
6419lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6420{
James Smarte8b62012007-08-02 11:10:09 -04006421 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006422 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006423 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006424 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6425 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6426 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6427 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6428 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6429 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006430 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006431 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006432 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6433 lpfc_max_luns_init(vport, lpfc_max_luns);
6434 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006435 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006436 return;
6437}