blob: b91b4bb1062df57bdb0e83f0330a413beb1c56d5 [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 Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
Paul Gortmakeracf3368f2011-05-27 09:47:43 -040026#include <linux/module.h>
James Smart0d878412009-10-02 15:16:56 -040027#include <linux/aer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Andy Shevchenkoecc30992010-08-10 18:01:27 -070029#include <linux/kernel.h>
dea31012005-04-17 16:05:31 -050030
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050032#include <scsi/scsi_device.h>
33#include <scsi/scsi_host.h>
34#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport_fc.h>
James Smart6a9c52c2009-10-02 15:16:51 -040036#include <scsi/fc/fc_fs.h>
dea31012005-04-17 16:05:31 -050037
James Smart895427b2017-02-12 13:52:30 -080038#include <linux/nvme-fc-driver.h>
39
James Smartda0436e2009-05-22 14:51:39 -040040#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050041#include "lpfc_hw.h"
42#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040043#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040044#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050045#include "lpfc_disc.h"
dea31012005-04-17 16:05:31 -050046#include "lpfc.h"
James Smart895427b2017-02-12 13:52:30 -080047#include "lpfc_scsi.h"
48#include "lpfc_nvme.h"
dea31012005-04-17 16:05:31 -050049#include "lpfc_logmsg.h"
50#include "lpfc_version.h"
51#include "lpfc_compat.h"
52#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050053#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070054#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050055
James Smart2ea259e2017-02-12 13:52:27 -080056#define LPFC_DEF_DEVLOSS_TMO 30
57#define LPFC_MIN_DEVLOSS_TMO 1
58#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050059
James Smartf7a919b2011-08-21 21:49:16 -040060/*
61 * Write key size should be multiple of 4. If write key is changed
62 * make sure that library write key is also changed.
63 */
64#define LPFC_REG_WRITE_KEY_SIZE 4
65#define LPFC_REG_WRITE_KEY "EMLX"
66
James Smarte59058c2008-08-24 21:49:00 -040067/**
James Smart3621a712009-04-06 18:47:14 -040068 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040069 * @incr: integer to convert.
70 * @hdw: ascii string holding converted integer plus a string terminator.
71 *
72 * Description:
73 * JEDEC Joint Electron Device Engineering Council.
74 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
75 * character string. The string is then terminated with a NULL in byte 9.
76 * Hex 0-9 becomes ascii '0' to '9'.
77 * Hex a-f becomes ascii '=' to 'B' capital B.
78 *
79 * Notes:
80 * Coded for 32 bit integers only.
81 **/
dea31012005-04-17 16:05:31 -050082static void
83lpfc_jedec_to_ascii(int incr, char hdw[])
84{
85 int i, j;
86 for (i = 0; i < 8; i++) {
87 j = (incr & 0xf);
88 if (j <= 9)
89 hdw[7 - i] = 0x30 + j;
90 else
91 hdw[7 - i] = 0x61 + j - 10;
92 incr = (incr >> 4);
93 }
94 hdw[8] = 0;
95 return;
96}
97
James Smarte59058c2008-08-24 21:49:00 -040098/**
James Smart3621a712009-04-06 18:47:14 -040099 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400100 * @dev: class unused variable.
101 * @attr: device attribute, not used.
102 * @buf: on return contains the module description text.
103 *
104 * Returns: size of formatted string.
105 **/
dea31012005-04-17 16:05:31 -0500106static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100107lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
108 char *buf)
dea31012005-04-17 16:05:31 -0500109{
110 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
111}
112
James Smart45ed1192009-10-02 15:17:02 -0400113/**
114 * lpfc_enable_fip_show - Return the fip mode of the HBA
115 * @dev: class unused variable.
116 * @attr: device attribute, not used.
117 * @buf: on return contains the module description text.
118 *
119 * Returns: size of formatted string.
120 **/
121static ssize_t
122lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
123 char *buf)
124{
125 struct Scsi_Host *shost = class_to_shost(dev);
126 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
127 struct lpfc_hba *phba = vport->phba;
128
129 if (phba->hba_flag & HBA_FIP_SUPPORT)
130 return snprintf(buf, PAGE_SIZE, "1\n");
131 else
132 return snprintf(buf, PAGE_SIZE, "0\n");
133}
134
James Smart81301a92008-12-04 22:39:46 -0500135static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800136lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
137 char *buf)
138{
139 struct Scsi_Host *shost = class_to_shost(dev);
140 struct lpfc_vport *vport = shost_priv(shost);
141 struct lpfc_hba *phba = vport->phba;
142 struct nvme_fc_local_port *localport;
143 struct lpfc_nvme_lport *lport;
144 struct lpfc_nvme_rport *rport;
145 struct nvme_fc_remote_port *nrport;
146 char *statep;
147 int len = 0;
148
149 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
150 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
151 return len;
152 }
153
154 localport = vport->localport;
155 if (!localport) {
156 len = snprintf(buf, PAGE_SIZE,
157 "NVME Initiator x%llx is not allocated\n",
158 wwn_to_u64(vport->fc_portname.u.wwn));
159 return len;
160 }
161 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
162
163 spin_lock_irq(shost->host_lock);
164 lport = (struct lpfc_nvme_lport *)localport->private;
165
166 /* Port state is only one of two values for now. */
167 if (localport->port_id)
168 statep = "ONLINE";
169 else
170 statep = "UNKNOWN ";
171
172 len += snprintf(buf + len, PAGE_SIZE - len,
173 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
174 "NVME LPORT lpfc",
175 phba->brd_no,
176 wwn_to_u64(vport->fc_portname.u.wwn),
177 wwn_to_u64(vport->fc_nodename.u.wwn),
178 localport->port_id, statep);
179
180 list_for_each_entry(rport, &lport->rport_list, list) {
181 /* local short-hand pointer. */
182 nrport = rport->remoteport;
183
184 /* Port state is only one of two values for now. */
185 switch (nrport->port_state) {
186 case FC_OBJSTATE_ONLINE:
187 statep = "ONLINE";
188 break;
189 case FC_OBJSTATE_UNKNOWN:
190 statep = "UNKNOWN ";
191 break;
192 default:
193 statep = "UNSUPPORTED";
194 break;
195 }
196
197 /* Tab in to show lport ownership. */
198 len += snprintf(buf + len, PAGE_SIZE - len,
199 "NVME RPORT ");
200 if (phba->brd_no >= 10)
201 len += snprintf(buf + len, PAGE_SIZE - len, " ");
202
203 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
204 nrport->port_name);
205 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
206 nrport->node_name);
207 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
208 nrport->port_id);
209
210 switch (nrport->port_role) {
211 case FC_PORT_ROLE_NVME_INITIATOR:
212 len += snprintf(buf + len, PAGE_SIZE - len,
213 "INITIATOR ");
214 break;
215 case FC_PORT_ROLE_NVME_TARGET:
216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "TARGET ");
218 break;
219 case FC_PORT_ROLE_NVME_DISCOVERY:
220 len += snprintf(buf + len, PAGE_SIZE - len,
221 "DISCOVERY ");
222 break;
223 default:
224 len += snprintf(buf + len, PAGE_SIZE - len,
225 "UNKNOWN_ROLE x%x",
226 nrport->port_role);
227 break;
228 }
229 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
230 /* Terminate the string. */
231 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
232 }
233 spin_unlock_irq(shost->host_lock);
234
235 len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n");
236 len += snprintf(buf+len, PAGE_SIZE-len,
237 "LS: Xmt %016llx Cmpl %016llx\n",
238 phba->fc4NvmeLsRequests,
239 phba->fc4NvmeLsCmpls);
240
241 len += snprintf(buf+len, PAGE_SIZE-len,
242 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
243 phba->fc4NvmeInputRequests,
244 phba->fc4NvmeOutputRequests,
245 phba->fc4NvmeControlRequests);
246
247 len += snprintf(buf+len, PAGE_SIZE-len,
248 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
249
250 return len;
251}
252
253static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500254lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
255 char *buf)
256{
257 struct Scsi_Host *shost = class_to_shost(dev);
258 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
259 struct lpfc_hba *phba = vport->phba;
260
261 if (phba->cfg_enable_bg)
262 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
263 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
264 else
265 return snprintf(buf, PAGE_SIZE,
266 "BlockGuard Not Supported\n");
267 else
268 return snprintf(buf, PAGE_SIZE,
269 "BlockGuard Disabled\n");
270}
271
272static ssize_t
273lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
274 char *buf)
275{
276 struct Scsi_Host *shost = class_to_shost(dev);
277 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
278 struct lpfc_hba *phba = vport->phba;
279
James Smart87b5c322008-12-16 10:34:09 -0500280 return snprintf(buf, PAGE_SIZE, "%llu\n",
281 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500282}
283
284static ssize_t
285lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
286 char *buf)
287{
288 struct Scsi_Host *shost = class_to_shost(dev);
289 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
290 struct lpfc_hba *phba = vport->phba;
291
James Smart87b5c322008-12-16 10:34:09 -0500292 return snprintf(buf, PAGE_SIZE, "%llu\n",
293 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500294}
295
296static ssize_t
297lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
298 char *buf)
299{
300 struct Scsi_Host *shost = class_to_shost(dev);
301 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
302 struct lpfc_hba *phba = vport->phba;
303
James Smart87b5c322008-12-16 10:34:09 -0500304 return snprintf(buf, PAGE_SIZE, "%llu\n",
305 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500306}
307
James Smarte59058c2008-08-24 21:49:00 -0400308/**
James Smart3621a712009-04-06 18:47:14 -0400309 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400310 * @dev: class converted to a Scsi_host structure.
311 * @attr: device attribute, not used.
312 * @buf: on return contains the formatted text from lpfc_info().
313 *
314 * Returns: size of formatted string.
315 **/
dea31012005-04-17 16:05:31 -0500316static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100317lpfc_info_show(struct device *dev, struct device_attribute *attr,
318 char *buf)
dea31012005-04-17 16:05:31 -0500319{
Tony Jonesee959b02008-02-22 00:13:36 +0100320 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500321
dea31012005-04-17 16:05:31 -0500322 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
323}
324
James Smarte59058c2008-08-24 21:49:00 -0400325/**
James Smart3621a712009-04-06 18:47:14 -0400326 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400327 * @dev: class converted to a Scsi_host structure.
328 * @attr: device attribute, not used.
329 * @buf: on return contains the formatted text serial number.
330 *
331 * Returns: size of formatted string.
332 **/
dea31012005-04-17 16:05:31 -0500333static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100334lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
335 char *buf)
dea31012005-04-17 16:05:31 -0500336{
Tony Jonesee959b02008-02-22 00:13:36 +0100337 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
339 struct lpfc_hba *phba = vport->phba;
340
dea31012005-04-17 16:05:31 -0500341 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
342}
343
James Smarte59058c2008-08-24 21:49:00 -0400344/**
James Smart3621a712009-04-06 18:47:14 -0400345 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400346 * @dev: class converted to a Scsi_host structure.
347 * @attr: device attribute, not used.
348 * @buf: on return contains the formatted support level.
349 *
350 * Description:
351 * Returns a number indicating the temperature sensor level currently
352 * supported, zero or one in ascii.
353 *
354 * Returns: size of formatted string.
355 **/
dea31012005-04-17 16:05:31 -0500356static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100357lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
358 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400359{
Tony Jonesee959b02008-02-22 00:13:36 +0100360 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
362 struct lpfc_hba *phba = vport->phba;
363 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
364}
365
James Smarte59058c2008-08-24 21:49:00 -0400366/**
James Smart3621a712009-04-06 18:47:14 -0400367 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400368 * @dev: class converted to a Scsi_host structure.
369 * @attr: device attribute, not used.
370 * @buf: on return contains the scsi vpd model description.
371 *
372 * Returns: size of formatted string.
373 **/
James Smart57127f12007-10-27 13:37:05 -0400374static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100375lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
376 char *buf)
dea31012005-04-17 16:05:31 -0500377{
Tony Jonesee959b02008-02-22 00:13:36 +0100378 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
380 struct lpfc_hba *phba = vport->phba;
381
dea31012005-04-17 16:05:31 -0500382 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
383}
384
James Smarte59058c2008-08-24 21:49:00 -0400385/**
James Smart3621a712009-04-06 18:47:14 -0400386 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400387 * @dev: class converted to a Scsi_host structure.
388 * @attr: device attribute, not used.
389 * @buf: on return contains the scsi vpd model name.
390 *
391 * Returns: size of formatted string.
392 **/
dea31012005-04-17 16:05:31 -0500393static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100394lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
395 char *buf)
dea31012005-04-17 16:05:31 -0500396{
Tony Jonesee959b02008-02-22 00:13:36 +0100397 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500398 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
399 struct lpfc_hba *phba = vport->phba;
400
dea31012005-04-17 16:05:31 -0500401 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
402}
403
James Smarte59058c2008-08-24 21:49:00 -0400404/**
James Smart3621a712009-04-06 18:47:14 -0400405 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400406 * @dev: class converted to a Scsi_host structure.
407 * @attr: device attribute, not used.
408 * @buf: on return contains the scsi vpd program type.
409 *
410 * Returns: size of formatted string.
411 **/
dea31012005-04-17 16:05:31 -0500412static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100413lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
414 char *buf)
dea31012005-04-17 16:05:31 -0500415{
Tony Jonesee959b02008-02-22 00:13:36 +0100416 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500417 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
418 struct lpfc_hba *phba = vport->phba;
419
dea31012005-04-17 16:05:31 -0500420 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
421}
422
James Smarte59058c2008-08-24 21:49:00 -0400423/**
James Smart3621a712009-04-06 18:47:14 -0400424 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400425 * @dev: class converted to a Scsi_host structure.
426 * @attr: device attribute, not used.
427 * @buf: on return contains the Menlo Maintenance sli flag.
428 *
429 * Returns: size of formatted string.
430 **/
431static ssize_t
432lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
433{
434 struct Scsi_Host *shost = class_to_shost(dev);
435 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
436 struct lpfc_hba *phba = vport->phba;
437
438 return snprintf(buf, PAGE_SIZE, "%d\n",
439 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
440}
441
442/**
James Smart3621a712009-04-06 18:47:14 -0400443 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400444 * @dev: class converted to a Scsi_host structure.
445 * @attr: device attribute, not used.
446 * @buf: on return contains scsi vpd program type.
447 *
448 * Returns: size of formatted string.
449 **/
dea31012005-04-17 16:05:31 -0500450static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100451lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
452 char *buf)
dea31012005-04-17 16:05:31 -0500453{
Tony Jonesee959b02008-02-22 00:13:36 +0100454 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500455 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
456 struct lpfc_hba *phba = vport->phba;
457
dea31012005-04-17 16:05:31 -0500458 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
459}
460
James Smarte59058c2008-08-24 21:49:00 -0400461/**
James Smart3621a712009-04-06 18:47:14 -0400462 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400463 * @dev: class converted to a Scsi_host structure.
464 * @attr: device attribute, not used.
465 * @buf: on return contains the scsi vpd program type.
466 *
467 * Returns: size of formatted string.
468 **/
dea31012005-04-17 16:05:31 -0500469static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100470lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
471 char *buf)
dea31012005-04-17 16:05:31 -0500472{
Tony Jonesee959b02008-02-22 00:13:36 +0100473 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500474 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
475 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500476 uint32_t if_type;
477 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500478 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500479 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500480
dea31012005-04-17 16:05:31 -0500481 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500482 if_type = phba->sli4_hba.pc_sli4_params.if_type;
483 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
484
485 if (phba->sli_rev < LPFC_SLI_REV4)
486 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
487 fwrev, phba->sli_rev);
488 else
489 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
490 fwrev, phba->sli_rev, if_type, sli_family);
491
492 return len;
dea31012005-04-17 16:05:31 -0500493}
494
James Smarte59058c2008-08-24 21:49:00 -0400495/**
James Smart3621a712009-04-06 18:47:14 -0400496 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400497 * @dev: class converted to a Scsi_host structure.
498 * @attr: device attribute, not used.
499 * @buf: on return contains the scsi vpd program type.
500 *
501 * Returns: size of formatted string.
502 **/
dea31012005-04-17 16:05:31 -0500503static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100504lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500505{
506 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100507 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
509 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500510 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500511
dea31012005-04-17 16:05:31 -0500512 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
513 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
514}
James Smarte59058c2008-08-24 21:49:00 -0400515
516/**
James Smart3621a712009-04-06 18:47:14 -0400517 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400518 * @dev: class converted to a Scsi_host structure.
519 * @attr: device attribute, not used.
520 * @buf: on return contains the ROM and FCode ascii strings.
521 *
522 * Returns: size of formatted string.
523 **/
dea31012005-04-17 16:05:31 -0500524static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100525lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
526 char *buf)
dea31012005-04-17 16:05:31 -0500527{
Tony Jonesee959b02008-02-22 00:13:36 +0100528 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500529 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
530 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400531 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500532
James Smarta0683bf2015-04-07 15:07:16 -0400533 if (phba->sli_rev < LPFC_SLI_REV4)
534 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
535
536 lpfc_decode_firmware_rev(phba, fwrev, 1);
537 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500538}
James Smarte59058c2008-08-24 21:49:00 -0400539
540/**
James Smart3621a712009-04-06 18:47:14 -0400541 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400542 * @dev: class converted to a Scsi_host structure.
543 * @attr: device attribute, not used.
544 * @buf: on return contains text describing the state of the link.
545 *
546 * Notes:
547 * The switch statement has no default so zero will be returned.
548 *
549 * Returns: size of formatted string.
550 **/
dea31012005-04-17 16:05:31 -0500551static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100552lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
553 char *buf)
dea31012005-04-17 16:05:31 -0500554{
Tony Jonesee959b02008-02-22 00:13:36 +0100555 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500556 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
557 struct lpfc_hba *phba = vport->phba;
558 int len = 0;
559
560 switch (phba->link_state) {
561 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500562 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500563 case LPFC_INIT_START:
564 case LPFC_INIT_MBX_CMDS:
565 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500566 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400567 if (phba->hba_flag & LINK_DISABLED)
568 len += snprintf(buf + len, PAGE_SIZE-len,
569 "Link Down - User disabled\n");
570 else
571 len += snprintf(buf + len, PAGE_SIZE-len,
572 "Link Down\n");
dea31012005-04-17 16:05:31 -0500573 break;
574 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500575 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500576 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400577 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500578
579 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500580 case LPFC_LOCAL_CFG_LINK:
581 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500582 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500583 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500584 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500585 case LPFC_FLOGI:
586 case LPFC_FABRIC_CFG_LINK:
587 case LPFC_NS_REG:
588 case LPFC_NS_QRY:
589 case LPFC_BUILD_DISC_LIST:
590 case LPFC_DISC_AUTH:
591 len += snprintf(buf + len, PAGE_SIZE - len,
592 "Discovery\n");
593 break;
594 case LPFC_VPORT_READY:
595 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
596 break;
597
James Smart92d7f7b2007-06-17 19:56:38 -0500598 case LPFC_VPORT_FAILED:
599 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
600 break;
601
602 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500603 len += snprintf(buf + len, PAGE_SIZE - len,
604 "Unknown\n");
605 break;
606 }
James Smart84774a42008-08-24 21:50:06 -0400607 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
608 len += snprintf(buf + len, PAGE_SIZE-len,
609 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500610 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500611 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500612 len += snprintf(buf + len, PAGE_SIZE-len,
613 " Public Loop\n");
614 else
615 len += snprintf(buf + len, PAGE_SIZE-len,
616 " Private Loop\n");
617 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500618 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500619 len += snprintf(buf + len, PAGE_SIZE-len,
620 " Fabric\n");
621 else
622 len += snprintf(buf + len, PAGE_SIZE-len,
623 " Point-2-Point\n");
624 }
625 }
James Smart2e0fef82007-06-17 19:56:36 -0500626
dea31012005-04-17 16:05:31 -0500627 return len;
628}
629
James Smarte59058c2008-08-24 21:49:00 -0400630/**
James Smart026abb82011-12-13 13:20:45 -0500631 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
632 * @dev: class unused variable.
633 * @attr: device attribute, not used.
634 * @buf: on return contains the module description text.
635 *
636 * Returns: size of formatted string.
637 **/
638static ssize_t
639lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
640 char *buf)
641{
642 struct Scsi_Host *shost = class_to_shost(dev);
643 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
644 struct lpfc_hba *phba = vport->phba;
645
646 if (phba->sli_rev < LPFC_SLI_REV4)
647 return snprintf(buf, PAGE_SIZE, "fc\n");
648
649 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
650 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
651 return snprintf(buf, PAGE_SIZE, "fcoe\n");
652 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
653 return snprintf(buf, PAGE_SIZE, "fc\n");
654 }
655 return snprintf(buf, PAGE_SIZE, "unknown\n");
656}
657
658/**
James Smart1ba981f2014-02-20 09:56:45 -0500659 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
660 * (OAS) is supported.
661 * @dev: class unused variable.
662 * @attr: device attribute, not used.
663 * @buf: on return contains the module description text.
664 *
665 * Returns: size of formatted string.
666 **/
667static ssize_t
668lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
669 char *buf)
670{
671 struct Scsi_Host *shost = class_to_shost(dev);
672 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
673 struct lpfc_hba *phba = vport->phba;
674
675 return snprintf(buf, PAGE_SIZE, "%d\n",
676 phba->sli4_hba.pc_sli4_params.oas_supported);
677}
678
679/**
James Smart84d1b002010-02-12 14:42:33 -0500680 * lpfc_link_state_store - Transition the link_state on an HBA port
681 * @dev: class device that is converted into a Scsi_host.
682 * @attr: device attribute, not used.
683 * @buf: one or more lpfc_polling_flags values.
684 * @count: not used.
685 *
686 * Returns:
687 * -EINVAL if the buffer is not "up" or "down"
688 * return from link state change function if non-zero
689 * length of the buf on success
690 **/
691static ssize_t
692lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
693 const char *buf, size_t count)
694{
695 struct Scsi_Host *shost = class_to_shost(dev);
696 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
697 struct lpfc_hba *phba = vport->phba;
698
699 int status = -EINVAL;
700
701 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
702 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400703 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500704 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
705 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400706 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500707
708 if (status == 0)
709 return strlen(buf);
710 else
711 return status;
712}
713
714/**
James Smart3621a712009-04-06 18:47:14 -0400715 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400716 * @dev: class device that is converted into a Scsi_host.
717 * @attr: device attribute, not used.
718 * @buf: on return contains the sum of fc mapped and unmapped.
719 *
720 * Description:
721 * Returns the ascii text number of the sum of the fc mapped and unmapped
722 * vport counts.
723 *
724 * Returns: size of formatted string.
725 **/
dea31012005-04-17 16:05:31 -0500726static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100727lpfc_num_discovered_ports_show(struct device *dev,
728 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500729{
Tony Jonesee959b02008-02-22 00:13:36 +0100730 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
732
733 return snprintf(buf, PAGE_SIZE, "%d\n",
734 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500735}
736
James Smarte59058c2008-08-24 21:49:00 -0400737/**
James Smart3621a712009-04-06 18:47:14 -0400738 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400739 * @shost: Scsi_Host pointer.
740 *
741 * Description:
742 * Bring the link down gracefully then re-init the link. The firmware will
743 * re-init the fiber channel interface as required. Does not issue a LIP.
744 *
745 * Returns:
746 * -EPERM port offline or management commands are being blocked
747 * -ENOMEM cannot allocate memory for the mailbox command
748 * -EIO error sending the mailbox command
749 * zero for success
750 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700751static int
James Smart2e0fef82007-06-17 19:56:36 -0500752lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500753{
James Smart2e0fef82007-06-17 19:56:36 -0500754 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
755 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500756 LPFC_MBOXQ_t *pmboxq;
757 int mbxstatus = MBXERR_ERROR;
758
James Smart2e0fef82007-06-17 19:56:36 -0500759 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500760 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500761 return -EPERM;
762
763 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
764
765 if (!pmboxq)
766 return -ENOMEM;
767
768 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400769 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
770 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400771
James Smart33ccf8d2006-08-17 11:57:58 -0400772 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500773
James Smart04c68492009-05-22 14:52:52 -0400774 if ((mbxstatus == MBX_SUCCESS) &&
775 (pmboxq->u.mb.mbxStatus == 0 ||
776 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400777 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
778 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
779 phba->cfg_link_speed);
780 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
781 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400782 if ((mbxstatus == MBX_SUCCESS) &&
783 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
784 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
785 "2859 SLI authentication is required "
786 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400787 }
788
James Smart5b8bd0c2007-04-25 09:52:49 -0400789 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500790 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400791 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500792
793 if (mbxstatus == MBXERR_ERROR)
794 return -EIO;
795
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700796 return 0;
dea31012005-04-17 16:05:31 -0500797}
798
James Smart895427b2017-02-12 13:52:30 -0800799int
800lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
801{
802 int cnt = 0;
803
804 spin_lock_irq(lock);
805 while (!list_empty(q)) {
806 spin_unlock_irq(lock);
807 msleep(20);
808 if (cnt++ > 250) { /* 5 secs */
809 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
810 "0466 %s %s\n",
811 "Outstanding IO when ",
812 "bringing Adapter offline\n");
813 return 0;
814 }
815 spin_lock_irq(lock);
816 }
817 spin_unlock_irq(lock);
818 return 1;
819}
820
James Smarte59058c2008-08-24 21:49:00 -0400821/**
James Smart3621a712009-04-06 18:47:14 -0400822 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400823 * @phba: lpfc_hba pointer.
824 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
825 *
826 * Notes:
827 * Assumes any error from lpfc_do_offline() will be negative.
828 * Can wait up to 5 seconds for the port ring buffers count
829 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400830 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400831 *
832 * Returns:
833 * -EIO error posting the event
834 * zero for success
835 **/
James Smart40496f02006-07-06 15:50:22 -0400836static int
James Smart46fa3112007-04-25 09:51:45 -0400837lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
838{
839 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800840 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400841 struct lpfc_sli_ring *pring;
842 struct lpfc_sli *psli;
843 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400844 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500845 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400846
847 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500848 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400849 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500850 if (rc == 0)
851 return -ENOMEM;
852
James Smart46fa3112007-04-25 09:51:45 -0400853 wait_for_completion(&online_compl);
854
855 if (status != 0)
856 return -EIO;
857
858 psli = &phba->sli;
859
James Smart09372822008-01-11 01:52:54 -0500860 /* Wait a little for things to settle down, but not
861 * long enough for dev loss timeout to expire.
862 */
James Smart895427b2017-02-12 13:52:30 -0800863 if (phba->sli_rev != LPFC_SLI_REV4) {
864 for (i = 0; i < psli->num_rings; i++) {
865 pring = &psli->sli3_ring[i];
866 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
867 &phba->hbalock))
868 goto out;
869 }
870 } else {
871 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
872 pring = qp->pring;
873 if (!pring)
874 continue;
875 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
876 &pring->ring_lock))
877 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400878 }
879 }
James Smart895427b2017-02-12 13:52:30 -0800880out:
James Smart46fa3112007-04-25 09:51:45 -0400881 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500882 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
883 if (rc == 0)
884 return -ENOMEM;
885
James Smart46fa3112007-04-25 09:51:45 -0400886 wait_for_completion(&online_compl);
887
888 if (status != 0)
889 return -EIO;
890
891 return 0;
892}
893
James Smarte59058c2008-08-24 21:49:00 -0400894/**
James Smart3621a712009-04-06 18:47:14 -0400895 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400896 * @phba: lpfc_hba pointer.
897 *
898 * Description:
899 * If the port is configured to allow a reset then the hba is brought
900 * offline then online.
901 *
902 * Notes:
903 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500904 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400905 *
906 * Returns:
907 * lpfc_do_offline() return code if not zero
908 * -EIO reset not configured or error posting the event
909 * zero for success
910 **/
James Smart7f860592011-03-11 16:05:52 -0500911int
James Smart40496f02006-07-06 15:50:22 -0400912lpfc_selective_reset(struct lpfc_hba *phba)
913{
914 struct completion online_compl;
915 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -0500916 int rc;
James Smart40496f02006-07-06 15:50:22 -0400917
James Smart71157c92013-07-15 18:34:36 -0400918 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -0400919 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -0500920
James Smart71157c92013-07-15 18:34:36 -0400921 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
922 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400923
James Smart71157c92013-07-15 18:34:36 -0400924 if (status != 0)
925 return status;
926 }
James Smart40496f02006-07-06 15:50:22 -0400927
928 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500929 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -0400930 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -0500931 if (rc == 0)
932 return -ENOMEM;
933
James Smart40496f02006-07-06 15:50:22 -0400934 wait_for_completion(&online_compl);
935
936 if (status != 0)
937 return -EIO;
938
939 return 0;
940}
941
James Smarte59058c2008-08-24 21:49:00 -0400942/**
James Smart3621a712009-04-06 18:47:14 -0400943 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -0400944 * @dev: class device that is converted into a Scsi_host.
945 * @attr: device attribute, not used.
946 * @buf: containing the string "selective".
947 * @count: unused variable.
948 *
949 * Description:
950 * If the buf contains the string "selective" then lpfc_selective_reset()
951 * is called to perform the reset.
952 *
953 * Notes:
954 * Assumes any error from lpfc_selective_reset() will be negative.
955 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200956 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -0400957 *
958 * Returns:
959 * -EINVAL if the buffer does not contain the string "selective"
960 * length of buf if lpfc-selective_reset() if the call succeeds
961 * return value of lpfc_selective_reset() if the call fails
962**/
James Smart40496f02006-07-06 15:50:22 -0400963static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100964lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
965 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400966{
Tony Jonesee959b02008-02-22 00:13:36 +0100967 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500968 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
969 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -0400970 int status = -EINVAL;
971
James Smart73d91e52011-10-10 21:32:10 -0400972 if (!phba->cfg_enable_hba_reset)
973 return -EACCES;
974
James Smart40496f02006-07-06 15:50:22 -0400975 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -0500976 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -0400977
978 if (status == 0)
979 return strlen(buf);
980 else
981 return status;
982}
983
James Smarte59058c2008-08-24 21:49:00 -0400984/**
James Smart88a2cfb2011-07-22 18:36:33 -0400985 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
986 * @phba: lpfc_hba pointer.
987 *
988 * Description:
989 * SLI4 interface type-2 device to wait on the sliport status register for
990 * the readyness after performing a firmware reset.
991 *
992 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +0900993 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -0500994 * reset, -EIO when port timeout from recovering from the reset.
995 *
996 * Note:
997 * As the caller will interpret the return code by value, be careful in making
998 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -0400999 **/
James Smart73d91e52011-10-10 21:32:10 -04001000int
James Smart88a2cfb2011-07-22 18:36:33 -04001001lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1002{
James Smartf7a919b2011-08-21 21:49:16 -04001003 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001004 int i;
1005
James Smartf7a919b2011-08-21 21:49:16 -04001006 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001007 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1008 &portstat_reg.word0);
1009
Masanari Iida0b1587b2013-07-17 04:37:44 +09001010 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001011 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1012 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1013 return -EPERM;
1014
James Smart88a2cfb2011-07-22 18:36:33 -04001015 /* wait for the SLI port firmware ready after firmware reset */
1016 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1017 msleep(10);
1018 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1019 &portstat_reg.word0);
1020 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1021 continue;
1022 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1023 continue;
1024 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1025 continue;
1026 break;
1027 }
1028
1029 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1030 return 0;
1031 else
1032 return -EIO;
1033}
1034
1035/**
James Smart52d52442011-05-24 11:42:45 -04001036 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001037 * @phba: lpfc_hba pointer.
1038 *
1039 * Description:
James Smart52d52442011-05-24 11:42:45 -04001040 * Request SLI4 interface type-2 device to perform a physical register set
1041 * access.
James Smartc0c11512011-05-24 11:41:34 -04001042 *
1043 * Returns:
1044 * zero for success
1045 **/
1046static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001047lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001048{
1049 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001050 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001051 uint32_t before_fc_flag;
1052 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001053 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001054 int status = 0, rc = 0;
1055 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001056
1057 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001058 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001059
James Smart52d52442011-05-24 11:42:45 -04001060 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1061 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1062 LPFC_SLI_INTF_IF_TYPE_2))
1063 return -EPERM;
1064
James Smart026abb82011-12-13 13:20:45 -05001065 /* Keep state if we need to restore back */
1066 before_fc_flag = phba->pport->fc_flag;
1067 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1068
James Smartb76f2dc2011-07-22 18:37:42 -04001069 /* Disable SR-IOV virtual functions if enabled */
1070 if (phba->cfg_sriov_nr_virtfn) {
1071 pci_disable_sriov(pdev);
1072 phba->cfg_sriov_nr_virtfn = 0;
1073 }
James Smart229adb02013-04-17 20:16:51 -04001074
James Smart02936352014-04-04 13:52:12 -04001075 if (opcode == LPFC_FW_DUMP)
1076 phba->hba_flag |= HBA_FW_DUMP_OP;
1077
James Smartc0c11512011-05-24 11:41:34 -04001078 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1079
James Smart02936352014-04-04 13:52:12 -04001080 if (status != 0) {
1081 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001082 return status;
James Smart02936352014-04-04 13:52:12 -04001083 }
James Smartc0c11512011-05-24 11:41:34 -04001084
1085 /* wait for the device to be quiesced before firmware reset */
1086 msleep(100);
1087
1088 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1089 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001090
1091 if (opcode == LPFC_FW_DUMP)
1092 reg_val |= LPFC_FW_DUMP_REQUEST;
1093 else if (opcode == LPFC_FW_RESET)
1094 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1095 else if (opcode == LPFC_DV_RESET)
1096 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1097
James Smartc0c11512011-05-24 11:41:34 -04001098 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1099 LPFC_CTL_PDEV_CTL_OFFSET);
1100 /* flush */
1101 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1102
1103 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001104 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1105
James Smart026abb82011-12-13 13:20:45 -05001106 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001107 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001108 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001109 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001110 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001111 } else if (rc == -EIO) {
1112 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001113 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1114 "3153 Fail to perform the requested "
1115 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001116 return rc;
James Smart026abb82011-12-13 13:20:45 -05001117 }
1118
1119 /* keep the original port state */
1120 if (before_fc_flag & FC_OFFLINE_MODE)
1121 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001122
1123 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001124 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1125 LPFC_EVT_ONLINE);
1126 if (!job_posted)
1127 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001128
1129 wait_for_completion(&online_compl);
1130
James Smart026abb82011-12-13 13:20:45 -05001131out:
1132 /* in any case, restore the virtual functions enabled as before */
1133 if (sriov_nr_virtfn) {
1134 sriov_err =
1135 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1136 if (!sriov_err)
1137 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1138 }
James Smartc0c11512011-05-24 11:41:34 -04001139
James Smart026abb82011-12-13 13:20:45 -05001140 /* return proper error code */
1141 if (!rc) {
1142 if (!job_posted)
1143 rc = -ENOMEM;
1144 else if (status)
1145 rc = -EIO;
1146 }
1147 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001148}
1149
1150/**
James Smart3621a712009-04-06 18:47:14 -04001151 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001152 * @dev: class device that is converted into a Scsi_host.
1153 * @attr: device attribute, not used.
1154 * @buf: on return contains the ascii number of nport events.
1155 *
1156 * Returns: size of formatted string.
1157 **/
dea31012005-04-17 16:05:31 -05001158static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001159lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1160 char *buf)
dea31012005-04-17 16:05:31 -05001161{
Tony Jonesee959b02008-02-22 00:13:36 +01001162 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001163 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1164 struct lpfc_hba *phba = vport->phba;
1165
dea31012005-04-17 16:05:31 -05001166 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1167}
1168
James Smarte59058c2008-08-24 21:49:00 -04001169/**
James Smart3621a712009-04-06 18:47:14 -04001170 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001171 * @dev: class device that is converted into a Scsi_host.
1172 * @attr: device attribute, not used.
1173 * @buf: on return contains the state of the adapter.
1174 *
1175 * Returns: size of formatted string.
1176 **/
dea31012005-04-17 16:05:31 -05001177static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001178lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1179 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001180{
Tony Jonesee959b02008-02-22 00:13:36 +01001181 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001182 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1183 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001184 char * state;
1185
James Smart2e0fef82007-06-17 19:56:36 -05001186 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001187 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001188 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001189 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001190 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001191 state = "offline";
1192 else
1193 state = "online";
1194
1195 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1196}
1197
James Smarte59058c2008-08-24 21:49:00 -04001198/**
James Smart3621a712009-04-06 18:47:14 -04001199 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001200 * @dev: class device that is converted into a Scsi_host.
1201 * @attr: device attribute, not used.
1202 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1203 * @count: unused variable.
1204 *
1205 * Returns:
1206 * -EACCES if enable hba reset not enabled
1207 * -EINVAL if the buffer does not contain a valid string (see above)
1208 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1209 * buf length greater than zero indicates success
1210 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001211static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001212lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1213 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001214{
Tony Jonesee959b02008-02-22 00:13:36 +01001215 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001216 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1217 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001218 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001219 char *board_mode_str = NULL;
1220 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001221 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001222
James Smart026abb82011-12-13 13:20:45 -05001223 if (!phba->cfg_enable_hba_reset) {
1224 status = -EACCES;
1225 goto board_mode_out;
1226 }
James Smart88a2cfb2011-07-22 18:36:33 -04001227
1228 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001229 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001230
Jamie Wellnitz41415862006-02-28 19:25:27 -05001231 init_completion(&online_compl);
1232
James Smart46fa3112007-04-25 09:51:45 -04001233 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001234 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001235 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001236 if (rc == 0) {
1237 status = -ENOMEM;
1238 goto board_mode_out;
1239 }
James Smart46fa3112007-04-25 09:51:45 -04001240 wait_for_completion(&online_compl);
1241 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1242 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001243 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001244 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001245 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001246 else
1247 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001248 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001249 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001250 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001251 else
1252 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001253 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001254 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1255 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1256 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1257 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1258 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001259 else
James Smart026abb82011-12-13 13:20:45 -05001260 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001261
James Smart026abb82011-12-13 13:20:45 -05001262board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001263 if (!status)
1264 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001265 else {
1266 board_mode_str = strchr(buf, '\n');
1267 if (board_mode_str)
1268 *board_mode_str = '\0';
1269 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1270 "3097 Failed \"%s\", status(%d), "
1271 "fc_flag(x%x)\n",
1272 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001273 return status;
James Smart026abb82011-12-13 13:20:45 -05001274 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001275}
1276
James Smarte59058c2008-08-24 21:49:00 -04001277/**
James Smart3621a712009-04-06 18:47:14 -04001278 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001279 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001280 * @mxri: max xri count.
1281 * @axri: available xri count.
1282 * @mrpi: max rpi count.
1283 * @arpi: available rpi count.
1284 * @mvpi: max vpi count.
1285 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001286 *
1287 * Description:
1288 * If an integer pointer for an count is not null then the value for the
1289 * count is returned.
1290 *
1291 * Returns:
1292 * zero on error
1293 * one for success
1294 **/
James Smart311464e2007-08-02 11:10:37 -04001295static int
James Smart858c9f62007-06-17 19:56:39 -05001296lpfc_get_hba_info(struct lpfc_hba *phba,
1297 uint32_t *mxri, uint32_t *axri,
1298 uint32_t *mrpi, uint32_t *arpi,
1299 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001300{
James Smart04c68492009-05-22 14:52:52 -04001301 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001302 LPFC_MBOXQ_t *pmboxq;
1303 MAILBOX_t *pmb;
1304 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001305 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001306
1307 /*
1308 * prevent udev from issuing mailbox commands until the port is
1309 * configured.
1310 */
1311 if (phba->link_state < LPFC_LINK_DOWN ||
1312 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001313 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001314 return 0;
1315
1316 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1317 return 0;
1318
1319 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1320 if (!pmboxq)
1321 return 0;
1322 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1323
James Smart04c68492009-05-22 14:52:52 -04001324 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001325 pmb->mbxCommand = MBX_READ_CONFIG;
1326 pmb->mbxOwner = OWN_HOST;
1327 pmboxq->context1 = NULL;
1328
James Smart75baf692010-06-08 18:31:21 -04001329 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001330 rc = MBX_NOT_FINISHED;
1331 else
1332 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1333
1334 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001335 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001336 mempool_free(pmboxq, phba->mbox_mem_pool);
1337 return 0;
1338 }
1339
James Smartda0436e2009-05-22 14:51:39 -04001340 if (phba->sli_rev == LPFC_SLI_REV4) {
1341 rd_config = &pmboxq->u.mqe.un.rd_config;
1342 if (mrpi)
1343 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1344 if (arpi)
1345 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1346 phba->sli4_hba.max_cfg_param.rpi_used;
1347 if (mxri)
1348 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1349 if (axri)
1350 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1351 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001352
1353 /* Account for differences with SLI-3. Get vpi count from
1354 * mailbox data and subtract one for max vpi value.
1355 */
1356 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1357 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1358
James Smartda0436e2009-05-22 14:51:39 -04001359 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001360 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001361 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001362 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001363 } else {
1364 if (mrpi)
1365 *mrpi = pmb->un.varRdConfig.max_rpi;
1366 if (arpi)
1367 *arpi = pmb->un.varRdConfig.avail_rpi;
1368 if (mxri)
1369 *mxri = pmb->un.varRdConfig.max_xri;
1370 if (axri)
1371 *axri = pmb->un.varRdConfig.avail_xri;
1372 if (mvpi)
1373 *mvpi = pmb->un.varRdConfig.max_vpi;
1374 if (avpi)
1375 *avpi = pmb->un.varRdConfig.avail_vpi;
1376 }
James Smart92d7f7b2007-06-17 19:56:38 -05001377
1378 mempool_free(pmboxq, phba->mbox_mem_pool);
1379 return 1;
1380}
1381
James Smarte59058c2008-08-24 21:49:00 -04001382/**
James Smart3621a712009-04-06 18:47:14 -04001383 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001384 * @dev: class device that is converted into a Scsi_host.
1385 * @attr: device attribute, not used.
1386 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1387 *
1388 * Description:
1389 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1390 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1391 * to "Unknown" and the buffer length is returned, therefore the caller
1392 * must check for "Unknown" in the buffer to detect a failure.
1393 *
1394 * Returns: size of formatted string.
1395 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001396static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001397lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1398 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001399{
Tony Jonesee959b02008-02-22 00:13:36 +01001400 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001401 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1402 struct lpfc_hba *phba = vport->phba;
1403 uint32_t cnt;
1404
James Smart858c9f62007-06-17 19:56:39 -05001405 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001406 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1407 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1408}
1409
James Smarte59058c2008-08-24 21:49:00 -04001410/**
James Smart3621a712009-04-06 18:47:14 -04001411 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001412 * @dev: class device that is converted into a Scsi_host.
1413 * @attr: device attribute, not used.
1414 * @buf: containing the used rpi count in decimal or "Unknown".
1415 *
1416 * Description:
1417 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1418 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1419 * to "Unknown" and the buffer length is returned, therefore the caller
1420 * must check for "Unknown" in the buffer to detect a failure.
1421 *
1422 * Returns: size of formatted string.
1423 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001424static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001425lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1426 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001427{
Tony Jonesee959b02008-02-22 00:13:36 +01001428 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001429 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1430 struct lpfc_hba *phba = vport->phba;
1431 uint32_t cnt, acnt;
1432
James Smart858c9f62007-06-17 19:56:39 -05001433 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001434 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1435 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1436}
1437
James Smarte59058c2008-08-24 21:49:00 -04001438/**
James Smart3621a712009-04-06 18:47:14 -04001439 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001440 * @dev: class device that is converted into a Scsi_host.
1441 * @attr: device attribute, not used.
1442 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1443 *
1444 * Description:
1445 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1446 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1447 * to "Unknown" and the buffer length is returned, therefore the caller
1448 * must check for "Unknown" in the buffer to detect a failure.
1449 *
1450 * Returns: size of formatted string.
1451 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001452static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001453lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1454 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001455{
Tony Jonesee959b02008-02-22 00:13:36 +01001456 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001457 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1458 struct lpfc_hba *phba = vport->phba;
1459 uint32_t cnt;
1460
James Smart858c9f62007-06-17 19:56:39 -05001461 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001462 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1463 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1464}
1465
James Smarte59058c2008-08-24 21:49:00 -04001466/**
James Smart3621a712009-04-06 18:47:14 -04001467 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001468 * @dev: class device that is converted into a Scsi_host.
1469 * @attr: device attribute, not used.
1470 * @buf: on return contains the used xri count in decimal or "Unknown".
1471 *
1472 * Description:
1473 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1474 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1475 * to "Unknown" and the buffer length is returned, therefore the caller
1476 * must check for "Unknown" in the buffer to detect a failure.
1477 *
1478 * Returns: size of formatted string.
1479 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001480static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001481lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1482 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001483{
Tony Jonesee959b02008-02-22 00:13:36 +01001484 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001485 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1486 struct lpfc_hba *phba = vport->phba;
1487 uint32_t cnt, acnt;
1488
James Smart858c9f62007-06-17 19:56:39 -05001489 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1490 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1491 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1492}
1493
James Smarte59058c2008-08-24 21:49:00 -04001494/**
James Smart3621a712009-04-06 18:47:14 -04001495 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001496 * @dev: class device that is converted into a Scsi_host.
1497 * @attr: device attribute, not used.
1498 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1499 *
1500 * Description:
1501 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1502 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1503 * to "Unknown" and the buffer length is returned, therefore the caller
1504 * must check for "Unknown" in the buffer to detect a failure.
1505 *
1506 * Returns: size of formatted string.
1507 **/
James Smart858c9f62007-06-17 19:56:39 -05001508static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001509lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1510 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001511{
Tony Jonesee959b02008-02-22 00:13:36 +01001512 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1514 struct lpfc_hba *phba = vport->phba;
1515 uint32_t cnt;
1516
1517 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1518 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1519 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1520}
1521
James Smarte59058c2008-08-24 21:49:00 -04001522/**
James Smart3621a712009-04-06 18:47:14 -04001523 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001524 * @dev: class device that is converted into a Scsi_host.
1525 * @attr: device attribute, not used.
1526 * @buf: on return contains the used vpi count in decimal or "Unknown".
1527 *
1528 * Description:
1529 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1530 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1531 * to "Unknown" and the buffer length is returned, therefore the caller
1532 * must check for "Unknown" in the buffer to detect a failure.
1533 *
1534 * Returns: size of formatted string.
1535 **/
James Smart858c9f62007-06-17 19:56:39 -05001536static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001537lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1538 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001539{
Tony Jonesee959b02008-02-22 00:13:36 +01001540 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1542 struct lpfc_hba *phba = vport->phba;
1543 uint32_t cnt, acnt;
1544
1545 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001546 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1547 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1548}
1549
James Smarte59058c2008-08-24 21:49:00 -04001550/**
James Smart3621a712009-04-06 18:47:14 -04001551 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001552 * @dev: class device that is converted into a Scsi_host.
1553 * @attr: device attribute, not used.
1554 * @buf: text that must be interpreted to determine if npiv is supported.
1555 *
1556 * Description:
1557 * Buffer will contain text indicating npiv is not suppoerted on the port,
1558 * the port is an NPIV physical port, or it is an npiv virtual port with
1559 * the id of the vport.
1560 *
1561 * Returns: size of formatted string.
1562 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001563static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001564lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1565 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001566{
Tony Jonesee959b02008-02-22 00:13:36 +01001567 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1569 struct lpfc_hba *phba = vport->phba;
1570
1571 if (!(phba->max_vpi))
1572 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1573 if (vport->port_type == LPFC_PHYSICAL_PORT)
1574 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1575 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1576}
1577
James Smarte59058c2008-08-24 21:49:00 -04001578/**
James Smart3621a712009-04-06 18:47:14 -04001579 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001580 * @dev: class device that is converted into a Scsi_host.
1581 * @attr: device attribute, not used.
1582 * @buf: on return contains the cfg_poll in hex.
1583 *
1584 * Notes:
1585 * cfg_poll should be a lpfc_polling_flags type.
1586 *
1587 * Returns: size of formatted string.
1588 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001589static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001590lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1591 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001592{
Tony Jonesee959b02008-02-22 00:13:36 +01001593 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001594 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1595 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001596
1597 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1598}
1599
James Smarte59058c2008-08-24 21:49:00 -04001600/**
James Smart3621a712009-04-06 18:47:14 -04001601 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001602 * @dev: class device that is converted into a Scsi_host.
1603 * @attr: device attribute, not used.
1604 * @buf: one or more lpfc_polling_flags values.
1605 * @count: not used.
1606 *
1607 * Notes:
1608 * buf contents converted to integer and checked for a valid value.
1609 *
1610 * Returns:
1611 * -EINVAL if the buffer connot be converted or is out of range
1612 * length of the buf on success
1613 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001614static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001615lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1616 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001617{
Tony Jonesee959b02008-02-22 00:13:36 +01001618 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1620 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001621 uint32_t creg_val;
1622 uint32_t old_val;
1623 int val=0;
1624
1625 if (!isdigit(buf[0]))
1626 return -EINVAL;
1627
1628 if (sscanf(buf, "%i", &val) != 1)
1629 return -EINVAL;
1630
1631 if ((val & 0x3) != val)
1632 return -EINVAL;
1633
James Smart45ed1192009-10-02 15:17:02 -04001634 if (phba->sli_rev == LPFC_SLI_REV4)
1635 val = 0;
1636
James Smart88a2cfb2011-07-22 18:36:33 -04001637 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1638 "3051 lpfc_poll changed from %d to %d\n",
1639 phba->cfg_poll, val);
1640
James Smart2e0fef82007-06-17 19:56:36 -05001641 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001642
1643 old_val = phba->cfg_poll;
1644
1645 if (val & ENABLE_FCP_RING_POLLING) {
1646 if ((val & DISABLE_FCP_RING_INT) &&
1647 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001648 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1649 spin_unlock_irq(&phba->hbalock);
1650 return -EINVAL;
1651 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001652 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1653 writel(creg_val, phba->HCregaddr);
1654 readl(phba->HCregaddr); /* flush */
1655
1656 lpfc_poll_start_timer(phba);
1657 }
1658 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001659 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001660 return -EINVAL;
1661 }
1662
1663 if (!(val & DISABLE_FCP_RING_INT) &&
1664 (old_val & DISABLE_FCP_RING_INT))
1665 {
James Smart2e0fef82007-06-17 19:56:36 -05001666 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001667 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001668 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001669 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1670 spin_unlock_irq(&phba->hbalock);
1671 return -EINVAL;
1672 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001673 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1674 writel(creg_val, phba->HCregaddr);
1675 readl(phba->HCregaddr); /* flush */
1676 }
1677
1678 phba->cfg_poll = val;
1679
James Smart2e0fef82007-06-17 19:56:36 -05001680 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001681
1682 return strlen(buf);
1683}
dea31012005-04-17 16:05:31 -05001684
James Smarte59058c2008-08-24 21:49:00 -04001685/**
James Smartbc739052010-08-04 16:11:18 -04001686 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1687 * @dev: class unused variable.
1688 * @attr: device attribute, not used.
1689 * @buf: on return contains the module description text.
1690 *
1691 * Returns: size of formatted string.
1692 **/
1693static ssize_t
1694lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1695 char *buf)
1696{
1697 struct Scsi_Host *shost = class_to_shost(dev);
1698 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1699 struct lpfc_hba *phba = vport->phba;
1700
1701 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1702}
1703
1704/**
1705 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1706 * @dev: class unused variable.
1707 * @attr: device attribute, not used.
1708 * @buf: on return contains the module description text.
1709 *
1710 * Returns: size of formatted string.
1711 **/
1712static ssize_t
1713lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1714 char *buf)
1715{
1716 struct Scsi_Host *shost = class_to_shost(dev);
1717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1718 struct lpfc_hba *phba = vport->phba;
1719
1720 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1721}
1722
1723/**
James Smartab56dc22011-02-16 12:39:57 -05001724 * lpfc_dss_show - Return the current state of dss and the configured state
1725 * @dev: class converted to a Scsi_host structure.
1726 * @attr: device attribute, not used.
1727 * @buf: on return contains the formatted text.
1728 *
1729 * Returns: size of formatted string.
1730 **/
1731static ssize_t
1732lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1733 char *buf)
1734{
1735 struct Scsi_Host *shost = class_to_shost(dev);
1736 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1737 struct lpfc_hba *phba = vport->phba;
1738
1739 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1740 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1741 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1742 "" : "Not ");
1743}
1744
1745/**
James Smart912e3ac2011-05-24 11:42:11 -04001746 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1747 * @dev: class converted to a Scsi_host structure.
1748 * @attr: device attribute, not used.
1749 * @buf: on return contains the formatted support level.
1750 *
1751 * Description:
1752 * Returns the maximum number of virtual functions a physical function can
1753 * support, 0 will be returned if called on virtual function.
1754 *
1755 * Returns: size of formatted string.
1756 **/
1757static ssize_t
1758lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1759 struct device_attribute *attr,
1760 char *buf)
1761{
1762 struct Scsi_Host *shost = class_to_shost(dev);
1763 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1764 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001765 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001766
James Smart0a96e972011-07-22 18:37:28 -04001767 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1768 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001769}
1770
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001771static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1772{
1773 return val >= min && val <= max;
1774}
1775
James Smart912e3ac2011-05-24 11:42:11 -04001776/**
James Smart3621a712009-04-06 18:47:14 -04001777 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001778 *
1779 * Description:
1780 * Macro that given an attr e.g. hba_queue_depth expands
1781 * into a function with the name lpfc_hba_queue_depth_show.
1782 *
1783 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1784 * @dev: class device that is converted into a Scsi_host.
1785 * @attr: device attribute, not used.
1786 * @buf: on return contains the attribute value in decimal.
1787 *
1788 * Returns: size of formatted string.
1789 **/
dea31012005-04-17 16:05:31 -05001790#define lpfc_param_show(attr) \
1791static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001792lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1793 char *buf) \
dea31012005-04-17 16:05:31 -05001794{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001795 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1797 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001798 return snprintf(buf, PAGE_SIZE, "%d\n",\
1799 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001800}
1801
James Smarte59058c2008-08-24 21:49:00 -04001802/**
James Smart3621a712009-04-06 18:47:14 -04001803 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001804 *
1805 * Description:
1806 * Macro that given an attr e.g. hba_queue_depth expands
1807 * into a function with the name lpfc_hba_queue_depth_show
1808 *
1809 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1810 * @dev: class device that is converted into a Scsi_host.
1811 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001812 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001813 *
1814 * Returns: size of formatted string.
1815 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001816#define lpfc_param_hex_show(attr) \
1817static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001818lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1819 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001820{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001821 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1823 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001824 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001825 val = phba->cfg_##attr;\
1826 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1827 phba->cfg_##attr);\
1828}
1829
James Smarte59058c2008-08-24 21:49:00 -04001830/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001831 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001832 *
1833 * Description:
1834 * Macro that given an attr e.g. hba_queue_depth expands
1835 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1836 * takes a default argument, a minimum and maximum argument.
1837 *
1838 * lpfc_##attr##_init: Initializes an attribute.
1839 * @phba: pointer the the adapter structure.
1840 * @val: integer attribute value.
1841 *
1842 * Validates the min and max values then sets the adapter config field
1843 * accordingly, or uses the default if out of range and prints an error message.
1844 *
1845 * Returns:
1846 * zero on success
1847 * -EINVAL if default used
1848 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001849#define lpfc_param_init(attr, default, minval, maxval) \
1850static int \
James Smart84d1b002010-02-12 14:42:33 -05001851lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001852{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001853 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001854 phba->cfg_##attr = val;\
1855 return 0;\
1856 }\
1857 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001858 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1859 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001860 phba->cfg_##attr = default;\
1861 return -EINVAL;\
1862}
1863
James Smarte59058c2008-08-24 21:49:00 -04001864/**
James Smart3621a712009-04-06 18:47:14 -04001865 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001866 *
1867 * Description:
1868 * Macro that given an attr e.g. hba_queue_depth expands
1869 * into a function with the name lpfc_hba_queue_depth_set
1870 *
1871 * lpfc_##attr##_set: Sets an attribute value.
1872 * @phba: pointer the the adapter structure.
1873 * @val: integer attribute value.
1874 *
1875 * Description:
1876 * Validates the min and max values then sets the
1877 * adapter config field if in the valid range. prints error message
1878 * and does not set the parameter if invalid.
1879 *
1880 * Returns:
1881 * zero on success
1882 * -EINVAL if val is invalid
1883 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001884#define lpfc_param_set(attr, default, minval, maxval) \
1885static int \
James Smart84d1b002010-02-12 14:42:33 -05001886lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001887{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001888 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001889 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1890 "3052 lpfc_" #attr " changed from %d to %d\n", \
1891 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001892 phba->cfg_##attr = val;\
1893 return 0;\
1894 }\
1895 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001896 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1897 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001898 return -EINVAL;\
1899}
1900
James Smarte59058c2008-08-24 21:49:00 -04001901/**
James Smart3621a712009-04-06 18:47:14 -04001902 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001903 *
1904 * Description:
1905 * Macro that given an attr e.g. hba_queue_depth expands
1906 * into a function with the name lpfc_hba_queue_depth_store.
1907 *
1908 * lpfc_##attr##_store: Set an sttribute value.
1909 * @dev: class device that is converted into a Scsi_host.
1910 * @attr: device attribute, not used.
1911 * @buf: contains the attribute value in ascii.
1912 * @count: not used.
1913 *
1914 * Description:
1915 * Convert the ascii text number to an integer, then
1916 * use the lpfc_##attr##_set function to set the value.
1917 *
1918 * Returns:
1919 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1920 * length of buffer upon success.
1921 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001922#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05001923static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001924lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1925 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05001926{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001927 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001928 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1929 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001930 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001931 if (!isdigit(buf[0]))\
1932 return -EINVAL;\
1933 if (sscanf(buf, "%i", &val) != 1)\
1934 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001935 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04001936 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001937 else \
1938 return -EINVAL;\
dea31012005-04-17 16:05:31 -05001939}
1940
James Smarte59058c2008-08-24 21:49:00 -04001941/**
James Smart3621a712009-04-06 18:47:14 -04001942 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001943 *
1944 * Description:
1945 * Macro that given an attr e.g. hba_queue_depth expands
1946 * into a function with the name lpfc_hba_queue_depth_show
1947 *
1948 * lpfc_##attr##_show: prints the attribute value in decimal.
1949 * @dev: class device that is converted into a Scsi_host.
1950 * @attr: device attribute, not used.
1951 * @buf: on return contains the attribute value in decimal.
1952 *
1953 * Returns: length of formatted string.
1954 **/
James Smart3de2a652007-08-02 11:09:59 -04001955#define lpfc_vport_param_show(attr) \
1956static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001957lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1958 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001959{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001960 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001962 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1963}
1964
James Smarte59058c2008-08-24 21:49:00 -04001965/**
James Smart3621a712009-04-06 18:47:14 -04001966 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04001967 *
1968 * Description:
1969 * Macro that given an attr e.g.
1970 * hba_queue_depth expands into a function with the name
1971 * lpfc_hba_queue_depth_show
1972 *
James Smart3621a712009-04-06 18:47:14 -04001973 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001974 * @dev: class device that is converted into a Scsi_host.
1975 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001976 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001977 *
1978 * Returns: length of formatted string.
1979 **/
James Smart3de2a652007-08-02 11:09:59 -04001980#define lpfc_vport_param_hex_show(attr) \
1981static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001982lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1983 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04001984{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001985 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04001986 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04001987 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1988}
1989
James Smarte59058c2008-08-24 21:49:00 -04001990/**
James Smart3621a712009-04-06 18:47:14 -04001991 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001992 *
1993 * Description:
1994 * Macro that given an attr e.g. hba_queue_depth expands
1995 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1996 * takes a default argument, a minimum and maximum argument.
1997 *
1998 * lpfc_##attr##_init: validates the min and max values then sets the
1999 * adapter config field accordingly, or uses the default if out of range
2000 * and prints an error message.
2001 * @phba: pointer the the adapter structure.
2002 * @val: integer attribute value.
2003 *
2004 * Returns:
2005 * zero on success
2006 * -EINVAL if default used
2007 **/
James Smart3de2a652007-08-02 11:09:59 -04002008#define lpfc_vport_param_init(attr, default, minval, maxval) \
2009static int \
James Smart84d1b002010-02-12 14:42:33 -05002010lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002011{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002012 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002013 vport->cfg_##attr = val;\
2014 return 0;\
2015 }\
James Smarte8b62012007-08-02 11:10:09 -04002016 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002017 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002018 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002019 vport->cfg_##attr = default;\
2020 return -EINVAL;\
2021}
2022
James Smarte59058c2008-08-24 21:49:00 -04002023/**
James Smart3621a712009-04-06 18:47:14 -04002024 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002025 *
2026 * Description:
2027 * Macro that given an attr e.g. hba_queue_depth expands
2028 * into a function with the name lpfc_hba_queue_depth_set
2029 *
2030 * lpfc_##attr##_set: validates the min and max values then sets the
2031 * adapter config field if in the valid range. prints error message
2032 * and does not set the parameter if invalid.
2033 * @phba: pointer the the adapter structure.
2034 * @val: integer attribute value.
2035 *
2036 * Returns:
2037 * zero on success
2038 * -EINVAL if val is invalid
2039 **/
James Smart3de2a652007-08-02 11:09:59 -04002040#define lpfc_vport_param_set(attr, default, minval, maxval) \
2041static int \
James Smart84d1b002010-02-12 14:42:33 -05002042lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002043{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002044 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002045 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002046 "3053 lpfc_" #attr \
2047 " changed from %d (x%x) to %d (x%x)\n", \
2048 vport->cfg_##attr, vport->cfg_##attr, \
2049 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002050 vport->cfg_##attr = val;\
2051 return 0;\
2052 }\
James Smarte8b62012007-08-02 11:10:09 -04002053 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002054 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002055 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002056 return -EINVAL;\
2057}
2058
James Smarte59058c2008-08-24 21:49:00 -04002059/**
James Smart3621a712009-04-06 18:47:14 -04002060 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002061 *
2062 * Description:
2063 * Macro that given an attr e.g. hba_queue_depth
2064 * expands into a function with the name lpfc_hba_queue_depth_store
2065 *
2066 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2067 * use the lpfc_##attr##_set function to set the value.
2068 * @cdev: class device that is converted into a Scsi_host.
2069 * @buf: contains the attribute value in decimal.
2070 * @count: not used.
2071 *
2072 * Returns:
2073 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2074 * length of buffer upon success.
2075 **/
James Smart3de2a652007-08-02 11:09:59 -04002076#define lpfc_vport_param_store(attr) \
2077static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002078lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2079 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002080{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002081 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002082 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002083 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002084 if (!isdigit(buf[0]))\
2085 return -EINVAL;\
2086 if (sscanf(buf, "%i", &val) != 1)\
2087 return -EINVAL;\
2088 if (lpfc_##attr##_set(vport, val) == 0) \
2089 return strlen(buf);\
2090 else \
2091 return -EINVAL;\
2092}
2093
2094
James Smart895427b2017-02-12 13:52:30 -08002095static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002096static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2097static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2098static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2099static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002100static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2101static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2102static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2103static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2104static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2105static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2106static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2107static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002108static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2109 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002110static DEVICE_ATTR(option_rom_version, S_IRUGO,
2111 lpfc_option_rom_version_show, NULL);
2112static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2113 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002114static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002115static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2116static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002117static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002118static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2119 lpfc_board_mode_show, lpfc_board_mode_store);
2120static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2121static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2122static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2123static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2124static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2125static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2126static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2127static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2128static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002129static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2130static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002131static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002132static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2133 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002134static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002135static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2136 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002137
James Smart352e5fd2016-12-30 06:57:47 -08002138static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002139#define WWN_SZ 8
2140/**
2141 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2142 * @buf: WWN string.
2143 * @cnt: Length of string.
2144 * @wwn: Array to receive converted wwn value.
2145 *
2146 * Returns:
2147 * -EINVAL if the buffer does not contain a valid wwn
2148 * 0 success
2149 **/
2150static size_t
2151lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2152{
2153 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002154
James Smart1ba981f2014-02-20 09:56:45 -05002155 /* Count may include a LF at end of string */
2156 if (buf[cnt-1] == '\n')
2157 cnt--;
2158
2159 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2160 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2161 return -EINVAL;
2162
2163 memset(wwn, 0, WWN_SZ);
2164
2165 /* Validate and store the new name */
2166 for (i = 0, j = 0; i < 16; i++) {
2167 if ((*buf >= 'a') && (*buf <= 'f'))
2168 j = ((j << 4) | ((*buf++ - 'a') + 10));
2169 else if ((*buf >= 'A') && (*buf <= 'F'))
2170 j = ((j << 4) | ((*buf++ - 'A') + 10));
2171 else if ((*buf >= '0') && (*buf <= '9'))
2172 j = ((j << 4) | (*buf++ - '0'));
2173 else
2174 return -EINVAL;
2175 if (i % 2) {
2176 wwn[i/2] = j & 0xff;
2177 j = 0;
2178 }
2179 }
2180 return 0;
2181}
James Smart352e5fd2016-12-30 06:57:47 -08002182/**
2183 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2184 * @dev: class device that is converted into a Scsi_host.
2185 * @attr: device attribute, not used.
2186 * @buf: containing the string lpfc_soft_wwn_key.
2187 * @count: must be size of lpfc_soft_wwn_key.
2188 *
2189 * Returns:
2190 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2191 * length of buf indicates success
2192 **/
2193static ssize_t
2194lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2195 const char *buf, size_t count)
2196{
2197 struct Scsi_Host *shost = class_to_shost(dev);
2198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2199 struct lpfc_hba *phba = vport->phba;
2200 unsigned int cnt = count;
2201
2202 /*
2203 * We're doing a simple sanity check for soft_wwpn setting.
2204 * We require that the user write a specific key to enable
2205 * the soft_wwpn attribute to be settable. Once the attribute
2206 * is written, the enable key resets. If further updates are
2207 * desired, the key must be written again to re-enable the
2208 * attribute.
2209 *
2210 * The "key" is not secret - it is a hardcoded string shown
2211 * here. The intent is to protect against the random user or
2212 * application that is just writing attributes.
2213 */
2214
2215 /* count may include a LF at end of string */
2216 if (buf[cnt-1] == '\n')
2217 cnt--;
2218
2219 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2220 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2221 return -EINVAL;
2222
2223 phba->soft_wwn_enable = 1;
2224
2225 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2226 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2227 phba->brd_no);
2228 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2229 " The soft_wwpn feature is not supported by Broadcom.");
2230
2231 return count;
2232}
2233static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2234 lpfc_soft_wwn_enable_store);
2235
2236/**
2237 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2238 * @dev: class device that is converted into a Scsi_host.
2239 * @attr: device attribute, not used.
2240 * @buf: on return contains the wwpn in hexadecimal.
2241 *
2242 * Returns: size of formatted string.
2243 **/
2244static ssize_t
2245lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2246 char *buf)
2247{
2248 struct Scsi_Host *shost = class_to_shost(dev);
2249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2250 struct lpfc_hba *phba = vport->phba;
2251
2252 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2253 (unsigned long long)phba->cfg_soft_wwpn);
2254}
2255
2256/**
2257 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2258 * @dev class device that is converted into a Scsi_host.
2259 * @attr: device attribute, not used.
2260 * @buf: contains the wwpn in hexadecimal.
2261 * @count: number of wwpn bytes in buf
2262 *
2263 * Returns:
2264 * -EACCES hba reset not enabled, adapter over temp
2265 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2266 * -EIO error taking adapter offline or online
2267 * value of count on success
2268 **/
2269static ssize_t
2270lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2271 const char *buf, size_t count)
2272{
2273 struct Scsi_Host *shost = class_to_shost(dev);
2274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2275 struct lpfc_hba *phba = vport->phba;
2276 struct completion online_compl;
2277 int stat1 = 0, stat2 = 0;
2278 unsigned int cnt = count;
2279 u8 wwpn[WWN_SZ];
2280 int rc;
2281
2282 if (!phba->cfg_enable_hba_reset)
2283 return -EACCES;
2284 spin_lock_irq(&phba->hbalock);
2285 if (phba->over_temp_state == HBA_OVER_TEMP) {
2286 spin_unlock_irq(&phba->hbalock);
2287 return -EACCES;
2288 }
2289 spin_unlock_irq(&phba->hbalock);
2290 /* count may include a LF at end of string */
2291 if (buf[cnt-1] == '\n')
2292 cnt--;
2293
2294 if (!phba->soft_wwn_enable)
2295 return -EINVAL;
2296
2297 /* lock setting wwpn, wwnn down */
2298 phba->soft_wwn_enable = 0;
2299
2300 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002301 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002302 /* not able to set wwpn, unlock it */
2303 phba->soft_wwn_enable = 1;
2304 return rc;
2305 }
2306
2307 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2308 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2309 if (phba->cfg_soft_wwnn)
2310 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2311
2312 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2313 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2314
2315 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2316 if (stat1)
2317 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2318 "0463 lpfc_soft_wwpn attribute set failed to "
2319 "reinit adapter - %d\n", stat1);
2320 init_completion(&online_compl);
2321 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2322 LPFC_EVT_ONLINE);
2323 if (rc == 0)
2324 return -ENOMEM;
2325
2326 wait_for_completion(&online_compl);
2327 if (stat2)
2328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2329 "0464 lpfc_soft_wwpn attribute set failed to "
2330 "reinit adapter - %d\n", stat2);
2331 return (stat1 || stat2) ? -EIO : count;
2332}
2333static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2334 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2335
2336/**
2337 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2338 * @dev: class device that is converted into a Scsi_host.
2339 * @attr: device attribute, not used.
2340 * @buf: on return contains the wwnn in hexadecimal.
2341 *
2342 * Returns: size of formatted string.
2343 **/
2344static ssize_t
2345lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2346 char *buf)
2347{
2348 struct Scsi_Host *shost = class_to_shost(dev);
2349 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2350 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2351 (unsigned long long)phba->cfg_soft_wwnn);
2352}
2353
2354/**
2355 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2356 * @cdev: class device that is converted into a Scsi_host.
2357 * @buf: contains the ww node name in hexadecimal.
2358 * @count: number of wwnn bytes in buf.
2359 *
2360 * Returns:
2361 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2362 * value of count on success
2363 **/
2364static ssize_t
2365lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2366 const char *buf, size_t count)
2367{
2368 struct Scsi_Host *shost = class_to_shost(dev);
2369 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2370 unsigned int cnt = count;
2371 u8 wwnn[WWN_SZ];
2372 int rc;
2373
2374 /* count may include a LF at end of string */
2375 if (buf[cnt-1] == '\n')
2376 cnt--;
2377
2378 if (!phba->soft_wwn_enable)
2379 return -EINVAL;
2380
2381 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002382 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002383 /* Allow wwnn to be set many times, as long as the enable
2384 * is set. However, once the wwpn is set, everything locks.
2385 */
2386 return rc;
2387 }
2388
2389 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2390
2391 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2392 "lpfc%d: soft_wwnn set. Value will take effect upon "
2393 "setting of the soft_wwpn\n", phba->brd_no);
2394
2395 return count;
2396}
2397static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2398 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002399
James Smart1ba981f2014-02-20 09:56:45 -05002400/**
2401 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2402 * Optimized Access Storage (OAS) operations.
2403 * @dev: class device that is converted into a Scsi_host.
2404 * @attr: device attribute, not used.
2405 * @buf: buffer for passing information.
2406 *
2407 * Returns:
2408 * value of count
2409 **/
2410static ssize_t
2411lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2412 char *buf)
2413{
2414 struct Scsi_Host *shost = class_to_shost(dev);
2415 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2416
2417 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2418 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2419}
2420
2421/**
2422 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2423 * Optimized Access Storage (OAS) operations.
2424 * @dev: class device that is converted into a Scsi_host.
2425 * @attr: device attribute, not used.
2426 * @buf: buffer for passing information.
2427 * @count: Size of the data buffer.
2428 *
2429 * Returns:
2430 * -EINVAL count is invalid, invalid wwpn byte invalid
2431 * -EPERM oas is not supported by hba
2432 * value of count on success
2433 **/
2434static ssize_t
2435lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2436 const char *buf, size_t count)
2437{
2438 struct Scsi_Host *shost = class_to_shost(dev);
2439 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2440 unsigned int cnt = count;
2441 uint8_t wwpn[WWN_SZ];
2442 int rc;
2443
James Smartf38fa0b2014-04-04 13:52:21 -04002444 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002445 return -EPERM;
2446
2447 /* count may include a LF at end of string */
2448 if (buf[cnt-1] == '\n')
2449 cnt--;
2450
2451 rc = lpfc_wwn_set(buf, cnt, wwpn);
2452 if (rc)
2453 return rc;
2454
2455 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2456 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2457 if (wwn_to_u64(wwpn) == 0)
2458 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2459 else
2460 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2461 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2462 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2463 return count;
2464}
2465static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2466 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2467
2468/**
James Smartc92c8412016-07-06 12:36:05 -07002469 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2470 * Optimized Access Storage (OAS) operations.
2471 * @dev: class device that is converted into a Scsi_host.
2472 * @attr: device attribute, not used.
2473 * @buf: buffer for passing information.
2474 *
2475 * Returns:
2476 * value of count
2477 **/
2478static ssize_t
2479lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2480 char *buf)
2481{
2482 struct Scsi_Host *shost = class_to_shost(dev);
2483 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2484
2485 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2486}
2487
2488/**
2489 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2490 * Optimized Access Storage (OAS) operations.
2491 * @dev: class device that is converted into a Scsi_host.
2492 * @attr: device attribute, not used.
2493 * @buf: buffer for passing information.
2494 * @count: Size of the data buffer.
2495 *
2496 * Returns:
2497 * -EINVAL count is invalid, invalid wwpn byte invalid
2498 * -EPERM oas is not supported by hba
2499 * value of count on success
2500 **/
2501static ssize_t
2502lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2503 const char *buf, size_t count)
2504{
2505 struct Scsi_Host *shost = class_to_shost(dev);
2506 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2507 unsigned int cnt = count;
2508 unsigned long val;
2509 int ret;
2510
2511 if (!phba->cfg_fof)
2512 return -EPERM;
2513
2514 /* count may include a LF at end of string */
2515 if (buf[cnt-1] == '\n')
2516 cnt--;
2517
2518 ret = kstrtoul(buf, 0, &val);
2519 if (ret || (val > 0x7f))
2520 return -EINVAL;
2521
2522 if (val)
2523 phba->cfg_oas_priority = (uint8_t)val;
2524 else
2525 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2526 return count;
2527}
2528static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2529 lpfc_oas_priority_show, lpfc_oas_priority_store);
2530
2531/**
James Smart1ba981f2014-02-20 09:56:45 -05002532 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2533 * for Optimized Access Storage (OAS) operations.
2534 * @dev: class device that is converted into a Scsi_host.
2535 * @attr: device attribute, not used.
2536 * @buf: buffer for passing information.
2537 *
2538 * Returns:
2539 * value of count on success
2540 **/
2541static ssize_t
2542lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2543 char *buf)
2544{
2545 struct Scsi_Host *shost = class_to_shost(dev);
2546 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2547
2548 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2549 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2550}
2551
2552/**
2553 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2554 * for Optimized Access Storage (OAS) operations.
2555 * @dev: class device that is converted into a Scsi_host.
2556 * @attr: device attribute, not used.
2557 * @buf: buffer for passing information.
2558 * @count: Size of the data buffer.
2559 *
2560 * Returns:
2561 * -EINVAL count is invalid, invalid wwpn byte invalid
2562 * -EPERM oas is not supported by hba
2563 * value of count on success
2564 **/
2565static ssize_t
2566lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2567 const char *buf, size_t count)
2568{
2569 struct Scsi_Host *shost = class_to_shost(dev);
2570 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2571 unsigned int cnt = count;
2572 uint8_t wwpn[WWN_SZ];
2573 int rc;
2574
James Smartf38fa0b2014-04-04 13:52:21 -04002575 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002576 return -EPERM;
2577
2578 /* count may include a LF at end of string */
2579 if (buf[cnt-1] == '\n')
2580 cnt--;
2581
2582 rc = lpfc_wwn_set(buf, cnt, wwpn);
2583 if (rc)
2584 return rc;
2585
2586 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2587 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2588 if (wwn_to_u64(wwpn) == 0)
2589 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2590 else
2591 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2592 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002593 if (phba->cfg_oas_priority == 0)
2594 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002595 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2596 return count;
2597}
2598static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2599 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2600
2601/**
2602 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2603 * of whether luns will be enabled or disabled
2604 * for Optimized Access Storage (OAS) operations.
2605 * @dev: class device that is converted into a Scsi_host.
2606 * @attr: device attribute, not used.
2607 * @buf: buffer for passing information.
2608 *
2609 * Returns:
2610 * size of formatted string.
2611 **/
2612static ssize_t
2613lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2614 char *buf)
2615{
2616 struct Scsi_Host *shost = class_to_shost(dev);
2617 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2618
2619 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2620}
2621
2622/**
2623 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2624 * of whether luns will be enabled or disabled
2625 * for 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 * @count: Size of the data buffer.
2630 *
2631 * Returns:
2632 * -EINVAL count is invalid, invalid wwpn byte invalid
2633 * -EPERM oas is not supported by hba
2634 * value of count on success
2635 **/
2636static ssize_t
2637lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2638 const char *buf, size_t count)
2639{
2640 struct Scsi_Host *shost = class_to_shost(dev);
2641 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2642 int val = 0;
2643
James Smartf38fa0b2014-04-04 13:52:21 -04002644 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002645 return -EPERM;
2646
2647 if (!isdigit(buf[0]))
2648 return -EINVAL;
2649
2650 if (sscanf(buf, "%i", &val) != 1)
2651 return -EINVAL;
2652
2653 if ((val != 0) && (val != 1))
2654 return -EINVAL;
2655
2656 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002657 return strlen(buf);
2658}
2659static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2660 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2661
2662/**
2663 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2664 * Storage (OAS) lun returned by the
2665 * lpfc_oas_lun_show function.
2666 * @dev: class device that is converted into a Scsi_host.
2667 * @attr: device attribute, not used.
2668 * @buf: buffer for passing information.
2669 *
2670 * Returns:
2671 * size of formatted string.
2672 **/
2673static ssize_t
2674lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2675 char *buf)
2676{
2677 struct Scsi_Host *shost = class_to_shost(dev);
2678 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2679
2680 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2681 return -EFAULT;
2682
2683 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2684}
2685static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2686 lpfc_oas_lun_status_show, NULL);
2687
2688
2689/**
2690 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2691 * (OAS) operations.
2692 * @phba: lpfc_hba pointer.
2693 * @ndlp: pointer to fcp target node.
2694 * @lun: the fc lun for setting oas state.
2695 * @oas_state: the oas state to be set to the lun.
2696 *
2697 * Returns:
2698 * SUCCESS : 0
2699 * -EPERM OAS is not enabled or not supported by this port.
2700 *
2701 */
2702static size_t
2703lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002704 uint8_t tgt_wwpn[], uint64_t lun,
2705 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002706{
2707
2708 int rc = 0;
2709
James Smartf38fa0b2014-04-04 13:52:21 -04002710 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002711 return -EPERM;
2712
2713 if (oas_state) {
2714 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002715 (struct lpfc_name *)tgt_wwpn,
2716 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002717 rc = -ENOMEM;
2718 } else {
2719 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002720 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002721 }
2722 return rc;
2723
2724}
2725
2726/**
2727 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2728 * Access Storage (OAS) operations.
2729 * @phba: lpfc_hba pointer.
2730 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2731 * @tgt_wwpn: wwpn of the target associated with the returned lun
2732 * @lun_status: status of the lun returned lun
2733 *
2734 * Returns the first or next lun enabled for OAS operations for the vport/target
2735 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2736 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2737 *
2738 * Return:
2739 * lun that is OAS enabled for the vport/target
2740 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2741 */
2742static uint64_t
2743lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002744 uint8_t tgt_wwpn[], uint32_t *lun_status,
2745 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002746{
2747 uint64_t found_lun;
2748
2749 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2750 return NOT_OAS_ENABLED_LUN;
2751 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2752 phba->sli4_hba.oas_next_vpt_wwpn,
2753 (struct lpfc_name *)
2754 phba->sli4_hba.oas_next_tgt_wwpn,
2755 &phba->sli4_hba.oas_next_lun,
2756 (struct lpfc_name *)vpt_wwpn,
2757 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002758 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002759 return found_lun;
2760 else
2761 return NOT_OAS_ENABLED_LUN;
2762}
2763
2764/**
2765 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2766 * @phba: lpfc_hba pointer.
2767 * @vpt_wwpn: vport wwpn by reference.
2768 * @tgt_wwpn: target wwpn by reference.
2769 * @lun: the fc lun for setting oas state.
2770 * @oas_state: the oas state to be set to the oas_lun.
2771 *
2772 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2773 * a lun for OAS operations.
2774 *
2775 * Return:
2776 * SUCCESS: 0
2777 * -ENOMEM: failed to enable an lun for OAS operations
2778 * -EPERM: OAS is not enabled
2779 */
2780static ssize_t
2781lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2782 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002783 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002784{
2785
2786 int rc;
2787
2788 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002789 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002790 return rc;
2791}
2792
2793/**
2794 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2795 * @dev: class device that is converted into a Scsi_host.
2796 * @attr: device attribute, not used.
2797 * @buf: buffer for passing information.
2798 *
2799 * This routine returns a lun enabled for OAS each time the function
2800 * is called.
2801 *
2802 * Returns:
2803 * SUCCESS: size of formatted string.
2804 * -EFAULT: target or vport wwpn was not set properly.
2805 * -EPERM: oas is not enabled.
2806 **/
2807static ssize_t
2808lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2809 char *buf)
2810{
2811 struct Scsi_Host *shost = class_to_shost(dev);
2812 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2813
2814 uint64_t oas_lun;
2815 int len = 0;
2816
James Smartf38fa0b2014-04-04 13:52:21 -04002817 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002818 return -EPERM;
2819
2820 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2821 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2822 return -EFAULT;
2823
2824 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2825 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2826 return -EFAULT;
2827
2828 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2829 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002830 &phba->cfg_oas_lun_status,
2831 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002832 if (oas_lun != NOT_OAS_ENABLED_LUN)
2833 phba->cfg_oas_flags |= OAS_LUN_VALID;
2834
2835 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2836
2837 return len;
2838}
2839
2840/**
2841 * lpfc_oas_lun_store - Sets the OAS state for lun
2842 * @dev: class device that is converted into a Scsi_host.
2843 * @attr: device attribute, not used.
2844 * @buf: buffer for passing information.
2845 *
2846 * This function sets the OAS state for lun. Before this function is called,
2847 * the vport wwpn, target wwpn, and oas state need to be set.
2848 *
2849 * Returns:
2850 * SUCCESS: size of formatted string.
2851 * -EFAULT: target or vport wwpn was not set properly.
2852 * -EPERM: oas is not enabled.
2853 * size of formatted string.
2854 **/
2855static ssize_t
2856lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2857 const char *buf, size_t count)
2858{
2859 struct Scsi_Host *shost = class_to_shost(dev);
2860 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2861 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002862 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002863 ssize_t rc;
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 (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2869 return -EFAULT;
2870
2871 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2872 return -EFAULT;
2873
2874 if (!isdigit(buf[0]))
2875 return -EINVAL;
2876
2877 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2878 return -EINVAL;
2879
James Smartb5749fe2016-12-19 15:07:26 -08002880 pri = phba->cfg_oas_priority;
2881 if (pri == 0)
2882 pri = phba->cfg_XLanePriority;
2883
James Smart1ba981f2014-02-20 09:56:45 -05002884 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002885 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2886 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002887 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2888 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002889 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002890
2891 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002892 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002893 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002894 if (rc)
2895 return rc;
2896
2897 return count;
2898}
2899static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2900 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002901
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002902static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002903module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002904MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2905 " 0 - none,"
2906 " 1 - poll with interrupts enabled"
2907 " 3 - poll and disable FCP ring interrupts");
2908
Tony Jonesee959b02008-02-22 00:13:36 +01002909static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2910 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05002911
James Smart12247e82016-07-06 12:36:09 -07002912LPFC_ATTR(sli_mode, 0, 0, 3,
2913 "SLI mode selector:"
2914 " 0 - auto (SLI-3 if supported),"
2915 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2916 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05002917
James Smart458c0832016-07-06 12:36:07 -07002918LPFC_ATTR_R(enable_npiv, 1, 0, 1,
2919 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05002920
James Smart7d791df2011-07-22 18:37:52 -04002921LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
2922 "FCF Fast failover=1 Priority failover=2");
2923
James Smarte5771b42013-03-01 16:37:14 -05002924/*
2925# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
2926# 0x0 = disabled, XRI/OXID use not tracked.
2927# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
2928# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
2929*/
James Smart31202b02016-10-13 15:06:08 -07002930LPFC_ATTR_R(enable_rrq, 2, 0, 2,
2931 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05002932
dea31012005-04-17 16:05:31 -05002933/*
James Smart84d1b002010-02-12 14:42:33 -05002934# lpfc_suppress_link_up: Bring link up at initialization
2935# 0x0 = bring link up (issue MBX_INIT_LINK)
2936# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2937# 0x2 = never bring up link
2938# Default value is 0.
2939*/
James Smarte40a02c2010-02-26 14:13:54 -05002940LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2941 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2942 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04002943/*
2944# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2945# 1 - (1024)
2946# 2 - (2048)
2947# 3 - (3072)
2948# 4 - (4096)
2949# 5 - (5120)
2950*/
2951static ssize_t
2952lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2953{
2954 struct Scsi_Host *shost = class_to_shost(dev);
2955 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2956
2957 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2958}
2959
2960static DEVICE_ATTR(iocb_hw, S_IRUGO,
2961 lpfc_iocb_hw_show, NULL);
2962static ssize_t
2963lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2964{
2965 struct Scsi_Host *shost = class_to_shost(dev);
2966 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08002967 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04002968
James Smart895427b2017-02-12 13:52:30 -08002969 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04002970}
2971
2972static DEVICE_ATTR(txq_hw, S_IRUGO,
2973 lpfc_txq_hw_show, NULL);
2974static ssize_t
2975lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2976 char *buf)
2977{
2978 struct Scsi_Host *shost = class_to_shost(dev);
2979 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08002980 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04002981
James Smart895427b2017-02-12 13:52:30 -08002982 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04002983}
2984
2985static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2986 lpfc_txcmplq_hw_show, NULL);
2987
James Smart0d8c8ba2016-10-13 15:06:07 -07002988LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04002989 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05002990
2991/*
James Smartc01f3202006-08-18 17:47:08 -04002992# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2993# until the timer expires. Value range is [0,255]. Default value is 30.
2994*/
2995static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2996static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2997module_param(lpfc_nodev_tmo, int, 0);
2998MODULE_PARM_DESC(lpfc_nodev_tmo,
2999 "Seconds driver will hold I/O waiting "
3000 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003001
3002/**
James Smart3621a712009-04-06 18:47:14 -04003003 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003004 * @dev: class converted to a Scsi_host structure.
3005 * @attr: device attribute, not used.
3006 * @buf: on return contains the dev loss timeout in decimal.
3007 *
3008 * Returns: size of formatted string.
3009 **/
James Smartc01f3202006-08-18 17:47:08 -04003010static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003011lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3012 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003013{
Tony Jonesee959b02008-02-22 00:13:36 +01003014 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003016
James Smart3de2a652007-08-02 11:09:59 -04003017 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003018}
3019
James Smarte59058c2008-08-24 21:49:00 -04003020/**
James Smart3621a712009-04-06 18:47:14 -04003021 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003022 * @vport: lpfc vport structure pointer.
3023 * @val: contains the nodev timeout value.
3024 *
3025 * Description:
3026 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3027 * a kernel error message is printed and zero is returned.
3028 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3029 * Otherwise nodev tmo is set to the default value.
3030 *
3031 * Returns:
3032 * zero if already set or if val is in range
3033 * -EINVAL val out of range
3034 **/
James Smartc01f3202006-08-18 17:47:08 -04003035static int
James Smart3de2a652007-08-02 11:09:59 -04003036lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003037{
James Smart3de2a652007-08-02 11:09:59 -04003038 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3039 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3040 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003041 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003042 "0407 Ignoring lpfc_nodev_tmo module "
3043 "parameter because lpfc_devloss_tmo "
3044 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003045 return 0;
3046 }
3047
3048 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003049 vport->cfg_nodev_tmo = val;
3050 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003051 return 0;
3052 }
James Smarte8b62012007-08-02 11:10:09 -04003053 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3054 "0400 lpfc_nodev_tmo attribute cannot be set to"
3055 " %d, allowed range is [%d, %d]\n",
3056 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003057 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003058 return -EINVAL;
3059}
3060
James Smarte59058c2008-08-24 21:49:00 -04003061/**
James Smart3621a712009-04-06 18:47:14 -04003062 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003063 * @vport: lpfc vport structure pointer.
3064 *
3065 * Description:
3066 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3067 **/
James Smart7054a602007-04-25 09:52:34 -04003068static void
James Smart3de2a652007-08-02 11:09:59 -04003069lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003070{
James Smart858c9f62007-06-17 19:56:39 -05003071 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003072 struct lpfc_nodelist *ndlp;
3073
James Smart51ef4c22007-08-02 11:10:31 -04003074 shost = lpfc_shost_from_vport(vport);
3075 spin_lock_irq(shost->host_lock);
3076 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003077 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003078 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3079 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003080}
3081
James Smarte59058c2008-08-24 21:49:00 -04003082/**
James Smart3621a712009-04-06 18:47:14 -04003083 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003084 * @vport: lpfc vport structure pointer.
3085 * @val: contains the tmo value.
3086 *
3087 * Description:
3088 * If the devloss tmo is already set or the vport dev loss tmo has changed
3089 * then a kernel error message is printed and zero is returned.
3090 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3091 * Otherwise nodev tmo is set to the default value.
3092 *
3093 * Returns:
3094 * zero if already set or if val is in range
3095 * -EINVAL val out of range
3096 **/
James Smartc01f3202006-08-18 17:47:08 -04003097static int
James Smart3de2a652007-08-02 11:09:59 -04003098lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003099{
James Smart3de2a652007-08-02 11:09:59 -04003100 if (vport->dev_loss_tmo_changed ||
3101 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003102 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003103 "0401 Ignoring change to lpfc_nodev_tmo "
3104 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003105 return 0;
3106 }
James Smartc01f3202006-08-18 17:47:08 -04003107 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003108 vport->cfg_nodev_tmo = val;
3109 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003110 /*
3111 * For compat: set the fc_host dev loss so new rports
3112 * will get the value.
3113 */
3114 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003115 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003116 return 0;
3117 }
James Smarte8b62012007-08-02 11:10:09 -04003118 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003119 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003120 "%d, allowed range is [%d, %d]\n",
3121 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003122 return -EINVAL;
3123}
3124
James Smart3de2a652007-08-02 11:09:59 -04003125lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003126
Tony Jonesee959b02008-02-22 00:13:36 +01003127static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3128 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003129
3130/*
3131# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3132# disappear until the timer expires. Value range is [0,255]. Default
3133# value is 30.
3134*/
James Smartab56dc22011-02-16 12:39:57 -05003135module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003136MODULE_PARM_DESC(lpfc_devloss_tmo,
3137 "Seconds driver will hold I/O waiting "
3138 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003139lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3140 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3141lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003142
3143/**
James Smart3621a712009-04-06 18:47:14 -04003144 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003145 * @vport: lpfc vport structure pointer.
3146 * @val: contains the tmo value.
3147 *
3148 * Description:
3149 * If val is in a valid range then set the vport nodev tmo,
3150 * devloss tmo, also set the vport dev loss tmo changed flag.
3151 * Else a kernel error message is printed.
3152 *
3153 * Returns:
3154 * zero if val is in range
3155 * -EINVAL val out of range
3156 **/
James Smartc01f3202006-08-18 17:47:08 -04003157static int
James Smart3de2a652007-08-02 11:09:59 -04003158lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003159{
3160 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003161 vport->cfg_nodev_tmo = val;
3162 vport->cfg_devloss_tmo = val;
3163 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003164 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003165 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003166 return 0;
3167 }
3168
James Smarte8b62012007-08-02 11:10:09 -04003169 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003170 "0404 lpfc_devloss_tmo attribute cannot be set to "
3171 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003172 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003173 return -EINVAL;
3174}
3175
James Smart3de2a652007-08-02 11:09:59 -04003176lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003177static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3178 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003179
3180/*
James Smart895427b2017-02-12 13:52:30 -08003181 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3182 * Supported Values: 1 - register just FCP
3183 * 3 - register both FCP and NVME
3184 * Supported values are [1,3]. Default value is 3
3185 */
3186LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3187 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3188 "Define fc4 type to register with fabric.");
3189
3190/*
3191 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3192 * This parameter is only used if:
3193 * lpfc_enable_fc4_type is 3 - register both FCP and NVME
3194 *
3195 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3196 * The remaining XRIs get split up based on lpfc_xri_split per port:
3197 *
3198 * Supported Values are in percentages
3199 * the xri_split value is the percentage the SCSI port will get. The remaining
3200 * percentage will go to NVME.
3201 */
3202LPFC_ATTR_R(xri_split, 50, 10, 90,
3203 "Division of XRI resources between SCSI and NVME");
3204
3205/*
dea31012005-04-17 16:05:31 -05003206# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3207# deluged with LOTS of information.
3208# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003209# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003210*/
James Smartf4b4c682009-05-22 14:53:12 -04003211LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003212 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003213
3214/*
James Smart7ee5d432007-10-27 13:37:17 -04003215# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3216# objects that have been registered with the nameserver after login.
3217*/
James Smartcf971242012-03-01 22:37:32 -05003218LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003219 "Deregister nameserver objects before LOGO");
3220
3221/*
dea31012005-04-17 16:05:31 -05003222# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003223# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3224# If this parameter value is greater than 1/8th the maximum number of exchanges
3225# supported by the HBA port, then the lun queue depth will be reduced to
3226# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003227*/
James Smart572709e2013-07-15 18:32:43 -04003228LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003229 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003230
3231/*
James Smart7dc517d2010-07-14 15:32:10 -04003232# tgt_queue_depth: This parameter is used to limit the number of outstanding
3233# commands per target port. Value range is [10,65535]. Default value is 65535.
3234*/
3235LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003236 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003237
3238/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003239# hba_queue_depth: This parameter is used to limit the number of outstanding
3240# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3241# value is greater than the maximum number of exchanges supported by the HBA,
3242# then maximum number of exchanges supported by the HBA is used to determine
3243# the hba_queue_depth.
3244*/
3245LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3246 "Max number of FCP commands we can queue to a lpfc HBA");
3247
3248/*
James Smart92d7f7b2007-06-17 19:56:38 -05003249# peer_port_login: This parameter allows/prevents logins
3250# between peer ports hosted on the same physical port.
3251# When this parameter is set 0 peer ports of same physical port
3252# are not allowed to login to each other.
3253# When this parameter is set 1 peer ports of same physical port
3254# are allowed to login to each other.
3255# Default value of this parameter is 0.
3256*/
James Smart3de2a652007-08-02 11:09:59 -04003257LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3258 "Allow peer ports on the same physical port to login to each "
3259 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003260
3261/*
James Smart3de2a652007-08-02 11:09:59 -04003262# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003263# between Virtual Ports and remote initiators.
3264# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3265# other initiators and will attempt to PLOGI all remote ports.
3266# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3267# remote ports and will not attempt to PLOGI to other initiators.
3268# This parameter does not restrict to the physical port.
3269# This parameter does not restrict logins to Fabric resident remote ports.
3270# Default value of this parameter is 1.
3271*/
James Smart3de2a652007-08-02 11:09:59 -04003272static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003273module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003274MODULE_PARM_DESC(lpfc_restrict_login,
3275 "Restrict virtual ports login to remote initiators.");
3276lpfc_vport_param_show(restrict_login);
3277
James Smarte59058c2008-08-24 21:49:00 -04003278/**
James Smart3621a712009-04-06 18:47:14 -04003279 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003280 * @vport: lpfc vport structure pointer.
3281 * @val: contains the restrict login value.
3282 *
3283 * Description:
3284 * If val is not in a valid range then log a kernel error message and set
3285 * the vport restrict login to one.
3286 * If the port type is physical clear the restrict login flag and return.
3287 * Else set the restrict login flag to val.
3288 *
3289 * Returns:
3290 * zero if val is in range
3291 * -EINVAL val out of range
3292 **/
James Smart3de2a652007-08-02 11:09:59 -04003293static int
3294lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3295{
3296 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003297 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003298 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003299 "be set to %d, allowed range is [0, 1]\n",
3300 val);
James Smart3de2a652007-08-02 11:09:59 -04003301 vport->cfg_restrict_login = 1;
3302 return -EINVAL;
3303 }
3304 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3305 vport->cfg_restrict_login = 0;
3306 return 0;
3307 }
3308 vport->cfg_restrict_login = val;
3309 return 0;
3310}
3311
James Smarte59058c2008-08-24 21:49:00 -04003312/**
James Smart3621a712009-04-06 18:47:14 -04003313 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003314 * @vport: lpfc vport structure pointer.
3315 * @val: contains the restrict login value.
3316 *
3317 * Description:
3318 * If val is not in a valid range then log a kernel error message and set
3319 * the vport restrict login to one.
3320 * If the port type is physical and the val is not zero log a kernel
3321 * error message, clear the restrict login flag and return zero.
3322 * Else set the restrict login flag to val.
3323 *
3324 * Returns:
3325 * zero if val is in range
3326 * -EINVAL val out of range
3327 **/
James Smart3de2a652007-08-02 11:09:59 -04003328static int
3329lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3330{
3331 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003332 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003333 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003334 "be set to %d, allowed range is [0, 1]\n",
3335 val);
James Smart3de2a652007-08-02 11:09:59 -04003336 vport->cfg_restrict_login = 1;
3337 return -EINVAL;
3338 }
3339 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003340 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3341 "0468 lpfc_restrict_login must be 0 for "
3342 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003343 vport->cfg_restrict_login = 0;
3344 return 0;
3345 }
3346 vport->cfg_restrict_login = val;
3347 return 0;
3348}
3349lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003350static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3351 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003352
3353/*
dea31012005-04-17 16:05:31 -05003354# Some disk devices have a "select ID" or "select Target" capability.
3355# From a protocol standpoint "select ID" usually means select the
3356# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3357# annex" which contains a table that maps a "select ID" (a number
3358# between 0 and 7F) to an ALPA. By default, for compatibility with
3359# older drivers, the lpfc driver scans this table from low ALPA to high
3360# ALPA.
3361#
3362# Turning on the scan-down variable (on = 1, off = 0) will
3363# cause the lpfc driver to use an inverted table, effectively
3364# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3365#
3366# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3367# and will not work across a fabric. Also this parameter will take
3368# effect only in the case when ALPA map is not available.)
3369*/
James Smart3de2a652007-08-02 11:09:59 -04003370LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3371 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003372
3373/*
dea31012005-04-17 16:05:31 -05003374# lpfc_topology: link topology for init link
3375# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003376# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003377# 0x02 = attempt point-to-point mode only
3378# 0x04 = attempt loop mode only
3379# 0x06 = attempt point-to-point mode then loop
3380# Set point-to-point mode if you want to run as an N_Port.
3381# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3382# Default value is 0.
3383*/
James Smart0a035432016-10-13 15:06:10 -07003384LPFC_ATTR(topology, 0, 0, 6,
3385 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003386
3387/**
James Smart3621a712009-04-06 18:47:14 -04003388 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003389 * @phba: lpfc_hba pointer.
3390 * @val: topology value.
3391 *
3392 * Description:
3393 * If val is in a valid range then set the adapter's topology field and
3394 * issue a lip; if the lip fails reset the topology to the old value.
3395 *
3396 * If the value is not in range log a kernel error message and return an error.
3397 *
3398 * Returns:
3399 * zero if val is in range and lip okay
3400 * non-zero return value from lpfc_issue_lip()
3401 * -EINVAL val out of range
3402 **/
James Smarta257bf92009-04-06 18:48:10 -04003403static ssize_t
3404lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3405 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003406{
James Smarta257bf92009-04-06 18:48:10 -04003407 struct Scsi_Host *shost = class_to_shost(dev);
3408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3409 struct lpfc_hba *phba = vport->phba;
3410 int val = 0;
3411 int nolip = 0;
3412 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003413 int err;
3414 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003415
3416 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3417 nolip = 1;
3418 val_buf = &buf[strlen("nolip ")];
3419 }
3420
3421 if (!isdigit(val_buf[0]))
3422 return -EINVAL;
3423 if (sscanf(val_buf, "%i", &val) != 1)
3424 return -EINVAL;
3425
James Smart83108bd2008-01-11 01:53:09 -05003426 if (val >= 0 && val <= 6) {
3427 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003428 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3429 val == 4) {
3430 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3431 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003432 val);
James Smartff78d8f2011-12-13 13:21:35 -05003433 return -EINVAL;
3434 }
James Smartd38dd522015-08-31 16:48:17 -04003435 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3436 val == 4) {
3437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3438 "3114 Loop mode not supported\n");
3439 return -EINVAL;
3440 }
3441 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003442 if (nolip)
3443 return strlen(buf);
3444
James Smart88a2cfb2011-07-22 18:36:33 -04003445 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3446 "3054 lpfc_topology changed from %d to %d\n",
3447 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003448 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3449 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003450 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003451 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003452 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003453 return -EINVAL;
3454 } else
3455 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003456 }
3457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3458 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3459 "allowed range is [0, 6]\n",
3460 phba->brd_no, val);
3461 return -EINVAL;
3462}
James Smart0a035432016-10-13 15:06:10 -07003463
James Smart83108bd2008-01-11 01:53:09 -05003464lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003465static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003466 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003467
James Smart21e9a0a2009-05-22 14:53:21 -04003468/**
3469 * lpfc_static_vport_show: Read callback function for
3470 * lpfc_static_vport sysfs file.
3471 * @dev: Pointer to class device object.
3472 * @attr: device attribute structure.
3473 * @buf: Data buffer.
3474 *
3475 * This function is the read call back function for
3476 * lpfc_static_vport sysfs file. The lpfc_static_vport
3477 * sysfs file report the mageability of the vport.
3478 **/
3479static ssize_t
3480lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3481 char *buf)
3482{
3483 struct Scsi_Host *shost = class_to_shost(dev);
3484 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3485 if (vport->vport_flag & STATIC_VPORT)
3486 sprintf(buf, "1\n");
3487 else
3488 sprintf(buf, "0\n");
3489
3490 return strlen(buf);
3491}
3492
3493/*
3494 * Sysfs attribute to control the statistical data collection.
3495 */
3496static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3497 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003498
3499/**
James Smart3621a712009-04-06 18:47:14 -04003500 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003501 * @dev: Pointer to class device.
3502 * @buf: Data buffer.
3503 * @count: Size of the data buffer.
3504 *
3505 * This function get called when an user write to the lpfc_stat_data_ctrl
3506 * sysfs file. This function parse the command written to the sysfs file
3507 * and take appropriate action. These commands are used for controlling
3508 * driver statistical data collection.
3509 * Following are the command this function handles.
3510 *
3511 * setbucket <bucket_type> <base> <step>
3512 * = Set the latency buckets.
3513 * destroybucket = destroy all the buckets.
3514 * start = start data collection
3515 * stop = stop data collection
3516 * reset = reset the collected data
3517 **/
3518static ssize_t
3519lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3520 const char *buf, size_t count)
3521{
3522 struct Scsi_Host *shost = class_to_shost(dev);
3523 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3524 struct lpfc_hba *phba = vport->phba;
3525#define LPFC_MAX_DATA_CTRL_LEN 1024
3526 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3527 unsigned long i;
3528 char *str_ptr, *token;
3529 struct lpfc_vport **vports;
3530 struct Scsi_Host *v_shost;
3531 char *bucket_type_str, *base_str, *step_str;
3532 unsigned long base, step, bucket_type;
3533
3534 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003535 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003536 return -EINVAL;
3537
James Smarteb016562014-09-03 12:58:06 -04003538 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003539 str_ptr = &bucket_data[0];
3540 /* Ignore this token - this is command token */
3541 token = strsep(&str_ptr, "\t ");
3542 if (!token)
3543 return -EINVAL;
3544
3545 bucket_type_str = strsep(&str_ptr, "\t ");
3546 if (!bucket_type_str)
3547 return -EINVAL;
3548
3549 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3550 bucket_type = LPFC_LINEAR_BUCKET;
3551 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3552 bucket_type = LPFC_POWER2_BUCKET;
3553 else
3554 return -EINVAL;
3555
3556 base_str = strsep(&str_ptr, "\t ");
3557 if (!base_str)
3558 return -EINVAL;
3559 base = simple_strtoul(base_str, NULL, 0);
3560
3561 step_str = strsep(&str_ptr, "\t ");
3562 if (!step_str)
3563 return -EINVAL;
3564 step = simple_strtoul(step_str, NULL, 0);
3565 if (!step)
3566 return -EINVAL;
3567
3568 /* Block the data collection for every vport */
3569 vports = lpfc_create_vport_work_array(phba);
3570 if (vports == NULL)
3571 return -ENOMEM;
3572
James Smartf4b4c682009-05-22 14:53:12 -04003573 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003574 v_shost = lpfc_shost_from_vport(vports[i]);
3575 spin_lock_irq(v_shost->host_lock);
3576 /* Block and reset data collection */
3577 vports[i]->stat_data_blocked = 1;
3578 if (vports[i]->stat_data_enabled)
3579 lpfc_vport_reset_stat_data(vports[i]);
3580 spin_unlock_irq(v_shost->host_lock);
3581 }
3582
3583 /* Set the bucket attributes */
3584 phba->bucket_type = bucket_type;
3585 phba->bucket_base = base;
3586 phba->bucket_step = step;
3587
James Smartf4b4c682009-05-22 14:53:12 -04003588 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003589 v_shost = lpfc_shost_from_vport(vports[i]);
3590
3591 /* Unblock data collection */
3592 spin_lock_irq(v_shost->host_lock);
3593 vports[i]->stat_data_blocked = 0;
3594 spin_unlock_irq(v_shost->host_lock);
3595 }
3596 lpfc_destroy_vport_work_array(phba, vports);
3597 return strlen(buf);
3598 }
3599
3600 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3601 vports = lpfc_create_vport_work_array(phba);
3602 if (vports == NULL)
3603 return -ENOMEM;
3604
James Smartf4b4c682009-05-22 14:53:12 -04003605 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003606 v_shost = lpfc_shost_from_vport(vports[i]);
3607 spin_lock_irq(shost->host_lock);
3608 vports[i]->stat_data_blocked = 1;
3609 lpfc_free_bucket(vport);
3610 vport->stat_data_enabled = 0;
3611 vports[i]->stat_data_blocked = 0;
3612 spin_unlock_irq(shost->host_lock);
3613 }
3614 lpfc_destroy_vport_work_array(phba, vports);
3615 phba->bucket_type = LPFC_NO_BUCKET;
3616 phba->bucket_base = 0;
3617 phba->bucket_step = 0;
3618 return strlen(buf);
3619 }
3620
3621 if (!strncmp(buf, "start", strlen("start"))) {
3622 /* If no buckets configured return error */
3623 if (phba->bucket_type == LPFC_NO_BUCKET)
3624 return -EINVAL;
3625 spin_lock_irq(shost->host_lock);
3626 if (vport->stat_data_enabled) {
3627 spin_unlock_irq(shost->host_lock);
3628 return strlen(buf);
3629 }
3630 lpfc_alloc_bucket(vport);
3631 vport->stat_data_enabled = 1;
3632 spin_unlock_irq(shost->host_lock);
3633 return strlen(buf);
3634 }
3635
3636 if (!strncmp(buf, "stop", strlen("stop"))) {
3637 spin_lock_irq(shost->host_lock);
3638 if (vport->stat_data_enabled == 0) {
3639 spin_unlock_irq(shost->host_lock);
3640 return strlen(buf);
3641 }
3642 lpfc_free_bucket(vport);
3643 vport->stat_data_enabled = 0;
3644 spin_unlock_irq(shost->host_lock);
3645 return strlen(buf);
3646 }
3647
3648 if (!strncmp(buf, "reset", strlen("reset"))) {
3649 if ((phba->bucket_type == LPFC_NO_BUCKET)
3650 || !vport->stat_data_enabled)
3651 return strlen(buf);
3652 spin_lock_irq(shost->host_lock);
3653 vport->stat_data_blocked = 1;
3654 lpfc_vport_reset_stat_data(vport);
3655 vport->stat_data_blocked = 0;
3656 spin_unlock_irq(shost->host_lock);
3657 return strlen(buf);
3658 }
3659 return -EINVAL;
3660}
3661
3662
3663/**
James Smart3621a712009-04-06 18:47:14 -04003664 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003665 * @dev: Pointer to class device object.
3666 * @buf: Data buffer.
3667 *
3668 * This function is the read call back function for
3669 * lpfc_stat_data_ctrl sysfs file. This function report the
3670 * current statistical data collection state.
3671 **/
3672static ssize_t
3673lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3674 char *buf)
3675{
3676 struct Scsi_Host *shost = class_to_shost(dev);
3677 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3678 struct lpfc_hba *phba = vport->phba;
3679 int index = 0;
3680 int i;
3681 char *bucket_type;
3682 unsigned long bucket_value;
3683
3684 switch (phba->bucket_type) {
3685 case LPFC_LINEAR_BUCKET:
3686 bucket_type = "linear";
3687 break;
3688 case LPFC_POWER2_BUCKET:
3689 bucket_type = "power2";
3690 break;
3691 default:
3692 bucket_type = "No Bucket";
3693 break;
3694 }
3695
3696 sprintf(&buf[index], "Statistical Data enabled :%d, "
3697 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3698 " Bucket step :%d\nLatency Ranges :",
3699 vport->stat_data_enabled, vport->stat_data_blocked,
3700 bucket_type, phba->bucket_base, phba->bucket_step);
3701 index = strlen(buf);
3702 if (phba->bucket_type != LPFC_NO_BUCKET) {
3703 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3704 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3705 bucket_value = phba->bucket_base +
3706 phba->bucket_step * i;
3707 else
3708 bucket_value = phba->bucket_base +
3709 (1 << i) * phba->bucket_step;
3710
3711 if (index + 10 > PAGE_SIZE)
3712 break;
3713 sprintf(&buf[index], "%08ld ", bucket_value);
3714 index = strlen(buf);
3715 }
3716 }
3717 sprintf(&buf[index], "\n");
3718 return strlen(buf);
3719}
3720
3721/*
3722 * Sysfs attribute to control the statistical data collection.
3723 */
3724static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3725 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3726
3727/*
3728 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3729 */
3730
3731/*
3732 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3733 * for each target.
3734 */
3735#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3736#define MAX_STAT_DATA_SIZE_PER_TARGET \
3737 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3738
3739
3740/**
James Smart3621a712009-04-06 18:47:14 -04003741 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003742 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003743 * @kobj: Pointer to the kernel object
3744 * @bin_attr: Attribute object
3745 * @buff: Buffer pointer
3746 * @off: File offset
3747 * @count: Buffer size
3748 *
3749 * This function is the read call back function for lpfc_drvr_stat_data
3750 * sysfs file. This function export the statistical data to user
3751 * applications.
3752 **/
3753static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003754sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3755 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003756 char *buf, loff_t off, size_t count)
3757{
3758 struct device *dev = container_of(kobj, struct device,
3759 kobj);
3760 struct Scsi_Host *shost = class_to_shost(dev);
3761 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3762 struct lpfc_hba *phba = vport->phba;
3763 int i = 0, index = 0;
3764 unsigned long nport_index;
3765 struct lpfc_nodelist *ndlp = NULL;
3766 nport_index = (unsigned long)off /
3767 MAX_STAT_DATA_SIZE_PER_TARGET;
3768
3769 if (!vport->stat_data_enabled || vport->stat_data_blocked
3770 || (phba->bucket_type == LPFC_NO_BUCKET))
3771 return 0;
3772
3773 spin_lock_irq(shost->host_lock);
3774 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3775 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3776 continue;
3777
3778 if (nport_index > 0) {
3779 nport_index--;
3780 continue;
3781 }
3782
3783 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3784 > count)
3785 break;
3786
3787 if (!ndlp->lat_data)
3788 continue;
3789
3790 /* Print the WWN */
3791 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3792 ndlp->nlp_portname.u.wwn[0],
3793 ndlp->nlp_portname.u.wwn[1],
3794 ndlp->nlp_portname.u.wwn[2],
3795 ndlp->nlp_portname.u.wwn[3],
3796 ndlp->nlp_portname.u.wwn[4],
3797 ndlp->nlp_portname.u.wwn[5],
3798 ndlp->nlp_portname.u.wwn[6],
3799 ndlp->nlp_portname.u.wwn[7]);
3800
3801 index = strlen(buf);
3802
3803 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3804 sprintf(&buf[index], "%010u,",
3805 ndlp->lat_data[i].cmd_count);
3806 index = strlen(buf);
3807 }
3808 sprintf(&buf[index], "\n");
3809 index = strlen(buf);
3810 }
3811 spin_unlock_irq(shost->host_lock);
3812 return index;
3813}
3814
3815static struct bin_attribute sysfs_drvr_stat_data_attr = {
3816 .attr = {
3817 .name = "lpfc_drvr_stat_data",
3818 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003819 },
3820 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3821 .read = sysfs_drvr_stat_data_read,
3822 .write = NULL,
3823};
3824
dea31012005-04-17 16:05:31 -05003825/*
3826# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3827# connection.
James Smart76a95d72010-11-20 23:11:48 -05003828# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003829*/
James Smarte59058c2008-08-24 21:49:00 -04003830/**
James Smart3621a712009-04-06 18:47:14 -04003831 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003832 * @phba: lpfc_hba pointer.
3833 * @val: link speed value.
3834 *
3835 * Description:
3836 * If val is in a valid range then set the adapter's link speed field and
3837 * issue a lip; if the lip fails reset the link speed to the old value.
3838 *
3839 * Notes:
3840 * If the value is not in range log a kernel error message and return an error.
3841 *
3842 * Returns:
3843 * zero if val is in range and lip okay.
3844 * non-zero return value from lpfc_issue_lip()
3845 * -EINVAL val out of range
3846 **/
James Smarta257bf92009-04-06 18:48:10 -04003847static ssize_t
3848lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3849 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003850{
James Smarta257bf92009-04-06 18:48:10 -04003851 struct Scsi_Host *shost = class_to_shost(dev);
3852 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3853 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003854 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003855 int nolip = 0;
3856 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003857 int err;
James Smartc6918162016-10-13 15:06:16 -07003858 uint32_t prev_val, if_type;
3859
3860 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3861 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3862 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3863 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05003864
James Smarta257bf92009-04-06 18:48:10 -04003865 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3866 nolip = 1;
3867 val_buf = &buf[strlen("nolip ")];
3868 }
3869
3870 if (!isdigit(val_buf[0]))
3871 return -EINVAL;
3872 if (sscanf(val_buf, "%i", &val) != 1)
3873 return -EINVAL;
3874
James Smart88a2cfb2011-07-22 18:36:33 -04003875 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3876 "3055 lpfc_link_speed changed from %d to %d %s\n",
3877 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3878
James Smart76a95d72010-11-20 23:11:48 -05003879 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3880 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3881 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3882 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3883 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003884 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3885 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003886 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3887 "2879 lpfc_link_speed attribute cannot be set "
3888 "to %d. Speed is not supported by this port.\n",
3889 val);
James Smart83108bd2008-01-11 01:53:09 -05003890 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003891 }
James Smartff78d8f2011-12-13 13:21:35 -05003892 if (val == LPFC_USER_LINK_SPEED_16G &&
3893 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3894 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3895 "3112 lpfc_link_speed attribute cannot be set "
3896 "to %d. Speed is not supported in loop mode.\n",
3897 val);
3898 return -EINVAL;
3899 }
James Smart76a95d72010-11-20 23:11:48 -05003900 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3901 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003902 prev_val = phba->cfg_link_speed;
3903 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04003904 if (nolip)
3905 return strlen(buf);
3906
James Smart83108bd2008-01-11 01:53:09 -05003907 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003908 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003909 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003910 return -EINVAL;
3911 } else
3912 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003913 }
James Smart83108bd2008-01-11 01:53:09 -05003914 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05003915 "0469 lpfc_link_speed attribute cannot be set to %d, "
3916 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05003917 return -EINVAL;
3918}
3919
3920static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05003921module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05003922MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
3923lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04003924
3925/**
James Smart3621a712009-04-06 18:47:14 -04003926 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003927 * @phba: lpfc_hba pointer.
3928 * @val: link speed value.
3929 *
3930 * Description:
3931 * If val is in a valid range then set the adapter's link speed field.
3932 *
3933 * Notes:
3934 * If the value is not in range log a kernel error message, clear the link
3935 * speed and return an error.
3936 *
3937 * Returns:
3938 * zero if val saved.
3939 * -EINVAL val out of range
3940 **/
James Smart83108bd2008-01-11 01:53:09 -05003941static int
3942lpfc_link_speed_init(struct lpfc_hba *phba, int val)
3943{
James Smartff78d8f2011-12-13 13:21:35 -05003944 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
3945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3946 "3111 lpfc_link_speed of %d cannot "
3947 "support loop mode, setting topology to default.\n",
3948 val);
3949 phba->cfg_topology = 0;
3950 }
James Smart76a95d72010-11-20 23:11:48 -05003951 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
3952 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05003953 phba->cfg_link_speed = val;
3954 return 0;
3955 }
3956 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003957 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05003958 "be set to %d, allowed values are "
3959 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05003960 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05003961 return -EINVAL;
3962}
3963
Tony Jonesee959b02008-02-22 00:13:36 +01003964static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05003965 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05003966
3967/*
James Smart0d878412009-10-02 15:16:56 -04003968# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3969# 0 = aer disabled or not supported
3970# 1 = aer supported and enabled (default)
3971# Value range is [0,1]. Default value is 1.
3972*/
James Smart506139a2016-10-13 15:06:09 -07003973LPFC_ATTR(aer_support, 1, 0, 1,
3974 "Enable PCIe device AER support");
3975lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04003976
3977/**
3978 * lpfc_aer_support_store - Set the adapter for aer support
3979 *
3980 * @dev: class device that is converted into a Scsi_host.
3981 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04003982 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04003983 * @count: unused variable.
3984 *
3985 * Description:
3986 * If the val is 1 and currently the device's AER capability was not
3987 * enabled, invoke the kernel's enable AER helper routine, trying to
3988 * enable the device's AER capability. If the helper routine enabling
3989 * AER returns success, update the device's cfg_aer_support flag to
3990 * indicate AER is supported by the device; otherwise, if the device
3991 * AER capability is already enabled to support AER, then do nothing.
3992 *
3993 * If the val is 0 and currently the device's AER support was enabled,
3994 * invoke the kernel's disable AER helper routine. After that, update
3995 * the device's cfg_aer_support flag to indicate AER is not supported
3996 * by the device; otherwise, if the device AER capability is already
3997 * disabled from supporting AER, then do nothing.
3998 *
3999 * Returns:
4000 * length of the buf on success if val is in range the intended mode
4001 * is supported.
4002 * -EINVAL if val out of range or intended mode is not supported.
4003 **/
4004static ssize_t
4005lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4006 const char *buf, size_t count)
4007{
4008 struct Scsi_Host *shost = class_to_shost(dev);
4009 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4010 struct lpfc_hba *phba = vport->phba;
4011 int val = 0, rc = -EINVAL;
4012
4013 if (!isdigit(buf[0]))
4014 return -EINVAL;
4015 if (sscanf(buf, "%i", &val) != 1)
4016 return -EINVAL;
4017
4018 switch (val) {
4019 case 0:
4020 if (phba->hba_flag & HBA_AER_ENABLED) {
4021 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4022 if (!rc) {
4023 spin_lock_irq(&phba->hbalock);
4024 phba->hba_flag &= ~HBA_AER_ENABLED;
4025 spin_unlock_irq(&phba->hbalock);
4026 phba->cfg_aer_support = 0;
4027 rc = strlen(buf);
4028 } else
James Smart891478a2009-11-18 15:40:23 -05004029 rc = -EPERM;
4030 } else {
James Smart0d878412009-10-02 15:16:56 -04004031 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004032 rc = strlen(buf);
4033 }
James Smart0d878412009-10-02 15:16:56 -04004034 break;
4035 case 1:
4036 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4037 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4038 if (!rc) {
4039 spin_lock_irq(&phba->hbalock);
4040 phba->hba_flag |= HBA_AER_ENABLED;
4041 spin_unlock_irq(&phba->hbalock);
4042 phba->cfg_aer_support = 1;
4043 rc = strlen(buf);
4044 } else
James Smart891478a2009-11-18 15:40:23 -05004045 rc = -EPERM;
4046 } else {
James Smart0d878412009-10-02 15:16:56 -04004047 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004048 rc = strlen(buf);
4049 }
James Smart0d878412009-10-02 15:16:56 -04004050 break;
4051 default:
4052 rc = -EINVAL;
4053 break;
4054 }
4055 return rc;
4056}
4057
James Smart0d878412009-10-02 15:16:56 -04004058static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4059 lpfc_aer_support_show, lpfc_aer_support_store);
4060
4061/**
4062 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4063 * @dev: class device that is converted into a Scsi_host.
4064 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004065 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004066 * @count: unused variable.
4067 *
4068 * Description:
4069 * If the @buf contains 1 and the device currently has the AER support
4070 * enabled, then invokes the kernel AER helper routine
4071 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4072 * error status register.
4073 *
4074 * Notes:
4075 *
4076 * Returns:
4077 * -EINVAL if the buf does not contain the 1 or the device is not currently
4078 * enabled with the AER support.
4079 **/
4080static ssize_t
4081lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4082 const char *buf, size_t count)
4083{
4084 struct Scsi_Host *shost = class_to_shost(dev);
4085 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4086 struct lpfc_hba *phba = vport->phba;
4087 int val, rc = -1;
4088
4089 if (!isdigit(buf[0]))
4090 return -EINVAL;
4091 if (sscanf(buf, "%i", &val) != 1)
4092 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004093 if (val != 1)
4094 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004095
James Smart891478a2009-11-18 15:40:23 -05004096 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004097 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4098
4099 if (rc == 0)
4100 return strlen(buf);
4101 else
James Smart891478a2009-11-18 15:40:23 -05004102 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004103}
4104
4105static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4106 lpfc_aer_cleanup_state);
4107
James Smart912e3ac2011-05-24 11:42:11 -04004108/**
4109 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4110 *
4111 * @dev: class device that is converted into a Scsi_host.
4112 * @attr: device attribute, not used.
4113 * @buf: containing the string the number of vfs to be enabled.
4114 * @count: unused variable.
4115 *
4116 * Description:
4117 * When this api is called either through user sysfs, the driver shall
4118 * try to enable or disable SR-IOV virtual functions according to the
4119 * following:
4120 *
4121 * If zero virtual function has been enabled to the physical function,
4122 * the driver shall invoke the pci enable virtual function api trying
4123 * to enable the virtual functions. If the nr_vfn provided is greater
4124 * than the maximum supported, the maximum virtual function number will
4125 * be used for invoking the api; otherwise, the nr_vfn provided shall
4126 * be used for invoking the api. If the api call returned success, the
4127 * actual number of virtual functions enabled will be set to the driver
4128 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4129 * cfg_sriov_nr_virtfn remains zero.
4130 *
4131 * If none-zero virtual functions have already been enabled to the
4132 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4133 * -EINVAL will be returned and the driver does nothing;
4134 *
4135 * If the nr_vfn provided is zero and none-zero virtual functions have
4136 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4137 * disabling virtual function api shall be invoded to disable all the
4138 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4139 * zero. Otherwise, if zero virtual function has been enabled, do
4140 * nothing.
4141 *
4142 * Returns:
4143 * length of the buf on success if val is in range the intended mode
4144 * is supported.
4145 * -EINVAL if val out of range or intended mode is not supported.
4146 **/
4147static ssize_t
4148lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4149 const char *buf, size_t count)
4150{
4151 struct Scsi_Host *shost = class_to_shost(dev);
4152 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4153 struct lpfc_hba *phba = vport->phba;
4154 struct pci_dev *pdev = phba->pcidev;
4155 int val = 0, rc = -EINVAL;
4156
4157 /* Sanity check on user data */
4158 if (!isdigit(buf[0]))
4159 return -EINVAL;
4160 if (sscanf(buf, "%i", &val) != 1)
4161 return -EINVAL;
4162 if (val < 0)
4163 return -EINVAL;
4164
4165 /* Request disabling virtual functions */
4166 if (val == 0) {
4167 if (phba->cfg_sriov_nr_virtfn > 0) {
4168 pci_disable_sriov(pdev);
4169 phba->cfg_sriov_nr_virtfn = 0;
4170 }
4171 return strlen(buf);
4172 }
4173
4174 /* Request enabling virtual functions */
4175 if (phba->cfg_sriov_nr_virtfn > 0) {
4176 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4177 "3018 There are %d virtual functions "
4178 "enabled on physical function.\n",
4179 phba->cfg_sriov_nr_virtfn);
4180 return -EEXIST;
4181 }
4182
4183 if (val <= LPFC_MAX_VFN_PER_PFN)
4184 phba->cfg_sriov_nr_virtfn = val;
4185 else {
4186 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4187 "3019 Enabling %d virtual functions is not "
4188 "allowed.\n", val);
4189 return -EINVAL;
4190 }
4191
4192 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4193 if (rc) {
4194 phba->cfg_sriov_nr_virtfn = 0;
4195 rc = -EPERM;
4196 } else
4197 rc = strlen(buf);
4198
4199 return rc;
4200}
4201
James Smart0cfbbf22016-10-13 15:06:12 -07004202LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4203 "Enable PCIe device SR-IOV virtual fn");
4204
James Smart912e3ac2011-05-24 11:42:11 -04004205lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004206static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4207 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4208
James Smart173edbb2012-06-12 13:54:50 -04004209/**
James Smartc71ab862012-10-31 14:44:33 -04004210 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4211 *
4212 * @dev: class device that is converted into a Scsi_host.
4213 * @attr: device attribute, not used.
4214 * @buf: containing the string the number of vfs to be enabled.
4215 * @count: unused variable.
4216 *
4217 * Description:
4218 *
4219 * Returns:
4220 * length of the buf on success if val is in range the intended mode
4221 * is supported.
4222 * -EINVAL if val out of range or intended mode is not supported.
4223 **/
4224static ssize_t
4225lpfc_request_firmware_upgrade_store(struct device *dev,
4226 struct device_attribute *attr,
4227 const char *buf, size_t count)
4228{
4229 struct Scsi_Host *shost = class_to_shost(dev);
4230 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4231 struct lpfc_hba *phba = vport->phba;
4232 int val = 0, rc = -EINVAL;
4233
4234 /* Sanity check on user data */
4235 if (!isdigit(buf[0]))
4236 return -EINVAL;
4237 if (sscanf(buf, "%i", &val) != 1)
4238 return -EINVAL;
4239 if (val != 1)
4240 return -EINVAL;
4241
4242 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4243 if (rc)
4244 rc = -EPERM;
4245 else
4246 rc = strlen(buf);
4247 return rc;
4248}
4249
4250static int lpfc_req_fw_upgrade;
4251module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4252MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4253lpfc_param_show(request_firmware_upgrade)
4254
4255/**
4256 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4257 * @phba: lpfc_hba pointer.
4258 * @val: 0 or 1.
4259 *
4260 * Description:
4261 * Set the initial Linux generic firmware upgrade enable or disable flag.
4262 *
4263 * Returns:
4264 * zero if val saved.
4265 * -EINVAL val out of range
4266 **/
4267static int
4268lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4269{
4270 if (val >= 0 && val <= 1) {
4271 phba->cfg_request_firmware_upgrade = val;
4272 return 0;
4273 }
4274 return -EINVAL;
4275}
4276static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4277 lpfc_request_firmware_upgrade_show,
4278 lpfc_request_firmware_upgrade_store);
4279
4280/**
James Smart173edbb2012-06-12 13:54:50 -04004281 * lpfc_fcp_imax_store
4282 *
4283 * @dev: class device that is converted into a Scsi_host.
4284 * @attr: device attribute, not used.
4285 * @buf: string with the number of fast-path FCP interrupts per second.
4286 * @count: unused variable.
4287 *
4288 * Description:
4289 * If val is in a valid range [636,651042], then set the adapter's
4290 * maximum number of fast-path FCP interrupts per second.
4291 *
4292 * Returns:
4293 * length of the buf on success if val is in range the intended mode
4294 * is supported.
4295 * -EINVAL if val out of range or intended mode is not supported.
4296 **/
4297static ssize_t
4298lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4299 const char *buf, size_t count)
4300{
4301 struct Scsi_Host *shost = class_to_shost(dev);
4302 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4303 struct lpfc_hba *phba = vport->phba;
4304 int val = 0, i;
4305
James Smartbf8dae82012-08-03 12:36:24 -04004306 /* fcp_imax is only valid for SLI4 */
4307 if (phba->sli_rev != LPFC_SLI_REV4)
4308 return -EINVAL;
4309
James Smart173edbb2012-06-12 13:54:50 -04004310 /* Sanity check on user data */
4311 if (!isdigit(buf[0]))
4312 return -EINVAL;
4313 if (sscanf(buf, "%i", &val) != 1)
4314 return -EINVAL;
4315
James Smartbf8dae82012-08-03 12:36:24 -04004316 /*
4317 * Value range for the HBA is [5000,5000000]
4318 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004319 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004320 */
James Smart895427b2017-02-12 13:52:30 -08004321 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004322 return -EINVAL;
4323
4324 phba->cfg_fcp_imax = (uint32_t)val;
James Smart895427b2017-02-12 13:52:30 -08004325 for (i = 0; i < phba->io_channel_irqs; i++)
4326 lpfc_modify_hba_eq_delay(phba, i);
James Smart173edbb2012-06-12 13:54:50 -04004327
4328 return strlen(buf);
4329}
4330
4331/*
4332# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004333# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004334#
James Smartbf8dae82012-08-03 12:36:24 -04004335# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004336*/
James Smartbf8dae82012-08-03 12:36:24 -04004337static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004338module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4339MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004340 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004341lpfc_param_show(fcp_imax)
4342
4343/**
4344 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4345 * @phba: lpfc_hba pointer.
4346 * @val: link speed value.
4347 *
4348 * Description:
4349 * If val is in a valid range [636,651042], then initialize the adapter's
4350 * maximum number of fast-path FCP interrupts per second.
4351 *
4352 * Returns:
4353 * zero if val saved.
4354 * -EINVAL val out of range
4355 **/
4356static int
4357lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4358{
James Smartbf8dae82012-08-03 12:36:24 -04004359 if (phba->sli_rev != LPFC_SLI_REV4) {
4360 phba->cfg_fcp_imax = 0;
4361 return 0;
4362 }
4363
James Smart895427b2017-02-12 13:52:30 -08004364 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4365 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004366 phba->cfg_fcp_imax = val;
4367 return 0;
4368 }
4369
4370 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004371 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4372 val);
James Smartbf8dae82012-08-03 12:36:24 -04004373 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004374
4375 return 0;
4376}
4377
4378static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4379 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4380
James Smart7bb03bb2013-04-17 20:19:16 -04004381/**
4382 * lpfc_state_show - Display current driver CPU affinity
4383 * @dev: class converted to a Scsi_host structure.
4384 * @attr: device attribute, not used.
4385 * @buf: on return contains text describing the state of the link.
4386 *
4387 * Returns: size of formatted string.
4388 **/
4389static ssize_t
4390lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4391 char *buf)
4392{
4393 struct Scsi_Host *shost = class_to_shost(dev);
4394 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4395 struct lpfc_hba *phba = vport->phba;
4396 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004397 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004398
4399 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4400 (phba->intr_type != MSIX))
4401 return len;
4402
4403 switch (phba->cfg_fcp_cpu_map) {
4404 case 0:
4405 len += snprintf(buf + len, PAGE_SIZE-len,
4406 "fcp_cpu_map: No mapping (%d)\n",
4407 phba->cfg_fcp_cpu_map);
4408 return len;
4409 case 1:
4410 len += snprintf(buf + len, PAGE_SIZE-len,
4411 "fcp_cpu_map: HBA centric mapping (%d): "
4412 "%d online CPUs\n",
4413 phba->cfg_fcp_cpu_map,
4414 phba->sli4_hba.num_online_cpu);
4415 break;
4416 case 2:
4417 len += snprintf(buf + len, PAGE_SIZE-len,
4418 "fcp_cpu_map: Driver centric mapping (%d): "
4419 "%d online CPUs\n",
4420 phba->cfg_fcp_cpu_map,
4421 phba->sli4_hba.num_online_cpu);
4422 break;
4423 }
4424
James Smart76fd07a2014-02-20 09:57:18 -05004425 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4426 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4427
4428 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004429 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4430 len += snprintf(buf + len, PAGE_SIZE-len,
4431 "CPU %02d io_chan %02d "
4432 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004433 phba->sli4_hba.curr_disp_cpu,
4434 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004435 cpup->core_id);
4436 else
4437 len += snprintf(buf + len, PAGE_SIZE-len,
4438 "CPU %02d io_chan %02d "
4439 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004440 phba->sli4_hba.curr_disp_cpu,
4441 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004442 cpup->core_id, cpup->irq);
4443
James Smart76fd07a2014-02-20 09:57:18 -05004444 phba->sli4_hba.curr_disp_cpu++;
4445
4446 /* display max number of CPUs keeping some margin */
4447 if (phba->sli4_hba.curr_disp_cpu <
4448 phba->sli4_hba.num_present_cpu &&
4449 (len >= (PAGE_SIZE - 64))) {
4450 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4451 break;
4452 }
James Smart7bb03bb2013-04-17 20:19:16 -04004453 }
James Smart76fd07a2014-02-20 09:57:18 -05004454
4455 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4456 phba->sli4_hba.curr_disp_cpu = 0;
4457
James Smart7bb03bb2013-04-17 20:19:16 -04004458 return len;
4459}
4460
4461/**
4462 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4463 * @dev: class device that is converted into a Scsi_host.
4464 * @attr: device attribute, not used.
4465 * @buf: one or more lpfc_polling_flags values.
4466 * @count: not used.
4467 *
4468 * Returns:
4469 * -EINVAL - Not implemented yet.
4470 **/
4471static ssize_t
4472lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4473 const char *buf, size_t count)
4474{
4475 int status = -EINVAL;
4476 return status;
4477}
4478
4479/*
4480# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4481# for the HBA.
4482#
4483# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4484# 0 - Do not affinitze IRQ vectors
4485# 1 - Affintize HBA vectors with respect to each HBA
4486# (start with CPU0 for each HBA)
4487# 2 - Affintize HBA vectors with respect to the entire driver
4488# (round robin thru all CPUs across all HBAs)
4489*/
4490static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4491module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4492MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4493 "Defines how to map CPUs to IRQ vectors per HBA");
4494
4495/**
4496 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4497 * @phba: lpfc_hba pointer.
4498 * @val: link speed value.
4499 *
4500 * Description:
4501 * If val is in a valid range [0-2], then affinitze the adapter's
4502 * MSIX vectors.
4503 *
4504 * Returns:
4505 * zero if val saved.
4506 * -EINVAL val out of range
4507 **/
4508static int
4509lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4510{
4511 if (phba->sli_rev != LPFC_SLI_REV4) {
4512 phba->cfg_fcp_cpu_map = 0;
4513 return 0;
4514 }
4515
4516 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4517 phba->cfg_fcp_cpu_map = val;
4518 return 0;
4519 }
4520
4521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004522 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4523 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004524 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4525
4526 return 0;
4527}
4528
4529static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4530 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4531
James Smart0d878412009-10-02 15:16:56 -04004532/*
dea31012005-04-17 16:05:31 -05004533# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4534# Value range is [2,3]. Default value is 3.
4535*/
James Smart3de2a652007-08-02 11:09:59 -04004536LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4537 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004538
4539/*
4540# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4541# is [0,1]. Default value is 0.
4542*/
James Smart3de2a652007-08-02 11:09:59 -04004543LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4544 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004545
4546/*
James Smart3cb01c52013-07-15 18:35:04 -04004547# lpfc_first_burst_size: First burst size to use on the NPorts
4548# that support first burst.
4549# Value range is [0,65536]. Default value is 0.
4550*/
4551LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4552 "First burst size for Targets that support first burst");
4553
4554/*
James Smart895427b2017-02-12 13:52:30 -08004555* lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4556* For the Initiator (I), enabling this parameter means that an NVME
4557* PRLI response with FBA enabled and an FB_SIZE set to a nonzero value
4558* will be processed by the initiator for subsequent NVME FCP IO.
4559* Parameter supported on physical port only - no NPIV support.
4560* Value range is [0,1]. Default value is 0 (disabled).
4561*/
4562LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4563 "Enable First Burst feature on I and T functions.");
4564
4565/*
James Smart977b5a02008-09-07 11:52:04 -04004566# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4567# depth. Default value is 0. When the value of this parameter is zero the
4568# SCSI command completion time is not used for controlling I/O queue depth. When
4569# the parameter is set to a non-zero value, the I/O queue depth is controlled
4570# to limit the I/O completion time to the parameter value.
4571# The value is set in milliseconds.
4572*/
James Smarted5b1522016-10-13 15:06:11 -07004573LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004574 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004575
James Smart977b5a02008-09-07 11:52:04 -04004576lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004577static int
4578lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4579{
4580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4581 struct lpfc_nodelist *ndlp, *next_ndlp;
4582
4583 if (val == vport->cfg_max_scsicmpl_time)
4584 return 0;
4585 if ((val < 0) || (val > 60000))
4586 return -EINVAL;
4587 vport->cfg_max_scsicmpl_time = val;
4588
4589 spin_lock_irq(shost->host_lock);
4590 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4591 if (!NLP_CHK_NODE_ACT(ndlp))
4592 continue;
4593 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4594 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004595 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004596 }
4597 spin_unlock_irq(shost->host_lock);
4598 return 0;
4599}
4600lpfc_vport_param_store(max_scsicmpl_time);
4601static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4602 lpfc_max_scsicmpl_time_show,
4603 lpfc_max_scsicmpl_time_store);
4604
4605/*
dea31012005-04-17 16:05:31 -05004606# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4607# range is [0,1]. Default value is 0.
4608*/
4609LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4610
4611/*
James Smart895427b2017-02-12 13:52:30 -08004612 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4613 * range is [0,1]. Default value is 0.
4614 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4615 * For [1], FCP commands are issued to a Work Queue associated with the
4616 * current CPU.
4617 *
4618 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4619 * LPFC_FCP_SCHED_BY_CPU == 1
4620 *
4621 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4622 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4623 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4624 * through WQs will be used.
4625 */
4626LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4627 LPFC_FCP_SCHED_ROUND_ROBIN,
4628 LPFC_FCP_SCHED_BY_CPU,
4629 "Determine scheduling algorithm for "
4630 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004631
4632/*
James Smarta6571c62012-10-31 14:44:42 -04004633# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4634# range is [0,1]. Default value is 0.
4635# For [0], bus reset issues target reset to ALL devices
4636# For [1], bus reset issues target reset to non-FCP2 devices
4637*/
4638LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4639 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4640
4641
4642/*
dea31012005-04-17 16:05:31 -05004643# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4644# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004645# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004646# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4647# cr_delay is set to 0.
4648*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004649LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004650 "interrupt response is generated");
4651
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004652LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004653 "interrupt response is generated");
4654
4655/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004656# lpfc_multi_ring_support: Determines how many rings to spread available
4657# cmd/rsp IOCB entries across.
4658# Value range is [1,2]. Default value is 1.
4659*/
4660LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4661 "SLI rings to spread IOCB entries across");
4662
4663/*
James Smarta4bc3372006-12-02 13:34:16 -05004664# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4665# identifies what rctl value to configure the additional ring for.
4666# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4667*/
James Smart6a9c52c2009-10-02 15:16:51 -04004668LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004669 255, "Identifies RCTL for additional ring configuration");
4670
4671/*
4672# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4673# identifies what type value to configure the additional ring for.
4674# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4675*/
James Smart6a9c52c2009-10-02 15:16:51 -04004676LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004677 255, "Identifies TYPE for additional ring configuration");
4678
4679/*
James Smart4258e982015-12-16 18:11:58 -05004680# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4681# 0 = SmartSAN functionality disabled (default)
4682# 1 = SmartSAN functionality enabled
4683# This parameter will override the value of lpfc_fdmi_on module parameter.
4684# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004685*/
James Smart4258e982015-12-16 18:11:58 -05004686LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4687
4688/*
4689# lpfc_fdmi_on: Controls FDMI support.
4690# 0 No FDMI support (default)
4691# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004692# Traditional FDMI support means the driver will assume FDMI-2 support;
4693# however, if that fails, it will fallback to FDMI-1.
4694# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4695# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4696# lpfc_fdmi_on.
4697# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004698*/
James Smart8663cbb2016-03-31 14:12:33 -07004699LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004700
4701/*
4702# Specifies the maximum number of ELS cmds we can have outstanding (for
4703# discovery). Value range is [1,64]. Default value = 32.
4704*/
James Smart3de2a652007-08-02 11:09:59 -04004705LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004706 "during discovery");
4707
4708/*
James Smartc4a7c922013-05-31 17:04:59 -04004709# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4710# will be scanned by the SCSI midlayer when sequential scanning is
4711# used; and is also the highest LUN ID allowed when the SCSI midlayer
4712# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4713# LUN ID limit, but the SCSI midlayer requires this field for the uses
4714# above. The lpfc driver limits the default value to 255 for two reasons.
4715# As it bounds the sequential scan loop, scanning for thousands of luns
4716# on a target can take minutes of wall clock time. Additionally,
4717# there are FC targets, such as JBODs, that only recognize 8-bits of
4718# LUN ID. When they receive a value greater than 8 bits, they chop off
4719# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4720# and so on all as LUN ID 0. This causes the linux kernel, which sees
4721# valid responses at each of the LUN IDs, to believe there are multiple
4722# devices present, when in fact, there is only 1.
4723# A customer that is aware of their target behaviors, and the results as
4724# indicated above, is welcome to increase the lpfc_max_luns value.
4725# As mentioned, this value is not used by the lpfc driver, only the
4726# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004727# Value range is [0,65535]. Default value is 255.
4728# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004729*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004730LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004731
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004732/*
4733# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4734# Value range is [1,255], default value is 10.
4735*/
4736LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4737 "Milliseconds driver will wait between polling FCP ring");
4738
James Smart4ff43242006-12-02 13:34:56 -05004739/*
James Smart0c411222013-09-06 12:22:46 -04004740# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4741# to complete in seconds. Value range is [5,180], default value is 60.
4742*/
4743LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4744 "Maximum time to wait for task management commands to complete");
4745/*
James Smart4ff43242006-12-02 13:34:56 -05004746# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4747# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004748# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004749# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004750# 2 = MSI-X enabled (default)
4751# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004752*/
George Kadianakis8605c462010-01-17 21:19:31 +02004753LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004754 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004755
James Smart13815c82008-01-11 01:52:48 -05004756/*
James Smart895427b2017-02-12 13:52:30 -08004757 * lpfc_nvme_oas: Use the oas bit when sending NVME IOs
4758 *
4759 * 0 = NVME OAS disabled
4760 * 1 = NVME OAS enabled
4761 *
4762 * Value range is [0,1]. Default value is 0.
4763 */
4764LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4765 "Use OAS bit on NVME IOs");
4766
4767/*
4768 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4769 * will advertise it supports to the SCSI layer. This also will map to
4770 * the number of WQs the driver will create.
4771 *
4772 * 0 = Configure the number of io channels to the number of active CPUs.
4773 * 1,32 = Manually specify how many io channels to use.
4774 *
4775 * Value range is [0,32]. Default value is 4.
4776 */
4777LPFC_ATTR_R(fcp_io_channel,
4778 LPFC_FCP_IO_CHAN_DEF,
4779 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004780 "Set the number of FCP I/O channels");
4781
4782/*
James Smart895427b2017-02-12 13:52:30 -08004783 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4784 * will advertise it supports to the NVME layer. This also will map to
4785 * the number of WQs the driver will create.
4786 *
4787 * This module parameter is valid when lpfc_enable_fc4_type is set
4788 * to support NVME.
4789 *
4790 * The NVME Layer will try to create this many, plus 1 administrative
4791 * hardware queue. The administrative queue will always map to WQ 0
4792 * A hardware IO queue maps (qidx) to a specific driver WQ.
4793 *
4794 * 0 = Configure the number of io channels to the number of active CPUs.
4795 * 1,32 = Manually specify how many io channels to use.
4796 *
4797 * Value range is [0,32]. Default value is 0.
4798 */
4799LPFC_ATTR_R(nvme_io_channel,
4800 LPFC_NVME_IO_CHAN_DEF,
4801 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4802 "Set the number of NVME I/O channels");
4803
4804/*
James Smart13815c82008-01-11 01:52:48 -05004805# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4806# 0 = HBA resets disabled
4807# 1 = HBA resets enabled (default)
4808# Value range is [0,1]. Default value is 1.
4809*/
4810LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004811
James Smart13815c82008-01-11 01:52:48 -05004812/*
James Smarteb7a3392010-11-20 23:12:02 -05004813# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004814# 0 = HBA Heartbeat disabled
4815# 1 = HBA Heartbeat enabled (default)
4816# Value range is [0,1]. Default value is 1.
4817*/
James Smarteb7a3392010-11-20 23:12:02 -05004818LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004819
James Smart83108bd2008-01-11 01:53:09 -05004820/*
James Smart1ba981f2014-02-20 09:56:45 -05004821# lpfc_EnableXLane: Enable Express Lane Feature
4822# 0x0 Express Lane Feature disabled
4823# 0x1 Express Lane Feature enabled
4824# Value range is [0,1]. Default value is 0.
4825*/
4826LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4827
4828/*
4829# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4830# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4831# Value range is [0x0,0x7f]. Default value is 0
4832*/
James Smart28d7f3d2014-05-21 08:05:28 -04004833LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004834
4835/*
James Smart81301a92008-12-04 22:39:46 -05004836# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4837# 0 = BlockGuard disabled (default)
4838# 1 = BlockGuard enabled
4839# Value range is [0,1]. Default value is 0.
4840*/
4841LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4842
James Smart6fb120a2009-05-22 14:52:59 -04004843/*
James Smartba20c852012-08-03 12:36:52 -04004844# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4845# 0 = disabled (default)
4846# 1 = enabled
4847# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004848#
4849# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004850*/
4851unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4852
James Smartba20c852012-08-03 12:36:52 -04004853/*
James Smart81301a92008-12-04 22:39:46 -05004854# lpfc_prot_mask: i
4855# - Bit mask of host protection capabilities used to register with the
4856# SCSI mid-layer
4857# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4858# - Allows you to ultimately specify which profiles to use
4859# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004860# - SHOST_DIF_TYPE1_PROTECTION 1
4861# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4862# - SHOST_DIX_TYPE0_PROTECTION 8
4863# HBA supports DIX Type 0: Host to HBA protection only
4864# - SHOST_DIX_TYPE1_PROTECTION 16
4865# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004866#
4867*/
James Smartb3b98b72016-10-13 15:06:06 -07004868LPFC_ATTR(prot_mask,
4869 (SHOST_DIF_TYPE1_PROTECTION |
4870 SHOST_DIX_TYPE0_PROTECTION |
4871 SHOST_DIX_TYPE1_PROTECTION),
4872 0,
4873 (SHOST_DIF_TYPE1_PROTECTION |
4874 SHOST_DIX_TYPE0_PROTECTION |
4875 SHOST_DIX_TYPE1_PROTECTION),
4876 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05004877
4878/*
4879# lpfc_prot_guard: i
4880# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004881# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004882# - Allows you to ultimately specify which profiles to use
4883# - Default will result in registering capabilities for all guard types
4884#
4885*/
James Smartb3b98b72016-10-13 15:06:06 -07004886LPFC_ATTR(prot_guard,
4887 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
4888 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05004889
James Smart92494142011-02-16 12:39:44 -05004890/*
4891 * Delay initial NPort discovery when Clean Address bit is cleared in
4892 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4893 * This parameter can have value 0 or 1.
4894 * When this parameter is set to 0, no delay is added to the initial
4895 * discovery.
4896 * When this parameter is set to non-zero value, initial Nport discovery is
4897 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
4898 * accept and FCID/Fabric name/Fabric portname is changed.
4899 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
4900 * when Clean Address bit is cleared in FLOGI/FDISC
4901 * accept and FCID/Fabric name/Fabric portname is changed.
4902 * Default value is 0.
4903 */
James Smart8eb8b962016-07-06 12:36:08 -07004904LPFC_ATTR(delay_discovery, 0, 0, 1,
4905 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05004906
4907/*
James Smart3621a712009-04-06 18:47:14 -04004908 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04004909 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05004910 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
4911 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04004912 * Because of the additional overhead involved in setting up T10-DIF,
4913 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
4914 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05004915 */
4916LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
4917 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
4918
James Smart96f70772013-04-17 20:16:15 -04004919/*
James Smart7bdedb32016-07-06 12:36:00 -07004920 * lpfc_enable_mds_diags: Enable MDS Diagnostics
4921 * 0 = MDS Diagnostics disabled (default)
4922 * 1 = MDS Diagnostics enabled
4923 * Value range is [0,1]. Default value is 0.
4924 */
4925LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
4926
Tony Jonesee959b02008-02-22 00:13:36 +01004927struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08004928 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05004929 &dev_attr_bg_info,
4930 &dev_attr_bg_guard_err,
4931 &dev_attr_bg_apptag_err,
4932 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01004933 &dev_attr_info,
4934 &dev_attr_serialnum,
4935 &dev_attr_modeldesc,
4936 &dev_attr_modelname,
4937 &dev_attr_programtype,
4938 &dev_attr_portnum,
4939 &dev_attr_fwrev,
4940 &dev_attr_hdw,
4941 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01004942 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01004943 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04004944 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01004945 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04004946 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01004947 &dev_attr_lpfc_temp_sensor,
4948 &dev_attr_lpfc_log_verbose,
4949 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04004950 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01004951 &dev_attr_lpfc_hba_queue_depth,
4952 &dev_attr_lpfc_peer_port_login,
4953 &dev_attr_lpfc_nodev_tmo,
4954 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08004955 &dev_attr_lpfc_enable_fc4_type,
4956 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01004957 &dev_attr_lpfc_fcp_class,
4958 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04004959 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01004960 &dev_attr_lpfc_ack0,
4961 &dev_attr_lpfc_topology,
4962 &dev_attr_lpfc_scan_down,
4963 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04004964 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04004965 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01004966 &dev_attr_lpfc_cr_delay,
4967 &dev_attr_lpfc_cr_count,
4968 &dev_attr_lpfc_multi_ring_support,
4969 &dev_attr_lpfc_multi_ring_rctl,
4970 &dev_attr_lpfc_multi_ring_type,
4971 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05004972 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01004973 &dev_attr_lpfc_max_luns,
4974 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04004975 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05004976 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01004977 &dev_attr_nport_evt_cnt,
4978 &dev_attr_board_mode,
4979 &dev_attr_max_vpi,
4980 &dev_attr_used_vpi,
4981 &dev_attr_max_rpi,
4982 &dev_attr_used_rpi,
4983 &dev_attr_max_xri,
4984 &dev_attr_used_xri,
4985 &dev_attr_npiv_info,
4986 &dev_attr_issue_reset,
4987 &dev_attr_lpfc_poll,
4988 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04004989 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01004990 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08004991 &dev_attr_lpfc_nvme_oas,
James Smartda0436e2009-05-22 14:51:39 -04004992 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04004993 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04004994 &dev_attr_lpfc_fcp_io_channel,
James Smart895427b2017-02-12 13:52:30 -08004995 &dev_attr_lpfc_nvme_io_channel,
4996 &dev_attr_lpfc_nvme_enable_fb,
James Smart81301a92008-12-04 22:39:46 -05004997 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08004998 &dev_attr_lpfc_soft_wwnn,
4999 &dev_attr_lpfc_soft_wwpn,
5000 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005001 &dev_attr_lpfc_enable_hba_reset,
5002 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005003 &dev_attr_lpfc_EnableXLane,
5004 &dev_attr_lpfc_XLanePriority,
5005 &dev_attr_lpfc_xlane_lun,
5006 &dev_attr_lpfc_xlane_tgt,
5007 &dev_attr_lpfc_xlane_vpt,
5008 &dev_attr_lpfc_xlane_lun_state,
5009 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005010 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005011 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005012 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005013 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005014 &dev_attr_lpfc_aer_support,
5015 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005016 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005017 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005018 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005019 &dev_attr_lpfc_iocb_cnt,
5020 &dev_attr_iocb_hw,
5021 &dev_attr_txq_hw,
5022 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005023 &dev_attr_lpfc_fips_level,
5024 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005025 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005026 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005027 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005028 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005029 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05005030 NULL,
5031};
5032
Tony Jonesee959b02008-02-22 00:13:36 +01005033struct device_attribute *lpfc_vport_attrs[] = {
5034 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005035 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005036 &dev_attr_num_discovered_ports,
5037 &dev_attr_lpfc_drvr_version,
5038 &dev_attr_lpfc_log_verbose,
5039 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005040 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005041 &dev_attr_lpfc_nodev_tmo,
5042 &dev_attr_lpfc_devloss_tmo,
5043 &dev_attr_lpfc_hba_queue_depth,
5044 &dev_attr_lpfc_peer_port_login,
5045 &dev_attr_lpfc_restrict_login,
5046 &dev_attr_lpfc_fcp_class,
5047 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005048 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005049 &dev_attr_lpfc_max_luns,
5050 &dev_attr_nport_evt_cnt,
5051 &dev_attr_npiv_info,
5052 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005053 &dev_attr_lpfc_max_scsicmpl_time,
5054 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005055 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005056 &dev_attr_lpfc_fips_level,
5057 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005058 NULL,
5059};
5060
James Smarte59058c2008-08-24 21:49:00 -04005061/**
James Smart3621a712009-04-06 18:47:14 -04005062 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005063 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005064 * @kobj: kernel kobject that contains the kernel class device.
5065 * @bin_attr: kernel attributes passed to us.
5066 * @buf: contains the data to be written to the adapter IOREG space.
5067 * @off: offset into buffer to beginning of data.
5068 * @count: bytes to transfer.
5069 *
5070 * Description:
5071 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5072 * Uses the adapter io control registers to send buf contents to the adapter.
5073 *
5074 * Returns:
5075 * -ERANGE off and count combo out of range
5076 * -EINVAL off, count or buff address invalid
5077 * -EPERM adapter is offline
5078 * value of count, buf contents written
5079 **/
dea31012005-04-17 16:05:31 -05005080static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005081sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5082 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005083 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005084{
5085 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005086 struct device *dev = container_of(kobj, struct device, kobj);
5087 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005088 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5089 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005090
James Smartf1126682009-06-10 17:22:44 -04005091 if (phba->sli_rev >= LPFC_SLI_REV4)
5092 return -EPERM;
5093
dea31012005-04-17 16:05:31 -05005094 if ((off + count) > FF_REG_AREA_SIZE)
5095 return -ERANGE;
5096
James Smartf7a919b2011-08-21 21:49:16 -04005097 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5098 return 0;
dea31012005-04-17 16:05:31 -05005099
5100 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5101 return -EINVAL;
5102
James Smartf7a919b2011-08-21 21:49:16 -04005103 /* This is to protect HBA registers from accidental writes. */
5104 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5105 return -EINVAL;
5106
5107 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005108 return -EPERM;
dea31012005-04-17 16:05:31 -05005109
James Smart2e0fef82007-06-17 19:56:36 -05005110 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005111 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5112 buf_off += sizeof(uint32_t))
5113 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005114 phba->ctrl_regs_memmap_p + off + buf_off);
5115
James Smart2e0fef82007-06-17 19:56:36 -05005116 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005117
5118 return count;
5119}
5120
James Smarte59058c2008-08-24 21:49:00 -04005121/**
James Smart3621a712009-04-06 18:47:14 -04005122 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005123 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005124 * @kobj: kernel kobject that contains the kernel class device.
5125 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005126 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005127 * @off: offset into buffer to beginning of data.
5128 * @count: bytes to transfer.
5129 *
5130 * Description:
5131 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5132 * Uses the adapter io control registers to read data into buf.
5133 *
5134 * Returns:
5135 * -ERANGE off and count combo out of range
5136 * -EINVAL off, count or buff address invalid
5137 * value of count, buf contents read
5138 **/
dea31012005-04-17 16:05:31 -05005139static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005140sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5141 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005142 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005143{
5144 size_t buf_off;
5145 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005146 struct device *dev = container_of(kobj, struct device, kobj);
5147 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005148 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5149 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005150
James Smartf1126682009-06-10 17:22:44 -04005151 if (phba->sli_rev >= LPFC_SLI_REV4)
5152 return -EPERM;
5153
dea31012005-04-17 16:05:31 -05005154 if (off > FF_REG_AREA_SIZE)
5155 return -ERANGE;
5156
5157 if ((off + count) > FF_REG_AREA_SIZE)
5158 count = FF_REG_AREA_SIZE - off;
5159
5160 if (count == 0) return 0;
5161
5162 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5163 return -EINVAL;
5164
James Smart2e0fef82007-06-17 19:56:36 -05005165 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005166
5167 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5168 tmp_ptr = (uint32_t *)(buf + buf_off);
5169 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5170 }
5171
James Smart2e0fef82007-06-17 19:56:36 -05005172 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005173
5174 return count;
5175}
5176
5177static struct bin_attribute sysfs_ctlreg_attr = {
5178 .attr = {
5179 .name = "ctlreg",
5180 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005181 },
5182 .size = 256,
5183 .read = sysfs_ctlreg_read,
5184 .write = sysfs_ctlreg_write,
5185};
5186
James Smarte59058c2008-08-24 21:49:00 -04005187/**
James Smart3621a712009-04-06 18:47:14 -04005188 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005189 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005190 * @kobj: kernel kobject that contains the kernel class device.
5191 * @bin_attr: kernel attributes passed to us.
5192 * @buf: contains the data to be written to sysfs mbox.
5193 * @off: offset into buffer to beginning of data.
5194 * @count: bytes to transfer.
5195 *
5196 * Description:
James Smart026abb82011-12-13 13:20:45 -05005197 * Deprecated function. All mailbox access from user space is performed via the
5198 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005199 *
5200 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005201 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005202 **/
dea31012005-04-17 16:05:31 -05005203static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005204sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5205 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005206 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005207{
James Smart026abb82011-12-13 13:20:45 -05005208 return -EPERM;
dea31012005-04-17 16:05:31 -05005209}
5210
James Smarte59058c2008-08-24 21:49:00 -04005211/**
James Smart3621a712009-04-06 18:47:14 -04005212 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005213 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005214 * @kobj: kernel kobject that contains the kernel class device.
5215 * @bin_attr: kernel attributes passed to us.
5216 * @buf: contains the data to be read from sysfs mbox.
5217 * @off: offset into buffer to beginning of data.
5218 * @count: bytes to transfer.
5219 *
5220 * Description:
James Smart026abb82011-12-13 13:20:45 -05005221 * Deprecated function. All mailbox access from user space is performed via the
5222 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005223 *
5224 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005225 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005226 **/
dea31012005-04-17 16:05:31 -05005227static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005228sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5229 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005230 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005231{
James Smart026abb82011-12-13 13:20:45 -05005232 return -EPERM;
dea31012005-04-17 16:05:31 -05005233}
5234
5235static struct bin_attribute sysfs_mbox_attr = {
5236 .attr = {
5237 .name = "mbox",
5238 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005239 },
James Smartc0c11512011-05-24 11:41:34 -04005240 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005241 .read = sysfs_mbox_read,
5242 .write = sysfs_mbox_write,
5243};
5244
James Smarte59058c2008-08-24 21:49:00 -04005245/**
James Smart3621a712009-04-06 18:47:14 -04005246 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005247 * @vport: address of lpfc vport structure.
5248 *
5249 * Return codes:
5250 * zero on success
5251 * error return code from sysfs_create_bin_file()
5252 **/
dea31012005-04-17 16:05:31 -05005253int
James Smart2e0fef82007-06-17 19:56:36 -05005254lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005255{
James Smart2e0fef82007-06-17 19:56:36 -05005256 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005257 int error;
5258
Tony Jonesee959b02008-02-22 00:13:36 +01005259 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005260 &sysfs_drvr_stat_data_attr);
5261
5262 /* Virtual ports do not need ctrl_reg and mbox */
5263 if (error || vport->port_type == LPFC_NPIV_PORT)
5264 goto out;
5265
5266 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005267 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005268 if (error)
James Smarteada2722008-12-04 22:39:13 -05005269 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005270
Tony Jonesee959b02008-02-22 00:13:36 +01005271 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005272 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005273 if (error)
5274 goto out_remove_ctlreg_attr;
5275
5276 return 0;
5277out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005278 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005279out_remove_stat_attr:
5280 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5281 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005282out:
5283 return error;
5284}
5285
James Smarte59058c2008-08-24 21:49:00 -04005286/**
James Smart3621a712009-04-06 18:47:14 -04005287 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005288 * @vport: address of lpfc vport structure.
5289 **/
dea31012005-04-17 16:05:31 -05005290void
James Smart2e0fef82007-06-17 19:56:36 -05005291lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005292{
James Smart2e0fef82007-06-17 19:56:36 -05005293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005294 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5295 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005296 /* Virtual ports do not need ctrl_reg and mbox */
5297 if (vport->port_type == LPFC_NPIV_PORT)
5298 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005299 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5300 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005301}
5302
dea31012005-04-17 16:05:31 -05005303/*
5304 * Dynamic FC Host Attributes Support
5305 */
5306
James Smarte59058c2008-08-24 21:49:00 -04005307/**
James Smart6c9231f2016-12-19 15:07:24 -08005308 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5309 * @shost: kernel scsi host pointer.
5310 **/
5311static void
5312lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5313{
5314 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5315
5316 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5317 sizeof fc_host_symbolic_name(shost));
5318}
5319
5320/**
James Smart3621a712009-04-06 18:47:14 -04005321 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005322 * @shost: kernel scsi host pointer.
5323 **/
dea31012005-04-17 16:05:31 -05005324static void
5325lpfc_get_host_port_id(struct Scsi_Host *shost)
5326{
James Smart2e0fef82007-06-17 19:56:36 -05005327 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5328
dea31012005-04-17 16:05:31 -05005329 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005330 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005331}
5332
James Smarte59058c2008-08-24 21:49:00 -04005333/**
James Smart3621a712009-04-06 18:47:14 -04005334 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005335 * @shost: kernel scsi host pointer.
5336 **/
dea31012005-04-17 16:05:31 -05005337static void
5338lpfc_get_host_port_type(struct Scsi_Host *shost)
5339{
James Smart2e0fef82007-06-17 19:56:36 -05005340 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5341 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005342
5343 spin_lock_irq(shost->host_lock);
5344
James Smart92d7f7b2007-06-17 19:56:38 -05005345 if (vport->port_type == LPFC_NPIV_PORT) {
5346 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5347 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005348 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005349 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005350 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5351 else
5352 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5353 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005354 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005355 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5356 else
5357 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5358 }
5359 } else
5360 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5361
5362 spin_unlock_irq(shost->host_lock);
5363}
5364
James Smarte59058c2008-08-24 21:49:00 -04005365/**
James Smart3621a712009-04-06 18:47:14 -04005366 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005367 * @shost: kernel scsi host pointer.
5368 **/
dea31012005-04-17 16:05:31 -05005369static void
5370lpfc_get_host_port_state(struct Scsi_Host *shost)
5371{
James Smart2e0fef82007-06-17 19:56:36 -05005372 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5373 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005374
5375 spin_lock_irq(shost->host_lock);
5376
James Smart2e0fef82007-06-17 19:56:36 -05005377 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005378 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5379 else {
James Smart2e0fef82007-06-17 19:56:36 -05005380 switch (phba->link_state) {
5381 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005382 case LPFC_LINK_DOWN:
5383 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5384 break;
5385 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005386 case LPFC_CLEAR_LA:
5387 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005388 /* Links up, reports port state accordingly */
5389 if (vport->port_state < LPFC_VPORT_READY)
5390 fc_host_port_state(shost) =
5391 FC_PORTSTATE_BYPASSED;
5392 else
5393 fc_host_port_state(shost) =
5394 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005395 break;
5396 case LPFC_HBA_ERROR:
5397 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5398 break;
5399 default:
5400 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5401 break;
5402 }
5403 }
5404
5405 spin_unlock_irq(shost->host_lock);
5406}
5407
James Smarte59058c2008-08-24 21:49:00 -04005408/**
James Smart3621a712009-04-06 18:47:14 -04005409 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005410 * @shost: kernel scsi host pointer.
5411 **/
dea31012005-04-17 16:05:31 -05005412static void
5413lpfc_get_host_speed(struct Scsi_Host *shost)
5414{
James Smart2e0fef82007-06-17 19:56:36 -05005415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5416 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005417
5418 spin_lock_irq(shost->host_lock);
5419
James Smarta085e872015-12-16 18:12:02 -05005420 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005421 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005422 case LPFC_LINK_SPEED_1GHZ:
5423 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005424 break;
James Smart76a95d72010-11-20 23:11:48 -05005425 case LPFC_LINK_SPEED_2GHZ:
5426 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005427 break;
James Smart76a95d72010-11-20 23:11:48 -05005428 case LPFC_LINK_SPEED_4GHZ:
5429 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005430 break;
James Smart76a95d72010-11-20 23:11:48 -05005431 case LPFC_LINK_SPEED_8GHZ:
5432 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005433 break;
James Smart76a95d72010-11-20 23:11:48 -05005434 case LPFC_LINK_SPEED_10GHZ:
5435 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005436 break;
James Smart76a95d72010-11-20 23:11:48 -05005437 case LPFC_LINK_SPEED_16GHZ:
5438 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5439 break;
James Smartd38dd522015-08-31 16:48:17 -04005440 case LPFC_LINK_SPEED_32GHZ:
5441 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5442 break;
James Smart76a95d72010-11-20 23:11:48 -05005443 default:
5444 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005445 break;
5446 }
James Smart09372822008-01-11 01:52:54 -05005447 } else
5448 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005449
5450 spin_unlock_irq(shost->host_lock);
5451}
5452
James Smarte59058c2008-08-24 21:49:00 -04005453/**
James Smart3621a712009-04-06 18:47:14 -04005454 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005455 * @shost: kernel scsi host pointer.
5456 **/
dea31012005-04-17 16:05:31 -05005457static void
5458lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5459{
James Smart2e0fef82007-06-17 19:56:36 -05005460 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5461 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005462 u64 node_name;
dea31012005-04-17 16:05:31 -05005463
5464 spin_lock_irq(shost->host_lock);
5465
James Smart73d91e52011-10-10 21:32:10 -04005466 if ((vport->port_state > LPFC_FLOGI) &&
5467 ((vport->fc_flag & FC_FABRIC) ||
5468 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5469 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005470 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005471 else
5472 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005473 node_name = 0;
dea31012005-04-17 16:05:31 -05005474
5475 spin_unlock_irq(shost->host_lock);
5476
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005477 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005478}
5479
James Smarte59058c2008-08-24 21:49:00 -04005480/**
James Smart3621a712009-04-06 18:47:14 -04005481 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005482 * @shost: kernel scsi host pointer.
5483 *
5484 * Notes:
5485 * NULL on error for link down, no mbox pool, sli2 active,
5486 * management not allowed, memory allocation error, or mbox error.
5487 *
5488 * Returns:
5489 * NULL for error
5490 * address of the adapter host statistics
5491 **/
dea31012005-04-17 16:05:31 -05005492static struct fc_host_statistics *
5493lpfc_get_stats(struct Scsi_Host *shost)
5494{
James Smart2e0fef82007-06-17 19:56:36 -05005495 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5496 struct lpfc_hba *phba = vport->phba;
5497 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005498 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005499 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005500 LPFC_MBOXQ_t *pmboxq;
5501 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005502 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005503 int rc = 0;
dea31012005-04-17 16:05:31 -05005504
James Smart92d7f7b2007-06-17 19:56:38 -05005505 /*
5506 * prevent udev from issuing mailbox commands until the port is
5507 * configured.
5508 */
James Smart2e0fef82007-06-17 19:56:36 -05005509 if (phba->link_state < LPFC_LINK_DOWN ||
5510 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005511 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005512 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005513
5514 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005515 return NULL;
5516
dea31012005-04-17 16:05:31 -05005517 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5518 if (!pmboxq)
5519 return NULL;
5520 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5521
James Smart04c68492009-05-22 14:52:52 -04005522 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005523 pmb->mbxCommand = MBX_READ_STATUS;
5524 pmb->mbxOwner = OWN_HOST;
5525 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005526 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005527
James Smart75baf692010-06-08 18:31:21 -04005528 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005529 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005530 else
dea31012005-04-17 16:05:31 -05005531 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5532
5533 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005534 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005535 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005536 return NULL;
5537 }
5538
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005539 memset(hs, 0, sizeof (struct fc_host_statistics));
5540
dea31012005-04-17 16:05:31 -05005541 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005542 /*
5543 * The MBX_READ_STATUS returns tx_k_bytes which has to
5544 * converted to words
5545 */
5546 hs->tx_words = (uint64_t)
5547 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5548 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005549 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005550 hs->rx_words = (uint64_t)
5551 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5552 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005553
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005554 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005555 pmb->mbxCommand = MBX_READ_LNK_STAT;
5556 pmb->mbxOwner = OWN_HOST;
5557 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005558 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005559
James Smart75baf692010-06-08 18:31:21 -04005560 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005561 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005562 else
dea31012005-04-17 16:05:31 -05005563 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5564
5565 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005566 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005567 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005568 return NULL;
5569 }
5570
5571 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5572 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5573 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5574 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5575 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5576 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5577 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5578
James Smart64ba8812006-08-02 15:24:34 -04005579 hs->link_failure_count -= lso->link_failure_count;
5580 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5581 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5582 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5583 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5584 hs->invalid_crc_count -= lso->invalid_crc_count;
5585 hs->error_frames -= lso->error_frames;
5586
James Smart76a95d72010-11-20 23:11:48 -05005587 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005588 hs->lip_count = -1;
5589 hs->nos_count = (phba->link_events >> 1);
5590 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005591 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005592 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005593 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005594 hs->nos_count = -1;
5595 } else {
5596 hs->lip_count = -1;
5597 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005598 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005599 }
5600
5601 hs->dumped_frames = -1;
5602
James Smart64ba8812006-08-02 15:24:34 -04005603 seconds = get_seconds();
5604 if (seconds < psli->stats_start)
5605 hs->seconds_since_last_reset = seconds +
5606 ((unsigned long)-1 - psli->stats_start);
5607 else
5608 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005609
James Smart1dcb58e2007-04-25 09:51:30 -04005610 mempool_free(pmboxq, phba->mbox_mem_pool);
5611
dea31012005-04-17 16:05:31 -05005612 return hs;
5613}
5614
James Smarte59058c2008-08-24 21:49:00 -04005615/**
James Smart3621a712009-04-06 18:47:14 -04005616 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005617 * @shost: kernel scsi host pointer.
5618 **/
James Smart64ba8812006-08-02 15:24:34 -04005619static void
5620lpfc_reset_stats(struct Scsi_Host *shost)
5621{
James Smart2e0fef82007-06-17 19:56:36 -05005622 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5623 struct lpfc_hba *phba = vport->phba;
5624 struct lpfc_sli *psli = &phba->sli;
5625 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005626 LPFC_MBOXQ_t *pmboxq;
5627 MAILBOX_t *pmb;
5628 int rc = 0;
5629
James Smart2e0fef82007-06-17 19:56:36 -05005630 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005631 return;
5632
James Smart64ba8812006-08-02 15:24:34 -04005633 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5634 if (!pmboxq)
5635 return;
5636 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5637
James Smart04c68492009-05-22 14:52:52 -04005638 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005639 pmb->mbxCommand = MBX_READ_STATUS;
5640 pmb->mbxOwner = OWN_HOST;
5641 pmb->un.varWords[0] = 0x1; /* reset request */
5642 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005643 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005644
James Smart2e0fef82007-06-17 19:56:36 -05005645 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005646 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005647 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5648 else
5649 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5650
5651 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005652 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005653 mempool_free(pmboxq, phba->mbox_mem_pool);
5654 return;
5655 }
5656
5657 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5658 pmb->mbxCommand = MBX_READ_LNK_STAT;
5659 pmb->mbxOwner = OWN_HOST;
5660 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005661 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005662
James Smart2e0fef82007-06-17 19:56:36 -05005663 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005664 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005665 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5666 else
5667 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5668
5669 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005670 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005671 mempool_free( pmboxq, phba->mbox_mem_pool);
5672 return;
5673 }
5674
5675 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5676 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5677 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5678 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5679 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5680 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5681 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005682 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005683 lso->link_events = (phba->link_events >> 1);
5684 else
5685 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005686
5687 psli->stats_start = get_seconds();
5688
James Smart1dcb58e2007-04-25 09:51:30 -04005689 mempool_free(pmboxq, phba->mbox_mem_pool);
5690
James Smart64ba8812006-08-02 15:24:34 -04005691 return;
5692}
dea31012005-04-17 16:05:31 -05005693
5694/*
5695 * The LPFC driver treats linkdown handling as target loss events so there
5696 * are no sysfs handlers for link_down_tmo.
5697 */
James Smart685f0bf2007-04-25 09:53:08 -04005698
James Smarte59058c2008-08-24 21:49:00 -04005699/**
James Smart3621a712009-04-06 18:47:14 -04005700 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005701 * @starget: kernel scsi target pointer.
5702 *
5703 * Returns:
5704 * address of the node list if found
5705 * NULL target not found
5706 **/
James Smart685f0bf2007-04-25 09:53:08 -04005707static struct lpfc_nodelist *
5708lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005709{
James Smart2e0fef82007-06-17 19:56:36 -05005710 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005712 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005713
5714 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005715 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005716 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005717 if (NLP_CHK_NODE_ACT(ndlp) &&
5718 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005719 starget->id == ndlp->nlp_sid) {
5720 spin_unlock_irq(shost->host_lock);
5721 return ndlp;
dea31012005-04-17 16:05:31 -05005722 }
5723 }
5724 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005725 return NULL;
5726}
dea31012005-04-17 16:05:31 -05005727
James Smarte59058c2008-08-24 21:49:00 -04005728/**
James Smart3621a712009-04-06 18:47:14 -04005729 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005730 * @starget: kernel scsi target pointer.
5731 **/
James Smart685f0bf2007-04-25 09:53:08 -04005732static void
5733lpfc_get_starget_port_id(struct scsi_target *starget)
5734{
5735 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5736
5737 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005738}
5739
James Smarte59058c2008-08-24 21:49:00 -04005740/**
James Smart3621a712009-04-06 18:47:14 -04005741 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005742 * @starget: kernel scsi target pointer.
5743 *
5744 * Description: Set the target node name to the ndlp node name wwn or zero.
5745 **/
dea31012005-04-17 16:05:31 -05005746static void
5747lpfc_get_starget_node_name(struct scsi_target *starget)
5748{
James Smart685f0bf2007-04-25 09:53:08 -04005749 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005750
James Smart685f0bf2007-04-25 09:53:08 -04005751 fc_starget_node_name(starget) =
5752 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005753}
5754
James Smarte59058c2008-08-24 21:49:00 -04005755/**
James Smart3621a712009-04-06 18:47:14 -04005756 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005757 * @starget: kernel scsi target pointer.
5758 *
5759 * Description: set the target port name to the ndlp port name wwn or zero.
5760 **/
dea31012005-04-17 16:05:31 -05005761static void
5762lpfc_get_starget_port_name(struct scsi_target *starget)
5763{
James Smart685f0bf2007-04-25 09:53:08 -04005764 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005765
James Smart685f0bf2007-04-25 09:53:08 -04005766 fc_starget_port_name(starget) =
5767 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005768}
5769
James Smarte59058c2008-08-24 21:49:00 -04005770/**
James Smart3621a712009-04-06 18:47:14 -04005771 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005772 * @rport: fc rport address.
5773 * @timeout: new value for dev loss tmo.
5774 *
5775 * Description:
5776 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5777 * dev_loss_tmo to one.
5778 **/
dea31012005-04-17 16:05:31 -05005779static void
dea31012005-04-17 16:05:31 -05005780lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5781{
dea31012005-04-17 16:05:31 -05005782 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005783 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005784 else
James Smartc01f3202006-08-18 17:47:08 -04005785 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005786}
5787
James Smarte59058c2008-08-24 21:49:00 -04005788/**
James Smart3621a712009-04-06 18:47:14 -04005789 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005790 *
5791 * Description:
5792 * Macro that uses field to generate a function with the name lpfc_show_rport_
5793 *
5794 * lpfc_show_rport_##field: returns the bytes formatted in buf
5795 * @cdev: class converted to an fc_rport.
5796 * @buf: on return contains the target_field or zero.
5797 *
5798 * Returns: size of formatted string.
5799 **/
dea31012005-04-17 16:05:31 -05005800#define lpfc_rport_show_function(field, format_string, sz, cast) \
5801static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005802lpfc_show_rport_##field (struct device *dev, \
5803 struct device_attribute *attr, \
5804 char *buf) \
dea31012005-04-17 16:05:31 -05005805{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005806 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005807 struct lpfc_rport_data *rdata = rport->hostdata; \
5808 return snprintf(buf, sz, format_string, \
5809 (rdata->target) ? cast rdata->target->field : 0); \
5810}
5811
5812#define lpfc_rport_rd_attr(field, format_string, sz) \
5813 lpfc_rport_show_function(field, format_string, sz, ) \
5814static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5815
James Smarteada2722008-12-04 22:39:13 -05005816/**
James Smart3621a712009-04-06 18:47:14 -04005817 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005818 * @fc_vport: The fc_vport who's symbolic name has been changed.
5819 *
5820 * Description:
5821 * This function is called by the transport after the @fc_vport's symbolic name
5822 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005823 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005824 **/
5825static void
5826lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5827{
5828 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5829
5830 if (vport->port_state == LPFC_VPORT_READY)
5831 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5832}
dea31012005-04-17 16:05:31 -05005833
James Smartf4b4c682009-05-22 14:53:12 -04005834/**
5835 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5836 * @phba: Pointer to lpfc_hba struct.
5837 *
5838 * This function is called by the lpfc_get_cfgparam() routine to set the
5839 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005840 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005841 * before hba port or vport created.
5842 **/
5843static void
5844lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5845{
5846 phba->cfg_log_verbose = verbose;
5847}
5848
dea31012005-04-17 16:05:31 -05005849struct fc_function_template lpfc_transport_functions = {
5850 /* fixed attributes the driver supports */
5851 .show_host_node_name = 1,
5852 .show_host_port_name = 1,
5853 .show_host_supported_classes = 1,
5854 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005855 .show_host_supported_speeds = 1,
5856 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08005857
5858 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005859 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005860
5861 /* dynamic attributes the driver supports */
5862 .get_host_port_id = lpfc_get_host_port_id,
5863 .show_host_port_id = 1,
5864
5865 .get_host_port_type = lpfc_get_host_port_type,
5866 .show_host_port_type = 1,
5867
5868 .get_host_port_state = lpfc_get_host_port_state,
5869 .show_host_port_state = 1,
5870
5871 /* active_fc4s is shown but doesn't change (thus no get function) */
5872 .show_host_active_fc4s = 1,
5873
5874 .get_host_speed = lpfc_get_host_speed,
5875 .show_host_speed = 1,
5876
5877 .get_host_fabric_name = lpfc_get_host_fabric_name,
5878 .show_host_fabric_name = 1,
5879
5880 /*
5881 * The LPFC driver treats linkdown handling as target loss events
5882 * so there are no sysfs handlers for link_down_tmo.
5883 */
5884
5885 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005886 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005887
5888 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5889 .show_rport_maxframe_size = 1,
5890 .show_rport_supported_classes = 1,
5891
dea31012005-04-17 16:05:31 -05005892 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5893 .show_rport_dev_loss_tmo = 1,
5894
5895 .get_starget_port_id = lpfc_get_starget_port_id,
5896 .show_starget_port_id = 1,
5897
5898 .get_starget_node_name = lpfc_get_starget_node_name,
5899 .show_starget_node_name = 1,
5900
5901 .get_starget_port_name = lpfc_get_starget_port_name,
5902 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07005903
5904 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04005905 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5906 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05005907
James Smart92d7f7b2007-06-17 19:56:38 -05005908 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05005909
5910 .vport_disable = lpfc_vport_disable,
5911
5912 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04005913
5914 .bsg_request = lpfc_bsg_request,
5915 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05005916};
5917
James Smart98c9ea52007-10-27 13:37:33 -04005918struct fc_function_template lpfc_vport_transport_functions = {
5919 /* fixed attributes the driver supports */
5920 .show_host_node_name = 1,
5921 .show_host_port_name = 1,
5922 .show_host_supported_classes = 1,
5923 .show_host_supported_fc4s = 1,
5924 .show_host_supported_speeds = 1,
5925 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08005926
5927 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005928 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04005929
5930 /* dynamic attributes the driver supports */
5931 .get_host_port_id = lpfc_get_host_port_id,
5932 .show_host_port_id = 1,
5933
5934 .get_host_port_type = lpfc_get_host_port_type,
5935 .show_host_port_type = 1,
5936
5937 .get_host_port_state = lpfc_get_host_port_state,
5938 .show_host_port_state = 1,
5939
5940 /* active_fc4s is shown but doesn't change (thus no get function) */
5941 .show_host_active_fc4s = 1,
5942
5943 .get_host_speed = lpfc_get_host_speed,
5944 .show_host_speed = 1,
5945
5946 .get_host_fabric_name = lpfc_get_host_fabric_name,
5947 .show_host_fabric_name = 1,
5948
5949 /*
5950 * The LPFC driver treats linkdown handling as target loss events
5951 * so there are no sysfs handlers for link_down_tmo.
5952 */
5953
5954 .get_fc_host_stats = lpfc_get_stats,
5955 .reset_fc_host_stats = lpfc_reset_stats,
5956
5957 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5958 .show_rport_maxframe_size = 1,
5959 .show_rport_supported_classes = 1,
5960
5961 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5962 .show_rport_dev_loss_tmo = 1,
5963
5964 .get_starget_port_id = lpfc_get_starget_port_id,
5965 .show_starget_port_id = 1,
5966
5967 .get_starget_node_name = lpfc_get_starget_node_name,
5968 .show_starget_node_name = 1,
5969
5970 .get_starget_port_name = lpfc_get_starget_port_name,
5971 .show_starget_port_name = 1,
5972
5973 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
5974 .terminate_rport_io = lpfc_terminate_rport_io,
5975
5976 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05005977
5978 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04005979};
5980
James Smarte59058c2008-08-24 21:49:00 -04005981/**
James Smart3621a712009-04-06 18:47:14 -04005982 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04005983 * @phba: lpfc_hba pointer.
5984 **/
dea31012005-04-17 16:05:31 -05005985void
5986lpfc_get_cfgparam(struct lpfc_hba *phba)
5987{
James Smart49aa1432012-08-03 12:36:42 -04005988 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04005989 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005990 lpfc_cr_delay_init(phba, lpfc_cr_delay);
5991 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05005992 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05005993 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
5994 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005995 lpfc_ack0_init(phba, lpfc_ack0);
5996 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04005997 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05005998 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04005999 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006000 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006001 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006002 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006003 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6004 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006005 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006006 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smartda0436e2009-05-22 14:51:39 -04006007 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006008 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006009 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6010 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006011
James Smart1ba981f2014-02-20 09:56:45 -05006012 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6013 if (phba->sli_rev != LPFC_SLI_REV4)
6014 phba->cfg_EnableXLane = 0;
6015 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006016
James Smart1ba981f2014-02-20 09:56:45 -05006017 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6018 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6019 phba->cfg_oas_lun_state = 0;
6020 phba->cfg_oas_lun_status = 0;
6021 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006022 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006023 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006024 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6025 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006026 if (phba->sli_rev == LPFC_SLI_REV4)
6027 phba->cfg_poll = 0;
6028 else
James Smart1ba981f2014-02-20 09:56:45 -05006029 phba->cfg_poll = lpfc_poll;
James Smart4258e982015-12-16 18:11:58 -05006030
James Smart895427b2017-02-12 13:52:30 -08006031 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6032
6033 /* Initialize first burst. Target vs Initiator are different. */
6034 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6035 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6036 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6037
6038 if (phba->sli_rev != LPFC_SLI_REV4) {
6039 /* NVME only supported on SLI4 */
6040 phba->nvmet_support = 0;
6041 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6042 } else {
6043 /* We MUST have FCP support */
6044 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6045 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6046 }
6047
6048 /* A value of 0 means use the number of CPUs found in the system */
6049 if (phba->cfg_nvme_io_channel == 0)
6050 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6051 if (phba->cfg_fcp_io_channel == 0)
6052 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6053
6054 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6055 phba->cfg_nvme_io_channel = 0;
6056
6057 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6058 phba->cfg_fcp_io_channel = 0;
6059
6060 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6061 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6062 else
6063 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6064
James Smart352e5fd2016-12-30 06:57:47 -08006065 phba->cfg_soft_wwnn = 0L;
6066 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006067 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006068 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006069 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006070 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006071 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006072 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006073 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006074 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006075 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006076 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006077 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006078 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006079 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006080 return;
6081}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006082
James Smarte59058c2008-08-24 21:49:00 -04006083/**
James Smart895427b2017-02-12 13:52:30 -08006084 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6085 * dependencies between protocols and roles.
6086 * @phba: lpfc_hba pointer.
6087 **/
6088void
6089lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6090{
6091 phba->nvmet_support = 0;
6092 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6093 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6094 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6095 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6096
6097 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6098 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6099 else
6100 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6101}
6102
6103/**
James Smart3621a712009-04-06 18:47:14 -04006104 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006105 * @vport: lpfc_vport pointer.
6106 **/
James Smart3de2a652007-08-02 11:09:59 -04006107void
6108lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6109{
James Smarte8b62012007-08-02 11:10:09 -04006110 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006111 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006112 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006113 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6114 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6115 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6116 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6117 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6118 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006119 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006120 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006121 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6122 lpfc_max_luns_init(vport, lpfc_max_luns);
6123 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006124 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006125 return;
6126}