blob: 3e02bc3a7c3f7990c2354e858055770290d37a4a [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 Smart80cc0042017-06-01 21:06:56 -0700151 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -0800152 struct nvme_fc_remote_port *nrport;
James Smart2cee7802017-06-01 21:07:02 -0700153 uint64_t data1, data2, data3, tot;
James Smart895427b2017-02-12 13:52:30 -0800154 char *statep;
155 int len = 0;
156
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
159 return len;
160 }
James Smartf358dd02017-02-12 13:52:34 -0800161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
166 return len;
167 }
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
171 else
172 statep = "INIT";
173 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartb4fd6812017-06-15 22:56:42 -0700174 "NVME Target Enabled State %s\n",
James Smartf358dd02017-02-12 13:52:34 -0800175 statep);
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
178 "NVME Target: lpfc",
179 phba->brd_no,
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
183
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200184 len += snprintf(buf + len, PAGE_SIZE - len,
James Smartf358dd02017-02-12 13:52:34 -0800185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
198 }
199
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
206
207 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart50738422017-08-01 15:12:40 -0700208 "FCP: Rcv %08x Defer %08x Release %08x "
209 "Drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800210 atomic_read(&tgtp->rcv_fcp_cmd_in),
James Smart50738422017-08-01 15:12:40 -0700211 atomic_read(&tgtp->rcv_fcp_cmd_defer),
James Smart547077a2017-05-15 15:20:40 -0700212 atomic_read(&tgtp->xmt_fcp_release),
James Smartf358dd02017-02-12 13:52:34 -0800213 atomic_read(&tgtp->rcv_fcp_cmd_drop));
214
215 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
216 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
217 len += snprintf(buf+len, PAGE_SIZE-len,
218 "Rcv FCP: in %08x != out %08x\n",
219 atomic_read(&tgtp->rcv_fcp_cmd_in),
220 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 }
222
223 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700224 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
225 "drop %08x\n",
James Smartf358dd02017-02-12 13:52:34 -0800226 atomic_read(&tgtp->xmt_fcp_read),
227 atomic_read(&tgtp->xmt_fcp_read_rsp),
228 atomic_read(&tgtp->xmt_fcp_write),
James Smart547077a2017-05-15 15:20:40 -0700229 atomic_read(&tgtp->xmt_fcp_rsp),
James Smartf358dd02017-02-12 13:52:34 -0800230 atomic_read(&tgtp->xmt_fcp_drop));
231
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart547077a2017-05-15 15:20:40 -0700239 "ABORT: Xmt %08x Cmpl %08x\n",
240 atomic_read(&tgtp->xmt_fcp_abort),
241 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
242
243 len += snprintf(buf + len, PAGE_SIZE - len,
244 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
245 atomic_read(&tgtp->xmt_abort_sol),
246 atomic_read(&tgtp->xmt_abort_unsol),
James Smartf358dd02017-02-12 13:52:34 -0800247 atomic_read(&tgtp->xmt_abort_rsp),
James Smart547077a2017-05-15 15:20:40 -0700248 atomic_read(&tgtp->xmt_abort_rsp_error));
James Smartf358dd02017-02-12 13:52:34 -0800249
Dick Kennedy66d7ce92017-08-23 16:55:42 -0700250 /* Calculate outstanding IOs */
251 tot = atomic_read(&tgtp->rcv_fcp_cmd_drop);
252 tot += atomic_read(&tgtp->xmt_fcp_release);
253 tot = atomic_read(&tgtp->rcv_fcp_cmd_in) - tot;
James Smart2cee7802017-06-01 21:07:02 -0700254
James Smarta8cf5df2017-05-15 15:20:46 -0700255 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart2cee7802017-06-01 21:07:02 -0700256 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
257 "CTX Outstanding %08llx\n",
James Smart966bb5b2017-06-15 22:56:45 -0700258 phba->sli4_hba.nvmet_xri_cnt,
James Smarta8cf5df2017-05-15 15:20:46 -0700259 phba->sli4_hba.nvmet_io_wait_cnt,
James Smart2cee7802017-06-01 21:07:02 -0700260 phba->sli4_hba.nvmet_io_wait_total,
261 tot);
James Smarta8cf5df2017-05-15 15:20:46 -0700262
James Smartf358dd02017-02-12 13:52:34 -0800263 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
264 return len;
265 }
James Smart895427b2017-02-12 13:52:30 -0800266
267 localport = vport->localport;
268 if (!localport) {
269 len = snprintf(buf, PAGE_SIZE,
270 "NVME Initiator x%llx is not allocated\n",
271 wwn_to_u64(vport->fc_portname.u.wwn));
272 return len;
273 }
274 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
275
276 spin_lock_irq(shost->host_lock);
James Smart895427b2017-02-12 13:52:30 -0800277
278 /* Port state is only one of two values for now. */
279 if (localport->port_id)
280 statep = "ONLINE";
281 else
282 statep = "UNKNOWN ";
283
284 len += snprintf(buf + len, PAGE_SIZE - len,
285 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
286 "NVME LPORT lpfc",
287 phba->brd_no,
288 wwn_to_u64(vport->fc_portname.u.wwn),
289 wwn_to_u64(vport->fc_nodename.u.wwn),
290 localport->port_id, statep);
291
James Smart80cc0042017-06-01 21:06:56 -0700292 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
293 if (!ndlp->nrport)
294 continue;
295
James Smart895427b2017-02-12 13:52:30 -0800296 /* local short-hand pointer. */
James Smart80cc0042017-06-01 21:06:56 -0700297 nrport = ndlp->nrport->remoteport;
James Smart895427b2017-02-12 13:52:30 -0800298
299 /* Port state is only one of two values for now. */
300 switch (nrport->port_state) {
301 case FC_OBJSTATE_ONLINE:
302 statep = "ONLINE";
303 break;
304 case FC_OBJSTATE_UNKNOWN:
305 statep = "UNKNOWN ";
306 break;
307 default:
308 statep = "UNSUPPORTED";
309 break;
310 }
311
312 /* Tab in to show lport ownership. */
313 len += snprintf(buf + len, PAGE_SIZE - len,
314 "NVME RPORT ");
315 if (phba->brd_no >= 10)
316 len += snprintf(buf + len, PAGE_SIZE - len, " ");
317
318 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
319 nrport->port_name);
320 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
321 nrport->node_name);
322 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
323 nrport->port_id);
324
James Smart7d790f02017-06-01 21:06:57 -0700325 /* An NVME rport can have multiple roles. */
326 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
James Smart895427b2017-02-12 13:52:30 -0800327 len += snprintf(buf + len, PAGE_SIZE - len,
328 "INITIATOR ");
James Smart7d790f02017-06-01 21:06:57 -0700329 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
James Smart895427b2017-02-12 13:52:30 -0800330 len += snprintf(buf + len, PAGE_SIZE - len,
331 "TARGET ");
James Smart7d790f02017-06-01 21:06:57 -0700332 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
James Smart895427b2017-02-12 13:52:30 -0800333 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700334 "DISCSRVC ");
335 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
336 FC_PORT_ROLE_NVME_TARGET |
337 FC_PORT_ROLE_NVME_DISCOVERY))
James Smart895427b2017-02-12 13:52:30 -0800338 len += snprintf(buf + len, PAGE_SIZE - len,
James Smart7d790f02017-06-01 21:06:57 -0700339 "UNKNOWN ROLE x%x",
James Smart895427b2017-02-12 13:52:30 -0800340 nrport->port_role);
James Smart7d790f02017-06-01 21:06:57 -0700341
James Smart895427b2017-02-12 13:52:30 -0800342 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
343 /* Terminate the string. */
344 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
345 }
346 spin_unlock_irq(shost->host_lock);
347
Maurizio Lombardiea98ab32017-04-18 11:55:51 +0200348 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
James Smart895427b2017-02-12 13:52:30 -0800349 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart2cee7802017-06-01 21:07:02 -0700350 "LS: Xmt %016x Cmpl %016x\n",
351 atomic_read(&phba->fc4NvmeLsRequests),
352 atomic_read(&phba->fc4NvmeLsCmpls));
James Smart895427b2017-02-12 13:52:30 -0800353
James Smart2cee7802017-06-01 21:07:02 -0700354 tot = atomic_read(&phba->fc4NvmeIoCmpls);
355 data1 = atomic_read(&phba->fc4NvmeInputRequests);
356 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
357 data3 = atomic_read(&phba->fc4NvmeControlRequests);
James Smart895427b2017-02-12 13:52:30 -0800358 len += snprintf(buf+len, PAGE_SIZE-len,
359 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
James Smart2cee7802017-06-01 21:07:02 -0700360 data1, data2, data3);
James Smart895427b2017-02-12 13:52:30 -0800361
362 len += snprintf(buf+len, PAGE_SIZE-len,
James Smart2cee7802017-06-01 21:07:02 -0700363 " Cmpl %016llx Outstanding %016llx\n",
364 tot, (data1 + data2 + data3) - tot);
James Smart895427b2017-02-12 13:52:30 -0800365 return len;
366}
367
368static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500369lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
370 char *buf)
371{
372 struct Scsi_Host *shost = class_to_shost(dev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
375
376 if (phba->cfg_enable_bg)
377 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
378 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
379 else
380 return snprintf(buf, PAGE_SIZE,
381 "BlockGuard Not Supported\n");
382 else
383 return snprintf(buf, PAGE_SIZE,
384 "BlockGuard Disabled\n");
385}
386
387static ssize_t
388lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
389 char *buf)
390{
391 struct Scsi_Host *shost = class_to_shost(dev);
392 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
393 struct lpfc_hba *phba = vport->phba;
394
James Smart87b5c322008-12-16 10:34:09 -0500395 return snprintf(buf, PAGE_SIZE, "%llu\n",
396 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500397}
398
399static ssize_t
400lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
401 char *buf)
402{
403 struct Scsi_Host *shost = class_to_shost(dev);
404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
405 struct lpfc_hba *phba = vport->phba;
406
James Smart87b5c322008-12-16 10:34:09 -0500407 return snprintf(buf, PAGE_SIZE, "%llu\n",
408 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500409}
410
411static ssize_t
412lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
414{
415 struct Scsi_Host *shost = class_to_shost(dev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
418
James Smart87b5c322008-12-16 10:34:09 -0500419 return snprintf(buf, PAGE_SIZE, "%llu\n",
420 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500421}
422
James Smarte59058c2008-08-24 21:49:00 -0400423/**
James Smart3621a712009-04-06 18:47:14 -0400424 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400425 * @dev: class converted to a Scsi_host structure.
426 * @attr: device attribute, not used.
427 * @buf: on return contains the formatted text from lpfc_info().
428 *
429 * Returns: size of formatted string.
430 **/
dea31012005-04-17 16:05:31 -0500431static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100432lpfc_info_show(struct device *dev, struct device_attribute *attr,
433 char *buf)
dea31012005-04-17 16:05:31 -0500434{
Tony Jonesee959b02008-02-22 00:13:36 +0100435 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500436
dea31012005-04-17 16:05:31 -0500437 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
438}
439
James Smarte59058c2008-08-24 21:49:00 -0400440/**
James Smart3621a712009-04-06 18:47:14 -0400441 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400442 * @dev: class converted to a Scsi_host structure.
443 * @attr: device attribute, not used.
444 * @buf: on return contains the formatted text serial number.
445 *
446 * Returns: size of formatted string.
447 **/
dea31012005-04-17 16:05:31 -0500448static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100449lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
450 char *buf)
dea31012005-04-17 16:05:31 -0500451{
Tony Jonesee959b02008-02-22 00:13:36 +0100452 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
454 struct lpfc_hba *phba = vport->phba;
455
dea31012005-04-17 16:05:31 -0500456 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
457}
458
James Smarte59058c2008-08-24 21:49:00 -0400459/**
James Smart3621a712009-04-06 18:47:14 -0400460 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400461 * @dev: class converted to a Scsi_host structure.
462 * @attr: device attribute, not used.
463 * @buf: on return contains the formatted support level.
464 *
465 * Description:
466 * Returns a number indicating the temperature sensor level currently
467 * supported, zero or one in ascii.
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_temp_sensor_show(struct device *dev, struct device_attribute *attr,
473 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400474{
Tony Jonesee959b02008-02-22 00:13:36 +0100475 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400476 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
477 struct lpfc_hba *phba = vport->phba;
478 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
479}
480
James Smarte59058c2008-08-24 21:49:00 -0400481/**
James Smart3621a712009-04-06 18:47:14 -0400482 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400483 * @dev: class converted to a Scsi_host structure.
484 * @attr: device attribute, not used.
485 * @buf: on return contains the scsi vpd model description.
486 *
487 * Returns: size of formatted string.
488 **/
James Smart57127f12007-10-27 13:37:05 -0400489static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100490lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
491 char *buf)
dea31012005-04-17 16:05:31 -0500492{
Tony Jonesee959b02008-02-22 00:13:36 +0100493 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500494 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
495 struct lpfc_hba *phba = vport->phba;
496
dea31012005-04-17 16:05:31 -0500497 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
498}
499
James Smarte59058c2008-08-24 21:49:00 -0400500/**
James Smart3621a712009-04-06 18:47:14 -0400501 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400502 * @dev: class converted to a Scsi_host structure.
503 * @attr: device attribute, not used.
504 * @buf: on return contains the scsi vpd model name.
505 *
506 * Returns: size of formatted string.
507 **/
dea31012005-04-17 16:05:31 -0500508static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100509lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
510 char *buf)
dea31012005-04-17 16:05:31 -0500511{
Tony Jonesee959b02008-02-22 00:13:36 +0100512 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
514 struct lpfc_hba *phba = vport->phba;
515
dea31012005-04-17 16:05:31 -0500516 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
517}
518
James Smarte59058c2008-08-24 21:49:00 -0400519/**
James Smart3621a712009-04-06 18:47:14 -0400520 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400521 * @dev: class converted to a Scsi_host structure.
522 * @attr: device attribute, not used.
523 * @buf: on return contains the scsi vpd program type.
524 *
525 * Returns: size of formatted string.
526 **/
dea31012005-04-17 16:05:31 -0500527static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100528lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
529 char *buf)
dea31012005-04-17 16:05:31 -0500530{
Tony Jonesee959b02008-02-22 00:13:36 +0100531 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
533 struct lpfc_hba *phba = vport->phba;
534
dea31012005-04-17 16:05:31 -0500535 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
536}
537
James Smarte59058c2008-08-24 21:49:00 -0400538/**
James Smart3621a712009-04-06 18:47:14 -0400539 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400540 * @dev: class converted to a Scsi_host structure.
541 * @attr: device attribute, not used.
542 * @buf: on return contains the Menlo Maintenance sli flag.
543 *
544 * Returns: size of formatted string.
545 **/
546static ssize_t
547lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
548{
549 struct Scsi_Host *shost = class_to_shost(dev);
550 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
551 struct lpfc_hba *phba = vport->phba;
552
553 return snprintf(buf, PAGE_SIZE, "%d\n",
554 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
555}
556
557/**
James Smart3621a712009-04-06 18:47:14 -0400558 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400559 * @dev: class converted to a Scsi_host structure.
560 * @attr: device attribute, not used.
561 * @buf: on return contains scsi vpd program type.
562 *
563 * Returns: size of formatted string.
564 **/
dea31012005-04-17 16:05:31 -0500565static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100566lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
567 char *buf)
dea31012005-04-17 16:05:31 -0500568{
Tony Jonesee959b02008-02-22 00:13:36 +0100569 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
572
dea31012005-04-17 16:05:31 -0500573 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
574}
575
James Smarte59058c2008-08-24 21:49:00 -0400576/**
James Smart3621a712009-04-06 18:47:14 -0400577 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400578 * @dev: class converted to a Scsi_host structure.
579 * @attr: device attribute, not used.
580 * @buf: on return contains the scsi vpd program type.
581 *
582 * Returns: size of formatted string.
583 **/
dea31012005-04-17 16:05:31 -0500584static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100585lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
586 char *buf)
dea31012005-04-17 16:05:31 -0500587{
Tony Jonesee959b02008-02-22 00:13:36 +0100588 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
590 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500591 uint32_t if_type;
592 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500593 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500594 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500595
dea31012005-04-17 16:05:31 -0500596 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500597 if_type = phba->sli4_hba.pc_sli4_params.if_type;
598 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
599
600 if (phba->sli_rev < LPFC_SLI_REV4)
601 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
602 fwrev, phba->sli_rev);
603 else
604 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
605 fwrev, phba->sli_rev, if_type, sli_family);
606
607 return len;
dea31012005-04-17 16:05:31 -0500608}
609
James Smarte59058c2008-08-24 21:49:00 -0400610/**
James Smart3621a712009-04-06 18:47:14 -0400611 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400612 * @dev: class converted to a Scsi_host structure.
613 * @attr: device attribute, not used.
614 * @buf: on return contains the scsi vpd program type.
615 *
616 * Returns: size of formatted string.
617 **/
dea31012005-04-17 16:05:31 -0500618static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100619lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500620{
621 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100622 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
624 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500625 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500626
dea31012005-04-17 16:05:31 -0500627 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
628 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
629}
James Smarte59058c2008-08-24 21:49:00 -0400630
631/**
James Smart3621a712009-04-06 18:47:14 -0400632 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400633 * @dev: class converted to a Scsi_host structure.
634 * @attr: device attribute, not used.
635 * @buf: on return contains the ROM and FCode ascii strings.
636 *
637 * Returns: size of formatted string.
638 **/
dea31012005-04-17 16:05:31 -0500639static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100640lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
641 char *buf)
dea31012005-04-17 16:05:31 -0500642{
Tony Jonesee959b02008-02-22 00:13:36 +0100643 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400646 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500647
James Smarta0683bf2015-04-07 15:07:16 -0400648 if (phba->sli_rev < LPFC_SLI_REV4)
649 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
650
651 lpfc_decode_firmware_rev(phba, fwrev, 1);
652 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500653}
James Smarte59058c2008-08-24 21:49:00 -0400654
655/**
James Smart3621a712009-04-06 18:47:14 -0400656 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400657 * @dev: class converted to a Scsi_host structure.
658 * @attr: device attribute, not used.
659 * @buf: on return contains text describing the state of the link.
660 *
661 * Notes:
662 * The switch statement has no default so zero will be returned.
663 *
664 * Returns: size of formatted string.
665 **/
dea31012005-04-17 16:05:31 -0500666static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100667lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
668 char *buf)
dea31012005-04-17 16:05:31 -0500669{
Tony Jonesee959b02008-02-22 00:13:36 +0100670 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
672 struct lpfc_hba *phba = vport->phba;
673 int len = 0;
674
675 switch (phba->link_state) {
676 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500677 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500678 case LPFC_INIT_START:
679 case LPFC_INIT_MBX_CMDS:
680 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500681 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400682 if (phba->hba_flag & LINK_DISABLED)
683 len += snprintf(buf + len, PAGE_SIZE-len,
684 "Link Down - User disabled\n");
685 else
686 len += snprintf(buf + len, PAGE_SIZE-len,
687 "Link Down\n");
dea31012005-04-17 16:05:31 -0500688 break;
689 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500690 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500691 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400692 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500693
694 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500695 case LPFC_LOCAL_CFG_LINK:
696 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500697 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500698 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500699 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500700 case LPFC_FLOGI:
701 case LPFC_FABRIC_CFG_LINK:
702 case LPFC_NS_REG:
703 case LPFC_NS_QRY:
704 case LPFC_BUILD_DISC_LIST:
705 case LPFC_DISC_AUTH:
706 len += snprintf(buf + len, PAGE_SIZE - len,
707 "Discovery\n");
708 break;
709 case LPFC_VPORT_READY:
710 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
711 break;
712
James Smart92d7f7b2007-06-17 19:56:38 -0500713 case LPFC_VPORT_FAILED:
714 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
715 break;
716
717 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500718 len += snprintf(buf + len, PAGE_SIZE - len,
719 "Unknown\n");
720 break;
721 }
James Smart84774a42008-08-24 21:50:06 -0400722 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
723 len += snprintf(buf + len, PAGE_SIZE-len,
724 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500725 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500726 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500727 len += snprintf(buf + len, PAGE_SIZE-len,
728 " Public Loop\n");
729 else
730 len += snprintf(buf + len, PAGE_SIZE-len,
731 " Private Loop\n");
732 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500733 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500734 len += snprintf(buf + len, PAGE_SIZE-len,
735 " Fabric\n");
736 else
737 len += snprintf(buf + len, PAGE_SIZE-len,
738 " Point-2-Point\n");
739 }
740 }
James Smart2e0fef82007-06-17 19:56:36 -0500741
dea31012005-04-17 16:05:31 -0500742 return len;
743}
744
James Smarte59058c2008-08-24 21:49:00 -0400745/**
James Smart026abb82011-12-13 13:20:45 -0500746 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
747 * @dev: class unused variable.
748 * @attr: device attribute, not used.
749 * @buf: on return contains the module description text.
750 *
751 * Returns: size of formatted string.
752 **/
753static ssize_t
754lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
755 char *buf)
756{
757 struct Scsi_Host *shost = class_to_shost(dev);
758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
759 struct lpfc_hba *phba = vport->phba;
760
761 if (phba->sli_rev < LPFC_SLI_REV4)
762 return snprintf(buf, PAGE_SIZE, "fc\n");
763
764 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
765 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
766 return snprintf(buf, PAGE_SIZE, "fcoe\n");
767 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
768 return snprintf(buf, PAGE_SIZE, "fc\n");
769 }
770 return snprintf(buf, PAGE_SIZE, "unknown\n");
771}
772
773/**
James Smart1ba981f2014-02-20 09:56:45 -0500774 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
775 * (OAS) is supported.
776 * @dev: class unused variable.
777 * @attr: device attribute, not used.
778 * @buf: on return contains the module description text.
779 *
780 * Returns: size of formatted string.
781 **/
782static ssize_t
783lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
784 char *buf)
785{
786 struct Scsi_Host *shost = class_to_shost(dev);
787 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
788 struct lpfc_hba *phba = vport->phba;
789
790 return snprintf(buf, PAGE_SIZE, "%d\n",
791 phba->sli4_hba.pc_sli4_params.oas_supported);
792}
793
794/**
James Smart84d1b002010-02-12 14:42:33 -0500795 * lpfc_link_state_store - Transition the link_state on an HBA port
796 * @dev: class device that is converted into a Scsi_host.
797 * @attr: device attribute, not used.
798 * @buf: one or more lpfc_polling_flags values.
799 * @count: not used.
800 *
801 * Returns:
802 * -EINVAL if the buffer is not "up" or "down"
803 * return from link state change function if non-zero
804 * length of the buf on success
805 **/
806static ssize_t
807lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
809{
810 struct Scsi_Host *shost = class_to_shost(dev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
813
814 int status = -EINVAL;
815
816 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
817 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400818 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500819 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
820 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400821 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500822
823 if (status == 0)
824 return strlen(buf);
825 else
826 return status;
827}
828
829/**
James Smart3621a712009-04-06 18:47:14 -0400830 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400831 * @dev: class device that is converted into a Scsi_host.
832 * @attr: device attribute, not used.
833 * @buf: on return contains the sum of fc mapped and unmapped.
834 *
835 * Description:
836 * Returns the ascii text number of the sum of the fc mapped and unmapped
837 * vport counts.
838 *
839 * Returns: size of formatted string.
840 **/
dea31012005-04-17 16:05:31 -0500841static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100842lpfc_num_discovered_ports_show(struct device *dev,
843 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500844{
Tony Jonesee959b02008-02-22 00:13:36 +0100845 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847
848 return snprintf(buf, PAGE_SIZE, "%d\n",
849 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500850}
851
James Smarte59058c2008-08-24 21:49:00 -0400852/**
James Smart3621a712009-04-06 18:47:14 -0400853 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400854 * @shost: Scsi_Host pointer.
855 *
856 * Description:
857 * Bring the link down gracefully then re-init the link. The firmware will
858 * re-init the fiber channel interface as required. Does not issue a LIP.
859 *
860 * Returns:
861 * -EPERM port offline or management commands are being blocked
862 * -ENOMEM cannot allocate memory for the mailbox command
863 * -EIO error sending the mailbox command
864 * zero for success
865 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700866static int
James Smart2e0fef82007-06-17 19:56:36 -0500867lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500868{
James Smart2e0fef82007-06-17 19:56:36 -0500869 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
870 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500871 LPFC_MBOXQ_t *pmboxq;
872 int mbxstatus = MBXERR_ERROR;
873
James Smart2e0fef82007-06-17 19:56:36 -0500874 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500875 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500876 return -EPERM;
877
878 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
879
880 if (!pmboxq)
881 return -ENOMEM;
882
883 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400884 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
885 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400886
James Smart33ccf8d2006-08-17 11:57:58 -0400887 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500888
James Smart04c68492009-05-22 14:52:52 -0400889 if ((mbxstatus == MBX_SUCCESS) &&
890 (pmboxq->u.mb.mbxStatus == 0 ||
891 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400892 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
893 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
894 phba->cfg_link_speed);
895 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
896 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400897 if ((mbxstatus == MBX_SUCCESS) &&
898 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
899 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
900 "2859 SLI authentication is required "
901 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400902 }
903
James Smart5b8bd0c2007-04-25 09:52:49 -0400904 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500905 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400906 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500907
908 if (mbxstatus == MBXERR_ERROR)
909 return -EIO;
910
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700911 return 0;
dea31012005-04-17 16:05:31 -0500912}
913
James Smart895427b2017-02-12 13:52:30 -0800914int
915lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
916{
917 int cnt = 0;
918
919 spin_lock_irq(lock);
920 while (!list_empty(q)) {
921 spin_unlock_irq(lock);
922 msleep(20);
923 if (cnt++ > 250) { /* 5 secs */
924 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
925 "0466 %s %s\n",
926 "Outstanding IO when ",
927 "bringing Adapter offline\n");
928 return 0;
929 }
930 spin_lock_irq(lock);
931 }
932 spin_unlock_irq(lock);
933 return 1;
934}
935
James Smarte59058c2008-08-24 21:49:00 -0400936/**
James Smart3621a712009-04-06 18:47:14 -0400937 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400938 * @phba: lpfc_hba pointer.
939 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
940 *
941 * Notes:
942 * Assumes any error from lpfc_do_offline() will be negative.
943 * Can wait up to 5 seconds for the port ring buffers count
944 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400945 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400946 *
947 * Returns:
948 * -EIO error posting the event
949 * zero for success
950 **/
James Smart40496f02006-07-06 15:50:22 -0400951static int
James Smart46fa3112007-04-25 09:51:45 -0400952lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
953{
954 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800955 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400956 struct lpfc_sli_ring *pring;
957 struct lpfc_sli *psli;
958 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400959 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500960 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400961
962 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500963 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400964 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500965 if (rc == 0)
966 return -ENOMEM;
967
James Smart46fa3112007-04-25 09:51:45 -0400968 wait_for_completion(&online_compl);
969
970 if (status != 0)
971 return -EIO;
972
973 psli = &phba->sli;
974
James Smart09372822008-01-11 01:52:54 -0500975 /* Wait a little for things to settle down, but not
976 * long enough for dev loss timeout to expire.
977 */
James Smart895427b2017-02-12 13:52:30 -0800978 if (phba->sli_rev != LPFC_SLI_REV4) {
979 for (i = 0; i < psli->num_rings; i++) {
980 pring = &psli->sli3_ring[i];
981 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
982 &phba->hbalock))
983 goto out;
984 }
985 } else {
986 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
987 pring = qp->pring;
988 if (!pring)
989 continue;
990 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
991 &pring->ring_lock))
992 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400993 }
994 }
James Smart895427b2017-02-12 13:52:30 -0800995out:
James Smart46fa3112007-04-25 09:51:45 -0400996 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500997 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
998 if (rc == 0)
999 return -ENOMEM;
1000
James Smart46fa3112007-04-25 09:51:45 -04001001 wait_for_completion(&online_compl);
1002
1003 if (status != 0)
1004 return -EIO;
1005
1006 return 0;
1007}
1008
James Smarte59058c2008-08-24 21:49:00 -04001009/**
James Smart3621a712009-04-06 18:47:14 -04001010 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -04001011 * @phba: lpfc_hba pointer.
1012 *
1013 * Description:
1014 * If the port is configured to allow a reset then the hba is brought
1015 * offline then online.
1016 *
1017 * Notes:
1018 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -05001019 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -04001020 *
1021 * Returns:
1022 * lpfc_do_offline() return code if not zero
1023 * -EIO reset not configured or error posting the event
1024 * zero for success
1025 **/
James Smart7f860592011-03-11 16:05:52 -05001026int
James Smart40496f02006-07-06 15:50:22 -04001027lpfc_selective_reset(struct lpfc_hba *phba)
1028{
1029 struct completion online_compl;
1030 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001031 int rc;
James Smart40496f02006-07-06 15:50:22 -04001032
James Smart71157c92013-07-15 18:34:36 -04001033 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001034 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001035
James Smart71157c92013-07-15 18:34:36 -04001036 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1037 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001038
James Smart71157c92013-07-15 18:34:36 -04001039 if (status != 0)
1040 return status;
1041 }
James Smart40496f02006-07-06 15:50:22 -04001042
1043 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001044 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001045 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001046 if (rc == 0)
1047 return -ENOMEM;
1048
James Smart40496f02006-07-06 15:50:22 -04001049 wait_for_completion(&online_compl);
1050
1051 if (status != 0)
1052 return -EIO;
1053
1054 return 0;
1055}
1056
James Smarte59058c2008-08-24 21:49:00 -04001057/**
James Smart3621a712009-04-06 18:47:14 -04001058 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001059 * @dev: class device that is converted into a Scsi_host.
1060 * @attr: device attribute, not used.
1061 * @buf: containing the string "selective".
1062 * @count: unused variable.
1063 *
1064 * Description:
1065 * If the buf contains the string "selective" then lpfc_selective_reset()
1066 * is called to perform the reset.
1067 *
1068 * Notes:
1069 * Assumes any error from lpfc_selective_reset() will be negative.
1070 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001071 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001072 *
1073 * Returns:
1074 * -EINVAL if the buffer does not contain the string "selective"
1075 * length of buf if lpfc-selective_reset() if the call succeeds
1076 * return value of lpfc_selective_reset() if the call fails
1077**/
James Smart40496f02006-07-06 15:50:22 -04001078static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001079lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1080 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001081{
Tony Jonesee959b02008-02-22 00:13:36 +01001082 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001083 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1084 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001085 int status = -EINVAL;
1086
James Smart73d91e52011-10-10 21:32:10 -04001087 if (!phba->cfg_enable_hba_reset)
1088 return -EACCES;
1089
James Smart40496f02006-07-06 15:50:22 -04001090 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001091 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001092
1093 if (status == 0)
1094 return strlen(buf);
1095 else
1096 return status;
1097}
1098
James Smarte59058c2008-08-24 21:49:00 -04001099/**
James Smart88a2cfb2011-07-22 18:36:33 -04001100 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1101 * @phba: lpfc_hba pointer.
1102 *
1103 * Description:
1104 * SLI4 interface type-2 device to wait on the sliport status register for
1105 * the readyness after performing a firmware reset.
1106 *
1107 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001108 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001109 * reset, -EIO when port timeout from recovering from the reset.
1110 *
1111 * Note:
1112 * As the caller will interpret the return code by value, be careful in making
1113 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001114 **/
James Smart73d91e52011-10-10 21:32:10 -04001115int
James Smart88a2cfb2011-07-22 18:36:33 -04001116lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1117{
James Smartf7a919b2011-08-21 21:49:16 -04001118 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001119 int i;
1120
James Smartf7a919b2011-08-21 21:49:16 -04001121 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001122 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1123 &portstat_reg.word0);
1124
Masanari Iida0b1587b2013-07-17 04:37:44 +09001125 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001126 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1127 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1128 return -EPERM;
1129
James Smart88a2cfb2011-07-22 18:36:33 -04001130 /* wait for the SLI port firmware ready after firmware reset */
1131 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1132 msleep(10);
1133 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1134 &portstat_reg.word0);
1135 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1136 continue;
1137 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1138 continue;
1139 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1140 continue;
1141 break;
1142 }
1143
1144 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1145 return 0;
1146 else
1147 return -EIO;
1148}
1149
1150/**
James Smart52d52442011-05-24 11:42:45 -04001151 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001152 * @phba: lpfc_hba pointer.
1153 *
1154 * Description:
James Smart52d52442011-05-24 11:42:45 -04001155 * Request SLI4 interface type-2 device to perform a physical register set
1156 * access.
James Smartc0c11512011-05-24 11:41:34 -04001157 *
1158 * Returns:
1159 * zero for success
1160 **/
1161static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001162lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001163{
1164 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001165 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001166 uint32_t before_fc_flag;
1167 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001168 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001169 int status = 0, rc = 0;
1170 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001171
1172 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001173 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001174
James Smart52d52442011-05-24 11:42:45 -04001175 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1176 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1177 LPFC_SLI_INTF_IF_TYPE_2))
1178 return -EPERM;
1179
James Smart026abb82011-12-13 13:20:45 -05001180 /* Keep state if we need to restore back */
1181 before_fc_flag = phba->pport->fc_flag;
1182 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1183
James Smartb76f2dc2011-07-22 18:37:42 -04001184 /* Disable SR-IOV virtual functions if enabled */
1185 if (phba->cfg_sriov_nr_virtfn) {
1186 pci_disable_sriov(pdev);
1187 phba->cfg_sriov_nr_virtfn = 0;
1188 }
James Smart229adb02013-04-17 20:16:51 -04001189
James Smart02936352014-04-04 13:52:12 -04001190 if (opcode == LPFC_FW_DUMP)
1191 phba->hba_flag |= HBA_FW_DUMP_OP;
1192
James Smartc0c11512011-05-24 11:41:34 -04001193 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1194
James Smart02936352014-04-04 13:52:12 -04001195 if (status != 0) {
1196 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001197 return status;
James Smart02936352014-04-04 13:52:12 -04001198 }
James Smartc0c11512011-05-24 11:41:34 -04001199
1200 /* wait for the device to be quiesced before firmware reset */
1201 msleep(100);
1202
1203 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1204 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001205
1206 if (opcode == LPFC_FW_DUMP)
1207 reg_val |= LPFC_FW_DUMP_REQUEST;
1208 else if (opcode == LPFC_FW_RESET)
1209 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1210 else if (opcode == LPFC_DV_RESET)
1211 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1212
James Smartc0c11512011-05-24 11:41:34 -04001213 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1214 LPFC_CTL_PDEV_CTL_OFFSET);
1215 /* flush */
1216 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1217
1218 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001219 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1220
James Smart026abb82011-12-13 13:20:45 -05001221 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001222 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001223 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001224 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001225 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001226 } else if (rc == -EIO) {
1227 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001228 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1229 "3153 Fail to perform the requested "
1230 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001231 return rc;
James Smart026abb82011-12-13 13:20:45 -05001232 }
1233
1234 /* keep the original port state */
1235 if (before_fc_flag & FC_OFFLINE_MODE)
1236 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001237
1238 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001239 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1240 LPFC_EVT_ONLINE);
1241 if (!job_posted)
1242 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001243
1244 wait_for_completion(&online_compl);
1245
James Smart026abb82011-12-13 13:20:45 -05001246out:
1247 /* in any case, restore the virtual functions enabled as before */
1248 if (sriov_nr_virtfn) {
1249 sriov_err =
1250 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1251 if (!sriov_err)
1252 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1253 }
James Smartc0c11512011-05-24 11:41:34 -04001254
James Smart026abb82011-12-13 13:20:45 -05001255 /* return proper error code */
1256 if (!rc) {
1257 if (!job_posted)
1258 rc = -ENOMEM;
1259 else if (status)
1260 rc = -EIO;
1261 }
1262 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001263}
1264
1265/**
James Smart3621a712009-04-06 18:47:14 -04001266 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001267 * @dev: class device that is converted into a Scsi_host.
1268 * @attr: device attribute, not used.
1269 * @buf: on return contains the ascii number of nport events.
1270 *
1271 * Returns: size of formatted string.
1272 **/
dea31012005-04-17 16:05:31 -05001273static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001274lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1275 char *buf)
dea31012005-04-17 16:05:31 -05001276{
Tony Jonesee959b02008-02-22 00:13:36 +01001277 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001278 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1279 struct lpfc_hba *phba = vport->phba;
1280
dea31012005-04-17 16:05:31 -05001281 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart3621a712009-04-06 18:47:14 -04001285 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001286 * @dev: class device that is converted into a Scsi_host.
1287 * @attr: device attribute, not used.
1288 * @buf: on return contains the state of the adapter.
1289 *
1290 * Returns: size of formatted string.
1291 **/
dea31012005-04-17 16:05:31 -05001292static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001293lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1294 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001295{
Tony Jonesee959b02008-02-22 00:13:36 +01001296 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001297 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1298 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001299 char * state;
1300
James Smart2e0fef82007-06-17 19:56:36 -05001301 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001302 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001303 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001304 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001305 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001306 state = "offline";
1307 else
1308 state = "online";
1309
1310 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001315 * @dev: class device that is converted into a Scsi_host.
1316 * @attr: device attribute, not used.
1317 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1318 * @count: unused variable.
1319 *
1320 * Returns:
1321 * -EACCES if enable hba reset not enabled
1322 * -EINVAL if the buffer does not contain a valid string (see above)
1323 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1324 * buf length greater than zero indicates success
1325 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001326static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001327lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1328 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001329{
Tony Jonesee959b02008-02-22 00:13:36 +01001330 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001331 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1332 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001333 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001334 char *board_mode_str = NULL;
1335 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001336 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001337
James Smart026abb82011-12-13 13:20:45 -05001338 if (!phba->cfg_enable_hba_reset) {
1339 status = -EACCES;
1340 goto board_mode_out;
1341 }
James Smart88a2cfb2011-07-22 18:36:33 -04001342
1343 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001344 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001345
Jamie Wellnitz41415862006-02-28 19:25:27 -05001346 init_completion(&online_compl);
1347
James Smart46fa3112007-04-25 09:51:45 -04001348 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001349 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001350 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001351 if (rc == 0) {
1352 status = -ENOMEM;
1353 goto board_mode_out;
1354 }
James Smart46fa3112007-04-25 09:51:45 -04001355 wait_for_completion(&online_compl);
James Smart522dcee2017-06-01 21:07:03 -07001356 if (status)
1357 status = -EIO;
James Smart46fa3112007-04-25 09:51:45 -04001358 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1359 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001360 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001361 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001362 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001363 else
1364 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001365 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001366 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001367 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001368 else
1369 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001370 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001371 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1372 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1373 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1374 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1375 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001376 else
James Smart026abb82011-12-13 13:20:45 -05001377 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001378
James Smart026abb82011-12-13 13:20:45 -05001379board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001380 if (!status)
1381 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001382 else {
1383 board_mode_str = strchr(buf, '\n');
1384 if (board_mode_str)
1385 *board_mode_str = '\0';
1386 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1387 "3097 Failed \"%s\", status(%d), "
1388 "fc_flag(x%x)\n",
1389 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001390 return status;
James Smart026abb82011-12-13 13:20:45 -05001391 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001392}
1393
James Smarte59058c2008-08-24 21:49:00 -04001394/**
James Smart3621a712009-04-06 18:47:14 -04001395 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001396 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001397 * @mxri: max xri count.
1398 * @axri: available xri count.
1399 * @mrpi: max rpi count.
1400 * @arpi: available rpi count.
1401 * @mvpi: max vpi count.
1402 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001403 *
1404 * Description:
1405 * If an integer pointer for an count is not null then the value for the
1406 * count is returned.
1407 *
1408 * Returns:
1409 * zero on error
1410 * one for success
1411 **/
James Smart311464e2007-08-02 11:10:37 -04001412static int
James Smart858c9f62007-06-17 19:56:39 -05001413lpfc_get_hba_info(struct lpfc_hba *phba,
1414 uint32_t *mxri, uint32_t *axri,
1415 uint32_t *mrpi, uint32_t *arpi,
1416 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001417{
James Smart04c68492009-05-22 14:52:52 -04001418 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001419 LPFC_MBOXQ_t *pmboxq;
1420 MAILBOX_t *pmb;
1421 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001422 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001423
1424 /*
1425 * prevent udev from issuing mailbox commands until the port is
1426 * configured.
1427 */
1428 if (phba->link_state < LPFC_LINK_DOWN ||
1429 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001430 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001431 return 0;
1432
1433 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1434 return 0;
1435
1436 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1437 if (!pmboxq)
1438 return 0;
1439 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1440
James Smart04c68492009-05-22 14:52:52 -04001441 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001442 pmb->mbxCommand = MBX_READ_CONFIG;
1443 pmb->mbxOwner = OWN_HOST;
1444 pmboxq->context1 = NULL;
1445
James Smart75baf692010-06-08 18:31:21 -04001446 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001447 rc = MBX_NOT_FINISHED;
1448 else
1449 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1450
1451 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001452 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001453 mempool_free(pmboxq, phba->mbox_mem_pool);
1454 return 0;
1455 }
1456
James Smartda0436e2009-05-22 14:51:39 -04001457 if (phba->sli_rev == LPFC_SLI_REV4) {
1458 rd_config = &pmboxq->u.mqe.un.rd_config;
1459 if (mrpi)
1460 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1461 if (arpi)
1462 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1463 phba->sli4_hba.max_cfg_param.rpi_used;
1464 if (mxri)
1465 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1466 if (axri)
1467 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1468 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001469
1470 /* Account for differences with SLI-3. Get vpi count from
1471 * mailbox data and subtract one for max vpi value.
1472 */
1473 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1474 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1475
James Smartda0436e2009-05-22 14:51:39 -04001476 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001477 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001478 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001479 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001480 } else {
1481 if (mrpi)
1482 *mrpi = pmb->un.varRdConfig.max_rpi;
1483 if (arpi)
1484 *arpi = pmb->un.varRdConfig.avail_rpi;
1485 if (mxri)
1486 *mxri = pmb->un.varRdConfig.max_xri;
1487 if (axri)
1488 *axri = pmb->un.varRdConfig.avail_xri;
1489 if (mvpi)
1490 *mvpi = pmb->un.varRdConfig.max_vpi;
1491 if (avpi)
1492 *avpi = pmb->un.varRdConfig.avail_vpi;
1493 }
James Smart92d7f7b2007-06-17 19:56:38 -05001494
1495 mempool_free(pmboxq, phba->mbox_mem_pool);
1496 return 1;
1497}
1498
James Smarte59058c2008-08-24 21:49:00 -04001499/**
James Smart3621a712009-04-06 18:47:14 -04001500 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001501 * @dev: class device that is converted into a Scsi_host.
1502 * @attr: device attribute, not used.
1503 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1504 *
1505 * Description:
1506 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1507 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1508 * to "Unknown" and the buffer length is returned, therefore the caller
1509 * must check for "Unknown" in the buffer to detect a failure.
1510 *
1511 * Returns: size of formatted string.
1512 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001513static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001514lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1515 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001516{
Tony Jonesee959b02008-02-22 00:13:36 +01001517 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1519 struct lpfc_hba *phba = vport->phba;
1520 uint32_t cnt;
1521
James Smart858c9f62007-06-17 19:56:39 -05001522 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001523 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1524 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1525}
1526
James Smarte59058c2008-08-24 21:49:00 -04001527/**
James Smart3621a712009-04-06 18:47:14 -04001528 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001529 * @dev: class device that is converted into a Scsi_host.
1530 * @attr: device attribute, not used.
1531 * @buf: containing the used rpi count in decimal or "Unknown".
1532 *
1533 * Description:
1534 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1535 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1536 * to "Unknown" and the buffer length is returned, therefore the caller
1537 * must check for "Unknown" in the buffer to detect a failure.
1538 *
1539 * Returns: size of formatted string.
1540 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001541static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001542lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1543 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001544{
Tony Jonesee959b02008-02-22 00:13:36 +01001545 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001546 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1547 struct lpfc_hba *phba = vport->phba;
1548 uint32_t cnt, acnt;
1549
James Smart858c9f62007-06-17 19:56:39 -05001550 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001551 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1552 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1553}
1554
James Smarte59058c2008-08-24 21:49:00 -04001555/**
James Smart3621a712009-04-06 18:47:14 -04001556 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001557 * @dev: class device that is converted into a Scsi_host.
1558 * @attr: device attribute, not used.
1559 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1560 *
1561 * Description:
1562 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1563 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1564 * to "Unknown" and the buffer length is returned, therefore the caller
1565 * must check for "Unknown" in the buffer to detect a failure.
1566 *
1567 * Returns: size of formatted string.
1568 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001569static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001570lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1571 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001572{
Tony Jonesee959b02008-02-22 00:13:36 +01001573 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1575 struct lpfc_hba *phba = vport->phba;
1576 uint32_t cnt;
1577
James Smart858c9f62007-06-17 19:56:39 -05001578 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001579 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1580 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1581}
1582
James Smarte59058c2008-08-24 21:49:00 -04001583/**
James Smart3621a712009-04-06 18:47:14 -04001584 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001585 * @dev: class device that is converted into a Scsi_host.
1586 * @attr: device attribute, not used.
1587 * @buf: on return contains the used xri count in decimal or "Unknown".
1588 *
1589 * Description:
1590 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1591 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1592 * to "Unknown" and the buffer length is returned, therefore the caller
1593 * must check for "Unknown" in the buffer to detect a failure.
1594 *
1595 * Returns: size of formatted string.
1596 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001597static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001598lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1599 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001600{
Tony Jonesee959b02008-02-22 00:13:36 +01001601 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1603 struct lpfc_hba *phba = vport->phba;
1604 uint32_t cnt, acnt;
1605
James Smart858c9f62007-06-17 19:56:39 -05001606 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1607 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1608 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1609}
1610
James Smarte59058c2008-08-24 21:49:00 -04001611/**
James Smart3621a712009-04-06 18:47:14 -04001612 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001613 * @dev: class device that is converted into a Scsi_host.
1614 * @attr: device attribute, not used.
1615 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1616 *
1617 * Description:
1618 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1619 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1620 * to "Unknown" and the buffer length is returned, therefore the caller
1621 * must check for "Unknown" in the buffer to detect a failure.
1622 *
1623 * Returns: size of formatted string.
1624 **/
James Smart858c9f62007-06-17 19:56:39 -05001625static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001626lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1627 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001628{
Tony Jonesee959b02008-02-22 00:13:36 +01001629 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001630 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1631 struct lpfc_hba *phba = vport->phba;
1632 uint32_t cnt;
1633
1634 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1635 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1636 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1637}
1638
James Smarte59058c2008-08-24 21:49:00 -04001639/**
James Smart3621a712009-04-06 18:47:14 -04001640 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001641 * @dev: class device that is converted into a Scsi_host.
1642 * @attr: device attribute, not used.
1643 * @buf: on return contains the used vpi count in decimal or "Unknown".
1644 *
1645 * Description:
1646 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1647 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1648 * to "Unknown" and the buffer length is returned, therefore the caller
1649 * must check for "Unknown" in the buffer to detect a failure.
1650 *
1651 * Returns: size of formatted string.
1652 **/
James Smart858c9f62007-06-17 19:56:39 -05001653static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001654lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1655 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001656{
Tony Jonesee959b02008-02-22 00:13:36 +01001657 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001658 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1659 struct lpfc_hba *phba = vport->phba;
1660 uint32_t cnt, acnt;
1661
1662 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001663 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1664 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1665}
1666
James Smarte59058c2008-08-24 21:49:00 -04001667/**
James Smart3621a712009-04-06 18:47:14 -04001668 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001669 * @dev: class device that is converted into a Scsi_host.
1670 * @attr: device attribute, not used.
1671 * @buf: text that must be interpreted to determine if npiv is supported.
1672 *
1673 * Description:
1674 * Buffer will contain text indicating npiv is not suppoerted on the port,
1675 * the port is an NPIV physical port, or it is an npiv virtual port with
1676 * the id of the vport.
1677 *
1678 * Returns: size of formatted string.
1679 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001680static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001681lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1682 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001683{
Tony Jonesee959b02008-02-22 00:13:36 +01001684 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001685 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1686 struct lpfc_hba *phba = vport->phba;
1687
1688 if (!(phba->max_vpi))
1689 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1690 if (vport->port_type == LPFC_PHYSICAL_PORT)
1691 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1692 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1693}
1694
James Smarte59058c2008-08-24 21:49:00 -04001695/**
James Smart3621a712009-04-06 18:47:14 -04001696 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001697 * @dev: class device that is converted into a Scsi_host.
1698 * @attr: device attribute, not used.
1699 * @buf: on return contains the cfg_poll in hex.
1700 *
1701 * Notes:
1702 * cfg_poll should be a lpfc_polling_flags type.
1703 *
1704 * Returns: size of formatted string.
1705 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001706static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001707lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1708 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001709{
Tony Jonesee959b02008-02-22 00:13:36 +01001710 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1712 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001713
1714 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1715}
1716
James Smarte59058c2008-08-24 21:49:00 -04001717/**
James Smart3621a712009-04-06 18:47:14 -04001718 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001719 * @dev: class device that is converted into a Scsi_host.
1720 * @attr: device attribute, not used.
1721 * @buf: one or more lpfc_polling_flags values.
1722 * @count: not used.
1723 *
1724 * Notes:
1725 * buf contents converted to integer and checked for a valid value.
1726 *
1727 * Returns:
1728 * -EINVAL if the buffer connot be converted or is out of range
1729 * length of the buf on success
1730 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001731static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001732lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1733 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001734{
Tony Jonesee959b02008-02-22 00:13:36 +01001735 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001736 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1737 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001738 uint32_t creg_val;
1739 uint32_t old_val;
1740 int val=0;
1741
1742 if (!isdigit(buf[0]))
1743 return -EINVAL;
1744
1745 if (sscanf(buf, "%i", &val) != 1)
1746 return -EINVAL;
1747
1748 if ((val & 0x3) != val)
1749 return -EINVAL;
1750
James Smart45ed1192009-10-02 15:17:02 -04001751 if (phba->sli_rev == LPFC_SLI_REV4)
1752 val = 0;
1753
James Smart88a2cfb2011-07-22 18:36:33 -04001754 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1755 "3051 lpfc_poll changed from %d to %d\n",
1756 phba->cfg_poll, val);
1757
James Smart2e0fef82007-06-17 19:56:36 -05001758 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001759
1760 old_val = phba->cfg_poll;
1761
1762 if (val & ENABLE_FCP_RING_POLLING) {
1763 if ((val & DISABLE_FCP_RING_INT) &&
1764 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001765 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1766 spin_unlock_irq(&phba->hbalock);
1767 return -EINVAL;
1768 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001769 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1770 writel(creg_val, phba->HCregaddr);
1771 readl(phba->HCregaddr); /* flush */
1772
1773 lpfc_poll_start_timer(phba);
1774 }
1775 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001776 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001777 return -EINVAL;
1778 }
1779
1780 if (!(val & DISABLE_FCP_RING_INT) &&
1781 (old_val & DISABLE_FCP_RING_INT))
1782 {
James Smart2e0fef82007-06-17 19:56:36 -05001783 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001784 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001785 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001786 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1787 spin_unlock_irq(&phba->hbalock);
1788 return -EINVAL;
1789 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001790 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1791 writel(creg_val, phba->HCregaddr);
1792 readl(phba->HCregaddr); /* flush */
1793 }
1794
1795 phba->cfg_poll = val;
1796
James Smart2e0fef82007-06-17 19:56:36 -05001797 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001798
1799 return strlen(buf);
1800}
dea31012005-04-17 16:05:31 -05001801
James Smarte59058c2008-08-24 21:49:00 -04001802/**
James Smartbc739052010-08-04 16:11:18 -04001803 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1804 * @dev: class unused variable.
1805 * @attr: device attribute, not used.
1806 * @buf: on return contains the module description text.
1807 *
1808 * Returns: size of formatted string.
1809 **/
1810static ssize_t
1811lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1812 char *buf)
1813{
1814 struct Scsi_Host *shost = class_to_shost(dev);
1815 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1816 struct lpfc_hba *phba = vport->phba;
1817
1818 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1819}
1820
1821/**
1822 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1823 * @dev: class unused variable.
1824 * @attr: device attribute, not used.
1825 * @buf: on return contains the module description text.
1826 *
1827 * Returns: size of formatted string.
1828 **/
1829static ssize_t
1830lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1831 char *buf)
1832{
1833 struct Scsi_Host *shost = class_to_shost(dev);
1834 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1835 struct lpfc_hba *phba = vport->phba;
1836
1837 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1838}
1839
1840/**
James Smartab56dc22011-02-16 12:39:57 -05001841 * lpfc_dss_show - Return the current state of dss and the configured state
1842 * @dev: class converted to a Scsi_host structure.
1843 * @attr: device attribute, not used.
1844 * @buf: on return contains the formatted text.
1845 *
1846 * Returns: size of formatted string.
1847 **/
1848static ssize_t
1849lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1850 char *buf)
1851{
1852 struct Scsi_Host *shost = class_to_shost(dev);
1853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
1855
1856 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1857 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1858 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1859 "" : "Not ");
1860}
1861
1862/**
James Smart912e3ac2011-05-24 11:42:11 -04001863 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1864 * @dev: class converted to a Scsi_host structure.
1865 * @attr: device attribute, not used.
1866 * @buf: on return contains the formatted support level.
1867 *
1868 * Description:
1869 * Returns the maximum number of virtual functions a physical function can
1870 * support, 0 will be returned if called on virtual function.
1871 *
1872 * Returns: size of formatted string.
1873 **/
1874static ssize_t
1875lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1876 struct device_attribute *attr,
1877 char *buf)
1878{
1879 struct Scsi_Host *shost = class_to_shost(dev);
1880 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1881 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001882 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001883
James Smart0a96e972011-07-22 18:37:28 -04001884 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1885 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001886}
1887
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001888static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1889{
1890 return val >= min && val <= max;
1891}
1892
James Smart912e3ac2011-05-24 11:42:11 -04001893/**
James Smart44fd7fe2017-08-23 16:55:47 -07001894 * lpfc_enable_bbcr_set: Sets an attribute value.
1895 * @phba: pointer the the adapter structure.
1896 * @val: integer attribute value.
1897 *
1898 * Description:
1899 * Validates the min and max values then sets the
1900 * adapter config field if in the valid range. prints error message
1901 * and does not set the parameter if invalid.
1902 *
1903 * Returns:
1904 * zero on success
1905 * -EINVAL if val is invalid
1906 */
1907static ssize_t
1908lpfc_enable_bbcr_set(struct lpfc_hba *phba, uint val)
1909{
1910 if (lpfc_rangecheck(val, 0, 1) && phba->sli_rev == LPFC_SLI_REV4) {
1911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1912 "3068 %s_enable_bbcr changed from %d to %d\n",
1913 LPFC_DRIVER_NAME, phba->cfg_enable_bbcr, val);
1914 phba->cfg_enable_bbcr = val;
1915 return 0;
1916 }
1917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1918 "0451 %s_enable_bbcr cannot set to %d, range is 0, 1\n",
1919 LPFC_DRIVER_NAME, val);
1920 return -EINVAL;
1921}
1922
1923/**
James Smart3621a712009-04-06 18:47:14 -04001924 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001925 *
1926 * Description:
1927 * Macro that given an attr e.g. hba_queue_depth expands
1928 * into a function with the name lpfc_hba_queue_depth_show.
1929 *
1930 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1931 * @dev: class device that is converted into a Scsi_host.
1932 * @attr: device attribute, not used.
1933 * @buf: on return contains the attribute value in decimal.
1934 *
1935 * Returns: size of formatted string.
1936 **/
dea31012005-04-17 16:05:31 -05001937#define lpfc_param_show(attr) \
1938static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001939lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1940 char *buf) \
dea31012005-04-17 16:05:31 -05001941{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001942 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001943 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1944 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001945 return snprintf(buf, PAGE_SIZE, "%d\n",\
1946 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001947}
1948
James Smarte59058c2008-08-24 21:49:00 -04001949/**
James Smart3621a712009-04-06 18:47:14 -04001950 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001951 *
1952 * Description:
1953 * Macro that given an attr e.g. hba_queue_depth expands
1954 * into a function with the name lpfc_hba_queue_depth_show
1955 *
1956 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1957 * @dev: class device that is converted into a Scsi_host.
1958 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001959 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001960 *
1961 * Returns: size of formatted string.
1962 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001963#define lpfc_param_hex_show(attr) \
1964static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001965lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1966 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001967{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001968 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001969 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1970 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001971 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001972 val = phba->cfg_##attr;\
1973 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1974 phba->cfg_##attr);\
1975}
1976
James Smarte59058c2008-08-24 21:49:00 -04001977/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001978 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001979 *
1980 * Description:
1981 * Macro that given an attr e.g. hba_queue_depth expands
1982 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1983 * takes a default argument, a minimum and maximum argument.
1984 *
1985 * lpfc_##attr##_init: Initializes an attribute.
1986 * @phba: pointer the the adapter structure.
1987 * @val: integer attribute value.
1988 *
1989 * Validates the min and max values then sets the adapter config field
1990 * accordingly, or uses the default if out of range and prints an error message.
1991 *
1992 * Returns:
1993 * zero on success
1994 * -EINVAL if default used
1995 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001996#define lpfc_param_init(attr, default, minval, maxval) \
1997static int \
James Smart84d1b002010-02-12 14:42:33 -05001998lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001999{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002000 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002001 phba->cfg_##attr = val;\
2002 return 0;\
2003 }\
2004 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002005 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
2006 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002007 phba->cfg_##attr = default;\
2008 return -EINVAL;\
2009}
2010
James Smarte59058c2008-08-24 21:49:00 -04002011/**
James Smart3621a712009-04-06 18:47:14 -04002012 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002013 *
2014 * Description:
2015 * Macro that given an attr e.g. hba_queue_depth expands
2016 * into a function with the name lpfc_hba_queue_depth_set
2017 *
2018 * lpfc_##attr##_set: Sets an attribute value.
2019 * @phba: pointer the the adapter structure.
2020 * @val: integer attribute value.
2021 *
2022 * Description:
2023 * Validates the min and max values then sets the
2024 * adapter config field if in the valid range. prints error message
2025 * and does not set the parameter if invalid.
2026 *
2027 * Returns:
2028 * zero on success
2029 * -EINVAL if val is invalid
2030 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002031#define lpfc_param_set(attr, default, minval, maxval) \
2032static int \
James Smart84d1b002010-02-12 14:42:33 -05002033lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002034{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002035 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002036 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2037 "3052 lpfc_" #attr " changed from %d to %d\n", \
2038 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002039 phba->cfg_##attr = val;\
2040 return 0;\
2041 }\
2042 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04002043 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2044 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002045 return -EINVAL;\
2046}
2047
James Smarte59058c2008-08-24 21:49:00 -04002048/**
James Smart3621a712009-04-06 18:47:14 -04002049 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04002050 *
2051 * Description:
2052 * Macro that given an attr e.g. hba_queue_depth expands
2053 * into a function with the name lpfc_hba_queue_depth_store.
2054 *
2055 * lpfc_##attr##_store: Set an sttribute value.
2056 * @dev: class device that is converted into a Scsi_host.
2057 * @attr: device attribute, not used.
2058 * @buf: contains the attribute value in ascii.
2059 * @count: not used.
2060 *
2061 * Description:
2062 * Convert the ascii text number to an integer, then
2063 * use the lpfc_##attr##_set function to set the value.
2064 *
2065 * Returns:
2066 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2067 * length of buffer upon success.
2068 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002069#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002070static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002071lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2072 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002073{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002074 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002075 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2076 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002077 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002078 if (!isdigit(buf[0]))\
2079 return -EINVAL;\
2080 if (sscanf(buf, "%i", &val) != 1)\
2081 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002082 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002083 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002084 else \
2085 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002086}
2087
James Smarte59058c2008-08-24 21:49:00 -04002088/**
James Smart3621a712009-04-06 18:47:14 -04002089 * lpfc_vport_param_show - Return decimal formatted cfg 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_show
2094 *
2095 * lpfc_##attr##_show: prints the attribute value in decimal.
2096 * @dev: class device that is converted into a Scsi_host.
2097 * @attr: device attribute, not used.
2098 * @buf: on return contains the attribute value in decimal.
2099 *
2100 * Returns: length of formatted string.
2101 **/
James Smart3de2a652007-08-02 11:09:59 -04002102#define lpfc_vport_param_show(attr) \
2103static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002104lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2105 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002106{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002107 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002109 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2110}
2111
James Smarte59058c2008-08-24 21:49:00 -04002112/**
James Smart3621a712009-04-06 18:47:14 -04002113 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002114 *
2115 * Description:
2116 * Macro that given an attr e.g.
2117 * hba_queue_depth expands into a function with the name
2118 * lpfc_hba_queue_depth_show
2119 *
James Smart3621a712009-04-06 18:47:14 -04002120 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002121 * @dev: class device that is converted into a Scsi_host.
2122 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002123 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002124 *
2125 * Returns: length of formatted string.
2126 **/
James Smart3de2a652007-08-02 11:09:59 -04002127#define lpfc_vport_param_hex_show(attr) \
2128static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002129lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2130 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002131{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002132 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002134 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2135}
2136
James Smarte59058c2008-08-24 21:49:00 -04002137/**
James Smart3621a712009-04-06 18:47:14 -04002138 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002139 *
2140 * Description:
2141 * Macro that given an attr e.g. hba_queue_depth expands
2142 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2143 * takes a default argument, a minimum and maximum argument.
2144 *
2145 * lpfc_##attr##_init: validates the min and max values then sets the
2146 * adapter config field accordingly, or uses the default if out of range
2147 * and prints an error message.
2148 * @phba: pointer the the adapter structure.
2149 * @val: integer attribute value.
2150 *
2151 * Returns:
2152 * zero on success
2153 * -EINVAL if default used
2154 **/
James Smart3de2a652007-08-02 11:09:59 -04002155#define lpfc_vport_param_init(attr, default, minval, maxval) \
2156static int \
James Smart84d1b002010-02-12 14:42:33 -05002157lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002158{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002159 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002160 vport->cfg_##attr = val;\
2161 return 0;\
2162 }\
James Smarte8b62012007-08-02 11:10:09 -04002163 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002164 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002165 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002166 vport->cfg_##attr = default;\
2167 return -EINVAL;\
2168}
2169
James Smarte59058c2008-08-24 21:49:00 -04002170/**
James Smart3621a712009-04-06 18:47:14 -04002171 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002172 *
2173 * Description:
2174 * Macro that given an attr e.g. hba_queue_depth expands
2175 * into a function with the name lpfc_hba_queue_depth_set
2176 *
2177 * lpfc_##attr##_set: validates the min and max values then sets the
2178 * adapter config field if in the valid range. prints error message
2179 * and does not set the parameter if invalid.
2180 * @phba: pointer the the adapter structure.
2181 * @val: integer attribute value.
2182 *
2183 * Returns:
2184 * zero on success
2185 * -EINVAL if val is invalid
2186 **/
James Smart3de2a652007-08-02 11:09:59 -04002187#define lpfc_vport_param_set(attr, default, minval, maxval) \
2188static int \
James Smart84d1b002010-02-12 14:42:33 -05002189lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002190{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002191 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002192 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002193 "3053 lpfc_" #attr \
2194 " changed from %d (x%x) to %d (x%x)\n", \
2195 vport->cfg_##attr, vport->cfg_##attr, \
2196 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002197 vport->cfg_##attr = val;\
2198 return 0;\
2199 }\
James Smarte8b62012007-08-02 11:10:09 -04002200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002201 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002202 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002203 return -EINVAL;\
2204}
2205
James Smarte59058c2008-08-24 21:49:00 -04002206/**
James Smart3621a712009-04-06 18:47:14 -04002207 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002208 *
2209 * Description:
2210 * Macro that given an attr e.g. hba_queue_depth
2211 * expands into a function with the name lpfc_hba_queue_depth_store
2212 *
2213 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2214 * use the lpfc_##attr##_set function to set the value.
2215 * @cdev: class device that is converted into a Scsi_host.
2216 * @buf: contains the attribute value in decimal.
2217 * @count: not used.
2218 *
2219 * Returns:
2220 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2221 * length of buffer upon success.
2222 **/
James Smart3de2a652007-08-02 11:09:59 -04002223#define lpfc_vport_param_store(attr) \
2224static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002225lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2226 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002227{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002228 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002230 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002231 if (!isdigit(buf[0]))\
2232 return -EINVAL;\
2233 if (sscanf(buf, "%i", &val) != 1)\
2234 return -EINVAL;\
2235 if (lpfc_##attr##_set(vport, val) == 0) \
2236 return strlen(buf);\
2237 else \
2238 return -EINVAL;\
2239}
2240
2241
James Smart895427b2017-02-12 13:52:30 -08002242static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002243static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2244static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2245static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2246static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002247static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2248static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2249static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2250static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2251static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2252static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2253static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2254static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002255static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2256 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002257static DEVICE_ATTR(option_rom_version, S_IRUGO,
2258 lpfc_option_rom_version_show, NULL);
2259static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2260 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002261static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002262static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2263static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002264static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002265static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2266 lpfc_board_mode_show, lpfc_board_mode_store);
2267static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2268static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2269static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2270static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2271static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2272static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2273static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2274static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2275static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002276static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2277static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002278static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002279static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2280 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002281static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002282static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2283 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002284
James Smart352e5fd2016-12-30 06:57:47 -08002285static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002286#define WWN_SZ 8
2287/**
2288 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2289 * @buf: WWN string.
2290 * @cnt: Length of string.
2291 * @wwn: Array to receive converted wwn value.
2292 *
2293 * Returns:
2294 * -EINVAL if the buffer does not contain a valid wwn
2295 * 0 success
2296 **/
2297static size_t
2298lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2299{
2300 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002301
James Smart1ba981f2014-02-20 09:56:45 -05002302 /* Count may include a LF at end of string */
2303 if (buf[cnt-1] == '\n')
2304 cnt--;
2305
2306 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2307 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2308 return -EINVAL;
2309
2310 memset(wwn, 0, WWN_SZ);
2311
2312 /* Validate and store the new name */
2313 for (i = 0, j = 0; i < 16; i++) {
2314 if ((*buf >= 'a') && (*buf <= 'f'))
2315 j = ((j << 4) | ((*buf++ - 'a') + 10));
2316 else if ((*buf >= 'A') && (*buf <= 'F'))
2317 j = ((j << 4) | ((*buf++ - 'A') + 10));
2318 else if ((*buf >= '0') && (*buf <= '9'))
2319 j = ((j << 4) | (*buf++ - '0'));
2320 else
2321 return -EINVAL;
2322 if (i % 2) {
2323 wwn[i/2] = j & 0xff;
2324 j = 0;
2325 }
2326 }
2327 return 0;
2328}
James Smart352e5fd2016-12-30 06:57:47 -08002329/**
2330 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2331 * @dev: class device that is converted into a Scsi_host.
2332 * @attr: device attribute, not used.
2333 * @buf: containing the string lpfc_soft_wwn_key.
2334 * @count: must be size of lpfc_soft_wwn_key.
2335 *
2336 * Returns:
2337 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2338 * length of buf indicates success
2339 **/
2340static ssize_t
2341lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2342 const char *buf, size_t count)
2343{
2344 struct Scsi_Host *shost = class_to_shost(dev);
2345 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2346 struct lpfc_hba *phba = vport->phba;
2347 unsigned int cnt = count;
James Smartaeb3c812017-04-21 16:05:02 -07002348 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2349 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
James Smart352e5fd2016-12-30 06:57:47 -08002350
2351 /*
2352 * We're doing a simple sanity check for soft_wwpn setting.
2353 * We require that the user write a specific key to enable
2354 * the soft_wwpn attribute to be settable. Once the attribute
2355 * is written, the enable key resets. If further updates are
2356 * desired, the key must be written again to re-enable the
2357 * attribute.
2358 *
2359 * The "key" is not secret - it is a hardcoded string shown
2360 * here. The intent is to protect against the random user or
2361 * application that is just writing attributes.
2362 */
James Smartaeb3c812017-04-21 16:05:02 -07002363 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2364 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2365 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2366 " be enabled: fawwpn is enabled\n");
2367 return -EINVAL;
2368 }
James Smart352e5fd2016-12-30 06:57:47 -08002369
2370 /* count may include a LF at end of string */
2371 if (buf[cnt-1] == '\n')
2372 cnt--;
2373
2374 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2375 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2376 return -EINVAL;
2377
2378 phba->soft_wwn_enable = 1;
2379
2380 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2381 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2382 phba->brd_no);
2383 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2384 " The soft_wwpn feature is not supported by Broadcom.");
2385
2386 return count;
2387}
2388static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2389 lpfc_soft_wwn_enable_store);
2390
2391/**
2392 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2393 * @dev: class device that is converted into a Scsi_host.
2394 * @attr: device attribute, not used.
2395 * @buf: on return contains the wwpn in hexadecimal.
2396 *
2397 * Returns: size of formatted string.
2398 **/
2399static ssize_t
2400lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2401 char *buf)
2402{
2403 struct Scsi_Host *shost = class_to_shost(dev);
2404 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2405 struct lpfc_hba *phba = vport->phba;
2406
2407 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2408 (unsigned long long)phba->cfg_soft_wwpn);
2409}
2410
2411/**
2412 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2413 * @dev class device that is converted into a Scsi_host.
2414 * @attr: device attribute, not used.
2415 * @buf: contains the wwpn in hexadecimal.
2416 * @count: number of wwpn bytes in buf
2417 *
2418 * Returns:
2419 * -EACCES hba reset not enabled, adapter over temp
2420 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2421 * -EIO error taking adapter offline or online
2422 * value of count on success
2423 **/
2424static ssize_t
2425lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2426 const char *buf, size_t count)
2427{
2428 struct Scsi_Host *shost = class_to_shost(dev);
2429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2430 struct lpfc_hba *phba = vport->phba;
2431 struct completion online_compl;
2432 int stat1 = 0, stat2 = 0;
2433 unsigned int cnt = count;
2434 u8 wwpn[WWN_SZ];
2435 int rc;
2436
2437 if (!phba->cfg_enable_hba_reset)
2438 return -EACCES;
2439 spin_lock_irq(&phba->hbalock);
2440 if (phba->over_temp_state == HBA_OVER_TEMP) {
2441 spin_unlock_irq(&phba->hbalock);
2442 return -EACCES;
2443 }
2444 spin_unlock_irq(&phba->hbalock);
2445 /* count may include a LF at end of string */
2446 if (buf[cnt-1] == '\n')
2447 cnt--;
2448
2449 if (!phba->soft_wwn_enable)
2450 return -EINVAL;
2451
2452 /* lock setting wwpn, wwnn down */
2453 phba->soft_wwn_enable = 0;
2454
2455 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002456 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002457 /* not able to set wwpn, unlock it */
2458 phba->soft_wwn_enable = 1;
2459 return rc;
2460 }
2461
2462 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2463 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2464 if (phba->cfg_soft_wwnn)
2465 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2466
2467 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2468 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2469
2470 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2471 if (stat1)
2472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2473 "0463 lpfc_soft_wwpn attribute set failed to "
2474 "reinit adapter - %d\n", stat1);
2475 init_completion(&online_compl);
2476 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2477 LPFC_EVT_ONLINE);
2478 if (rc == 0)
2479 return -ENOMEM;
2480
2481 wait_for_completion(&online_compl);
2482 if (stat2)
2483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2484 "0464 lpfc_soft_wwpn attribute set failed to "
2485 "reinit adapter - %d\n", stat2);
2486 return (stat1 || stat2) ? -EIO : count;
2487}
2488static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2489 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2490
2491/**
2492 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2493 * @dev: class device that is converted into a Scsi_host.
2494 * @attr: device attribute, not used.
2495 * @buf: on return contains the wwnn in hexadecimal.
2496 *
2497 * Returns: size of formatted string.
2498 **/
2499static ssize_t
2500lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2501 char *buf)
2502{
2503 struct Scsi_Host *shost = class_to_shost(dev);
2504 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2505 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2506 (unsigned long long)phba->cfg_soft_wwnn);
2507}
2508
2509/**
2510 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2511 * @cdev: class device that is converted into a Scsi_host.
2512 * @buf: contains the ww node name in hexadecimal.
2513 * @count: number of wwnn bytes in buf.
2514 *
2515 * Returns:
2516 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2517 * value of count on success
2518 **/
2519static ssize_t
2520lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2521 const char *buf, size_t count)
2522{
2523 struct Scsi_Host *shost = class_to_shost(dev);
2524 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2525 unsigned int cnt = count;
2526 u8 wwnn[WWN_SZ];
2527 int rc;
2528
2529 /* count may include a LF at end of string */
2530 if (buf[cnt-1] == '\n')
2531 cnt--;
2532
2533 if (!phba->soft_wwn_enable)
2534 return -EINVAL;
2535
2536 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002537 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002538 /* Allow wwnn to be set many times, as long as the enable
2539 * is set. However, once the wwpn is set, everything locks.
2540 */
2541 return rc;
2542 }
2543
2544 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2545
2546 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2547 "lpfc%d: soft_wwnn set. Value will take effect upon "
2548 "setting of the soft_wwpn\n", phba->brd_no);
2549
2550 return count;
2551}
2552static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2553 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002554
James Smart1ba981f2014-02-20 09:56:45 -05002555/**
2556 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2557 * Optimized Access Storage (OAS) operations.
2558 * @dev: class device that is converted into a Scsi_host.
2559 * @attr: device attribute, not used.
2560 * @buf: buffer for passing information.
2561 *
2562 * Returns:
2563 * value of count
2564 **/
2565static ssize_t
2566lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2567 char *buf)
2568{
2569 struct Scsi_Host *shost = class_to_shost(dev);
2570 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2571
2572 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2573 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2574}
2575
2576/**
2577 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2578 * Optimized Access Storage (OAS) operations.
2579 * @dev: class device that is converted into a Scsi_host.
2580 * @attr: device attribute, not used.
2581 * @buf: buffer for passing information.
2582 * @count: Size of the data buffer.
2583 *
2584 * Returns:
2585 * -EINVAL count is invalid, invalid wwpn byte invalid
2586 * -EPERM oas is not supported by hba
2587 * value of count on success
2588 **/
2589static ssize_t
2590lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2591 const char *buf, size_t count)
2592{
2593 struct Scsi_Host *shost = class_to_shost(dev);
2594 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2595 unsigned int cnt = count;
2596 uint8_t wwpn[WWN_SZ];
2597 int rc;
2598
James Smartf38fa0b2014-04-04 13:52:21 -04002599 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002600 return -EPERM;
2601
2602 /* count may include a LF at end of string */
2603 if (buf[cnt-1] == '\n')
2604 cnt--;
2605
2606 rc = lpfc_wwn_set(buf, cnt, wwpn);
2607 if (rc)
2608 return rc;
2609
2610 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2611 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2612 if (wwn_to_u64(wwpn) == 0)
2613 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2614 else
2615 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2616 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2617 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2618 return count;
2619}
2620static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2621 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2622
2623/**
James Smartc92c8412016-07-06 12:36:05 -07002624 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2625 * Optimized Access Storage (OAS) operations.
2626 * @dev: class device that is converted into a Scsi_host.
2627 * @attr: device attribute, not used.
2628 * @buf: buffer for passing information.
2629 *
2630 * Returns:
2631 * value of count
2632 **/
2633static ssize_t
2634lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2635 char *buf)
2636{
2637 struct Scsi_Host *shost = class_to_shost(dev);
2638 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2639
2640 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2641}
2642
2643/**
2644 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2645 * Optimized Access Storage (OAS) operations.
2646 * @dev: class device that is converted into a Scsi_host.
2647 * @attr: device attribute, not used.
2648 * @buf: buffer for passing information.
2649 * @count: Size of the data buffer.
2650 *
2651 * Returns:
2652 * -EINVAL count is invalid, invalid wwpn byte invalid
2653 * -EPERM oas is not supported by hba
2654 * value of count on success
2655 **/
2656static ssize_t
2657lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2658 const char *buf, size_t count)
2659{
2660 struct Scsi_Host *shost = class_to_shost(dev);
2661 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2662 unsigned int cnt = count;
2663 unsigned long val;
2664 int ret;
2665
2666 if (!phba->cfg_fof)
2667 return -EPERM;
2668
2669 /* count may include a LF at end of string */
2670 if (buf[cnt-1] == '\n')
2671 cnt--;
2672
2673 ret = kstrtoul(buf, 0, &val);
2674 if (ret || (val > 0x7f))
2675 return -EINVAL;
2676
2677 if (val)
2678 phba->cfg_oas_priority = (uint8_t)val;
2679 else
2680 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2681 return count;
2682}
2683static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2684 lpfc_oas_priority_show, lpfc_oas_priority_store);
2685
2686/**
James Smart1ba981f2014-02-20 09:56:45 -05002687 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2688 * for Optimized Access Storage (OAS) operations.
2689 * @dev: class device that is converted into a Scsi_host.
2690 * @attr: device attribute, not used.
2691 * @buf: buffer for passing information.
2692 *
2693 * Returns:
2694 * value of count on success
2695 **/
2696static ssize_t
2697lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2698 char *buf)
2699{
2700 struct Scsi_Host *shost = class_to_shost(dev);
2701 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2702
2703 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2704 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2705}
2706
2707/**
2708 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2709 * for Optimized Access Storage (OAS) operations.
2710 * @dev: class device that is converted into a Scsi_host.
2711 * @attr: device attribute, not used.
2712 * @buf: buffer for passing information.
2713 * @count: Size of the data buffer.
2714 *
2715 * Returns:
2716 * -EINVAL count is invalid, invalid wwpn byte invalid
2717 * -EPERM oas is not supported by hba
2718 * value of count on success
2719 **/
2720static ssize_t
2721lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2722 const char *buf, size_t count)
2723{
2724 struct Scsi_Host *shost = class_to_shost(dev);
2725 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2726 unsigned int cnt = count;
2727 uint8_t wwpn[WWN_SZ];
2728 int rc;
2729
James Smartf38fa0b2014-04-04 13:52:21 -04002730 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002731 return -EPERM;
2732
2733 /* count may include a LF at end of string */
2734 if (buf[cnt-1] == '\n')
2735 cnt--;
2736
2737 rc = lpfc_wwn_set(buf, cnt, wwpn);
2738 if (rc)
2739 return rc;
2740
2741 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2742 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2743 if (wwn_to_u64(wwpn) == 0)
2744 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2745 else
2746 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2747 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002748 if (phba->cfg_oas_priority == 0)
2749 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002750 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2751 return count;
2752}
2753static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2754 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2755
2756/**
2757 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2758 * of whether luns will be enabled or disabled
2759 * for Optimized Access Storage (OAS) operations.
2760 * @dev: class device that is converted into a Scsi_host.
2761 * @attr: device attribute, not used.
2762 * @buf: buffer for passing information.
2763 *
2764 * Returns:
2765 * size of formatted string.
2766 **/
2767static ssize_t
2768lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2769 char *buf)
2770{
2771 struct Scsi_Host *shost = class_to_shost(dev);
2772 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2773
2774 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2775}
2776
2777/**
2778 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2779 * of whether luns will be enabled or disabled
2780 * for Optimized Access Storage (OAS) operations.
2781 * @dev: class device that is converted into a Scsi_host.
2782 * @attr: device attribute, not used.
2783 * @buf: buffer for passing information.
2784 * @count: Size of the data buffer.
2785 *
2786 * Returns:
2787 * -EINVAL count is invalid, invalid wwpn byte invalid
2788 * -EPERM oas is not supported by hba
2789 * value of count on success
2790 **/
2791static ssize_t
2792lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2793 const char *buf, size_t count)
2794{
2795 struct Scsi_Host *shost = class_to_shost(dev);
2796 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2797 int val = 0;
2798
James Smartf38fa0b2014-04-04 13:52:21 -04002799 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002800 return -EPERM;
2801
2802 if (!isdigit(buf[0]))
2803 return -EINVAL;
2804
2805 if (sscanf(buf, "%i", &val) != 1)
2806 return -EINVAL;
2807
2808 if ((val != 0) && (val != 1))
2809 return -EINVAL;
2810
2811 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002812 return strlen(buf);
2813}
2814static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2815 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2816
2817/**
2818 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2819 * Storage (OAS) lun returned by the
2820 * lpfc_oas_lun_show function.
2821 * @dev: class device that is converted into a Scsi_host.
2822 * @attr: device attribute, not used.
2823 * @buf: buffer for passing information.
2824 *
2825 * Returns:
2826 * size of formatted string.
2827 **/
2828static ssize_t
2829lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2830 char *buf)
2831{
2832 struct Scsi_Host *shost = class_to_shost(dev);
2833 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2834
2835 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2836 return -EFAULT;
2837
2838 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2839}
2840static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2841 lpfc_oas_lun_status_show, NULL);
2842
2843
2844/**
2845 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2846 * (OAS) operations.
2847 * @phba: lpfc_hba pointer.
2848 * @ndlp: pointer to fcp target node.
2849 * @lun: the fc lun for setting oas state.
2850 * @oas_state: the oas state to be set to the lun.
2851 *
2852 * Returns:
2853 * SUCCESS : 0
2854 * -EPERM OAS is not enabled or not supported by this port.
2855 *
2856 */
2857static size_t
2858lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002859 uint8_t tgt_wwpn[], uint64_t lun,
2860 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002861{
2862
2863 int rc = 0;
2864
James Smartf38fa0b2014-04-04 13:52:21 -04002865 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002866 return -EPERM;
2867
2868 if (oas_state) {
2869 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002870 (struct lpfc_name *)tgt_wwpn,
2871 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002872 rc = -ENOMEM;
2873 } else {
2874 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002875 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002876 }
2877 return rc;
2878
2879}
2880
2881/**
2882 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2883 * Access Storage (OAS) operations.
2884 * @phba: lpfc_hba pointer.
2885 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2886 * @tgt_wwpn: wwpn of the target associated with the returned lun
2887 * @lun_status: status of the lun returned lun
2888 *
2889 * Returns the first or next lun enabled for OAS operations for the vport/target
2890 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2891 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2892 *
2893 * Return:
2894 * lun that is OAS enabled for the vport/target
2895 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2896 */
2897static uint64_t
2898lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002899 uint8_t tgt_wwpn[], uint32_t *lun_status,
2900 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002901{
2902 uint64_t found_lun;
2903
2904 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2905 return NOT_OAS_ENABLED_LUN;
2906 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2907 phba->sli4_hba.oas_next_vpt_wwpn,
2908 (struct lpfc_name *)
2909 phba->sli4_hba.oas_next_tgt_wwpn,
2910 &phba->sli4_hba.oas_next_lun,
2911 (struct lpfc_name *)vpt_wwpn,
2912 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002913 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002914 return found_lun;
2915 else
2916 return NOT_OAS_ENABLED_LUN;
2917}
2918
2919/**
2920 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2921 * @phba: lpfc_hba pointer.
2922 * @vpt_wwpn: vport wwpn by reference.
2923 * @tgt_wwpn: target wwpn by reference.
2924 * @lun: the fc lun for setting oas state.
2925 * @oas_state: the oas state to be set to the oas_lun.
2926 *
2927 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2928 * a lun for OAS operations.
2929 *
2930 * Return:
2931 * SUCCESS: 0
2932 * -ENOMEM: failed to enable an lun for OAS operations
2933 * -EPERM: OAS is not enabled
2934 */
2935static ssize_t
2936lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2937 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002938 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002939{
2940
2941 int rc;
2942
2943 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002944 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002945 return rc;
2946}
2947
2948/**
2949 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2950 * @dev: class device that is converted into a Scsi_host.
2951 * @attr: device attribute, not used.
2952 * @buf: buffer for passing information.
2953 *
2954 * This routine returns a lun enabled for OAS each time the function
2955 * is called.
2956 *
2957 * Returns:
2958 * SUCCESS: size of formatted string.
2959 * -EFAULT: target or vport wwpn was not set properly.
2960 * -EPERM: oas is not enabled.
2961 **/
2962static ssize_t
2963lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2964 char *buf)
2965{
2966 struct Scsi_Host *shost = class_to_shost(dev);
2967 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2968
2969 uint64_t oas_lun;
2970 int len = 0;
2971
James Smartf38fa0b2014-04-04 13:52:21 -04002972 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002973 return -EPERM;
2974
2975 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2976 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2977 return -EFAULT;
2978
2979 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2980 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2981 return -EFAULT;
2982
2983 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2984 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002985 &phba->cfg_oas_lun_status,
2986 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002987 if (oas_lun != NOT_OAS_ENABLED_LUN)
2988 phba->cfg_oas_flags |= OAS_LUN_VALID;
2989
2990 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2991
2992 return len;
2993}
2994
2995/**
2996 * lpfc_oas_lun_store - Sets the OAS state for lun
2997 * @dev: class device that is converted into a Scsi_host.
2998 * @attr: device attribute, not used.
2999 * @buf: buffer for passing information.
3000 *
3001 * This function sets the OAS state for lun. Before this function is called,
3002 * the vport wwpn, target wwpn, and oas state need to be set.
3003 *
3004 * Returns:
3005 * SUCCESS: size of formatted string.
3006 * -EFAULT: target or vport wwpn was not set properly.
3007 * -EPERM: oas is not enabled.
3008 * size of formatted string.
3009 **/
3010static ssize_t
3011lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
3012 const char *buf, size_t count)
3013{
3014 struct Scsi_Host *shost = class_to_shost(dev);
3015 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
3016 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08003017 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05003018 ssize_t rc;
3019
James Smartf38fa0b2014-04-04 13:52:21 -04003020 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05003021 return -EPERM;
3022
3023 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
3024 return -EFAULT;
3025
3026 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3027 return -EFAULT;
3028
3029 if (!isdigit(buf[0]))
3030 return -EINVAL;
3031
3032 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3033 return -EINVAL;
3034
James Smartb5749fe2016-12-19 15:07:26 -08003035 pri = phba->cfg_oas_priority;
3036 if (pri == 0)
3037 pri = phba->cfg_XLanePriority;
3038
James Smart1ba981f2014-02-20 09:56:45 -05003039 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07003040 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3041 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05003042 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3043 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003044 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05003045
3046 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07003047 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08003048 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05003049 if (rc)
3050 return rc;
3051
3052 return count;
3053}
3054static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3055 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04003056
James Smartf358dd02017-02-12 13:52:34 -08003057int lpfc_enable_nvmet_cnt;
3058unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3059 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3060 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3061module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3062MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3063
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003064static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003065module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003066MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3067 " 0 - none,"
3068 " 1 - poll with interrupts enabled"
3069 " 3 - poll and disable FCP ring interrupts");
3070
Tony Jonesee959b02008-02-22 00:13:36 +01003071static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3072 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05003073
James Smart96418b52017-03-04 09:30:31 -08003074int lpfc_no_hba_reset_cnt;
3075unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3076 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3077module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3078MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3079
James Smart12247e82016-07-06 12:36:09 -07003080LPFC_ATTR(sli_mode, 0, 0, 3,
3081 "SLI mode selector:"
3082 " 0 - auto (SLI-3 if supported),"
3083 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3084 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003085
James Smart458c0832016-07-06 12:36:07 -07003086LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3087 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003088
James Smart7d791df2011-07-22 18:37:52 -04003089LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3090 "FCF Fast failover=1 Priority failover=2");
3091
James Smarte5771b42013-03-01 16:37:14 -05003092/*
3093# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3094# 0x0 = disabled, XRI/OXID use not tracked.
3095# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3096# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3097*/
James Smart31202b02016-10-13 15:06:08 -07003098LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3099 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003100
dea31012005-04-17 16:05:31 -05003101/*
James Smart84d1b002010-02-12 14:42:33 -05003102# lpfc_suppress_link_up: Bring link up at initialization
3103# 0x0 = bring link up (issue MBX_INIT_LINK)
3104# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3105# 0x2 = never bring up link
3106# Default value is 0.
3107*/
James Smarte40a02c2010-02-26 14:13:54 -05003108LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3109 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3110 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003111/*
3112# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3113# 1 - (1024)
3114# 2 - (2048)
3115# 3 - (3072)
3116# 4 - (4096)
3117# 5 - (5120)
3118*/
3119static ssize_t
3120lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3121{
3122 struct Scsi_Host *shost = class_to_shost(dev);
3123 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3124
3125 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3126}
3127
3128static DEVICE_ATTR(iocb_hw, S_IRUGO,
3129 lpfc_iocb_hw_show, NULL);
3130static ssize_t
3131lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3132{
3133 struct Scsi_Host *shost = class_to_shost(dev);
3134 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003135 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003136
James Smart895427b2017-02-12 13:52:30 -08003137 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003138}
3139
3140static DEVICE_ATTR(txq_hw, S_IRUGO,
3141 lpfc_txq_hw_show, NULL);
3142static ssize_t
3143lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3144 char *buf)
3145{
3146 struct Scsi_Host *shost = class_to_shost(dev);
3147 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003148 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003149
James Smart895427b2017-02-12 13:52:30 -08003150 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003151}
3152
3153static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3154 lpfc_txcmplq_hw_show, NULL);
3155
James Smart0d8c8ba2016-10-13 15:06:07 -07003156LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003157 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003158
3159/*
James Smartc01f3202006-08-18 17:47:08 -04003160# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3161# until the timer expires. Value range is [0,255]. Default value is 30.
3162*/
3163static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3164static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3165module_param(lpfc_nodev_tmo, int, 0);
3166MODULE_PARM_DESC(lpfc_nodev_tmo,
3167 "Seconds driver will hold I/O waiting "
3168 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003169
3170/**
James Smart3621a712009-04-06 18:47:14 -04003171 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003172 * @dev: class converted to a Scsi_host structure.
3173 * @attr: device attribute, not used.
3174 * @buf: on return contains the dev loss timeout in decimal.
3175 *
3176 * Returns: size of formatted string.
3177 **/
James Smartc01f3202006-08-18 17:47:08 -04003178static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003179lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3180 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003181{
Tony Jonesee959b02008-02-22 00:13:36 +01003182 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003183 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003184
James Smart3de2a652007-08-02 11:09:59 -04003185 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003186}
3187
James Smarte59058c2008-08-24 21:49:00 -04003188/**
James Smart3621a712009-04-06 18:47:14 -04003189 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003190 * @vport: lpfc vport structure pointer.
3191 * @val: contains the nodev timeout value.
3192 *
3193 * Description:
3194 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3195 * a kernel error message is printed and zero is returned.
3196 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3197 * Otherwise nodev tmo is set to the default value.
3198 *
3199 * Returns:
3200 * zero if already set or if val is in range
3201 * -EINVAL val out of range
3202 **/
James Smartc01f3202006-08-18 17:47:08 -04003203static int
James Smart3de2a652007-08-02 11:09:59 -04003204lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003205{
James Smart3de2a652007-08-02 11:09:59 -04003206 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3207 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3208 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003209 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003210 "0407 Ignoring lpfc_nodev_tmo module "
3211 "parameter because lpfc_devloss_tmo "
3212 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003213 return 0;
3214 }
3215
3216 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003217 vport->cfg_nodev_tmo = val;
3218 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003219 return 0;
3220 }
James Smarte8b62012007-08-02 11:10:09 -04003221 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3222 "0400 lpfc_nodev_tmo attribute cannot be set to"
3223 " %d, allowed range is [%d, %d]\n",
3224 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003225 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003226 return -EINVAL;
3227}
3228
James Smarte59058c2008-08-24 21:49:00 -04003229/**
James Smart3621a712009-04-06 18:47:14 -04003230 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003231 * @vport: lpfc vport structure pointer.
3232 *
3233 * Description:
3234 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3235 **/
James Smart7054a602007-04-25 09:52:34 -04003236static void
James Smart3de2a652007-08-02 11:09:59 -04003237lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003238{
James Smart858c9f62007-06-17 19:56:39 -05003239 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003240 struct lpfc_nodelist *ndlp;
3241
James Smart51ef4c22007-08-02 11:10:31 -04003242 shost = lpfc_shost_from_vport(vport);
3243 spin_lock_irq(shost->host_lock);
James Smart7a06dcd2017-06-01 21:06:55 -07003244 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3245 if (!NLP_CHK_NODE_ACT(ndlp))
3246 continue;
3247 if (ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003248 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
James Smart6ddcf0a2017-11-03 09:33:30 -07003249#if (IS_ENABLED(CONFIG_NVME_FC))
3250 if (ndlp->nrport)
3251 nvme_fc_set_remoteport_devloss(ndlp->nrport->remoteport,
3252 vport->cfg_devloss_tmo);
3253#endif
James Smart7a06dcd2017-06-01 21:06:55 -07003254 }
James Smart51ef4c22007-08-02 11:10:31 -04003255 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003256}
3257
James Smarte59058c2008-08-24 21:49:00 -04003258/**
James Smart3621a712009-04-06 18:47:14 -04003259 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003260 * @vport: lpfc vport structure pointer.
3261 * @val: contains the tmo value.
3262 *
3263 * Description:
3264 * If the devloss tmo is already set or the vport dev loss tmo has changed
3265 * then a kernel error message is printed and zero is returned.
3266 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3267 * Otherwise nodev tmo is set to the default value.
3268 *
3269 * Returns:
3270 * zero if already set or if val is in range
3271 * -EINVAL val out of range
3272 **/
James Smartc01f3202006-08-18 17:47:08 -04003273static int
James Smart3de2a652007-08-02 11:09:59 -04003274lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003275{
James Smart3de2a652007-08-02 11:09:59 -04003276 if (vport->dev_loss_tmo_changed ||
3277 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003278 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003279 "0401 Ignoring change to lpfc_nodev_tmo "
3280 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003281 return 0;
3282 }
James Smartc01f3202006-08-18 17:47:08 -04003283 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003284 vport->cfg_nodev_tmo = val;
3285 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003286 /*
3287 * For compat: set the fc_host dev loss so new rports
3288 * will get the value.
3289 */
3290 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003291 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003292 return 0;
3293 }
James Smarte8b62012007-08-02 11:10:09 -04003294 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003295 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003296 "%d, allowed range is [%d, %d]\n",
3297 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003298 return -EINVAL;
3299}
3300
James Smart3de2a652007-08-02 11:09:59 -04003301lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003302
Tony Jonesee959b02008-02-22 00:13:36 +01003303static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3304 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003305
3306/*
3307# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3308# disappear until the timer expires. Value range is [0,255]. Default
3309# value is 30.
3310*/
James Smartab56dc22011-02-16 12:39:57 -05003311module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003312MODULE_PARM_DESC(lpfc_devloss_tmo,
3313 "Seconds driver will hold I/O waiting "
3314 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003315lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3316 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3317lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003318
3319/**
James Smart3621a712009-04-06 18:47:14 -04003320 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003321 * @vport: lpfc vport structure pointer.
3322 * @val: contains the tmo value.
3323 *
3324 * Description:
3325 * If val is in a valid range then set the vport nodev tmo,
3326 * devloss tmo, also set the vport dev loss tmo changed flag.
3327 * Else a kernel error message is printed.
3328 *
3329 * Returns:
3330 * zero if val is in range
3331 * -EINVAL val out of range
3332 **/
James Smartc01f3202006-08-18 17:47:08 -04003333static int
James Smart3de2a652007-08-02 11:09:59 -04003334lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003335{
3336 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003337 vport->cfg_nodev_tmo = val;
3338 vport->cfg_devloss_tmo = val;
3339 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003340 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003341 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003342 return 0;
3343 }
3344
James Smarte8b62012007-08-02 11:10:09 -04003345 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003346 "0404 lpfc_devloss_tmo attribute cannot be set to "
3347 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003348 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003349 return -EINVAL;
3350}
3351
James Smart3de2a652007-08-02 11:09:59 -04003352lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003353static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3354 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003355
3356/*
James Smartf358dd02017-02-12 13:52:34 -08003357 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3358 * lpfc_suppress_rsp = 0 Disable
3359 * lpfc_suppress_rsp = 1 Enable (default)
3360 *
3361 */
3362LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3363 "Enable suppress rsp feature is firmware supports it");
3364
3365/*
James Smart2d7dbc42017-02-12 13:52:35 -08003366 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3367 * lpfc_nvmet_mrq = 1 use a single RQ pair
3368 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3369 *
3370 */
3371LPFC_ATTR_R(nvmet_mrq,
3372 1, 1, 16,
3373 "Specify number of RQ pairs for processing NVMET cmds");
3374
3375/*
James Smart895427b2017-02-12 13:52:30 -08003376 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3377 * Supported Values: 1 - register just FCP
3378 * 3 - register both FCP and NVME
James Smart7d708032017-03-08 14:36:01 -08003379 * Supported values are [1,3]. Default value is 1
James Smart895427b2017-02-12 13:52:30 -08003380 */
James Smart7d708032017-03-08 14:36:01 -08003381LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
James Smart895427b2017-02-12 13:52:30 -08003382 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3383 "Define fc4 type to register with fabric.");
3384
3385/*
3386 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3387 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003388 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3389 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003390 *
3391 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3392 * The remaining XRIs get split up based on lpfc_xri_split per port:
3393 *
3394 * Supported Values are in percentages
3395 * the xri_split value is the percentage the SCSI port will get. The remaining
3396 * percentage will go to NVME.
3397 */
3398LPFC_ATTR_R(xri_split, 50, 10, 90,
James Smart4410a672017-04-21 16:04:57 -07003399 "Division of XRI resources between SCSI and NVME");
James Smart895427b2017-02-12 13:52:30 -08003400
3401/*
dea31012005-04-17 16:05:31 -05003402# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3403# deluged with LOTS of information.
3404# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003405# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003406*/
James Smartf4b4c682009-05-22 14:53:12 -04003407LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003408 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003409
3410/*
James Smart7ee5d432007-10-27 13:37:17 -04003411# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3412# objects that have been registered with the nameserver after login.
3413*/
James Smartcf971242012-03-01 22:37:32 -05003414LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003415 "Deregister nameserver objects before LOGO");
3416
3417/*
dea31012005-04-17 16:05:31 -05003418# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003419# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3420# If this parameter value is greater than 1/8th the maximum number of exchanges
3421# supported by the HBA port, then the lun queue depth will be reduced to
3422# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003423*/
James Smart572709e2013-07-15 18:32:43 -04003424LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003425 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003426
3427/*
James Smart7dc517d2010-07-14 15:32:10 -04003428# tgt_queue_depth: This parameter is used to limit the number of outstanding
3429# commands per target port. Value range is [10,65535]. Default value is 65535.
3430*/
3431LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003432 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003433
3434/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003435# hba_queue_depth: This parameter is used to limit the number of outstanding
3436# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3437# value is greater than the maximum number of exchanges supported by the HBA,
3438# then maximum number of exchanges supported by the HBA is used to determine
3439# the hba_queue_depth.
3440*/
3441LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3442 "Max number of FCP commands we can queue to a lpfc HBA");
3443
3444/*
James Smart92d7f7b2007-06-17 19:56:38 -05003445# peer_port_login: This parameter allows/prevents logins
3446# between peer ports hosted on the same physical port.
3447# When this parameter is set 0 peer ports of same physical port
3448# are not allowed to login to each other.
3449# When this parameter is set 1 peer ports of same physical port
3450# are allowed to login to each other.
3451# Default value of this parameter is 0.
3452*/
James Smart3de2a652007-08-02 11:09:59 -04003453LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3454 "Allow peer ports on the same physical port to login to each "
3455 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003456
3457/*
James Smart3de2a652007-08-02 11:09:59 -04003458# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003459# between Virtual Ports and remote initiators.
3460# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3461# other initiators and will attempt to PLOGI all remote ports.
3462# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3463# remote ports and will not attempt to PLOGI to other initiators.
3464# This parameter does not restrict to the physical port.
3465# This parameter does not restrict logins to Fabric resident remote ports.
3466# Default value of this parameter is 1.
3467*/
James Smart3de2a652007-08-02 11:09:59 -04003468static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003469module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003470MODULE_PARM_DESC(lpfc_restrict_login,
3471 "Restrict virtual ports login to remote initiators.");
3472lpfc_vport_param_show(restrict_login);
3473
James Smarte59058c2008-08-24 21:49:00 -04003474/**
James Smart3621a712009-04-06 18:47:14 -04003475 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003476 * @vport: lpfc vport structure pointer.
3477 * @val: contains the restrict login value.
3478 *
3479 * Description:
3480 * If val is not in a valid range then log a kernel error message and set
3481 * the vport restrict login to one.
3482 * If the port type is physical clear the restrict login flag and return.
3483 * Else set the restrict login flag to val.
3484 *
3485 * Returns:
3486 * zero if val is in range
3487 * -EINVAL val out of range
3488 **/
James Smart3de2a652007-08-02 11:09:59 -04003489static int
3490lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3491{
3492 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003493 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003494 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003495 "be set to %d, allowed range is [0, 1]\n",
3496 val);
James Smart3de2a652007-08-02 11:09:59 -04003497 vport->cfg_restrict_login = 1;
3498 return -EINVAL;
3499 }
3500 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3501 vport->cfg_restrict_login = 0;
3502 return 0;
3503 }
3504 vport->cfg_restrict_login = val;
3505 return 0;
3506}
3507
James Smarte59058c2008-08-24 21:49:00 -04003508/**
James Smart3621a712009-04-06 18:47:14 -04003509 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003510 * @vport: lpfc vport structure pointer.
3511 * @val: contains the restrict login value.
3512 *
3513 * Description:
3514 * If val is not in a valid range then log a kernel error message and set
3515 * the vport restrict login to one.
3516 * If the port type is physical and the val is not zero log a kernel
3517 * error message, clear the restrict login flag and return zero.
3518 * Else set the restrict login flag to val.
3519 *
3520 * Returns:
3521 * zero if val is in range
3522 * -EINVAL val out of range
3523 **/
James Smart3de2a652007-08-02 11:09:59 -04003524static int
3525lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3526{
3527 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003528 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003529 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003530 "be set to %d, allowed range is [0, 1]\n",
3531 val);
James Smart3de2a652007-08-02 11:09:59 -04003532 vport->cfg_restrict_login = 1;
3533 return -EINVAL;
3534 }
3535 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003536 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3537 "0468 lpfc_restrict_login must be 0 for "
3538 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003539 vport->cfg_restrict_login = 0;
3540 return 0;
3541 }
3542 vport->cfg_restrict_login = val;
3543 return 0;
3544}
3545lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003546static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3547 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003548
3549/*
dea31012005-04-17 16:05:31 -05003550# Some disk devices have a "select ID" or "select Target" capability.
3551# From a protocol standpoint "select ID" usually means select the
3552# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3553# annex" which contains a table that maps a "select ID" (a number
3554# between 0 and 7F) to an ALPA. By default, for compatibility with
3555# older drivers, the lpfc driver scans this table from low ALPA to high
3556# ALPA.
3557#
3558# Turning on the scan-down variable (on = 1, off = 0) will
3559# cause the lpfc driver to use an inverted table, effectively
3560# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3561#
3562# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3563# and will not work across a fabric. Also this parameter will take
3564# effect only in the case when ALPA map is not available.)
3565*/
James Smart3de2a652007-08-02 11:09:59 -04003566LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3567 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003568
3569/*
dea31012005-04-17 16:05:31 -05003570# lpfc_topology: link topology for init link
3571# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003572# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003573# 0x02 = attempt point-to-point mode only
3574# 0x04 = attempt loop mode only
3575# 0x06 = attempt point-to-point mode then loop
3576# Set point-to-point mode if you want to run as an N_Port.
3577# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3578# Default value is 0.
3579*/
James Smart0a035432016-10-13 15:06:10 -07003580LPFC_ATTR(topology, 0, 0, 6,
3581 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003582
3583/**
James Smart3621a712009-04-06 18:47:14 -04003584 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003585 * @phba: lpfc_hba pointer.
3586 * @val: topology value.
3587 *
3588 * Description:
3589 * If val is in a valid range then set the adapter's topology field and
3590 * issue a lip; if the lip fails reset the topology to the old value.
3591 *
3592 * If the value is not in range log a kernel error message and return an error.
3593 *
3594 * Returns:
3595 * zero if val is in range and lip okay
3596 * non-zero return value from lpfc_issue_lip()
3597 * -EINVAL val out of range
3598 **/
James Smarta257bf92009-04-06 18:48:10 -04003599static ssize_t
3600lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3601 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003602{
James Smarta257bf92009-04-06 18:48:10 -04003603 struct Scsi_Host *shost = class_to_shost(dev);
3604 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3605 struct lpfc_hba *phba = vport->phba;
3606 int val = 0;
3607 int nolip = 0;
3608 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003609 int err;
3610 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003611
3612 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3613 nolip = 1;
3614 val_buf = &buf[strlen("nolip ")];
3615 }
3616
3617 if (!isdigit(val_buf[0]))
3618 return -EINVAL;
3619 if (sscanf(val_buf, "%i", &val) != 1)
3620 return -EINVAL;
3621
James Smart83108bd2008-01-11 01:53:09 -05003622 if (val >= 0 && val <= 6) {
3623 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003624 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3625 val == 4) {
3626 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3627 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003628 val);
James Smartff78d8f2011-12-13 13:21:35 -05003629 return -EINVAL;
3630 }
James Smartd38dd522015-08-31 16:48:17 -04003631 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3632 val == 4) {
3633 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3634 "3114 Loop mode not supported\n");
3635 return -EINVAL;
3636 }
3637 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003638 if (nolip)
3639 return strlen(buf);
3640
James Smart88a2cfb2011-07-22 18:36:33 -04003641 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3642 "3054 lpfc_topology changed from %d to %d\n",
3643 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003644 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3645 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003646 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003647 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003648 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003649 return -EINVAL;
3650 } else
3651 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003652 }
3653 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3654 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3655 "allowed range is [0, 6]\n",
3656 phba->brd_no, val);
3657 return -EINVAL;
3658}
James Smart0a035432016-10-13 15:06:10 -07003659
James Smart83108bd2008-01-11 01:53:09 -05003660lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003661static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003662 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003663
James Smart21e9a0a2009-05-22 14:53:21 -04003664/**
3665 * lpfc_static_vport_show: Read callback function for
3666 * lpfc_static_vport sysfs file.
3667 * @dev: Pointer to class device object.
3668 * @attr: device attribute structure.
3669 * @buf: Data buffer.
3670 *
3671 * This function is the read call back function for
3672 * lpfc_static_vport sysfs file. The lpfc_static_vport
3673 * sysfs file report the mageability of the vport.
3674 **/
3675static ssize_t
3676lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3677 char *buf)
3678{
3679 struct Scsi_Host *shost = class_to_shost(dev);
3680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3681 if (vport->vport_flag & STATIC_VPORT)
3682 sprintf(buf, "1\n");
3683 else
3684 sprintf(buf, "0\n");
3685
3686 return strlen(buf);
3687}
3688
3689/*
3690 * Sysfs attribute to control the statistical data collection.
3691 */
3692static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3693 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003694
3695/**
James Smart3621a712009-04-06 18:47:14 -04003696 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003697 * @dev: Pointer to class device.
3698 * @buf: Data buffer.
3699 * @count: Size of the data buffer.
3700 *
Masahiro Yamada9332ef92017-02-27 14:28:47 -08003701 * This function get called when a user write to the lpfc_stat_data_ctrl
James Smartea2151b2008-09-07 11:52:10 -04003702 * sysfs file. This function parse the command written to the sysfs file
3703 * and take appropriate action. These commands are used for controlling
3704 * driver statistical data collection.
3705 * Following are the command this function handles.
3706 *
3707 * setbucket <bucket_type> <base> <step>
3708 * = Set the latency buckets.
3709 * destroybucket = destroy all the buckets.
3710 * start = start data collection
3711 * stop = stop data collection
3712 * reset = reset the collected data
3713 **/
3714static ssize_t
3715lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3716 const char *buf, size_t count)
3717{
3718 struct Scsi_Host *shost = class_to_shost(dev);
3719 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3720 struct lpfc_hba *phba = vport->phba;
3721#define LPFC_MAX_DATA_CTRL_LEN 1024
3722 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3723 unsigned long i;
3724 char *str_ptr, *token;
3725 struct lpfc_vport **vports;
3726 struct Scsi_Host *v_shost;
3727 char *bucket_type_str, *base_str, *step_str;
3728 unsigned long base, step, bucket_type;
3729
3730 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003731 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003732 return -EINVAL;
3733
James Smarteb016562014-09-03 12:58:06 -04003734 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003735 str_ptr = &bucket_data[0];
3736 /* Ignore this token - this is command token */
3737 token = strsep(&str_ptr, "\t ");
3738 if (!token)
3739 return -EINVAL;
3740
3741 bucket_type_str = strsep(&str_ptr, "\t ");
3742 if (!bucket_type_str)
3743 return -EINVAL;
3744
3745 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3746 bucket_type = LPFC_LINEAR_BUCKET;
3747 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3748 bucket_type = LPFC_POWER2_BUCKET;
3749 else
3750 return -EINVAL;
3751
3752 base_str = strsep(&str_ptr, "\t ");
3753 if (!base_str)
3754 return -EINVAL;
3755 base = simple_strtoul(base_str, NULL, 0);
3756
3757 step_str = strsep(&str_ptr, "\t ");
3758 if (!step_str)
3759 return -EINVAL;
3760 step = simple_strtoul(step_str, NULL, 0);
3761 if (!step)
3762 return -EINVAL;
3763
3764 /* Block the data collection for every vport */
3765 vports = lpfc_create_vport_work_array(phba);
3766 if (vports == NULL)
3767 return -ENOMEM;
3768
James Smartf4b4c682009-05-22 14:53:12 -04003769 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003770 v_shost = lpfc_shost_from_vport(vports[i]);
3771 spin_lock_irq(v_shost->host_lock);
3772 /* Block and reset data collection */
3773 vports[i]->stat_data_blocked = 1;
3774 if (vports[i]->stat_data_enabled)
3775 lpfc_vport_reset_stat_data(vports[i]);
3776 spin_unlock_irq(v_shost->host_lock);
3777 }
3778
3779 /* Set the bucket attributes */
3780 phba->bucket_type = bucket_type;
3781 phba->bucket_base = base;
3782 phba->bucket_step = step;
3783
James Smartf4b4c682009-05-22 14:53:12 -04003784 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003785 v_shost = lpfc_shost_from_vport(vports[i]);
3786
3787 /* Unblock data collection */
3788 spin_lock_irq(v_shost->host_lock);
3789 vports[i]->stat_data_blocked = 0;
3790 spin_unlock_irq(v_shost->host_lock);
3791 }
3792 lpfc_destroy_vport_work_array(phba, vports);
3793 return strlen(buf);
3794 }
3795
3796 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3797 vports = lpfc_create_vport_work_array(phba);
3798 if (vports == NULL)
3799 return -ENOMEM;
3800
James Smartf4b4c682009-05-22 14:53:12 -04003801 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003802 v_shost = lpfc_shost_from_vport(vports[i]);
3803 spin_lock_irq(shost->host_lock);
3804 vports[i]->stat_data_blocked = 1;
3805 lpfc_free_bucket(vport);
3806 vport->stat_data_enabled = 0;
3807 vports[i]->stat_data_blocked = 0;
3808 spin_unlock_irq(shost->host_lock);
3809 }
3810 lpfc_destroy_vport_work_array(phba, vports);
3811 phba->bucket_type = LPFC_NO_BUCKET;
3812 phba->bucket_base = 0;
3813 phba->bucket_step = 0;
3814 return strlen(buf);
3815 }
3816
3817 if (!strncmp(buf, "start", strlen("start"))) {
3818 /* If no buckets configured return error */
3819 if (phba->bucket_type == LPFC_NO_BUCKET)
3820 return -EINVAL;
3821 spin_lock_irq(shost->host_lock);
3822 if (vport->stat_data_enabled) {
3823 spin_unlock_irq(shost->host_lock);
3824 return strlen(buf);
3825 }
3826 lpfc_alloc_bucket(vport);
3827 vport->stat_data_enabled = 1;
3828 spin_unlock_irq(shost->host_lock);
3829 return strlen(buf);
3830 }
3831
3832 if (!strncmp(buf, "stop", strlen("stop"))) {
3833 spin_lock_irq(shost->host_lock);
3834 if (vport->stat_data_enabled == 0) {
3835 spin_unlock_irq(shost->host_lock);
3836 return strlen(buf);
3837 }
3838 lpfc_free_bucket(vport);
3839 vport->stat_data_enabled = 0;
3840 spin_unlock_irq(shost->host_lock);
3841 return strlen(buf);
3842 }
3843
3844 if (!strncmp(buf, "reset", strlen("reset"))) {
3845 if ((phba->bucket_type == LPFC_NO_BUCKET)
3846 || !vport->stat_data_enabled)
3847 return strlen(buf);
3848 spin_lock_irq(shost->host_lock);
3849 vport->stat_data_blocked = 1;
3850 lpfc_vport_reset_stat_data(vport);
3851 vport->stat_data_blocked = 0;
3852 spin_unlock_irq(shost->host_lock);
3853 return strlen(buf);
3854 }
3855 return -EINVAL;
3856}
3857
3858
3859/**
James Smart3621a712009-04-06 18:47:14 -04003860 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003861 * @dev: Pointer to class device object.
3862 * @buf: Data buffer.
3863 *
3864 * This function is the read call back function for
3865 * lpfc_stat_data_ctrl sysfs file. This function report the
3866 * current statistical data collection state.
3867 **/
3868static ssize_t
3869lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3870 char *buf)
3871{
3872 struct Scsi_Host *shost = class_to_shost(dev);
3873 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3874 struct lpfc_hba *phba = vport->phba;
3875 int index = 0;
3876 int i;
3877 char *bucket_type;
3878 unsigned long bucket_value;
3879
3880 switch (phba->bucket_type) {
3881 case LPFC_LINEAR_BUCKET:
3882 bucket_type = "linear";
3883 break;
3884 case LPFC_POWER2_BUCKET:
3885 bucket_type = "power2";
3886 break;
3887 default:
3888 bucket_type = "No Bucket";
3889 break;
3890 }
3891
3892 sprintf(&buf[index], "Statistical Data enabled :%d, "
3893 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3894 " Bucket step :%d\nLatency Ranges :",
3895 vport->stat_data_enabled, vport->stat_data_blocked,
3896 bucket_type, phba->bucket_base, phba->bucket_step);
3897 index = strlen(buf);
3898 if (phba->bucket_type != LPFC_NO_BUCKET) {
3899 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3900 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3901 bucket_value = phba->bucket_base +
3902 phba->bucket_step * i;
3903 else
3904 bucket_value = phba->bucket_base +
3905 (1 << i) * phba->bucket_step;
3906
3907 if (index + 10 > PAGE_SIZE)
3908 break;
3909 sprintf(&buf[index], "%08ld ", bucket_value);
3910 index = strlen(buf);
3911 }
3912 }
3913 sprintf(&buf[index], "\n");
3914 return strlen(buf);
3915}
3916
3917/*
3918 * Sysfs attribute to control the statistical data collection.
3919 */
3920static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3921 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3922
3923/*
3924 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3925 */
3926
3927/*
3928 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3929 * for each target.
3930 */
3931#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3932#define MAX_STAT_DATA_SIZE_PER_TARGET \
3933 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3934
3935
3936/**
James Smart3621a712009-04-06 18:47:14 -04003937 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003938 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003939 * @kobj: Pointer to the kernel object
3940 * @bin_attr: Attribute object
3941 * @buff: Buffer pointer
3942 * @off: File offset
3943 * @count: Buffer size
3944 *
3945 * This function is the read call back function for lpfc_drvr_stat_data
3946 * sysfs file. This function export the statistical data to user
3947 * applications.
3948 **/
3949static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003950sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3951 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003952 char *buf, loff_t off, size_t count)
3953{
3954 struct device *dev = container_of(kobj, struct device,
3955 kobj);
3956 struct Scsi_Host *shost = class_to_shost(dev);
3957 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3958 struct lpfc_hba *phba = vport->phba;
3959 int i = 0, index = 0;
3960 unsigned long nport_index;
3961 struct lpfc_nodelist *ndlp = NULL;
3962 nport_index = (unsigned long)off /
3963 MAX_STAT_DATA_SIZE_PER_TARGET;
3964
3965 if (!vport->stat_data_enabled || vport->stat_data_blocked
3966 || (phba->bucket_type == LPFC_NO_BUCKET))
3967 return 0;
3968
3969 spin_lock_irq(shost->host_lock);
3970 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3971 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3972 continue;
3973
3974 if (nport_index > 0) {
3975 nport_index--;
3976 continue;
3977 }
3978
3979 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3980 > count)
3981 break;
3982
3983 if (!ndlp->lat_data)
3984 continue;
3985
3986 /* Print the WWN */
3987 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3988 ndlp->nlp_portname.u.wwn[0],
3989 ndlp->nlp_portname.u.wwn[1],
3990 ndlp->nlp_portname.u.wwn[2],
3991 ndlp->nlp_portname.u.wwn[3],
3992 ndlp->nlp_portname.u.wwn[4],
3993 ndlp->nlp_portname.u.wwn[5],
3994 ndlp->nlp_portname.u.wwn[6],
3995 ndlp->nlp_portname.u.wwn[7]);
3996
3997 index = strlen(buf);
3998
3999 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
4000 sprintf(&buf[index], "%010u,",
4001 ndlp->lat_data[i].cmd_count);
4002 index = strlen(buf);
4003 }
4004 sprintf(&buf[index], "\n");
4005 index = strlen(buf);
4006 }
4007 spin_unlock_irq(shost->host_lock);
4008 return index;
4009}
4010
4011static struct bin_attribute sysfs_drvr_stat_data_attr = {
4012 .attr = {
4013 .name = "lpfc_drvr_stat_data",
4014 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04004015 },
4016 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
4017 .read = sysfs_drvr_stat_data_read,
4018 .write = NULL,
4019};
4020
dea31012005-04-17 16:05:31 -05004021/*
4022# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
4023# connection.
James Smart76a95d72010-11-20 23:11:48 -05004024# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05004025*/
James Smarte59058c2008-08-24 21:49:00 -04004026/**
James Smart3621a712009-04-06 18:47:14 -04004027 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004028 * @phba: lpfc_hba pointer.
4029 * @val: link speed value.
4030 *
4031 * Description:
4032 * If val is in a valid range then set the adapter's link speed field and
4033 * issue a lip; if the lip fails reset the link speed to the old value.
4034 *
4035 * Notes:
4036 * If the value is not in range log a kernel error message and return an error.
4037 *
4038 * Returns:
4039 * zero if val is in range and lip okay.
4040 * non-zero return value from lpfc_issue_lip()
4041 * -EINVAL val out of range
4042 **/
James Smarta257bf92009-04-06 18:48:10 -04004043static ssize_t
4044lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4045 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05004046{
James Smarta257bf92009-04-06 18:48:10 -04004047 struct Scsi_Host *shost = class_to_shost(dev);
4048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4049 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05004050 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04004051 int nolip = 0;
4052 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05004053 int err;
James Smartc6918162016-10-13 15:06:16 -07004054 uint32_t prev_val, if_type;
4055
4056 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4057 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4058 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4059 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05004060
James Smarta257bf92009-04-06 18:48:10 -04004061 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4062 nolip = 1;
4063 val_buf = &buf[strlen("nolip ")];
4064 }
4065
4066 if (!isdigit(val_buf[0]))
4067 return -EINVAL;
4068 if (sscanf(val_buf, "%i", &val) != 1)
4069 return -EINVAL;
4070
James Smart88a2cfb2011-07-22 18:36:33 -04004071 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4072 "3055 lpfc_link_speed changed from %d to %d %s\n",
4073 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4074
James Smart76a95d72010-11-20 23:11:48 -05004075 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4076 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4077 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4078 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4079 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004080 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4081 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004082 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4083 "2879 lpfc_link_speed attribute cannot be set "
4084 "to %d. Speed is not supported by this port.\n",
4085 val);
James Smart83108bd2008-01-11 01:53:09 -05004086 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004087 }
James Smartff78d8f2011-12-13 13:21:35 -05004088 if (val == LPFC_USER_LINK_SPEED_16G &&
4089 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4090 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4091 "3112 lpfc_link_speed attribute cannot be set "
4092 "to %d. Speed is not supported in loop mode.\n",
4093 val);
4094 return -EINVAL;
4095 }
James Smart76a95d72010-11-20 23:11:48 -05004096 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4097 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004098 prev_val = phba->cfg_link_speed;
4099 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004100 if (nolip)
4101 return strlen(buf);
4102
James Smart83108bd2008-01-11 01:53:09 -05004103 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004104 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004105 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004106 return -EINVAL;
4107 } else
4108 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004109 }
James Smart83108bd2008-01-11 01:53:09 -05004110 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004111 "0469 lpfc_link_speed attribute cannot be set to %d, "
4112 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004113 return -EINVAL;
4114}
4115
4116static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004117module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004118MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4119lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004120
4121/**
James Smart3621a712009-04-06 18:47:14 -04004122 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004123 * @phba: lpfc_hba pointer.
4124 * @val: link speed value.
4125 *
4126 * Description:
4127 * If val is in a valid range then set the adapter's link speed field.
4128 *
4129 * Notes:
4130 * If the value is not in range log a kernel error message, clear the link
4131 * speed and return an error.
4132 *
4133 * Returns:
4134 * zero if val saved.
4135 * -EINVAL val out of range
4136 **/
James Smart83108bd2008-01-11 01:53:09 -05004137static int
4138lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4139{
James Smartff78d8f2011-12-13 13:21:35 -05004140 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4141 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4142 "3111 lpfc_link_speed of %d cannot "
4143 "support loop mode, setting topology to default.\n",
4144 val);
4145 phba->cfg_topology = 0;
4146 }
James Smart76a95d72010-11-20 23:11:48 -05004147 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4148 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004149 phba->cfg_link_speed = val;
4150 return 0;
4151 }
4152 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004153 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004154 "be set to %d, allowed values are "
4155 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004156 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004157 return -EINVAL;
4158}
4159
Tony Jonesee959b02008-02-22 00:13:36 +01004160static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05004161 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05004162
4163/*
James Smart0d878412009-10-02 15:16:56 -04004164# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4165# 0 = aer disabled or not supported
4166# 1 = aer supported and enabled (default)
4167# Value range is [0,1]. Default value is 1.
4168*/
James Smart506139a2016-10-13 15:06:09 -07004169LPFC_ATTR(aer_support, 1, 0, 1,
4170 "Enable PCIe device AER support");
4171lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004172
4173/**
4174 * lpfc_aer_support_store - Set the adapter for aer support
4175 *
4176 * @dev: class device that is converted into a Scsi_host.
4177 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004178 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004179 * @count: unused variable.
4180 *
4181 * Description:
4182 * If the val is 1 and currently the device's AER capability was not
4183 * enabled, invoke the kernel's enable AER helper routine, trying to
4184 * enable the device's AER capability. If the helper routine enabling
4185 * AER returns success, update the device's cfg_aer_support flag to
4186 * indicate AER is supported by the device; otherwise, if the device
4187 * AER capability is already enabled to support AER, then do nothing.
4188 *
4189 * If the val is 0 and currently the device's AER support was enabled,
4190 * invoke the kernel's disable AER helper routine. After that, update
4191 * the device's cfg_aer_support flag to indicate AER is not supported
4192 * by the device; otherwise, if the device AER capability is already
4193 * disabled from supporting AER, then do nothing.
4194 *
4195 * Returns:
4196 * length of the buf on success if val is in range the intended mode
4197 * is supported.
4198 * -EINVAL if val out of range or intended mode is not supported.
4199 **/
4200static ssize_t
4201lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4202 const char *buf, size_t count)
4203{
4204 struct Scsi_Host *shost = class_to_shost(dev);
4205 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4206 struct lpfc_hba *phba = vport->phba;
4207 int val = 0, rc = -EINVAL;
4208
4209 if (!isdigit(buf[0]))
4210 return -EINVAL;
4211 if (sscanf(buf, "%i", &val) != 1)
4212 return -EINVAL;
4213
4214 switch (val) {
4215 case 0:
4216 if (phba->hba_flag & HBA_AER_ENABLED) {
4217 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4218 if (!rc) {
4219 spin_lock_irq(&phba->hbalock);
4220 phba->hba_flag &= ~HBA_AER_ENABLED;
4221 spin_unlock_irq(&phba->hbalock);
4222 phba->cfg_aer_support = 0;
4223 rc = strlen(buf);
4224 } else
James Smart891478a2009-11-18 15:40:23 -05004225 rc = -EPERM;
4226 } else {
James Smart0d878412009-10-02 15:16:56 -04004227 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004228 rc = strlen(buf);
4229 }
James Smart0d878412009-10-02 15:16:56 -04004230 break;
4231 case 1:
4232 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4233 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4234 if (!rc) {
4235 spin_lock_irq(&phba->hbalock);
4236 phba->hba_flag |= HBA_AER_ENABLED;
4237 spin_unlock_irq(&phba->hbalock);
4238 phba->cfg_aer_support = 1;
4239 rc = strlen(buf);
4240 } else
James Smart891478a2009-11-18 15:40:23 -05004241 rc = -EPERM;
4242 } else {
James Smart0d878412009-10-02 15:16:56 -04004243 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004244 rc = strlen(buf);
4245 }
James Smart0d878412009-10-02 15:16:56 -04004246 break;
4247 default:
4248 rc = -EINVAL;
4249 break;
4250 }
4251 return rc;
4252}
4253
James Smart0d878412009-10-02 15:16:56 -04004254static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4255 lpfc_aer_support_show, lpfc_aer_support_store);
4256
4257/**
4258 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4259 * @dev: class device that is converted into a Scsi_host.
4260 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004261 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004262 * @count: unused variable.
4263 *
4264 * Description:
4265 * If the @buf contains 1 and the device currently has the AER support
4266 * enabled, then invokes the kernel AER helper routine
4267 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4268 * error status register.
4269 *
4270 * Notes:
4271 *
4272 * Returns:
4273 * -EINVAL if the buf does not contain the 1 or the device is not currently
4274 * enabled with the AER support.
4275 **/
4276static ssize_t
4277lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4278 const char *buf, size_t count)
4279{
4280 struct Scsi_Host *shost = class_to_shost(dev);
4281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4282 struct lpfc_hba *phba = vport->phba;
4283 int val, rc = -1;
4284
4285 if (!isdigit(buf[0]))
4286 return -EINVAL;
4287 if (sscanf(buf, "%i", &val) != 1)
4288 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004289 if (val != 1)
4290 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004291
James Smart891478a2009-11-18 15:40:23 -05004292 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004293 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4294
4295 if (rc == 0)
4296 return strlen(buf);
4297 else
James Smart891478a2009-11-18 15:40:23 -05004298 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004299}
4300
4301static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4302 lpfc_aer_cleanup_state);
4303
James Smart912e3ac2011-05-24 11:42:11 -04004304/**
4305 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4306 *
4307 * @dev: class device that is converted into a Scsi_host.
4308 * @attr: device attribute, not used.
4309 * @buf: containing the string the number of vfs to be enabled.
4310 * @count: unused variable.
4311 *
4312 * Description:
4313 * When this api is called either through user sysfs, the driver shall
4314 * try to enable or disable SR-IOV virtual functions according to the
4315 * following:
4316 *
4317 * If zero virtual function has been enabled to the physical function,
4318 * the driver shall invoke the pci enable virtual function api trying
4319 * to enable the virtual functions. If the nr_vfn provided is greater
4320 * than the maximum supported, the maximum virtual function number will
4321 * be used for invoking the api; otherwise, the nr_vfn provided shall
4322 * be used for invoking the api. If the api call returned success, the
4323 * actual number of virtual functions enabled will be set to the driver
4324 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4325 * cfg_sriov_nr_virtfn remains zero.
4326 *
4327 * If none-zero virtual functions have already been enabled to the
4328 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4329 * -EINVAL will be returned and the driver does nothing;
4330 *
4331 * If the nr_vfn provided is zero and none-zero virtual functions have
4332 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4333 * disabling virtual function api shall be invoded to disable all the
4334 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4335 * zero. Otherwise, if zero virtual function has been enabled, do
4336 * nothing.
4337 *
4338 * Returns:
4339 * length of the buf on success if val is in range the intended mode
4340 * is supported.
4341 * -EINVAL if val out of range or intended mode is not supported.
4342 **/
4343static ssize_t
4344lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4345 const char *buf, size_t count)
4346{
4347 struct Scsi_Host *shost = class_to_shost(dev);
4348 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4349 struct lpfc_hba *phba = vport->phba;
4350 struct pci_dev *pdev = phba->pcidev;
4351 int val = 0, rc = -EINVAL;
4352
4353 /* Sanity check on user data */
4354 if (!isdigit(buf[0]))
4355 return -EINVAL;
4356 if (sscanf(buf, "%i", &val) != 1)
4357 return -EINVAL;
4358 if (val < 0)
4359 return -EINVAL;
4360
4361 /* Request disabling virtual functions */
4362 if (val == 0) {
4363 if (phba->cfg_sriov_nr_virtfn > 0) {
4364 pci_disable_sriov(pdev);
4365 phba->cfg_sriov_nr_virtfn = 0;
4366 }
4367 return strlen(buf);
4368 }
4369
4370 /* Request enabling virtual functions */
4371 if (phba->cfg_sriov_nr_virtfn > 0) {
4372 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4373 "3018 There are %d virtual functions "
4374 "enabled on physical function.\n",
4375 phba->cfg_sriov_nr_virtfn);
4376 return -EEXIST;
4377 }
4378
4379 if (val <= LPFC_MAX_VFN_PER_PFN)
4380 phba->cfg_sriov_nr_virtfn = val;
4381 else {
4382 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4383 "3019 Enabling %d virtual functions is not "
4384 "allowed.\n", val);
4385 return -EINVAL;
4386 }
4387
4388 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4389 if (rc) {
4390 phba->cfg_sriov_nr_virtfn = 0;
4391 rc = -EPERM;
4392 } else
4393 rc = strlen(buf);
4394
4395 return rc;
4396}
4397
James Smart0cfbbf22016-10-13 15:06:12 -07004398LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4399 "Enable PCIe device SR-IOV virtual fn");
4400
James Smart912e3ac2011-05-24 11:42:11 -04004401lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004402static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4403 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4404
James Smart173edbb2012-06-12 13:54:50 -04004405/**
James Smartc71ab862012-10-31 14:44:33 -04004406 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4407 *
4408 * @dev: class device that is converted into a Scsi_host.
4409 * @attr: device attribute, not used.
4410 * @buf: containing the string the number of vfs to be enabled.
4411 * @count: unused variable.
4412 *
4413 * Description:
4414 *
4415 * Returns:
4416 * length of the buf on success if val is in range the intended mode
4417 * is supported.
4418 * -EINVAL if val out of range or intended mode is not supported.
4419 **/
4420static ssize_t
4421lpfc_request_firmware_upgrade_store(struct device *dev,
4422 struct device_attribute *attr,
4423 const char *buf, size_t count)
4424{
4425 struct Scsi_Host *shost = class_to_shost(dev);
4426 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4427 struct lpfc_hba *phba = vport->phba;
4428 int val = 0, rc = -EINVAL;
4429
4430 /* Sanity check on user data */
4431 if (!isdigit(buf[0]))
4432 return -EINVAL;
4433 if (sscanf(buf, "%i", &val) != 1)
4434 return -EINVAL;
4435 if (val != 1)
4436 return -EINVAL;
4437
4438 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4439 if (rc)
4440 rc = -EPERM;
4441 else
4442 rc = strlen(buf);
4443 return rc;
4444}
4445
4446static int lpfc_req_fw_upgrade;
4447module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4448MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4449lpfc_param_show(request_firmware_upgrade)
4450
4451/**
4452 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4453 * @phba: lpfc_hba pointer.
4454 * @val: 0 or 1.
4455 *
4456 * Description:
4457 * Set the initial Linux generic firmware upgrade enable or disable flag.
4458 *
4459 * Returns:
4460 * zero if val saved.
4461 * -EINVAL val out of range
4462 **/
4463static int
4464lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4465{
4466 if (val >= 0 && val <= 1) {
4467 phba->cfg_request_firmware_upgrade = val;
4468 return 0;
4469 }
4470 return -EINVAL;
4471}
4472static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4473 lpfc_request_firmware_upgrade_show,
4474 lpfc_request_firmware_upgrade_store);
4475
4476/**
James Smart173edbb2012-06-12 13:54:50 -04004477 * lpfc_fcp_imax_store
4478 *
4479 * @dev: class device that is converted into a Scsi_host.
4480 * @attr: device attribute, not used.
4481 * @buf: string with the number of fast-path FCP interrupts per second.
4482 * @count: unused variable.
4483 *
4484 * Description:
4485 * If val is in a valid range [636,651042], then set the adapter's
4486 * maximum number of fast-path FCP interrupts per second.
4487 *
4488 * Returns:
4489 * length of the buf on success if val is in range the intended mode
4490 * is supported.
4491 * -EINVAL if val out of range or intended mode is not supported.
4492 **/
4493static ssize_t
4494lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4495 const char *buf, size_t count)
4496{
4497 struct Scsi_Host *shost = class_to_shost(dev);
4498 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4499 struct lpfc_hba *phba = vport->phba;
4500 int val = 0, i;
4501
James Smartbf8dae82012-08-03 12:36:24 -04004502 /* fcp_imax is only valid for SLI4 */
4503 if (phba->sli_rev != LPFC_SLI_REV4)
4504 return -EINVAL;
4505
James Smart173edbb2012-06-12 13:54:50 -04004506 /* Sanity check on user data */
4507 if (!isdigit(buf[0]))
4508 return -EINVAL;
4509 if (sscanf(buf, "%i", &val) != 1)
4510 return -EINVAL;
4511
James Smartbf8dae82012-08-03 12:36:24 -04004512 /*
4513 * Value range for the HBA is [5000,5000000]
4514 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004515 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004516 */
James Smart895427b2017-02-12 13:52:30 -08004517 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004518 return -EINVAL;
4519
4520 phba->cfg_fcp_imax = (uint32_t)val;
James Smart0cf07f842017-06-01 21:07:10 -07004521 phba->initial_imax = phba->cfg_fcp_imax;
James Smart43140ca2017-03-04 09:30:34 -08004522
4523 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
James Smart0cf07f842017-06-01 21:07:10 -07004524 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4525 val);
James Smart173edbb2012-06-12 13:54:50 -04004526
4527 return strlen(buf);
4528}
4529
4530/*
4531# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004532# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004533#
James Smartbf8dae82012-08-03 12:36:24 -04004534# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004535*/
James Smartbf8dae82012-08-03 12:36:24 -04004536static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004537module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4538MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004539 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004540lpfc_param_show(fcp_imax)
4541
4542/**
4543 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4544 * @phba: lpfc_hba pointer.
4545 * @val: link speed value.
4546 *
4547 * Description:
4548 * If val is in a valid range [636,651042], then initialize the adapter's
4549 * maximum number of fast-path FCP interrupts per second.
4550 *
4551 * Returns:
4552 * zero if val saved.
4553 * -EINVAL val out of range
4554 **/
4555static int
4556lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4557{
James Smartbf8dae82012-08-03 12:36:24 -04004558 if (phba->sli_rev != LPFC_SLI_REV4) {
4559 phba->cfg_fcp_imax = 0;
4560 return 0;
4561 }
4562
James Smart895427b2017-02-12 13:52:30 -08004563 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4564 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004565 phba->cfg_fcp_imax = val;
4566 return 0;
4567 }
4568
4569 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004570 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4571 val);
James Smartbf8dae82012-08-03 12:36:24 -04004572 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004573
4574 return 0;
4575}
4576
4577static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4578 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4579
James Smart0cf07f842017-06-01 21:07:10 -07004580/*
4581 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4582 * 0 No auto_imax support
4583 * 1 auto imax on
4584 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4585 * the EQ Delay Multiplier, depending on the activity for that EQ.
4586 * Value range [0,1]. Default value is 1.
4587 */
4588LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4589
James Smart7bb03bb2013-04-17 20:19:16 -04004590/**
4591 * lpfc_state_show - Display current driver CPU affinity
4592 * @dev: class converted to a Scsi_host structure.
4593 * @attr: device attribute, not used.
4594 * @buf: on return contains text describing the state of the link.
4595 *
4596 * Returns: size of formatted string.
4597 **/
4598static ssize_t
4599lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4600 char *buf)
4601{
4602 struct Scsi_Host *shost = class_to_shost(dev);
4603 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4604 struct lpfc_hba *phba = vport->phba;
4605 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004606 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004607
4608 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4609 (phba->intr_type != MSIX))
4610 return len;
4611
4612 switch (phba->cfg_fcp_cpu_map) {
4613 case 0:
4614 len += snprintf(buf + len, PAGE_SIZE-len,
4615 "fcp_cpu_map: No mapping (%d)\n",
4616 phba->cfg_fcp_cpu_map);
4617 return len;
4618 case 1:
4619 len += snprintf(buf + len, PAGE_SIZE-len,
4620 "fcp_cpu_map: HBA centric mapping (%d): "
4621 "%d online CPUs\n",
4622 phba->cfg_fcp_cpu_map,
4623 phba->sli4_hba.num_online_cpu);
4624 break;
4625 case 2:
4626 len += snprintf(buf + len, PAGE_SIZE-len,
4627 "fcp_cpu_map: Driver centric mapping (%d): "
4628 "%d online CPUs\n",
4629 phba->cfg_fcp_cpu_map,
4630 phba->sli4_hba.num_online_cpu);
4631 break;
4632 }
4633
James Smart76fd07a2014-02-20 09:57:18 -05004634 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4635 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4636
4637 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004638 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4639 len += snprintf(buf + len, PAGE_SIZE-len,
4640 "CPU %02d io_chan %02d "
4641 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004642 phba->sli4_hba.curr_disp_cpu,
4643 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004644 cpup->core_id);
4645 else
4646 len += snprintf(buf + len, PAGE_SIZE-len,
4647 "CPU %02d io_chan %02d "
4648 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004649 phba->sli4_hba.curr_disp_cpu,
4650 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004651 cpup->core_id, cpup->irq);
4652
James Smart76fd07a2014-02-20 09:57:18 -05004653 phba->sli4_hba.curr_disp_cpu++;
4654
4655 /* display max number of CPUs keeping some margin */
4656 if (phba->sli4_hba.curr_disp_cpu <
4657 phba->sli4_hba.num_present_cpu &&
4658 (len >= (PAGE_SIZE - 64))) {
4659 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4660 break;
4661 }
James Smart7bb03bb2013-04-17 20:19:16 -04004662 }
James Smart76fd07a2014-02-20 09:57:18 -05004663
4664 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4665 phba->sli4_hba.curr_disp_cpu = 0;
4666
James Smart7bb03bb2013-04-17 20:19:16 -04004667 return len;
4668}
4669
4670/**
4671 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4672 * @dev: class device that is converted into a Scsi_host.
4673 * @attr: device attribute, not used.
4674 * @buf: one or more lpfc_polling_flags values.
4675 * @count: not used.
4676 *
4677 * Returns:
4678 * -EINVAL - Not implemented yet.
4679 **/
4680static ssize_t
4681lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4682 const char *buf, size_t count)
4683{
4684 int status = -EINVAL;
4685 return status;
4686}
4687
4688/*
4689# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4690# for the HBA.
4691#
4692# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4693# 0 - Do not affinitze IRQ vectors
4694# 1 - Affintize HBA vectors with respect to each HBA
4695# (start with CPU0 for each HBA)
4696# 2 - Affintize HBA vectors with respect to the entire driver
4697# (round robin thru all CPUs across all HBAs)
4698*/
4699static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4700module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4701MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4702 "Defines how to map CPUs to IRQ vectors per HBA");
4703
4704/**
4705 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4706 * @phba: lpfc_hba pointer.
4707 * @val: link speed value.
4708 *
4709 * Description:
4710 * If val is in a valid range [0-2], then affinitze the adapter's
4711 * MSIX vectors.
4712 *
4713 * Returns:
4714 * zero if val saved.
4715 * -EINVAL val out of range
4716 **/
4717static int
4718lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4719{
4720 if (phba->sli_rev != LPFC_SLI_REV4) {
4721 phba->cfg_fcp_cpu_map = 0;
4722 return 0;
4723 }
4724
4725 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4726 phba->cfg_fcp_cpu_map = val;
4727 return 0;
4728 }
4729
4730 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004731 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4732 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004733 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4734
4735 return 0;
4736}
4737
4738static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4739 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4740
James Smart0d878412009-10-02 15:16:56 -04004741/*
dea31012005-04-17 16:05:31 -05004742# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4743# Value range is [2,3]. Default value is 3.
4744*/
James Smart3de2a652007-08-02 11:09:59 -04004745LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4746 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004747
4748/*
4749# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4750# is [0,1]. Default value is 0.
4751*/
James Smart3de2a652007-08-02 11:09:59 -04004752LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4753 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004754
4755/*
James Smart3cb01c52013-07-15 18:35:04 -04004756# lpfc_first_burst_size: First burst size to use on the NPorts
4757# that support first burst.
4758# Value range is [0,65536]. Default value is 0.
4759*/
4760LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4761 "First burst size for Targets that support first burst");
4762
4763/*
James Smart2d7dbc42017-02-12 13:52:35 -08004764* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4765* When the driver is configured as an NVME target, this value is
4766* communicated to the NVME initiator in the PRLI response. It is
4767* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4768* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004769* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004770* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004771*/
James Smart2d7dbc42017-02-12 13:52:35 -08004772LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4773 "NVME Target mode first burst size in 512B increments.");
4774
4775/*
4776 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4777 * For the Initiator (I), enabling this parameter means that an NVMET
4778 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4779 * processed by the initiator for subsequent NVME FCP IO. For the target
4780 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4781 * driver parameter as the target function's first burst size returned to the
4782 * initiator in the target's NVME PRLI response. Parameter supported on physical
4783 * port only - no NPIV support.
4784 * Value range is [0,1]. Default value is 0 (disabled).
4785 */
James Smart895427b2017-02-12 13:52:30 -08004786LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4787 "Enable First Burst feature on I and T functions.");
4788
4789/*
James Smart977b5a02008-09-07 11:52:04 -04004790# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4791# depth. Default value is 0. When the value of this parameter is zero the
4792# SCSI command completion time is not used for controlling I/O queue depth. When
4793# the parameter is set to a non-zero value, the I/O queue depth is controlled
4794# to limit the I/O completion time to the parameter value.
4795# The value is set in milliseconds.
4796*/
James Smarted5b1522016-10-13 15:06:11 -07004797LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004798 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004799
James Smart977b5a02008-09-07 11:52:04 -04004800lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004801static int
4802lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4803{
4804 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4805 struct lpfc_nodelist *ndlp, *next_ndlp;
4806
4807 if (val == vport->cfg_max_scsicmpl_time)
4808 return 0;
4809 if ((val < 0) || (val > 60000))
4810 return -EINVAL;
4811 vport->cfg_max_scsicmpl_time = val;
4812
4813 spin_lock_irq(shost->host_lock);
4814 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4815 if (!NLP_CHK_NODE_ACT(ndlp))
4816 continue;
4817 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4818 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004819 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004820 }
4821 spin_unlock_irq(shost->host_lock);
4822 return 0;
4823}
4824lpfc_vport_param_store(max_scsicmpl_time);
4825static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4826 lpfc_max_scsicmpl_time_show,
4827 lpfc_max_scsicmpl_time_store);
4828
4829/*
dea31012005-04-17 16:05:31 -05004830# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4831# range is [0,1]. Default value is 0.
4832*/
4833LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4834
4835/*
James Smart895427b2017-02-12 13:52:30 -08004836 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4837 * range is [0,1]. Default value is 0.
4838 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4839 * For [1], FCP commands are issued to a Work Queue associated with the
4840 * current CPU.
4841 *
4842 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4843 * LPFC_FCP_SCHED_BY_CPU == 1
4844 *
4845 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4846 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4847 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4848 * through WQs will be used.
4849 */
4850LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4851 LPFC_FCP_SCHED_ROUND_ROBIN,
4852 LPFC_FCP_SCHED_BY_CPU,
4853 "Determine scheduling algorithm for "
4854 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004855
4856/*
James Smarta6571c62012-10-31 14:44:42 -04004857# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4858# range is [0,1]. Default value is 0.
4859# For [0], bus reset issues target reset to ALL devices
4860# For [1], bus reset issues target reset to non-FCP2 devices
4861*/
4862LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4863 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4864
4865
4866/*
dea31012005-04-17 16:05:31 -05004867# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4868# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004869# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004870# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4871# cr_delay is set to 0.
4872*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004873LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004874 "interrupt response is generated");
4875
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004876LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004877 "interrupt response is generated");
4878
4879/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004880# lpfc_multi_ring_support: Determines how many rings to spread available
4881# cmd/rsp IOCB entries across.
4882# Value range is [1,2]. Default value is 1.
4883*/
4884LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4885 "SLI rings to spread IOCB entries across");
4886
4887/*
James Smarta4bc3372006-12-02 13:34:16 -05004888# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4889# identifies what rctl value to configure the additional ring for.
4890# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4891*/
James Smart6a9c52c2009-10-02 15:16:51 -04004892LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004893 255, "Identifies RCTL for additional ring configuration");
4894
4895/*
4896# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4897# identifies what type value to configure the additional ring for.
4898# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4899*/
James Smart6a9c52c2009-10-02 15:16:51 -04004900LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004901 255, "Identifies TYPE for additional ring configuration");
4902
4903/*
James Smart4258e982015-12-16 18:11:58 -05004904# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4905# 0 = SmartSAN functionality disabled (default)
4906# 1 = SmartSAN functionality enabled
4907# This parameter will override the value of lpfc_fdmi_on module parameter.
4908# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004909*/
James Smart4258e982015-12-16 18:11:58 -05004910LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4911
4912/*
4913# lpfc_fdmi_on: Controls FDMI support.
4914# 0 No FDMI support (default)
4915# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004916# Traditional FDMI support means the driver will assume FDMI-2 support;
4917# however, if that fails, it will fallback to FDMI-1.
4918# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4919# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4920# lpfc_fdmi_on.
4921# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004922*/
James Smart8663cbb2016-03-31 14:12:33 -07004923LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004924
4925/*
4926# Specifies the maximum number of ELS cmds we can have outstanding (for
4927# discovery). Value range is [1,64]. Default value = 32.
4928*/
James Smart3de2a652007-08-02 11:09:59 -04004929LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004930 "during discovery");
4931
4932/*
James Smartc4a7c922013-05-31 17:04:59 -04004933# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4934# will be scanned by the SCSI midlayer when sequential scanning is
4935# used; and is also the highest LUN ID allowed when the SCSI midlayer
4936# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4937# LUN ID limit, but the SCSI midlayer requires this field for the uses
4938# above. The lpfc driver limits the default value to 255 for two reasons.
4939# As it bounds the sequential scan loop, scanning for thousands of luns
4940# on a target can take minutes of wall clock time. Additionally,
4941# there are FC targets, such as JBODs, that only recognize 8-bits of
4942# LUN ID. When they receive a value greater than 8 bits, they chop off
4943# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4944# and so on all as LUN ID 0. This causes the linux kernel, which sees
4945# valid responses at each of the LUN IDs, to believe there are multiple
4946# devices present, when in fact, there is only 1.
4947# A customer that is aware of their target behaviors, and the results as
4948# indicated above, is welcome to increase the lpfc_max_luns value.
4949# As mentioned, this value is not used by the lpfc driver, only the
4950# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004951# Value range is [0,65535]. Default value is 255.
4952# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004953*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004954LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004955
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004956/*
4957# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4958# Value range is [1,255], default value is 10.
4959*/
4960LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4961 "Milliseconds driver will wait between polling FCP ring");
4962
James Smart4ff43242006-12-02 13:34:56 -05004963/*
James Smart0c411222013-09-06 12:22:46 -04004964# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4965# to complete in seconds. Value range is [5,180], default value is 60.
4966*/
4967LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4968 "Maximum time to wait for task management commands to complete");
4969/*
James Smart4ff43242006-12-02 13:34:56 -05004970# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4971# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004972# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004973# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004974# 2 = MSI-X enabled (default)
4975# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004976*/
George Kadianakis8605c462010-01-17 21:19:31 +02004977LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004978 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004979
James Smart13815c82008-01-11 01:52:48 -05004980/*
James Smartf358dd02017-02-12 13:52:34 -08004981 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004982 *
4983 * 0 = NVME OAS disabled
4984 * 1 = NVME OAS enabled
4985 *
4986 * Value range is [0,1]. Default value is 0.
4987 */
4988LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4989 "Use OAS bit on NVME IOs");
4990
4991/*
4992 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4993 * will advertise it supports to the SCSI layer. This also will map to
4994 * the number of WQs the driver will create.
4995 *
4996 * 0 = Configure the number of io channels to the number of active CPUs.
4997 * 1,32 = Manually specify how many io channels to use.
4998 *
4999 * Value range is [0,32]. Default value is 4.
5000 */
5001LPFC_ATTR_R(fcp_io_channel,
5002 LPFC_FCP_IO_CHAN_DEF,
5003 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04005004 "Set the number of FCP I/O channels");
5005
5006/*
James Smart895427b2017-02-12 13:52:30 -08005007 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
5008 * will advertise it supports to the NVME layer. This also will map to
5009 * the number of WQs the driver will create.
5010 *
5011 * This module parameter is valid when lpfc_enable_fc4_type is set
5012 * to support NVME.
5013 *
5014 * The NVME Layer will try to create this many, plus 1 administrative
5015 * hardware queue. The administrative queue will always map to WQ 0
5016 * A hardware IO queue maps (qidx) to a specific driver WQ.
5017 *
5018 * 0 = Configure the number of io channels to the number of active CPUs.
5019 * 1,32 = Manually specify how many io channels to use.
5020 *
5021 * Value range is [0,32]. Default value is 0.
5022 */
5023LPFC_ATTR_R(nvme_io_channel,
5024 LPFC_NVME_IO_CHAN_DEF,
5025 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
5026 "Set the number of NVME I/O channels");
5027
5028/*
James Smart13815c82008-01-11 01:52:48 -05005029# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
5030# 0 = HBA resets disabled
5031# 1 = HBA resets enabled (default)
5032# Value range is [0,1]. Default value is 1.
5033*/
5034LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04005035
James Smart13815c82008-01-11 01:52:48 -05005036/*
James Smarteb7a3392010-11-20 23:12:02 -05005037# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05005038# 0 = HBA Heartbeat disabled
5039# 1 = HBA Heartbeat enabled (default)
5040# Value range is [0,1]. Default value is 1.
5041*/
James Smarteb7a3392010-11-20 23:12:02 -05005042LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05005043
James Smart83108bd2008-01-11 01:53:09 -05005044/*
James Smart1ba981f2014-02-20 09:56:45 -05005045# lpfc_EnableXLane: Enable Express Lane Feature
5046# 0x0 Express Lane Feature disabled
5047# 0x1 Express Lane Feature enabled
5048# Value range is [0,1]. Default value is 0.
5049*/
5050LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5051
5052/*
5053# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5054# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5055# Value range is [0x0,0x7f]. Default value is 0
5056*/
James Smart28d7f3d2014-05-21 08:05:28 -04005057LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05005058
5059/*
James Smart81301a92008-12-04 22:39:46 -05005060# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5061# 0 = BlockGuard disabled (default)
5062# 1 = BlockGuard enabled
5063# Value range is [0,1]. Default value is 0.
5064*/
5065LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5066
James Smart6fb120a2009-05-22 14:52:59 -04005067/*
James Smartba20c852012-08-03 12:36:52 -04005068# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5069# 0 = disabled (default)
5070# 1 = enabled
5071# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04005072#
5073# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04005074*/
5075unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5076
James Smartba20c852012-08-03 12:36:52 -04005077/*
James Smart81301a92008-12-04 22:39:46 -05005078# lpfc_prot_mask: i
5079# - Bit mask of host protection capabilities used to register with the
5080# SCSI mid-layer
5081# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5082# - Allows you to ultimately specify which profiles to use
5083# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005084# - SHOST_DIF_TYPE1_PROTECTION 1
5085# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5086# - SHOST_DIX_TYPE0_PROTECTION 8
5087# HBA supports DIX Type 0: Host to HBA protection only
5088# - SHOST_DIX_TYPE1_PROTECTION 16
5089# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005090#
5091*/
James Smartb3b98b72016-10-13 15:06:06 -07005092LPFC_ATTR(prot_mask,
5093 (SHOST_DIF_TYPE1_PROTECTION |
5094 SHOST_DIX_TYPE0_PROTECTION |
5095 SHOST_DIX_TYPE1_PROTECTION),
5096 0,
5097 (SHOST_DIF_TYPE1_PROTECTION |
5098 SHOST_DIX_TYPE0_PROTECTION |
5099 SHOST_DIX_TYPE1_PROTECTION),
5100 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005101
5102/*
5103# lpfc_prot_guard: i
5104# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005105# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005106# - Allows you to ultimately specify which profiles to use
5107# - Default will result in registering capabilities for all guard types
5108#
5109*/
James Smartb3b98b72016-10-13 15:06:06 -07005110LPFC_ATTR(prot_guard,
5111 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5112 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005113
James Smart92494142011-02-16 12:39:44 -05005114/*
5115 * Delay initial NPort discovery when Clean Address bit is cleared in
5116 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5117 * This parameter can have value 0 or 1.
5118 * When this parameter is set to 0, no delay is added to the initial
5119 * discovery.
5120 * When this parameter is set to non-zero value, initial Nport discovery is
5121 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5122 * accept and FCID/Fabric name/Fabric portname is changed.
5123 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5124 * when Clean Address bit is cleared in FLOGI/FDISC
5125 * accept and FCID/Fabric name/Fabric portname is changed.
5126 * Default value is 0.
5127 */
James Smart8eb8b962016-07-06 12:36:08 -07005128LPFC_ATTR(delay_discovery, 0, 0, 1,
5129 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005130
5131/*
James Smart3621a712009-04-06 18:47:14 -04005132 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005133 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005134 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5135 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005136 * Because of the additional overhead involved in setting up T10-DIF,
5137 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5138 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005139 */
5140LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5141 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5142
James Smart96f70772013-04-17 20:16:15 -04005143/*
James Smart7bdedb32016-07-06 12:36:00 -07005144 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5145 * 0 = MDS Diagnostics disabled (default)
5146 * 1 = MDS Diagnostics enabled
5147 * Value range is [0,1]. Default value is 0.
5148 */
5149LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5150
James Smart44fd7fe2017-08-23 16:55:47 -07005151/*
5152 * lpfc_enable_bbcr: Enable BB Credit Recovery
5153 * 0 = BB Credit Recovery disabled
5154 * 1 = BB Credit Recovery enabled (default)
5155 * Value range is [0,1]. Default value is 1.
5156 */
5157LPFC_BBCR_ATTR_RW(enable_bbcr, 1, 0, 1, "Enable BBC Recovery");
5158
Tony Jonesee959b02008-02-22 00:13:36 +01005159struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005160 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005161 &dev_attr_bg_info,
5162 &dev_attr_bg_guard_err,
5163 &dev_attr_bg_apptag_err,
5164 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005165 &dev_attr_info,
5166 &dev_attr_serialnum,
5167 &dev_attr_modeldesc,
5168 &dev_attr_modelname,
5169 &dev_attr_programtype,
5170 &dev_attr_portnum,
5171 &dev_attr_fwrev,
5172 &dev_attr_hdw,
5173 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005174 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005175 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005176 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005177 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005178 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005179 &dev_attr_lpfc_temp_sensor,
5180 &dev_attr_lpfc_log_verbose,
5181 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005182 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005183 &dev_attr_lpfc_hba_queue_depth,
5184 &dev_attr_lpfc_peer_port_login,
5185 &dev_attr_lpfc_nodev_tmo,
5186 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005187 &dev_attr_lpfc_enable_fc4_type,
5188 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005189 &dev_attr_lpfc_fcp_class,
5190 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005191 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005192 &dev_attr_lpfc_ack0,
5193 &dev_attr_lpfc_topology,
5194 &dev_attr_lpfc_scan_down,
5195 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005196 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005197 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005198 &dev_attr_lpfc_cr_delay,
5199 &dev_attr_lpfc_cr_count,
5200 &dev_attr_lpfc_multi_ring_support,
5201 &dev_attr_lpfc_multi_ring_rctl,
5202 &dev_attr_lpfc_multi_ring_type,
5203 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005204 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005205 &dev_attr_lpfc_max_luns,
5206 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005207 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005208 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005209 &dev_attr_nport_evt_cnt,
5210 &dev_attr_board_mode,
5211 &dev_attr_max_vpi,
5212 &dev_attr_used_vpi,
5213 &dev_attr_max_rpi,
5214 &dev_attr_used_rpi,
5215 &dev_attr_max_xri,
5216 &dev_attr_used_xri,
5217 &dev_attr_npiv_info,
5218 &dev_attr_issue_reset,
5219 &dev_attr_lpfc_poll,
5220 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005221 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005222 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005223 &dev_attr_lpfc_nvme_oas,
James Smart0cf07f842017-06-01 21:07:10 -07005224 &dev_attr_lpfc_auto_imax,
James Smartda0436e2009-05-22 14:51:39 -04005225 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005226 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005227 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005228 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005229 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005230 &dev_attr_lpfc_nvmet_mrq,
James Smart895427b2017-02-12 13:52:30 -08005231 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005232 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005233 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005234 &dev_attr_lpfc_soft_wwnn,
5235 &dev_attr_lpfc_soft_wwpn,
5236 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005237 &dev_attr_lpfc_enable_hba_reset,
5238 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005239 &dev_attr_lpfc_EnableXLane,
5240 &dev_attr_lpfc_XLanePriority,
5241 &dev_attr_lpfc_xlane_lun,
5242 &dev_attr_lpfc_xlane_tgt,
5243 &dev_attr_lpfc_xlane_vpt,
5244 &dev_attr_lpfc_xlane_lun_state,
5245 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005246 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005247 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005248 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005249 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005250 &dev_attr_lpfc_aer_support,
5251 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005252 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005253 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005254 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005255 &dev_attr_lpfc_iocb_cnt,
5256 &dev_attr_iocb_hw,
5257 &dev_attr_txq_hw,
5258 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005259 &dev_attr_lpfc_fips_level,
5260 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005261 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005262 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005263 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005264 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005265 &dev_attr_lpfc_enable_mds_diags,
James Smart44fd7fe2017-08-23 16:55:47 -07005266 &dev_attr_lpfc_enable_bbcr,
dea31012005-04-17 16:05:31 -05005267 NULL,
5268};
5269
Tony Jonesee959b02008-02-22 00:13:36 +01005270struct device_attribute *lpfc_vport_attrs[] = {
5271 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005272 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005273 &dev_attr_num_discovered_ports,
5274 &dev_attr_lpfc_drvr_version,
5275 &dev_attr_lpfc_log_verbose,
5276 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005277 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005278 &dev_attr_lpfc_nodev_tmo,
5279 &dev_attr_lpfc_devloss_tmo,
5280 &dev_attr_lpfc_hba_queue_depth,
5281 &dev_attr_lpfc_peer_port_login,
5282 &dev_attr_lpfc_restrict_login,
5283 &dev_attr_lpfc_fcp_class,
5284 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005285 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005286 &dev_attr_lpfc_max_luns,
5287 &dev_attr_nport_evt_cnt,
5288 &dev_attr_npiv_info,
5289 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005290 &dev_attr_lpfc_max_scsicmpl_time,
5291 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005292 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005293 &dev_attr_lpfc_fips_level,
5294 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005295 NULL,
5296};
5297
James Smarte59058c2008-08-24 21:49:00 -04005298/**
James Smart3621a712009-04-06 18:47:14 -04005299 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005300 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005301 * @kobj: kernel kobject that contains the kernel class device.
5302 * @bin_attr: kernel attributes passed to us.
5303 * @buf: contains the data to be written to the adapter IOREG space.
5304 * @off: offset into buffer to beginning of data.
5305 * @count: bytes to transfer.
5306 *
5307 * Description:
5308 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5309 * Uses the adapter io control registers to send buf contents to the adapter.
5310 *
5311 * Returns:
5312 * -ERANGE off and count combo out of range
5313 * -EINVAL off, count or buff address invalid
5314 * -EPERM adapter is offline
5315 * value of count, buf contents written
5316 **/
dea31012005-04-17 16:05:31 -05005317static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005318sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5319 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005320 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005321{
5322 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005323 struct device *dev = container_of(kobj, struct device, kobj);
5324 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5326 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005327
James Smartf1126682009-06-10 17:22:44 -04005328 if (phba->sli_rev >= LPFC_SLI_REV4)
5329 return -EPERM;
5330
dea31012005-04-17 16:05:31 -05005331 if ((off + count) > FF_REG_AREA_SIZE)
5332 return -ERANGE;
5333
James Smartf7a919b2011-08-21 21:49:16 -04005334 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5335 return 0;
dea31012005-04-17 16:05:31 -05005336
5337 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5338 return -EINVAL;
5339
James Smartf7a919b2011-08-21 21:49:16 -04005340 /* This is to protect HBA registers from accidental writes. */
5341 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5342 return -EINVAL;
5343
5344 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005345 return -EPERM;
dea31012005-04-17 16:05:31 -05005346
James Smart2e0fef82007-06-17 19:56:36 -05005347 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005348 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5349 buf_off += sizeof(uint32_t))
5350 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005351 phba->ctrl_regs_memmap_p + off + buf_off);
5352
James Smart2e0fef82007-06-17 19:56:36 -05005353 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005354
5355 return count;
5356}
5357
James Smarte59058c2008-08-24 21:49:00 -04005358/**
James Smart3621a712009-04-06 18:47:14 -04005359 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005360 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005361 * @kobj: kernel kobject that contains the kernel class device.
5362 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005363 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005364 * @off: offset into buffer to beginning of data.
5365 * @count: bytes to transfer.
5366 *
5367 * Description:
5368 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5369 * Uses the adapter io control registers to read data into buf.
5370 *
5371 * Returns:
5372 * -ERANGE off and count combo out of range
5373 * -EINVAL off, count or buff address invalid
5374 * value of count, buf contents read
5375 **/
dea31012005-04-17 16:05:31 -05005376static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005377sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5378 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005379 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005380{
5381 size_t buf_off;
5382 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005383 struct device *dev = container_of(kobj, struct device, kobj);
5384 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005385 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5386 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005387
James Smartf1126682009-06-10 17:22:44 -04005388 if (phba->sli_rev >= LPFC_SLI_REV4)
5389 return -EPERM;
5390
dea31012005-04-17 16:05:31 -05005391 if (off > FF_REG_AREA_SIZE)
5392 return -ERANGE;
5393
5394 if ((off + count) > FF_REG_AREA_SIZE)
5395 count = FF_REG_AREA_SIZE - off;
5396
5397 if (count == 0) return 0;
5398
5399 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5400 return -EINVAL;
5401
James Smart2e0fef82007-06-17 19:56:36 -05005402 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005403
5404 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5405 tmp_ptr = (uint32_t *)(buf + buf_off);
5406 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5407 }
5408
James Smart2e0fef82007-06-17 19:56:36 -05005409 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005410
5411 return count;
5412}
5413
5414static struct bin_attribute sysfs_ctlreg_attr = {
5415 .attr = {
5416 .name = "ctlreg",
5417 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005418 },
5419 .size = 256,
5420 .read = sysfs_ctlreg_read,
5421 .write = sysfs_ctlreg_write,
5422};
5423
James Smarte59058c2008-08-24 21:49:00 -04005424/**
James Smart3621a712009-04-06 18:47:14 -04005425 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005426 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005427 * @kobj: kernel kobject that contains the kernel class device.
5428 * @bin_attr: kernel attributes passed to us.
5429 * @buf: contains the data to be written to sysfs mbox.
5430 * @off: offset into buffer to beginning of data.
5431 * @count: bytes to transfer.
5432 *
5433 * Description:
James Smart026abb82011-12-13 13:20:45 -05005434 * Deprecated function. All mailbox access from user space is performed via the
5435 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005436 *
5437 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005438 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005439 **/
dea31012005-04-17 16:05:31 -05005440static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005441sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5442 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005443 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005444{
James Smart026abb82011-12-13 13:20:45 -05005445 return -EPERM;
dea31012005-04-17 16:05:31 -05005446}
5447
James Smarte59058c2008-08-24 21:49:00 -04005448/**
James Smart3621a712009-04-06 18:47:14 -04005449 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005450 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005451 * @kobj: kernel kobject that contains the kernel class device.
5452 * @bin_attr: kernel attributes passed to us.
5453 * @buf: contains the data to be read from sysfs mbox.
5454 * @off: offset into buffer to beginning of data.
5455 * @count: bytes to transfer.
5456 *
5457 * Description:
James Smart026abb82011-12-13 13:20:45 -05005458 * Deprecated function. All mailbox access from user space is performed via the
5459 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005460 *
5461 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005462 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005463 **/
dea31012005-04-17 16:05:31 -05005464static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005465sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5466 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005467 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005468{
James Smart026abb82011-12-13 13:20:45 -05005469 return -EPERM;
dea31012005-04-17 16:05:31 -05005470}
5471
5472static struct bin_attribute sysfs_mbox_attr = {
5473 .attr = {
5474 .name = "mbox",
5475 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005476 },
James Smartc0c11512011-05-24 11:41:34 -04005477 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005478 .read = sysfs_mbox_read,
5479 .write = sysfs_mbox_write,
5480};
5481
James Smarte59058c2008-08-24 21:49:00 -04005482/**
James Smart3621a712009-04-06 18:47:14 -04005483 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005484 * @vport: address of lpfc vport structure.
5485 *
5486 * Return codes:
5487 * zero on success
5488 * error return code from sysfs_create_bin_file()
5489 **/
dea31012005-04-17 16:05:31 -05005490int
James Smart2e0fef82007-06-17 19:56:36 -05005491lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005492{
James Smart2e0fef82007-06-17 19:56:36 -05005493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005494 int error;
5495
Tony Jonesee959b02008-02-22 00:13:36 +01005496 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005497 &sysfs_drvr_stat_data_attr);
5498
5499 /* Virtual ports do not need ctrl_reg and mbox */
5500 if (error || vport->port_type == LPFC_NPIV_PORT)
5501 goto out;
5502
5503 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005504 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005505 if (error)
James Smarteada2722008-12-04 22:39:13 -05005506 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005507
Tony Jonesee959b02008-02-22 00:13:36 +01005508 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005509 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005510 if (error)
5511 goto out_remove_ctlreg_attr;
5512
5513 return 0;
5514out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005515 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005516out_remove_stat_attr:
5517 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5518 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005519out:
5520 return error;
5521}
5522
James Smarte59058c2008-08-24 21:49:00 -04005523/**
James Smart3621a712009-04-06 18:47:14 -04005524 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005525 * @vport: address of lpfc vport structure.
5526 **/
dea31012005-04-17 16:05:31 -05005527void
James Smart2e0fef82007-06-17 19:56:36 -05005528lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005529{
James Smart2e0fef82007-06-17 19:56:36 -05005530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005531 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5532 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005533 /* Virtual ports do not need ctrl_reg and mbox */
5534 if (vport->port_type == LPFC_NPIV_PORT)
5535 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005536 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5537 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005538}
5539
dea31012005-04-17 16:05:31 -05005540/*
5541 * Dynamic FC Host Attributes Support
5542 */
5543
James Smarte59058c2008-08-24 21:49:00 -04005544/**
James Smart6c9231f2016-12-19 15:07:24 -08005545 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5546 * @shost: kernel scsi host pointer.
5547 **/
5548static void
5549lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5550{
5551 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5552
5553 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5554 sizeof fc_host_symbolic_name(shost));
5555}
5556
5557/**
James Smart3621a712009-04-06 18:47:14 -04005558 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005559 * @shost: kernel scsi host pointer.
5560 **/
dea31012005-04-17 16:05:31 -05005561static void
5562lpfc_get_host_port_id(struct Scsi_Host *shost)
5563{
James Smart2e0fef82007-06-17 19:56:36 -05005564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5565
dea31012005-04-17 16:05:31 -05005566 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005567 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005568}
5569
James Smarte59058c2008-08-24 21:49:00 -04005570/**
James Smart3621a712009-04-06 18:47:14 -04005571 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005572 * @shost: kernel scsi host pointer.
5573 **/
dea31012005-04-17 16:05:31 -05005574static void
5575lpfc_get_host_port_type(struct Scsi_Host *shost)
5576{
James Smart2e0fef82007-06-17 19:56:36 -05005577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5578 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005579
5580 spin_lock_irq(shost->host_lock);
5581
James Smart92d7f7b2007-06-17 19:56:38 -05005582 if (vport->port_type == LPFC_NPIV_PORT) {
5583 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5584 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005585 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005586 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005587 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5588 else
5589 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5590 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005591 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005592 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5593 else
5594 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5595 }
5596 } else
5597 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5598
5599 spin_unlock_irq(shost->host_lock);
5600}
5601
James Smarte59058c2008-08-24 21:49:00 -04005602/**
James Smart3621a712009-04-06 18:47:14 -04005603 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005604 * @shost: kernel scsi host pointer.
5605 **/
dea31012005-04-17 16:05:31 -05005606static void
5607lpfc_get_host_port_state(struct Scsi_Host *shost)
5608{
James Smart2e0fef82007-06-17 19:56:36 -05005609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5610 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005611
5612 spin_lock_irq(shost->host_lock);
5613
James Smart2e0fef82007-06-17 19:56:36 -05005614 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005615 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5616 else {
James Smart2e0fef82007-06-17 19:56:36 -05005617 switch (phba->link_state) {
5618 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005619 case LPFC_LINK_DOWN:
5620 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5621 break;
5622 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005623 case LPFC_CLEAR_LA:
5624 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005625 /* Links up, reports port state accordingly */
5626 if (vport->port_state < LPFC_VPORT_READY)
5627 fc_host_port_state(shost) =
5628 FC_PORTSTATE_BYPASSED;
5629 else
5630 fc_host_port_state(shost) =
5631 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005632 break;
5633 case LPFC_HBA_ERROR:
5634 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5635 break;
5636 default:
5637 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5638 break;
5639 }
5640 }
5641
5642 spin_unlock_irq(shost->host_lock);
5643}
5644
James Smarte59058c2008-08-24 21:49:00 -04005645/**
James Smart3621a712009-04-06 18:47:14 -04005646 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005647 * @shost: kernel scsi host pointer.
5648 **/
dea31012005-04-17 16:05:31 -05005649static void
5650lpfc_get_host_speed(struct Scsi_Host *shost)
5651{
James Smart2e0fef82007-06-17 19:56:36 -05005652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5653 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005654
5655 spin_lock_irq(shost->host_lock);
5656
James Smarta085e872015-12-16 18:12:02 -05005657 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005658 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005659 case LPFC_LINK_SPEED_1GHZ:
5660 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005661 break;
James Smart76a95d72010-11-20 23:11:48 -05005662 case LPFC_LINK_SPEED_2GHZ:
5663 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005664 break;
James Smart76a95d72010-11-20 23:11:48 -05005665 case LPFC_LINK_SPEED_4GHZ:
5666 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005667 break;
James Smart76a95d72010-11-20 23:11:48 -05005668 case LPFC_LINK_SPEED_8GHZ:
5669 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005670 break;
James Smart76a95d72010-11-20 23:11:48 -05005671 case LPFC_LINK_SPEED_10GHZ:
5672 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005673 break;
James Smart76a95d72010-11-20 23:11:48 -05005674 case LPFC_LINK_SPEED_16GHZ:
5675 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5676 break;
James Smartd38dd522015-08-31 16:48:17 -04005677 case LPFC_LINK_SPEED_32GHZ:
5678 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5679 break;
James Smart76a95d72010-11-20 23:11:48 -05005680 default:
5681 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005682 break;
5683 }
James Smart09372822008-01-11 01:52:54 -05005684 } else
5685 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005686
5687 spin_unlock_irq(shost->host_lock);
5688}
5689
James Smarte59058c2008-08-24 21:49:00 -04005690/**
James Smart3621a712009-04-06 18:47:14 -04005691 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005692 * @shost: kernel scsi host pointer.
5693 **/
dea31012005-04-17 16:05:31 -05005694static void
5695lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5696{
James Smart2e0fef82007-06-17 19:56:36 -05005697 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5698 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005699 u64 node_name;
dea31012005-04-17 16:05:31 -05005700
5701 spin_lock_irq(shost->host_lock);
5702
James Smart73d91e52011-10-10 21:32:10 -04005703 if ((vport->port_state > LPFC_FLOGI) &&
5704 ((vport->fc_flag & FC_FABRIC) ||
5705 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5706 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005707 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005708 else
5709 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005710 node_name = 0;
dea31012005-04-17 16:05:31 -05005711
5712 spin_unlock_irq(shost->host_lock);
5713
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005714 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005715}
5716
James Smarte59058c2008-08-24 21:49:00 -04005717/**
James Smart3621a712009-04-06 18:47:14 -04005718 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005719 * @shost: kernel scsi host pointer.
5720 *
5721 * Notes:
5722 * NULL on error for link down, no mbox pool, sli2 active,
5723 * management not allowed, memory allocation error, or mbox error.
5724 *
5725 * Returns:
5726 * NULL for error
5727 * address of the adapter host statistics
5728 **/
dea31012005-04-17 16:05:31 -05005729static struct fc_host_statistics *
5730lpfc_get_stats(struct Scsi_Host *shost)
5731{
James Smart2e0fef82007-06-17 19:56:36 -05005732 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5733 struct lpfc_hba *phba = vport->phba;
5734 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005735 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005736 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005737 LPFC_MBOXQ_t *pmboxq;
5738 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005739 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005740 int rc = 0;
dea31012005-04-17 16:05:31 -05005741
James Smart92d7f7b2007-06-17 19:56:38 -05005742 /*
5743 * prevent udev from issuing mailbox commands until the port is
5744 * configured.
5745 */
James Smart2e0fef82007-06-17 19:56:36 -05005746 if (phba->link_state < LPFC_LINK_DOWN ||
5747 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005748 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005749 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005750
5751 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005752 return NULL;
5753
dea31012005-04-17 16:05:31 -05005754 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5755 if (!pmboxq)
5756 return NULL;
5757 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5758
James Smart04c68492009-05-22 14:52:52 -04005759 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005760 pmb->mbxCommand = MBX_READ_STATUS;
5761 pmb->mbxOwner = OWN_HOST;
5762 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005763 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005764
James Smart75baf692010-06-08 18:31:21 -04005765 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005766 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005767 else
dea31012005-04-17 16:05:31 -05005768 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5769
5770 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005771 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005772 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005773 return NULL;
5774 }
5775
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005776 memset(hs, 0, sizeof (struct fc_host_statistics));
5777
dea31012005-04-17 16:05:31 -05005778 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005779 /*
5780 * The MBX_READ_STATUS returns tx_k_bytes which has to
5781 * converted to words
5782 */
5783 hs->tx_words = (uint64_t)
5784 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5785 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005786 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005787 hs->rx_words = (uint64_t)
5788 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5789 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005790
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005791 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005792 pmb->mbxCommand = MBX_READ_LNK_STAT;
5793 pmb->mbxOwner = OWN_HOST;
5794 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005795 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005796
James Smart75baf692010-06-08 18:31:21 -04005797 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005798 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005799 else
dea31012005-04-17 16:05:31 -05005800 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5801
5802 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005803 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005804 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005805 return NULL;
5806 }
5807
5808 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5809 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5810 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5811 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5812 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5813 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5814 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5815
James Smart64ba8812006-08-02 15:24:34 -04005816 hs->link_failure_count -= lso->link_failure_count;
5817 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5818 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5819 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5820 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5821 hs->invalid_crc_count -= lso->invalid_crc_count;
5822 hs->error_frames -= lso->error_frames;
5823
James Smart76a95d72010-11-20 23:11:48 -05005824 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005825 hs->lip_count = -1;
5826 hs->nos_count = (phba->link_events >> 1);
5827 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005828 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005829 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005830 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005831 hs->nos_count = -1;
5832 } else {
5833 hs->lip_count = -1;
5834 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005835 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005836 }
5837
5838 hs->dumped_frames = -1;
5839
James Smart64ba8812006-08-02 15:24:34 -04005840 seconds = get_seconds();
5841 if (seconds < psli->stats_start)
5842 hs->seconds_since_last_reset = seconds +
5843 ((unsigned long)-1 - psli->stats_start);
5844 else
5845 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005846
James Smart1dcb58e2007-04-25 09:51:30 -04005847 mempool_free(pmboxq, phba->mbox_mem_pool);
5848
dea31012005-04-17 16:05:31 -05005849 return hs;
5850}
5851
James Smarte59058c2008-08-24 21:49:00 -04005852/**
James Smart3621a712009-04-06 18:47:14 -04005853 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005854 * @shost: kernel scsi host pointer.
5855 **/
James Smart64ba8812006-08-02 15:24:34 -04005856static void
5857lpfc_reset_stats(struct Scsi_Host *shost)
5858{
James Smart2e0fef82007-06-17 19:56:36 -05005859 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5860 struct lpfc_hba *phba = vport->phba;
5861 struct lpfc_sli *psli = &phba->sli;
5862 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005863 LPFC_MBOXQ_t *pmboxq;
5864 MAILBOX_t *pmb;
5865 int rc = 0;
5866
James Smart2e0fef82007-06-17 19:56:36 -05005867 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005868 return;
5869
James Smart64ba8812006-08-02 15:24:34 -04005870 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5871 if (!pmboxq)
5872 return;
5873 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5874
James Smart04c68492009-05-22 14:52:52 -04005875 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005876 pmb->mbxCommand = MBX_READ_STATUS;
5877 pmb->mbxOwner = OWN_HOST;
5878 pmb->un.varWords[0] = 0x1; /* reset request */
5879 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005880 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005881
James Smart2e0fef82007-06-17 19:56:36 -05005882 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005883 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005884 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5885 else
5886 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5887
5888 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005889 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005890 mempool_free(pmboxq, phba->mbox_mem_pool);
5891 return;
5892 }
5893
5894 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5895 pmb->mbxCommand = MBX_READ_LNK_STAT;
5896 pmb->mbxOwner = OWN_HOST;
5897 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005898 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005899
James Smart2e0fef82007-06-17 19:56:36 -05005900 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005901 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005902 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5903 else
5904 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5905
5906 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005907 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005908 mempool_free( pmboxq, phba->mbox_mem_pool);
5909 return;
5910 }
5911
5912 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5913 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5914 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5915 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5916 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5917 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5918 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005919 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005920 lso->link_events = (phba->link_events >> 1);
5921 else
5922 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005923
5924 psli->stats_start = get_seconds();
5925
James Smart1dcb58e2007-04-25 09:51:30 -04005926 mempool_free(pmboxq, phba->mbox_mem_pool);
5927
James Smart64ba8812006-08-02 15:24:34 -04005928 return;
5929}
dea31012005-04-17 16:05:31 -05005930
5931/*
5932 * The LPFC driver treats linkdown handling as target loss events so there
5933 * are no sysfs handlers for link_down_tmo.
5934 */
James Smart685f0bf2007-04-25 09:53:08 -04005935
James Smarte59058c2008-08-24 21:49:00 -04005936/**
James Smart3621a712009-04-06 18:47:14 -04005937 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005938 * @starget: kernel scsi target pointer.
5939 *
5940 * Returns:
5941 * address of the node list if found
5942 * NULL target not found
5943 **/
James Smart685f0bf2007-04-25 09:53:08 -04005944static struct lpfc_nodelist *
5945lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005946{
James Smart2e0fef82007-06-17 19:56:36 -05005947 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5948 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005949 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005950
5951 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005952 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005953 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005954 if (NLP_CHK_NODE_ACT(ndlp) &&
5955 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005956 starget->id == ndlp->nlp_sid) {
5957 spin_unlock_irq(shost->host_lock);
5958 return ndlp;
dea31012005-04-17 16:05:31 -05005959 }
5960 }
5961 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005962 return NULL;
5963}
dea31012005-04-17 16:05:31 -05005964
James Smarte59058c2008-08-24 21:49:00 -04005965/**
James Smart3621a712009-04-06 18:47:14 -04005966 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005967 * @starget: kernel scsi target pointer.
5968 **/
James Smart685f0bf2007-04-25 09:53:08 -04005969static void
5970lpfc_get_starget_port_id(struct scsi_target *starget)
5971{
5972 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5973
5974 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005975}
5976
James Smarte59058c2008-08-24 21:49:00 -04005977/**
James Smart3621a712009-04-06 18:47:14 -04005978 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005979 * @starget: kernel scsi target pointer.
5980 *
5981 * Description: Set the target node name to the ndlp node name wwn or zero.
5982 **/
dea31012005-04-17 16:05:31 -05005983static void
5984lpfc_get_starget_node_name(struct scsi_target *starget)
5985{
James Smart685f0bf2007-04-25 09:53:08 -04005986 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005987
James Smart685f0bf2007-04-25 09:53:08 -04005988 fc_starget_node_name(starget) =
5989 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005990}
5991
James Smarte59058c2008-08-24 21:49:00 -04005992/**
James Smart3621a712009-04-06 18:47:14 -04005993 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005994 * @starget: kernel scsi target pointer.
5995 *
5996 * Description: set the target port name to the ndlp port name wwn or zero.
5997 **/
dea31012005-04-17 16:05:31 -05005998static void
5999lpfc_get_starget_port_name(struct scsi_target *starget)
6000{
James Smart685f0bf2007-04-25 09:53:08 -04006001 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05006002
James Smart685f0bf2007-04-25 09:53:08 -04006003 fc_starget_port_name(starget) =
6004 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05006005}
6006
James Smarte59058c2008-08-24 21:49:00 -04006007/**
James Smart3621a712009-04-06 18:47:14 -04006008 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04006009 * @rport: fc rport address.
6010 * @timeout: new value for dev loss tmo.
6011 *
6012 * Description:
6013 * If timeout is non zero set the dev_loss_tmo to timeout, else set
6014 * dev_loss_tmo to one.
6015 **/
dea31012005-04-17 16:05:31 -05006016static void
dea31012005-04-17 16:05:31 -05006017lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
6018{
dea31012005-04-17 16:05:31 -05006019 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04006020 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05006021 else
James Smartc01f3202006-08-18 17:47:08 -04006022 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05006023}
6024
James Smarte59058c2008-08-24 21:49:00 -04006025/**
James Smart3621a712009-04-06 18:47:14 -04006026 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04006027 *
6028 * Description:
6029 * Macro that uses field to generate a function with the name lpfc_show_rport_
6030 *
6031 * lpfc_show_rport_##field: returns the bytes formatted in buf
6032 * @cdev: class converted to an fc_rport.
6033 * @buf: on return contains the target_field or zero.
6034 *
6035 * Returns: size of formatted string.
6036 **/
dea31012005-04-17 16:05:31 -05006037#define lpfc_rport_show_function(field, format_string, sz, cast) \
6038static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01006039lpfc_show_rport_##field (struct device *dev, \
6040 struct device_attribute *attr, \
6041 char *buf) \
dea31012005-04-17 16:05:31 -05006042{ \
Tony Jonesee959b02008-02-22 00:13:36 +01006043 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05006044 struct lpfc_rport_data *rdata = rport->hostdata; \
6045 return snprintf(buf, sz, format_string, \
6046 (rdata->target) ? cast rdata->target->field : 0); \
6047}
6048
6049#define lpfc_rport_rd_attr(field, format_string, sz) \
6050 lpfc_rport_show_function(field, format_string, sz, ) \
6051static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6052
James Smarteada2722008-12-04 22:39:13 -05006053/**
James Smart3621a712009-04-06 18:47:14 -04006054 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05006055 * @fc_vport: The fc_vport who's symbolic name has been changed.
6056 *
6057 * Description:
6058 * This function is called by the transport after the @fc_vport's symbolic name
6059 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03006060 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05006061 **/
6062static void
6063lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6064{
6065 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6066
6067 if (vport->port_state == LPFC_VPORT_READY)
6068 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6069}
dea31012005-04-17 16:05:31 -05006070
James Smartf4b4c682009-05-22 14:53:12 -04006071/**
6072 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6073 * @phba: Pointer to lpfc_hba struct.
6074 *
6075 * This function is called by the lpfc_get_cfgparam() routine to set the
6076 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02006077 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04006078 * before hba port or vport created.
6079 **/
6080static void
6081lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6082{
6083 phba->cfg_log_verbose = verbose;
6084}
6085
dea31012005-04-17 16:05:31 -05006086struct fc_function_template lpfc_transport_functions = {
6087 /* fixed attributes the driver supports */
6088 .show_host_node_name = 1,
6089 .show_host_port_name = 1,
6090 .show_host_supported_classes = 1,
6091 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006092 .show_host_supported_speeds = 1,
6093 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006094
6095 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006096 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006097
6098 /* dynamic attributes the driver supports */
6099 .get_host_port_id = lpfc_get_host_port_id,
6100 .show_host_port_id = 1,
6101
6102 .get_host_port_type = lpfc_get_host_port_type,
6103 .show_host_port_type = 1,
6104
6105 .get_host_port_state = lpfc_get_host_port_state,
6106 .show_host_port_state = 1,
6107
6108 /* active_fc4s is shown but doesn't change (thus no get function) */
6109 .show_host_active_fc4s = 1,
6110
6111 .get_host_speed = lpfc_get_host_speed,
6112 .show_host_speed = 1,
6113
6114 .get_host_fabric_name = lpfc_get_host_fabric_name,
6115 .show_host_fabric_name = 1,
6116
6117 /*
6118 * The LPFC driver treats linkdown handling as target loss events
6119 * so there are no sysfs handlers for link_down_tmo.
6120 */
6121
6122 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006123 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006124
6125 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6126 .show_rport_maxframe_size = 1,
6127 .show_rport_supported_classes = 1,
6128
dea31012005-04-17 16:05:31 -05006129 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6130 .show_rport_dev_loss_tmo = 1,
6131
6132 .get_starget_port_id = lpfc_get_starget_port_id,
6133 .show_starget_port_id = 1,
6134
6135 .get_starget_node_name = lpfc_get_starget_node_name,
6136 .show_starget_node_name = 1,
6137
6138 .get_starget_port_name = lpfc_get_starget_port_name,
6139 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006140
6141 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006142 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6143 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006144
James Smart92d7f7b2007-06-17 19:56:38 -05006145 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006146
6147 .vport_disable = lpfc_vport_disable,
6148
6149 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006150
6151 .bsg_request = lpfc_bsg_request,
6152 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006153};
6154
James Smart98c9ea52007-10-27 13:37:33 -04006155struct fc_function_template lpfc_vport_transport_functions = {
6156 /* fixed attributes the driver supports */
6157 .show_host_node_name = 1,
6158 .show_host_port_name = 1,
6159 .show_host_supported_classes = 1,
6160 .show_host_supported_fc4s = 1,
6161 .show_host_supported_speeds = 1,
6162 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006163
6164 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006165 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006166
6167 /* dynamic attributes the driver supports */
6168 .get_host_port_id = lpfc_get_host_port_id,
6169 .show_host_port_id = 1,
6170
6171 .get_host_port_type = lpfc_get_host_port_type,
6172 .show_host_port_type = 1,
6173
6174 .get_host_port_state = lpfc_get_host_port_state,
6175 .show_host_port_state = 1,
6176
6177 /* active_fc4s is shown but doesn't change (thus no get function) */
6178 .show_host_active_fc4s = 1,
6179
6180 .get_host_speed = lpfc_get_host_speed,
6181 .show_host_speed = 1,
6182
6183 .get_host_fabric_name = lpfc_get_host_fabric_name,
6184 .show_host_fabric_name = 1,
6185
6186 /*
6187 * The LPFC driver treats linkdown handling as target loss events
6188 * so there are no sysfs handlers for link_down_tmo.
6189 */
6190
6191 .get_fc_host_stats = lpfc_get_stats,
6192 .reset_fc_host_stats = lpfc_reset_stats,
6193
6194 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6195 .show_rport_maxframe_size = 1,
6196 .show_rport_supported_classes = 1,
6197
6198 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6199 .show_rport_dev_loss_tmo = 1,
6200
6201 .get_starget_port_id = lpfc_get_starget_port_id,
6202 .show_starget_port_id = 1,
6203
6204 .get_starget_node_name = lpfc_get_starget_node_name,
6205 .show_starget_node_name = 1,
6206
6207 .get_starget_port_name = lpfc_get_starget_port_name,
6208 .show_starget_port_name = 1,
6209
6210 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6211 .terminate_rport_io = lpfc_terminate_rport_io,
6212
6213 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006214
6215 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006216};
6217
James Smarte59058c2008-08-24 21:49:00 -04006218/**
James Smart3621a712009-04-06 18:47:14 -04006219 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006220 * @phba: lpfc_hba pointer.
6221 **/
dea31012005-04-17 16:05:31 -05006222void
6223lpfc_get_cfgparam(struct lpfc_hba *phba)
6224{
James Smart49aa1432012-08-03 12:36:42 -04006225 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006226 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006227 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6228 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006229 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006230 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6231 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006232 lpfc_ack0_init(phba, lpfc_ack0);
6233 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006234 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006235 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006236 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006237 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006238 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006239 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006240 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6241 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006242 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006243 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smart0cf07f842017-06-01 21:07:10 -07006244 lpfc_auto_imax_init(phba, lpfc_auto_imax);
James Smartda0436e2009-05-22 14:51:39 -04006245 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006246 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006247 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6248 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006249
James Smart1ba981f2014-02-20 09:56:45 -05006250 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6251 if (phba->sli_rev != LPFC_SLI_REV4)
6252 phba->cfg_EnableXLane = 0;
6253 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006254
James Smart1ba981f2014-02-20 09:56:45 -05006255 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6256 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6257 phba->cfg_oas_lun_state = 0;
6258 phba->cfg_oas_lun_status = 0;
6259 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006260 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006261 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006262 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6263 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006264 if (phba->sli_rev == LPFC_SLI_REV4)
6265 phba->cfg_poll = 0;
6266 else
James Smart1ba981f2014-02-20 09:56:45 -05006267 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006268 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006269
James Smart895427b2017-02-12 13:52:30 -08006270 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006271 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
James Smart895427b2017-02-12 13:52:30 -08006272
6273 /* Initialize first burst. Target vs Initiator are different. */
6274 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006275 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006276 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6277 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
James Smart44fd7fe2017-08-23 16:55:47 -07006278 lpfc_enable_bbcr_init(phba, lpfc_enable_bbcr);
James Smart895427b2017-02-12 13:52:30 -08006279
6280 if (phba->sli_rev != LPFC_SLI_REV4) {
6281 /* NVME only supported on SLI4 */
6282 phba->nvmet_support = 0;
6283 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
James Smart44fd7fe2017-08-23 16:55:47 -07006284 phba->cfg_enable_bbcr = 0;
James Smart895427b2017-02-12 13:52:30 -08006285 } else {
6286 /* We MUST have FCP support */
6287 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6288 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6289 }
6290
James Smart0cf07f842017-06-01 21:07:10 -07006291 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6292 phba->cfg_auto_imax = 0;
6293 phba->initial_imax = phba->cfg_fcp_imax;
6294
James Smart895427b2017-02-12 13:52:30 -08006295 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006296 if (phba->cfg_fcp_io_channel == 0)
6297 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006298 if (phba->cfg_nvme_io_channel == 0)
6299 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006300
6301 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6302 phba->cfg_fcp_io_channel = 0;
6303
James Smartf358dd02017-02-12 13:52:34 -08006304 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6305 phba->cfg_nvme_io_channel = 0;
6306
James Smart895427b2017-02-12 13:52:30 -08006307 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6308 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6309 else
6310 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
James Smart4258e982015-12-16 18:11:58 -05006311
James Smart352e5fd2016-12-30 06:57:47 -08006312 phba->cfg_soft_wwnn = 0L;
6313 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006314 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006315 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006316 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006317 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006318 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006319 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006320 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006321 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006322 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006323 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006324 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006325 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006326 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006327 return;
6328}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006329
James Smarte59058c2008-08-24 21:49:00 -04006330/**
James Smart895427b2017-02-12 13:52:30 -08006331 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6332 * dependencies between protocols and roles.
6333 * @phba: lpfc_hba pointer.
6334 **/
6335void
6336lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6337{
James Smart895427b2017-02-12 13:52:30 -08006338 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6339 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006340
James Smart895427b2017-02-12 13:52:30 -08006341 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6342 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6343
James Smartf358dd02017-02-12 13:52:34 -08006344 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6345 phba->nvmet_support) {
6346 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6347 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006348
6349 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6350 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6351 "NVME Target PRLI ACC enable_fb ",
6352 phba->cfg_nvme_enable_fb,
6353 phba->cfg_nvmet_fb_size,
6354 LPFC_NVMET_FB_SZ_MAX);
6355
6356 if (phba->cfg_nvme_enable_fb == 0)
6357 phba->cfg_nvmet_fb_size = 0;
6358 else {
6359 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6360 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6361 }
6362
6363 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6364 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6365 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6366 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6367 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6368 phba->cfg_nvmet_mrq);
6369 }
6370 } else {
James Smartf358dd02017-02-12 13:52:34 -08006371 /* Not NVME Target mode. Turn off Target parameters. */
6372 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006373 phba->cfg_nvmet_mrq = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006374 phba->cfg_nvmet_fb_size = 0;
6375 }
James Smartf358dd02017-02-12 13:52:34 -08006376
James Smart895427b2017-02-12 13:52:30 -08006377 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6378 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6379 else
6380 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6381}
6382
6383/**
James Smart3621a712009-04-06 18:47:14 -04006384 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006385 * @vport: lpfc_vport pointer.
6386 **/
James Smart3de2a652007-08-02 11:09:59 -04006387void
6388lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6389{
James Smarte8b62012007-08-02 11:10:09 -04006390 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006391 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006392 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006393 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6394 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6395 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6396 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6397 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6398 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006399 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006400 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006401 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6402 lpfc_max_luns_init(vport, lpfc_max_luns);
6403 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006404 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006405 return;
6406}