blob: 835c6c1f4cd4f2bb253934e126f8b7cf88b872ae [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"
James Smartf358dd02017-02-12 13:52:34 -080049#include "lpfc_nvmet.h"
dea31012005-04-17 16:05:31 -050050#include "lpfc_logmsg.h"
51#include "lpfc_version.h"
52#include "lpfc_compat.h"
53#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050054#include "lpfc_vport.h"
James Smart93dd1912016-07-06 12:36:10 -070055#include "lpfc_attr.h"
dea31012005-04-17 16:05:31 -050056
James Smart2ea259e2017-02-12 13:52:27 -080057#define LPFC_DEF_DEVLOSS_TMO 30
58#define LPFC_MIN_DEVLOSS_TMO 1
59#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050060
James Smartf7a919b2011-08-21 21:49:16 -040061/*
62 * Write key size should be multiple of 4. If write key is changed
63 * make sure that library write key is also changed.
64 */
65#define LPFC_REG_WRITE_KEY_SIZE 4
66#define LPFC_REG_WRITE_KEY "EMLX"
67
James Smarte59058c2008-08-24 21:49:00 -040068/**
James Smart3621a712009-04-06 18:47:14 -040069 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040070 * @incr: integer to convert.
71 * @hdw: ascii string holding converted integer plus a string terminator.
72 *
73 * Description:
74 * JEDEC Joint Electron Device Engineering Council.
75 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
76 * character string. The string is then terminated with a NULL in byte 9.
77 * Hex 0-9 becomes ascii '0' to '9'.
78 * Hex a-f becomes ascii '=' to 'B' capital B.
79 *
80 * Notes:
81 * Coded for 32 bit integers only.
82 **/
dea31012005-04-17 16:05:31 -050083static void
84lpfc_jedec_to_ascii(int incr, char hdw[])
85{
86 int i, j;
87 for (i = 0; i < 8; i++) {
88 j = (incr & 0xf);
89 if (j <= 9)
90 hdw[7 - i] = 0x30 + j;
91 else
92 hdw[7 - i] = 0x61 + j - 10;
93 incr = (incr >> 4);
94 }
95 hdw[8] = 0;
96 return;
97}
98
James Smarte59058c2008-08-24 21:49:00 -040099/**
James Smart3621a712009-04-06 18:47:14 -0400100 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400101 * @dev: class unused variable.
102 * @attr: device attribute, not used.
103 * @buf: on return contains the module description text.
104 *
105 * Returns: size of formatted string.
106 **/
dea31012005-04-17 16:05:31 -0500107static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100108lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
109 char *buf)
dea31012005-04-17 16:05:31 -0500110{
111 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
112}
113
James Smart45ed1192009-10-02 15:17:02 -0400114/**
115 * lpfc_enable_fip_show - Return the fip mode of the HBA
116 * @dev: class unused variable.
117 * @attr: device attribute, not used.
118 * @buf: on return contains the module description text.
119 *
120 * Returns: size of formatted string.
121 **/
122static ssize_t
123lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
124 char *buf)
125{
126 struct Scsi_Host *shost = class_to_shost(dev);
127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
129
130 if (phba->hba_flag & HBA_FIP_SUPPORT)
131 return snprintf(buf, PAGE_SIZE, "1\n");
132 else
133 return snprintf(buf, PAGE_SIZE, "0\n");
134}
135
James Smart81301a92008-12-04 22:39:46 -0500136static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800137lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
138 char *buf)
139{
140 struct Scsi_Host *shost = class_to_shost(dev);
141 struct lpfc_vport *vport = shost_priv(shost);
142 struct lpfc_hba *phba = vport->phba;
James Smartf358dd02017-02-12 13:52:34 -0800143 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800144 struct nvme_fc_local_port *localport;
145 struct lpfc_nvme_lport *lport;
146 struct lpfc_nvme_rport *rport;
147 struct nvme_fc_remote_port *nrport;
148 char *statep;
149 int len = 0;
150
151 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
152 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
153 return len;
154 }
James Smartf358dd02017-02-12 13:52:34 -0800155 if (phba->nvmet_support) {
156 if (!phba->targetport) {
157 len = snprintf(buf, PAGE_SIZE,
158 "NVME Target: x%llx is not allocated\n",
159 wwn_to_u64(vport->fc_portname.u.wwn));
160 return len;
161 }
162 /* Port state is only one of two values for now. */
163 if (phba->targetport->port_id)
164 statep = "REGISTERED";
165 else
166 statep = "INIT";
167 len += snprintf(buf + len, PAGE_SIZE - len,
168 "NVME Target: Enabled State %s\n",
169 statep);
170 len += snprintf(buf + len, PAGE_SIZE - len,
171 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
172 "NVME Target: lpfc",
173 phba->brd_no,
174 wwn_to_u64(vport->fc_portname.u.wwn),
175 wwn_to_u64(vport->fc_nodename.u.wwn),
176 phba->targetport->port_id);
177
178 len += snprintf(buf + len, PAGE_SIZE,
179 "\nNVME Target: Statistics\n");
180 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
181 len += snprintf(buf+len, PAGE_SIZE-len,
182 "LS: Rcv %08x Drop %08x Abort %08x\n",
183 atomic_read(&tgtp->rcv_ls_req_in),
184 atomic_read(&tgtp->rcv_ls_req_drop),
185 atomic_read(&tgtp->xmt_ls_abort));
186 if (atomic_read(&tgtp->rcv_ls_req_in) !=
187 atomic_read(&tgtp->rcv_ls_req_out)) {
188 len += snprintf(buf+len, PAGE_SIZE-len,
189 "Rcv LS: in %08x != out %08x\n",
190 atomic_read(&tgtp->rcv_ls_req_in),
191 atomic_read(&tgtp->rcv_ls_req_out));
192 }
193
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
196 atomic_read(&tgtp->xmt_ls_rsp),
197 atomic_read(&tgtp->xmt_ls_drop),
198 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
199 atomic_read(&tgtp->xmt_ls_rsp_error));
200
201 len += snprintf(buf+len, PAGE_SIZE-len,
202 "FCP: Rcv %08x Drop %08x\n",
203 atomic_read(&tgtp->rcv_fcp_cmd_in),
204 atomic_read(&tgtp->rcv_fcp_cmd_drop));
205
206 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
207 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
208 len += snprintf(buf+len, PAGE_SIZE-len,
209 "Rcv FCP: in %08x != out %08x\n",
210 atomic_read(&tgtp->rcv_fcp_cmd_in),
211 atomic_read(&tgtp->rcv_fcp_cmd_out));
212 }
213
214 len += snprintf(buf+len, PAGE_SIZE-len,
215 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x\n",
216 atomic_read(&tgtp->xmt_fcp_read),
217 atomic_read(&tgtp->xmt_fcp_read_rsp),
218 atomic_read(&tgtp->xmt_fcp_write),
219 atomic_read(&tgtp->xmt_fcp_rsp));
220
221 len += snprintf(buf+len, PAGE_SIZE-len,
222 "FCP Rsp: abort %08x drop %08x\n",
223 atomic_read(&tgtp->xmt_fcp_abort),
224 atomic_read(&tgtp->xmt_fcp_drop));
225
226 len += snprintf(buf+len, PAGE_SIZE-len,
227 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
228 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
229 atomic_read(&tgtp->xmt_fcp_rsp_error),
230 atomic_read(&tgtp->xmt_fcp_rsp_drop));
231
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "ABORT: Xmt %08x Err %08x Cmpl %08x",
234 atomic_read(&tgtp->xmt_abort_rsp),
235 atomic_read(&tgtp->xmt_abort_rsp_error),
236 atomic_read(&tgtp->xmt_abort_cmpl));
237
238 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
239 return len;
240 }
James Smart895427b2017-02-12 13:52:30 -0800241
242 localport = vport->localport;
243 if (!localport) {
244 len = snprintf(buf, PAGE_SIZE,
245 "NVME Initiator x%llx is not allocated\n",
246 wwn_to_u64(vport->fc_portname.u.wwn));
247 return len;
248 }
249 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
250
251 spin_lock_irq(shost->host_lock);
252 lport = (struct lpfc_nvme_lport *)localport->private;
253
254 /* Port state is only one of two values for now. */
255 if (localport->port_id)
256 statep = "ONLINE";
257 else
258 statep = "UNKNOWN ";
259
260 len += snprintf(buf + len, PAGE_SIZE - len,
261 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
262 "NVME LPORT lpfc",
263 phba->brd_no,
264 wwn_to_u64(vport->fc_portname.u.wwn),
265 wwn_to_u64(vport->fc_nodename.u.wwn),
266 localport->port_id, statep);
267
268 list_for_each_entry(rport, &lport->rport_list, list) {
269 /* local short-hand pointer. */
270 nrport = rport->remoteport;
271
272 /* Port state is only one of two values for now. */
273 switch (nrport->port_state) {
274 case FC_OBJSTATE_ONLINE:
275 statep = "ONLINE";
276 break;
277 case FC_OBJSTATE_UNKNOWN:
278 statep = "UNKNOWN ";
279 break;
280 default:
281 statep = "UNSUPPORTED";
282 break;
283 }
284
285 /* Tab in to show lport ownership. */
286 len += snprintf(buf + len, PAGE_SIZE - len,
287 "NVME RPORT ");
288 if (phba->brd_no >= 10)
289 len += snprintf(buf + len, PAGE_SIZE - len, " ");
290
291 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
292 nrport->port_name);
293 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
294 nrport->node_name);
295 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
296 nrport->port_id);
297
298 switch (nrport->port_role) {
299 case FC_PORT_ROLE_NVME_INITIATOR:
300 len += snprintf(buf + len, PAGE_SIZE - len,
301 "INITIATOR ");
302 break;
303 case FC_PORT_ROLE_NVME_TARGET:
304 len += snprintf(buf + len, PAGE_SIZE - len,
305 "TARGET ");
306 break;
307 case FC_PORT_ROLE_NVME_DISCOVERY:
308 len += snprintf(buf + len, PAGE_SIZE - len,
309 "DISCOVERY ");
310 break;
311 default:
312 len += snprintf(buf + len, PAGE_SIZE - len,
313 "UNKNOWN_ROLE x%x",
314 nrport->port_role);
315 break;
316 }
317 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
318 /* Terminate the string. */
319 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
320 }
321 spin_unlock_irq(shost->host_lock);
322
323 len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n");
324 len += snprintf(buf+len, PAGE_SIZE-len,
325 "LS: Xmt %016llx Cmpl %016llx\n",
326 phba->fc4NvmeLsRequests,
327 phba->fc4NvmeLsCmpls);
328
329 len += snprintf(buf+len, PAGE_SIZE-len,
330 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
331 phba->fc4NvmeInputRequests,
332 phba->fc4NvmeOutputRequests,
333 phba->fc4NvmeControlRequests);
334
335 len += snprintf(buf+len, PAGE_SIZE-len,
336 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
337
338 return len;
339}
340
341static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500342lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
343 char *buf)
344{
345 struct Scsi_Host *shost = class_to_shost(dev);
346 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
347 struct lpfc_hba *phba = vport->phba;
348
349 if (phba->cfg_enable_bg)
350 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
351 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
352 else
353 return snprintf(buf, PAGE_SIZE,
354 "BlockGuard Not Supported\n");
355 else
356 return snprintf(buf, PAGE_SIZE,
357 "BlockGuard Disabled\n");
358}
359
360static ssize_t
361lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
362 char *buf)
363{
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367
James Smart87b5c322008-12-16 10:34:09 -0500368 return snprintf(buf, PAGE_SIZE, "%llu\n",
369 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500370}
371
372static ssize_t
373lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
374 char *buf)
375{
376 struct Scsi_Host *shost = class_to_shost(dev);
377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
378 struct lpfc_hba *phba = vport->phba;
379
James Smart87b5c322008-12-16 10:34:09 -0500380 return snprintf(buf, PAGE_SIZE, "%llu\n",
381 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500382}
383
384static ssize_t
385lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
386 char *buf)
387{
388 struct Scsi_Host *shost = class_to_shost(dev);
389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
391
James Smart87b5c322008-12-16 10:34:09 -0500392 return snprintf(buf, PAGE_SIZE, "%llu\n",
393 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500394}
395
James Smarte59058c2008-08-24 21:49:00 -0400396/**
James Smart3621a712009-04-06 18:47:14 -0400397 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400398 * @dev: class converted to a Scsi_host structure.
399 * @attr: device attribute, not used.
400 * @buf: on return contains the formatted text from lpfc_info().
401 *
402 * Returns: size of formatted string.
403 **/
dea31012005-04-17 16:05:31 -0500404static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100405lpfc_info_show(struct device *dev, struct device_attribute *attr,
406 char *buf)
dea31012005-04-17 16:05:31 -0500407{
Tony Jonesee959b02008-02-22 00:13:36 +0100408 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500409
dea31012005-04-17 16:05:31 -0500410 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
411}
412
James Smarte59058c2008-08-24 21:49:00 -0400413/**
James Smart3621a712009-04-06 18:47:14 -0400414 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400415 * @dev: class converted to a Scsi_host structure.
416 * @attr: device attribute, not used.
417 * @buf: on return contains the formatted text serial number.
418 *
419 * Returns: size of formatted string.
420 **/
dea31012005-04-17 16:05:31 -0500421static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100422lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
423 char *buf)
dea31012005-04-17 16:05:31 -0500424{
Tony Jonesee959b02008-02-22 00:13:36 +0100425 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500426 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
427 struct lpfc_hba *phba = vport->phba;
428
dea31012005-04-17 16:05:31 -0500429 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
430}
431
James Smarte59058c2008-08-24 21:49:00 -0400432/**
James Smart3621a712009-04-06 18:47:14 -0400433 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400434 * @dev: class converted to a Scsi_host structure.
435 * @attr: device attribute, not used.
436 * @buf: on return contains the formatted support level.
437 *
438 * Description:
439 * Returns a number indicating the temperature sensor level currently
440 * supported, zero or one in ascii.
441 *
442 * Returns: size of formatted string.
443 **/
dea31012005-04-17 16:05:31 -0500444static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100445lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
446 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400447{
Tony Jonesee959b02008-02-22 00:13:36 +0100448 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
450 struct lpfc_hba *phba = vport->phba;
451 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
452}
453
James Smarte59058c2008-08-24 21:49:00 -0400454/**
James Smart3621a712009-04-06 18:47:14 -0400455 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400456 * @dev: class converted to a Scsi_host structure.
457 * @attr: device attribute, not used.
458 * @buf: on return contains the scsi vpd model description.
459 *
460 * Returns: size of formatted string.
461 **/
James Smart57127f12007-10-27 13:37:05 -0400462static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100463lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
464 char *buf)
dea31012005-04-17 16:05:31 -0500465{
Tony Jonesee959b02008-02-22 00:13:36 +0100466 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500467 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
468 struct lpfc_hba *phba = vport->phba;
469
dea31012005-04-17 16:05:31 -0500470 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
471}
472
James Smarte59058c2008-08-24 21:49:00 -0400473/**
James Smart3621a712009-04-06 18:47:14 -0400474 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400475 * @dev: class converted to a Scsi_host structure.
476 * @attr: device attribute, not used.
477 * @buf: on return contains the scsi vpd model name.
478 *
479 * Returns: size of formatted string.
480 **/
dea31012005-04-17 16:05:31 -0500481static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100482lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
483 char *buf)
dea31012005-04-17 16:05:31 -0500484{
Tony Jonesee959b02008-02-22 00:13:36 +0100485 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
487 struct lpfc_hba *phba = vport->phba;
488
dea31012005-04-17 16:05:31 -0500489 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
490}
491
James Smarte59058c2008-08-24 21:49:00 -0400492/**
James Smart3621a712009-04-06 18:47:14 -0400493 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400494 * @dev: class converted to a Scsi_host structure.
495 * @attr: device attribute, not used.
496 * @buf: on return contains the scsi vpd program type.
497 *
498 * Returns: size of formatted string.
499 **/
dea31012005-04-17 16:05:31 -0500500static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100501lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
502 char *buf)
dea31012005-04-17 16:05:31 -0500503{
Tony Jonesee959b02008-02-22 00:13:36 +0100504 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
506 struct lpfc_hba *phba = vport->phba;
507
dea31012005-04-17 16:05:31 -0500508 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
509}
510
James Smarte59058c2008-08-24 21:49:00 -0400511/**
James Smart3621a712009-04-06 18:47:14 -0400512 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400513 * @dev: class converted to a Scsi_host structure.
514 * @attr: device attribute, not used.
515 * @buf: on return contains the Menlo Maintenance sli flag.
516 *
517 * Returns: size of formatted string.
518 **/
519static ssize_t
520lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
521{
522 struct Scsi_Host *shost = class_to_shost(dev);
523 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
524 struct lpfc_hba *phba = vport->phba;
525
526 return snprintf(buf, PAGE_SIZE, "%d\n",
527 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
528}
529
530/**
James Smart3621a712009-04-06 18:47:14 -0400531 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400532 * @dev: class converted to a Scsi_host structure.
533 * @attr: device attribute, not used.
534 * @buf: on return contains scsi vpd program type.
535 *
536 * Returns: size of formatted string.
537 **/
dea31012005-04-17 16:05:31 -0500538static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100539lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
540 char *buf)
dea31012005-04-17 16:05:31 -0500541{
Tony Jonesee959b02008-02-22 00:13:36 +0100542 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500543 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
544 struct lpfc_hba *phba = vport->phba;
545
dea31012005-04-17 16:05:31 -0500546 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
547}
548
James Smarte59058c2008-08-24 21:49:00 -0400549/**
James Smart3621a712009-04-06 18:47:14 -0400550 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400551 * @dev: class converted to a Scsi_host structure.
552 * @attr: device attribute, not used.
553 * @buf: on return contains the scsi vpd program type.
554 *
555 * Returns: size of formatted string.
556 **/
dea31012005-04-17 16:05:31 -0500557static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100558lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
559 char *buf)
dea31012005-04-17 16:05:31 -0500560{
Tony Jonesee959b02008-02-22 00:13:36 +0100561 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
563 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500564 uint32_t if_type;
565 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500566 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500567 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500568
dea31012005-04-17 16:05:31 -0500569 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500570 if_type = phba->sli4_hba.pc_sli4_params.if_type;
571 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
572
573 if (phba->sli_rev < LPFC_SLI_REV4)
574 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
575 fwrev, phba->sli_rev);
576 else
577 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
578 fwrev, phba->sli_rev, if_type, sli_family);
579
580 return len;
dea31012005-04-17 16:05:31 -0500581}
582
James Smarte59058c2008-08-24 21:49:00 -0400583/**
James Smart3621a712009-04-06 18:47:14 -0400584 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400585 * @dev: class converted to a Scsi_host structure.
586 * @attr: device attribute, not used.
587 * @buf: on return contains the scsi vpd program type.
588 *
589 * Returns: size of formatted string.
590 **/
dea31012005-04-17 16:05:31 -0500591static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100592lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500593{
594 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100595 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500596 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
597 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500598 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500599
dea31012005-04-17 16:05:31 -0500600 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
601 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
602}
James Smarte59058c2008-08-24 21:49:00 -0400603
604/**
James Smart3621a712009-04-06 18:47:14 -0400605 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400606 * @dev: class converted to a Scsi_host structure.
607 * @attr: device attribute, not used.
608 * @buf: on return contains the ROM and FCode ascii strings.
609 *
610 * Returns: size of formatted string.
611 **/
dea31012005-04-17 16:05:31 -0500612static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100613lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
614 char *buf)
dea31012005-04-17 16:05:31 -0500615{
Tony Jonesee959b02008-02-22 00:13:36 +0100616 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500617 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
618 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400619 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500620
James Smarta0683bf2015-04-07 15:07:16 -0400621 if (phba->sli_rev < LPFC_SLI_REV4)
622 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
623
624 lpfc_decode_firmware_rev(phba, fwrev, 1);
625 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500626}
James Smarte59058c2008-08-24 21:49:00 -0400627
628/**
James Smart3621a712009-04-06 18:47:14 -0400629 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400630 * @dev: class converted to a Scsi_host structure.
631 * @attr: device attribute, not used.
632 * @buf: on return contains text describing the state of the link.
633 *
634 * Notes:
635 * The switch statement has no default so zero will be returned.
636 *
637 * Returns: size of formatted string.
638 **/
dea31012005-04-17 16:05:31 -0500639static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100640lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
641 char *buf)
dea31012005-04-17 16:05:31 -0500642{
Tony Jonesee959b02008-02-22 00:13:36 +0100643 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500644 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
645 struct lpfc_hba *phba = vport->phba;
646 int len = 0;
647
648 switch (phba->link_state) {
649 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500650 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500651 case LPFC_INIT_START:
652 case LPFC_INIT_MBX_CMDS:
653 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500654 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400655 if (phba->hba_flag & LINK_DISABLED)
656 len += snprintf(buf + len, PAGE_SIZE-len,
657 "Link Down - User disabled\n");
658 else
659 len += snprintf(buf + len, PAGE_SIZE-len,
660 "Link Down\n");
dea31012005-04-17 16:05:31 -0500661 break;
662 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500663 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500664 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400665 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500666
667 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500668 case LPFC_LOCAL_CFG_LINK:
669 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500670 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500671 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500672 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500673 case LPFC_FLOGI:
674 case LPFC_FABRIC_CFG_LINK:
675 case LPFC_NS_REG:
676 case LPFC_NS_QRY:
677 case LPFC_BUILD_DISC_LIST:
678 case LPFC_DISC_AUTH:
679 len += snprintf(buf + len, PAGE_SIZE - len,
680 "Discovery\n");
681 break;
682 case LPFC_VPORT_READY:
683 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
684 break;
685
James Smart92d7f7b2007-06-17 19:56:38 -0500686 case LPFC_VPORT_FAILED:
687 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
688 break;
689
690 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500691 len += snprintf(buf + len, PAGE_SIZE - len,
692 "Unknown\n");
693 break;
694 }
James Smart84774a42008-08-24 21:50:06 -0400695 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
696 len += snprintf(buf + len, PAGE_SIZE-len,
697 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500698 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500699 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500700 len += snprintf(buf + len, PAGE_SIZE-len,
701 " Public Loop\n");
702 else
703 len += snprintf(buf + len, PAGE_SIZE-len,
704 " Private Loop\n");
705 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500706 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500707 len += snprintf(buf + len, PAGE_SIZE-len,
708 " Fabric\n");
709 else
710 len += snprintf(buf + len, PAGE_SIZE-len,
711 " Point-2-Point\n");
712 }
713 }
James Smart2e0fef82007-06-17 19:56:36 -0500714
dea31012005-04-17 16:05:31 -0500715 return len;
716}
717
James Smarte59058c2008-08-24 21:49:00 -0400718/**
James Smart026abb82011-12-13 13:20:45 -0500719 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
720 * @dev: class unused variable.
721 * @attr: device attribute, not used.
722 * @buf: on return contains the module description text.
723 *
724 * Returns: size of formatted string.
725 **/
726static ssize_t
727lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
728 char *buf)
729{
730 struct Scsi_Host *shost = class_to_shost(dev);
731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
732 struct lpfc_hba *phba = vport->phba;
733
734 if (phba->sli_rev < LPFC_SLI_REV4)
735 return snprintf(buf, PAGE_SIZE, "fc\n");
736
737 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
738 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
739 return snprintf(buf, PAGE_SIZE, "fcoe\n");
740 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
741 return snprintf(buf, PAGE_SIZE, "fc\n");
742 }
743 return snprintf(buf, PAGE_SIZE, "unknown\n");
744}
745
746/**
James Smart1ba981f2014-02-20 09:56:45 -0500747 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
748 * (OAS) is supported.
749 * @dev: class unused variable.
750 * @attr: device attribute, not used.
751 * @buf: on return contains the module description text.
752 *
753 * Returns: size of formatted string.
754 **/
755static ssize_t
756lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
757 char *buf)
758{
759 struct Scsi_Host *shost = class_to_shost(dev);
760 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
761 struct lpfc_hba *phba = vport->phba;
762
763 return snprintf(buf, PAGE_SIZE, "%d\n",
764 phba->sli4_hba.pc_sli4_params.oas_supported);
765}
766
767/**
James Smart84d1b002010-02-12 14:42:33 -0500768 * lpfc_link_state_store - Transition the link_state on an HBA port
769 * @dev: class device that is converted into a Scsi_host.
770 * @attr: device attribute, not used.
771 * @buf: one or more lpfc_polling_flags values.
772 * @count: not used.
773 *
774 * Returns:
775 * -EINVAL if the buffer is not "up" or "down"
776 * return from link state change function if non-zero
777 * length of the buf on success
778 **/
779static ssize_t
780lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
781 const char *buf, size_t count)
782{
783 struct Scsi_Host *shost = class_to_shost(dev);
784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
785 struct lpfc_hba *phba = vport->phba;
786
787 int status = -EINVAL;
788
789 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
790 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400791 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500792 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
793 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400794 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500795
796 if (status == 0)
797 return strlen(buf);
798 else
799 return status;
800}
801
802/**
James Smart3621a712009-04-06 18:47:14 -0400803 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400804 * @dev: class device that is converted into a Scsi_host.
805 * @attr: device attribute, not used.
806 * @buf: on return contains the sum of fc mapped and unmapped.
807 *
808 * Description:
809 * Returns the ascii text number of the sum of the fc mapped and unmapped
810 * vport counts.
811 *
812 * Returns: size of formatted string.
813 **/
dea31012005-04-17 16:05:31 -0500814static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100815lpfc_num_discovered_ports_show(struct device *dev,
816 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500817{
Tony Jonesee959b02008-02-22 00:13:36 +0100818 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500819 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
820
821 return snprintf(buf, PAGE_SIZE, "%d\n",
822 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500823}
824
James Smarte59058c2008-08-24 21:49:00 -0400825/**
James Smart3621a712009-04-06 18:47:14 -0400826 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400827 * @shost: Scsi_Host pointer.
828 *
829 * Description:
830 * Bring the link down gracefully then re-init the link. The firmware will
831 * re-init the fiber channel interface as required. Does not issue a LIP.
832 *
833 * Returns:
834 * -EPERM port offline or management commands are being blocked
835 * -ENOMEM cannot allocate memory for the mailbox command
836 * -EIO error sending the mailbox command
837 * zero for success
838 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700839static int
James Smart2e0fef82007-06-17 19:56:36 -0500840lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500841{
James Smart2e0fef82007-06-17 19:56:36 -0500842 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
843 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500844 LPFC_MBOXQ_t *pmboxq;
845 int mbxstatus = MBXERR_ERROR;
846
James Smart2e0fef82007-06-17 19:56:36 -0500847 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500848 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500849 return -EPERM;
850
851 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
852
853 if (!pmboxq)
854 return -ENOMEM;
855
856 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400857 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
858 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400859
James Smart33ccf8d2006-08-17 11:57:58 -0400860 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500861
James Smart04c68492009-05-22 14:52:52 -0400862 if ((mbxstatus == MBX_SUCCESS) &&
863 (pmboxq->u.mb.mbxStatus == 0 ||
864 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400865 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
866 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
867 phba->cfg_link_speed);
868 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
869 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400870 if ((mbxstatus == MBX_SUCCESS) &&
871 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
872 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
873 "2859 SLI authentication is required "
874 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400875 }
876
James Smart5b8bd0c2007-04-25 09:52:49 -0400877 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500878 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400879 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500880
881 if (mbxstatus == MBXERR_ERROR)
882 return -EIO;
883
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700884 return 0;
dea31012005-04-17 16:05:31 -0500885}
886
James Smart895427b2017-02-12 13:52:30 -0800887int
888lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
889{
890 int cnt = 0;
891
892 spin_lock_irq(lock);
893 while (!list_empty(q)) {
894 spin_unlock_irq(lock);
895 msleep(20);
896 if (cnt++ > 250) { /* 5 secs */
897 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
898 "0466 %s %s\n",
899 "Outstanding IO when ",
900 "bringing Adapter offline\n");
901 return 0;
902 }
903 spin_lock_irq(lock);
904 }
905 spin_unlock_irq(lock);
906 return 1;
907}
908
James Smarte59058c2008-08-24 21:49:00 -0400909/**
James Smart3621a712009-04-06 18:47:14 -0400910 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400911 * @phba: lpfc_hba pointer.
912 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
913 *
914 * Notes:
915 * Assumes any error from lpfc_do_offline() will be negative.
916 * Can wait up to 5 seconds for the port ring buffers count
917 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400918 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400919 *
920 * Returns:
921 * -EIO error posting the event
922 * zero for success
923 **/
James Smart40496f02006-07-06 15:50:22 -0400924static int
James Smart46fa3112007-04-25 09:51:45 -0400925lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
926{
927 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800928 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400929 struct lpfc_sli_ring *pring;
930 struct lpfc_sli *psli;
931 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400932 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500933 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400934
935 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500936 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400937 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500938 if (rc == 0)
939 return -ENOMEM;
940
James Smart46fa3112007-04-25 09:51:45 -0400941 wait_for_completion(&online_compl);
942
943 if (status != 0)
944 return -EIO;
945
946 psli = &phba->sli;
947
James Smart09372822008-01-11 01:52:54 -0500948 /* Wait a little for things to settle down, but not
949 * long enough for dev loss timeout to expire.
950 */
James Smart895427b2017-02-12 13:52:30 -0800951 if (phba->sli_rev != LPFC_SLI_REV4) {
952 for (i = 0; i < psli->num_rings; i++) {
953 pring = &psli->sli3_ring[i];
954 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
955 &phba->hbalock))
956 goto out;
957 }
958 } else {
959 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
960 pring = qp->pring;
961 if (!pring)
962 continue;
963 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
964 &pring->ring_lock))
965 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400966 }
967 }
James Smart895427b2017-02-12 13:52:30 -0800968out:
James Smart46fa3112007-04-25 09:51:45 -0400969 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500970 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
971 if (rc == 0)
972 return -ENOMEM;
973
James Smart46fa3112007-04-25 09:51:45 -0400974 wait_for_completion(&online_compl);
975
976 if (status != 0)
977 return -EIO;
978
979 return 0;
980}
981
James Smarte59058c2008-08-24 21:49:00 -0400982/**
James Smart3621a712009-04-06 18:47:14 -0400983 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400984 * @phba: lpfc_hba pointer.
985 *
986 * Description:
987 * If the port is configured to allow a reset then the hba is brought
988 * offline then online.
989 *
990 * Notes:
991 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500992 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400993 *
994 * Returns:
995 * lpfc_do_offline() return code if not zero
996 * -EIO reset not configured or error posting the event
997 * zero for success
998 **/
James Smart7f860592011-03-11 16:05:52 -0500999int
James Smart40496f02006-07-06 15:50:22 -04001000lpfc_selective_reset(struct lpfc_hba *phba)
1001{
1002 struct completion online_compl;
1003 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001004 int rc;
James Smart40496f02006-07-06 15:50:22 -04001005
James Smart71157c92013-07-15 18:34:36 -04001006 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001007 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001008
James Smart71157c92013-07-15 18:34:36 -04001009 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1010 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001011
James Smart71157c92013-07-15 18:34:36 -04001012 if (status != 0)
1013 return status;
1014 }
James Smart40496f02006-07-06 15:50:22 -04001015
1016 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001017 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001018 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001019 if (rc == 0)
1020 return -ENOMEM;
1021
James Smart40496f02006-07-06 15:50:22 -04001022 wait_for_completion(&online_compl);
1023
1024 if (status != 0)
1025 return -EIO;
1026
1027 return 0;
1028}
1029
James Smarte59058c2008-08-24 21:49:00 -04001030/**
James Smart3621a712009-04-06 18:47:14 -04001031 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001032 * @dev: class device that is converted into a Scsi_host.
1033 * @attr: device attribute, not used.
1034 * @buf: containing the string "selective".
1035 * @count: unused variable.
1036 *
1037 * Description:
1038 * If the buf contains the string "selective" then lpfc_selective_reset()
1039 * is called to perform the reset.
1040 *
1041 * Notes:
1042 * Assumes any error from lpfc_selective_reset() will be negative.
1043 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001044 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001045 *
1046 * Returns:
1047 * -EINVAL if the buffer does not contain the string "selective"
1048 * length of buf if lpfc-selective_reset() if the call succeeds
1049 * return value of lpfc_selective_reset() if the call fails
1050**/
James Smart40496f02006-07-06 15:50:22 -04001051static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001052lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1053 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001054{
Tony Jonesee959b02008-02-22 00:13:36 +01001055 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001056 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1057 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001058 int status = -EINVAL;
1059
James Smart73d91e52011-10-10 21:32:10 -04001060 if (!phba->cfg_enable_hba_reset)
1061 return -EACCES;
1062
James Smart40496f02006-07-06 15:50:22 -04001063 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001064 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001065
1066 if (status == 0)
1067 return strlen(buf);
1068 else
1069 return status;
1070}
1071
James Smarte59058c2008-08-24 21:49:00 -04001072/**
James Smart88a2cfb2011-07-22 18:36:33 -04001073 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1074 * @phba: lpfc_hba pointer.
1075 *
1076 * Description:
1077 * SLI4 interface type-2 device to wait on the sliport status register for
1078 * the readyness after performing a firmware reset.
1079 *
1080 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001081 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001082 * reset, -EIO when port timeout from recovering from the reset.
1083 *
1084 * Note:
1085 * As the caller will interpret the return code by value, be careful in making
1086 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001087 **/
James Smart73d91e52011-10-10 21:32:10 -04001088int
James Smart88a2cfb2011-07-22 18:36:33 -04001089lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1090{
James Smartf7a919b2011-08-21 21:49:16 -04001091 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001092 int i;
1093
James Smartf7a919b2011-08-21 21:49:16 -04001094 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001095 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1096 &portstat_reg.word0);
1097
Masanari Iida0b1587b2013-07-17 04:37:44 +09001098 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001099 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1100 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1101 return -EPERM;
1102
James Smart88a2cfb2011-07-22 18:36:33 -04001103 /* wait for the SLI port firmware ready after firmware reset */
1104 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1105 msleep(10);
1106 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1107 &portstat_reg.word0);
1108 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1109 continue;
1110 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1111 continue;
1112 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1113 continue;
1114 break;
1115 }
1116
1117 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1118 return 0;
1119 else
1120 return -EIO;
1121}
1122
1123/**
James Smart52d52442011-05-24 11:42:45 -04001124 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001125 * @phba: lpfc_hba pointer.
1126 *
1127 * Description:
James Smart52d52442011-05-24 11:42:45 -04001128 * Request SLI4 interface type-2 device to perform a physical register set
1129 * access.
James Smartc0c11512011-05-24 11:41:34 -04001130 *
1131 * Returns:
1132 * zero for success
1133 **/
1134static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001135lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001136{
1137 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001138 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001139 uint32_t before_fc_flag;
1140 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001141 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001142 int status = 0, rc = 0;
1143 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001144
1145 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001146 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001147
James Smart52d52442011-05-24 11:42:45 -04001148 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1149 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1150 LPFC_SLI_INTF_IF_TYPE_2))
1151 return -EPERM;
1152
James Smart026abb82011-12-13 13:20:45 -05001153 /* Keep state if we need to restore back */
1154 before_fc_flag = phba->pport->fc_flag;
1155 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1156
James Smartb76f2dc2011-07-22 18:37:42 -04001157 /* Disable SR-IOV virtual functions if enabled */
1158 if (phba->cfg_sriov_nr_virtfn) {
1159 pci_disable_sriov(pdev);
1160 phba->cfg_sriov_nr_virtfn = 0;
1161 }
James Smart229adb02013-04-17 20:16:51 -04001162
James Smart02936352014-04-04 13:52:12 -04001163 if (opcode == LPFC_FW_DUMP)
1164 phba->hba_flag |= HBA_FW_DUMP_OP;
1165
James Smartc0c11512011-05-24 11:41:34 -04001166 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1167
James Smart02936352014-04-04 13:52:12 -04001168 if (status != 0) {
1169 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001170 return status;
James Smart02936352014-04-04 13:52:12 -04001171 }
James Smartc0c11512011-05-24 11:41:34 -04001172
1173 /* wait for the device to be quiesced before firmware reset */
1174 msleep(100);
1175
1176 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1177 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001178
1179 if (opcode == LPFC_FW_DUMP)
1180 reg_val |= LPFC_FW_DUMP_REQUEST;
1181 else if (opcode == LPFC_FW_RESET)
1182 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1183 else if (opcode == LPFC_DV_RESET)
1184 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1185
James Smartc0c11512011-05-24 11:41:34 -04001186 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1187 LPFC_CTL_PDEV_CTL_OFFSET);
1188 /* flush */
1189 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1190
1191 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001192 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1193
James Smart026abb82011-12-13 13:20:45 -05001194 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001195 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001196 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001197 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001198 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001199 } else if (rc == -EIO) {
1200 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001201 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1202 "3153 Fail to perform the requested "
1203 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001204 return rc;
James Smart026abb82011-12-13 13:20:45 -05001205 }
1206
1207 /* keep the original port state */
1208 if (before_fc_flag & FC_OFFLINE_MODE)
1209 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001210
1211 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001212 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1213 LPFC_EVT_ONLINE);
1214 if (!job_posted)
1215 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001216
1217 wait_for_completion(&online_compl);
1218
James Smart026abb82011-12-13 13:20:45 -05001219out:
1220 /* in any case, restore the virtual functions enabled as before */
1221 if (sriov_nr_virtfn) {
1222 sriov_err =
1223 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1224 if (!sriov_err)
1225 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1226 }
James Smartc0c11512011-05-24 11:41:34 -04001227
James Smart026abb82011-12-13 13:20:45 -05001228 /* return proper error code */
1229 if (!rc) {
1230 if (!job_posted)
1231 rc = -ENOMEM;
1232 else if (status)
1233 rc = -EIO;
1234 }
1235 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001236}
1237
1238/**
James Smart3621a712009-04-06 18:47:14 -04001239 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001240 * @dev: class device that is converted into a Scsi_host.
1241 * @attr: device attribute, not used.
1242 * @buf: on return contains the ascii number of nport events.
1243 *
1244 * Returns: size of formatted string.
1245 **/
dea31012005-04-17 16:05:31 -05001246static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001247lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1248 char *buf)
dea31012005-04-17 16:05:31 -05001249{
Tony Jonesee959b02008-02-22 00:13:36 +01001250 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001251 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1252 struct lpfc_hba *phba = vport->phba;
1253
dea31012005-04-17 16:05:31 -05001254 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1255}
1256
James Smarte59058c2008-08-24 21:49:00 -04001257/**
James Smart3621a712009-04-06 18:47:14 -04001258 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001259 * @dev: class device that is converted into a Scsi_host.
1260 * @attr: device attribute, not used.
1261 * @buf: on return contains the state of the adapter.
1262 *
1263 * Returns: size of formatted string.
1264 **/
dea31012005-04-17 16:05:31 -05001265static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001266lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1267 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001268{
Tony Jonesee959b02008-02-22 00:13:36 +01001269 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001270 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1271 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001272 char * state;
1273
James Smart2e0fef82007-06-17 19:56:36 -05001274 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001275 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001276 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001277 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001278 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001279 state = "offline";
1280 else
1281 state = "online";
1282
1283 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1284}
1285
James Smarte59058c2008-08-24 21:49:00 -04001286/**
James Smart3621a712009-04-06 18:47:14 -04001287 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001288 * @dev: class device that is converted into a Scsi_host.
1289 * @attr: device attribute, not used.
1290 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1291 * @count: unused variable.
1292 *
1293 * Returns:
1294 * -EACCES if enable hba reset not enabled
1295 * -EINVAL if the buffer does not contain a valid string (see above)
1296 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1297 * buf length greater than zero indicates success
1298 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001299static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001300lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1301 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001302{
Tony Jonesee959b02008-02-22 00:13:36 +01001303 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001304 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1305 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001306 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001307 char *board_mode_str = NULL;
1308 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001309 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001310
James Smart026abb82011-12-13 13:20:45 -05001311 if (!phba->cfg_enable_hba_reset) {
1312 status = -EACCES;
1313 goto board_mode_out;
1314 }
James Smart88a2cfb2011-07-22 18:36:33 -04001315
1316 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001317 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001318
Jamie Wellnitz41415862006-02-28 19:25:27 -05001319 init_completion(&online_compl);
1320
James Smart46fa3112007-04-25 09:51:45 -04001321 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001322 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001323 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001324 if (rc == 0) {
1325 status = -ENOMEM;
1326 goto board_mode_out;
1327 }
James Smart46fa3112007-04-25 09:51:45 -04001328 wait_for_completion(&online_compl);
1329 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1330 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001331 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001332 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001333 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001334 else
1335 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001336 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001337 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001338 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001339 else
1340 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001341 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001342 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1343 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1344 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1345 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1346 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001347 else
James Smart026abb82011-12-13 13:20:45 -05001348 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001349
James Smart026abb82011-12-13 13:20:45 -05001350board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001351 if (!status)
1352 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001353 else {
1354 board_mode_str = strchr(buf, '\n');
1355 if (board_mode_str)
1356 *board_mode_str = '\0';
1357 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1358 "3097 Failed \"%s\", status(%d), "
1359 "fc_flag(x%x)\n",
1360 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001361 return status;
James Smart026abb82011-12-13 13:20:45 -05001362 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001363}
1364
James Smarte59058c2008-08-24 21:49:00 -04001365/**
James Smart3621a712009-04-06 18:47:14 -04001366 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001367 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001368 * @mxri: max xri count.
1369 * @axri: available xri count.
1370 * @mrpi: max rpi count.
1371 * @arpi: available rpi count.
1372 * @mvpi: max vpi count.
1373 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001374 *
1375 * Description:
1376 * If an integer pointer for an count is not null then the value for the
1377 * count is returned.
1378 *
1379 * Returns:
1380 * zero on error
1381 * one for success
1382 **/
James Smart311464e2007-08-02 11:10:37 -04001383static int
James Smart858c9f62007-06-17 19:56:39 -05001384lpfc_get_hba_info(struct lpfc_hba *phba,
1385 uint32_t *mxri, uint32_t *axri,
1386 uint32_t *mrpi, uint32_t *arpi,
1387 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001388{
James Smart04c68492009-05-22 14:52:52 -04001389 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001390 LPFC_MBOXQ_t *pmboxq;
1391 MAILBOX_t *pmb;
1392 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001393 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001394
1395 /*
1396 * prevent udev from issuing mailbox commands until the port is
1397 * configured.
1398 */
1399 if (phba->link_state < LPFC_LINK_DOWN ||
1400 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001401 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001402 return 0;
1403
1404 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1405 return 0;
1406
1407 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1408 if (!pmboxq)
1409 return 0;
1410 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1411
James Smart04c68492009-05-22 14:52:52 -04001412 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001413 pmb->mbxCommand = MBX_READ_CONFIG;
1414 pmb->mbxOwner = OWN_HOST;
1415 pmboxq->context1 = NULL;
1416
James Smart75baf692010-06-08 18:31:21 -04001417 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001418 rc = MBX_NOT_FINISHED;
1419 else
1420 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1421
1422 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001423 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001424 mempool_free(pmboxq, phba->mbox_mem_pool);
1425 return 0;
1426 }
1427
James Smartda0436e2009-05-22 14:51:39 -04001428 if (phba->sli_rev == LPFC_SLI_REV4) {
1429 rd_config = &pmboxq->u.mqe.un.rd_config;
1430 if (mrpi)
1431 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1432 if (arpi)
1433 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1434 phba->sli4_hba.max_cfg_param.rpi_used;
1435 if (mxri)
1436 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1437 if (axri)
1438 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1439 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001440
1441 /* Account for differences with SLI-3. Get vpi count from
1442 * mailbox data and subtract one for max vpi value.
1443 */
1444 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1445 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1446
James Smartda0436e2009-05-22 14:51:39 -04001447 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001448 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001449 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001450 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001451 } else {
1452 if (mrpi)
1453 *mrpi = pmb->un.varRdConfig.max_rpi;
1454 if (arpi)
1455 *arpi = pmb->un.varRdConfig.avail_rpi;
1456 if (mxri)
1457 *mxri = pmb->un.varRdConfig.max_xri;
1458 if (axri)
1459 *axri = pmb->un.varRdConfig.avail_xri;
1460 if (mvpi)
1461 *mvpi = pmb->un.varRdConfig.max_vpi;
1462 if (avpi)
1463 *avpi = pmb->un.varRdConfig.avail_vpi;
1464 }
James Smart92d7f7b2007-06-17 19:56:38 -05001465
1466 mempool_free(pmboxq, phba->mbox_mem_pool);
1467 return 1;
1468}
1469
James Smarte59058c2008-08-24 21:49:00 -04001470/**
James Smart3621a712009-04-06 18:47:14 -04001471 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001472 * @dev: class device that is converted into a Scsi_host.
1473 * @attr: device attribute, not used.
1474 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1475 *
1476 * Description:
1477 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1478 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1479 * to "Unknown" and the buffer length is returned, therefore the caller
1480 * must check for "Unknown" in the buffer to detect a failure.
1481 *
1482 * Returns: size of formatted string.
1483 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001484static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001485lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1486 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001487{
Tony Jonesee959b02008-02-22 00:13:36 +01001488 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001489 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1490 struct lpfc_hba *phba = vport->phba;
1491 uint32_t cnt;
1492
James Smart858c9f62007-06-17 19:56:39 -05001493 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001494 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1495 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1496}
1497
James Smarte59058c2008-08-24 21:49:00 -04001498/**
James Smart3621a712009-04-06 18:47:14 -04001499 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001500 * @dev: class device that is converted into a Scsi_host.
1501 * @attr: device attribute, not used.
1502 * @buf: containing the used rpi count in decimal or "Unknown".
1503 *
1504 * Description:
1505 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1506 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1507 * to "Unknown" and the buffer length is returned, therefore the caller
1508 * must check for "Unknown" in the buffer to detect a failure.
1509 *
1510 * Returns: size of formatted string.
1511 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001512static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001513lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1514 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001515{
Tony Jonesee959b02008-02-22 00:13:36 +01001516 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001517 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1518 struct lpfc_hba *phba = vport->phba;
1519 uint32_t cnt, acnt;
1520
James Smart858c9f62007-06-17 19:56:39 -05001521 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001522 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1523 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1524}
1525
James Smarte59058c2008-08-24 21:49:00 -04001526/**
James Smart3621a712009-04-06 18:47:14 -04001527 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001528 * @dev: class device that is converted into a Scsi_host.
1529 * @attr: device attribute, not used.
1530 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1531 *
1532 * Description:
1533 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1534 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1535 * to "Unknown" and the buffer length is returned, therefore the caller
1536 * must check for "Unknown" in the buffer to detect a failure.
1537 *
1538 * Returns: size of formatted string.
1539 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001540static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001541lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1542 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001543{
Tony Jonesee959b02008-02-22 00:13:36 +01001544 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1546 struct lpfc_hba *phba = vport->phba;
1547 uint32_t cnt;
1548
James Smart858c9f62007-06-17 19:56:39 -05001549 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001550 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1551 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1552}
1553
James Smarte59058c2008-08-24 21:49:00 -04001554/**
James Smart3621a712009-04-06 18:47:14 -04001555 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001556 * @dev: class device that is converted into a Scsi_host.
1557 * @attr: device attribute, not used.
1558 * @buf: on return contains the used xri count in decimal or "Unknown".
1559 *
1560 * Description:
1561 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1562 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1563 * to "Unknown" and the buffer length is returned, therefore the caller
1564 * must check for "Unknown" in the buffer to detect a failure.
1565 *
1566 * Returns: size of formatted string.
1567 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001568static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001569lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1570 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001571{
Tony Jonesee959b02008-02-22 00:13:36 +01001572 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001573 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1574 struct lpfc_hba *phba = vport->phba;
1575 uint32_t cnt, acnt;
1576
James Smart858c9f62007-06-17 19:56:39 -05001577 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1578 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1579 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1580}
1581
James Smarte59058c2008-08-24 21:49:00 -04001582/**
James Smart3621a712009-04-06 18:47:14 -04001583 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001584 * @dev: class device that is converted into a Scsi_host.
1585 * @attr: device attribute, not used.
1586 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1587 *
1588 * Description:
1589 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1590 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1591 * to "Unknown" and the buffer length is returned, therefore the caller
1592 * must check for "Unknown" in the buffer to detect a failure.
1593 *
1594 * Returns: size of formatted string.
1595 **/
James Smart858c9f62007-06-17 19:56:39 -05001596static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001597lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1598 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001599{
Tony Jonesee959b02008-02-22 00:13:36 +01001600 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001601 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1602 struct lpfc_hba *phba = vport->phba;
1603 uint32_t cnt;
1604
1605 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1606 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1607 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1608}
1609
James Smarte59058c2008-08-24 21:49:00 -04001610/**
James Smart3621a712009-04-06 18:47:14 -04001611 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001612 * @dev: class device that is converted into a Scsi_host.
1613 * @attr: device attribute, not used.
1614 * @buf: on return contains the used vpi count in decimal or "Unknown".
1615 *
1616 * Description:
1617 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1618 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1619 * to "Unknown" and the buffer length is returned, therefore the caller
1620 * must check for "Unknown" in the buffer to detect a failure.
1621 *
1622 * Returns: size of formatted string.
1623 **/
James Smart858c9f62007-06-17 19:56:39 -05001624static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001625lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1626 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001627{
Tony Jonesee959b02008-02-22 00:13:36 +01001628 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001629 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1630 struct lpfc_hba *phba = vport->phba;
1631 uint32_t cnt, acnt;
1632
1633 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001634 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1635 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1636}
1637
James Smarte59058c2008-08-24 21:49:00 -04001638/**
James Smart3621a712009-04-06 18:47:14 -04001639 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001640 * @dev: class device that is converted into a Scsi_host.
1641 * @attr: device attribute, not used.
1642 * @buf: text that must be interpreted to determine if npiv is supported.
1643 *
1644 * Description:
1645 * Buffer will contain text indicating npiv is not suppoerted on the port,
1646 * the port is an NPIV physical port, or it is an npiv virtual port with
1647 * the id of the vport.
1648 *
1649 * Returns: size of formatted string.
1650 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001651static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001652lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1653 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001654{
Tony Jonesee959b02008-02-22 00:13:36 +01001655 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1657 struct lpfc_hba *phba = vport->phba;
1658
1659 if (!(phba->max_vpi))
1660 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1661 if (vport->port_type == LPFC_PHYSICAL_PORT)
1662 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1663 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1664}
1665
James Smarte59058c2008-08-24 21:49:00 -04001666/**
James Smart3621a712009-04-06 18:47:14 -04001667 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001668 * @dev: class device that is converted into a Scsi_host.
1669 * @attr: device attribute, not used.
1670 * @buf: on return contains the cfg_poll in hex.
1671 *
1672 * Notes:
1673 * cfg_poll should be a lpfc_polling_flags type.
1674 *
1675 * Returns: size of formatted string.
1676 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001677static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001678lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1679 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001680{
Tony Jonesee959b02008-02-22 00:13:36 +01001681 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1683 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001684
1685 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1686}
1687
James Smarte59058c2008-08-24 21:49:00 -04001688/**
James Smart3621a712009-04-06 18:47:14 -04001689 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001690 * @dev: class device that is converted into a Scsi_host.
1691 * @attr: device attribute, not used.
1692 * @buf: one or more lpfc_polling_flags values.
1693 * @count: not used.
1694 *
1695 * Notes:
1696 * buf contents converted to integer and checked for a valid value.
1697 *
1698 * Returns:
1699 * -EINVAL if the buffer connot be converted or is out of range
1700 * length of the buf on success
1701 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001702static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001703lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1704 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001705{
Tony Jonesee959b02008-02-22 00:13:36 +01001706 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001707 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1708 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001709 uint32_t creg_val;
1710 uint32_t old_val;
1711 int val=0;
1712
1713 if (!isdigit(buf[0]))
1714 return -EINVAL;
1715
1716 if (sscanf(buf, "%i", &val) != 1)
1717 return -EINVAL;
1718
1719 if ((val & 0x3) != val)
1720 return -EINVAL;
1721
James Smart45ed1192009-10-02 15:17:02 -04001722 if (phba->sli_rev == LPFC_SLI_REV4)
1723 val = 0;
1724
James Smart88a2cfb2011-07-22 18:36:33 -04001725 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1726 "3051 lpfc_poll changed from %d to %d\n",
1727 phba->cfg_poll, val);
1728
James Smart2e0fef82007-06-17 19:56:36 -05001729 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001730
1731 old_val = phba->cfg_poll;
1732
1733 if (val & ENABLE_FCP_RING_POLLING) {
1734 if ((val & DISABLE_FCP_RING_INT) &&
1735 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001736 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1737 spin_unlock_irq(&phba->hbalock);
1738 return -EINVAL;
1739 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001740 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1741 writel(creg_val, phba->HCregaddr);
1742 readl(phba->HCregaddr); /* flush */
1743
1744 lpfc_poll_start_timer(phba);
1745 }
1746 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001747 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001748 return -EINVAL;
1749 }
1750
1751 if (!(val & DISABLE_FCP_RING_INT) &&
1752 (old_val & DISABLE_FCP_RING_INT))
1753 {
James Smart2e0fef82007-06-17 19:56:36 -05001754 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001755 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001756 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001757 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1758 spin_unlock_irq(&phba->hbalock);
1759 return -EINVAL;
1760 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001761 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1762 writel(creg_val, phba->HCregaddr);
1763 readl(phba->HCregaddr); /* flush */
1764 }
1765
1766 phba->cfg_poll = val;
1767
James Smart2e0fef82007-06-17 19:56:36 -05001768 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001769
1770 return strlen(buf);
1771}
dea31012005-04-17 16:05:31 -05001772
James Smarte59058c2008-08-24 21:49:00 -04001773/**
James Smartbc739052010-08-04 16:11:18 -04001774 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1775 * @dev: class unused variable.
1776 * @attr: device attribute, not used.
1777 * @buf: on return contains the module description text.
1778 *
1779 * Returns: size of formatted string.
1780 **/
1781static ssize_t
1782lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1783 char *buf)
1784{
1785 struct Scsi_Host *shost = class_to_shost(dev);
1786 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1787 struct lpfc_hba *phba = vport->phba;
1788
1789 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1790}
1791
1792/**
1793 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1794 * @dev: class unused variable.
1795 * @attr: device attribute, not used.
1796 * @buf: on return contains the module description text.
1797 *
1798 * Returns: size of formatted string.
1799 **/
1800static ssize_t
1801lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1802 char *buf)
1803{
1804 struct Scsi_Host *shost = class_to_shost(dev);
1805 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1806 struct lpfc_hba *phba = vport->phba;
1807
1808 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1809}
1810
1811/**
James Smartab56dc22011-02-16 12:39:57 -05001812 * lpfc_dss_show - Return the current state of dss and the configured state
1813 * @dev: class converted to a Scsi_host structure.
1814 * @attr: device attribute, not used.
1815 * @buf: on return contains the formatted text.
1816 *
1817 * Returns: size of formatted string.
1818 **/
1819static ssize_t
1820lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1821 char *buf)
1822{
1823 struct Scsi_Host *shost = class_to_shost(dev);
1824 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1825 struct lpfc_hba *phba = vport->phba;
1826
1827 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1828 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1829 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1830 "" : "Not ");
1831}
1832
1833/**
James Smart912e3ac2011-05-24 11:42:11 -04001834 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1835 * @dev: class converted to a Scsi_host structure.
1836 * @attr: device attribute, not used.
1837 * @buf: on return contains the formatted support level.
1838 *
1839 * Description:
1840 * Returns the maximum number of virtual functions a physical function can
1841 * support, 0 will be returned if called on virtual function.
1842 *
1843 * Returns: size of formatted string.
1844 **/
1845static ssize_t
1846lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1847 struct device_attribute *attr,
1848 char *buf)
1849{
1850 struct Scsi_Host *shost = class_to_shost(dev);
1851 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1852 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001853 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001854
James Smart0a96e972011-07-22 18:37:28 -04001855 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1856 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001857}
1858
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001859static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1860{
1861 return val >= min && val <= max;
1862}
1863
James Smart912e3ac2011-05-24 11:42:11 -04001864/**
James Smart3621a712009-04-06 18:47:14 -04001865 * lpfc_param_show - Return a cfg attribute value in decimal
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_show.
1870 *
1871 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1872 * @dev: class device that is converted into a Scsi_host.
1873 * @attr: device attribute, not used.
1874 * @buf: on return contains the attribute value in decimal.
1875 *
1876 * Returns: size of formatted string.
1877 **/
dea31012005-04-17 16:05:31 -05001878#define lpfc_param_show(attr) \
1879static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001880lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1881 char *buf) \
dea31012005-04-17 16:05:31 -05001882{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001883 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001884 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1885 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001886 return snprintf(buf, PAGE_SIZE, "%d\n",\
1887 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001888}
1889
James Smarte59058c2008-08-24 21:49:00 -04001890/**
James Smart3621a712009-04-06 18:47:14 -04001891 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001892 *
1893 * Description:
1894 * Macro that given an attr e.g. hba_queue_depth expands
1895 * into a function with the name lpfc_hba_queue_depth_show
1896 *
1897 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1898 * @dev: class device that is converted into a Scsi_host.
1899 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001900 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001901 *
1902 * Returns: size of formatted string.
1903 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001904#define lpfc_param_hex_show(attr) \
1905static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001906lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1907 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001908{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001909 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001910 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1911 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001912 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001913 val = phba->cfg_##attr;\
1914 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1915 phba->cfg_##attr);\
1916}
1917
James Smarte59058c2008-08-24 21:49:00 -04001918/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001919 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001920 *
1921 * Description:
1922 * Macro that given an attr e.g. hba_queue_depth expands
1923 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1924 * takes a default argument, a minimum and maximum argument.
1925 *
1926 * lpfc_##attr##_init: Initializes an attribute.
1927 * @phba: pointer the the adapter structure.
1928 * @val: integer attribute value.
1929 *
1930 * Validates the min and max values then sets the adapter config field
1931 * accordingly, or uses the default if out of range and prints an error message.
1932 *
1933 * Returns:
1934 * zero on success
1935 * -EINVAL if default used
1936 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001937#define lpfc_param_init(attr, default, minval, maxval) \
1938static int \
James Smart84d1b002010-02-12 14:42:33 -05001939lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001940{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001941 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001942 phba->cfg_##attr = val;\
1943 return 0;\
1944 }\
1945 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001946 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1947 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001948 phba->cfg_##attr = default;\
1949 return -EINVAL;\
1950}
1951
James Smarte59058c2008-08-24 21:49:00 -04001952/**
James Smart3621a712009-04-06 18:47:14 -04001953 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001954 *
1955 * Description:
1956 * Macro that given an attr e.g. hba_queue_depth expands
1957 * into a function with the name lpfc_hba_queue_depth_set
1958 *
1959 * lpfc_##attr##_set: Sets an attribute value.
1960 * @phba: pointer the the adapter structure.
1961 * @val: integer attribute value.
1962 *
1963 * Description:
1964 * Validates the min and max values then sets the
1965 * adapter config field if in the valid range. prints error message
1966 * and does not set the parameter if invalid.
1967 *
1968 * Returns:
1969 * zero on success
1970 * -EINVAL if val is invalid
1971 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001972#define lpfc_param_set(attr, default, minval, maxval) \
1973static int \
James Smart84d1b002010-02-12 14:42:33 -05001974lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001975{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001976 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1978 "3052 lpfc_" #attr " changed from %d to %d\n", \
1979 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001980 phba->cfg_##attr = val;\
1981 return 0;\
1982 }\
1983 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001984 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1985 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001986 return -EINVAL;\
1987}
1988
James Smarte59058c2008-08-24 21:49:00 -04001989/**
James Smart3621a712009-04-06 18:47:14 -04001990 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001991 *
1992 * Description:
1993 * Macro that given an attr e.g. hba_queue_depth expands
1994 * into a function with the name lpfc_hba_queue_depth_store.
1995 *
1996 * lpfc_##attr##_store: Set an sttribute value.
1997 * @dev: class device that is converted into a Scsi_host.
1998 * @attr: device attribute, not used.
1999 * @buf: contains the attribute value in ascii.
2000 * @count: not used.
2001 *
2002 * Description:
2003 * Convert the ascii text number to an integer, then
2004 * use the lpfc_##attr##_set function to set the value.
2005 *
2006 * Returns:
2007 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2008 * length of buffer upon success.
2009 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002010#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002011static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002012lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2013 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002014{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002015 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2017 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002018 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002019 if (!isdigit(buf[0]))\
2020 return -EINVAL;\
2021 if (sscanf(buf, "%i", &val) != 1)\
2022 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002023 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002024 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002025 else \
2026 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002027}
2028
James Smarte59058c2008-08-24 21:49:00 -04002029/**
James Smart3621a712009-04-06 18:47:14 -04002030 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002031 *
2032 * Description:
2033 * Macro that given an attr e.g. hba_queue_depth expands
2034 * into a function with the name lpfc_hba_queue_depth_show
2035 *
2036 * lpfc_##attr##_show: prints the attribute value in decimal.
2037 * @dev: class device that is converted into a Scsi_host.
2038 * @attr: device attribute, not used.
2039 * @buf: on return contains the attribute value in decimal.
2040 *
2041 * Returns: length of formatted string.
2042 **/
James Smart3de2a652007-08-02 11:09:59 -04002043#define lpfc_vport_param_show(attr) \
2044static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002045lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2046 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002047{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002048 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002049 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002050 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2051}
2052
James Smarte59058c2008-08-24 21:49:00 -04002053/**
James Smart3621a712009-04-06 18:47:14 -04002054 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002055 *
2056 * Description:
2057 * Macro that given an attr e.g.
2058 * hba_queue_depth expands into a function with the name
2059 * lpfc_hba_queue_depth_show
2060 *
James Smart3621a712009-04-06 18:47:14 -04002061 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002062 * @dev: class device that is converted into a Scsi_host.
2063 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002064 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002065 *
2066 * Returns: length of formatted string.
2067 **/
James Smart3de2a652007-08-02 11:09:59 -04002068#define lpfc_vport_param_hex_show(attr) \
2069static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002070lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2071 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002072{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002073 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002075 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2076}
2077
James Smarte59058c2008-08-24 21:49:00 -04002078/**
James Smart3621a712009-04-06 18:47:14 -04002079 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002080 *
2081 * Description:
2082 * Macro that given an attr e.g. hba_queue_depth expands
2083 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2084 * takes a default argument, a minimum and maximum argument.
2085 *
2086 * lpfc_##attr##_init: validates the min and max values then sets the
2087 * adapter config field accordingly, or uses the default if out of range
2088 * and prints an error message.
2089 * @phba: pointer the the adapter structure.
2090 * @val: integer attribute value.
2091 *
2092 * Returns:
2093 * zero on success
2094 * -EINVAL if default used
2095 **/
James Smart3de2a652007-08-02 11:09:59 -04002096#define lpfc_vport_param_init(attr, default, minval, maxval) \
2097static int \
James Smart84d1b002010-02-12 14:42:33 -05002098lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002099{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002100 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002101 vport->cfg_##attr = val;\
2102 return 0;\
2103 }\
James Smarte8b62012007-08-02 11:10:09 -04002104 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002105 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002106 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002107 vport->cfg_##attr = default;\
2108 return -EINVAL;\
2109}
2110
James Smarte59058c2008-08-24 21:49:00 -04002111/**
James Smart3621a712009-04-06 18:47:14 -04002112 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002113 *
2114 * Description:
2115 * Macro that given an attr e.g. hba_queue_depth expands
2116 * into a function with the name lpfc_hba_queue_depth_set
2117 *
2118 * lpfc_##attr##_set: validates the min and max values then sets the
2119 * adapter config field if in the valid range. prints error message
2120 * and does not set the parameter if invalid.
2121 * @phba: pointer the the adapter structure.
2122 * @val: integer attribute value.
2123 *
2124 * Returns:
2125 * zero on success
2126 * -EINVAL if val is invalid
2127 **/
James Smart3de2a652007-08-02 11:09:59 -04002128#define lpfc_vport_param_set(attr, default, minval, maxval) \
2129static int \
James Smart84d1b002010-02-12 14:42:33 -05002130lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002131{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002132 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002133 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002134 "3053 lpfc_" #attr \
2135 " changed from %d (x%x) to %d (x%x)\n", \
2136 vport->cfg_##attr, vport->cfg_##attr, \
2137 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002138 vport->cfg_##attr = val;\
2139 return 0;\
2140 }\
James Smarte8b62012007-08-02 11:10:09 -04002141 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002142 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002143 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002144 return -EINVAL;\
2145}
2146
James Smarte59058c2008-08-24 21:49:00 -04002147/**
James Smart3621a712009-04-06 18:47:14 -04002148 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002149 *
2150 * Description:
2151 * Macro that given an attr e.g. hba_queue_depth
2152 * expands into a function with the name lpfc_hba_queue_depth_store
2153 *
2154 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2155 * use the lpfc_##attr##_set function to set the value.
2156 * @cdev: class device that is converted into a Scsi_host.
2157 * @buf: contains the attribute value in decimal.
2158 * @count: not used.
2159 *
2160 * Returns:
2161 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2162 * length of buffer upon success.
2163 **/
James Smart3de2a652007-08-02 11:09:59 -04002164#define lpfc_vport_param_store(attr) \
2165static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002166lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2167 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002168{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002169 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002171 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002172 if (!isdigit(buf[0]))\
2173 return -EINVAL;\
2174 if (sscanf(buf, "%i", &val) != 1)\
2175 return -EINVAL;\
2176 if (lpfc_##attr##_set(vport, val) == 0) \
2177 return strlen(buf);\
2178 else \
2179 return -EINVAL;\
2180}
2181
2182
James Smart895427b2017-02-12 13:52:30 -08002183static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002184static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2185static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2186static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2187static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002188static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2189static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2190static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2191static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2192static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2193static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2194static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2195static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002196static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2197 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002198static DEVICE_ATTR(option_rom_version, S_IRUGO,
2199 lpfc_option_rom_version_show, NULL);
2200static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2201 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002202static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002203static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2204static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002205static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002206static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2207 lpfc_board_mode_show, lpfc_board_mode_store);
2208static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2209static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2210static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2211static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2212static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2213static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2214static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2215static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2216static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002217static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2218static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002219static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002220static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2221 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002222static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002223static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2224 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002225
James Smart352e5fd2016-12-30 06:57:47 -08002226static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002227#define WWN_SZ 8
2228/**
2229 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2230 * @buf: WWN string.
2231 * @cnt: Length of string.
2232 * @wwn: Array to receive converted wwn value.
2233 *
2234 * Returns:
2235 * -EINVAL if the buffer does not contain a valid wwn
2236 * 0 success
2237 **/
2238static size_t
2239lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2240{
2241 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002242
James Smart1ba981f2014-02-20 09:56:45 -05002243 /* Count may include a LF at end of string */
2244 if (buf[cnt-1] == '\n')
2245 cnt--;
2246
2247 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2248 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2249 return -EINVAL;
2250
2251 memset(wwn, 0, WWN_SZ);
2252
2253 /* Validate and store the new name */
2254 for (i = 0, j = 0; i < 16; i++) {
2255 if ((*buf >= 'a') && (*buf <= 'f'))
2256 j = ((j << 4) | ((*buf++ - 'a') + 10));
2257 else if ((*buf >= 'A') && (*buf <= 'F'))
2258 j = ((j << 4) | ((*buf++ - 'A') + 10));
2259 else if ((*buf >= '0') && (*buf <= '9'))
2260 j = ((j << 4) | (*buf++ - '0'));
2261 else
2262 return -EINVAL;
2263 if (i % 2) {
2264 wwn[i/2] = j & 0xff;
2265 j = 0;
2266 }
2267 }
2268 return 0;
2269}
James Smart352e5fd2016-12-30 06:57:47 -08002270/**
2271 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2272 * @dev: class device that is converted into a Scsi_host.
2273 * @attr: device attribute, not used.
2274 * @buf: containing the string lpfc_soft_wwn_key.
2275 * @count: must be size of lpfc_soft_wwn_key.
2276 *
2277 * Returns:
2278 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2279 * length of buf indicates success
2280 **/
2281static ssize_t
2282lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2283 const char *buf, size_t count)
2284{
2285 struct Scsi_Host *shost = class_to_shost(dev);
2286 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2287 struct lpfc_hba *phba = vport->phba;
2288 unsigned int cnt = count;
2289
2290 /*
2291 * We're doing a simple sanity check for soft_wwpn setting.
2292 * We require that the user write a specific key to enable
2293 * the soft_wwpn attribute to be settable. Once the attribute
2294 * is written, the enable key resets. If further updates are
2295 * desired, the key must be written again to re-enable the
2296 * attribute.
2297 *
2298 * The "key" is not secret - it is a hardcoded string shown
2299 * here. The intent is to protect against the random user or
2300 * application that is just writing attributes.
2301 */
2302
2303 /* count may include a LF at end of string */
2304 if (buf[cnt-1] == '\n')
2305 cnt--;
2306
2307 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2308 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2309 return -EINVAL;
2310
2311 phba->soft_wwn_enable = 1;
2312
2313 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2314 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2315 phba->brd_no);
2316 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2317 " The soft_wwpn feature is not supported by Broadcom.");
2318
2319 return count;
2320}
2321static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2322 lpfc_soft_wwn_enable_store);
2323
2324/**
2325 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2326 * @dev: class device that is converted into a Scsi_host.
2327 * @attr: device attribute, not used.
2328 * @buf: on return contains the wwpn in hexadecimal.
2329 *
2330 * Returns: size of formatted string.
2331 **/
2332static ssize_t
2333lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2334 char *buf)
2335{
2336 struct Scsi_Host *shost = class_to_shost(dev);
2337 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2338 struct lpfc_hba *phba = vport->phba;
2339
2340 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2341 (unsigned long long)phba->cfg_soft_wwpn);
2342}
2343
2344/**
2345 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2346 * @dev class device that is converted into a Scsi_host.
2347 * @attr: device attribute, not used.
2348 * @buf: contains the wwpn in hexadecimal.
2349 * @count: number of wwpn bytes in buf
2350 *
2351 * Returns:
2352 * -EACCES hba reset not enabled, adapter over temp
2353 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2354 * -EIO error taking adapter offline or online
2355 * value of count on success
2356 **/
2357static ssize_t
2358lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2359 const char *buf, size_t count)
2360{
2361 struct Scsi_Host *shost = class_to_shost(dev);
2362 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2363 struct lpfc_hba *phba = vport->phba;
2364 struct completion online_compl;
2365 int stat1 = 0, stat2 = 0;
2366 unsigned int cnt = count;
2367 u8 wwpn[WWN_SZ];
2368 int rc;
2369
2370 if (!phba->cfg_enable_hba_reset)
2371 return -EACCES;
2372 spin_lock_irq(&phba->hbalock);
2373 if (phba->over_temp_state == HBA_OVER_TEMP) {
2374 spin_unlock_irq(&phba->hbalock);
2375 return -EACCES;
2376 }
2377 spin_unlock_irq(&phba->hbalock);
2378 /* count may include a LF at end of string */
2379 if (buf[cnt-1] == '\n')
2380 cnt--;
2381
2382 if (!phba->soft_wwn_enable)
2383 return -EINVAL;
2384
2385 /* lock setting wwpn, wwnn down */
2386 phba->soft_wwn_enable = 0;
2387
2388 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002389 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002390 /* not able to set wwpn, unlock it */
2391 phba->soft_wwn_enable = 1;
2392 return rc;
2393 }
2394
2395 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2396 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2397 if (phba->cfg_soft_wwnn)
2398 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2399
2400 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2401 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2402
2403 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2404 if (stat1)
2405 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2406 "0463 lpfc_soft_wwpn attribute set failed to "
2407 "reinit adapter - %d\n", stat1);
2408 init_completion(&online_compl);
2409 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2410 LPFC_EVT_ONLINE);
2411 if (rc == 0)
2412 return -ENOMEM;
2413
2414 wait_for_completion(&online_compl);
2415 if (stat2)
2416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2417 "0464 lpfc_soft_wwpn attribute set failed to "
2418 "reinit adapter - %d\n", stat2);
2419 return (stat1 || stat2) ? -EIO : count;
2420}
2421static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2422 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2423
2424/**
2425 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2426 * @dev: class device that is converted into a Scsi_host.
2427 * @attr: device attribute, not used.
2428 * @buf: on return contains the wwnn in hexadecimal.
2429 *
2430 * Returns: size of formatted string.
2431 **/
2432static ssize_t
2433lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2434 char *buf)
2435{
2436 struct Scsi_Host *shost = class_to_shost(dev);
2437 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2438 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2439 (unsigned long long)phba->cfg_soft_wwnn);
2440}
2441
2442/**
2443 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2444 * @cdev: class device that is converted into a Scsi_host.
2445 * @buf: contains the ww node name in hexadecimal.
2446 * @count: number of wwnn bytes in buf.
2447 *
2448 * Returns:
2449 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2450 * value of count on success
2451 **/
2452static ssize_t
2453lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2454 const char *buf, size_t count)
2455{
2456 struct Scsi_Host *shost = class_to_shost(dev);
2457 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2458 unsigned int cnt = count;
2459 u8 wwnn[WWN_SZ];
2460 int rc;
2461
2462 /* count may include a LF at end of string */
2463 if (buf[cnt-1] == '\n')
2464 cnt--;
2465
2466 if (!phba->soft_wwn_enable)
2467 return -EINVAL;
2468
2469 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002470 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002471 /* Allow wwnn to be set many times, as long as the enable
2472 * is set. However, once the wwpn is set, everything locks.
2473 */
2474 return rc;
2475 }
2476
2477 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2478
2479 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2480 "lpfc%d: soft_wwnn set. Value will take effect upon "
2481 "setting of the soft_wwpn\n", phba->brd_no);
2482
2483 return count;
2484}
2485static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2486 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002487
James Smart1ba981f2014-02-20 09:56:45 -05002488/**
2489 * lpfc_oas_tgt_show - Return 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 *
2495 * Returns:
2496 * value of count
2497 **/
2498static ssize_t
2499lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2500 char *buf)
2501{
2502 struct Scsi_Host *shost = class_to_shost(dev);
2503 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2504
2505 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2506 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2507}
2508
2509/**
2510 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2511 * Optimized Access Storage (OAS) operations.
2512 * @dev: class device that is converted into a Scsi_host.
2513 * @attr: device attribute, not used.
2514 * @buf: buffer for passing information.
2515 * @count: Size of the data buffer.
2516 *
2517 * Returns:
2518 * -EINVAL count is invalid, invalid wwpn byte invalid
2519 * -EPERM oas is not supported by hba
2520 * value of count on success
2521 **/
2522static ssize_t
2523lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2524 const char *buf, size_t count)
2525{
2526 struct Scsi_Host *shost = class_to_shost(dev);
2527 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2528 unsigned int cnt = count;
2529 uint8_t wwpn[WWN_SZ];
2530 int rc;
2531
James Smartf38fa0b2014-04-04 13:52:21 -04002532 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002533 return -EPERM;
2534
2535 /* count may include a LF at end of string */
2536 if (buf[cnt-1] == '\n')
2537 cnt--;
2538
2539 rc = lpfc_wwn_set(buf, cnt, wwpn);
2540 if (rc)
2541 return rc;
2542
2543 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2544 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2545 if (wwn_to_u64(wwpn) == 0)
2546 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2547 else
2548 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2549 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2550 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2551 return count;
2552}
2553static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2554 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2555
2556/**
James Smartc92c8412016-07-06 12:36:05 -07002557 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2558 * Optimized Access Storage (OAS) operations.
2559 * @dev: class device that is converted into a Scsi_host.
2560 * @attr: device attribute, not used.
2561 * @buf: buffer for passing information.
2562 *
2563 * Returns:
2564 * value of count
2565 **/
2566static ssize_t
2567lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2568 char *buf)
2569{
2570 struct Scsi_Host *shost = class_to_shost(dev);
2571 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2572
2573 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2574}
2575
2576/**
2577 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2578 * Optimized Access Storage (OAS) operations.
2579 * @dev: class device that is converted into a Scsi_host.
2580 * @attr: device attribute, not used.
2581 * @buf: buffer for passing information.
2582 * @count: Size of the data buffer.
2583 *
2584 * Returns:
2585 * -EINVAL count is invalid, invalid wwpn byte invalid
2586 * -EPERM oas is not supported by hba
2587 * value of count on success
2588 **/
2589static ssize_t
2590lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2591 const char *buf, size_t count)
2592{
2593 struct Scsi_Host *shost = class_to_shost(dev);
2594 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2595 unsigned int cnt = count;
2596 unsigned long val;
2597 int ret;
2598
2599 if (!phba->cfg_fof)
2600 return -EPERM;
2601
2602 /* count may include a LF at end of string */
2603 if (buf[cnt-1] == '\n')
2604 cnt--;
2605
2606 ret = kstrtoul(buf, 0, &val);
2607 if (ret || (val > 0x7f))
2608 return -EINVAL;
2609
2610 if (val)
2611 phba->cfg_oas_priority = (uint8_t)val;
2612 else
2613 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2614 return count;
2615}
2616static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2617 lpfc_oas_priority_show, lpfc_oas_priority_store);
2618
2619/**
James Smart1ba981f2014-02-20 09:56:45 -05002620 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2621 * for Optimized Access Storage (OAS) operations.
2622 * @dev: class device that is converted into a Scsi_host.
2623 * @attr: device attribute, not used.
2624 * @buf: buffer for passing information.
2625 *
2626 * Returns:
2627 * value of count on success
2628 **/
2629static ssize_t
2630lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2631 char *buf)
2632{
2633 struct Scsi_Host *shost = class_to_shost(dev);
2634 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2635
2636 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2637 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2638}
2639
2640/**
2641 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2642 * for Optimized Access Storage (OAS) operations.
2643 * @dev: class device that is converted into a Scsi_host.
2644 * @attr: device attribute, not used.
2645 * @buf: buffer for passing information.
2646 * @count: Size of the data buffer.
2647 *
2648 * Returns:
2649 * -EINVAL count is invalid, invalid wwpn byte invalid
2650 * -EPERM oas is not supported by hba
2651 * value of count on success
2652 **/
2653static ssize_t
2654lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2655 const char *buf, size_t count)
2656{
2657 struct Scsi_Host *shost = class_to_shost(dev);
2658 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2659 unsigned int cnt = count;
2660 uint8_t wwpn[WWN_SZ];
2661 int rc;
2662
James Smartf38fa0b2014-04-04 13:52:21 -04002663 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002664 return -EPERM;
2665
2666 /* count may include a LF at end of string */
2667 if (buf[cnt-1] == '\n')
2668 cnt--;
2669
2670 rc = lpfc_wwn_set(buf, cnt, wwpn);
2671 if (rc)
2672 return rc;
2673
2674 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2675 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2676 if (wwn_to_u64(wwpn) == 0)
2677 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2678 else
2679 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2680 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002681 if (phba->cfg_oas_priority == 0)
2682 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002683 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2684 return count;
2685}
2686static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2687 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2688
2689/**
2690 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2691 * of whether luns will be enabled or disabled
2692 * for Optimized Access Storage (OAS) operations.
2693 * @dev: class device that is converted into a Scsi_host.
2694 * @attr: device attribute, not used.
2695 * @buf: buffer for passing information.
2696 *
2697 * Returns:
2698 * size of formatted string.
2699 **/
2700static ssize_t
2701lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2702 char *buf)
2703{
2704 struct Scsi_Host *shost = class_to_shost(dev);
2705 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2706
2707 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2708}
2709
2710/**
2711 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2712 * of whether luns will be enabled or disabled
2713 * for Optimized Access Storage (OAS) operations.
2714 * @dev: class device that is converted into a Scsi_host.
2715 * @attr: device attribute, not used.
2716 * @buf: buffer for passing information.
2717 * @count: Size of the data buffer.
2718 *
2719 * Returns:
2720 * -EINVAL count is invalid, invalid wwpn byte invalid
2721 * -EPERM oas is not supported by hba
2722 * value of count on success
2723 **/
2724static ssize_t
2725lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2726 const char *buf, size_t count)
2727{
2728 struct Scsi_Host *shost = class_to_shost(dev);
2729 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2730 int val = 0;
2731
James Smartf38fa0b2014-04-04 13:52:21 -04002732 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002733 return -EPERM;
2734
2735 if (!isdigit(buf[0]))
2736 return -EINVAL;
2737
2738 if (sscanf(buf, "%i", &val) != 1)
2739 return -EINVAL;
2740
2741 if ((val != 0) && (val != 1))
2742 return -EINVAL;
2743
2744 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002745 return strlen(buf);
2746}
2747static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2748 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2749
2750/**
2751 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2752 * Storage (OAS) lun returned by the
2753 * lpfc_oas_lun_show function.
2754 * @dev: class device that is converted into a Scsi_host.
2755 * @attr: device attribute, not used.
2756 * @buf: buffer for passing information.
2757 *
2758 * Returns:
2759 * size of formatted string.
2760 **/
2761static ssize_t
2762lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2763 char *buf)
2764{
2765 struct Scsi_Host *shost = class_to_shost(dev);
2766 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2767
2768 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2769 return -EFAULT;
2770
2771 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2772}
2773static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2774 lpfc_oas_lun_status_show, NULL);
2775
2776
2777/**
2778 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2779 * (OAS) operations.
2780 * @phba: lpfc_hba pointer.
2781 * @ndlp: pointer to fcp target node.
2782 * @lun: the fc lun for setting oas state.
2783 * @oas_state: the oas state to be set to the lun.
2784 *
2785 * Returns:
2786 * SUCCESS : 0
2787 * -EPERM OAS is not enabled or not supported by this port.
2788 *
2789 */
2790static size_t
2791lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002792 uint8_t tgt_wwpn[], uint64_t lun,
2793 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002794{
2795
2796 int rc = 0;
2797
James Smartf38fa0b2014-04-04 13:52:21 -04002798 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002799 return -EPERM;
2800
2801 if (oas_state) {
2802 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002803 (struct lpfc_name *)tgt_wwpn,
2804 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002805 rc = -ENOMEM;
2806 } else {
2807 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002808 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002809 }
2810 return rc;
2811
2812}
2813
2814/**
2815 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2816 * Access Storage (OAS) operations.
2817 * @phba: lpfc_hba pointer.
2818 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2819 * @tgt_wwpn: wwpn of the target associated with the returned lun
2820 * @lun_status: status of the lun returned lun
2821 *
2822 * Returns the first or next lun enabled for OAS operations for the vport/target
2823 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2824 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2825 *
2826 * Return:
2827 * lun that is OAS enabled for the vport/target
2828 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2829 */
2830static uint64_t
2831lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002832 uint8_t tgt_wwpn[], uint32_t *lun_status,
2833 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002834{
2835 uint64_t found_lun;
2836
2837 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2838 return NOT_OAS_ENABLED_LUN;
2839 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2840 phba->sli4_hba.oas_next_vpt_wwpn,
2841 (struct lpfc_name *)
2842 phba->sli4_hba.oas_next_tgt_wwpn,
2843 &phba->sli4_hba.oas_next_lun,
2844 (struct lpfc_name *)vpt_wwpn,
2845 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002846 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002847 return found_lun;
2848 else
2849 return NOT_OAS_ENABLED_LUN;
2850}
2851
2852/**
2853 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2854 * @phba: lpfc_hba pointer.
2855 * @vpt_wwpn: vport wwpn by reference.
2856 * @tgt_wwpn: target wwpn by reference.
2857 * @lun: the fc lun for setting oas state.
2858 * @oas_state: the oas state to be set to the oas_lun.
2859 *
2860 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2861 * a lun for OAS operations.
2862 *
2863 * Return:
2864 * SUCCESS: 0
2865 * -ENOMEM: failed to enable an lun for OAS operations
2866 * -EPERM: OAS is not enabled
2867 */
2868static ssize_t
2869lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2870 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002871 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002872{
2873
2874 int rc;
2875
2876 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002877 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002878 return rc;
2879}
2880
2881/**
2882 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2883 * @dev: class device that is converted into a Scsi_host.
2884 * @attr: device attribute, not used.
2885 * @buf: buffer for passing information.
2886 *
2887 * This routine returns a lun enabled for OAS each time the function
2888 * is called.
2889 *
2890 * Returns:
2891 * SUCCESS: size of formatted string.
2892 * -EFAULT: target or vport wwpn was not set properly.
2893 * -EPERM: oas is not enabled.
2894 **/
2895static ssize_t
2896lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2897 char *buf)
2898{
2899 struct Scsi_Host *shost = class_to_shost(dev);
2900 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2901
2902 uint64_t oas_lun;
2903 int len = 0;
2904
James Smartf38fa0b2014-04-04 13:52:21 -04002905 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002906 return -EPERM;
2907
2908 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2909 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2910 return -EFAULT;
2911
2912 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2913 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2914 return -EFAULT;
2915
2916 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2917 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002918 &phba->cfg_oas_lun_status,
2919 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002920 if (oas_lun != NOT_OAS_ENABLED_LUN)
2921 phba->cfg_oas_flags |= OAS_LUN_VALID;
2922
2923 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2924
2925 return len;
2926}
2927
2928/**
2929 * lpfc_oas_lun_store - Sets the OAS state for lun
2930 * @dev: class device that is converted into a Scsi_host.
2931 * @attr: device attribute, not used.
2932 * @buf: buffer for passing information.
2933 *
2934 * This function sets the OAS state for lun. Before this function is called,
2935 * the vport wwpn, target wwpn, and oas state need to be set.
2936 *
2937 * Returns:
2938 * SUCCESS: size of formatted string.
2939 * -EFAULT: target or vport wwpn was not set properly.
2940 * -EPERM: oas is not enabled.
2941 * size of formatted string.
2942 **/
2943static ssize_t
2944lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2945 const char *buf, size_t count)
2946{
2947 struct Scsi_Host *shost = class_to_shost(dev);
2948 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2949 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002950 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002951 ssize_t rc;
2952
James Smartf38fa0b2014-04-04 13:52:21 -04002953 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002954 return -EPERM;
2955
2956 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2957 return -EFAULT;
2958
2959 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2960 return -EFAULT;
2961
2962 if (!isdigit(buf[0]))
2963 return -EINVAL;
2964
2965 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2966 return -EINVAL;
2967
James Smartb5749fe2016-12-19 15:07:26 -08002968 pri = phba->cfg_oas_priority;
2969 if (pri == 0)
2970 pri = phba->cfg_XLanePriority;
2971
James Smart1ba981f2014-02-20 09:56:45 -05002972 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002973 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2974 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002975 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2976 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002977 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002978
2979 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002980 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002981 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002982 if (rc)
2983 return rc;
2984
2985 return count;
2986}
2987static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2988 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002989
James Smartf358dd02017-02-12 13:52:34 -08002990int lpfc_enable_nvmet_cnt;
2991unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
2992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2993 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2994module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
2995MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
2996
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002997static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05002998module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002999MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3000 " 0 - none,"
3001 " 1 - poll with interrupts enabled"
3002 " 3 - poll and disable FCP ring interrupts");
3003
Tony Jonesee959b02008-02-22 00:13:36 +01003004static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3005 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05003006
James Smart12247e82016-07-06 12:36:09 -07003007LPFC_ATTR(sli_mode, 0, 0, 3,
3008 "SLI mode selector:"
3009 " 0 - auto (SLI-3 if supported),"
3010 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3011 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003012
James Smart458c0832016-07-06 12:36:07 -07003013LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3014 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003015
James Smart7d791df2011-07-22 18:37:52 -04003016LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3017 "FCF Fast failover=1 Priority failover=2");
3018
James Smarte5771b42013-03-01 16:37:14 -05003019/*
3020# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3021# 0x0 = disabled, XRI/OXID use not tracked.
3022# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3023# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3024*/
James Smart31202b02016-10-13 15:06:08 -07003025LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3026 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003027
dea31012005-04-17 16:05:31 -05003028/*
James Smart84d1b002010-02-12 14:42:33 -05003029# lpfc_suppress_link_up: Bring link up at initialization
3030# 0x0 = bring link up (issue MBX_INIT_LINK)
3031# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3032# 0x2 = never bring up link
3033# Default value is 0.
3034*/
James Smarte40a02c2010-02-26 14:13:54 -05003035LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3036 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3037 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003038/*
3039# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3040# 1 - (1024)
3041# 2 - (2048)
3042# 3 - (3072)
3043# 4 - (4096)
3044# 5 - (5120)
3045*/
3046static ssize_t
3047lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3048{
3049 struct Scsi_Host *shost = class_to_shost(dev);
3050 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3051
3052 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3053}
3054
3055static DEVICE_ATTR(iocb_hw, S_IRUGO,
3056 lpfc_iocb_hw_show, NULL);
3057static ssize_t
3058lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3059{
3060 struct Scsi_Host *shost = class_to_shost(dev);
3061 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003062 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003063
James Smart895427b2017-02-12 13:52:30 -08003064 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003065}
3066
3067static DEVICE_ATTR(txq_hw, S_IRUGO,
3068 lpfc_txq_hw_show, NULL);
3069static ssize_t
3070lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3071 char *buf)
3072{
3073 struct Scsi_Host *shost = class_to_shost(dev);
3074 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003075 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003076
James Smart895427b2017-02-12 13:52:30 -08003077 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003078}
3079
3080static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3081 lpfc_txcmplq_hw_show, NULL);
3082
James Smart0d8c8ba2016-10-13 15:06:07 -07003083LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003084 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003085
3086/*
James Smartc01f3202006-08-18 17:47:08 -04003087# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3088# until the timer expires. Value range is [0,255]. Default value is 30.
3089*/
3090static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3091static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3092module_param(lpfc_nodev_tmo, int, 0);
3093MODULE_PARM_DESC(lpfc_nodev_tmo,
3094 "Seconds driver will hold I/O waiting "
3095 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003096
3097/**
James Smart3621a712009-04-06 18:47:14 -04003098 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003099 * @dev: class converted to a Scsi_host structure.
3100 * @attr: device attribute, not used.
3101 * @buf: on return contains the dev loss timeout in decimal.
3102 *
3103 * Returns: size of formatted string.
3104 **/
James Smartc01f3202006-08-18 17:47:08 -04003105static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003106lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3107 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003108{
Tony Jonesee959b02008-02-22 00:13:36 +01003109 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003110 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003111
James Smart3de2a652007-08-02 11:09:59 -04003112 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003113}
3114
James Smarte59058c2008-08-24 21:49:00 -04003115/**
James Smart3621a712009-04-06 18:47:14 -04003116 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003117 * @vport: lpfc vport structure pointer.
3118 * @val: contains the nodev timeout value.
3119 *
3120 * Description:
3121 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3122 * a kernel error message is printed and zero is returned.
3123 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3124 * Otherwise nodev tmo is set to the default value.
3125 *
3126 * Returns:
3127 * zero if already set or if val is in range
3128 * -EINVAL val out of range
3129 **/
James Smartc01f3202006-08-18 17:47:08 -04003130static int
James Smart3de2a652007-08-02 11:09:59 -04003131lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003132{
James Smart3de2a652007-08-02 11:09:59 -04003133 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3134 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3135 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003136 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003137 "0407 Ignoring lpfc_nodev_tmo module "
3138 "parameter because lpfc_devloss_tmo "
3139 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003140 return 0;
3141 }
3142
3143 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003144 vport->cfg_nodev_tmo = val;
3145 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003146 return 0;
3147 }
James Smarte8b62012007-08-02 11:10:09 -04003148 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3149 "0400 lpfc_nodev_tmo attribute cannot be set to"
3150 " %d, allowed range is [%d, %d]\n",
3151 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003152 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003153 return -EINVAL;
3154}
3155
James Smarte59058c2008-08-24 21:49:00 -04003156/**
James Smart3621a712009-04-06 18:47:14 -04003157 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003158 * @vport: lpfc vport structure pointer.
3159 *
3160 * Description:
3161 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3162 **/
James Smart7054a602007-04-25 09:52:34 -04003163static void
James Smart3de2a652007-08-02 11:09:59 -04003164lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003165{
James Smart858c9f62007-06-17 19:56:39 -05003166 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003167 struct lpfc_nodelist *ndlp;
3168
James Smart51ef4c22007-08-02 11:10:31 -04003169 shost = lpfc_shost_from_vport(vport);
3170 spin_lock_irq(shost->host_lock);
3171 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003172 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003173 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3174 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003175}
3176
James Smarte59058c2008-08-24 21:49:00 -04003177/**
James Smart3621a712009-04-06 18:47:14 -04003178 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003179 * @vport: lpfc vport structure pointer.
3180 * @val: contains the tmo value.
3181 *
3182 * Description:
3183 * If the devloss tmo is already set or the vport dev loss tmo has changed
3184 * then a kernel error message is printed and zero is returned.
3185 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3186 * Otherwise nodev tmo is set to the default value.
3187 *
3188 * Returns:
3189 * zero if already set or if val is in range
3190 * -EINVAL val out of range
3191 **/
James Smartc01f3202006-08-18 17:47:08 -04003192static int
James Smart3de2a652007-08-02 11:09:59 -04003193lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003194{
James Smart3de2a652007-08-02 11:09:59 -04003195 if (vport->dev_loss_tmo_changed ||
3196 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003198 "0401 Ignoring change to lpfc_nodev_tmo "
3199 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003200 return 0;
3201 }
James Smartc01f3202006-08-18 17:47:08 -04003202 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003203 vport->cfg_nodev_tmo = val;
3204 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003205 /*
3206 * For compat: set the fc_host dev loss so new rports
3207 * will get the value.
3208 */
3209 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003210 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003211 return 0;
3212 }
James Smarte8b62012007-08-02 11:10:09 -04003213 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003214 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003215 "%d, allowed range is [%d, %d]\n",
3216 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003217 return -EINVAL;
3218}
3219
James Smart3de2a652007-08-02 11:09:59 -04003220lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003221
Tony Jonesee959b02008-02-22 00:13:36 +01003222static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3223 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003224
3225/*
3226# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3227# disappear until the timer expires. Value range is [0,255]. Default
3228# value is 30.
3229*/
James Smartab56dc22011-02-16 12:39:57 -05003230module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003231MODULE_PARM_DESC(lpfc_devloss_tmo,
3232 "Seconds driver will hold I/O waiting "
3233 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003234lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3235 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3236lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003237
3238/**
James Smart3621a712009-04-06 18:47:14 -04003239 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003240 * @vport: lpfc vport structure pointer.
3241 * @val: contains the tmo value.
3242 *
3243 * Description:
3244 * If val is in a valid range then set the vport nodev tmo,
3245 * devloss tmo, also set the vport dev loss tmo changed flag.
3246 * Else a kernel error message is printed.
3247 *
3248 * Returns:
3249 * zero if val is in range
3250 * -EINVAL val out of range
3251 **/
James Smartc01f3202006-08-18 17:47:08 -04003252static int
James Smart3de2a652007-08-02 11:09:59 -04003253lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003254{
3255 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003256 vport->cfg_nodev_tmo = val;
3257 vport->cfg_devloss_tmo = val;
3258 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003259 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003260 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003261 return 0;
3262 }
3263
James Smarte8b62012007-08-02 11:10:09 -04003264 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003265 "0404 lpfc_devloss_tmo attribute cannot be set to "
3266 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003267 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003268 return -EINVAL;
3269}
3270
James Smart3de2a652007-08-02 11:09:59 -04003271lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003272static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3273 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003274
3275/*
James Smartf358dd02017-02-12 13:52:34 -08003276 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3277 * lpfc_suppress_rsp = 0 Disable
3278 * lpfc_suppress_rsp = 1 Enable (default)
3279 *
3280 */
3281LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3282 "Enable suppress rsp feature is firmware supports it");
3283
3284/*
James Smart895427b2017-02-12 13:52:30 -08003285 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3286 * Supported Values: 1 - register just FCP
3287 * 3 - register both FCP and NVME
3288 * Supported values are [1,3]. Default value is 3
3289 */
3290LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3291 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3292 "Define fc4 type to register with fabric.");
3293
3294/*
3295 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3296 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003297 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3298 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003299 *
3300 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3301 * The remaining XRIs get split up based on lpfc_xri_split per port:
3302 *
3303 * Supported Values are in percentages
3304 * the xri_split value is the percentage the SCSI port will get. The remaining
3305 * percentage will go to NVME.
3306 */
3307LPFC_ATTR_R(xri_split, 50, 10, 90,
3308 "Division of XRI resources between SCSI and NVME");
3309
3310/*
dea31012005-04-17 16:05:31 -05003311# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3312# deluged with LOTS of information.
3313# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003314# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003315*/
James Smartf4b4c682009-05-22 14:53:12 -04003316LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003317 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003318
3319/*
James Smart7ee5d432007-10-27 13:37:17 -04003320# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3321# objects that have been registered with the nameserver after login.
3322*/
James Smartcf971242012-03-01 22:37:32 -05003323LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003324 "Deregister nameserver objects before LOGO");
3325
3326/*
dea31012005-04-17 16:05:31 -05003327# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003328# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3329# If this parameter value is greater than 1/8th the maximum number of exchanges
3330# supported by the HBA port, then the lun queue depth will be reduced to
3331# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003332*/
James Smart572709e2013-07-15 18:32:43 -04003333LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003334 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003335
3336/*
James Smart7dc517d2010-07-14 15:32:10 -04003337# tgt_queue_depth: This parameter is used to limit the number of outstanding
3338# commands per target port. Value range is [10,65535]. Default value is 65535.
3339*/
3340LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003341 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003342
3343/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003344# hba_queue_depth: This parameter is used to limit the number of outstanding
3345# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3346# value is greater than the maximum number of exchanges supported by the HBA,
3347# then maximum number of exchanges supported by the HBA is used to determine
3348# the hba_queue_depth.
3349*/
3350LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3351 "Max number of FCP commands we can queue to a lpfc HBA");
3352
3353/*
James Smart92d7f7b2007-06-17 19:56:38 -05003354# peer_port_login: This parameter allows/prevents logins
3355# between peer ports hosted on the same physical port.
3356# When this parameter is set 0 peer ports of same physical port
3357# are not allowed to login to each other.
3358# When this parameter is set 1 peer ports of same physical port
3359# are allowed to login to each other.
3360# Default value of this parameter is 0.
3361*/
James Smart3de2a652007-08-02 11:09:59 -04003362LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3363 "Allow peer ports on the same physical port to login to each "
3364 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003365
3366/*
James Smart3de2a652007-08-02 11:09:59 -04003367# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003368# between Virtual Ports and remote initiators.
3369# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3370# other initiators and will attempt to PLOGI all remote ports.
3371# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3372# remote ports and will not attempt to PLOGI to other initiators.
3373# This parameter does not restrict to the physical port.
3374# This parameter does not restrict logins to Fabric resident remote ports.
3375# Default value of this parameter is 1.
3376*/
James Smart3de2a652007-08-02 11:09:59 -04003377static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003378module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003379MODULE_PARM_DESC(lpfc_restrict_login,
3380 "Restrict virtual ports login to remote initiators.");
3381lpfc_vport_param_show(restrict_login);
3382
James Smarte59058c2008-08-24 21:49:00 -04003383/**
James Smart3621a712009-04-06 18:47:14 -04003384 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003385 * @vport: lpfc vport structure pointer.
3386 * @val: contains the restrict login value.
3387 *
3388 * Description:
3389 * If val is not in a valid range then log a kernel error message and set
3390 * the vport restrict login to one.
3391 * If the port type is physical clear the restrict login flag and return.
3392 * Else set the restrict login flag to val.
3393 *
3394 * Returns:
3395 * zero if val is in range
3396 * -EINVAL val out of range
3397 **/
James Smart3de2a652007-08-02 11:09:59 -04003398static int
3399lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3400{
3401 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003402 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003403 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003404 "be set to %d, allowed range is [0, 1]\n",
3405 val);
James Smart3de2a652007-08-02 11:09:59 -04003406 vport->cfg_restrict_login = 1;
3407 return -EINVAL;
3408 }
3409 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3410 vport->cfg_restrict_login = 0;
3411 return 0;
3412 }
3413 vport->cfg_restrict_login = val;
3414 return 0;
3415}
3416
James Smarte59058c2008-08-24 21:49:00 -04003417/**
James Smart3621a712009-04-06 18:47:14 -04003418 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003419 * @vport: lpfc vport structure pointer.
3420 * @val: contains the restrict login value.
3421 *
3422 * Description:
3423 * If val is not in a valid range then log a kernel error message and set
3424 * the vport restrict login to one.
3425 * If the port type is physical and the val is not zero log a kernel
3426 * error message, clear the restrict login flag and return zero.
3427 * Else set the restrict login flag to val.
3428 *
3429 * Returns:
3430 * zero if val is in range
3431 * -EINVAL val out of range
3432 **/
James Smart3de2a652007-08-02 11:09:59 -04003433static int
3434lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3435{
3436 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003437 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003438 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003439 "be set to %d, allowed range is [0, 1]\n",
3440 val);
James Smart3de2a652007-08-02 11:09:59 -04003441 vport->cfg_restrict_login = 1;
3442 return -EINVAL;
3443 }
3444 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003445 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3446 "0468 lpfc_restrict_login must be 0 for "
3447 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003448 vport->cfg_restrict_login = 0;
3449 return 0;
3450 }
3451 vport->cfg_restrict_login = val;
3452 return 0;
3453}
3454lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003455static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3456 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003457
3458/*
dea31012005-04-17 16:05:31 -05003459# Some disk devices have a "select ID" or "select Target" capability.
3460# From a protocol standpoint "select ID" usually means select the
3461# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3462# annex" which contains a table that maps a "select ID" (a number
3463# between 0 and 7F) to an ALPA. By default, for compatibility with
3464# older drivers, the lpfc driver scans this table from low ALPA to high
3465# ALPA.
3466#
3467# Turning on the scan-down variable (on = 1, off = 0) will
3468# cause the lpfc driver to use an inverted table, effectively
3469# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3470#
3471# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3472# and will not work across a fabric. Also this parameter will take
3473# effect only in the case when ALPA map is not available.)
3474*/
James Smart3de2a652007-08-02 11:09:59 -04003475LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3476 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003477
3478/*
dea31012005-04-17 16:05:31 -05003479# lpfc_topology: link topology for init link
3480# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003481# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003482# 0x02 = attempt point-to-point mode only
3483# 0x04 = attempt loop mode only
3484# 0x06 = attempt point-to-point mode then loop
3485# Set point-to-point mode if you want to run as an N_Port.
3486# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3487# Default value is 0.
3488*/
James Smart0a035432016-10-13 15:06:10 -07003489LPFC_ATTR(topology, 0, 0, 6,
3490 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003491
3492/**
James Smart3621a712009-04-06 18:47:14 -04003493 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003494 * @phba: lpfc_hba pointer.
3495 * @val: topology value.
3496 *
3497 * Description:
3498 * If val is in a valid range then set the adapter's topology field and
3499 * issue a lip; if the lip fails reset the topology to the old value.
3500 *
3501 * If the value is not in range log a kernel error message and return an error.
3502 *
3503 * Returns:
3504 * zero if val is in range and lip okay
3505 * non-zero return value from lpfc_issue_lip()
3506 * -EINVAL val out of range
3507 **/
James Smarta257bf92009-04-06 18:48:10 -04003508static ssize_t
3509lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3510 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003511{
James Smarta257bf92009-04-06 18:48:10 -04003512 struct Scsi_Host *shost = class_to_shost(dev);
3513 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3514 struct lpfc_hba *phba = vport->phba;
3515 int val = 0;
3516 int nolip = 0;
3517 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003518 int err;
3519 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003520
3521 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3522 nolip = 1;
3523 val_buf = &buf[strlen("nolip ")];
3524 }
3525
3526 if (!isdigit(val_buf[0]))
3527 return -EINVAL;
3528 if (sscanf(val_buf, "%i", &val) != 1)
3529 return -EINVAL;
3530
James Smart83108bd2008-01-11 01:53:09 -05003531 if (val >= 0 && val <= 6) {
3532 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003533 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3534 val == 4) {
3535 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3536 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003537 val);
James Smartff78d8f2011-12-13 13:21:35 -05003538 return -EINVAL;
3539 }
James Smartd38dd522015-08-31 16:48:17 -04003540 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3541 val == 4) {
3542 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3543 "3114 Loop mode not supported\n");
3544 return -EINVAL;
3545 }
3546 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003547 if (nolip)
3548 return strlen(buf);
3549
James Smart88a2cfb2011-07-22 18:36:33 -04003550 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3551 "3054 lpfc_topology changed from %d to %d\n",
3552 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003553 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3554 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003555 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003556 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003557 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003558 return -EINVAL;
3559 } else
3560 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003561 }
3562 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3563 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3564 "allowed range is [0, 6]\n",
3565 phba->brd_no, val);
3566 return -EINVAL;
3567}
James Smart0a035432016-10-13 15:06:10 -07003568
James Smart83108bd2008-01-11 01:53:09 -05003569lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003570static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003571 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003572
James Smart21e9a0a2009-05-22 14:53:21 -04003573/**
3574 * lpfc_static_vport_show: Read callback function for
3575 * lpfc_static_vport sysfs file.
3576 * @dev: Pointer to class device object.
3577 * @attr: device attribute structure.
3578 * @buf: Data buffer.
3579 *
3580 * This function is the read call back function for
3581 * lpfc_static_vport sysfs file. The lpfc_static_vport
3582 * sysfs file report the mageability of the vport.
3583 **/
3584static ssize_t
3585lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3586 char *buf)
3587{
3588 struct Scsi_Host *shost = class_to_shost(dev);
3589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3590 if (vport->vport_flag & STATIC_VPORT)
3591 sprintf(buf, "1\n");
3592 else
3593 sprintf(buf, "0\n");
3594
3595 return strlen(buf);
3596}
3597
3598/*
3599 * Sysfs attribute to control the statistical data collection.
3600 */
3601static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3602 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003603
3604/**
James Smart3621a712009-04-06 18:47:14 -04003605 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003606 * @dev: Pointer to class device.
3607 * @buf: Data buffer.
3608 * @count: Size of the data buffer.
3609 *
3610 * This function get called when an user write to the lpfc_stat_data_ctrl
3611 * sysfs file. This function parse the command written to the sysfs file
3612 * and take appropriate action. These commands are used for controlling
3613 * driver statistical data collection.
3614 * Following are the command this function handles.
3615 *
3616 * setbucket <bucket_type> <base> <step>
3617 * = Set the latency buckets.
3618 * destroybucket = destroy all the buckets.
3619 * start = start data collection
3620 * stop = stop data collection
3621 * reset = reset the collected data
3622 **/
3623static ssize_t
3624lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3625 const char *buf, size_t count)
3626{
3627 struct Scsi_Host *shost = class_to_shost(dev);
3628 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3629 struct lpfc_hba *phba = vport->phba;
3630#define LPFC_MAX_DATA_CTRL_LEN 1024
3631 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3632 unsigned long i;
3633 char *str_ptr, *token;
3634 struct lpfc_vport **vports;
3635 struct Scsi_Host *v_shost;
3636 char *bucket_type_str, *base_str, *step_str;
3637 unsigned long base, step, bucket_type;
3638
3639 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003640 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003641 return -EINVAL;
3642
James Smarteb016562014-09-03 12:58:06 -04003643 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003644 str_ptr = &bucket_data[0];
3645 /* Ignore this token - this is command token */
3646 token = strsep(&str_ptr, "\t ");
3647 if (!token)
3648 return -EINVAL;
3649
3650 bucket_type_str = strsep(&str_ptr, "\t ");
3651 if (!bucket_type_str)
3652 return -EINVAL;
3653
3654 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3655 bucket_type = LPFC_LINEAR_BUCKET;
3656 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3657 bucket_type = LPFC_POWER2_BUCKET;
3658 else
3659 return -EINVAL;
3660
3661 base_str = strsep(&str_ptr, "\t ");
3662 if (!base_str)
3663 return -EINVAL;
3664 base = simple_strtoul(base_str, NULL, 0);
3665
3666 step_str = strsep(&str_ptr, "\t ");
3667 if (!step_str)
3668 return -EINVAL;
3669 step = simple_strtoul(step_str, NULL, 0);
3670 if (!step)
3671 return -EINVAL;
3672
3673 /* Block the data collection for every vport */
3674 vports = lpfc_create_vport_work_array(phba);
3675 if (vports == NULL)
3676 return -ENOMEM;
3677
James Smartf4b4c682009-05-22 14:53:12 -04003678 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003679 v_shost = lpfc_shost_from_vport(vports[i]);
3680 spin_lock_irq(v_shost->host_lock);
3681 /* Block and reset data collection */
3682 vports[i]->stat_data_blocked = 1;
3683 if (vports[i]->stat_data_enabled)
3684 lpfc_vport_reset_stat_data(vports[i]);
3685 spin_unlock_irq(v_shost->host_lock);
3686 }
3687
3688 /* Set the bucket attributes */
3689 phba->bucket_type = bucket_type;
3690 phba->bucket_base = base;
3691 phba->bucket_step = step;
3692
James Smartf4b4c682009-05-22 14:53:12 -04003693 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003694 v_shost = lpfc_shost_from_vport(vports[i]);
3695
3696 /* Unblock data collection */
3697 spin_lock_irq(v_shost->host_lock);
3698 vports[i]->stat_data_blocked = 0;
3699 spin_unlock_irq(v_shost->host_lock);
3700 }
3701 lpfc_destroy_vport_work_array(phba, vports);
3702 return strlen(buf);
3703 }
3704
3705 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3706 vports = lpfc_create_vport_work_array(phba);
3707 if (vports == NULL)
3708 return -ENOMEM;
3709
James Smartf4b4c682009-05-22 14:53:12 -04003710 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003711 v_shost = lpfc_shost_from_vport(vports[i]);
3712 spin_lock_irq(shost->host_lock);
3713 vports[i]->stat_data_blocked = 1;
3714 lpfc_free_bucket(vport);
3715 vport->stat_data_enabled = 0;
3716 vports[i]->stat_data_blocked = 0;
3717 spin_unlock_irq(shost->host_lock);
3718 }
3719 lpfc_destroy_vport_work_array(phba, vports);
3720 phba->bucket_type = LPFC_NO_BUCKET;
3721 phba->bucket_base = 0;
3722 phba->bucket_step = 0;
3723 return strlen(buf);
3724 }
3725
3726 if (!strncmp(buf, "start", strlen("start"))) {
3727 /* If no buckets configured return error */
3728 if (phba->bucket_type == LPFC_NO_BUCKET)
3729 return -EINVAL;
3730 spin_lock_irq(shost->host_lock);
3731 if (vport->stat_data_enabled) {
3732 spin_unlock_irq(shost->host_lock);
3733 return strlen(buf);
3734 }
3735 lpfc_alloc_bucket(vport);
3736 vport->stat_data_enabled = 1;
3737 spin_unlock_irq(shost->host_lock);
3738 return strlen(buf);
3739 }
3740
3741 if (!strncmp(buf, "stop", strlen("stop"))) {
3742 spin_lock_irq(shost->host_lock);
3743 if (vport->stat_data_enabled == 0) {
3744 spin_unlock_irq(shost->host_lock);
3745 return strlen(buf);
3746 }
3747 lpfc_free_bucket(vport);
3748 vport->stat_data_enabled = 0;
3749 spin_unlock_irq(shost->host_lock);
3750 return strlen(buf);
3751 }
3752
3753 if (!strncmp(buf, "reset", strlen("reset"))) {
3754 if ((phba->bucket_type == LPFC_NO_BUCKET)
3755 || !vport->stat_data_enabled)
3756 return strlen(buf);
3757 spin_lock_irq(shost->host_lock);
3758 vport->stat_data_blocked = 1;
3759 lpfc_vport_reset_stat_data(vport);
3760 vport->stat_data_blocked = 0;
3761 spin_unlock_irq(shost->host_lock);
3762 return strlen(buf);
3763 }
3764 return -EINVAL;
3765}
3766
3767
3768/**
James Smart3621a712009-04-06 18:47:14 -04003769 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003770 * @dev: Pointer to class device object.
3771 * @buf: Data buffer.
3772 *
3773 * This function is the read call back function for
3774 * lpfc_stat_data_ctrl sysfs file. This function report the
3775 * current statistical data collection state.
3776 **/
3777static ssize_t
3778lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3779 char *buf)
3780{
3781 struct Scsi_Host *shost = class_to_shost(dev);
3782 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3783 struct lpfc_hba *phba = vport->phba;
3784 int index = 0;
3785 int i;
3786 char *bucket_type;
3787 unsigned long bucket_value;
3788
3789 switch (phba->bucket_type) {
3790 case LPFC_LINEAR_BUCKET:
3791 bucket_type = "linear";
3792 break;
3793 case LPFC_POWER2_BUCKET:
3794 bucket_type = "power2";
3795 break;
3796 default:
3797 bucket_type = "No Bucket";
3798 break;
3799 }
3800
3801 sprintf(&buf[index], "Statistical Data enabled :%d, "
3802 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3803 " Bucket step :%d\nLatency Ranges :",
3804 vport->stat_data_enabled, vport->stat_data_blocked,
3805 bucket_type, phba->bucket_base, phba->bucket_step);
3806 index = strlen(buf);
3807 if (phba->bucket_type != LPFC_NO_BUCKET) {
3808 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3809 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3810 bucket_value = phba->bucket_base +
3811 phba->bucket_step * i;
3812 else
3813 bucket_value = phba->bucket_base +
3814 (1 << i) * phba->bucket_step;
3815
3816 if (index + 10 > PAGE_SIZE)
3817 break;
3818 sprintf(&buf[index], "%08ld ", bucket_value);
3819 index = strlen(buf);
3820 }
3821 }
3822 sprintf(&buf[index], "\n");
3823 return strlen(buf);
3824}
3825
3826/*
3827 * Sysfs attribute to control the statistical data collection.
3828 */
3829static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3830 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3831
3832/*
3833 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3834 */
3835
3836/*
3837 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3838 * for each target.
3839 */
3840#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3841#define MAX_STAT_DATA_SIZE_PER_TARGET \
3842 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3843
3844
3845/**
James Smart3621a712009-04-06 18:47:14 -04003846 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003847 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003848 * @kobj: Pointer to the kernel object
3849 * @bin_attr: Attribute object
3850 * @buff: Buffer pointer
3851 * @off: File offset
3852 * @count: Buffer size
3853 *
3854 * This function is the read call back function for lpfc_drvr_stat_data
3855 * sysfs file. This function export the statistical data to user
3856 * applications.
3857 **/
3858static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003859sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3860 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003861 char *buf, loff_t off, size_t count)
3862{
3863 struct device *dev = container_of(kobj, struct device,
3864 kobj);
3865 struct Scsi_Host *shost = class_to_shost(dev);
3866 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3867 struct lpfc_hba *phba = vport->phba;
3868 int i = 0, index = 0;
3869 unsigned long nport_index;
3870 struct lpfc_nodelist *ndlp = NULL;
3871 nport_index = (unsigned long)off /
3872 MAX_STAT_DATA_SIZE_PER_TARGET;
3873
3874 if (!vport->stat_data_enabled || vport->stat_data_blocked
3875 || (phba->bucket_type == LPFC_NO_BUCKET))
3876 return 0;
3877
3878 spin_lock_irq(shost->host_lock);
3879 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3880 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3881 continue;
3882
3883 if (nport_index > 0) {
3884 nport_index--;
3885 continue;
3886 }
3887
3888 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3889 > count)
3890 break;
3891
3892 if (!ndlp->lat_data)
3893 continue;
3894
3895 /* Print the WWN */
3896 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3897 ndlp->nlp_portname.u.wwn[0],
3898 ndlp->nlp_portname.u.wwn[1],
3899 ndlp->nlp_portname.u.wwn[2],
3900 ndlp->nlp_portname.u.wwn[3],
3901 ndlp->nlp_portname.u.wwn[4],
3902 ndlp->nlp_portname.u.wwn[5],
3903 ndlp->nlp_portname.u.wwn[6],
3904 ndlp->nlp_portname.u.wwn[7]);
3905
3906 index = strlen(buf);
3907
3908 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3909 sprintf(&buf[index], "%010u,",
3910 ndlp->lat_data[i].cmd_count);
3911 index = strlen(buf);
3912 }
3913 sprintf(&buf[index], "\n");
3914 index = strlen(buf);
3915 }
3916 spin_unlock_irq(shost->host_lock);
3917 return index;
3918}
3919
3920static struct bin_attribute sysfs_drvr_stat_data_attr = {
3921 .attr = {
3922 .name = "lpfc_drvr_stat_data",
3923 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003924 },
3925 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3926 .read = sysfs_drvr_stat_data_read,
3927 .write = NULL,
3928};
3929
dea31012005-04-17 16:05:31 -05003930/*
3931# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3932# connection.
James Smart76a95d72010-11-20 23:11:48 -05003933# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003934*/
James Smarte59058c2008-08-24 21:49:00 -04003935/**
James Smart3621a712009-04-06 18:47:14 -04003936 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003937 * @phba: lpfc_hba pointer.
3938 * @val: link speed value.
3939 *
3940 * Description:
3941 * If val is in a valid range then set the adapter's link speed field and
3942 * issue a lip; if the lip fails reset the link speed to the old value.
3943 *
3944 * Notes:
3945 * If the value is not in range log a kernel error message and return an error.
3946 *
3947 * Returns:
3948 * zero if val is in range and lip okay.
3949 * non-zero return value from lpfc_issue_lip()
3950 * -EINVAL val out of range
3951 **/
James Smarta257bf92009-04-06 18:48:10 -04003952static ssize_t
3953lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3954 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003955{
James Smarta257bf92009-04-06 18:48:10 -04003956 struct Scsi_Host *shost = class_to_shost(dev);
3957 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3958 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003959 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003960 int nolip = 0;
3961 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003962 int err;
James Smartc6918162016-10-13 15:06:16 -07003963 uint32_t prev_val, if_type;
3964
3965 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3966 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3967 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3968 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05003969
James Smarta257bf92009-04-06 18:48:10 -04003970 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3971 nolip = 1;
3972 val_buf = &buf[strlen("nolip ")];
3973 }
3974
3975 if (!isdigit(val_buf[0]))
3976 return -EINVAL;
3977 if (sscanf(val_buf, "%i", &val) != 1)
3978 return -EINVAL;
3979
James Smart88a2cfb2011-07-22 18:36:33 -04003980 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3981 "3055 lpfc_link_speed changed from %d to %d %s\n",
3982 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
3983
James Smart76a95d72010-11-20 23:11:48 -05003984 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
3985 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
3986 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
3987 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
3988 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04003989 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
3990 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05003991 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3992 "2879 lpfc_link_speed attribute cannot be set "
3993 "to %d. Speed is not supported by this port.\n",
3994 val);
James Smart83108bd2008-01-11 01:53:09 -05003995 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05003996 }
James Smartff78d8f2011-12-13 13:21:35 -05003997 if (val == LPFC_USER_LINK_SPEED_16G &&
3998 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4000 "3112 lpfc_link_speed attribute cannot be set "
4001 "to %d. Speed is not supported in loop mode.\n",
4002 val);
4003 return -EINVAL;
4004 }
James Smart76a95d72010-11-20 23:11:48 -05004005 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4006 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004007 prev_val = phba->cfg_link_speed;
4008 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004009 if (nolip)
4010 return strlen(buf);
4011
James Smart83108bd2008-01-11 01:53:09 -05004012 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004013 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004014 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004015 return -EINVAL;
4016 } else
4017 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004018 }
James Smart83108bd2008-01-11 01:53:09 -05004019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004020 "0469 lpfc_link_speed attribute cannot be set to %d, "
4021 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004022 return -EINVAL;
4023}
4024
4025static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004026module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004027MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4028lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004029
4030/**
James Smart3621a712009-04-06 18:47:14 -04004031 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004032 * @phba: lpfc_hba pointer.
4033 * @val: link speed value.
4034 *
4035 * Description:
4036 * If val is in a valid range then set the adapter's link speed field.
4037 *
4038 * Notes:
4039 * If the value is not in range log a kernel error message, clear the link
4040 * speed and return an error.
4041 *
4042 * Returns:
4043 * zero if val saved.
4044 * -EINVAL val out of range
4045 **/
James Smart83108bd2008-01-11 01:53:09 -05004046static int
4047lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4048{
James Smartff78d8f2011-12-13 13:21:35 -05004049 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4051 "3111 lpfc_link_speed of %d cannot "
4052 "support loop mode, setting topology to default.\n",
4053 val);
4054 phba->cfg_topology = 0;
4055 }
James Smart76a95d72010-11-20 23:11:48 -05004056 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4057 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004058 phba->cfg_link_speed = val;
4059 return 0;
4060 }
4061 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004062 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004063 "be set to %d, allowed values are "
4064 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004065 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004066 return -EINVAL;
4067}
4068
Tony Jonesee959b02008-02-22 00:13:36 +01004069static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05004070 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05004071
4072/*
James Smart0d878412009-10-02 15:16:56 -04004073# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4074# 0 = aer disabled or not supported
4075# 1 = aer supported and enabled (default)
4076# Value range is [0,1]. Default value is 1.
4077*/
James Smart506139a2016-10-13 15:06:09 -07004078LPFC_ATTR(aer_support, 1, 0, 1,
4079 "Enable PCIe device AER support");
4080lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004081
4082/**
4083 * lpfc_aer_support_store - Set the adapter for aer support
4084 *
4085 * @dev: class device that is converted into a Scsi_host.
4086 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004087 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004088 * @count: unused variable.
4089 *
4090 * Description:
4091 * If the val is 1 and currently the device's AER capability was not
4092 * enabled, invoke the kernel's enable AER helper routine, trying to
4093 * enable the device's AER capability. If the helper routine enabling
4094 * AER returns success, update the device's cfg_aer_support flag to
4095 * indicate AER is supported by the device; otherwise, if the device
4096 * AER capability is already enabled to support AER, then do nothing.
4097 *
4098 * If the val is 0 and currently the device's AER support was enabled,
4099 * invoke the kernel's disable AER helper routine. After that, update
4100 * the device's cfg_aer_support flag to indicate AER is not supported
4101 * by the device; otherwise, if the device AER capability is already
4102 * disabled from supporting AER, then do nothing.
4103 *
4104 * Returns:
4105 * length of the buf on success if val is in range the intended mode
4106 * is supported.
4107 * -EINVAL if val out of range or intended mode is not supported.
4108 **/
4109static ssize_t
4110lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4111 const char *buf, size_t count)
4112{
4113 struct Scsi_Host *shost = class_to_shost(dev);
4114 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4115 struct lpfc_hba *phba = vport->phba;
4116 int val = 0, rc = -EINVAL;
4117
4118 if (!isdigit(buf[0]))
4119 return -EINVAL;
4120 if (sscanf(buf, "%i", &val) != 1)
4121 return -EINVAL;
4122
4123 switch (val) {
4124 case 0:
4125 if (phba->hba_flag & HBA_AER_ENABLED) {
4126 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4127 if (!rc) {
4128 spin_lock_irq(&phba->hbalock);
4129 phba->hba_flag &= ~HBA_AER_ENABLED;
4130 spin_unlock_irq(&phba->hbalock);
4131 phba->cfg_aer_support = 0;
4132 rc = strlen(buf);
4133 } else
James Smart891478a2009-11-18 15:40:23 -05004134 rc = -EPERM;
4135 } else {
James Smart0d878412009-10-02 15:16:56 -04004136 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004137 rc = strlen(buf);
4138 }
James Smart0d878412009-10-02 15:16:56 -04004139 break;
4140 case 1:
4141 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4142 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4143 if (!rc) {
4144 spin_lock_irq(&phba->hbalock);
4145 phba->hba_flag |= HBA_AER_ENABLED;
4146 spin_unlock_irq(&phba->hbalock);
4147 phba->cfg_aer_support = 1;
4148 rc = strlen(buf);
4149 } else
James Smart891478a2009-11-18 15:40:23 -05004150 rc = -EPERM;
4151 } else {
James Smart0d878412009-10-02 15:16:56 -04004152 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004153 rc = strlen(buf);
4154 }
James Smart0d878412009-10-02 15:16:56 -04004155 break;
4156 default:
4157 rc = -EINVAL;
4158 break;
4159 }
4160 return rc;
4161}
4162
James Smart0d878412009-10-02 15:16:56 -04004163static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4164 lpfc_aer_support_show, lpfc_aer_support_store);
4165
4166/**
4167 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4168 * @dev: class device that is converted into a Scsi_host.
4169 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004170 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004171 * @count: unused variable.
4172 *
4173 * Description:
4174 * If the @buf contains 1 and the device currently has the AER support
4175 * enabled, then invokes the kernel AER helper routine
4176 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4177 * error status register.
4178 *
4179 * Notes:
4180 *
4181 * Returns:
4182 * -EINVAL if the buf does not contain the 1 or the device is not currently
4183 * enabled with the AER support.
4184 **/
4185static ssize_t
4186lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4187 const char *buf, size_t count)
4188{
4189 struct Scsi_Host *shost = class_to_shost(dev);
4190 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4191 struct lpfc_hba *phba = vport->phba;
4192 int val, rc = -1;
4193
4194 if (!isdigit(buf[0]))
4195 return -EINVAL;
4196 if (sscanf(buf, "%i", &val) != 1)
4197 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004198 if (val != 1)
4199 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004200
James Smart891478a2009-11-18 15:40:23 -05004201 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004202 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4203
4204 if (rc == 0)
4205 return strlen(buf);
4206 else
James Smart891478a2009-11-18 15:40:23 -05004207 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004208}
4209
4210static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4211 lpfc_aer_cleanup_state);
4212
James Smart912e3ac2011-05-24 11:42:11 -04004213/**
4214 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4215 *
4216 * @dev: class device that is converted into a Scsi_host.
4217 * @attr: device attribute, not used.
4218 * @buf: containing the string the number of vfs to be enabled.
4219 * @count: unused variable.
4220 *
4221 * Description:
4222 * When this api is called either through user sysfs, the driver shall
4223 * try to enable or disable SR-IOV virtual functions according to the
4224 * following:
4225 *
4226 * If zero virtual function has been enabled to the physical function,
4227 * the driver shall invoke the pci enable virtual function api trying
4228 * to enable the virtual functions. If the nr_vfn provided is greater
4229 * than the maximum supported, the maximum virtual function number will
4230 * be used for invoking the api; otherwise, the nr_vfn provided shall
4231 * be used for invoking the api. If the api call returned success, the
4232 * actual number of virtual functions enabled will be set to the driver
4233 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4234 * cfg_sriov_nr_virtfn remains zero.
4235 *
4236 * If none-zero virtual functions have already been enabled to the
4237 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4238 * -EINVAL will be returned and the driver does nothing;
4239 *
4240 * If the nr_vfn provided is zero and none-zero virtual functions have
4241 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4242 * disabling virtual function api shall be invoded to disable all the
4243 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4244 * zero. Otherwise, if zero virtual function has been enabled, do
4245 * nothing.
4246 *
4247 * Returns:
4248 * length of the buf on success if val is in range the intended mode
4249 * is supported.
4250 * -EINVAL if val out of range or intended mode is not supported.
4251 **/
4252static ssize_t
4253lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4254 const char *buf, size_t count)
4255{
4256 struct Scsi_Host *shost = class_to_shost(dev);
4257 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4258 struct lpfc_hba *phba = vport->phba;
4259 struct pci_dev *pdev = phba->pcidev;
4260 int val = 0, rc = -EINVAL;
4261
4262 /* Sanity check on user data */
4263 if (!isdigit(buf[0]))
4264 return -EINVAL;
4265 if (sscanf(buf, "%i", &val) != 1)
4266 return -EINVAL;
4267 if (val < 0)
4268 return -EINVAL;
4269
4270 /* Request disabling virtual functions */
4271 if (val == 0) {
4272 if (phba->cfg_sriov_nr_virtfn > 0) {
4273 pci_disable_sriov(pdev);
4274 phba->cfg_sriov_nr_virtfn = 0;
4275 }
4276 return strlen(buf);
4277 }
4278
4279 /* Request enabling virtual functions */
4280 if (phba->cfg_sriov_nr_virtfn > 0) {
4281 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4282 "3018 There are %d virtual functions "
4283 "enabled on physical function.\n",
4284 phba->cfg_sriov_nr_virtfn);
4285 return -EEXIST;
4286 }
4287
4288 if (val <= LPFC_MAX_VFN_PER_PFN)
4289 phba->cfg_sriov_nr_virtfn = val;
4290 else {
4291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4292 "3019 Enabling %d virtual functions is not "
4293 "allowed.\n", val);
4294 return -EINVAL;
4295 }
4296
4297 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4298 if (rc) {
4299 phba->cfg_sriov_nr_virtfn = 0;
4300 rc = -EPERM;
4301 } else
4302 rc = strlen(buf);
4303
4304 return rc;
4305}
4306
James Smart0cfbbf22016-10-13 15:06:12 -07004307LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4308 "Enable PCIe device SR-IOV virtual fn");
4309
James Smart912e3ac2011-05-24 11:42:11 -04004310lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004311static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4312 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4313
James Smart173edbb2012-06-12 13:54:50 -04004314/**
James Smartc71ab862012-10-31 14:44:33 -04004315 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4316 *
4317 * @dev: class device that is converted into a Scsi_host.
4318 * @attr: device attribute, not used.
4319 * @buf: containing the string the number of vfs to be enabled.
4320 * @count: unused variable.
4321 *
4322 * Description:
4323 *
4324 * Returns:
4325 * length of the buf on success if val is in range the intended mode
4326 * is supported.
4327 * -EINVAL if val out of range or intended mode is not supported.
4328 **/
4329static ssize_t
4330lpfc_request_firmware_upgrade_store(struct device *dev,
4331 struct device_attribute *attr,
4332 const char *buf, size_t count)
4333{
4334 struct Scsi_Host *shost = class_to_shost(dev);
4335 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4336 struct lpfc_hba *phba = vport->phba;
4337 int val = 0, rc = -EINVAL;
4338
4339 /* Sanity check on user data */
4340 if (!isdigit(buf[0]))
4341 return -EINVAL;
4342 if (sscanf(buf, "%i", &val) != 1)
4343 return -EINVAL;
4344 if (val != 1)
4345 return -EINVAL;
4346
4347 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4348 if (rc)
4349 rc = -EPERM;
4350 else
4351 rc = strlen(buf);
4352 return rc;
4353}
4354
4355static int lpfc_req_fw_upgrade;
4356module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4357MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4358lpfc_param_show(request_firmware_upgrade)
4359
4360/**
4361 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4362 * @phba: lpfc_hba pointer.
4363 * @val: 0 or 1.
4364 *
4365 * Description:
4366 * Set the initial Linux generic firmware upgrade enable or disable flag.
4367 *
4368 * Returns:
4369 * zero if val saved.
4370 * -EINVAL val out of range
4371 **/
4372static int
4373lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4374{
4375 if (val >= 0 && val <= 1) {
4376 phba->cfg_request_firmware_upgrade = val;
4377 return 0;
4378 }
4379 return -EINVAL;
4380}
4381static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4382 lpfc_request_firmware_upgrade_show,
4383 lpfc_request_firmware_upgrade_store);
4384
4385/**
James Smart173edbb2012-06-12 13:54:50 -04004386 * lpfc_fcp_imax_store
4387 *
4388 * @dev: class device that is converted into a Scsi_host.
4389 * @attr: device attribute, not used.
4390 * @buf: string with the number of fast-path FCP interrupts per second.
4391 * @count: unused variable.
4392 *
4393 * Description:
4394 * If val is in a valid range [636,651042], then set the adapter's
4395 * maximum number of fast-path FCP interrupts per second.
4396 *
4397 * Returns:
4398 * length of the buf on success if val is in range the intended mode
4399 * is supported.
4400 * -EINVAL if val out of range or intended mode is not supported.
4401 **/
4402static ssize_t
4403lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4404 const char *buf, size_t count)
4405{
4406 struct Scsi_Host *shost = class_to_shost(dev);
4407 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4408 struct lpfc_hba *phba = vport->phba;
4409 int val = 0, i;
4410
James Smartbf8dae82012-08-03 12:36:24 -04004411 /* fcp_imax is only valid for SLI4 */
4412 if (phba->sli_rev != LPFC_SLI_REV4)
4413 return -EINVAL;
4414
James Smart173edbb2012-06-12 13:54:50 -04004415 /* Sanity check on user data */
4416 if (!isdigit(buf[0]))
4417 return -EINVAL;
4418 if (sscanf(buf, "%i", &val) != 1)
4419 return -EINVAL;
4420
James Smartbf8dae82012-08-03 12:36:24 -04004421 /*
4422 * Value range for the HBA is [5000,5000000]
4423 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004424 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004425 */
James Smart895427b2017-02-12 13:52:30 -08004426 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004427 return -EINVAL;
4428
4429 phba->cfg_fcp_imax = (uint32_t)val;
James Smart895427b2017-02-12 13:52:30 -08004430 for (i = 0; i < phba->io_channel_irqs; i++)
4431 lpfc_modify_hba_eq_delay(phba, i);
James Smart173edbb2012-06-12 13:54:50 -04004432
4433 return strlen(buf);
4434}
4435
4436/*
4437# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004438# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004439#
James Smartbf8dae82012-08-03 12:36:24 -04004440# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004441*/
James Smartbf8dae82012-08-03 12:36:24 -04004442static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004443module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4444MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004445 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004446lpfc_param_show(fcp_imax)
4447
4448/**
4449 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4450 * @phba: lpfc_hba pointer.
4451 * @val: link speed value.
4452 *
4453 * Description:
4454 * If val is in a valid range [636,651042], then initialize the adapter's
4455 * maximum number of fast-path FCP interrupts per second.
4456 *
4457 * Returns:
4458 * zero if val saved.
4459 * -EINVAL val out of range
4460 **/
4461static int
4462lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4463{
James Smartbf8dae82012-08-03 12:36:24 -04004464 if (phba->sli_rev != LPFC_SLI_REV4) {
4465 phba->cfg_fcp_imax = 0;
4466 return 0;
4467 }
4468
James Smart895427b2017-02-12 13:52:30 -08004469 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4470 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004471 phba->cfg_fcp_imax = val;
4472 return 0;
4473 }
4474
4475 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004476 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4477 val);
James Smartbf8dae82012-08-03 12:36:24 -04004478 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004479
4480 return 0;
4481}
4482
4483static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4484 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4485
James Smart7bb03bb2013-04-17 20:19:16 -04004486/**
4487 * lpfc_state_show - Display current driver CPU affinity
4488 * @dev: class converted to a Scsi_host structure.
4489 * @attr: device attribute, not used.
4490 * @buf: on return contains text describing the state of the link.
4491 *
4492 * Returns: size of formatted string.
4493 **/
4494static ssize_t
4495lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4496 char *buf)
4497{
4498 struct Scsi_Host *shost = class_to_shost(dev);
4499 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4500 struct lpfc_hba *phba = vport->phba;
4501 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004502 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004503
4504 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4505 (phba->intr_type != MSIX))
4506 return len;
4507
4508 switch (phba->cfg_fcp_cpu_map) {
4509 case 0:
4510 len += snprintf(buf + len, PAGE_SIZE-len,
4511 "fcp_cpu_map: No mapping (%d)\n",
4512 phba->cfg_fcp_cpu_map);
4513 return len;
4514 case 1:
4515 len += snprintf(buf + len, PAGE_SIZE-len,
4516 "fcp_cpu_map: HBA centric mapping (%d): "
4517 "%d online CPUs\n",
4518 phba->cfg_fcp_cpu_map,
4519 phba->sli4_hba.num_online_cpu);
4520 break;
4521 case 2:
4522 len += snprintf(buf + len, PAGE_SIZE-len,
4523 "fcp_cpu_map: Driver centric mapping (%d): "
4524 "%d online CPUs\n",
4525 phba->cfg_fcp_cpu_map,
4526 phba->sli4_hba.num_online_cpu);
4527 break;
4528 }
4529
James Smart76fd07a2014-02-20 09:57:18 -05004530 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4531 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4532
4533 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004534 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4535 len += snprintf(buf + len, PAGE_SIZE-len,
4536 "CPU %02d io_chan %02d "
4537 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004538 phba->sli4_hba.curr_disp_cpu,
4539 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004540 cpup->core_id);
4541 else
4542 len += snprintf(buf + len, PAGE_SIZE-len,
4543 "CPU %02d io_chan %02d "
4544 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004545 phba->sli4_hba.curr_disp_cpu,
4546 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004547 cpup->core_id, cpup->irq);
4548
James Smart76fd07a2014-02-20 09:57:18 -05004549 phba->sli4_hba.curr_disp_cpu++;
4550
4551 /* display max number of CPUs keeping some margin */
4552 if (phba->sli4_hba.curr_disp_cpu <
4553 phba->sli4_hba.num_present_cpu &&
4554 (len >= (PAGE_SIZE - 64))) {
4555 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4556 break;
4557 }
James Smart7bb03bb2013-04-17 20:19:16 -04004558 }
James Smart76fd07a2014-02-20 09:57:18 -05004559
4560 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4561 phba->sli4_hba.curr_disp_cpu = 0;
4562
James Smart7bb03bb2013-04-17 20:19:16 -04004563 return len;
4564}
4565
4566/**
4567 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4568 * @dev: class device that is converted into a Scsi_host.
4569 * @attr: device attribute, not used.
4570 * @buf: one or more lpfc_polling_flags values.
4571 * @count: not used.
4572 *
4573 * Returns:
4574 * -EINVAL - Not implemented yet.
4575 **/
4576static ssize_t
4577lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4578 const char *buf, size_t count)
4579{
4580 int status = -EINVAL;
4581 return status;
4582}
4583
4584/*
4585# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4586# for the HBA.
4587#
4588# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4589# 0 - Do not affinitze IRQ vectors
4590# 1 - Affintize HBA vectors with respect to each HBA
4591# (start with CPU0 for each HBA)
4592# 2 - Affintize HBA vectors with respect to the entire driver
4593# (round robin thru all CPUs across all HBAs)
4594*/
4595static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4596module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4597MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4598 "Defines how to map CPUs to IRQ vectors per HBA");
4599
4600/**
4601 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4602 * @phba: lpfc_hba pointer.
4603 * @val: link speed value.
4604 *
4605 * Description:
4606 * If val is in a valid range [0-2], then affinitze the adapter's
4607 * MSIX vectors.
4608 *
4609 * Returns:
4610 * zero if val saved.
4611 * -EINVAL val out of range
4612 **/
4613static int
4614lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4615{
4616 if (phba->sli_rev != LPFC_SLI_REV4) {
4617 phba->cfg_fcp_cpu_map = 0;
4618 return 0;
4619 }
4620
4621 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4622 phba->cfg_fcp_cpu_map = val;
4623 return 0;
4624 }
4625
4626 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004627 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4628 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004629 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4630
4631 return 0;
4632}
4633
4634static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4635 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4636
James Smart0d878412009-10-02 15:16:56 -04004637/*
dea31012005-04-17 16:05:31 -05004638# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4639# Value range is [2,3]. Default value is 3.
4640*/
James Smart3de2a652007-08-02 11:09:59 -04004641LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4642 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004643
4644/*
4645# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4646# is [0,1]. Default value is 0.
4647*/
James Smart3de2a652007-08-02 11:09:59 -04004648LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4649 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004650
4651/*
James Smart3cb01c52013-07-15 18:35:04 -04004652# lpfc_first_burst_size: First burst size to use on the NPorts
4653# that support first burst.
4654# Value range is [0,65536]. Default value is 0.
4655*/
4656LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4657 "First burst size for Targets that support first burst");
4658
4659/*
James Smart895427b2017-02-12 13:52:30 -08004660* lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4661* For the Initiator (I), enabling this parameter means that an NVME
4662* PRLI response with FBA enabled and an FB_SIZE set to a nonzero value
4663* will be processed by the initiator for subsequent NVME FCP IO.
4664* Parameter supported on physical port only - no NPIV support.
4665* Value range is [0,1]. Default value is 0 (disabled).
4666*/
4667LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4668 "Enable First Burst feature on I and T functions.");
4669
4670/*
James Smart977b5a02008-09-07 11:52:04 -04004671# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4672# depth. Default value is 0. When the value of this parameter is zero the
4673# SCSI command completion time is not used for controlling I/O queue depth. When
4674# the parameter is set to a non-zero value, the I/O queue depth is controlled
4675# to limit the I/O completion time to the parameter value.
4676# The value is set in milliseconds.
4677*/
James Smarted5b1522016-10-13 15:06:11 -07004678LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004679 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004680
James Smart977b5a02008-09-07 11:52:04 -04004681lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004682static int
4683lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4684{
4685 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4686 struct lpfc_nodelist *ndlp, *next_ndlp;
4687
4688 if (val == vport->cfg_max_scsicmpl_time)
4689 return 0;
4690 if ((val < 0) || (val > 60000))
4691 return -EINVAL;
4692 vport->cfg_max_scsicmpl_time = val;
4693
4694 spin_lock_irq(shost->host_lock);
4695 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4696 if (!NLP_CHK_NODE_ACT(ndlp))
4697 continue;
4698 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4699 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004700 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004701 }
4702 spin_unlock_irq(shost->host_lock);
4703 return 0;
4704}
4705lpfc_vport_param_store(max_scsicmpl_time);
4706static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4707 lpfc_max_scsicmpl_time_show,
4708 lpfc_max_scsicmpl_time_store);
4709
4710/*
dea31012005-04-17 16:05:31 -05004711# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4712# range is [0,1]. Default value is 0.
4713*/
4714LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4715
4716/*
James Smart895427b2017-02-12 13:52:30 -08004717 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4718 * range is [0,1]. Default value is 0.
4719 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4720 * For [1], FCP commands are issued to a Work Queue associated with the
4721 * current CPU.
4722 *
4723 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4724 * LPFC_FCP_SCHED_BY_CPU == 1
4725 *
4726 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4727 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4728 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4729 * through WQs will be used.
4730 */
4731LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4732 LPFC_FCP_SCHED_ROUND_ROBIN,
4733 LPFC_FCP_SCHED_BY_CPU,
4734 "Determine scheduling algorithm for "
4735 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004736
4737/*
James Smarta6571c62012-10-31 14:44:42 -04004738# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4739# range is [0,1]. Default value is 0.
4740# For [0], bus reset issues target reset to ALL devices
4741# For [1], bus reset issues target reset to non-FCP2 devices
4742*/
4743LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4744 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4745
4746
4747/*
dea31012005-04-17 16:05:31 -05004748# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4749# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004750# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004751# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4752# cr_delay is set to 0.
4753*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004754LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004755 "interrupt response is generated");
4756
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004757LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004758 "interrupt response is generated");
4759
4760/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004761# lpfc_multi_ring_support: Determines how many rings to spread available
4762# cmd/rsp IOCB entries across.
4763# Value range is [1,2]. Default value is 1.
4764*/
4765LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4766 "SLI rings to spread IOCB entries across");
4767
4768/*
James Smarta4bc3372006-12-02 13:34:16 -05004769# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4770# identifies what rctl value to configure the additional ring for.
4771# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4772*/
James Smart6a9c52c2009-10-02 15:16:51 -04004773LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004774 255, "Identifies RCTL for additional ring configuration");
4775
4776/*
4777# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4778# identifies what type value to configure the additional ring for.
4779# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4780*/
James Smart6a9c52c2009-10-02 15:16:51 -04004781LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004782 255, "Identifies TYPE for additional ring configuration");
4783
4784/*
James Smart4258e982015-12-16 18:11:58 -05004785# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4786# 0 = SmartSAN functionality disabled (default)
4787# 1 = SmartSAN functionality enabled
4788# This parameter will override the value of lpfc_fdmi_on module parameter.
4789# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004790*/
James Smart4258e982015-12-16 18:11:58 -05004791LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4792
4793/*
4794# lpfc_fdmi_on: Controls FDMI support.
4795# 0 No FDMI support (default)
4796# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004797# Traditional FDMI support means the driver will assume FDMI-2 support;
4798# however, if that fails, it will fallback to FDMI-1.
4799# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4800# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4801# lpfc_fdmi_on.
4802# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004803*/
James Smart8663cbb2016-03-31 14:12:33 -07004804LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004805
4806/*
4807# Specifies the maximum number of ELS cmds we can have outstanding (for
4808# discovery). Value range is [1,64]. Default value = 32.
4809*/
James Smart3de2a652007-08-02 11:09:59 -04004810LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004811 "during discovery");
4812
4813/*
James Smartc4a7c922013-05-31 17:04:59 -04004814# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4815# will be scanned by the SCSI midlayer when sequential scanning is
4816# used; and is also the highest LUN ID allowed when the SCSI midlayer
4817# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4818# LUN ID limit, but the SCSI midlayer requires this field for the uses
4819# above. The lpfc driver limits the default value to 255 for two reasons.
4820# As it bounds the sequential scan loop, scanning for thousands of luns
4821# on a target can take minutes of wall clock time. Additionally,
4822# there are FC targets, such as JBODs, that only recognize 8-bits of
4823# LUN ID. When they receive a value greater than 8 bits, they chop off
4824# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4825# and so on all as LUN ID 0. This causes the linux kernel, which sees
4826# valid responses at each of the LUN IDs, to believe there are multiple
4827# devices present, when in fact, there is only 1.
4828# A customer that is aware of their target behaviors, and the results as
4829# indicated above, is welcome to increase the lpfc_max_luns value.
4830# As mentioned, this value is not used by the lpfc driver, only the
4831# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004832# Value range is [0,65535]. Default value is 255.
4833# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004834*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004835LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004836
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004837/*
4838# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4839# Value range is [1,255], default value is 10.
4840*/
4841LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4842 "Milliseconds driver will wait between polling FCP ring");
4843
James Smart4ff43242006-12-02 13:34:56 -05004844/*
James Smart0c411222013-09-06 12:22:46 -04004845# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4846# to complete in seconds. Value range is [5,180], default value is 60.
4847*/
4848LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4849 "Maximum time to wait for task management commands to complete");
4850/*
James Smart4ff43242006-12-02 13:34:56 -05004851# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4852# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004853# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004854# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004855# 2 = MSI-X enabled (default)
4856# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004857*/
George Kadianakis8605c462010-01-17 21:19:31 +02004858LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004859 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004860
James Smart13815c82008-01-11 01:52:48 -05004861/*
James Smartf358dd02017-02-12 13:52:34 -08004862 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004863 *
4864 * 0 = NVME OAS disabled
4865 * 1 = NVME OAS enabled
4866 *
4867 * Value range is [0,1]. Default value is 0.
4868 */
4869LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4870 "Use OAS bit on NVME IOs");
4871
4872/*
4873 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4874 * will advertise it supports to the SCSI layer. This also will map to
4875 * the number of WQs the driver will create.
4876 *
4877 * 0 = Configure the number of io channels to the number of active CPUs.
4878 * 1,32 = Manually specify how many io channels to use.
4879 *
4880 * Value range is [0,32]. Default value is 4.
4881 */
4882LPFC_ATTR_R(fcp_io_channel,
4883 LPFC_FCP_IO_CHAN_DEF,
4884 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004885 "Set the number of FCP I/O channels");
4886
4887/*
James Smart895427b2017-02-12 13:52:30 -08004888 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4889 * will advertise it supports to the NVME layer. This also will map to
4890 * the number of WQs the driver will create.
4891 *
4892 * This module parameter is valid when lpfc_enable_fc4_type is set
4893 * to support NVME.
4894 *
4895 * The NVME Layer will try to create this many, plus 1 administrative
4896 * hardware queue. The administrative queue will always map to WQ 0
4897 * A hardware IO queue maps (qidx) to a specific driver WQ.
4898 *
4899 * 0 = Configure the number of io channels to the number of active CPUs.
4900 * 1,32 = Manually specify how many io channels to use.
4901 *
4902 * Value range is [0,32]. Default value is 0.
4903 */
4904LPFC_ATTR_R(nvme_io_channel,
4905 LPFC_NVME_IO_CHAN_DEF,
4906 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4907 "Set the number of NVME I/O channels");
4908
4909/*
James Smart13815c82008-01-11 01:52:48 -05004910# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4911# 0 = HBA resets disabled
4912# 1 = HBA resets enabled (default)
4913# Value range is [0,1]. Default value is 1.
4914*/
4915LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004916
James Smart13815c82008-01-11 01:52:48 -05004917/*
James Smarteb7a3392010-11-20 23:12:02 -05004918# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004919# 0 = HBA Heartbeat disabled
4920# 1 = HBA Heartbeat enabled (default)
4921# Value range is [0,1]. Default value is 1.
4922*/
James Smarteb7a3392010-11-20 23:12:02 -05004923LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004924
James Smart83108bd2008-01-11 01:53:09 -05004925/*
James Smart1ba981f2014-02-20 09:56:45 -05004926# lpfc_EnableXLane: Enable Express Lane Feature
4927# 0x0 Express Lane Feature disabled
4928# 0x1 Express Lane Feature enabled
4929# Value range is [0,1]. Default value is 0.
4930*/
4931LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4932
4933/*
4934# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4935# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4936# Value range is [0x0,0x7f]. Default value is 0
4937*/
James Smart28d7f3d2014-05-21 08:05:28 -04004938LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004939
4940/*
James Smart81301a92008-12-04 22:39:46 -05004941# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4942# 0 = BlockGuard disabled (default)
4943# 1 = BlockGuard enabled
4944# Value range is [0,1]. Default value is 0.
4945*/
4946LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4947
James Smart6fb120a2009-05-22 14:52:59 -04004948/*
James Smartba20c852012-08-03 12:36:52 -04004949# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4950# 0 = disabled (default)
4951# 1 = enabled
4952# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004953#
4954# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004955*/
4956unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4957
James Smartba20c852012-08-03 12:36:52 -04004958/*
James Smart81301a92008-12-04 22:39:46 -05004959# lpfc_prot_mask: i
4960# - Bit mask of host protection capabilities used to register with the
4961# SCSI mid-layer
4962# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
4963# - Allows you to ultimately specify which profiles to use
4964# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04004965# - SHOST_DIF_TYPE1_PROTECTION 1
4966# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
4967# - SHOST_DIX_TYPE0_PROTECTION 8
4968# HBA supports DIX Type 0: Host to HBA protection only
4969# - SHOST_DIX_TYPE1_PROTECTION 16
4970# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05004971#
4972*/
James Smartb3b98b72016-10-13 15:06:06 -07004973LPFC_ATTR(prot_mask,
4974 (SHOST_DIF_TYPE1_PROTECTION |
4975 SHOST_DIX_TYPE0_PROTECTION |
4976 SHOST_DIX_TYPE1_PROTECTION),
4977 0,
4978 (SHOST_DIF_TYPE1_PROTECTION |
4979 SHOST_DIX_TYPE0_PROTECTION |
4980 SHOST_DIX_TYPE1_PROTECTION),
4981 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05004982
4983/*
4984# lpfc_prot_guard: i
4985# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04004986# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05004987# - Allows you to ultimately specify which profiles to use
4988# - Default will result in registering capabilities for all guard types
4989#
4990*/
James Smartb3b98b72016-10-13 15:06:06 -07004991LPFC_ATTR(prot_guard,
4992 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
4993 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05004994
James Smart92494142011-02-16 12:39:44 -05004995/*
4996 * Delay initial NPort discovery when Clean Address bit is cleared in
4997 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
4998 * This parameter can have value 0 or 1.
4999 * When this parameter is set to 0, no delay is added to the initial
5000 * discovery.
5001 * When this parameter is set to non-zero value, initial Nport discovery is
5002 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5003 * accept and FCID/Fabric name/Fabric portname is changed.
5004 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5005 * when Clean Address bit is cleared in FLOGI/FDISC
5006 * accept and FCID/Fabric name/Fabric portname is changed.
5007 * Default value is 0.
5008 */
James Smart8eb8b962016-07-06 12:36:08 -07005009LPFC_ATTR(delay_discovery, 0, 0, 1,
5010 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005011
5012/*
James Smart3621a712009-04-06 18:47:14 -04005013 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005014 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005015 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5016 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005017 * Because of the additional overhead involved in setting up T10-DIF,
5018 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5019 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005020 */
5021LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5022 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5023
James Smart96f70772013-04-17 20:16:15 -04005024/*
James Smart7bdedb32016-07-06 12:36:00 -07005025 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5026 * 0 = MDS Diagnostics disabled (default)
5027 * 1 = MDS Diagnostics enabled
5028 * Value range is [0,1]. Default value is 0.
5029 */
5030LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5031
Tony Jonesee959b02008-02-22 00:13:36 +01005032struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005033 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005034 &dev_attr_bg_info,
5035 &dev_attr_bg_guard_err,
5036 &dev_attr_bg_apptag_err,
5037 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005038 &dev_attr_info,
5039 &dev_attr_serialnum,
5040 &dev_attr_modeldesc,
5041 &dev_attr_modelname,
5042 &dev_attr_programtype,
5043 &dev_attr_portnum,
5044 &dev_attr_fwrev,
5045 &dev_attr_hdw,
5046 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005047 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005048 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005049 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005050 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005051 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005052 &dev_attr_lpfc_temp_sensor,
5053 &dev_attr_lpfc_log_verbose,
5054 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005055 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005056 &dev_attr_lpfc_hba_queue_depth,
5057 &dev_attr_lpfc_peer_port_login,
5058 &dev_attr_lpfc_nodev_tmo,
5059 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005060 &dev_attr_lpfc_enable_fc4_type,
5061 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005062 &dev_attr_lpfc_fcp_class,
5063 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005064 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005065 &dev_attr_lpfc_ack0,
5066 &dev_attr_lpfc_topology,
5067 &dev_attr_lpfc_scan_down,
5068 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005069 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005070 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005071 &dev_attr_lpfc_cr_delay,
5072 &dev_attr_lpfc_cr_count,
5073 &dev_attr_lpfc_multi_ring_support,
5074 &dev_attr_lpfc_multi_ring_rctl,
5075 &dev_attr_lpfc_multi_ring_type,
5076 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005077 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005078 &dev_attr_lpfc_max_luns,
5079 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005080 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005081 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005082 &dev_attr_nport_evt_cnt,
5083 &dev_attr_board_mode,
5084 &dev_attr_max_vpi,
5085 &dev_attr_used_vpi,
5086 &dev_attr_max_rpi,
5087 &dev_attr_used_rpi,
5088 &dev_attr_max_xri,
5089 &dev_attr_used_xri,
5090 &dev_attr_npiv_info,
5091 &dev_attr_issue_reset,
5092 &dev_attr_lpfc_poll,
5093 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005094 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005095 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005096 &dev_attr_lpfc_nvme_oas,
James Smartda0436e2009-05-22 14:51:39 -04005097 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005098 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005099 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005100 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005101 &dev_attr_lpfc_nvme_io_channel,
5102 &dev_attr_lpfc_nvme_enable_fb,
James Smart81301a92008-12-04 22:39:46 -05005103 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005104 &dev_attr_lpfc_soft_wwnn,
5105 &dev_attr_lpfc_soft_wwpn,
5106 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005107 &dev_attr_lpfc_enable_hba_reset,
5108 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005109 &dev_attr_lpfc_EnableXLane,
5110 &dev_attr_lpfc_XLanePriority,
5111 &dev_attr_lpfc_xlane_lun,
5112 &dev_attr_lpfc_xlane_tgt,
5113 &dev_attr_lpfc_xlane_vpt,
5114 &dev_attr_lpfc_xlane_lun_state,
5115 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005116 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005117 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005118 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005119 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005120 &dev_attr_lpfc_aer_support,
5121 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005122 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005123 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005124 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005125 &dev_attr_lpfc_iocb_cnt,
5126 &dev_attr_iocb_hw,
5127 &dev_attr_txq_hw,
5128 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005129 &dev_attr_lpfc_fips_level,
5130 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005131 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005132 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005133 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005134 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005135 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05005136 NULL,
5137};
5138
Tony Jonesee959b02008-02-22 00:13:36 +01005139struct device_attribute *lpfc_vport_attrs[] = {
5140 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005141 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005142 &dev_attr_num_discovered_ports,
5143 &dev_attr_lpfc_drvr_version,
5144 &dev_attr_lpfc_log_verbose,
5145 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005146 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005147 &dev_attr_lpfc_nodev_tmo,
5148 &dev_attr_lpfc_devloss_tmo,
5149 &dev_attr_lpfc_hba_queue_depth,
5150 &dev_attr_lpfc_peer_port_login,
5151 &dev_attr_lpfc_restrict_login,
5152 &dev_attr_lpfc_fcp_class,
5153 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005154 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005155 &dev_attr_lpfc_max_luns,
5156 &dev_attr_nport_evt_cnt,
5157 &dev_attr_npiv_info,
5158 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005159 &dev_attr_lpfc_max_scsicmpl_time,
5160 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005161 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005162 &dev_attr_lpfc_fips_level,
5163 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005164 NULL,
5165};
5166
James Smarte59058c2008-08-24 21:49:00 -04005167/**
James Smart3621a712009-04-06 18:47:14 -04005168 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005169 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005170 * @kobj: kernel kobject that contains the kernel class device.
5171 * @bin_attr: kernel attributes passed to us.
5172 * @buf: contains the data to be written to the adapter IOREG space.
5173 * @off: offset into buffer to beginning of data.
5174 * @count: bytes to transfer.
5175 *
5176 * Description:
5177 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5178 * Uses the adapter io control registers to send buf contents to the adapter.
5179 *
5180 * Returns:
5181 * -ERANGE off and count combo out of range
5182 * -EINVAL off, count or buff address invalid
5183 * -EPERM adapter is offline
5184 * value of count, buf contents written
5185 **/
dea31012005-04-17 16:05:31 -05005186static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005187sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5188 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005189 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005190{
5191 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005192 struct device *dev = container_of(kobj, struct device, kobj);
5193 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005194 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5195 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005196
James Smartf1126682009-06-10 17:22:44 -04005197 if (phba->sli_rev >= LPFC_SLI_REV4)
5198 return -EPERM;
5199
dea31012005-04-17 16:05:31 -05005200 if ((off + count) > FF_REG_AREA_SIZE)
5201 return -ERANGE;
5202
James Smartf7a919b2011-08-21 21:49:16 -04005203 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5204 return 0;
dea31012005-04-17 16:05:31 -05005205
5206 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5207 return -EINVAL;
5208
James Smartf7a919b2011-08-21 21:49:16 -04005209 /* This is to protect HBA registers from accidental writes. */
5210 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5211 return -EINVAL;
5212
5213 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005214 return -EPERM;
dea31012005-04-17 16:05:31 -05005215
James Smart2e0fef82007-06-17 19:56:36 -05005216 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005217 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5218 buf_off += sizeof(uint32_t))
5219 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005220 phba->ctrl_regs_memmap_p + off + buf_off);
5221
James Smart2e0fef82007-06-17 19:56:36 -05005222 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005223
5224 return count;
5225}
5226
James Smarte59058c2008-08-24 21:49:00 -04005227/**
James Smart3621a712009-04-06 18:47:14 -04005228 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005229 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005230 * @kobj: kernel kobject that contains the kernel class device.
5231 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005232 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005233 * @off: offset into buffer to beginning of data.
5234 * @count: bytes to transfer.
5235 *
5236 * Description:
5237 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5238 * Uses the adapter io control registers to read data into buf.
5239 *
5240 * Returns:
5241 * -ERANGE off and count combo out of range
5242 * -EINVAL off, count or buff address invalid
5243 * value of count, buf contents read
5244 **/
dea31012005-04-17 16:05:31 -05005245static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005246sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5247 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005248 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005249{
5250 size_t buf_off;
5251 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005252 struct device *dev = container_of(kobj, struct device, kobj);
5253 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005254 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5255 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005256
James Smartf1126682009-06-10 17:22:44 -04005257 if (phba->sli_rev >= LPFC_SLI_REV4)
5258 return -EPERM;
5259
dea31012005-04-17 16:05:31 -05005260 if (off > FF_REG_AREA_SIZE)
5261 return -ERANGE;
5262
5263 if ((off + count) > FF_REG_AREA_SIZE)
5264 count = FF_REG_AREA_SIZE - off;
5265
5266 if (count == 0) return 0;
5267
5268 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5269 return -EINVAL;
5270
James Smart2e0fef82007-06-17 19:56:36 -05005271 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005272
5273 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5274 tmp_ptr = (uint32_t *)(buf + buf_off);
5275 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5276 }
5277
James Smart2e0fef82007-06-17 19:56:36 -05005278 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005279
5280 return count;
5281}
5282
5283static struct bin_attribute sysfs_ctlreg_attr = {
5284 .attr = {
5285 .name = "ctlreg",
5286 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005287 },
5288 .size = 256,
5289 .read = sysfs_ctlreg_read,
5290 .write = sysfs_ctlreg_write,
5291};
5292
James Smarte59058c2008-08-24 21:49:00 -04005293/**
James Smart3621a712009-04-06 18:47:14 -04005294 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005295 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005296 * @kobj: kernel kobject that contains the kernel class device.
5297 * @bin_attr: kernel attributes passed to us.
5298 * @buf: contains the data to be written to sysfs mbox.
5299 * @off: offset into buffer to beginning of data.
5300 * @count: bytes to transfer.
5301 *
5302 * Description:
James Smart026abb82011-12-13 13:20:45 -05005303 * Deprecated function. All mailbox access from user space is performed via the
5304 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005305 *
5306 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005307 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005308 **/
dea31012005-04-17 16:05:31 -05005309static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005310sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5311 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005312 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005313{
James Smart026abb82011-12-13 13:20:45 -05005314 return -EPERM;
dea31012005-04-17 16:05:31 -05005315}
5316
James Smarte59058c2008-08-24 21:49:00 -04005317/**
James Smart3621a712009-04-06 18:47:14 -04005318 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005319 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005320 * @kobj: kernel kobject that contains the kernel class device.
5321 * @bin_attr: kernel attributes passed to us.
5322 * @buf: contains the data to be read from sysfs mbox.
5323 * @off: offset into buffer to beginning of data.
5324 * @count: bytes to transfer.
5325 *
5326 * Description:
James Smart026abb82011-12-13 13:20:45 -05005327 * Deprecated function. All mailbox access from user space is performed via the
5328 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005329 *
5330 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005331 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005332 **/
dea31012005-04-17 16:05:31 -05005333static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005334sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5335 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005336 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005337{
James Smart026abb82011-12-13 13:20:45 -05005338 return -EPERM;
dea31012005-04-17 16:05:31 -05005339}
5340
5341static struct bin_attribute sysfs_mbox_attr = {
5342 .attr = {
5343 .name = "mbox",
5344 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005345 },
James Smartc0c11512011-05-24 11:41:34 -04005346 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005347 .read = sysfs_mbox_read,
5348 .write = sysfs_mbox_write,
5349};
5350
James Smarte59058c2008-08-24 21:49:00 -04005351/**
James Smart3621a712009-04-06 18:47:14 -04005352 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005353 * @vport: address of lpfc vport structure.
5354 *
5355 * Return codes:
5356 * zero on success
5357 * error return code from sysfs_create_bin_file()
5358 **/
dea31012005-04-17 16:05:31 -05005359int
James Smart2e0fef82007-06-17 19:56:36 -05005360lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005361{
James Smart2e0fef82007-06-17 19:56:36 -05005362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005363 int error;
5364
Tony Jonesee959b02008-02-22 00:13:36 +01005365 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005366 &sysfs_drvr_stat_data_attr);
5367
5368 /* Virtual ports do not need ctrl_reg and mbox */
5369 if (error || vport->port_type == LPFC_NPIV_PORT)
5370 goto out;
5371
5372 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005373 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005374 if (error)
James Smarteada2722008-12-04 22:39:13 -05005375 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005376
Tony Jonesee959b02008-02-22 00:13:36 +01005377 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005378 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005379 if (error)
5380 goto out_remove_ctlreg_attr;
5381
5382 return 0;
5383out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005384 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005385out_remove_stat_attr:
5386 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5387 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005388out:
5389 return error;
5390}
5391
James Smarte59058c2008-08-24 21:49:00 -04005392/**
James Smart3621a712009-04-06 18:47:14 -04005393 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005394 * @vport: address of lpfc vport structure.
5395 **/
dea31012005-04-17 16:05:31 -05005396void
James Smart2e0fef82007-06-17 19:56:36 -05005397lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005398{
James Smart2e0fef82007-06-17 19:56:36 -05005399 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005400 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5401 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005402 /* Virtual ports do not need ctrl_reg and mbox */
5403 if (vport->port_type == LPFC_NPIV_PORT)
5404 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005405 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5406 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005407}
5408
dea31012005-04-17 16:05:31 -05005409/*
5410 * Dynamic FC Host Attributes Support
5411 */
5412
James Smarte59058c2008-08-24 21:49:00 -04005413/**
James Smart6c9231f2016-12-19 15:07:24 -08005414 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5415 * @shost: kernel scsi host pointer.
5416 **/
5417static void
5418lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5419{
5420 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5421
5422 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5423 sizeof fc_host_symbolic_name(shost));
5424}
5425
5426/**
James Smart3621a712009-04-06 18:47:14 -04005427 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005428 * @shost: kernel scsi host pointer.
5429 **/
dea31012005-04-17 16:05:31 -05005430static void
5431lpfc_get_host_port_id(struct Scsi_Host *shost)
5432{
James Smart2e0fef82007-06-17 19:56:36 -05005433 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5434
dea31012005-04-17 16:05:31 -05005435 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005436 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005437}
5438
James Smarte59058c2008-08-24 21:49:00 -04005439/**
James Smart3621a712009-04-06 18:47:14 -04005440 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005441 * @shost: kernel scsi host pointer.
5442 **/
dea31012005-04-17 16:05:31 -05005443static void
5444lpfc_get_host_port_type(struct Scsi_Host *shost)
5445{
James Smart2e0fef82007-06-17 19:56:36 -05005446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5447 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005448
5449 spin_lock_irq(shost->host_lock);
5450
James Smart92d7f7b2007-06-17 19:56:38 -05005451 if (vport->port_type == LPFC_NPIV_PORT) {
5452 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5453 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005454 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005455 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005456 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5457 else
5458 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5459 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005460 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005461 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5462 else
5463 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5464 }
5465 } else
5466 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5467
5468 spin_unlock_irq(shost->host_lock);
5469}
5470
James Smarte59058c2008-08-24 21:49:00 -04005471/**
James Smart3621a712009-04-06 18:47:14 -04005472 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005473 * @shost: kernel scsi host pointer.
5474 **/
dea31012005-04-17 16:05:31 -05005475static void
5476lpfc_get_host_port_state(struct Scsi_Host *shost)
5477{
James Smart2e0fef82007-06-17 19:56:36 -05005478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5479 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005480
5481 spin_lock_irq(shost->host_lock);
5482
James Smart2e0fef82007-06-17 19:56:36 -05005483 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005484 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5485 else {
James Smart2e0fef82007-06-17 19:56:36 -05005486 switch (phba->link_state) {
5487 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005488 case LPFC_LINK_DOWN:
5489 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5490 break;
5491 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005492 case LPFC_CLEAR_LA:
5493 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005494 /* Links up, reports port state accordingly */
5495 if (vport->port_state < LPFC_VPORT_READY)
5496 fc_host_port_state(shost) =
5497 FC_PORTSTATE_BYPASSED;
5498 else
5499 fc_host_port_state(shost) =
5500 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005501 break;
5502 case LPFC_HBA_ERROR:
5503 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5504 break;
5505 default:
5506 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5507 break;
5508 }
5509 }
5510
5511 spin_unlock_irq(shost->host_lock);
5512}
5513
James Smarte59058c2008-08-24 21:49:00 -04005514/**
James Smart3621a712009-04-06 18:47:14 -04005515 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005516 * @shost: kernel scsi host pointer.
5517 **/
dea31012005-04-17 16:05:31 -05005518static void
5519lpfc_get_host_speed(struct Scsi_Host *shost)
5520{
James Smart2e0fef82007-06-17 19:56:36 -05005521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5522 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005523
5524 spin_lock_irq(shost->host_lock);
5525
James Smarta085e872015-12-16 18:12:02 -05005526 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005527 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005528 case LPFC_LINK_SPEED_1GHZ:
5529 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005530 break;
James Smart76a95d72010-11-20 23:11:48 -05005531 case LPFC_LINK_SPEED_2GHZ:
5532 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005533 break;
James Smart76a95d72010-11-20 23:11:48 -05005534 case LPFC_LINK_SPEED_4GHZ:
5535 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005536 break;
James Smart76a95d72010-11-20 23:11:48 -05005537 case LPFC_LINK_SPEED_8GHZ:
5538 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005539 break;
James Smart76a95d72010-11-20 23:11:48 -05005540 case LPFC_LINK_SPEED_10GHZ:
5541 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005542 break;
James Smart76a95d72010-11-20 23:11:48 -05005543 case LPFC_LINK_SPEED_16GHZ:
5544 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5545 break;
James Smartd38dd522015-08-31 16:48:17 -04005546 case LPFC_LINK_SPEED_32GHZ:
5547 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5548 break;
James Smart76a95d72010-11-20 23:11:48 -05005549 default:
5550 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005551 break;
5552 }
James Smart09372822008-01-11 01:52:54 -05005553 } else
5554 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005555
5556 spin_unlock_irq(shost->host_lock);
5557}
5558
James Smarte59058c2008-08-24 21:49:00 -04005559/**
James Smart3621a712009-04-06 18:47:14 -04005560 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005561 * @shost: kernel scsi host pointer.
5562 **/
dea31012005-04-17 16:05:31 -05005563static void
5564lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5565{
James Smart2e0fef82007-06-17 19:56:36 -05005566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5567 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005568 u64 node_name;
dea31012005-04-17 16:05:31 -05005569
5570 spin_lock_irq(shost->host_lock);
5571
James Smart73d91e52011-10-10 21:32:10 -04005572 if ((vport->port_state > LPFC_FLOGI) &&
5573 ((vport->fc_flag & FC_FABRIC) ||
5574 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5575 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005576 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005577 else
5578 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005579 node_name = 0;
dea31012005-04-17 16:05:31 -05005580
5581 spin_unlock_irq(shost->host_lock);
5582
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005583 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005584}
5585
James Smarte59058c2008-08-24 21:49:00 -04005586/**
James Smart3621a712009-04-06 18:47:14 -04005587 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005588 * @shost: kernel scsi host pointer.
5589 *
5590 * Notes:
5591 * NULL on error for link down, no mbox pool, sli2 active,
5592 * management not allowed, memory allocation error, or mbox error.
5593 *
5594 * Returns:
5595 * NULL for error
5596 * address of the adapter host statistics
5597 **/
dea31012005-04-17 16:05:31 -05005598static struct fc_host_statistics *
5599lpfc_get_stats(struct Scsi_Host *shost)
5600{
James Smart2e0fef82007-06-17 19:56:36 -05005601 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5602 struct lpfc_hba *phba = vport->phba;
5603 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005604 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005605 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005606 LPFC_MBOXQ_t *pmboxq;
5607 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005608 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005609 int rc = 0;
dea31012005-04-17 16:05:31 -05005610
James Smart92d7f7b2007-06-17 19:56:38 -05005611 /*
5612 * prevent udev from issuing mailbox commands until the port is
5613 * configured.
5614 */
James Smart2e0fef82007-06-17 19:56:36 -05005615 if (phba->link_state < LPFC_LINK_DOWN ||
5616 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005617 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005618 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005619
5620 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005621 return NULL;
5622
dea31012005-04-17 16:05:31 -05005623 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5624 if (!pmboxq)
5625 return NULL;
5626 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5627
James Smart04c68492009-05-22 14:52:52 -04005628 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005629 pmb->mbxCommand = MBX_READ_STATUS;
5630 pmb->mbxOwner = OWN_HOST;
5631 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005632 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005633
James Smart75baf692010-06-08 18:31:21 -04005634 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005635 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005636 else
dea31012005-04-17 16:05:31 -05005637 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5638
5639 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005640 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005641 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005642 return NULL;
5643 }
5644
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005645 memset(hs, 0, sizeof (struct fc_host_statistics));
5646
dea31012005-04-17 16:05:31 -05005647 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005648 /*
5649 * The MBX_READ_STATUS returns tx_k_bytes which has to
5650 * converted to words
5651 */
5652 hs->tx_words = (uint64_t)
5653 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5654 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005655 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005656 hs->rx_words = (uint64_t)
5657 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5658 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005659
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005660 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005661 pmb->mbxCommand = MBX_READ_LNK_STAT;
5662 pmb->mbxOwner = OWN_HOST;
5663 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005664 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005665
James Smart75baf692010-06-08 18:31:21 -04005666 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005667 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005668 else
dea31012005-04-17 16:05:31 -05005669 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5670
5671 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005672 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005673 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005674 return NULL;
5675 }
5676
5677 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5678 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5679 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5680 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5681 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5682 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5683 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5684
James Smart64ba8812006-08-02 15:24:34 -04005685 hs->link_failure_count -= lso->link_failure_count;
5686 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5687 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5688 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5689 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5690 hs->invalid_crc_count -= lso->invalid_crc_count;
5691 hs->error_frames -= lso->error_frames;
5692
James Smart76a95d72010-11-20 23:11:48 -05005693 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005694 hs->lip_count = -1;
5695 hs->nos_count = (phba->link_events >> 1);
5696 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005697 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005698 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005699 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005700 hs->nos_count = -1;
5701 } else {
5702 hs->lip_count = -1;
5703 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005704 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005705 }
5706
5707 hs->dumped_frames = -1;
5708
James Smart64ba8812006-08-02 15:24:34 -04005709 seconds = get_seconds();
5710 if (seconds < psli->stats_start)
5711 hs->seconds_since_last_reset = seconds +
5712 ((unsigned long)-1 - psli->stats_start);
5713 else
5714 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005715
James Smart1dcb58e2007-04-25 09:51:30 -04005716 mempool_free(pmboxq, phba->mbox_mem_pool);
5717
dea31012005-04-17 16:05:31 -05005718 return hs;
5719}
5720
James Smarte59058c2008-08-24 21:49:00 -04005721/**
James Smart3621a712009-04-06 18:47:14 -04005722 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005723 * @shost: kernel scsi host pointer.
5724 **/
James Smart64ba8812006-08-02 15:24:34 -04005725static void
5726lpfc_reset_stats(struct Scsi_Host *shost)
5727{
James Smart2e0fef82007-06-17 19:56:36 -05005728 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5729 struct lpfc_hba *phba = vport->phba;
5730 struct lpfc_sli *psli = &phba->sli;
5731 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005732 LPFC_MBOXQ_t *pmboxq;
5733 MAILBOX_t *pmb;
5734 int rc = 0;
5735
James Smart2e0fef82007-06-17 19:56:36 -05005736 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005737 return;
5738
James Smart64ba8812006-08-02 15:24:34 -04005739 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5740 if (!pmboxq)
5741 return;
5742 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5743
James Smart04c68492009-05-22 14:52:52 -04005744 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005745 pmb->mbxCommand = MBX_READ_STATUS;
5746 pmb->mbxOwner = OWN_HOST;
5747 pmb->un.varWords[0] = 0x1; /* reset request */
5748 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005749 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005750
James Smart2e0fef82007-06-17 19:56:36 -05005751 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005752 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005753 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5754 else
5755 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5756
5757 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005758 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005759 mempool_free(pmboxq, phba->mbox_mem_pool);
5760 return;
5761 }
5762
5763 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5764 pmb->mbxCommand = MBX_READ_LNK_STAT;
5765 pmb->mbxOwner = OWN_HOST;
5766 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005767 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005768
James Smart2e0fef82007-06-17 19:56:36 -05005769 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005770 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005771 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5772 else
5773 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5774
5775 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005776 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005777 mempool_free( pmboxq, phba->mbox_mem_pool);
5778 return;
5779 }
5780
5781 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5782 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5783 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5784 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5785 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5786 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5787 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005788 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005789 lso->link_events = (phba->link_events >> 1);
5790 else
5791 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005792
5793 psli->stats_start = get_seconds();
5794
James Smart1dcb58e2007-04-25 09:51:30 -04005795 mempool_free(pmboxq, phba->mbox_mem_pool);
5796
James Smart64ba8812006-08-02 15:24:34 -04005797 return;
5798}
dea31012005-04-17 16:05:31 -05005799
5800/*
5801 * The LPFC driver treats linkdown handling as target loss events so there
5802 * are no sysfs handlers for link_down_tmo.
5803 */
James Smart685f0bf2007-04-25 09:53:08 -04005804
James Smarte59058c2008-08-24 21:49:00 -04005805/**
James Smart3621a712009-04-06 18:47:14 -04005806 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005807 * @starget: kernel scsi target pointer.
5808 *
5809 * Returns:
5810 * address of the node list if found
5811 * NULL target not found
5812 **/
James Smart685f0bf2007-04-25 09:53:08 -04005813static struct lpfc_nodelist *
5814lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005815{
James Smart2e0fef82007-06-17 19:56:36 -05005816 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5817 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005818 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005819
5820 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005821 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005822 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005823 if (NLP_CHK_NODE_ACT(ndlp) &&
5824 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005825 starget->id == ndlp->nlp_sid) {
5826 spin_unlock_irq(shost->host_lock);
5827 return ndlp;
dea31012005-04-17 16:05:31 -05005828 }
5829 }
5830 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005831 return NULL;
5832}
dea31012005-04-17 16:05:31 -05005833
James Smarte59058c2008-08-24 21:49:00 -04005834/**
James Smart3621a712009-04-06 18:47:14 -04005835 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005836 * @starget: kernel scsi target pointer.
5837 **/
James Smart685f0bf2007-04-25 09:53:08 -04005838static void
5839lpfc_get_starget_port_id(struct scsi_target *starget)
5840{
5841 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5842
5843 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005844}
5845
James Smarte59058c2008-08-24 21:49:00 -04005846/**
James Smart3621a712009-04-06 18:47:14 -04005847 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005848 * @starget: kernel scsi target pointer.
5849 *
5850 * Description: Set the target node name to the ndlp node name wwn or zero.
5851 **/
dea31012005-04-17 16:05:31 -05005852static void
5853lpfc_get_starget_node_name(struct scsi_target *starget)
5854{
James Smart685f0bf2007-04-25 09:53:08 -04005855 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005856
James Smart685f0bf2007-04-25 09:53:08 -04005857 fc_starget_node_name(starget) =
5858 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005859}
5860
James Smarte59058c2008-08-24 21:49:00 -04005861/**
James Smart3621a712009-04-06 18:47:14 -04005862 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005863 * @starget: kernel scsi target pointer.
5864 *
5865 * Description: set the target port name to the ndlp port name wwn or zero.
5866 **/
dea31012005-04-17 16:05:31 -05005867static void
5868lpfc_get_starget_port_name(struct scsi_target *starget)
5869{
James Smart685f0bf2007-04-25 09:53:08 -04005870 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005871
James Smart685f0bf2007-04-25 09:53:08 -04005872 fc_starget_port_name(starget) =
5873 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005874}
5875
James Smarte59058c2008-08-24 21:49:00 -04005876/**
James Smart3621a712009-04-06 18:47:14 -04005877 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005878 * @rport: fc rport address.
5879 * @timeout: new value for dev loss tmo.
5880 *
5881 * Description:
5882 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5883 * dev_loss_tmo to one.
5884 **/
dea31012005-04-17 16:05:31 -05005885static void
dea31012005-04-17 16:05:31 -05005886lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5887{
dea31012005-04-17 16:05:31 -05005888 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005889 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005890 else
James Smartc01f3202006-08-18 17:47:08 -04005891 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005892}
5893
James Smarte59058c2008-08-24 21:49:00 -04005894/**
James Smart3621a712009-04-06 18:47:14 -04005895 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005896 *
5897 * Description:
5898 * Macro that uses field to generate a function with the name lpfc_show_rport_
5899 *
5900 * lpfc_show_rport_##field: returns the bytes formatted in buf
5901 * @cdev: class converted to an fc_rport.
5902 * @buf: on return contains the target_field or zero.
5903 *
5904 * Returns: size of formatted string.
5905 **/
dea31012005-04-17 16:05:31 -05005906#define lpfc_rport_show_function(field, format_string, sz, cast) \
5907static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005908lpfc_show_rport_##field (struct device *dev, \
5909 struct device_attribute *attr, \
5910 char *buf) \
dea31012005-04-17 16:05:31 -05005911{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005912 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005913 struct lpfc_rport_data *rdata = rport->hostdata; \
5914 return snprintf(buf, sz, format_string, \
5915 (rdata->target) ? cast rdata->target->field : 0); \
5916}
5917
5918#define lpfc_rport_rd_attr(field, format_string, sz) \
5919 lpfc_rport_show_function(field, format_string, sz, ) \
5920static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5921
James Smarteada2722008-12-04 22:39:13 -05005922/**
James Smart3621a712009-04-06 18:47:14 -04005923 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005924 * @fc_vport: The fc_vport who's symbolic name has been changed.
5925 *
5926 * Description:
5927 * This function is called by the transport after the @fc_vport's symbolic name
5928 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005929 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005930 **/
5931static void
5932lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5933{
5934 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5935
5936 if (vport->port_state == LPFC_VPORT_READY)
5937 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5938}
dea31012005-04-17 16:05:31 -05005939
James Smartf4b4c682009-05-22 14:53:12 -04005940/**
5941 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5942 * @phba: Pointer to lpfc_hba struct.
5943 *
5944 * This function is called by the lpfc_get_cfgparam() routine to set the
5945 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005946 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005947 * before hba port or vport created.
5948 **/
5949static void
5950lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5951{
5952 phba->cfg_log_verbose = verbose;
5953}
5954
dea31012005-04-17 16:05:31 -05005955struct fc_function_template lpfc_transport_functions = {
5956 /* fixed attributes the driver supports */
5957 .show_host_node_name = 1,
5958 .show_host_port_name = 1,
5959 .show_host_supported_classes = 1,
5960 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05005961 .show_host_supported_speeds = 1,
5962 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08005963
5964 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05005965 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05005966
5967 /* dynamic attributes the driver supports */
5968 .get_host_port_id = lpfc_get_host_port_id,
5969 .show_host_port_id = 1,
5970
5971 .get_host_port_type = lpfc_get_host_port_type,
5972 .show_host_port_type = 1,
5973
5974 .get_host_port_state = lpfc_get_host_port_state,
5975 .show_host_port_state = 1,
5976
5977 /* active_fc4s is shown but doesn't change (thus no get function) */
5978 .show_host_active_fc4s = 1,
5979
5980 .get_host_speed = lpfc_get_host_speed,
5981 .show_host_speed = 1,
5982
5983 .get_host_fabric_name = lpfc_get_host_fabric_name,
5984 .show_host_fabric_name = 1,
5985
5986 /*
5987 * The LPFC driver treats linkdown handling as target loss events
5988 * so there are no sysfs handlers for link_down_tmo.
5989 */
5990
5991 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04005992 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05005993
5994 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
5995 .show_rport_maxframe_size = 1,
5996 .show_rport_supported_classes = 1,
5997
dea31012005-04-17 16:05:31 -05005998 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
5999 .show_rport_dev_loss_tmo = 1,
6000
6001 .get_starget_port_id = lpfc_get_starget_port_id,
6002 .show_starget_port_id = 1,
6003
6004 .get_starget_node_name = lpfc_get_starget_node_name,
6005 .show_starget_node_name = 1,
6006
6007 .get_starget_port_name = lpfc_get_starget_port_name,
6008 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006009
6010 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006011 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6012 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006013
James Smart92d7f7b2007-06-17 19:56:38 -05006014 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006015
6016 .vport_disable = lpfc_vport_disable,
6017
6018 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006019
6020 .bsg_request = lpfc_bsg_request,
6021 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006022};
6023
James Smart98c9ea52007-10-27 13:37:33 -04006024struct fc_function_template lpfc_vport_transport_functions = {
6025 /* fixed attributes the driver supports */
6026 .show_host_node_name = 1,
6027 .show_host_port_name = 1,
6028 .show_host_supported_classes = 1,
6029 .show_host_supported_fc4s = 1,
6030 .show_host_supported_speeds = 1,
6031 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006032
6033 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006034 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006035
6036 /* dynamic attributes the driver supports */
6037 .get_host_port_id = lpfc_get_host_port_id,
6038 .show_host_port_id = 1,
6039
6040 .get_host_port_type = lpfc_get_host_port_type,
6041 .show_host_port_type = 1,
6042
6043 .get_host_port_state = lpfc_get_host_port_state,
6044 .show_host_port_state = 1,
6045
6046 /* active_fc4s is shown but doesn't change (thus no get function) */
6047 .show_host_active_fc4s = 1,
6048
6049 .get_host_speed = lpfc_get_host_speed,
6050 .show_host_speed = 1,
6051
6052 .get_host_fabric_name = lpfc_get_host_fabric_name,
6053 .show_host_fabric_name = 1,
6054
6055 /*
6056 * The LPFC driver treats linkdown handling as target loss events
6057 * so there are no sysfs handlers for link_down_tmo.
6058 */
6059
6060 .get_fc_host_stats = lpfc_get_stats,
6061 .reset_fc_host_stats = lpfc_reset_stats,
6062
6063 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6064 .show_rport_maxframe_size = 1,
6065 .show_rport_supported_classes = 1,
6066
6067 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6068 .show_rport_dev_loss_tmo = 1,
6069
6070 .get_starget_port_id = lpfc_get_starget_port_id,
6071 .show_starget_port_id = 1,
6072
6073 .get_starget_node_name = lpfc_get_starget_node_name,
6074 .show_starget_node_name = 1,
6075
6076 .get_starget_port_name = lpfc_get_starget_port_name,
6077 .show_starget_port_name = 1,
6078
6079 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6080 .terminate_rport_io = lpfc_terminate_rport_io,
6081
6082 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006083
6084 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006085};
6086
James Smarte59058c2008-08-24 21:49:00 -04006087/**
James Smart3621a712009-04-06 18:47:14 -04006088 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006089 * @phba: lpfc_hba pointer.
6090 **/
dea31012005-04-17 16:05:31 -05006091void
6092lpfc_get_cfgparam(struct lpfc_hba *phba)
6093{
James Smart49aa1432012-08-03 12:36:42 -04006094 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006095 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006096 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6097 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006098 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006099 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6100 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006101 lpfc_ack0_init(phba, lpfc_ack0);
6102 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006103 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006104 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006105 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006106 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006107 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006108 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006109 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6110 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006111 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006112 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smartda0436e2009-05-22 14:51:39 -04006113 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006114 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006115 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6116 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006117
James Smart1ba981f2014-02-20 09:56:45 -05006118 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6119 if (phba->sli_rev != LPFC_SLI_REV4)
6120 phba->cfg_EnableXLane = 0;
6121 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006122
James Smart1ba981f2014-02-20 09:56:45 -05006123 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6124 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6125 phba->cfg_oas_lun_state = 0;
6126 phba->cfg_oas_lun_status = 0;
6127 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006128 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006129 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006130 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6131 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006132 if (phba->sli_rev == LPFC_SLI_REV4)
6133 phba->cfg_poll = 0;
6134 else
James Smart1ba981f2014-02-20 09:56:45 -05006135 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006136 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006137
James Smart895427b2017-02-12 13:52:30 -08006138 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6139
6140 /* Initialize first burst. Target vs Initiator are different. */
6141 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6142 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6143 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6144
6145 if (phba->sli_rev != LPFC_SLI_REV4) {
6146 /* NVME only supported on SLI4 */
6147 phba->nvmet_support = 0;
6148 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6149 } else {
6150 /* We MUST have FCP support */
6151 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6152 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6153 }
6154
6155 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006156 if (phba->cfg_fcp_io_channel == 0)
6157 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006158 if (phba->cfg_nvme_io_channel == 0)
6159 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006160
6161 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6162 phba->cfg_fcp_io_channel = 0;
6163
James Smartf358dd02017-02-12 13:52:34 -08006164 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6165 phba->cfg_nvme_io_channel = 0;
6166
James Smart895427b2017-02-12 13:52:30 -08006167 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6168 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6169 else
6170 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6171
James Smart352e5fd2016-12-30 06:57:47 -08006172 phba->cfg_soft_wwnn = 0L;
6173 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006174 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006175 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006176 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006177 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006178 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006179 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006180 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006181 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006182 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006183 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006184 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006185 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006186 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006187 return;
6188}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006189
James Smarte59058c2008-08-24 21:49:00 -04006190/**
James Smart895427b2017-02-12 13:52:30 -08006191 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6192 * dependencies between protocols and roles.
6193 * @phba: lpfc_hba pointer.
6194 **/
6195void
6196lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6197{
James Smart895427b2017-02-12 13:52:30 -08006198 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6199 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006200
James Smart895427b2017-02-12 13:52:30 -08006201 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6202 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6203
James Smartf358dd02017-02-12 13:52:34 -08006204 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6205 phba->nvmet_support) {
6206 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6207 phba->cfg_fcp_io_channel = 0;
6208 } else
6209 /* Not NVME Target mode. Turn off Target parameters. */
6210 phba->nvmet_support = 0;
6211
James Smart895427b2017-02-12 13:52:30 -08006212 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6213 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6214 else
6215 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6216}
6217
6218/**
James Smart3621a712009-04-06 18:47:14 -04006219 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006220 * @vport: lpfc_vport pointer.
6221 **/
James Smart3de2a652007-08-02 11:09:59 -04006222void
6223lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6224{
James Smarte8b62012007-08-02 11:10:09 -04006225 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006226 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006227 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006228 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6229 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6230 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6231 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6232 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6233 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006234 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006235 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006236 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6237 lpfc_max_luns_init(vport, lpfc_max_luns);
6238 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006239 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006240 return;
6241}