blob: 700a68f303f3774f65f36490e419fad1458f022a [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 Smart2d7dbc42017-02-12 13:52:35 -080061#define LPFC_DEF_MRQ_POST 256
62#define LPFC_MIN_MRQ_POST 32
63#define LPFC_MAX_MRQ_POST 512
64
James Smartf7a919b2011-08-21 21:49:16 -040065/*
66 * Write key size should be multiple of 4. If write key is changed
67 * make sure that library write key is also changed.
68 */
69#define LPFC_REG_WRITE_KEY_SIZE 4
70#define LPFC_REG_WRITE_KEY "EMLX"
71
James Smarte59058c2008-08-24 21:49:00 -040072/**
James Smart3621a712009-04-06 18:47:14 -040073 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
James Smarte59058c2008-08-24 21:49:00 -040074 * @incr: integer to convert.
75 * @hdw: ascii string holding converted integer plus a string terminator.
76 *
77 * Description:
78 * JEDEC Joint Electron Device Engineering Council.
79 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
80 * character string. The string is then terminated with a NULL in byte 9.
81 * Hex 0-9 becomes ascii '0' to '9'.
82 * Hex a-f becomes ascii '=' to 'B' capital B.
83 *
84 * Notes:
85 * Coded for 32 bit integers only.
86 **/
dea31012005-04-17 16:05:31 -050087static void
88lpfc_jedec_to_ascii(int incr, char hdw[])
89{
90 int i, j;
91 for (i = 0; i < 8; i++) {
92 j = (incr & 0xf);
93 if (j <= 9)
94 hdw[7 - i] = 0x30 + j;
95 else
96 hdw[7 - i] = 0x61 + j - 10;
97 incr = (incr >> 4);
98 }
99 hdw[8] = 0;
100 return;
101}
102
James Smarte59058c2008-08-24 21:49:00 -0400103/**
James Smart3621a712009-04-06 18:47:14 -0400104 * lpfc_drvr_version_show - Return the Emulex driver string with version number
James Smarte59058c2008-08-24 21:49:00 -0400105 * @dev: class unused variable.
106 * @attr: device attribute, not used.
107 * @buf: on return contains the module description text.
108 *
109 * Returns: size of formatted string.
110 **/
dea31012005-04-17 16:05:31 -0500111static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100112lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
113 char *buf)
dea31012005-04-17 16:05:31 -0500114{
115 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
116}
117
James Smart45ed1192009-10-02 15:17:02 -0400118/**
119 * lpfc_enable_fip_show - Return the fip mode of the HBA
120 * @dev: class unused variable.
121 * @attr: device attribute, not used.
122 * @buf: on return contains the module description text.
123 *
124 * Returns: size of formatted string.
125 **/
126static ssize_t
127lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
128 char *buf)
129{
130 struct Scsi_Host *shost = class_to_shost(dev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
133
134 if (phba->hba_flag & HBA_FIP_SUPPORT)
135 return snprintf(buf, PAGE_SIZE, "1\n");
136 else
137 return snprintf(buf, PAGE_SIZE, "0\n");
138}
139
James Smart81301a92008-12-04 22:39:46 -0500140static ssize_t
James Smart895427b2017-02-12 13:52:30 -0800141lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
142 char *buf)
143{
144 struct Scsi_Host *shost = class_to_shost(dev);
145 struct lpfc_vport *vport = shost_priv(shost);
146 struct lpfc_hba *phba = vport->phba;
James Smartf358dd02017-02-12 13:52:34 -0800147 struct lpfc_nvmet_tgtport *tgtp;
James Smart895427b2017-02-12 13:52:30 -0800148 struct nvme_fc_local_port *localport;
149 struct lpfc_nvme_lport *lport;
150 struct lpfc_nvme_rport *rport;
151 struct nvme_fc_remote_port *nrport;
152 char *statep;
153 int len = 0;
154
155 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
156 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
157 return len;
158 }
James Smartf358dd02017-02-12 13:52:34 -0800159 if (phba->nvmet_support) {
160 if (!phba->targetport) {
161 len = snprintf(buf, PAGE_SIZE,
162 "NVME Target: x%llx is not allocated\n",
163 wwn_to_u64(vport->fc_portname.u.wwn));
164 return len;
165 }
166 /* Port state is only one of two values for now. */
167 if (phba->targetport->port_id)
168 statep = "REGISTERED";
169 else
170 statep = "INIT";
171 len += snprintf(buf + len, PAGE_SIZE - len,
172 "NVME Target: Enabled State %s\n",
173 statep);
174 len += snprintf(buf + len, PAGE_SIZE - len,
175 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
176 "NVME Target: lpfc",
177 phba->brd_no,
178 wwn_to_u64(vport->fc_portname.u.wwn),
179 wwn_to_u64(vport->fc_nodename.u.wwn),
180 phba->targetport->port_id);
181
182 len += snprintf(buf + len, PAGE_SIZE,
183 "\nNVME Target: Statistics\n");
184 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
185 len += snprintf(buf+len, PAGE_SIZE-len,
186 "LS: Rcv %08x Drop %08x Abort %08x\n",
187 atomic_read(&tgtp->rcv_ls_req_in),
188 atomic_read(&tgtp->rcv_ls_req_drop),
189 atomic_read(&tgtp->xmt_ls_abort));
190 if (atomic_read(&tgtp->rcv_ls_req_in) !=
191 atomic_read(&tgtp->rcv_ls_req_out)) {
192 len += snprintf(buf+len, PAGE_SIZE-len,
193 "Rcv LS: in %08x != out %08x\n",
194 atomic_read(&tgtp->rcv_ls_req_in),
195 atomic_read(&tgtp->rcv_ls_req_out));
196 }
197
198 len += snprintf(buf+len, PAGE_SIZE-len,
199 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
200 atomic_read(&tgtp->xmt_ls_rsp),
201 atomic_read(&tgtp->xmt_ls_drop),
202 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
203 atomic_read(&tgtp->xmt_ls_rsp_error));
204
205 len += snprintf(buf+len, PAGE_SIZE-len,
206 "FCP: Rcv %08x Drop %08x\n",
207 atomic_read(&tgtp->rcv_fcp_cmd_in),
208 atomic_read(&tgtp->rcv_fcp_cmd_drop));
209
210 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
211 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
212 len += snprintf(buf+len, PAGE_SIZE-len,
213 "Rcv FCP: in %08x != out %08x\n",
214 atomic_read(&tgtp->rcv_fcp_cmd_in),
215 atomic_read(&tgtp->rcv_fcp_cmd_out));
216 }
217
218 len += snprintf(buf+len, PAGE_SIZE-len,
219 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x\n",
220 atomic_read(&tgtp->xmt_fcp_read),
221 atomic_read(&tgtp->xmt_fcp_read_rsp),
222 atomic_read(&tgtp->xmt_fcp_write),
223 atomic_read(&tgtp->xmt_fcp_rsp));
224
225 len += snprintf(buf+len, PAGE_SIZE-len,
226 "FCP Rsp: abort %08x drop %08x\n",
227 atomic_read(&tgtp->xmt_fcp_abort),
228 atomic_read(&tgtp->xmt_fcp_drop));
229
230 len += snprintf(buf+len, PAGE_SIZE-len,
231 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
232 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
233 atomic_read(&tgtp->xmt_fcp_rsp_error),
234 atomic_read(&tgtp->xmt_fcp_rsp_drop));
235
236 len += snprintf(buf+len, PAGE_SIZE-len,
237 "ABORT: Xmt %08x Err %08x Cmpl %08x",
238 atomic_read(&tgtp->xmt_abort_rsp),
239 atomic_read(&tgtp->xmt_abort_rsp_error),
240 atomic_read(&tgtp->xmt_abort_cmpl));
241
242 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
243 return len;
244 }
James Smart895427b2017-02-12 13:52:30 -0800245
246 localport = vport->localport;
247 if (!localport) {
248 len = snprintf(buf, PAGE_SIZE,
249 "NVME Initiator x%llx is not allocated\n",
250 wwn_to_u64(vport->fc_portname.u.wwn));
251 return len;
252 }
253 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
254
255 spin_lock_irq(shost->host_lock);
256 lport = (struct lpfc_nvme_lport *)localport->private;
257
258 /* Port state is only one of two values for now. */
259 if (localport->port_id)
260 statep = "ONLINE";
261 else
262 statep = "UNKNOWN ";
263
264 len += snprintf(buf + len, PAGE_SIZE - len,
265 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
266 "NVME LPORT lpfc",
267 phba->brd_no,
268 wwn_to_u64(vport->fc_portname.u.wwn),
269 wwn_to_u64(vport->fc_nodename.u.wwn),
270 localport->port_id, statep);
271
272 list_for_each_entry(rport, &lport->rport_list, list) {
273 /* local short-hand pointer. */
274 nrport = rport->remoteport;
275
276 /* Port state is only one of two values for now. */
277 switch (nrport->port_state) {
278 case FC_OBJSTATE_ONLINE:
279 statep = "ONLINE";
280 break;
281 case FC_OBJSTATE_UNKNOWN:
282 statep = "UNKNOWN ";
283 break;
284 default:
285 statep = "UNSUPPORTED";
286 break;
287 }
288
289 /* Tab in to show lport ownership. */
290 len += snprintf(buf + len, PAGE_SIZE - len,
291 "NVME RPORT ");
292 if (phba->brd_no >= 10)
293 len += snprintf(buf + len, PAGE_SIZE - len, " ");
294
295 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
296 nrport->port_name);
297 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
298 nrport->node_name);
299 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
300 nrport->port_id);
301
302 switch (nrport->port_role) {
303 case FC_PORT_ROLE_NVME_INITIATOR:
304 len += snprintf(buf + len, PAGE_SIZE - len,
305 "INITIATOR ");
306 break;
307 case FC_PORT_ROLE_NVME_TARGET:
308 len += snprintf(buf + len, PAGE_SIZE - len,
309 "TARGET ");
310 break;
311 case FC_PORT_ROLE_NVME_DISCOVERY:
312 len += snprintf(buf + len, PAGE_SIZE - len,
313 "DISCOVERY ");
314 break;
315 default:
316 len += snprintf(buf + len, PAGE_SIZE - len,
317 "UNKNOWN_ROLE x%x",
318 nrport->port_role);
319 break;
320 }
321 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
322 /* Terminate the string. */
323 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
324 }
325 spin_unlock_irq(shost->host_lock);
326
327 len += snprintf(buf + len, PAGE_SIZE, "\nNVME Statistics\n");
328 len += snprintf(buf+len, PAGE_SIZE-len,
329 "LS: Xmt %016llx Cmpl %016llx\n",
330 phba->fc4NvmeLsRequests,
331 phba->fc4NvmeLsCmpls);
332
333 len += snprintf(buf+len, PAGE_SIZE-len,
334 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
335 phba->fc4NvmeInputRequests,
336 phba->fc4NvmeOutputRequests,
337 phba->fc4NvmeControlRequests);
338
339 len += snprintf(buf+len, PAGE_SIZE-len,
340 " Cmpl %016llx\n", phba->fc4NvmeIoCmpls);
341
342 return len;
343}
344
345static ssize_t
James Smart81301a92008-12-04 22:39:46 -0500346lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
347 char *buf)
348{
349 struct Scsi_Host *shost = class_to_shost(dev);
350 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
351 struct lpfc_hba *phba = vport->phba;
352
353 if (phba->cfg_enable_bg)
354 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
355 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
356 else
357 return snprintf(buf, PAGE_SIZE,
358 "BlockGuard Not Supported\n");
359 else
360 return snprintf(buf, PAGE_SIZE,
361 "BlockGuard Disabled\n");
362}
363
364static ssize_t
365lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
366 char *buf)
367{
368 struct Scsi_Host *shost = class_to_shost(dev);
369 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
370 struct lpfc_hba *phba = vport->phba;
371
James Smart87b5c322008-12-16 10:34:09 -0500372 return snprintf(buf, PAGE_SIZE, "%llu\n",
373 (unsigned long long)phba->bg_guard_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500374}
375
376static ssize_t
377lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
378 char *buf)
379{
380 struct Scsi_Host *shost = class_to_shost(dev);
381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
382 struct lpfc_hba *phba = vport->phba;
383
James Smart87b5c322008-12-16 10:34:09 -0500384 return snprintf(buf, PAGE_SIZE, "%llu\n",
385 (unsigned long long)phba->bg_apptag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500386}
387
388static ssize_t
389lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
390 char *buf)
391{
392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
395
James Smart87b5c322008-12-16 10:34:09 -0500396 return snprintf(buf, PAGE_SIZE, "%llu\n",
397 (unsigned long long)phba->bg_reftag_err_cnt);
James Smart81301a92008-12-04 22:39:46 -0500398}
399
James Smarte59058c2008-08-24 21:49:00 -0400400/**
James Smart3621a712009-04-06 18:47:14 -0400401 * lpfc_info_show - Return some pci info about the host in ascii
James Smarte59058c2008-08-24 21:49:00 -0400402 * @dev: class converted to a Scsi_host structure.
403 * @attr: device attribute, not used.
404 * @buf: on return contains the formatted text from lpfc_info().
405 *
406 * Returns: size of formatted string.
407 **/
dea31012005-04-17 16:05:31 -0500408static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100409lpfc_info_show(struct device *dev, struct device_attribute *attr,
410 char *buf)
dea31012005-04-17 16:05:31 -0500411{
Tony Jonesee959b02008-02-22 00:13:36 +0100412 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500413
dea31012005-04-17 16:05:31 -0500414 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
415}
416
James Smarte59058c2008-08-24 21:49:00 -0400417/**
James Smart3621a712009-04-06 18:47:14 -0400418 * lpfc_serialnum_show - Return the hba serial number in ascii
James Smarte59058c2008-08-24 21:49:00 -0400419 * @dev: class converted to a Scsi_host structure.
420 * @attr: device attribute, not used.
421 * @buf: on return contains the formatted text serial number.
422 *
423 * Returns: size of formatted string.
424 **/
dea31012005-04-17 16:05:31 -0500425static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100426lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
427 char *buf)
dea31012005-04-17 16:05:31 -0500428{
Tony Jonesee959b02008-02-22 00:13:36 +0100429 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500430 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
431 struct lpfc_hba *phba = vport->phba;
432
dea31012005-04-17 16:05:31 -0500433 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
434}
435
James Smarte59058c2008-08-24 21:49:00 -0400436/**
James Smart3621a712009-04-06 18:47:14 -0400437 * lpfc_temp_sensor_show - Return the temperature sensor level
James Smarte59058c2008-08-24 21:49:00 -0400438 * @dev: class converted to a Scsi_host structure.
439 * @attr: device attribute, not used.
440 * @buf: on return contains the formatted support level.
441 *
442 * Description:
443 * Returns a number indicating the temperature sensor level currently
444 * supported, zero or one in ascii.
445 *
446 * Returns: size of formatted string.
447 **/
dea31012005-04-17 16:05:31 -0500448static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100449lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
450 char *buf)
James Smart57127f12007-10-27 13:37:05 -0400451{
Tony Jonesee959b02008-02-22 00:13:36 +0100452 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400453 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
454 struct lpfc_hba *phba = vport->phba;
455 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
456}
457
James Smarte59058c2008-08-24 21:49:00 -0400458/**
James Smart3621a712009-04-06 18:47:14 -0400459 * lpfc_modeldesc_show - Return the model description of the hba
James Smarte59058c2008-08-24 21:49:00 -0400460 * @dev: class converted to a Scsi_host structure.
461 * @attr: device attribute, not used.
462 * @buf: on return contains the scsi vpd model description.
463 *
464 * Returns: size of formatted string.
465 **/
James Smart57127f12007-10-27 13:37:05 -0400466static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100467lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
468 char *buf)
dea31012005-04-17 16:05:31 -0500469{
Tony Jonesee959b02008-02-22 00:13:36 +0100470 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500471 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
472 struct lpfc_hba *phba = vport->phba;
473
dea31012005-04-17 16:05:31 -0500474 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
475}
476
James Smarte59058c2008-08-24 21:49:00 -0400477/**
James Smart3621a712009-04-06 18:47:14 -0400478 * lpfc_modelname_show - Return the model name of the hba
James Smarte59058c2008-08-24 21:49:00 -0400479 * @dev: class converted to a Scsi_host structure.
480 * @attr: device attribute, not used.
481 * @buf: on return contains the scsi vpd model name.
482 *
483 * Returns: size of formatted string.
484 **/
dea31012005-04-17 16:05:31 -0500485static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100486lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
487 char *buf)
dea31012005-04-17 16:05:31 -0500488{
Tony Jonesee959b02008-02-22 00:13:36 +0100489 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500490 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
491 struct lpfc_hba *phba = vport->phba;
492
dea31012005-04-17 16:05:31 -0500493 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
494}
495
James Smarte59058c2008-08-24 21:49:00 -0400496/**
James Smart3621a712009-04-06 18:47:14 -0400497 * lpfc_programtype_show - Return the program type of the hba
James Smarte59058c2008-08-24 21:49:00 -0400498 * @dev: class converted to a Scsi_host structure.
499 * @attr: device attribute, not used.
500 * @buf: on return contains the scsi vpd program type.
501 *
502 * Returns: size of formatted string.
503 **/
dea31012005-04-17 16:05:31 -0500504static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100505lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
506 char *buf)
dea31012005-04-17 16:05:31 -0500507{
Tony Jonesee959b02008-02-22 00:13:36 +0100508 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500509 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
510 struct lpfc_hba *phba = vport->phba;
511
dea31012005-04-17 16:05:31 -0500512 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
513}
514
James Smarte59058c2008-08-24 21:49:00 -0400515/**
James Smart3621a712009-04-06 18:47:14 -0400516 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
James Smart84774a42008-08-24 21:50:06 -0400517 * @dev: class converted to a Scsi_host structure.
518 * @attr: device attribute, not used.
519 * @buf: on return contains the Menlo Maintenance sli flag.
520 *
521 * Returns: size of formatted string.
522 **/
523static ssize_t
524lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
525{
526 struct Scsi_Host *shost = class_to_shost(dev);
527 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
528 struct lpfc_hba *phba = vport->phba;
529
530 return snprintf(buf, PAGE_SIZE, "%d\n",
531 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
532}
533
534/**
James Smart3621a712009-04-06 18:47:14 -0400535 * lpfc_vportnum_show - Return the port number in ascii of the hba
James Smarte59058c2008-08-24 21:49:00 -0400536 * @dev: class converted to a Scsi_host structure.
537 * @attr: device attribute, not used.
538 * @buf: on return contains scsi vpd program type.
539 *
540 * Returns: size of formatted string.
541 **/
dea31012005-04-17 16:05:31 -0500542static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100543lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
544 char *buf)
dea31012005-04-17 16:05:31 -0500545{
Tony Jonesee959b02008-02-22 00:13:36 +0100546 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
548 struct lpfc_hba *phba = vport->phba;
549
dea31012005-04-17 16:05:31 -0500550 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
551}
552
James Smarte59058c2008-08-24 21:49:00 -0400553/**
James Smart3621a712009-04-06 18:47:14 -0400554 * lpfc_fwrev_show - Return the firmware rev running in the hba
James Smarte59058c2008-08-24 21:49:00 -0400555 * @dev: class converted to a Scsi_host structure.
556 * @attr: device attribute, not used.
557 * @buf: on return contains the scsi vpd program type.
558 *
559 * Returns: size of formatted string.
560 **/
dea31012005-04-17 16:05:31 -0500561static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100562lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
563 char *buf)
dea31012005-04-17 16:05:31 -0500564{
Tony Jonesee959b02008-02-22 00:13:36 +0100565 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
567 struct lpfc_hba *phba = vport->phba;
James Smart026abb82011-12-13 13:20:45 -0500568 uint32_t if_type;
569 uint8_t sli_family;
James Smart6b5151f2012-01-18 16:24:06 -0500570 char fwrev[FW_REV_STR_SIZE];
James Smart026abb82011-12-13 13:20:45 -0500571 int len;
James Smart2e0fef82007-06-17 19:56:36 -0500572
dea31012005-04-17 16:05:31 -0500573 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart026abb82011-12-13 13:20:45 -0500574 if_type = phba->sli4_hba.pc_sli4_params.if_type;
575 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
576
577 if (phba->sli_rev < LPFC_SLI_REV4)
578 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
579 fwrev, phba->sli_rev);
580 else
581 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
582 fwrev, phba->sli_rev, if_type, sli_family);
583
584 return len;
dea31012005-04-17 16:05:31 -0500585}
586
James Smarte59058c2008-08-24 21:49:00 -0400587/**
James Smart3621a712009-04-06 18:47:14 -0400588 * lpfc_hdw_show - Return the jedec information about the hba
James Smarte59058c2008-08-24 21:49:00 -0400589 * @dev: class converted to a Scsi_host structure.
590 * @attr: device attribute, not used.
591 * @buf: on return contains the scsi vpd program type.
592 *
593 * Returns: size of formatted string.
594 **/
dea31012005-04-17 16:05:31 -0500595static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100596lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500597{
598 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100599 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
601 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500602 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500603
dea31012005-04-17 16:05:31 -0500604 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
605 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
606}
James Smarte59058c2008-08-24 21:49:00 -0400607
608/**
James Smart3621a712009-04-06 18:47:14 -0400609 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
James Smarte59058c2008-08-24 21:49:00 -0400610 * @dev: class converted to a Scsi_host structure.
611 * @attr: device attribute, not used.
612 * @buf: on return contains the ROM and FCode ascii strings.
613 *
614 * Returns: size of formatted string.
615 **/
dea31012005-04-17 16:05:31 -0500616static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100617lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
618 char *buf)
dea31012005-04-17 16:05:31 -0500619{
Tony Jonesee959b02008-02-22 00:13:36 +0100620 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500621 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
622 struct lpfc_hba *phba = vport->phba;
James Smarta0683bf2015-04-07 15:07:16 -0400623 char fwrev[FW_REV_STR_SIZE];
James Smart2e0fef82007-06-17 19:56:36 -0500624
James Smarta0683bf2015-04-07 15:07:16 -0400625 if (phba->sli_rev < LPFC_SLI_REV4)
626 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
627
628 lpfc_decode_firmware_rev(phba, fwrev, 1);
629 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
dea31012005-04-17 16:05:31 -0500630}
James Smarte59058c2008-08-24 21:49:00 -0400631
632/**
James Smart3621a712009-04-06 18:47:14 -0400633 * lpfc_state_show - Return the link state of the port
James Smarte59058c2008-08-24 21:49:00 -0400634 * @dev: class converted to a Scsi_host structure.
635 * @attr: device attribute, not used.
636 * @buf: on return contains text describing the state of the link.
637 *
638 * Notes:
639 * The switch statement has no default so zero will be returned.
640 *
641 * Returns: size of formatted string.
642 **/
dea31012005-04-17 16:05:31 -0500643static ssize_t
Hannes Reineckebbd1ae42008-03-18 14:32:28 +0100644lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
645 char *buf)
dea31012005-04-17 16:05:31 -0500646{
Tony Jonesee959b02008-02-22 00:13:36 +0100647 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500648 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
649 struct lpfc_hba *phba = vport->phba;
650 int len = 0;
651
652 switch (phba->link_state) {
653 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500654 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500655 case LPFC_INIT_START:
656 case LPFC_INIT_MBX_CMDS:
657 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500658 case LPFC_HBA_ERROR:
James Smarta0c87cb2009-07-19 10:01:10 -0400659 if (phba->hba_flag & LINK_DISABLED)
660 len += snprintf(buf + len, PAGE_SIZE-len,
661 "Link Down - User disabled\n");
662 else
663 len += snprintf(buf + len, PAGE_SIZE-len,
664 "Link Down\n");
dea31012005-04-17 16:05:31 -0500665 break;
666 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500667 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500668 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400669 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500670
671 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500672 case LPFC_LOCAL_CFG_LINK:
673 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500674 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500675 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500676 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500677 case LPFC_FLOGI:
678 case LPFC_FABRIC_CFG_LINK:
679 case LPFC_NS_REG:
680 case LPFC_NS_QRY:
681 case LPFC_BUILD_DISC_LIST:
682 case LPFC_DISC_AUTH:
683 len += snprintf(buf + len, PAGE_SIZE - len,
684 "Discovery\n");
685 break;
686 case LPFC_VPORT_READY:
687 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
688 break;
689
James Smart92d7f7b2007-06-17 19:56:38 -0500690 case LPFC_VPORT_FAILED:
691 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
692 break;
693
694 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500695 len += snprintf(buf + len, PAGE_SIZE - len,
696 "Unknown\n");
697 break;
698 }
James Smart84774a42008-08-24 21:50:06 -0400699 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
700 len += snprintf(buf + len, PAGE_SIZE-len,
701 " Menlo Maint Mode\n");
James Smart76a95d72010-11-20 23:11:48 -0500702 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500703 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500704 len += snprintf(buf + len, PAGE_SIZE-len,
705 " Public Loop\n");
706 else
707 len += snprintf(buf + len, PAGE_SIZE-len,
708 " Private Loop\n");
709 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500710 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500711 len += snprintf(buf + len, PAGE_SIZE-len,
712 " Fabric\n");
713 else
714 len += snprintf(buf + len, PAGE_SIZE-len,
715 " Point-2-Point\n");
716 }
717 }
James Smart2e0fef82007-06-17 19:56:36 -0500718
dea31012005-04-17 16:05:31 -0500719 return len;
720}
721
James Smarte59058c2008-08-24 21:49:00 -0400722/**
James Smart026abb82011-12-13 13:20:45 -0500723 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
724 * @dev: class unused variable.
725 * @attr: device attribute, not used.
726 * @buf: on return contains the module description text.
727 *
728 * Returns: size of formatted string.
729 **/
730static ssize_t
731lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
732 char *buf)
733{
734 struct Scsi_Host *shost = class_to_shost(dev);
735 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
736 struct lpfc_hba *phba = vport->phba;
737
738 if (phba->sli_rev < LPFC_SLI_REV4)
739 return snprintf(buf, PAGE_SIZE, "fc\n");
740
741 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
742 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
743 return snprintf(buf, PAGE_SIZE, "fcoe\n");
744 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
745 return snprintf(buf, PAGE_SIZE, "fc\n");
746 }
747 return snprintf(buf, PAGE_SIZE, "unknown\n");
748}
749
750/**
James Smart1ba981f2014-02-20 09:56:45 -0500751 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
752 * (OAS) is supported.
753 * @dev: class unused variable.
754 * @attr: device attribute, not used.
755 * @buf: on return contains the module description text.
756 *
757 * Returns: size of formatted string.
758 **/
759static ssize_t
760lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
761 char *buf)
762{
763 struct Scsi_Host *shost = class_to_shost(dev);
764 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
765 struct lpfc_hba *phba = vport->phba;
766
767 return snprintf(buf, PAGE_SIZE, "%d\n",
768 phba->sli4_hba.pc_sli4_params.oas_supported);
769}
770
771/**
James Smart84d1b002010-02-12 14:42:33 -0500772 * lpfc_link_state_store - Transition the link_state on an HBA port
773 * @dev: class device that is converted into a Scsi_host.
774 * @attr: device attribute, not used.
775 * @buf: one or more lpfc_polling_flags values.
776 * @count: not used.
777 *
778 * Returns:
779 * -EINVAL if the buffer is not "up" or "down"
780 * return from link state change function if non-zero
781 * length of the buf on success
782 **/
783static ssize_t
784lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
785 const char *buf, size_t count)
786{
787 struct Scsi_Host *shost = class_to_shost(dev);
788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
789 struct lpfc_hba *phba = vport->phba;
790
791 int status = -EINVAL;
792
793 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
794 (phba->link_state == LPFC_LINK_DOWN))
James Smart6e7288d2010-06-07 15:23:35 -0400795 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500796 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
797 (phba->link_state >= LPFC_LINK_UP))
James Smart6e7288d2010-06-07 15:23:35 -0400798 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
James Smart84d1b002010-02-12 14:42:33 -0500799
800 if (status == 0)
801 return strlen(buf);
802 else
803 return status;
804}
805
806/**
James Smart3621a712009-04-06 18:47:14 -0400807 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
James Smarte59058c2008-08-24 21:49:00 -0400808 * @dev: class device that is converted into a Scsi_host.
809 * @attr: device attribute, not used.
810 * @buf: on return contains the sum of fc mapped and unmapped.
811 *
812 * Description:
813 * Returns the ascii text number of the sum of the fc mapped and unmapped
814 * vport counts.
815 *
816 * Returns: size of formatted string.
817 **/
dea31012005-04-17 16:05:31 -0500818static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100819lpfc_num_discovered_ports_show(struct device *dev,
820 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500821{
Tony Jonesee959b02008-02-22 00:13:36 +0100822 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
824
825 return snprintf(buf, PAGE_SIZE, "%d\n",
826 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500827}
828
James Smarte59058c2008-08-24 21:49:00 -0400829/**
James Smart3621a712009-04-06 18:47:14 -0400830 * lpfc_issue_lip - Misnomer, name carried over from long ago
James Smarte59058c2008-08-24 21:49:00 -0400831 * @shost: Scsi_Host pointer.
832 *
833 * Description:
834 * Bring the link down gracefully then re-init the link. The firmware will
835 * re-init the fiber channel interface as required. Does not issue a LIP.
836 *
837 * Returns:
838 * -EPERM port offline or management commands are being blocked
839 * -ENOMEM cannot allocate memory for the mailbox command
840 * -EIO error sending the mailbox command
841 * zero for success
842 **/
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700843static int
James Smart2e0fef82007-06-17 19:56:36 -0500844lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500845{
James Smart2e0fef82007-06-17 19:56:36 -0500846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500848 LPFC_MBOXQ_t *pmboxq;
849 int mbxstatus = MBXERR_ERROR;
850
James Smart2e0fef82007-06-17 19:56:36 -0500851 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500852 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500853 return -EPERM;
854
855 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
856
857 if (!pmboxq)
858 return -ENOMEM;
859
860 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart04c68492009-05-22 14:52:52 -0400861 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
862 pmboxq->u.mb.mbxOwner = OWN_HOST;
James Smart4db621e2006-07-06 15:49:49 -0400863
James Smart33ccf8d2006-08-17 11:57:58 -0400864 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500865
James Smart04c68492009-05-22 14:52:52 -0400866 if ((mbxstatus == MBX_SUCCESS) &&
867 (pmboxq->u.mb.mbxStatus == 0 ||
868 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
James Smart4db621e2006-07-06 15:49:49 -0400869 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
870 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
871 phba->cfg_link_speed);
872 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
873 phba->fc_ratov * 2);
James Smartdcf2a4e2010-09-29 11:18:53 -0400874 if ((mbxstatus == MBX_SUCCESS) &&
875 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
876 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
877 "2859 SLI authentication is required "
878 "for INIT_LINK but has not done yet\n");
James Smart4db621e2006-07-06 15:49:49 -0400879 }
880
James Smart5b8bd0c2007-04-25 09:52:49 -0400881 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500882 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400883 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500884
885 if (mbxstatus == MBXERR_ERROR)
886 return -EIO;
887
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700888 return 0;
dea31012005-04-17 16:05:31 -0500889}
890
James Smart895427b2017-02-12 13:52:30 -0800891int
892lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
893{
894 int cnt = 0;
895
896 spin_lock_irq(lock);
897 while (!list_empty(q)) {
898 spin_unlock_irq(lock);
899 msleep(20);
900 if (cnt++ > 250) { /* 5 secs */
901 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
902 "0466 %s %s\n",
903 "Outstanding IO when ",
904 "bringing Adapter offline\n");
905 return 0;
906 }
907 spin_lock_irq(lock);
908 }
909 spin_unlock_irq(lock);
910 return 1;
911}
912
James Smarte59058c2008-08-24 21:49:00 -0400913/**
James Smart3621a712009-04-06 18:47:14 -0400914 * lpfc_do_offline - Issues a mailbox command to bring the link down
James Smarte59058c2008-08-24 21:49:00 -0400915 * @phba: lpfc_hba pointer.
916 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
917 *
918 * Notes:
919 * Assumes any error from lpfc_do_offline() will be negative.
920 * Can wait up to 5 seconds for the port ring buffers count
921 * to reach zero, prints a warning if it is not zero and continues.
James Smart3621a712009-04-06 18:47:14 -0400922 * lpfc_workq_post_event() returns a non-zero return code if call fails.
James Smarte59058c2008-08-24 21:49:00 -0400923 *
924 * Returns:
925 * -EIO error posting the event
926 * zero for success
927 **/
James Smart40496f02006-07-06 15:50:22 -0400928static int
James Smart46fa3112007-04-25 09:51:45 -0400929lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
930{
931 struct completion online_compl;
James Smart895427b2017-02-12 13:52:30 -0800932 struct lpfc_queue *qp = NULL;
James Smart46fa3112007-04-25 09:51:45 -0400933 struct lpfc_sli_ring *pring;
934 struct lpfc_sli *psli;
935 int status = 0;
James Smart46fa3112007-04-25 09:51:45 -0400936 int i;
James Smartfedd3b72011-02-16 12:39:24 -0500937 int rc;
James Smart46fa3112007-04-25 09:51:45 -0400938
939 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500940 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart46fa3112007-04-25 09:51:45 -0400941 LPFC_EVT_OFFLINE_PREP);
James Smartfedd3b72011-02-16 12:39:24 -0500942 if (rc == 0)
943 return -ENOMEM;
944
James Smart46fa3112007-04-25 09:51:45 -0400945 wait_for_completion(&online_compl);
946
947 if (status != 0)
948 return -EIO;
949
950 psli = &phba->sli;
951
James Smart09372822008-01-11 01:52:54 -0500952 /* Wait a little for things to settle down, but not
953 * long enough for dev loss timeout to expire.
954 */
James Smart895427b2017-02-12 13:52:30 -0800955 if (phba->sli_rev != LPFC_SLI_REV4) {
956 for (i = 0; i < psli->num_rings; i++) {
957 pring = &psli->sli3_ring[i];
958 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
959 &phba->hbalock))
960 goto out;
961 }
962 } else {
963 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
964 pring = qp->pring;
965 if (!pring)
966 continue;
967 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
968 &pring->ring_lock))
969 goto out;
James Smart46fa3112007-04-25 09:51:45 -0400970 }
971 }
James Smart895427b2017-02-12 13:52:30 -0800972out:
James Smart46fa3112007-04-25 09:51:45 -0400973 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -0500974 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
975 if (rc == 0)
976 return -ENOMEM;
977
James Smart46fa3112007-04-25 09:51:45 -0400978 wait_for_completion(&online_compl);
979
980 if (status != 0)
981 return -EIO;
982
983 return 0;
984}
985
James Smarte59058c2008-08-24 21:49:00 -0400986/**
James Smart3621a712009-04-06 18:47:14 -0400987 * lpfc_selective_reset - Offline then onlines the port
James Smarte59058c2008-08-24 21:49:00 -0400988 * @phba: lpfc_hba pointer.
989 *
990 * Description:
991 * If the port is configured to allow a reset then the hba is brought
992 * offline then online.
993 *
994 * Notes:
995 * Assumes any error from lpfc_do_offline() will be negative.
James Smartab56dc22011-02-16 12:39:57 -0500996 * Do not make this function static.
James Smarte59058c2008-08-24 21:49:00 -0400997 *
998 * Returns:
999 * lpfc_do_offline() return code if not zero
1000 * -EIO reset not configured or error posting the event
1001 * zero for success
1002 **/
James Smart7f860592011-03-11 16:05:52 -05001003int
James Smart40496f02006-07-06 15:50:22 -04001004lpfc_selective_reset(struct lpfc_hba *phba)
1005{
1006 struct completion online_compl;
1007 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001008 int rc;
James Smart40496f02006-07-06 15:50:22 -04001009
James Smart71157c92013-07-15 18:34:36 -04001010 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001011 return -EACCES;
James Smart13815c82008-01-11 01:52:48 -05001012
James Smart71157c92013-07-15 18:34:36 -04001013 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1014 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -04001015
James Smart71157c92013-07-15 18:34:36 -04001016 if (status != 0)
1017 return status;
1018 }
James Smart40496f02006-07-06 15:50:22 -04001019
1020 init_completion(&online_compl);
James Smartfedd3b72011-02-16 12:39:24 -05001021 rc = lpfc_workq_post_event(phba, &status, &online_compl,
James Smart40496f02006-07-06 15:50:22 -04001022 LPFC_EVT_ONLINE);
James Smartfedd3b72011-02-16 12:39:24 -05001023 if (rc == 0)
1024 return -ENOMEM;
1025
James Smart40496f02006-07-06 15:50:22 -04001026 wait_for_completion(&online_compl);
1027
1028 if (status != 0)
1029 return -EIO;
1030
1031 return 0;
1032}
1033
James Smarte59058c2008-08-24 21:49:00 -04001034/**
James Smart3621a712009-04-06 18:47:14 -04001035 * lpfc_issue_reset - Selectively resets an adapter
James Smarte59058c2008-08-24 21:49:00 -04001036 * @dev: class device that is converted into a Scsi_host.
1037 * @attr: device attribute, not used.
1038 * @buf: containing the string "selective".
1039 * @count: unused variable.
1040 *
1041 * Description:
1042 * If the buf contains the string "selective" then lpfc_selective_reset()
1043 * is called to perform the reset.
1044 *
1045 * Notes:
1046 * Assumes any error from lpfc_selective_reset() will be negative.
1047 * If lpfc_selective_reset() returns zero then the length of the buffer
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001048 * is returned which indicates success
James Smarte59058c2008-08-24 21:49:00 -04001049 *
1050 * Returns:
1051 * -EINVAL if the buffer does not contain the string "selective"
1052 * length of buf if lpfc-selective_reset() if the call succeeds
1053 * return value of lpfc_selective_reset() if the call fails
1054**/
James Smart40496f02006-07-06 15:50:22 -04001055static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001056lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1057 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -04001058{
Tony Jonesee959b02008-02-22 00:13:36 +01001059 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001060 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1061 struct lpfc_hba *phba = vport->phba;
James Smart40496f02006-07-06 15:50:22 -04001062 int status = -EINVAL;
1063
James Smart73d91e52011-10-10 21:32:10 -04001064 if (!phba->cfg_enable_hba_reset)
1065 return -EACCES;
1066
James Smart40496f02006-07-06 15:50:22 -04001067 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
James Smart7f860592011-03-11 16:05:52 -05001068 status = phba->lpfc_selective_reset(phba);
James Smart40496f02006-07-06 15:50:22 -04001069
1070 if (status == 0)
1071 return strlen(buf);
1072 else
1073 return status;
1074}
1075
James Smarte59058c2008-08-24 21:49:00 -04001076/**
James Smart88a2cfb2011-07-22 18:36:33 -04001077 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1078 * @phba: lpfc_hba pointer.
1079 *
1080 * Description:
1081 * SLI4 interface type-2 device to wait on the sliport status register for
1082 * the readyness after performing a firmware reset.
1083 *
1084 * Returns:
Masanari Iida0b1587b2013-07-17 04:37:44 +09001085 * zero for success, -EPERM when port does not have privilege to perform the
James Smart026abb82011-12-13 13:20:45 -05001086 * reset, -EIO when port timeout from recovering from the reset.
1087 *
1088 * Note:
1089 * As the caller will interpret the return code by value, be careful in making
1090 * change or addition to return codes.
James Smart88a2cfb2011-07-22 18:36:33 -04001091 **/
James Smart73d91e52011-10-10 21:32:10 -04001092int
James Smart88a2cfb2011-07-22 18:36:33 -04001093lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1094{
James Smartf7a919b2011-08-21 21:49:16 -04001095 struct lpfc_register portstat_reg = {0};
James Smart88a2cfb2011-07-22 18:36:33 -04001096 int i;
1097
James Smartf7a919b2011-08-21 21:49:16 -04001098 msleep(100);
James Smart88a2cfb2011-07-22 18:36:33 -04001099 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1100 &portstat_reg.word0);
1101
Masanari Iida0b1587b2013-07-17 04:37:44 +09001102 /* verify if privileged for the request operation */
James Smartf7a919b2011-08-21 21:49:16 -04001103 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1104 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1105 return -EPERM;
1106
James Smart88a2cfb2011-07-22 18:36:33 -04001107 /* wait for the SLI port firmware ready after firmware reset */
1108 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1109 msleep(10);
1110 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1111 &portstat_reg.word0);
1112 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1113 continue;
1114 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1115 continue;
1116 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1117 continue;
1118 break;
1119 }
1120
1121 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1122 return 0;
1123 else
1124 return -EIO;
1125}
1126
1127/**
James Smart52d52442011-05-24 11:42:45 -04001128 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
James Smartc0c11512011-05-24 11:41:34 -04001129 * @phba: lpfc_hba pointer.
1130 *
1131 * Description:
James Smart52d52442011-05-24 11:42:45 -04001132 * Request SLI4 interface type-2 device to perform a physical register set
1133 * access.
James Smartc0c11512011-05-24 11:41:34 -04001134 *
1135 * Returns:
1136 * zero for success
1137 **/
1138static ssize_t
James Smart52d52442011-05-24 11:42:45 -04001139lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
James Smartc0c11512011-05-24 11:41:34 -04001140{
1141 struct completion online_compl;
James Smartb76f2dc2011-07-22 18:37:42 -04001142 struct pci_dev *pdev = phba->pcidev;
James Smart026abb82011-12-13 13:20:45 -05001143 uint32_t before_fc_flag;
1144 uint32_t sriov_nr_virtfn;
James Smartc0c11512011-05-24 11:41:34 -04001145 uint32_t reg_val;
James Smart026abb82011-12-13 13:20:45 -05001146 int status = 0, rc = 0;
1147 int job_posted = 1, sriov_err;
James Smartc0c11512011-05-24 11:41:34 -04001148
1149 if (!phba->cfg_enable_hba_reset)
James Smartf7a919b2011-08-21 21:49:16 -04001150 return -EACCES;
James Smartc0c11512011-05-24 11:41:34 -04001151
James Smart52d52442011-05-24 11:42:45 -04001152 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1153 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1154 LPFC_SLI_INTF_IF_TYPE_2))
1155 return -EPERM;
1156
James Smart026abb82011-12-13 13:20:45 -05001157 /* Keep state if we need to restore back */
1158 before_fc_flag = phba->pport->fc_flag;
1159 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1160
James Smartb76f2dc2011-07-22 18:37:42 -04001161 /* Disable SR-IOV virtual functions if enabled */
1162 if (phba->cfg_sriov_nr_virtfn) {
1163 pci_disable_sriov(pdev);
1164 phba->cfg_sriov_nr_virtfn = 0;
1165 }
James Smart229adb02013-04-17 20:16:51 -04001166
James Smart02936352014-04-04 13:52:12 -04001167 if (opcode == LPFC_FW_DUMP)
1168 phba->hba_flag |= HBA_FW_DUMP_OP;
1169
James Smartc0c11512011-05-24 11:41:34 -04001170 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1171
James Smart02936352014-04-04 13:52:12 -04001172 if (status != 0) {
1173 phba->hba_flag &= ~HBA_FW_DUMP_OP;
James Smartc0c11512011-05-24 11:41:34 -04001174 return status;
James Smart02936352014-04-04 13:52:12 -04001175 }
James Smartc0c11512011-05-24 11:41:34 -04001176
1177 /* wait for the device to be quiesced before firmware reset */
1178 msleep(100);
1179
1180 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1181 LPFC_CTL_PDEV_CTL_OFFSET);
James Smart52d52442011-05-24 11:42:45 -04001182
1183 if (opcode == LPFC_FW_DUMP)
1184 reg_val |= LPFC_FW_DUMP_REQUEST;
1185 else if (opcode == LPFC_FW_RESET)
1186 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1187 else if (opcode == LPFC_DV_RESET)
1188 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1189
James Smartc0c11512011-05-24 11:41:34 -04001190 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1191 LPFC_CTL_PDEV_CTL_OFFSET);
1192 /* flush */
1193 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1194
1195 /* delay driver action following IF_TYPE_2 reset */
James Smart88a2cfb2011-07-22 18:36:33 -04001196 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1197
James Smart026abb82011-12-13 13:20:45 -05001198 if (rc == -EPERM) {
Masanari Iida0b1587b2013-07-17 04:37:44 +09001199 /* no privilege for reset */
James Smart6b5151f2012-01-18 16:24:06 -05001200 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
Masanari Iida0b1587b2013-07-17 04:37:44 +09001201 "3150 No privilege to perform the requested "
James Smart6b5151f2012-01-18 16:24:06 -05001202 "access: x%x\n", reg_val);
James Smart026abb82011-12-13 13:20:45 -05001203 } else if (rc == -EIO) {
1204 /* reset failed, there is nothing more we can do */
James Smart6b5151f2012-01-18 16:24:06 -05001205 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1206 "3153 Fail to perform the requested "
1207 "access: x%x\n", reg_val);
James Smartf7a919b2011-08-21 21:49:16 -04001208 return rc;
James Smart026abb82011-12-13 13:20:45 -05001209 }
1210
1211 /* keep the original port state */
1212 if (before_fc_flag & FC_OFFLINE_MODE)
1213 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001214
1215 init_completion(&online_compl);
James Smart026abb82011-12-13 13:20:45 -05001216 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1217 LPFC_EVT_ONLINE);
1218 if (!job_posted)
1219 goto out;
James Smartc0c11512011-05-24 11:41:34 -04001220
1221 wait_for_completion(&online_compl);
1222
James Smart026abb82011-12-13 13:20:45 -05001223out:
1224 /* in any case, restore the virtual functions enabled as before */
1225 if (sriov_nr_virtfn) {
1226 sriov_err =
1227 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1228 if (!sriov_err)
1229 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1230 }
James Smartc0c11512011-05-24 11:41:34 -04001231
James Smart026abb82011-12-13 13:20:45 -05001232 /* return proper error code */
1233 if (!rc) {
1234 if (!job_posted)
1235 rc = -ENOMEM;
1236 else if (status)
1237 rc = -EIO;
1238 }
1239 return rc;
James Smartc0c11512011-05-24 11:41:34 -04001240}
1241
1242/**
James Smart3621a712009-04-06 18:47:14 -04001243 * lpfc_nport_evt_cnt_show - Return the number of nport events
James Smarte59058c2008-08-24 21:49:00 -04001244 * @dev: class device that is converted into a Scsi_host.
1245 * @attr: device attribute, not used.
1246 * @buf: on return contains the ascii number of nport events.
1247 *
1248 * Returns: size of formatted string.
1249 **/
dea31012005-04-17 16:05:31 -05001250static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001251lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1252 char *buf)
dea31012005-04-17 16:05:31 -05001253{
Tony Jonesee959b02008-02-22 00:13:36 +01001254 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1256 struct lpfc_hba *phba = vport->phba;
1257
dea31012005-04-17 16:05:31 -05001258 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1259}
1260
James Smarte59058c2008-08-24 21:49:00 -04001261/**
James Smart3621a712009-04-06 18:47:14 -04001262 * lpfc_board_mode_show - Return the state of the board
James Smarte59058c2008-08-24 21:49:00 -04001263 * @dev: class device that is converted into a Scsi_host.
1264 * @attr: device attribute, not used.
1265 * @buf: on return contains the state of the adapter.
1266 *
1267 * Returns: size of formatted string.
1268 **/
dea31012005-04-17 16:05:31 -05001269static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001270lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1271 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001272{
Tony Jonesee959b02008-02-22 00:13:36 +01001273 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001274 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1275 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001276 char * state;
1277
James Smart2e0fef82007-06-17 19:56:36 -05001278 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001279 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -05001280 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001281 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -05001282 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001283 state = "offline";
1284 else
1285 state = "online";
1286
1287 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1288}
1289
James Smarte59058c2008-08-24 21:49:00 -04001290/**
James Smart3621a712009-04-06 18:47:14 -04001291 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
James Smarte59058c2008-08-24 21:49:00 -04001292 * @dev: class device that is converted into a Scsi_host.
1293 * @attr: device attribute, not used.
1294 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1295 * @count: unused variable.
1296 *
1297 * Returns:
1298 * -EACCES if enable hba reset not enabled
1299 * -EINVAL if the buffer does not contain a valid string (see above)
1300 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1301 * buf length greater than zero indicates success
1302 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001303static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001304lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1305 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -05001306{
Tony Jonesee959b02008-02-22 00:13:36 +01001307 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001308 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1309 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001310 struct completion online_compl;
James Smart026abb82011-12-13 13:20:45 -05001311 char *board_mode_str = NULL;
1312 int status = 0;
James Smartfedd3b72011-02-16 12:39:24 -05001313 int rc;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001314
James Smart026abb82011-12-13 13:20:45 -05001315 if (!phba->cfg_enable_hba_reset) {
1316 status = -EACCES;
1317 goto board_mode_out;
1318 }
James Smart88a2cfb2011-07-22 18:36:33 -04001319
1320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart026abb82011-12-13 13:20:45 -05001321 "3050 lpfc_board_mode set to %s\n", buf);
James Smart88a2cfb2011-07-22 18:36:33 -04001322
Jamie Wellnitz41415862006-02-28 19:25:27 -05001323 init_completion(&online_compl);
1324
James Smart46fa3112007-04-25 09:51:45 -04001325 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
James Smartfedd3b72011-02-16 12:39:24 -05001326 rc = lpfc_workq_post_event(phba, &status, &online_compl,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001327 LPFC_EVT_ONLINE);
James Smart026abb82011-12-13 13:20:45 -05001328 if (rc == 0) {
1329 status = -ENOMEM;
1330 goto board_mode_out;
1331 }
James Smart46fa3112007-04-25 09:51:45 -04001332 wait_for_completion(&online_compl);
1333 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1334 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001335 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001336 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001337 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001338 else
1339 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
James Smart46fa3112007-04-25 09:51:45 -04001340 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
James Smart6a9c52c2009-10-02 15:16:51 -04001341 if (phba->sli_rev == LPFC_SLI_REV4)
James Smart026abb82011-12-13 13:20:45 -05001342 status = -EINVAL;
James Smart6a9c52c2009-10-02 15:16:51 -04001343 else
1344 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
James Smartc0c11512011-05-24 11:41:34 -04001345 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
James Smart52d52442011-05-24 11:42:45 -04001346 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1347 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1348 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1349 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1350 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
Jamie Wellnitz41415862006-02-28 19:25:27 -05001351 else
James Smart026abb82011-12-13 13:20:45 -05001352 status = -EINVAL;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001353
James Smart026abb82011-12-13 13:20:45 -05001354board_mode_out:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001355 if (!status)
1356 return strlen(buf);
James Smart026abb82011-12-13 13:20:45 -05001357 else {
1358 board_mode_str = strchr(buf, '\n');
1359 if (board_mode_str)
1360 *board_mode_str = '\0';
1361 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1362 "3097 Failed \"%s\", status(%d), "
1363 "fc_flag(x%x)\n",
1364 buf, status, phba->pport->fc_flag);
James Smartf7a919b2011-08-21 21:49:16 -04001365 return status;
James Smart026abb82011-12-13 13:20:45 -05001366 }
Jamie Wellnitz41415862006-02-28 19:25:27 -05001367}
1368
James Smarte59058c2008-08-24 21:49:00 -04001369/**
James Smart3621a712009-04-06 18:47:14 -04001370 * lpfc_get_hba_info - Return various bits of informaton about the adapter
James Smarte59058c2008-08-24 21:49:00 -04001371 * @phba: pointer to the adapter structure.
James Smart3621a712009-04-06 18:47:14 -04001372 * @mxri: max xri count.
1373 * @axri: available xri count.
1374 * @mrpi: max rpi count.
1375 * @arpi: available rpi count.
1376 * @mvpi: max vpi count.
1377 * @avpi: available vpi count.
James Smarte59058c2008-08-24 21:49:00 -04001378 *
1379 * Description:
1380 * If an integer pointer for an count is not null then the value for the
1381 * count is returned.
1382 *
1383 * Returns:
1384 * zero on error
1385 * one for success
1386 **/
James Smart311464e2007-08-02 11:10:37 -04001387static int
James Smart858c9f62007-06-17 19:56:39 -05001388lpfc_get_hba_info(struct lpfc_hba *phba,
1389 uint32_t *mxri, uint32_t *axri,
1390 uint32_t *mrpi, uint32_t *arpi,
1391 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -05001392{
James Smart04c68492009-05-22 14:52:52 -04001393 struct lpfc_mbx_read_config *rd_config;
James Smart92d7f7b2007-06-17 19:56:38 -05001394 LPFC_MBOXQ_t *pmboxq;
1395 MAILBOX_t *pmb;
1396 int rc = 0;
James Smart15672312010-04-06 14:49:03 -04001397 uint32_t max_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -05001398
1399 /*
1400 * prevent udev from issuing mailbox commands until the port is
1401 * configured.
1402 */
1403 if (phba->link_state < LPFC_LINK_DOWN ||
1404 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04001405 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001406 return 0;
1407
1408 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1409 return 0;
1410
1411 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1412 if (!pmboxq)
1413 return 0;
1414 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1415
James Smart04c68492009-05-22 14:52:52 -04001416 pmb = &pmboxq->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05001417 pmb->mbxCommand = MBX_READ_CONFIG;
1418 pmb->mbxOwner = OWN_HOST;
1419 pmboxq->context1 = NULL;
1420
James Smart75baf692010-06-08 18:31:21 -04001421 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
James Smart92d7f7b2007-06-17 19:56:38 -05001422 rc = MBX_NOT_FINISHED;
1423 else
1424 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1425
1426 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05001427 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05001428 mempool_free(pmboxq, phba->mbox_mem_pool);
1429 return 0;
1430 }
1431
James Smartda0436e2009-05-22 14:51:39 -04001432 if (phba->sli_rev == LPFC_SLI_REV4) {
1433 rd_config = &pmboxq->u.mqe.un.rd_config;
1434 if (mrpi)
1435 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1436 if (arpi)
1437 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1438 phba->sli4_hba.max_cfg_param.rpi_used;
1439 if (mxri)
1440 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1441 if (axri)
1442 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1443 phba->sli4_hba.max_cfg_param.xri_used;
James Smart15672312010-04-06 14:49:03 -04001444
1445 /* Account for differences with SLI-3. Get vpi count from
1446 * mailbox data and subtract one for max vpi value.
1447 */
1448 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1449 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1450
James Smartda0436e2009-05-22 14:51:39 -04001451 if (mvpi)
James Smart15672312010-04-06 14:49:03 -04001452 *mvpi = max_vpi;
James Smartda0436e2009-05-22 14:51:39 -04001453 if (avpi)
James Smart15672312010-04-06 14:49:03 -04001454 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
James Smartda0436e2009-05-22 14:51:39 -04001455 } else {
1456 if (mrpi)
1457 *mrpi = pmb->un.varRdConfig.max_rpi;
1458 if (arpi)
1459 *arpi = pmb->un.varRdConfig.avail_rpi;
1460 if (mxri)
1461 *mxri = pmb->un.varRdConfig.max_xri;
1462 if (axri)
1463 *axri = pmb->un.varRdConfig.avail_xri;
1464 if (mvpi)
1465 *mvpi = pmb->un.varRdConfig.max_vpi;
1466 if (avpi)
1467 *avpi = pmb->un.varRdConfig.avail_vpi;
1468 }
James Smart92d7f7b2007-06-17 19:56:38 -05001469
1470 mempool_free(pmboxq, phba->mbox_mem_pool);
1471 return 1;
1472}
1473
James Smarte59058c2008-08-24 21:49:00 -04001474/**
James Smart3621a712009-04-06 18:47:14 -04001475 * lpfc_max_rpi_show - Return maximum rpi
James Smarte59058c2008-08-24 21:49:00 -04001476 * @dev: class device that is converted into a Scsi_host.
1477 * @attr: device attribute, not used.
1478 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1479 *
1480 * Description:
1481 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1482 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1483 * to "Unknown" and the buffer length is returned, therefore the caller
1484 * must check for "Unknown" in the buffer to detect a failure.
1485 *
1486 * Returns: size of formatted string.
1487 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001488static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001489lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1490 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001491{
Tony Jonesee959b02008-02-22 00:13:36 +01001492 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001493 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1494 struct lpfc_hba *phba = vport->phba;
1495 uint32_t cnt;
1496
James Smart858c9f62007-06-17 19:56:39 -05001497 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001498 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1499 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1500}
1501
James Smarte59058c2008-08-24 21:49:00 -04001502/**
James Smart3621a712009-04-06 18:47:14 -04001503 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
James Smarte59058c2008-08-24 21:49:00 -04001504 * @dev: class device that is converted into a Scsi_host.
1505 * @attr: device attribute, not used.
1506 * @buf: containing the used rpi count in decimal or "Unknown".
1507 *
1508 * Description:
1509 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1510 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1511 * to "Unknown" and the buffer length is returned, therefore the caller
1512 * must check for "Unknown" in the buffer to detect a failure.
1513 *
1514 * Returns: size of formatted string.
1515 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001516static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001517lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1518 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001519{
Tony Jonesee959b02008-02-22 00:13:36 +01001520 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1522 struct lpfc_hba *phba = vport->phba;
1523 uint32_t cnt, acnt;
1524
James Smart858c9f62007-06-17 19:56:39 -05001525 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001526 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1527 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1528}
1529
James Smarte59058c2008-08-24 21:49:00 -04001530/**
James Smart3621a712009-04-06 18:47:14 -04001531 * lpfc_max_xri_show - Return maximum xri
James Smarte59058c2008-08-24 21:49:00 -04001532 * @dev: class device that is converted into a Scsi_host.
1533 * @attr: device attribute, not used.
1534 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1535 *
1536 * Description:
1537 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1538 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1539 * to "Unknown" and the buffer length is returned, therefore the caller
1540 * must check for "Unknown" in the buffer to detect a failure.
1541 *
1542 * Returns: size of formatted string.
1543 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001544static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001545lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1546 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001547{
Tony Jonesee959b02008-02-22 00:13:36 +01001548 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1550 struct lpfc_hba *phba = vport->phba;
1551 uint32_t cnt;
1552
James Smart858c9f62007-06-17 19:56:39 -05001553 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -05001554 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1555 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1556}
1557
James Smarte59058c2008-08-24 21:49:00 -04001558/**
James Smart3621a712009-04-06 18:47:14 -04001559 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
James Smarte59058c2008-08-24 21:49:00 -04001560 * @dev: class device that is converted into a Scsi_host.
1561 * @attr: device attribute, not used.
1562 * @buf: on return contains the used xri count in decimal or "Unknown".
1563 *
1564 * Description:
1565 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1566 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1567 * to "Unknown" and the buffer length is returned, therefore the caller
1568 * must check for "Unknown" in the buffer to detect a failure.
1569 *
1570 * Returns: size of formatted string.
1571 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001572static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001573lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1574 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001575{
Tony Jonesee959b02008-02-22 00:13:36 +01001576 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1578 struct lpfc_hba *phba = vport->phba;
1579 uint32_t cnt, acnt;
1580
James Smart858c9f62007-06-17 19:56:39 -05001581 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1582 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1583 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1584}
1585
James Smarte59058c2008-08-24 21:49:00 -04001586/**
James Smart3621a712009-04-06 18:47:14 -04001587 * lpfc_max_vpi_show - Return maximum vpi
James Smarte59058c2008-08-24 21:49:00 -04001588 * @dev: class device that is converted into a Scsi_host.
1589 * @attr: device attribute, not used.
1590 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1591 *
1592 * Description:
1593 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1594 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1595 * to "Unknown" and the buffer length is returned, therefore the caller
1596 * must check for "Unknown" in the buffer to detect a failure.
1597 *
1598 * Returns: size of formatted string.
1599 **/
James Smart858c9f62007-06-17 19:56:39 -05001600static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001601lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1602 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001603{
Tony Jonesee959b02008-02-22 00:13:36 +01001604 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1606 struct lpfc_hba *phba = vport->phba;
1607 uint32_t cnt;
1608
1609 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1610 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1611 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1612}
1613
James Smarte59058c2008-08-24 21:49:00 -04001614/**
James Smart3621a712009-04-06 18:47:14 -04001615 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
James Smarte59058c2008-08-24 21:49:00 -04001616 * @dev: class device that is converted into a Scsi_host.
1617 * @attr: device attribute, not used.
1618 * @buf: on return contains the used vpi count in decimal or "Unknown".
1619 *
1620 * Description:
1621 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1622 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1623 * to "Unknown" and the buffer length is returned, therefore the caller
1624 * must check for "Unknown" in the buffer to detect a failure.
1625 *
1626 * Returns: size of formatted string.
1627 **/
James Smart858c9f62007-06-17 19:56:39 -05001628static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001629lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1630 char *buf)
James Smart858c9f62007-06-17 19:56:39 -05001631{
Tony Jonesee959b02008-02-22 00:13:36 +01001632 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -05001633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1634 struct lpfc_hba *phba = vport->phba;
1635 uint32_t cnt, acnt;
1636
1637 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -05001638 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1639 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1640}
1641
James Smarte59058c2008-08-24 21:49:00 -04001642/**
James Smart3621a712009-04-06 18:47:14 -04001643 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001644 * @dev: class device that is converted into a Scsi_host.
1645 * @attr: device attribute, not used.
1646 * @buf: text that must be interpreted to determine if npiv is supported.
1647 *
1648 * Description:
1649 * Buffer will contain text indicating npiv is not suppoerted on the port,
1650 * the port is an NPIV physical port, or it is an npiv virtual port with
1651 * the id of the vport.
1652 *
1653 * Returns: size of formatted string.
1654 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001655static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001656lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1657 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -05001658{
Tony Jonesee959b02008-02-22 00:13:36 +01001659 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -05001660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1661 struct lpfc_hba *phba = vport->phba;
1662
1663 if (!(phba->max_vpi))
1664 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1665 if (vport->port_type == LPFC_PHYSICAL_PORT)
1666 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1667 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1668}
1669
James Smarte59058c2008-08-24 21:49:00 -04001670/**
James Smart3621a712009-04-06 18:47:14 -04001671 * lpfc_poll_show - Return text about poll support for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001672 * @dev: class device that is converted into a Scsi_host.
1673 * @attr: device attribute, not used.
1674 * @buf: on return contains the cfg_poll in hex.
1675 *
1676 * Notes:
1677 * cfg_poll should be a lpfc_polling_flags type.
1678 *
1679 * Returns: size of formatted string.
1680 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001681static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001682lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1683 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001684{
Tony Jonesee959b02008-02-22 00:13:36 +01001685 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001686 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1687 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001688
1689 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1690}
1691
James Smarte59058c2008-08-24 21:49:00 -04001692/**
James Smart3621a712009-04-06 18:47:14 -04001693 * lpfc_poll_store - Set the value of cfg_poll for the adapter
James Smarte59058c2008-08-24 21:49:00 -04001694 * @dev: class device that is converted into a Scsi_host.
1695 * @attr: device attribute, not used.
1696 * @buf: one or more lpfc_polling_flags values.
1697 * @count: not used.
1698 *
1699 * Notes:
1700 * buf contents converted to integer and checked for a valid value.
1701 *
1702 * Returns:
1703 * -EINVAL if the buffer connot be converted or is out of range
1704 * length of the buf on success
1705 **/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001706static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001707lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1708 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001709{
Tony Jonesee959b02008-02-22 00:13:36 +01001710 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1712 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001713 uint32_t creg_val;
1714 uint32_t old_val;
1715 int val=0;
1716
1717 if (!isdigit(buf[0]))
1718 return -EINVAL;
1719
1720 if (sscanf(buf, "%i", &val) != 1)
1721 return -EINVAL;
1722
1723 if ((val & 0x3) != val)
1724 return -EINVAL;
1725
James Smart45ed1192009-10-02 15:17:02 -04001726 if (phba->sli_rev == LPFC_SLI_REV4)
1727 val = 0;
1728
James Smart88a2cfb2011-07-22 18:36:33 -04001729 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1730 "3051 lpfc_poll changed from %d to %d\n",
1731 phba->cfg_poll, val);
1732
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001734
1735 old_val = phba->cfg_poll;
1736
1737 if (val & ENABLE_FCP_RING_POLLING) {
1738 if ((val & DISABLE_FCP_RING_INT) &&
1739 !(old_val & DISABLE_FCP_RING_INT)) {
James Smart9940b972011-03-11 16:06:12 -05001740 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1741 spin_unlock_irq(&phba->hbalock);
1742 return -EINVAL;
1743 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001744 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1745 writel(creg_val, phba->HCregaddr);
1746 readl(phba->HCregaddr); /* flush */
1747
1748 lpfc_poll_start_timer(phba);
1749 }
1750 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -05001751 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001752 return -EINVAL;
1753 }
1754
1755 if (!(val & DISABLE_FCP_RING_INT) &&
1756 (old_val & DISABLE_FCP_RING_INT))
1757 {
James Smart2e0fef82007-06-17 19:56:36 -05001758 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001759 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -05001760 spin_lock_irq(&phba->hbalock);
James Smart9940b972011-03-11 16:06:12 -05001761 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1762 spin_unlock_irq(&phba->hbalock);
1763 return -EINVAL;
1764 }
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001765 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1766 writel(creg_val, phba->HCregaddr);
1767 readl(phba->HCregaddr); /* flush */
1768 }
1769
1770 phba->cfg_poll = val;
1771
James Smart2e0fef82007-06-17 19:56:36 -05001772 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001773
1774 return strlen(buf);
1775}
dea31012005-04-17 16:05:31 -05001776
James Smarte59058c2008-08-24 21:49:00 -04001777/**
James Smartbc739052010-08-04 16:11:18 -04001778 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1779 * @dev: class unused variable.
1780 * @attr: device attribute, not used.
1781 * @buf: on return contains the module description text.
1782 *
1783 * Returns: size of formatted string.
1784 **/
1785static ssize_t
1786lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1787 char *buf)
1788{
1789 struct Scsi_Host *shost = class_to_shost(dev);
1790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1791 struct lpfc_hba *phba = vport->phba;
1792
1793 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1794}
1795
1796/**
1797 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1798 * @dev: class unused variable.
1799 * @attr: device attribute, not used.
1800 * @buf: on return contains the module description text.
1801 *
1802 * Returns: size of formatted string.
1803 **/
1804static ssize_t
1805lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1806 char *buf)
1807{
1808 struct Scsi_Host *shost = class_to_shost(dev);
1809 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1810 struct lpfc_hba *phba = vport->phba;
1811
1812 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1813}
1814
1815/**
James Smartab56dc22011-02-16 12:39:57 -05001816 * lpfc_dss_show - Return the current state of dss and the configured state
1817 * @dev: class converted to a Scsi_host structure.
1818 * @attr: device attribute, not used.
1819 * @buf: on return contains the formatted text.
1820 *
1821 * Returns: size of formatted string.
1822 **/
1823static ssize_t
1824lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1825 char *buf)
1826{
1827 struct Scsi_Host *shost = class_to_shost(dev);
1828 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1829 struct lpfc_hba *phba = vport->phba;
1830
1831 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1832 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1833 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1834 "" : "Not ");
1835}
1836
1837/**
James Smart912e3ac2011-05-24 11:42:11 -04001838 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1839 * @dev: class converted to a Scsi_host structure.
1840 * @attr: device attribute, not used.
1841 * @buf: on return contains the formatted support level.
1842 *
1843 * Description:
1844 * Returns the maximum number of virtual functions a physical function can
1845 * support, 0 will be returned if called on virtual function.
1846 *
1847 * Returns: size of formatted string.
1848 **/
1849static ssize_t
1850lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1851 struct device_attribute *attr,
1852 char *buf)
1853{
1854 struct Scsi_Host *shost = class_to_shost(dev);
1855 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1856 struct lpfc_hba *phba = vport->phba;
James Smart0a96e972011-07-22 18:37:28 -04001857 uint16_t max_nr_virtfn;
James Smart912e3ac2011-05-24 11:42:11 -04001858
James Smart0a96e972011-07-22 18:37:28 -04001859 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1860 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
James Smart912e3ac2011-05-24 11:42:11 -04001861}
1862
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001863static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1864{
1865 return val >= min && val <= max;
1866}
1867
James Smart912e3ac2011-05-24 11:42:11 -04001868/**
James Smart3621a712009-04-06 18:47:14 -04001869 * lpfc_param_show - Return a cfg attribute value in decimal
James Smarte59058c2008-08-24 21:49:00 -04001870 *
1871 * Description:
1872 * Macro that given an attr e.g. hba_queue_depth expands
1873 * into a function with the name lpfc_hba_queue_depth_show.
1874 *
1875 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1876 * @dev: class device that is converted into a Scsi_host.
1877 * @attr: device attribute, not used.
1878 * @buf: on return contains the attribute value in decimal.
1879 *
1880 * Returns: size of formatted string.
1881 **/
dea31012005-04-17 16:05:31 -05001882#define lpfc_param_show(attr) \
1883static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001884lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1885 char *buf) \
dea31012005-04-17 16:05:31 -05001886{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001887 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1889 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001890 return snprintf(buf, PAGE_SIZE, "%d\n",\
1891 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -05001892}
1893
James Smarte59058c2008-08-24 21:49:00 -04001894/**
James Smart3621a712009-04-06 18:47:14 -04001895 * lpfc_param_hex_show - Return a cfg attribute value in hex
James Smarte59058c2008-08-24 21:49:00 -04001896 *
1897 * Description:
1898 * Macro that given an attr e.g. hba_queue_depth expands
1899 * into a function with the name lpfc_hba_queue_depth_show
1900 *
1901 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1902 * @dev: class device that is converted into a Scsi_host.
1903 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04001904 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04001905 *
1906 * Returns: size of formatted string.
1907 **/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001908#define lpfc_param_hex_show(attr) \
1909static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001910lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1911 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001912{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001913 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05001914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1915 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05001916 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001917 val = phba->cfg_##attr;\
1918 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1919 phba->cfg_##attr);\
1920}
1921
James Smarte59058c2008-08-24 21:49:00 -04001922/**
Uwe Kleine-Königb5950762010-11-01 15:38:34 -04001923 * lpfc_param_init - Initializes a cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04001924 *
1925 * Description:
1926 * Macro that given an attr e.g. hba_queue_depth expands
1927 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1928 * takes a default argument, a minimum and maximum argument.
1929 *
1930 * lpfc_##attr##_init: Initializes an attribute.
1931 * @phba: pointer the the adapter structure.
1932 * @val: integer attribute value.
1933 *
1934 * Validates the min and max values then sets the adapter config field
1935 * accordingly, or uses the default if out of range and prints an error message.
1936 *
1937 * Returns:
1938 * zero on success
1939 * -EINVAL if default used
1940 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001941#define lpfc_param_init(attr, default, minval, maxval) \
1942static int \
James Smart84d1b002010-02-12 14:42:33 -05001943lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001944{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001945 if (lpfc_rangecheck(val, minval, maxval)) {\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001946 phba->cfg_##attr = val;\
1947 return 0;\
1948 }\
1949 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001950 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1951 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001952 phba->cfg_##attr = default;\
1953 return -EINVAL;\
1954}
1955
James Smarte59058c2008-08-24 21:49:00 -04001956/**
James Smart3621a712009-04-06 18:47:14 -04001957 * lpfc_param_set - Set a cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04001958 *
1959 * Description:
1960 * Macro that given an attr e.g. hba_queue_depth expands
1961 * into a function with the name lpfc_hba_queue_depth_set
1962 *
1963 * lpfc_##attr##_set: Sets an attribute value.
1964 * @phba: pointer the the adapter structure.
1965 * @val: integer attribute value.
1966 *
1967 * Description:
1968 * Validates the min and max values then sets the
1969 * adapter config field if in the valid range. prints error message
1970 * and does not set the parameter if invalid.
1971 *
1972 * Returns:
1973 * zero on success
1974 * -EINVAL if val is invalid
1975 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001976#define lpfc_param_set(attr, default, minval, maxval) \
1977static int \
James Smart84d1b002010-02-12 14:42:33 -05001978lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001979{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02001980 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04001981 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1982 "3052 lpfc_" #attr " changed from %d to %d\n", \
1983 phba->cfg_##attr, val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001984 phba->cfg_##attr = val;\
1985 return 0;\
1986 }\
1987 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -04001988 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1989 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001990 return -EINVAL;\
1991}
1992
James Smarte59058c2008-08-24 21:49:00 -04001993/**
James Smart3621a712009-04-06 18:47:14 -04001994 * lpfc_param_store - Set a vport attribute value
James Smarte59058c2008-08-24 21:49:00 -04001995 *
1996 * Description:
1997 * Macro that given an attr e.g. hba_queue_depth expands
1998 * into a function with the name lpfc_hba_queue_depth_store.
1999 *
2000 * lpfc_##attr##_store: Set an sttribute value.
2001 * @dev: class device that is converted into a Scsi_host.
2002 * @attr: device attribute, not used.
2003 * @buf: contains the attribute value in ascii.
2004 * @count: not used.
2005 *
2006 * Description:
2007 * Convert the ascii text number to an integer, then
2008 * use the lpfc_##attr##_set function to set the value.
2009 *
2010 * Returns:
2011 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2012 * length of buffer upon success.
2013 **/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002014#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -05002015static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002016lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2017 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -05002018{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002019 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -05002020 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2021 struct lpfc_hba *phba = vport->phba;\
James Smart84d1b002010-02-12 14:42:33 -05002022 uint val = 0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04002023 if (!isdigit(buf[0]))\
2024 return -EINVAL;\
2025 if (sscanf(buf, "%i", &val) != 1)\
2026 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002027 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -04002028 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002029 else \
2030 return -EINVAL;\
dea31012005-04-17 16:05:31 -05002031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
James Smart3621a712009-04-06 18:47:14 -04002034 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
James Smarte59058c2008-08-24 21:49:00 -04002035 *
2036 * Description:
2037 * Macro that given an attr e.g. hba_queue_depth expands
2038 * into a function with the name lpfc_hba_queue_depth_show
2039 *
2040 * lpfc_##attr##_show: prints the attribute value in decimal.
2041 * @dev: class device that is converted into a Scsi_host.
2042 * @attr: device attribute, not used.
2043 * @buf: on return contains the attribute value in decimal.
2044 *
2045 * Returns: length of formatted string.
2046 **/
James Smart3de2a652007-08-02 11:09:59 -04002047#define lpfc_vport_param_show(attr) \
2048static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002049lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2050 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002051{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002052 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002053 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002054 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2055}
2056
James Smarte59058c2008-08-24 21:49:00 -04002057/**
James Smart3621a712009-04-06 18:47:14 -04002058 * lpfc_vport_param_hex_show - Return hex formatted attribute value
James Smarte59058c2008-08-24 21:49:00 -04002059 *
2060 * Description:
2061 * Macro that given an attr e.g.
2062 * hba_queue_depth expands into a function with the name
2063 * lpfc_hba_queue_depth_show
2064 *
James Smart3621a712009-04-06 18:47:14 -04002065 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002066 * @dev: class device that is converted into a Scsi_host.
2067 * @attr: device attribute, not used.
James Smart3621a712009-04-06 18:47:14 -04002068 * @buf: on return contains the attribute value in hexadecimal.
James Smarte59058c2008-08-24 21:49:00 -04002069 *
2070 * Returns: length of formatted string.
2071 **/
James Smart3de2a652007-08-02 11:09:59 -04002072#define lpfc_vport_param_hex_show(attr) \
2073static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002074lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2075 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -04002076{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002077 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002078 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart3de2a652007-08-02 11:09:59 -04002079 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2080}
2081
James Smarte59058c2008-08-24 21:49:00 -04002082/**
James Smart3621a712009-04-06 18:47:14 -04002083 * lpfc_vport_param_init - Initialize a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002084 *
2085 * Description:
2086 * Macro that given an attr e.g. hba_queue_depth expands
2087 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2088 * takes a default argument, a minimum and maximum argument.
2089 *
2090 * lpfc_##attr##_init: validates the min and max values then sets the
2091 * adapter config field accordingly, or uses the default if out of range
2092 * and prints an error message.
2093 * @phba: pointer the the adapter structure.
2094 * @val: integer attribute value.
2095 *
2096 * Returns:
2097 * zero on success
2098 * -EINVAL if default used
2099 **/
James Smart3de2a652007-08-02 11:09:59 -04002100#define lpfc_vport_param_init(attr, default, minval, maxval) \
2101static int \
James Smart84d1b002010-02-12 14:42:33 -05002102lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002103{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002104 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart3de2a652007-08-02 11:09:59 -04002105 vport->cfg_##attr = val;\
2106 return 0;\
2107 }\
James Smarte8b62012007-08-02 11:10:09 -04002108 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002109 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002110 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002111 vport->cfg_##attr = default;\
2112 return -EINVAL;\
2113}
2114
James Smarte59058c2008-08-24 21:49:00 -04002115/**
James Smart3621a712009-04-06 18:47:14 -04002116 * lpfc_vport_param_set - Set a vport cfg attribute
James Smarte59058c2008-08-24 21:49:00 -04002117 *
2118 * Description:
2119 * Macro that given an attr e.g. hba_queue_depth expands
2120 * into a function with the name lpfc_hba_queue_depth_set
2121 *
2122 * lpfc_##attr##_set: validates the min and max values then sets the
2123 * adapter config field if in the valid range. prints error message
2124 * and does not set the parameter if invalid.
2125 * @phba: pointer the the adapter structure.
2126 * @val: integer attribute value.
2127 *
2128 * Returns:
2129 * zero on success
2130 * -EINVAL if val is invalid
2131 **/
James Smart3de2a652007-08-02 11:09:59 -04002132#define lpfc_vport_param_set(attr, default, minval, maxval) \
2133static int \
James Smart84d1b002010-02-12 14:42:33 -05002134lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
James Smart3de2a652007-08-02 11:09:59 -04002135{ \
Arnd Bergmannde8c36b2016-06-15 22:42:17 +02002136 if (lpfc_rangecheck(val, minval, maxval)) {\
James Smart88a2cfb2011-07-22 18:36:33 -04002137 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smart14660f42013-09-06 12:20:20 -04002138 "3053 lpfc_" #attr \
2139 " changed from %d (x%x) to %d (x%x)\n", \
2140 vport->cfg_##attr, vport->cfg_##attr, \
2141 val, val); \
James Smart3de2a652007-08-02 11:09:59 -04002142 vport->cfg_##attr = val;\
2143 return 0;\
2144 }\
James Smarte8b62012007-08-02 11:10:09 -04002145 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
James Smartd7c255b2008-08-24 21:50:00 -04002146 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
James Smarte8b62012007-08-02 11:10:09 -04002147 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -04002148 return -EINVAL;\
2149}
2150
James Smarte59058c2008-08-24 21:49:00 -04002151/**
James Smart3621a712009-04-06 18:47:14 -04002152 * lpfc_vport_param_store - Set a vport attribute
James Smarte59058c2008-08-24 21:49:00 -04002153 *
2154 * Description:
2155 * Macro that given an attr e.g. hba_queue_depth
2156 * expands into a function with the name lpfc_hba_queue_depth_store
2157 *
2158 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2159 * use the lpfc_##attr##_set function to set the value.
2160 * @cdev: class device that is converted into a Scsi_host.
2161 * @buf: contains the attribute value in decimal.
2162 * @count: not used.
2163 *
2164 * Returns:
2165 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2166 * length of buffer upon success.
2167 **/
James Smart3de2a652007-08-02 11:09:59 -04002168#define lpfc_vport_param_store(attr) \
2169static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002170lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2171 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -04002172{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002173 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -04002174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
James Smart84d1b002010-02-12 14:42:33 -05002175 uint val = 0;\
James Smart3de2a652007-08-02 11:09:59 -04002176 if (!isdigit(buf[0]))\
2177 return -EINVAL;\
2178 if (sscanf(buf, "%i", &val) != 1)\
2179 return -EINVAL;\
2180 if (lpfc_##attr##_set(vport, val) == 0) \
2181 return strlen(buf);\
2182 else \
2183 return -EINVAL;\
2184}
2185
2186
James Smart895427b2017-02-12 13:52:30 -08002187static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
James Smart81301a92008-12-04 22:39:46 -05002188static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2189static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2190static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2191static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002192static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2193static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2194static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2195static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2196static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2197static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2198static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2199static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
James Smart84d1b002010-02-12 14:42:33 -05002200static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2201 lpfc_link_state_store);
Tony Jonesee959b02008-02-22 00:13:36 +01002202static DEVICE_ATTR(option_rom_version, S_IRUGO,
2203 lpfc_option_rom_version_show, NULL);
2204static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2205 lpfc_num_discovered_ports_show, NULL);
James Smart84774a42008-08-24 21:50:06 -04002206static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002207static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2208static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
James Smart45ed1192009-10-02 15:17:02 -04002209static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
Tony Jonesee959b02008-02-22 00:13:36 +01002210static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2211 lpfc_board_mode_show, lpfc_board_mode_store);
2212static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2213static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2214static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2215static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2216static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2217static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2218static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2219static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2220static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
James Smartbc739052010-08-04 16:11:18 -04002221static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2222static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
James Smartab56dc22011-02-16 12:39:57 -05002223static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
James Smart912e3ac2011-05-24 11:42:11 -04002224static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2225 lpfc_sriov_hw_max_virtfn_show, NULL);
James Smart026abb82011-12-13 13:20:45 -05002226static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
James Smart1ba981f2014-02-20 09:56:45 -05002227static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2228 NULL);
James Smartc3f28af2006-08-18 17:47:18 -04002229
James Smart352e5fd2016-12-30 06:57:47 -08002230static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smart1ba981f2014-02-20 09:56:45 -05002231#define WWN_SZ 8
2232/**
2233 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2234 * @buf: WWN string.
2235 * @cnt: Length of string.
2236 * @wwn: Array to receive converted wwn value.
2237 *
2238 * Returns:
2239 * -EINVAL if the buffer does not contain a valid wwn
2240 * 0 success
2241 **/
2242static size_t
2243lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2244{
2245 unsigned int i, j;
James Smartc3f28af2006-08-18 17:47:18 -04002246
James Smart1ba981f2014-02-20 09:56:45 -05002247 /* Count may include a LF at end of string */
2248 if (buf[cnt-1] == '\n')
2249 cnt--;
2250
2251 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2252 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2253 return -EINVAL;
2254
2255 memset(wwn, 0, WWN_SZ);
2256
2257 /* Validate and store the new name */
2258 for (i = 0, j = 0; i < 16; i++) {
2259 if ((*buf >= 'a') && (*buf <= 'f'))
2260 j = ((j << 4) | ((*buf++ - 'a') + 10));
2261 else if ((*buf >= 'A') && (*buf <= 'F'))
2262 j = ((j << 4) | ((*buf++ - 'A') + 10));
2263 else if ((*buf >= '0') && (*buf <= '9'))
2264 j = ((j << 4) | (*buf++ - '0'));
2265 else
2266 return -EINVAL;
2267 if (i % 2) {
2268 wwn[i/2] = j & 0xff;
2269 j = 0;
2270 }
2271 }
2272 return 0;
2273}
James Smart352e5fd2016-12-30 06:57:47 -08002274/**
2275 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2276 * @dev: class device that is converted into a Scsi_host.
2277 * @attr: device attribute, not used.
2278 * @buf: containing the string lpfc_soft_wwn_key.
2279 * @count: must be size of lpfc_soft_wwn_key.
2280 *
2281 * Returns:
2282 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2283 * length of buf indicates success
2284 **/
2285static ssize_t
2286lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2287 const char *buf, size_t count)
2288{
2289 struct Scsi_Host *shost = class_to_shost(dev);
2290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2291 struct lpfc_hba *phba = vport->phba;
2292 unsigned int cnt = count;
2293
2294 /*
2295 * We're doing a simple sanity check for soft_wwpn setting.
2296 * We require that the user write a specific key to enable
2297 * the soft_wwpn attribute to be settable. Once the attribute
2298 * is written, the enable key resets. If further updates are
2299 * desired, the key must be written again to re-enable the
2300 * attribute.
2301 *
2302 * The "key" is not secret - it is a hardcoded string shown
2303 * here. The intent is to protect against the random user or
2304 * application that is just writing attributes.
2305 */
2306
2307 /* count may include a LF at end of string */
2308 if (buf[cnt-1] == '\n')
2309 cnt--;
2310
2311 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2312 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2313 return -EINVAL;
2314
2315 phba->soft_wwn_enable = 1;
2316
2317 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2318 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2319 phba->brd_no);
2320 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2321 " The soft_wwpn feature is not supported by Broadcom.");
2322
2323 return count;
2324}
2325static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2326 lpfc_soft_wwn_enable_store);
2327
2328/**
2329 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2330 * @dev: class device that is converted into a Scsi_host.
2331 * @attr: device attribute, not used.
2332 * @buf: on return contains the wwpn in hexadecimal.
2333 *
2334 * Returns: size of formatted string.
2335 **/
2336static ssize_t
2337lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2338 char *buf)
2339{
2340 struct Scsi_Host *shost = class_to_shost(dev);
2341 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2342 struct lpfc_hba *phba = vport->phba;
2343
2344 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2345 (unsigned long long)phba->cfg_soft_wwpn);
2346}
2347
2348/**
2349 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2350 * @dev class device that is converted into a Scsi_host.
2351 * @attr: device attribute, not used.
2352 * @buf: contains the wwpn in hexadecimal.
2353 * @count: number of wwpn bytes in buf
2354 *
2355 * Returns:
2356 * -EACCES hba reset not enabled, adapter over temp
2357 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2358 * -EIO error taking adapter offline or online
2359 * value of count on success
2360 **/
2361static ssize_t
2362lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2363 const char *buf, size_t count)
2364{
2365 struct Scsi_Host *shost = class_to_shost(dev);
2366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2367 struct lpfc_hba *phba = vport->phba;
2368 struct completion online_compl;
2369 int stat1 = 0, stat2 = 0;
2370 unsigned int cnt = count;
2371 u8 wwpn[WWN_SZ];
2372 int rc;
2373
2374 if (!phba->cfg_enable_hba_reset)
2375 return -EACCES;
2376 spin_lock_irq(&phba->hbalock);
2377 if (phba->over_temp_state == HBA_OVER_TEMP) {
2378 spin_unlock_irq(&phba->hbalock);
2379 return -EACCES;
2380 }
2381 spin_unlock_irq(&phba->hbalock);
2382 /* count may include a LF at end of string */
2383 if (buf[cnt-1] == '\n')
2384 cnt--;
2385
2386 if (!phba->soft_wwn_enable)
2387 return -EINVAL;
2388
2389 /* lock setting wwpn, wwnn down */
2390 phba->soft_wwn_enable = 0;
2391
2392 rc = lpfc_wwn_set(buf, cnt, wwpn);
James Smarte2934ed2017-01-17 12:31:56 -08002393 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002394 /* not able to set wwpn, unlock it */
2395 phba->soft_wwn_enable = 1;
2396 return rc;
2397 }
2398
2399 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2400 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2401 if (phba->cfg_soft_wwnn)
2402 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2403
2404 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2405 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2406
2407 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2408 if (stat1)
2409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2410 "0463 lpfc_soft_wwpn attribute set failed to "
2411 "reinit adapter - %d\n", stat1);
2412 init_completion(&online_compl);
2413 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2414 LPFC_EVT_ONLINE);
2415 if (rc == 0)
2416 return -ENOMEM;
2417
2418 wait_for_completion(&online_compl);
2419 if (stat2)
2420 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2421 "0464 lpfc_soft_wwpn attribute set failed to "
2422 "reinit adapter - %d\n", stat2);
2423 return (stat1 || stat2) ? -EIO : count;
2424}
2425static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2426 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2427
2428/**
2429 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2430 * @dev: class device that is converted into a Scsi_host.
2431 * @attr: device attribute, not used.
2432 * @buf: on return contains the wwnn in hexadecimal.
2433 *
2434 * Returns: size of formatted string.
2435 **/
2436static ssize_t
2437lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2438 char *buf)
2439{
2440 struct Scsi_Host *shost = class_to_shost(dev);
2441 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2442 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2443 (unsigned long long)phba->cfg_soft_wwnn);
2444}
2445
2446/**
2447 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2448 * @cdev: class device that is converted into a Scsi_host.
2449 * @buf: contains the ww node name in hexadecimal.
2450 * @count: number of wwnn bytes in buf.
2451 *
2452 * Returns:
2453 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2454 * value of count on success
2455 **/
2456static ssize_t
2457lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2458 const char *buf, size_t count)
2459{
2460 struct Scsi_Host *shost = class_to_shost(dev);
2461 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2462 unsigned int cnt = count;
2463 u8 wwnn[WWN_SZ];
2464 int rc;
2465
2466 /* count may include a LF at end of string */
2467 if (buf[cnt-1] == '\n')
2468 cnt--;
2469
2470 if (!phba->soft_wwn_enable)
2471 return -EINVAL;
2472
2473 rc = lpfc_wwn_set(buf, cnt, wwnn);
James Smarte2934ed2017-01-17 12:31:56 -08002474 if (rc) {
James Smart352e5fd2016-12-30 06:57:47 -08002475 /* Allow wwnn to be set many times, as long as the enable
2476 * is set. However, once the wwpn is set, everything locks.
2477 */
2478 return rc;
2479 }
2480
2481 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2482
2483 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2484 "lpfc%d: soft_wwnn set. Value will take effect upon "
2485 "setting of the soft_wwpn\n", phba->brd_no);
2486
2487 return count;
2488}
2489static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2490 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05002491
James Smart1ba981f2014-02-20 09:56:45 -05002492/**
2493 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2494 * Optimized Access Storage (OAS) operations.
2495 * @dev: class device that is converted into a Scsi_host.
2496 * @attr: device attribute, not used.
2497 * @buf: buffer for passing information.
2498 *
2499 * Returns:
2500 * value of count
2501 **/
2502static ssize_t
2503lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2504 char *buf)
2505{
2506 struct Scsi_Host *shost = class_to_shost(dev);
2507 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2508
2509 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2510 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2511}
2512
2513/**
2514 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2515 * Optimized Access Storage (OAS) operations.
2516 * @dev: class device that is converted into a Scsi_host.
2517 * @attr: device attribute, not used.
2518 * @buf: buffer for passing information.
2519 * @count: Size of the data buffer.
2520 *
2521 * Returns:
2522 * -EINVAL count is invalid, invalid wwpn byte invalid
2523 * -EPERM oas is not supported by hba
2524 * value of count on success
2525 **/
2526static ssize_t
2527lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2528 const char *buf, size_t count)
2529{
2530 struct Scsi_Host *shost = class_to_shost(dev);
2531 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2532 unsigned int cnt = count;
2533 uint8_t wwpn[WWN_SZ];
2534 int rc;
2535
James Smartf38fa0b2014-04-04 13:52:21 -04002536 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002537 return -EPERM;
2538
2539 /* count may include a LF at end of string */
2540 if (buf[cnt-1] == '\n')
2541 cnt--;
2542
2543 rc = lpfc_wwn_set(buf, cnt, wwpn);
2544 if (rc)
2545 return rc;
2546
2547 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2548 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2549 if (wwn_to_u64(wwpn) == 0)
2550 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2551 else
2552 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2553 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2554 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2555 return count;
2556}
2557static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2558 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2559
2560/**
James Smartc92c8412016-07-06 12:36:05 -07002561 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2562 * Optimized Access Storage (OAS) operations.
2563 * @dev: class device that is converted into a Scsi_host.
2564 * @attr: device attribute, not used.
2565 * @buf: buffer for passing information.
2566 *
2567 * Returns:
2568 * value of count
2569 **/
2570static ssize_t
2571lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2572 char *buf)
2573{
2574 struct Scsi_Host *shost = class_to_shost(dev);
2575 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2576
2577 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2578}
2579
2580/**
2581 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2582 * Optimized Access Storage (OAS) operations.
2583 * @dev: class device that is converted into a Scsi_host.
2584 * @attr: device attribute, not used.
2585 * @buf: buffer for passing information.
2586 * @count: Size of the data buffer.
2587 *
2588 * Returns:
2589 * -EINVAL count is invalid, invalid wwpn byte invalid
2590 * -EPERM oas is not supported by hba
2591 * value of count on success
2592 **/
2593static ssize_t
2594lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2595 const char *buf, size_t count)
2596{
2597 struct Scsi_Host *shost = class_to_shost(dev);
2598 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2599 unsigned int cnt = count;
2600 unsigned long val;
2601 int ret;
2602
2603 if (!phba->cfg_fof)
2604 return -EPERM;
2605
2606 /* count may include a LF at end of string */
2607 if (buf[cnt-1] == '\n')
2608 cnt--;
2609
2610 ret = kstrtoul(buf, 0, &val);
2611 if (ret || (val > 0x7f))
2612 return -EINVAL;
2613
2614 if (val)
2615 phba->cfg_oas_priority = (uint8_t)val;
2616 else
2617 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2618 return count;
2619}
2620static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2621 lpfc_oas_priority_show, lpfc_oas_priority_store);
2622
2623/**
James Smart1ba981f2014-02-20 09:56:45 -05002624 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2625 * for Optimized Access Storage (OAS) operations.
2626 * @dev: class device that is converted into a Scsi_host.
2627 * @attr: device attribute, not used.
2628 * @buf: buffer for passing information.
2629 *
2630 * Returns:
2631 * value of count on success
2632 **/
2633static ssize_t
2634lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2635 char *buf)
2636{
2637 struct Scsi_Host *shost = class_to_shost(dev);
2638 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2639
2640 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2641 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2642}
2643
2644/**
2645 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2646 * for Optimized Access Storage (OAS) operations.
2647 * @dev: class device that is converted into a Scsi_host.
2648 * @attr: device attribute, not used.
2649 * @buf: buffer for passing information.
2650 * @count: Size of the data buffer.
2651 *
2652 * Returns:
2653 * -EINVAL count is invalid, invalid wwpn byte invalid
2654 * -EPERM oas is not supported by hba
2655 * value of count on success
2656 **/
2657static ssize_t
2658lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2659 const char *buf, size_t count)
2660{
2661 struct Scsi_Host *shost = class_to_shost(dev);
2662 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2663 unsigned int cnt = count;
2664 uint8_t wwpn[WWN_SZ];
2665 int rc;
2666
James Smartf38fa0b2014-04-04 13:52:21 -04002667 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002668 return -EPERM;
2669
2670 /* count may include a LF at end of string */
2671 if (buf[cnt-1] == '\n')
2672 cnt--;
2673
2674 rc = lpfc_wwn_set(buf, cnt, wwpn);
2675 if (rc)
2676 return rc;
2677
2678 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2679 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2680 if (wwn_to_u64(wwpn) == 0)
2681 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2682 else
2683 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2684 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
James Smartb5749fe2016-12-19 15:07:26 -08002685 if (phba->cfg_oas_priority == 0)
2686 phba->cfg_oas_priority = phba->cfg_XLanePriority;
James Smart1ba981f2014-02-20 09:56:45 -05002687 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2688 return count;
2689}
2690static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2691 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2692
2693/**
2694 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2695 * of whether luns will be enabled or disabled
2696 * for Optimized Access Storage (OAS) operations.
2697 * @dev: class device that is converted into a Scsi_host.
2698 * @attr: device attribute, not used.
2699 * @buf: buffer for passing information.
2700 *
2701 * Returns:
2702 * size of formatted string.
2703 **/
2704static ssize_t
2705lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2706 char *buf)
2707{
2708 struct Scsi_Host *shost = class_to_shost(dev);
2709 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2710
2711 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2712}
2713
2714/**
2715 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2716 * of whether luns will be enabled or disabled
2717 * for Optimized Access Storage (OAS) operations.
2718 * @dev: class device that is converted into a Scsi_host.
2719 * @attr: device attribute, not used.
2720 * @buf: buffer for passing information.
2721 * @count: Size of the data buffer.
2722 *
2723 * Returns:
2724 * -EINVAL count is invalid, invalid wwpn byte invalid
2725 * -EPERM oas is not supported by hba
2726 * value of count on success
2727 **/
2728static ssize_t
2729lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2730 const char *buf, size_t count)
2731{
2732 struct Scsi_Host *shost = class_to_shost(dev);
2733 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2734 int val = 0;
2735
James Smartf38fa0b2014-04-04 13:52:21 -04002736 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002737 return -EPERM;
2738
2739 if (!isdigit(buf[0]))
2740 return -EINVAL;
2741
2742 if (sscanf(buf, "%i", &val) != 1)
2743 return -EINVAL;
2744
2745 if ((val != 0) && (val != 1))
2746 return -EINVAL;
2747
2748 phba->cfg_oas_lun_state = val;
James Smart1ba981f2014-02-20 09:56:45 -05002749 return strlen(buf);
2750}
2751static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2752 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2753
2754/**
2755 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2756 * Storage (OAS) lun returned by the
2757 * lpfc_oas_lun_show function.
2758 * @dev: class device that is converted into a Scsi_host.
2759 * @attr: device attribute, not used.
2760 * @buf: buffer for passing information.
2761 *
2762 * Returns:
2763 * size of formatted string.
2764 **/
2765static ssize_t
2766lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2767 char *buf)
2768{
2769 struct Scsi_Host *shost = class_to_shost(dev);
2770 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2771
2772 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2773 return -EFAULT;
2774
2775 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2776}
2777static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2778 lpfc_oas_lun_status_show, NULL);
2779
2780
2781/**
2782 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2783 * (OAS) operations.
2784 * @phba: lpfc_hba pointer.
2785 * @ndlp: pointer to fcp target node.
2786 * @lun: the fc lun for setting oas state.
2787 * @oas_state: the oas state to be set to the lun.
2788 *
2789 * Returns:
2790 * SUCCESS : 0
2791 * -EPERM OAS is not enabled or not supported by this port.
2792 *
2793 */
2794static size_t
2795lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartc92c8412016-07-06 12:36:05 -07002796 uint8_t tgt_wwpn[], uint64_t lun,
2797 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002798{
2799
2800 int rc = 0;
2801
James Smartf38fa0b2014-04-04 13:52:21 -04002802 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002803 return -EPERM;
2804
2805 if (oas_state) {
2806 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002807 (struct lpfc_name *)tgt_wwpn,
2808 lun, pri))
James Smart1ba981f2014-02-20 09:56:45 -05002809 rc = -ENOMEM;
2810 } else {
2811 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002812 (struct lpfc_name *)tgt_wwpn, lun, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002813 }
2814 return rc;
2815
2816}
2817
2818/**
2819 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2820 * Access Storage (OAS) operations.
2821 * @phba: lpfc_hba pointer.
2822 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2823 * @tgt_wwpn: wwpn of the target associated with the returned lun
2824 * @lun_status: status of the lun returned lun
2825 *
2826 * Returns the first or next lun enabled for OAS operations for the vport/target
2827 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2828 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2829 *
2830 * Return:
2831 * lun that is OAS enabled for the vport/target
2832 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2833 */
2834static uint64_t
2835lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
James Smartb5749fe2016-12-19 15:07:26 -08002836 uint8_t tgt_wwpn[], uint32_t *lun_status,
2837 uint32_t *lun_pri)
James Smart1ba981f2014-02-20 09:56:45 -05002838{
2839 uint64_t found_lun;
2840
2841 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2842 return NOT_OAS_ENABLED_LUN;
2843 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2844 phba->sli4_hba.oas_next_vpt_wwpn,
2845 (struct lpfc_name *)
2846 phba->sli4_hba.oas_next_tgt_wwpn,
2847 &phba->sli4_hba.oas_next_lun,
2848 (struct lpfc_name *)vpt_wwpn,
2849 (struct lpfc_name *)tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002850 &found_lun, lun_status, lun_pri))
James Smart1ba981f2014-02-20 09:56:45 -05002851 return found_lun;
2852 else
2853 return NOT_OAS_ENABLED_LUN;
2854}
2855
2856/**
2857 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2858 * @phba: lpfc_hba pointer.
2859 * @vpt_wwpn: vport wwpn by reference.
2860 * @tgt_wwpn: target wwpn by reference.
2861 * @lun: the fc lun for setting oas state.
2862 * @oas_state: the oas state to be set to the oas_lun.
2863 *
2864 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2865 * a lun for OAS operations.
2866 *
2867 * Return:
2868 * SUCCESS: 0
2869 * -ENOMEM: failed to enable an lun for OAS operations
2870 * -EPERM: OAS is not enabled
2871 */
2872static ssize_t
2873lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2874 uint8_t tgt_wwpn[], uint64_t lun,
James Smartc92c8412016-07-06 12:36:05 -07002875 uint32_t oas_state, uint8_t pri)
James Smart1ba981f2014-02-20 09:56:45 -05002876{
2877
2878 int rc;
2879
2880 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
James Smartc92c8412016-07-06 12:36:05 -07002881 oas_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002882 return rc;
2883}
2884
2885/**
2886 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2887 * @dev: class device that is converted into a Scsi_host.
2888 * @attr: device attribute, not used.
2889 * @buf: buffer for passing information.
2890 *
2891 * This routine returns a lun enabled for OAS each time the function
2892 * is called.
2893 *
2894 * Returns:
2895 * SUCCESS: size of formatted string.
2896 * -EFAULT: target or vport wwpn was not set properly.
2897 * -EPERM: oas is not enabled.
2898 **/
2899static ssize_t
2900lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2901 char *buf)
2902{
2903 struct Scsi_Host *shost = class_to_shost(dev);
2904 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2905
2906 uint64_t oas_lun;
2907 int len = 0;
2908
James Smartf38fa0b2014-04-04 13:52:21 -04002909 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002910 return -EPERM;
2911
2912 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2913 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2914 return -EFAULT;
2915
2916 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2917 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2918 return -EFAULT;
2919
2920 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2921 phba->cfg_oas_tgt_wwpn,
James Smartb5749fe2016-12-19 15:07:26 -08002922 &phba->cfg_oas_lun_status,
2923 &phba->cfg_oas_priority);
James Smart1ba981f2014-02-20 09:56:45 -05002924 if (oas_lun != NOT_OAS_ENABLED_LUN)
2925 phba->cfg_oas_flags |= OAS_LUN_VALID;
2926
2927 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2928
2929 return len;
2930}
2931
2932/**
2933 * lpfc_oas_lun_store - Sets the OAS state for lun
2934 * @dev: class device that is converted into a Scsi_host.
2935 * @attr: device attribute, not used.
2936 * @buf: buffer for passing information.
2937 *
2938 * This function sets the OAS state for lun. Before this function is called,
2939 * the vport wwpn, target wwpn, and oas state need to be set.
2940 *
2941 * Returns:
2942 * SUCCESS: size of formatted string.
2943 * -EFAULT: target or vport wwpn was not set properly.
2944 * -EPERM: oas is not enabled.
2945 * size of formatted string.
2946 **/
2947static ssize_t
2948lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2949 const char *buf, size_t count)
2950{
2951 struct Scsi_Host *shost = class_to_shost(dev);
2952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2953 uint64_t scsi_lun;
James Smartb5749fe2016-12-19 15:07:26 -08002954 uint32_t pri;
James Smart1ba981f2014-02-20 09:56:45 -05002955 ssize_t rc;
2956
James Smartf38fa0b2014-04-04 13:52:21 -04002957 if (!phba->cfg_fof)
James Smart1ba981f2014-02-20 09:56:45 -05002958 return -EPERM;
2959
2960 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2961 return -EFAULT;
2962
2963 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2964 return -EFAULT;
2965
2966 if (!isdigit(buf[0]))
2967 return -EINVAL;
2968
2969 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
2970 return -EINVAL;
2971
James Smartb5749fe2016-12-19 15:07:26 -08002972 pri = phba->cfg_oas_priority;
2973 if (pri == 0)
2974 pri = phba->cfg_XLanePriority;
2975
James Smart1ba981f2014-02-20 09:56:45 -05002976 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
James Smartc92c8412016-07-06 12:36:05 -07002977 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
2978 "priority 0x%x with oas state %d\n",
James Smart1ba981f2014-02-20 09:56:45 -05002979 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
2980 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002981 pri, phba->cfg_oas_lun_state);
James Smart1ba981f2014-02-20 09:56:45 -05002982
2983 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
James Smartc92c8412016-07-06 12:36:05 -07002984 phba->cfg_oas_tgt_wwpn, scsi_lun,
James Smartb5749fe2016-12-19 15:07:26 -08002985 phba->cfg_oas_lun_state, pri);
James Smart1ba981f2014-02-20 09:56:45 -05002986 if (rc)
2987 return rc;
2988
2989 return count;
2990}
2991static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
2992 lpfc_oas_lun_show, lpfc_oas_lun_store);
James Smartc3f28af2006-08-18 17:47:18 -04002993
James Smartf358dd02017-02-12 13:52:34 -08002994int lpfc_enable_nvmet_cnt;
2995unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
2996 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2997 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2998module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
2999MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3000
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003001static int lpfc_poll = 0;
James Smartab56dc22011-02-16 12:39:57 -05003002module_param(lpfc_poll, int, S_IRUGO);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05003003MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3004 " 0 - none,"
3005 " 1 - poll with interrupts enabled"
3006 " 3 - poll and disable FCP ring interrupts");
3007
Tony Jonesee959b02008-02-22 00:13:36 +01003008static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3009 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05003010
James Smart12247e82016-07-06 12:36:09 -07003011LPFC_ATTR(sli_mode, 0, 0, 3,
3012 "SLI mode selector:"
3013 " 0 - auto (SLI-3 if supported),"
3014 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3015 " 3 - select SLI-3");
James Smart92d7f7b2007-06-17 19:56:38 -05003016
James Smart458c0832016-07-06 12:36:07 -07003017LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3018 "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05003019
James Smart7d791df2011-07-22 18:37:52 -04003020LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3021 "FCF Fast failover=1 Priority failover=2");
3022
James Smarte5771b42013-03-01 16:37:14 -05003023/*
3024# lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3025# 0x0 = disabled, XRI/OXID use not tracked.
3026# 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3027# 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3028*/
James Smart31202b02016-10-13 15:06:08 -07003029LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3030 "Enable RRQ functionality");
James Smart19ca7602010-11-20 23:11:55 -05003031
dea31012005-04-17 16:05:31 -05003032/*
James Smart84d1b002010-02-12 14:42:33 -05003033# lpfc_suppress_link_up: Bring link up at initialization
3034# 0x0 = bring link up (issue MBX_INIT_LINK)
3035# 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3036# 0x2 = never bring up link
3037# Default value is 0.
3038*/
James Smarte40a02c2010-02-26 14:13:54 -05003039LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3040 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3041 "Suppress Link Up at initialization");
James Smart2a9bf3d2010-06-07 15:24:45 -04003042/*
3043# lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3044# 1 - (1024)
3045# 2 - (2048)
3046# 3 - (3072)
3047# 4 - (4096)
3048# 5 - (5120)
3049*/
3050static ssize_t
3051lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3052{
3053 struct Scsi_Host *shost = class_to_shost(dev);
3054 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3055
3056 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3057}
3058
3059static DEVICE_ATTR(iocb_hw, S_IRUGO,
3060 lpfc_iocb_hw_show, NULL);
3061static ssize_t
3062lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3063{
3064 struct Scsi_Host *shost = class_to_shost(dev);
3065 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003066 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003067
James Smart895427b2017-02-12 13:52:30 -08003068 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003069}
3070
3071static DEVICE_ATTR(txq_hw, S_IRUGO,
3072 lpfc_txq_hw_show, NULL);
3073static ssize_t
3074lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3075 char *buf)
3076{
3077 struct Scsi_Host *shost = class_to_shost(dev);
3078 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
James Smart895427b2017-02-12 13:52:30 -08003079 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
James Smart2a9bf3d2010-06-07 15:24:45 -04003080
James Smart895427b2017-02-12 13:52:30 -08003081 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
James Smart2a9bf3d2010-06-07 15:24:45 -04003082}
3083
3084static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3085 lpfc_txcmplq_hw_show, NULL);
3086
James Smart0d8c8ba2016-10-13 15:06:07 -07003087LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
James Smart2a9bf3d2010-06-07 15:24:45 -04003088 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
James Smart84d1b002010-02-12 14:42:33 -05003089
3090/*
James Smartc01f3202006-08-18 17:47:08 -04003091# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3092# until the timer expires. Value range is [0,255]. Default value is 30.
3093*/
3094static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3095static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3096module_param(lpfc_nodev_tmo, int, 0);
3097MODULE_PARM_DESC(lpfc_nodev_tmo,
3098 "Seconds driver will hold I/O waiting "
3099 "for a device to come back");
James Smarte59058c2008-08-24 21:49:00 -04003100
3101/**
James Smart3621a712009-04-06 18:47:14 -04003102 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
James Smarte59058c2008-08-24 21:49:00 -04003103 * @dev: class converted to a Scsi_host structure.
3104 * @attr: device attribute, not used.
3105 * @buf: on return contains the dev loss timeout in decimal.
3106 *
3107 * Returns: size of formatted string.
3108 **/
James Smartc01f3202006-08-18 17:47:08 -04003109static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01003110lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3111 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04003112{
Tony Jonesee959b02008-02-22 00:13:36 +01003113 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05003114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smarte40a02c2010-02-26 14:13:54 -05003115
James Smart3de2a652007-08-02 11:09:59 -04003116 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04003117}
3118
James Smarte59058c2008-08-24 21:49:00 -04003119/**
James Smart3621a712009-04-06 18:47:14 -04003120 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
James Smarte59058c2008-08-24 21:49:00 -04003121 * @vport: lpfc vport structure pointer.
3122 * @val: contains the nodev timeout value.
3123 *
3124 * Description:
3125 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3126 * a kernel error message is printed and zero is returned.
3127 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3128 * Otherwise nodev tmo is set to the default value.
3129 *
3130 * Returns:
3131 * zero if already set or if val is in range
3132 * -EINVAL val out of range
3133 **/
James Smartc01f3202006-08-18 17:47:08 -04003134static int
James Smart3de2a652007-08-02 11:09:59 -04003135lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003136{
James Smart3de2a652007-08-02 11:09:59 -04003137 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3138 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3139 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04003140 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003141 "0407 Ignoring lpfc_nodev_tmo module "
3142 "parameter because lpfc_devloss_tmo "
3143 "is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003144 return 0;
3145 }
3146
3147 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003148 vport->cfg_nodev_tmo = val;
3149 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04003150 return 0;
3151 }
James Smarte8b62012007-08-02 11:10:09 -04003152 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3153 "0400 lpfc_nodev_tmo attribute cannot be set to"
3154 " %d, allowed range is [%d, %d]\n",
3155 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04003156 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04003157 return -EINVAL;
3158}
3159
James Smarte59058c2008-08-24 21:49:00 -04003160/**
James Smart3621a712009-04-06 18:47:14 -04003161 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
James Smarte59058c2008-08-24 21:49:00 -04003162 * @vport: lpfc vport structure pointer.
3163 *
3164 * Description:
3165 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3166 **/
James Smart7054a602007-04-25 09:52:34 -04003167static void
James Smart3de2a652007-08-02 11:09:59 -04003168lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04003169{
James Smart858c9f62007-06-17 19:56:39 -05003170 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04003171 struct lpfc_nodelist *ndlp;
3172
James Smart51ef4c22007-08-02 11:10:31 -04003173 shost = lpfc_shost_from_vport(vport);
3174 spin_lock_irq(shost->host_lock);
3175 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05003176 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04003177 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3178 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04003179}
3180
James Smarte59058c2008-08-24 21:49:00 -04003181/**
James Smart3621a712009-04-06 18:47:14 -04003182 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
James Smarte59058c2008-08-24 21:49:00 -04003183 * @vport: lpfc vport structure pointer.
3184 * @val: contains the tmo value.
3185 *
3186 * Description:
3187 * If the devloss tmo is already set or the vport dev loss tmo has changed
3188 * then a kernel error message is printed and zero is returned.
3189 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3190 * Otherwise nodev tmo is set to the default value.
3191 *
3192 * Returns:
3193 * zero if already set or if val is in range
3194 * -EINVAL val out of range
3195 **/
James Smartc01f3202006-08-18 17:47:08 -04003196static int
James Smart3de2a652007-08-02 11:09:59 -04003197lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003198{
James Smart3de2a652007-08-02 11:09:59 -04003199 if (vport->dev_loss_tmo_changed ||
3200 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04003201 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003202 "0401 Ignoring change to lpfc_nodev_tmo "
3203 "because lpfc_devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04003204 return 0;
3205 }
James Smartc01f3202006-08-18 17:47:08 -04003206 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003207 vport->cfg_nodev_tmo = val;
3208 vport->cfg_devloss_tmo = val;
Mike Christie0af5d702010-09-15 16:52:31 -05003209 /*
3210 * For compat: set the fc_host dev loss so new rports
3211 * will get the value.
3212 */
3213 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003214 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003215 return 0;
3216 }
James Smarte8b62012007-08-02 11:10:09 -04003217 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003218 "0403 lpfc_nodev_tmo attribute cannot be set to "
James Smarte8b62012007-08-02 11:10:09 -04003219 "%d, allowed range is [%d, %d]\n",
3220 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003221 return -EINVAL;
3222}
3223
James Smart3de2a652007-08-02 11:09:59 -04003224lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04003225
Tony Jonesee959b02008-02-22 00:13:36 +01003226static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3227 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003228
3229/*
3230# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3231# disappear until the timer expires. Value range is [0,255]. Default
3232# value is 30.
3233*/
James Smartab56dc22011-02-16 12:39:57 -05003234module_param(lpfc_devloss_tmo, int, S_IRUGO);
James Smartc01f3202006-08-18 17:47:08 -04003235MODULE_PARM_DESC(lpfc_devloss_tmo,
3236 "Seconds driver will hold I/O waiting "
3237 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04003238lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3239 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3240lpfc_vport_param_show(devloss_tmo)
James Smarte59058c2008-08-24 21:49:00 -04003241
3242/**
James Smart3621a712009-04-06 18:47:14 -04003243 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
James Smarte59058c2008-08-24 21:49:00 -04003244 * @vport: lpfc vport structure pointer.
3245 * @val: contains the tmo value.
3246 *
3247 * Description:
3248 * If val is in a valid range then set the vport nodev tmo,
3249 * devloss tmo, also set the vport dev loss tmo changed flag.
3250 * Else a kernel error message is printed.
3251 *
3252 * Returns:
3253 * zero if val is in range
3254 * -EINVAL val out of range
3255 **/
James Smartc01f3202006-08-18 17:47:08 -04003256static int
James Smart3de2a652007-08-02 11:09:59 -04003257lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04003258{
3259 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04003260 vport->cfg_nodev_tmo = val;
3261 vport->cfg_devloss_tmo = val;
3262 vport->dev_loss_tmo_changed = 1;
Mike Christie0af5d702010-09-15 16:52:31 -05003263 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
James Smart3de2a652007-08-02 11:09:59 -04003264 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04003265 return 0;
3266 }
3267
James Smarte8b62012007-08-02 11:10:09 -04003268 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07003269 "0404 lpfc_devloss_tmo attribute cannot be set to "
3270 "%d, allowed range is [%d, %d]\n",
James Smarte8b62012007-08-02 11:10:09 -04003271 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04003272 return -EINVAL;
3273}
3274
James Smart3de2a652007-08-02 11:09:59 -04003275lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01003276static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3277 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04003278
3279/*
James Smartf358dd02017-02-12 13:52:34 -08003280 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3281 * lpfc_suppress_rsp = 0 Disable
3282 * lpfc_suppress_rsp = 1 Enable (default)
3283 *
3284 */
3285LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3286 "Enable suppress rsp feature is firmware supports it");
3287
3288/*
James Smart2d7dbc42017-02-12 13:52:35 -08003289 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3290 * lpfc_nvmet_mrq = 1 use a single RQ pair
3291 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3292 *
3293 */
3294LPFC_ATTR_R(nvmet_mrq,
3295 1, 1, 16,
3296 "Specify number of RQ pairs for processing NVMET cmds");
3297
3298/*
3299 * lpfc_nvmet_mrq_post: Specify number buffers to post on every MRQ
3300 *
3301 */
3302LPFC_ATTR_R(nvmet_mrq_post, LPFC_DEF_MRQ_POST,
3303 LPFC_MIN_MRQ_POST, LPFC_MAX_MRQ_POST,
3304 "Specify number of buffers to post on every MRQ");
3305
3306/*
James Smart895427b2017-02-12 13:52:30 -08003307 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3308 * Supported Values: 1 - register just FCP
3309 * 3 - register both FCP and NVME
3310 * Supported values are [1,3]. Default value is 3
3311 */
3312LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_BOTH,
3313 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3314 "Define fc4 type to register with fabric.");
3315
3316/*
3317 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3318 * This parameter is only used if:
James Smartf358dd02017-02-12 13:52:34 -08003319 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3320 * port is not configured for NVMET.
James Smart895427b2017-02-12 13:52:30 -08003321 *
3322 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3323 * The remaining XRIs get split up based on lpfc_xri_split per port:
3324 *
3325 * Supported Values are in percentages
3326 * the xri_split value is the percentage the SCSI port will get. The remaining
3327 * percentage will go to NVME.
3328 */
3329LPFC_ATTR_R(xri_split, 50, 10, 90,
3330 "Division of XRI resources between SCSI and NVME");
3331
3332/*
dea31012005-04-17 16:05:31 -05003333# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3334# deluged with LOTS of information.
3335# You can set a bit mask to record specific types of verbose messages:
James Smartf4b4c682009-05-22 14:53:12 -04003336# See lpfc_logmsh.h for definitions.
dea31012005-04-17 16:05:31 -05003337*/
James Smartf4b4c682009-05-22 14:53:12 -04003338LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
James Smarte8b62012007-08-02 11:10:09 -04003339 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05003340
3341/*
James Smart7ee5d432007-10-27 13:37:17 -04003342# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3343# objects that have been registered with the nameserver after login.
3344*/
James Smartcf971242012-03-01 22:37:32 -05003345LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
James Smart7ee5d432007-10-27 13:37:17 -04003346 "Deregister nameserver objects before LOGO");
3347
3348/*
dea31012005-04-17 16:05:31 -05003349# lun_queue_depth: This parameter is used to limit the number of outstanding
James Smart572709e2013-07-15 18:32:43 -04003350# commands per FCP LUN. Value range is [1,512]. Default value is 30.
3351# If this parameter value is greater than 1/8th the maximum number of exchanges
3352# supported by the HBA port, then the lun queue depth will be reduced to
3353# 1/8th the maximum number of exchanges.
dea31012005-04-17 16:05:31 -05003354*/
James Smart572709e2013-07-15 18:32:43 -04003355LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
James Smart3de2a652007-08-02 11:09:59 -04003356 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05003357
3358/*
James Smart7dc517d2010-07-14 15:32:10 -04003359# tgt_queue_depth: This parameter is used to limit the number of outstanding
3360# commands per target port. Value range is [10,65535]. Default value is 65535.
3361*/
3362LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
James Smart572709e2013-07-15 18:32:43 -04003363 "Max number of FCP commands we can queue to a specific target port");
James Smart7dc517d2010-07-14 15:32:10 -04003364
3365/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05003366# hba_queue_depth: This parameter is used to limit the number of outstanding
3367# commands per lpfc HBA. Value range is [32,8192]. If this parameter
3368# value is greater than the maximum number of exchanges supported by the HBA,
3369# then maximum number of exchanges supported by the HBA is used to determine
3370# the hba_queue_depth.
3371*/
3372LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3373 "Max number of FCP commands we can queue to a lpfc HBA");
3374
3375/*
James Smart92d7f7b2007-06-17 19:56:38 -05003376# peer_port_login: This parameter allows/prevents logins
3377# between peer ports hosted on the same physical port.
3378# When this parameter is set 0 peer ports of same physical port
3379# are not allowed to login to each other.
3380# When this parameter is set 1 peer ports of same physical port
3381# are allowed to login to each other.
3382# Default value of this parameter is 0.
3383*/
James Smart3de2a652007-08-02 11:09:59 -04003384LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3385 "Allow peer ports on the same physical port to login to each "
3386 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05003387
3388/*
James Smart3de2a652007-08-02 11:09:59 -04003389# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05003390# between Virtual Ports and remote initiators.
3391# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3392# other initiators and will attempt to PLOGI all remote ports.
3393# When this parameter is set (1) Virtual Ports will reject PLOGIs from
3394# remote ports and will not attempt to PLOGI to other initiators.
3395# This parameter does not restrict to the physical port.
3396# This parameter does not restrict logins to Fabric resident remote ports.
3397# Default value of this parameter is 1.
3398*/
James Smart3de2a652007-08-02 11:09:59 -04003399static int lpfc_restrict_login = 1;
James Smartab56dc22011-02-16 12:39:57 -05003400module_param(lpfc_restrict_login, int, S_IRUGO);
James Smart3de2a652007-08-02 11:09:59 -04003401MODULE_PARM_DESC(lpfc_restrict_login,
3402 "Restrict virtual ports login to remote initiators.");
3403lpfc_vport_param_show(restrict_login);
3404
James Smarte59058c2008-08-24 21:49:00 -04003405/**
James Smart3621a712009-04-06 18:47:14 -04003406 * lpfc_restrict_login_init - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003407 * @vport: lpfc vport structure pointer.
3408 * @val: contains the restrict login value.
3409 *
3410 * Description:
3411 * If val is not in a valid range then log a kernel error message and set
3412 * the vport restrict login to one.
3413 * If the port type is physical clear the restrict login flag and return.
3414 * Else set the restrict login flag to val.
3415 *
3416 * Returns:
3417 * zero if val is in range
3418 * -EINVAL val out of range
3419 **/
James Smart3de2a652007-08-02 11:09:59 -04003420static int
3421lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3422{
3423 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003424 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003425 "0422 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003426 "be set to %d, allowed range is [0, 1]\n",
3427 val);
James Smart3de2a652007-08-02 11:09:59 -04003428 vport->cfg_restrict_login = 1;
3429 return -EINVAL;
3430 }
3431 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3432 vport->cfg_restrict_login = 0;
3433 return 0;
3434 }
3435 vport->cfg_restrict_login = val;
3436 return 0;
3437}
3438
James Smarte59058c2008-08-24 21:49:00 -04003439/**
James Smart3621a712009-04-06 18:47:14 -04003440 * lpfc_restrict_login_set - Set the vport restrict login flag
James Smarte59058c2008-08-24 21:49:00 -04003441 * @vport: lpfc vport structure pointer.
3442 * @val: contains the restrict login value.
3443 *
3444 * Description:
3445 * If val is not in a valid range then log a kernel error message and set
3446 * the vport restrict login to one.
3447 * If the port type is physical and the val is not zero log a kernel
3448 * error message, clear the restrict login flag and return zero.
3449 * Else set the restrict login flag to val.
3450 *
3451 * Returns:
3452 * zero if val is in range
3453 * -EINVAL val out of range
3454 **/
James Smart3de2a652007-08-02 11:09:59 -04003455static int
3456lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3457{
3458 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04003459 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04003460 "0425 lpfc_restrict_login attribute cannot "
James Smarte8b62012007-08-02 11:10:09 -04003461 "be set to %d, allowed range is [0, 1]\n",
3462 val);
James Smart3de2a652007-08-02 11:09:59 -04003463 vport->cfg_restrict_login = 1;
3464 return -EINVAL;
3465 }
3466 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04003467 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3468 "0468 lpfc_restrict_login must be 0 for "
3469 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04003470 vport->cfg_restrict_login = 0;
3471 return 0;
3472 }
3473 vport->cfg_restrict_login = val;
3474 return 0;
3475}
3476lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01003477static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3478 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05003479
3480/*
dea31012005-04-17 16:05:31 -05003481# Some disk devices have a "select ID" or "select Target" capability.
3482# From a protocol standpoint "select ID" usually means select the
3483# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3484# annex" which contains a table that maps a "select ID" (a number
3485# between 0 and 7F) to an ALPA. By default, for compatibility with
3486# older drivers, the lpfc driver scans this table from low ALPA to high
3487# ALPA.
3488#
3489# Turning on the scan-down variable (on = 1, off = 0) will
3490# cause the lpfc driver to use an inverted table, effectively
3491# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3492#
3493# (Note: This "select ID" functionality is a LOOP ONLY characteristic
3494# and will not work across a fabric. Also this parameter will take
3495# effect only in the case when ALPA map is not available.)
3496*/
James Smart3de2a652007-08-02 11:09:59 -04003497LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3498 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05003499
3500/*
dea31012005-04-17 16:05:31 -05003501# lpfc_topology: link topology for init link
3502# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05003503# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05003504# 0x02 = attempt point-to-point mode only
3505# 0x04 = attempt loop mode only
3506# 0x06 = attempt point-to-point mode then loop
3507# Set point-to-point mode if you want to run as an N_Port.
3508# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3509# Default value is 0.
3510*/
James Smart0a035432016-10-13 15:06:10 -07003511LPFC_ATTR(topology, 0, 0, 6,
3512 "Select Fibre Channel topology");
James Smarte59058c2008-08-24 21:49:00 -04003513
3514/**
James Smart3621a712009-04-06 18:47:14 -04003515 * lpfc_topology_set - Set the adapters topology field
James Smarte59058c2008-08-24 21:49:00 -04003516 * @phba: lpfc_hba pointer.
3517 * @val: topology value.
3518 *
3519 * Description:
3520 * If val is in a valid range then set the adapter's topology field and
3521 * issue a lip; if the lip fails reset the topology to the old value.
3522 *
3523 * If the value is not in range log a kernel error message and return an error.
3524 *
3525 * Returns:
3526 * zero if val is in range and lip okay
3527 * non-zero return value from lpfc_issue_lip()
3528 * -EINVAL val out of range
3529 **/
James Smarta257bf92009-04-06 18:48:10 -04003530static ssize_t
3531lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3532 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003533{
James Smarta257bf92009-04-06 18:48:10 -04003534 struct Scsi_Host *shost = class_to_shost(dev);
3535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3536 struct lpfc_hba *phba = vport->phba;
3537 int val = 0;
3538 int nolip = 0;
3539 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003540 int err;
3541 uint32_t prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003542
3543 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3544 nolip = 1;
3545 val_buf = &buf[strlen("nolip ")];
3546 }
3547
3548 if (!isdigit(val_buf[0]))
3549 return -EINVAL;
3550 if (sscanf(val_buf, "%i", &val) != 1)
3551 return -EINVAL;
3552
James Smart83108bd2008-01-11 01:53:09 -05003553 if (val >= 0 && val <= 6) {
3554 prev_val = phba->cfg_topology;
James Smartff78d8f2011-12-13 13:21:35 -05003555 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3556 val == 4) {
3557 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3558 "3113 Loop mode not supported at speed %d\n",
James Smartd38dd522015-08-31 16:48:17 -04003559 val);
James Smartff78d8f2011-12-13 13:21:35 -05003560 return -EINVAL;
3561 }
James Smartd38dd522015-08-31 16:48:17 -04003562 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3563 val == 4) {
3564 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3565 "3114 Loop mode not supported\n");
3566 return -EINVAL;
3567 }
3568 phba->cfg_topology = val;
James Smarta257bf92009-04-06 18:48:10 -04003569 if (nolip)
3570 return strlen(buf);
3571
James Smart88a2cfb2011-07-22 18:36:33 -04003572 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3573 "3054 lpfc_topology changed from %d to %d\n",
3574 prev_val, val);
James Smarte74c03c2013-04-17 20:15:19 -04003575 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3576 phba->fc_topology_changed = 1;
James Smart83108bd2008-01-11 01:53:09 -05003577 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04003578 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05003579 phba->cfg_topology = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04003580 return -EINVAL;
3581 } else
3582 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05003583 }
3584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3585 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3586 "allowed range is [0, 6]\n",
3587 phba->brd_no, val);
3588 return -EINVAL;
3589}
James Smart0a035432016-10-13 15:06:10 -07003590
James Smart83108bd2008-01-11 01:53:09 -05003591lpfc_param_show(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01003592static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05003593 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05003594
James Smart21e9a0a2009-05-22 14:53:21 -04003595/**
3596 * lpfc_static_vport_show: Read callback function for
3597 * lpfc_static_vport sysfs file.
3598 * @dev: Pointer to class device object.
3599 * @attr: device attribute structure.
3600 * @buf: Data buffer.
3601 *
3602 * This function is the read call back function for
3603 * lpfc_static_vport sysfs file. The lpfc_static_vport
3604 * sysfs file report the mageability of the vport.
3605 **/
3606static ssize_t
3607lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3608 char *buf)
3609{
3610 struct Scsi_Host *shost = class_to_shost(dev);
3611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3612 if (vport->vport_flag & STATIC_VPORT)
3613 sprintf(buf, "1\n");
3614 else
3615 sprintf(buf, "0\n");
3616
3617 return strlen(buf);
3618}
3619
3620/*
3621 * Sysfs attribute to control the statistical data collection.
3622 */
3623static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3624 lpfc_static_vport_show, NULL);
James Smartea2151b2008-09-07 11:52:10 -04003625
3626/**
James Smart3621a712009-04-06 18:47:14 -04003627 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003628 * @dev: Pointer to class device.
3629 * @buf: Data buffer.
3630 * @count: Size of the data buffer.
3631 *
3632 * This function get called when an user write to the lpfc_stat_data_ctrl
3633 * sysfs file. This function parse the command written to the sysfs file
3634 * and take appropriate action. These commands are used for controlling
3635 * driver statistical data collection.
3636 * Following are the command this function handles.
3637 *
3638 * setbucket <bucket_type> <base> <step>
3639 * = Set the latency buckets.
3640 * destroybucket = destroy all the buckets.
3641 * start = start data collection
3642 * stop = stop data collection
3643 * reset = reset the collected data
3644 **/
3645static ssize_t
3646lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3647 const char *buf, size_t count)
3648{
3649 struct Scsi_Host *shost = class_to_shost(dev);
3650 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3651 struct lpfc_hba *phba = vport->phba;
3652#define LPFC_MAX_DATA_CTRL_LEN 1024
3653 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3654 unsigned long i;
3655 char *str_ptr, *token;
3656 struct lpfc_vport **vports;
3657 struct Scsi_Host *v_shost;
3658 char *bucket_type_str, *base_str, *step_str;
3659 unsigned long base, step, bucket_type;
3660
3661 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
James Smarta257bf92009-04-06 18:48:10 -04003662 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
James Smartea2151b2008-09-07 11:52:10 -04003663 return -EINVAL;
3664
James Smarteb016562014-09-03 12:58:06 -04003665 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
James Smartea2151b2008-09-07 11:52:10 -04003666 str_ptr = &bucket_data[0];
3667 /* Ignore this token - this is command token */
3668 token = strsep(&str_ptr, "\t ");
3669 if (!token)
3670 return -EINVAL;
3671
3672 bucket_type_str = strsep(&str_ptr, "\t ");
3673 if (!bucket_type_str)
3674 return -EINVAL;
3675
3676 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3677 bucket_type = LPFC_LINEAR_BUCKET;
3678 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3679 bucket_type = LPFC_POWER2_BUCKET;
3680 else
3681 return -EINVAL;
3682
3683 base_str = strsep(&str_ptr, "\t ");
3684 if (!base_str)
3685 return -EINVAL;
3686 base = simple_strtoul(base_str, NULL, 0);
3687
3688 step_str = strsep(&str_ptr, "\t ");
3689 if (!step_str)
3690 return -EINVAL;
3691 step = simple_strtoul(step_str, NULL, 0);
3692 if (!step)
3693 return -EINVAL;
3694
3695 /* Block the data collection for every vport */
3696 vports = lpfc_create_vport_work_array(phba);
3697 if (vports == NULL)
3698 return -ENOMEM;
3699
James Smartf4b4c682009-05-22 14:53:12 -04003700 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003701 v_shost = lpfc_shost_from_vport(vports[i]);
3702 spin_lock_irq(v_shost->host_lock);
3703 /* Block and reset data collection */
3704 vports[i]->stat_data_blocked = 1;
3705 if (vports[i]->stat_data_enabled)
3706 lpfc_vport_reset_stat_data(vports[i]);
3707 spin_unlock_irq(v_shost->host_lock);
3708 }
3709
3710 /* Set the bucket attributes */
3711 phba->bucket_type = bucket_type;
3712 phba->bucket_base = base;
3713 phba->bucket_step = step;
3714
James Smartf4b4c682009-05-22 14:53:12 -04003715 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003716 v_shost = lpfc_shost_from_vport(vports[i]);
3717
3718 /* Unblock data collection */
3719 spin_lock_irq(v_shost->host_lock);
3720 vports[i]->stat_data_blocked = 0;
3721 spin_unlock_irq(v_shost->host_lock);
3722 }
3723 lpfc_destroy_vport_work_array(phba, vports);
3724 return strlen(buf);
3725 }
3726
3727 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3728 vports = lpfc_create_vport_work_array(phba);
3729 if (vports == NULL)
3730 return -ENOMEM;
3731
James Smartf4b4c682009-05-22 14:53:12 -04003732 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smartea2151b2008-09-07 11:52:10 -04003733 v_shost = lpfc_shost_from_vport(vports[i]);
3734 spin_lock_irq(shost->host_lock);
3735 vports[i]->stat_data_blocked = 1;
3736 lpfc_free_bucket(vport);
3737 vport->stat_data_enabled = 0;
3738 vports[i]->stat_data_blocked = 0;
3739 spin_unlock_irq(shost->host_lock);
3740 }
3741 lpfc_destroy_vport_work_array(phba, vports);
3742 phba->bucket_type = LPFC_NO_BUCKET;
3743 phba->bucket_base = 0;
3744 phba->bucket_step = 0;
3745 return strlen(buf);
3746 }
3747
3748 if (!strncmp(buf, "start", strlen("start"))) {
3749 /* If no buckets configured return error */
3750 if (phba->bucket_type == LPFC_NO_BUCKET)
3751 return -EINVAL;
3752 spin_lock_irq(shost->host_lock);
3753 if (vport->stat_data_enabled) {
3754 spin_unlock_irq(shost->host_lock);
3755 return strlen(buf);
3756 }
3757 lpfc_alloc_bucket(vport);
3758 vport->stat_data_enabled = 1;
3759 spin_unlock_irq(shost->host_lock);
3760 return strlen(buf);
3761 }
3762
3763 if (!strncmp(buf, "stop", strlen("stop"))) {
3764 spin_lock_irq(shost->host_lock);
3765 if (vport->stat_data_enabled == 0) {
3766 spin_unlock_irq(shost->host_lock);
3767 return strlen(buf);
3768 }
3769 lpfc_free_bucket(vport);
3770 vport->stat_data_enabled = 0;
3771 spin_unlock_irq(shost->host_lock);
3772 return strlen(buf);
3773 }
3774
3775 if (!strncmp(buf, "reset", strlen("reset"))) {
3776 if ((phba->bucket_type == LPFC_NO_BUCKET)
3777 || !vport->stat_data_enabled)
3778 return strlen(buf);
3779 spin_lock_irq(shost->host_lock);
3780 vport->stat_data_blocked = 1;
3781 lpfc_vport_reset_stat_data(vport);
3782 vport->stat_data_blocked = 0;
3783 spin_unlock_irq(shost->host_lock);
3784 return strlen(buf);
3785 }
3786 return -EINVAL;
3787}
3788
3789
3790/**
James Smart3621a712009-04-06 18:47:14 -04003791 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003792 * @dev: Pointer to class device object.
3793 * @buf: Data buffer.
3794 *
3795 * This function is the read call back function for
3796 * lpfc_stat_data_ctrl sysfs file. This function report the
3797 * current statistical data collection state.
3798 **/
3799static ssize_t
3800lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3801 char *buf)
3802{
3803 struct Scsi_Host *shost = class_to_shost(dev);
3804 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3805 struct lpfc_hba *phba = vport->phba;
3806 int index = 0;
3807 int i;
3808 char *bucket_type;
3809 unsigned long bucket_value;
3810
3811 switch (phba->bucket_type) {
3812 case LPFC_LINEAR_BUCKET:
3813 bucket_type = "linear";
3814 break;
3815 case LPFC_POWER2_BUCKET:
3816 bucket_type = "power2";
3817 break;
3818 default:
3819 bucket_type = "No Bucket";
3820 break;
3821 }
3822
3823 sprintf(&buf[index], "Statistical Data enabled :%d, "
3824 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3825 " Bucket step :%d\nLatency Ranges :",
3826 vport->stat_data_enabled, vport->stat_data_blocked,
3827 bucket_type, phba->bucket_base, phba->bucket_step);
3828 index = strlen(buf);
3829 if (phba->bucket_type != LPFC_NO_BUCKET) {
3830 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3831 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3832 bucket_value = phba->bucket_base +
3833 phba->bucket_step * i;
3834 else
3835 bucket_value = phba->bucket_base +
3836 (1 << i) * phba->bucket_step;
3837
3838 if (index + 10 > PAGE_SIZE)
3839 break;
3840 sprintf(&buf[index], "%08ld ", bucket_value);
3841 index = strlen(buf);
3842 }
3843 }
3844 sprintf(&buf[index], "\n");
3845 return strlen(buf);
3846}
3847
3848/*
3849 * Sysfs attribute to control the statistical data collection.
3850 */
3851static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3852 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3853
3854/*
3855 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3856 */
3857
3858/*
3859 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3860 * for each target.
3861 */
3862#define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3863#define MAX_STAT_DATA_SIZE_PER_TARGET \
3864 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3865
3866
3867/**
James Smart3621a712009-04-06 18:47:14 -04003868 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
Chris Wright2c3c8be2010-05-12 18:28:57 -07003869 * @filp: sysfs file
James Smartea2151b2008-09-07 11:52:10 -04003870 * @kobj: Pointer to the kernel object
3871 * @bin_attr: Attribute object
3872 * @buff: Buffer pointer
3873 * @off: File offset
3874 * @count: Buffer size
3875 *
3876 * This function is the read call back function for lpfc_drvr_stat_data
3877 * sysfs file. This function export the statistical data to user
3878 * applications.
3879 **/
3880static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07003881sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3882 struct bin_attribute *bin_attr,
James Smartea2151b2008-09-07 11:52:10 -04003883 char *buf, loff_t off, size_t count)
3884{
3885 struct device *dev = container_of(kobj, struct device,
3886 kobj);
3887 struct Scsi_Host *shost = class_to_shost(dev);
3888 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3889 struct lpfc_hba *phba = vport->phba;
3890 int i = 0, index = 0;
3891 unsigned long nport_index;
3892 struct lpfc_nodelist *ndlp = NULL;
3893 nport_index = (unsigned long)off /
3894 MAX_STAT_DATA_SIZE_PER_TARGET;
3895
3896 if (!vport->stat_data_enabled || vport->stat_data_blocked
3897 || (phba->bucket_type == LPFC_NO_BUCKET))
3898 return 0;
3899
3900 spin_lock_irq(shost->host_lock);
3901 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3902 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3903 continue;
3904
3905 if (nport_index > 0) {
3906 nport_index--;
3907 continue;
3908 }
3909
3910 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3911 > count)
3912 break;
3913
3914 if (!ndlp->lat_data)
3915 continue;
3916
3917 /* Print the WWN */
3918 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3919 ndlp->nlp_portname.u.wwn[0],
3920 ndlp->nlp_portname.u.wwn[1],
3921 ndlp->nlp_portname.u.wwn[2],
3922 ndlp->nlp_portname.u.wwn[3],
3923 ndlp->nlp_portname.u.wwn[4],
3924 ndlp->nlp_portname.u.wwn[5],
3925 ndlp->nlp_portname.u.wwn[6],
3926 ndlp->nlp_portname.u.wwn[7]);
3927
3928 index = strlen(buf);
3929
3930 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3931 sprintf(&buf[index], "%010u,",
3932 ndlp->lat_data[i].cmd_count);
3933 index = strlen(buf);
3934 }
3935 sprintf(&buf[index], "\n");
3936 index = strlen(buf);
3937 }
3938 spin_unlock_irq(shost->host_lock);
3939 return index;
3940}
3941
3942static struct bin_attribute sysfs_drvr_stat_data_attr = {
3943 .attr = {
3944 .name = "lpfc_drvr_stat_data",
3945 .mode = S_IRUSR,
James Smartea2151b2008-09-07 11:52:10 -04003946 },
3947 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3948 .read = sysfs_drvr_stat_data_read,
3949 .write = NULL,
3950};
3951
dea31012005-04-17 16:05:31 -05003952/*
3953# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3954# connection.
James Smart76a95d72010-11-20 23:11:48 -05003955# Value range is [0,16]. Default value is 0.
dea31012005-04-17 16:05:31 -05003956*/
James Smarte59058c2008-08-24 21:49:00 -04003957/**
James Smart3621a712009-04-06 18:47:14 -04003958 * lpfc_link_speed_set - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04003959 * @phba: lpfc_hba pointer.
3960 * @val: link speed value.
3961 *
3962 * Description:
3963 * If val is in a valid range then set the adapter's link speed field and
3964 * issue a lip; if the lip fails reset the link speed to the old value.
3965 *
3966 * Notes:
3967 * If the value is not in range log a kernel error message and return an error.
3968 *
3969 * Returns:
3970 * zero if val is in range and lip okay.
3971 * non-zero return value from lpfc_issue_lip()
3972 * -EINVAL val out of range
3973 **/
James Smarta257bf92009-04-06 18:48:10 -04003974static ssize_t
3975lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
3976 const char *buf, size_t count)
James Smart83108bd2008-01-11 01:53:09 -05003977{
James Smarta257bf92009-04-06 18:48:10 -04003978 struct Scsi_Host *shost = class_to_shost(dev);
3979 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3980 struct lpfc_hba *phba = vport->phba;
James Smart76a95d72010-11-20 23:11:48 -05003981 int val = LPFC_USER_LINK_SPEED_AUTO;
James Smarta257bf92009-04-06 18:48:10 -04003982 int nolip = 0;
3983 const char *val_buf = buf;
James Smart83108bd2008-01-11 01:53:09 -05003984 int err;
James Smartc6918162016-10-13 15:06:16 -07003985 uint32_t prev_val, if_type;
3986
3987 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
3988 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
3989 phba->hba_flag & HBA_FORCED_LINK_SPEED)
3990 return -EPERM;
James Smart83108bd2008-01-11 01:53:09 -05003991
James Smarta257bf92009-04-06 18:48:10 -04003992 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3993 nolip = 1;
3994 val_buf = &buf[strlen("nolip ")];
3995 }
3996
3997 if (!isdigit(val_buf[0]))
3998 return -EINVAL;
3999 if (sscanf(val_buf, "%i", &val) != 1)
4000 return -EINVAL;
4001
James Smart88a2cfb2011-07-22 18:36:33 -04004002 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4003 "3055 lpfc_link_speed changed from %d to %d %s\n",
4004 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4005
James Smart76a95d72010-11-20 23:11:48 -05004006 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4007 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4008 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4009 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4010 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
James Smartd38dd522015-08-31 16:48:17 -04004011 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4012 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
James Smart76a95d72010-11-20 23:11:48 -05004013 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4014 "2879 lpfc_link_speed attribute cannot be set "
4015 "to %d. Speed is not supported by this port.\n",
4016 val);
James Smart83108bd2008-01-11 01:53:09 -05004017 return -EINVAL;
James Smart76a95d72010-11-20 23:11:48 -05004018 }
James Smartff78d8f2011-12-13 13:21:35 -05004019 if (val == LPFC_USER_LINK_SPEED_16G &&
4020 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4021 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4022 "3112 lpfc_link_speed attribute cannot be set "
4023 "to %d. Speed is not supported in loop mode.\n",
4024 val);
4025 return -EINVAL;
4026 }
James Smart76a95d72010-11-20 23:11:48 -05004027 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4028 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004029 prev_val = phba->cfg_link_speed;
4030 phba->cfg_link_speed = val;
James Smarta257bf92009-04-06 18:48:10 -04004031 if (nolip)
4032 return strlen(buf);
4033
James Smart83108bd2008-01-11 01:53:09 -05004034 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
James Smarta257bf92009-04-06 18:48:10 -04004035 if (err) {
James Smart83108bd2008-01-11 01:53:09 -05004036 phba->cfg_link_speed = prev_val;
James Smarta257bf92009-04-06 18:48:10 -04004037 return -EINVAL;
4038 } else
4039 return strlen(buf);
James Smart83108bd2008-01-11 01:53:09 -05004040 }
James Smart83108bd2008-01-11 01:53:09 -05004041 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart76a95d72010-11-20 23:11:48 -05004042 "0469 lpfc_link_speed attribute cannot be set to %d, "
4043 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart83108bd2008-01-11 01:53:09 -05004044 return -EINVAL;
4045}
4046
4047static int lpfc_link_speed = 0;
James Smartab56dc22011-02-16 12:39:57 -05004048module_param(lpfc_link_speed, int, S_IRUGO);
James Smart83108bd2008-01-11 01:53:09 -05004049MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4050lpfc_param_show(link_speed)
James Smarte59058c2008-08-24 21:49:00 -04004051
4052/**
James Smart3621a712009-04-06 18:47:14 -04004053 * lpfc_link_speed_init - Set the adapters link speed
James Smarte59058c2008-08-24 21:49:00 -04004054 * @phba: lpfc_hba pointer.
4055 * @val: link speed value.
4056 *
4057 * Description:
4058 * If val is in a valid range then set the adapter's link speed field.
4059 *
4060 * Notes:
4061 * If the value is not in range log a kernel error message, clear the link
4062 * speed and return an error.
4063 *
4064 * Returns:
4065 * zero if val saved.
4066 * -EINVAL val out of range
4067 **/
James Smart83108bd2008-01-11 01:53:09 -05004068static int
4069lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4070{
James Smartff78d8f2011-12-13 13:21:35 -05004071 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4072 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4073 "3111 lpfc_link_speed of %d cannot "
4074 "support loop mode, setting topology to default.\n",
4075 val);
4076 phba->cfg_topology = 0;
4077 }
James Smart76a95d72010-11-20 23:11:48 -05004078 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4079 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
James Smart83108bd2008-01-11 01:53:09 -05004080 phba->cfg_link_speed = val;
4081 return 0;
4082 }
4083 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smartd7c255b2008-08-24 21:50:00 -04004084 "0405 lpfc_link_speed attribute cannot "
James Smart83108bd2008-01-11 01:53:09 -05004085 "be set to %d, allowed values are "
4086 "["LPFC_LINK_SPEED_STRING"]\n", val);
James Smart76a95d72010-11-20 23:11:48 -05004087 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
James Smart83108bd2008-01-11 01:53:09 -05004088 return -EINVAL;
4089}
4090
Tony Jonesee959b02008-02-22 00:13:36 +01004091static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart76a95d72010-11-20 23:11:48 -05004092 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05004093
4094/*
James Smart0d878412009-10-02 15:16:56 -04004095# lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4096# 0 = aer disabled or not supported
4097# 1 = aer supported and enabled (default)
4098# Value range is [0,1]. Default value is 1.
4099*/
James Smart506139a2016-10-13 15:06:09 -07004100LPFC_ATTR(aer_support, 1, 0, 1,
4101 "Enable PCIe device AER support");
4102lpfc_param_show(aer_support)
James Smart0d878412009-10-02 15:16:56 -04004103
4104/**
4105 * lpfc_aer_support_store - Set the adapter for aer support
4106 *
4107 * @dev: class device that is converted into a Scsi_host.
4108 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004109 * @buf: containing enable or disable aer flag.
James Smart0d878412009-10-02 15:16:56 -04004110 * @count: unused variable.
4111 *
4112 * Description:
4113 * If the val is 1 and currently the device's AER capability was not
4114 * enabled, invoke the kernel's enable AER helper routine, trying to
4115 * enable the device's AER capability. If the helper routine enabling
4116 * AER returns success, update the device's cfg_aer_support flag to
4117 * indicate AER is supported by the device; otherwise, if the device
4118 * AER capability is already enabled to support AER, then do nothing.
4119 *
4120 * If the val is 0 and currently the device's AER support was enabled,
4121 * invoke the kernel's disable AER helper routine. After that, update
4122 * the device's cfg_aer_support flag to indicate AER is not supported
4123 * by the device; otherwise, if the device AER capability is already
4124 * disabled from supporting AER, then do nothing.
4125 *
4126 * Returns:
4127 * length of the buf on success if val is in range the intended mode
4128 * is supported.
4129 * -EINVAL if val out of range or intended mode is not supported.
4130 **/
4131static ssize_t
4132lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4133 const char *buf, size_t count)
4134{
4135 struct Scsi_Host *shost = class_to_shost(dev);
4136 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4137 struct lpfc_hba *phba = vport->phba;
4138 int val = 0, rc = -EINVAL;
4139
4140 if (!isdigit(buf[0]))
4141 return -EINVAL;
4142 if (sscanf(buf, "%i", &val) != 1)
4143 return -EINVAL;
4144
4145 switch (val) {
4146 case 0:
4147 if (phba->hba_flag & HBA_AER_ENABLED) {
4148 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4149 if (!rc) {
4150 spin_lock_irq(&phba->hbalock);
4151 phba->hba_flag &= ~HBA_AER_ENABLED;
4152 spin_unlock_irq(&phba->hbalock);
4153 phba->cfg_aer_support = 0;
4154 rc = strlen(buf);
4155 } else
James Smart891478a2009-11-18 15:40:23 -05004156 rc = -EPERM;
4157 } else {
James Smart0d878412009-10-02 15:16:56 -04004158 phba->cfg_aer_support = 0;
James Smart891478a2009-11-18 15:40:23 -05004159 rc = strlen(buf);
4160 }
James Smart0d878412009-10-02 15:16:56 -04004161 break;
4162 case 1:
4163 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4164 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4165 if (!rc) {
4166 spin_lock_irq(&phba->hbalock);
4167 phba->hba_flag |= HBA_AER_ENABLED;
4168 spin_unlock_irq(&phba->hbalock);
4169 phba->cfg_aer_support = 1;
4170 rc = strlen(buf);
4171 } else
James Smart891478a2009-11-18 15:40:23 -05004172 rc = -EPERM;
4173 } else {
James Smart0d878412009-10-02 15:16:56 -04004174 phba->cfg_aer_support = 1;
James Smart891478a2009-11-18 15:40:23 -05004175 rc = strlen(buf);
4176 }
James Smart0d878412009-10-02 15:16:56 -04004177 break;
4178 default:
4179 rc = -EINVAL;
4180 break;
4181 }
4182 return rc;
4183}
4184
James Smart0d878412009-10-02 15:16:56 -04004185static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4186 lpfc_aer_support_show, lpfc_aer_support_store);
4187
4188/**
4189 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4190 * @dev: class device that is converted into a Scsi_host.
4191 * @attr: device attribute, not used.
James Smart912e3ac2011-05-24 11:42:11 -04004192 * @buf: containing flag 1 for aer cleanup state.
James Smart0d878412009-10-02 15:16:56 -04004193 * @count: unused variable.
4194 *
4195 * Description:
4196 * If the @buf contains 1 and the device currently has the AER support
4197 * enabled, then invokes the kernel AER helper routine
4198 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4199 * error status register.
4200 *
4201 * Notes:
4202 *
4203 * Returns:
4204 * -EINVAL if the buf does not contain the 1 or the device is not currently
4205 * enabled with the AER support.
4206 **/
4207static ssize_t
4208lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4209 const char *buf, size_t count)
4210{
4211 struct Scsi_Host *shost = class_to_shost(dev);
4212 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4213 struct lpfc_hba *phba = vport->phba;
4214 int val, rc = -1;
4215
4216 if (!isdigit(buf[0]))
4217 return -EINVAL;
4218 if (sscanf(buf, "%i", &val) != 1)
4219 return -EINVAL;
James Smart891478a2009-11-18 15:40:23 -05004220 if (val != 1)
4221 return -EINVAL;
James Smart0d878412009-10-02 15:16:56 -04004222
James Smart891478a2009-11-18 15:40:23 -05004223 if (phba->hba_flag & HBA_AER_ENABLED)
James Smart0d878412009-10-02 15:16:56 -04004224 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4225
4226 if (rc == 0)
4227 return strlen(buf);
4228 else
James Smart891478a2009-11-18 15:40:23 -05004229 return -EPERM;
James Smart0d878412009-10-02 15:16:56 -04004230}
4231
4232static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4233 lpfc_aer_cleanup_state);
4234
James Smart912e3ac2011-05-24 11:42:11 -04004235/**
4236 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4237 *
4238 * @dev: class device that is converted into a Scsi_host.
4239 * @attr: device attribute, not used.
4240 * @buf: containing the string the number of vfs to be enabled.
4241 * @count: unused variable.
4242 *
4243 * Description:
4244 * When this api is called either through user sysfs, the driver shall
4245 * try to enable or disable SR-IOV virtual functions according to the
4246 * following:
4247 *
4248 * If zero virtual function has been enabled to the physical function,
4249 * the driver shall invoke the pci enable virtual function api trying
4250 * to enable the virtual functions. If the nr_vfn provided is greater
4251 * than the maximum supported, the maximum virtual function number will
4252 * be used for invoking the api; otherwise, the nr_vfn provided shall
4253 * be used for invoking the api. If the api call returned success, the
4254 * actual number of virtual functions enabled will be set to the driver
4255 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4256 * cfg_sriov_nr_virtfn remains zero.
4257 *
4258 * If none-zero virtual functions have already been enabled to the
4259 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4260 * -EINVAL will be returned and the driver does nothing;
4261 *
4262 * If the nr_vfn provided is zero and none-zero virtual functions have
4263 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4264 * disabling virtual function api shall be invoded to disable all the
4265 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4266 * zero. Otherwise, if zero virtual function has been enabled, do
4267 * nothing.
4268 *
4269 * Returns:
4270 * length of the buf on success if val is in range the intended mode
4271 * is supported.
4272 * -EINVAL if val out of range or intended mode is not supported.
4273 **/
4274static ssize_t
4275lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4276 const char *buf, size_t count)
4277{
4278 struct Scsi_Host *shost = class_to_shost(dev);
4279 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4280 struct lpfc_hba *phba = vport->phba;
4281 struct pci_dev *pdev = phba->pcidev;
4282 int val = 0, rc = -EINVAL;
4283
4284 /* Sanity check on user data */
4285 if (!isdigit(buf[0]))
4286 return -EINVAL;
4287 if (sscanf(buf, "%i", &val) != 1)
4288 return -EINVAL;
4289 if (val < 0)
4290 return -EINVAL;
4291
4292 /* Request disabling virtual functions */
4293 if (val == 0) {
4294 if (phba->cfg_sriov_nr_virtfn > 0) {
4295 pci_disable_sriov(pdev);
4296 phba->cfg_sriov_nr_virtfn = 0;
4297 }
4298 return strlen(buf);
4299 }
4300
4301 /* Request enabling virtual functions */
4302 if (phba->cfg_sriov_nr_virtfn > 0) {
4303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4304 "3018 There are %d virtual functions "
4305 "enabled on physical function.\n",
4306 phba->cfg_sriov_nr_virtfn);
4307 return -EEXIST;
4308 }
4309
4310 if (val <= LPFC_MAX_VFN_PER_PFN)
4311 phba->cfg_sriov_nr_virtfn = val;
4312 else {
4313 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4314 "3019 Enabling %d virtual functions is not "
4315 "allowed.\n", val);
4316 return -EINVAL;
4317 }
4318
4319 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4320 if (rc) {
4321 phba->cfg_sriov_nr_virtfn = 0;
4322 rc = -EPERM;
4323 } else
4324 rc = strlen(buf);
4325
4326 return rc;
4327}
4328
James Smart0cfbbf22016-10-13 15:06:12 -07004329LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4330 "Enable PCIe device SR-IOV virtual fn");
4331
James Smart912e3ac2011-05-24 11:42:11 -04004332lpfc_param_show(sriov_nr_virtfn)
James Smart912e3ac2011-05-24 11:42:11 -04004333static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4334 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4335
James Smart173edbb2012-06-12 13:54:50 -04004336/**
James Smartc71ab862012-10-31 14:44:33 -04004337 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4338 *
4339 * @dev: class device that is converted into a Scsi_host.
4340 * @attr: device attribute, not used.
4341 * @buf: containing the string the number of vfs to be enabled.
4342 * @count: unused variable.
4343 *
4344 * Description:
4345 *
4346 * Returns:
4347 * length of the buf on success if val is in range the intended mode
4348 * is supported.
4349 * -EINVAL if val out of range or intended mode is not supported.
4350 **/
4351static ssize_t
4352lpfc_request_firmware_upgrade_store(struct device *dev,
4353 struct device_attribute *attr,
4354 const char *buf, size_t count)
4355{
4356 struct Scsi_Host *shost = class_to_shost(dev);
4357 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4358 struct lpfc_hba *phba = vport->phba;
4359 int val = 0, rc = -EINVAL;
4360
4361 /* Sanity check on user data */
4362 if (!isdigit(buf[0]))
4363 return -EINVAL;
4364 if (sscanf(buf, "%i", &val) != 1)
4365 return -EINVAL;
4366 if (val != 1)
4367 return -EINVAL;
4368
4369 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4370 if (rc)
4371 rc = -EPERM;
4372 else
4373 rc = strlen(buf);
4374 return rc;
4375}
4376
4377static int lpfc_req_fw_upgrade;
4378module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4379MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4380lpfc_param_show(request_firmware_upgrade)
4381
4382/**
4383 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4384 * @phba: lpfc_hba pointer.
4385 * @val: 0 or 1.
4386 *
4387 * Description:
4388 * Set the initial Linux generic firmware upgrade enable or disable flag.
4389 *
4390 * Returns:
4391 * zero if val saved.
4392 * -EINVAL val out of range
4393 **/
4394static int
4395lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4396{
4397 if (val >= 0 && val <= 1) {
4398 phba->cfg_request_firmware_upgrade = val;
4399 return 0;
4400 }
4401 return -EINVAL;
4402}
4403static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4404 lpfc_request_firmware_upgrade_show,
4405 lpfc_request_firmware_upgrade_store);
4406
4407/**
James Smart173edbb2012-06-12 13:54:50 -04004408 * lpfc_fcp_imax_store
4409 *
4410 * @dev: class device that is converted into a Scsi_host.
4411 * @attr: device attribute, not used.
4412 * @buf: string with the number of fast-path FCP interrupts per second.
4413 * @count: unused variable.
4414 *
4415 * Description:
4416 * If val is in a valid range [636,651042], then set the adapter's
4417 * maximum number of fast-path FCP interrupts per second.
4418 *
4419 * Returns:
4420 * length of the buf on success if val is in range the intended mode
4421 * is supported.
4422 * -EINVAL if val out of range or intended mode is not supported.
4423 **/
4424static ssize_t
4425lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4426 const char *buf, size_t count)
4427{
4428 struct Scsi_Host *shost = class_to_shost(dev);
4429 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4430 struct lpfc_hba *phba = vport->phba;
4431 int val = 0, i;
4432
James Smartbf8dae82012-08-03 12:36:24 -04004433 /* fcp_imax is only valid for SLI4 */
4434 if (phba->sli_rev != LPFC_SLI_REV4)
4435 return -EINVAL;
4436
James Smart173edbb2012-06-12 13:54:50 -04004437 /* Sanity check on user data */
4438 if (!isdigit(buf[0]))
4439 return -EINVAL;
4440 if (sscanf(buf, "%i", &val) != 1)
4441 return -EINVAL;
4442
James Smartbf8dae82012-08-03 12:36:24 -04004443 /*
4444 * Value range for the HBA is [5000,5000000]
4445 * The value for each EQ depends on how many EQs are configured.
James Smart895427b2017-02-12 13:52:30 -08004446 * Allow value == 0
James Smartbf8dae82012-08-03 12:36:24 -04004447 */
James Smart895427b2017-02-12 13:52:30 -08004448 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
James Smart173edbb2012-06-12 13:54:50 -04004449 return -EINVAL;
4450
4451 phba->cfg_fcp_imax = (uint32_t)val;
James Smart895427b2017-02-12 13:52:30 -08004452 for (i = 0; i < phba->io_channel_irqs; i++)
4453 lpfc_modify_hba_eq_delay(phba, i);
James Smart173edbb2012-06-12 13:54:50 -04004454
4455 return strlen(buf);
4456}
4457
4458/*
4459# lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
James Smartbf8dae82012-08-03 12:36:24 -04004460# for the HBA.
James Smart173edbb2012-06-12 13:54:50 -04004461#
James Smartbf8dae82012-08-03 12:36:24 -04004462# Value range is [5,000 to 5,000,000]. Default value is 50,000.
James Smart173edbb2012-06-12 13:54:50 -04004463*/
James Smartbf8dae82012-08-03 12:36:24 -04004464static int lpfc_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004465module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4466MODULE_PARM_DESC(lpfc_fcp_imax,
James Smartbf8dae82012-08-03 12:36:24 -04004467 "Set the maximum number of FCP interrupts per second per HBA");
James Smart173edbb2012-06-12 13:54:50 -04004468lpfc_param_show(fcp_imax)
4469
4470/**
4471 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4472 * @phba: lpfc_hba pointer.
4473 * @val: link speed value.
4474 *
4475 * Description:
4476 * If val is in a valid range [636,651042], then initialize the adapter's
4477 * maximum number of fast-path FCP interrupts per second.
4478 *
4479 * Returns:
4480 * zero if val saved.
4481 * -EINVAL val out of range
4482 **/
4483static int
4484lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4485{
James Smartbf8dae82012-08-03 12:36:24 -04004486 if (phba->sli_rev != LPFC_SLI_REV4) {
4487 phba->cfg_fcp_imax = 0;
4488 return 0;
4489 }
4490
James Smart895427b2017-02-12 13:52:30 -08004491 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4492 (val == 0)) {
James Smart173edbb2012-06-12 13:54:50 -04004493 phba->cfg_fcp_imax = val;
4494 return 0;
4495 }
4496
4497 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004498 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4499 val);
James Smartbf8dae82012-08-03 12:36:24 -04004500 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
James Smart173edbb2012-06-12 13:54:50 -04004501
4502 return 0;
4503}
4504
4505static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4506 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4507
James Smart7bb03bb2013-04-17 20:19:16 -04004508/**
4509 * lpfc_state_show - Display current driver CPU affinity
4510 * @dev: class converted to a Scsi_host structure.
4511 * @attr: device attribute, not used.
4512 * @buf: on return contains text describing the state of the link.
4513 *
4514 * Returns: size of formatted string.
4515 **/
4516static ssize_t
4517lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4518 char *buf)
4519{
4520 struct Scsi_Host *shost = class_to_shost(dev);
4521 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4522 struct lpfc_hba *phba = vport->phba;
4523 struct lpfc_vector_map_info *cpup;
James Smart76fd07a2014-02-20 09:57:18 -05004524 int len = 0;
James Smart7bb03bb2013-04-17 20:19:16 -04004525
4526 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4527 (phba->intr_type != MSIX))
4528 return len;
4529
4530 switch (phba->cfg_fcp_cpu_map) {
4531 case 0:
4532 len += snprintf(buf + len, PAGE_SIZE-len,
4533 "fcp_cpu_map: No mapping (%d)\n",
4534 phba->cfg_fcp_cpu_map);
4535 return len;
4536 case 1:
4537 len += snprintf(buf + len, PAGE_SIZE-len,
4538 "fcp_cpu_map: HBA centric mapping (%d): "
4539 "%d online CPUs\n",
4540 phba->cfg_fcp_cpu_map,
4541 phba->sli4_hba.num_online_cpu);
4542 break;
4543 case 2:
4544 len += snprintf(buf + len, PAGE_SIZE-len,
4545 "fcp_cpu_map: Driver centric mapping (%d): "
4546 "%d online CPUs\n",
4547 phba->cfg_fcp_cpu_map,
4548 phba->sli4_hba.num_online_cpu);
4549 break;
4550 }
4551
James Smart76fd07a2014-02-20 09:57:18 -05004552 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4553 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4554
4555 /* margin should fit in this and the truncated message */
James Smart7bb03bb2013-04-17 20:19:16 -04004556 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4557 len += snprintf(buf + len, PAGE_SIZE-len,
4558 "CPU %02d io_chan %02d "
4559 "physid %d coreid %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004560 phba->sli4_hba.curr_disp_cpu,
4561 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004562 cpup->core_id);
4563 else
4564 len += snprintf(buf + len, PAGE_SIZE-len,
4565 "CPU %02d io_chan %02d "
4566 "physid %d coreid %d IRQ %d\n",
James Smart76fd07a2014-02-20 09:57:18 -05004567 phba->sli4_hba.curr_disp_cpu,
4568 cpup->channel_id, cpup->phys_id,
James Smart7bb03bb2013-04-17 20:19:16 -04004569 cpup->core_id, cpup->irq);
4570
James Smart76fd07a2014-02-20 09:57:18 -05004571 phba->sli4_hba.curr_disp_cpu++;
4572
4573 /* display max number of CPUs keeping some margin */
4574 if (phba->sli4_hba.curr_disp_cpu <
4575 phba->sli4_hba.num_present_cpu &&
4576 (len >= (PAGE_SIZE - 64))) {
4577 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4578 break;
4579 }
James Smart7bb03bb2013-04-17 20:19:16 -04004580 }
James Smart76fd07a2014-02-20 09:57:18 -05004581
4582 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4583 phba->sli4_hba.curr_disp_cpu = 0;
4584
James Smart7bb03bb2013-04-17 20:19:16 -04004585 return len;
4586}
4587
4588/**
4589 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4590 * @dev: class device that is converted into a Scsi_host.
4591 * @attr: device attribute, not used.
4592 * @buf: one or more lpfc_polling_flags values.
4593 * @count: not used.
4594 *
4595 * Returns:
4596 * -EINVAL - Not implemented yet.
4597 **/
4598static ssize_t
4599lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4600 const char *buf, size_t count)
4601{
4602 int status = -EINVAL;
4603 return status;
4604}
4605
4606/*
4607# lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4608# for the HBA.
4609#
4610# Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4611# 0 - Do not affinitze IRQ vectors
4612# 1 - Affintize HBA vectors with respect to each HBA
4613# (start with CPU0 for each HBA)
4614# 2 - Affintize HBA vectors with respect to the entire driver
4615# (round robin thru all CPUs across all HBAs)
4616*/
4617static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4618module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4619MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4620 "Defines how to map CPUs to IRQ vectors per HBA");
4621
4622/**
4623 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4624 * @phba: lpfc_hba pointer.
4625 * @val: link speed value.
4626 *
4627 * Description:
4628 * If val is in a valid range [0-2], then affinitze the adapter's
4629 * MSIX vectors.
4630 *
4631 * Returns:
4632 * zero if val saved.
4633 * -EINVAL val out of range
4634 **/
4635static int
4636lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4637{
4638 if (phba->sli_rev != LPFC_SLI_REV4) {
4639 phba->cfg_fcp_cpu_map = 0;
4640 return 0;
4641 }
4642
4643 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4644 phba->cfg_fcp_cpu_map = val;
4645 return 0;
4646 }
4647
4648 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smart6c860682016-10-13 15:06:13 -07004649 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4650 "default\n", val);
James Smart7bb03bb2013-04-17 20:19:16 -04004651 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4652
4653 return 0;
4654}
4655
4656static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4657 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4658
James Smart0d878412009-10-02 15:16:56 -04004659/*
dea31012005-04-17 16:05:31 -05004660# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4661# Value range is [2,3]. Default value is 3.
4662*/
James Smart3de2a652007-08-02 11:09:59 -04004663LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4664 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05004665
4666/*
4667# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4668# is [0,1]. Default value is 0.
4669*/
James Smart3de2a652007-08-02 11:09:59 -04004670LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4671 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05004672
4673/*
James Smart3cb01c52013-07-15 18:35:04 -04004674# lpfc_first_burst_size: First burst size to use on the NPorts
4675# that support first burst.
4676# Value range is [0,65536]. Default value is 0.
4677*/
4678LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4679 "First burst size for Targets that support first burst");
4680
4681/*
James Smart2d7dbc42017-02-12 13:52:35 -08004682* lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4683* When the driver is configured as an NVME target, this value is
4684* communicated to the NVME initiator in the PRLI response. It is
4685* used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4686* parameters are set and the target is sending the PRLI RSP.
James Smart895427b2017-02-12 13:52:30 -08004687* Parameter supported on physical port only - no NPIV support.
James Smart2d7dbc42017-02-12 13:52:35 -08004688* Value range is [0,65536]. Default value is 0.
James Smart895427b2017-02-12 13:52:30 -08004689*/
James Smart2d7dbc42017-02-12 13:52:35 -08004690LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4691 "NVME Target mode first burst size in 512B increments.");
4692
4693/*
4694 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4695 * For the Initiator (I), enabling this parameter means that an NVMET
4696 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4697 * processed by the initiator for subsequent NVME FCP IO. For the target
4698 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4699 * driver parameter as the target function's first burst size returned to the
4700 * initiator in the target's NVME PRLI response. Parameter supported on physical
4701 * port only - no NPIV support.
4702 * Value range is [0,1]. Default value is 0 (disabled).
4703 */
James Smart895427b2017-02-12 13:52:30 -08004704LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4705 "Enable First Burst feature on I and T functions.");
4706
4707/*
James Smart977b5a02008-09-07 11:52:04 -04004708# lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4709# depth. Default value is 0. When the value of this parameter is zero the
4710# SCSI command completion time is not used for controlling I/O queue depth. When
4711# the parameter is set to a non-zero value, the I/O queue depth is controlled
4712# to limit the I/O completion time to the parameter value.
4713# The value is set in milliseconds.
4714*/
James Smarted5b1522016-10-13 15:06:11 -07004715LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
James Smart977b5a02008-09-07 11:52:04 -04004716 "Use command completion time to control queue depth");
James Smarted5b1522016-10-13 15:06:11 -07004717
James Smart977b5a02008-09-07 11:52:04 -04004718lpfc_vport_param_show(max_scsicmpl_time);
James Smart977b5a02008-09-07 11:52:04 -04004719static int
4720lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4721{
4722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4723 struct lpfc_nodelist *ndlp, *next_ndlp;
4724
4725 if (val == vport->cfg_max_scsicmpl_time)
4726 return 0;
4727 if ((val < 0) || (val > 60000))
4728 return -EINVAL;
4729 vport->cfg_max_scsicmpl_time = val;
4730
4731 spin_lock_irq(shost->host_lock);
4732 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4733 if (!NLP_CHK_NODE_ACT(ndlp))
4734 continue;
4735 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4736 continue;
James Smart7dc517d2010-07-14 15:32:10 -04004737 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart977b5a02008-09-07 11:52:04 -04004738 }
4739 spin_unlock_irq(shost->host_lock);
4740 return 0;
4741}
4742lpfc_vport_param_store(max_scsicmpl_time);
4743static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4744 lpfc_max_scsicmpl_time_show,
4745 lpfc_max_scsicmpl_time_store);
4746
4747/*
dea31012005-04-17 16:05:31 -05004748# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4749# range is [0,1]. Default value is 0.
4750*/
4751LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4752
4753/*
James Smart895427b2017-02-12 13:52:30 -08004754 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4755 * range is [0,1]. Default value is 0.
4756 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4757 * For [1], FCP commands are issued to a Work Queue associated with the
4758 * current CPU.
4759 *
4760 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4761 * LPFC_FCP_SCHED_BY_CPU == 1
4762 *
4763 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4764 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4765 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4766 * through WQs will be used.
4767 */
4768LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4769 LPFC_FCP_SCHED_ROUND_ROBIN,
4770 LPFC_FCP_SCHED_BY_CPU,
4771 "Determine scheduling algorithm for "
4772 "issuing commands [0] - Round Robin, [1] - Current CPU");
James Smart49aa1432012-08-03 12:36:42 -04004773
4774/*
James Smarta6571c62012-10-31 14:44:42 -04004775# lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4776# range is [0,1]. Default value is 0.
4777# For [0], bus reset issues target reset to ALL devices
4778# For [1], bus reset issues target reset to non-FCP2 devices
4779*/
4780LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4781 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4782
4783
4784/*
dea31012005-04-17 16:05:31 -05004785# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4786# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04004787# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05004788# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4789# cr_delay is set to 0.
4790*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004791LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05004792 "interrupt response is generated");
4793
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05004794LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05004795 "interrupt response is generated");
4796
4797/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05004798# lpfc_multi_ring_support: Determines how many rings to spread available
4799# cmd/rsp IOCB entries across.
4800# Value range is [1,2]. Default value is 1.
4801*/
4802LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4803 "SLI rings to spread IOCB entries across");
4804
4805/*
James Smarta4bc3372006-12-02 13:34:16 -05004806# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4807# identifies what rctl value to configure the additional ring for.
4808# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4809*/
James Smart6a9c52c2009-10-02 15:16:51 -04004810LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004811 255, "Identifies RCTL for additional ring configuration");
4812
4813/*
4814# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4815# identifies what type value to configure the additional ring for.
4816# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4817*/
James Smart6a9c52c2009-10-02 15:16:51 -04004818LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
James Smarta4bc3372006-12-02 13:34:16 -05004819 255, "Identifies TYPE for additional ring configuration");
4820
4821/*
James Smart4258e982015-12-16 18:11:58 -05004822# lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4823# 0 = SmartSAN functionality disabled (default)
4824# 1 = SmartSAN functionality enabled
4825# This parameter will override the value of lpfc_fdmi_on module parameter.
4826# Value range is [0,1]. Default value is 0.
dea31012005-04-17 16:05:31 -05004827*/
James Smart4258e982015-12-16 18:11:58 -05004828LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4829
4830/*
4831# lpfc_fdmi_on: Controls FDMI support.
4832# 0 No FDMI support (default)
4833# 1 Traditional FDMI support
James Smart8663cbb2016-03-31 14:12:33 -07004834# Traditional FDMI support means the driver will assume FDMI-2 support;
4835# however, if that fails, it will fallback to FDMI-1.
4836# If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4837# If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4838# lpfc_fdmi_on.
4839# Value range [0,1]. Default value is 0.
James Smart4258e982015-12-16 18:11:58 -05004840*/
James Smart8663cbb2016-03-31 14:12:33 -07004841LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05004842
4843/*
4844# Specifies the maximum number of ELS cmds we can have outstanding (for
4845# discovery). Value range is [1,64]. Default value = 32.
4846*/
James Smart3de2a652007-08-02 11:09:59 -04004847LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05004848 "during discovery");
4849
4850/*
James Smartc4a7c922013-05-31 17:04:59 -04004851# lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4852# will be scanned by the SCSI midlayer when sequential scanning is
4853# used; and is also the highest LUN ID allowed when the SCSI midlayer
4854# parses REPORT_LUN responses. The lpfc driver has no LUN count or
4855# LUN ID limit, but the SCSI midlayer requires this field for the uses
4856# above. The lpfc driver limits the default value to 255 for two reasons.
4857# As it bounds the sequential scan loop, scanning for thousands of luns
4858# on a target can take minutes of wall clock time. Additionally,
4859# there are FC targets, such as JBODs, that only recognize 8-bits of
4860# LUN ID. When they receive a value greater than 8 bits, they chop off
4861# the high order bits. In other words, they see LUN IDs 0, 256, 512,
4862# and so on all as LUN ID 0. This causes the linux kernel, which sees
4863# valid responses at each of the LUN IDs, to believe there are multiple
4864# devices present, when in fact, there is only 1.
4865# A customer that is aware of their target behaviors, and the results as
4866# indicated above, is welcome to increase the lpfc_max_luns value.
4867# As mentioned, this value is not used by the lpfc driver, only the
4868# SCSI midlayer.
James Smart65a29c12006-07-06 15:50:50 -04004869# Value range is [0,65535]. Default value is 255.
4870# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05004871*/
Hannes Reinecke1abf6352014-06-25 15:27:38 +02004872LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
dea31012005-04-17 16:05:31 -05004873
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05004874/*
4875# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4876# Value range is [1,255], default value is 10.
4877*/
4878LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4879 "Milliseconds driver will wait between polling FCP ring");
4880
James Smart4ff43242006-12-02 13:34:56 -05004881/*
James Smart0c411222013-09-06 12:22:46 -04004882# lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4883# to complete in seconds. Value range is [5,180], default value is 60.
4884*/
4885LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4886 "Maximum time to wait for task management commands to complete");
4887/*
James Smart4ff43242006-12-02 13:34:56 -05004888# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4889# support this feature
George Kadianakis8605c462010-01-17 21:19:31 +02004890# 0 = MSI disabled
James Smart4ff43242006-12-02 13:34:56 -05004891# 1 = MSI enabled
George Kadianakis8605c462010-01-17 21:19:31 +02004892# 2 = MSI-X enabled (default)
4893# Value range is [0,2]. Default value is 2.
James Smart4ff43242006-12-02 13:34:56 -05004894*/
George Kadianakis8605c462010-01-17 21:19:31 +02004895LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
James Smartdb2378e2008-02-08 18:49:51 -05004896 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05004897
James Smart13815c82008-01-11 01:52:48 -05004898/*
James Smartf358dd02017-02-12 13:52:34 -08004899 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
James Smart895427b2017-02-12 13:52:30 -08004900 *
4901 * 0 = NVME OAS disabled
4902 * 1 = NVME OAS enabled
4903 *
4904 * Value range is [0,1]. Default value is 0.
4905 */
4906LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4907 "Use OAS bit on NVME IOs");
4908
4909/*
4910 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4911 * will advertise it supports to the SCSI layer. This also will map to
4912 * the number of WQs the driver will create.
4913 *
4914 * 0 = Configure the number of io channels to the number of active CPUs.
4915 * 1,32 = Manually specify how many io channels to use.
4916 *
4917 * Value range is [0,32]. Default value is 4.
4918 */
4919LPFC_ATTR_R(fcp_io_channel,
4920 LPFC_FCP_IO_CHAN_DEF,
4921 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
James Smart67d12732012-08-03 12:36:13 -04004922 "Set the number of FCP I/O channels");
4923
4924/*
James Smart895427b2017-02-12 13:52:30 -08004925 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4926 * will advertise it supports to the NVME layer. This also will map to
4927 * the number of WQs the driver will create.
4928 *
4929 * This module parameter is valid when lpfc_enable_fc4_type is set
4930 * to support NVME.
4931 *
4932 * The NVME Layer will try to create this many, plus 1 administrative
4933 * hardware queue. The administrative queue will always map to WQ 0
4934 * A hardware IO queue maps (qidx) to a specific driver WQ.
4935 *
4936 * 0 = Configure the number of io channels to the number of active CPUs.
4937 * 1,32 = Manually specify how many io channels to use.
4938 *
4939 * Value range is [0,32]. Default value is 0.
4940 */
4941LPFC_ATTR_R(nvme_io_channel,
4942 LPFC_NVME_IO_CHAN_DEF,
4943 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4944 "Set the number of NVME I/O channels");
4945
4946/*
James Smart13815c82008-01-11 01:52:48 -05004947# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4948# 0 = HBA resets disabled
4949# 1 = HBA resets enabled (default)
4950# Value range is [0,1]. Default value is 1.
4951*/
4952LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04004953
James Smart13815c82008-01-11 01:52:48 -05004954/*
James Smarteb7a3392010-11-20 23:12:02 -05004955# lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
James Smart13815c82008-01-11 01:52:48 -05004956# 0 = HBA Heartbeat disabled
4957# 1 = HBA Heartbeat enabled (default)
4958# Value range is [0,1]. Default value is 1.
4959*/
James Smarteb7a3392010-11-20 23:12:02 -05004960LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05004961
James Smart83108bd2008-01-11 01:53:09 -05004962/*
James Smart1ba981f2014-02-20 09:56:45 -05004963# lpfc_EnableXLane: Enable Express Lane Feature
4964# 0x0 Express Lane Feature disabled
4965# 0x1 Express Lane Feature enabled
4966# Value range is [0,1]. Default value is 0.
4967*/
4968LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
4969
4970/*
4971# lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
4972# 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
4973# Value range is [0x0,0x7f]. Default value is 0
4974*/
James Smart28d7f3d2014-05-21 08:05:28 -04004975LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
James Smart1ba981f2014-02-20 09:56:45 -05004976
4977/*
James Smart81301a92008-12-04 22:39:46 -05004978# lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
4979# 0 = BlockGuard disabled (default)
4980# 1 = BlockGuard enabled
4981# Value range is [0,1]. Default value is 0.
4982*/
4983LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
4984
James Smart6fb120a2009-05-22 14:52:59 -04004985/*
James Smartba20c852012-08-03 12:36:52 -04004986# lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
4987# 0 = disabled (default)
4988# 1 = enabled
4989# Value range is [0,1]. Default value is 0.
James Smart5688d672013-04-17 20:17:13 -04004990#
4991# This feature in under investigation and may be supported in the future.
James Smartba20c852012-08-03 12:36:52 -04004992*/
4993unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
4994
James Smartba20c852012-08-03 12:36:52 -04004995/*
James Smart81301a92008-12-04 22:39:46 -05004996# lpfc_prot_mask: i
4997# - Bit mask of host protection capabilities used to register with the
4998# SCSI mid-layer
4999# - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5000# - Allows you to ultimately specify which profiles to use
5001# - Default will result in registering capabilities for all profiles.
James Smart005ffa72012-09-29 11:29:17 -04005002# - SHOST_DIF_TYPE1_PROTECTION 1
5003# HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5004# - SHOST_DIX_TYPE0_PROTECTION 8
5005# HBA supports DIX Type 0: Host to HBA protection only
5006# - SHOST_DIX_TYPE1_PROTECTION 16
5007# HBA supports DIX Type 1: Host to HBA Type 1 protection
James Smart81301a92008-12-04 22:39:46 -05005008#
5009*/
James Smartb3b98b72016-10-13 15:06:06 -07005010LPFC_ATTR(prot_mask,
5011 (SHOST_DIF_TYPE1_PROTECTION |
5012 SHOST_DIX_TYPE0_PROTECTION |
5013 SHOST_DIX_TYPE1_PROTECTION),
5014 0,
5015 (SHOST_DIF_TYPE1_PROTECTION |
5016 SHOST_DIX_TYPE0_PROTECTION |
5017 SHOST_DIX_TYPE1_PROTECTION),
5018 "T10-DIF host protection capabilities mask");
James Smart81301a92008-12-04 22:39:46 -05005019
5020/*
5021# lpfc_prot_guard: i
5022# - Bit mask of protection guard types to register with the SCSI mid-layer
James Smart005ffa72012-09-29 11:29:17 -04005023# - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
James Smart81301a92008-12-04 22:39:46 -05005024# - Allows you to ultimately specify which profiles to use
5025# - Default will result in registering capabilities for all guard types
5026#
5027*/
James Smartb3b98b72016-10-13 15:06:06 -07005028LPFC_ATTR(prot_guard,
5029 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5030 "T10-DIF host protection guard type");
James Smart81301a92008-12-04 22:39:46 -05005031
James Smart92494142011-02-16 12:39:44 -05005032/*
5033 * Delay initial NPort discovery when Clean Address bit is cleared in
5034 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5035 * This parameter can have value 0 or 1.
5036 * When this parameter is set to 0, no delay is added to the initial
5037 * discovery.
5038 * When this parameter is set to non-zero value, initial Nport discovery is
5039 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5040 * accept and FCID/Fabric name/Fabric portname is changed.
5041 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5042 * when Clean Address bit is cleared in FLOGI/FDISC
5043 * accept and FCID/Fabric name/Fabric portname is changed.
5044 * Default value is 0.
5045 */
James Smart8eb8b962016-07-06 12:36:08 -07005046LPFC_ATTR(delay_discovery, 0, 0, 1,
5047 "Delay NPort discovery when Clean Address bit is cleared.");
James Smart81301a92008-12-04 22:39:46 -05005048
5049/*
James Smart3621a712009-04-06 18:47:14 -04005050 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
James Smart96f70772013-04-17 20:16:15 -04005051 * This value can be set to values between 64 and 4096. The default value is
James Smart83108bd2008-01-11 01:53:09 -05005052 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5053 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
James Smart96f70772013-04-17 20:16:15 -04005054 * Because of the additional overhead involved in setting up T10-DIF,
5055 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5056 * and will be limited to 512 if BlockGuard is enabled under SLI3.
James Smart83108bd2008-01-11 01:53:09 -05005057 */
5058LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5059 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5060
James Smart96f70772013-04-17 20:16:15 -04005061/*
James Smart7bdedb32016-07-06 12:36:00 -07005062 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5063 * 0 = MDS Diagnostics disabled (default)
5064 * 1 = MDS Diagnostics enabled
5065 * Value range is [0,1]. Default value is 0.
5066 */
5067LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5068
Tony Jonesee959b02008-02-22 00:13:36 +01005069struct device_attribute *lpfc_hba_attrs[] = {
James Smart895427b2017-02-12 13:52:30 -08005070 &dev_attr_nvme_info,
James Smart81301a92008-12-04 22:39:46 -05005071 &dev_attr_bg_info,
5072 &dev_attr_bg_guard_err,
5073 &dev_attr_bg_apptag_err,
5074 &dev_attr_bg_reftag_err,
Tony Jonesee959b02008-02-22 00:13:36 +01005075 &dev_attr_info,
5076 &dev_attr_serialnum,
5077 &dev_attr_modeldesc,
5078 &dev_attr_modelname,
5079 &dev_attr_programtype,
5080 &dev_attr_portnum,
5081 &dev_attr_fwrev,
5082 &dev_attr_hdw,
5083 &dev_attr_option_rom_version,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005084 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005085 &dev_attr_num_discovered_ports,
James Smart84774a42008-08-24 21:50:06 -04005086 &dev_attr_menlo_mgmt_mode,
Tony Jonesee959b02008-02-22 00:13:36 +01005087 &dev_attr_lpfc_drvr_version,
James Smart45ed1192009-10-02 15:17:02 -04005088 &dev_attr_lpfc_enable_fip,
Tony Jonesee959b02008-02-22 00:13:36 +01005089 &dev_attr_lpfc_temp_sensor,
5090 &dev_attr_lpfc_log_verbose,
5091 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005092 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005093 &dev_attr_lpfc_hba_queue_depth,
5094 &dev_attr_lpfc_peer_port_login,
5095 &dev_attr_lpfc_nodev_tmo,
5096 &dev_attr_lpfc_devloss_tmo,
James Smart895427b2017-02-12 13:52:30 -08005097 &dev_attr_lpfc_enable_fc4_type,
5098 &dev_attr_lpfc_xri_split,
Tony Jonesee959b02008-02-22 00:13:36 +01005099 &dev_attr_lpfc_fcp_class,
5100 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005101 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005102 &dev_attr_lpfc_ack0,
5103 &dev_attr_lpfc_topology,
5104 &dev_attr_lpfc_scan_down,
5105 &dev_attr_lpfc_link_speed,
James Smart49aa1432012-08-03 12:36:42 -04005106 &dev_attr_lpfc_fcp_io_sched,
James Smarta6571c62012-10-31 14:44:42 -04005107 &dev_attr_lpfc_fcp2_no_tgt_reset,
Tony Jonesee959b02008-02-22 00:13:36 +01005108 &dev_attr_lpfc_cr_delay,
5109 &dev_attr_lpfc_cr_count,
5110 &dev_attr_lpfc_multi_ring_support,
5111 &dev_attr_lpfc_multi_ring_rctl,
5112 &dev_attr_lpfc_multi_ring_type,
5113 &dev_attr_lpfc_fdmi_on,
James Smart4258e982015-12-16 18:11:58 -05005114 &dev_attr_lpfc_enable_SmartSAN,
Tony Jonesee959b02008-02-22 00:13:36 +01005115 &dev_attr_lpfc_max_luns,
5116 &dev_attr_lpfc_enable_npiv,
James Smart7d791df2011-07-22 18:37:52 -04005117 &dev_attr_lpfc_fcf_failover_policy,
James Smart19ca7602010-11-20 23:11:55 -05005118 &dev_attr_lpfc_enable_rrq,
Tony Jonesee959b02008-02-22 00:13:36 +01005119 &dev_attr_nport_evt_cnt,
5120 &dev_attr_board_mode,
5121 &dev_attr_max_vpi,
5122 &dev_attr_used_vpi,
5123 &dev_attr_max_rpi,
5124 &dev_attr_used_rpi,
5125 &dev_attr_max_xri,
5126 &dev_attr_used_xri,
5127 &dev_attr_npiv_info,
5128 &dev_attr_issue_reset,
5129 &dev_attr_lpfc_poll,
5130 &dev_attr_lpfc_poll_tmo,
James Smart0c411222013-09-06 12:22:46 -04005131 &dev_attr_lpfc_task_mgmt_tmo,
Tony Jonesee959b02008-02-22 00:13:36 +01005132 &dev_attr_lpfc_use_msi,
James Smart895427b2017-02-12 13:52:30 -08005133 &dev_attr_lpfc_nvme_oas,
James Smartda0436e2009-05-22 14:51:39 -04005134 &dev_attr_lpfc_fcp_imax,
James Smart7bb03bb2013-04-17 20:19:16 -04005135 &dev_attr_lpfc_fcp_cpu_map,
James Smart67d12732012-08-03 12:36:13 -04005136 &dev_attr_lpfc_fcp_io_channel,
James Smartf358dd02017-02-12 13:52:34 -08005137 &dev_attr_lpfc_suppress_rsp,
James Smart895427b2017-02-12 13:52:30 -08005138 &dev_attr_lpfc_nvme_io_channel,
James Smart2d7dbc42017-02-12 13:52:35 -08005139 &dev_attr_lpfc_nvmet_mrq,
5140 &dev_attr_lpfc_nvmet_mrq_post,
James Smart895427b2017-02-12 13:52:30 -08005141 &dev_attr_lpfc_nvme_enable_fb,
James Smart2d7dbc42017-02-12 13:52:35 -08005142 &dev_attr_lpfc_nvmet_fb_size,
James Smart81301a92008-12-04 22:39:46 -05005143 &dev_attr_lpfc_enable_bg,
James Smart352e5fd2016-12-30 06:57:47 -08005144 &dev_attr_lpfc_soft_wwnn,
5145 &dev_attr_lpfc_soft_wwpn,
5146 &dev_attr_lpfc_soft_wwn_enable,
Tony Jonesee959b02008-02-22 00:13:36 +01005147 &dev_attr_lpfc_enable_hba_reset,
5148 &dev_attr_lpfc_enable_hba_heartbeat,
James Smart1ba981f2014-02-20 09:56:45 -05005149 &dev_attr_lpfc_EnableXLane,
5150 &dev_attr_lpfc_XLanePriority,
5151 &dev_attr_lpfc_xlane_lun,
5152 &dev_attr_lpfc_xlane_tgt,
5153 &dev_attr_lpfc_xlane_vpt,
5154 &dev_attr_lpfc_xlane_lun_state,
5155 &dev_attr_lpfc_xlane_lun_status,
James Smartc92c8412016-07-06 12:36:05 -07005156 &dev_attr_lpfc_xlane_priority,
Tony Jonesee959b02008-02-22 00:13:36 +01005157 &dev_attr_lpfc_sg_seg_cnt,
James Smart977b5a02008-09-07 11:52:04 -04005158 &dev_attr_lpfc_max_scsicmpl_time,
James Smartea2151b2008-09-07 11:52:10 -04005159 &dev_attr_lpfc_stat_data_ctrl,
James Smart0d878412009-10-02 15:16:56 -04005160 &dev_attr_lpfc_aer_support,
5161 &dev_attr_lpfc_aer_state_cleanup,
James Smart912e3ac2011-05-24 11:42:11 -04005162 &dev_attr_lpfc_sriov_nr_virtfn,
James Smartc71ab862012-10-31 14:44:33 -04005163 &dev_attr_lpfc_req_fw_upgrade,
James Smart84d1b002010-02-12 14:42:33 -05005164 &dev_attr_lpfc_suppress_link_up,
James Smart2a9bf3d2010-06-07 15:24:45 -04005165 &dev_attr_lpfc_iocb_cnt,
5166 &dev_attr_iocb_hw,
5167 &dev_attr_txq_hw,
5168 &dev_attr_txcmplq_hw,
James Smartbc739052010-08-04 16:11:18 -04005169 &dev_attr_lpfc_fips_level,
5170 &dev_attr_lpfc_fips_rev,
James Smartab56dc22011-02-16 12:39:57 -05005171 &dev_attr_lpfc_dss,
James Smart912e3ac2011-05-24 11:42:11 -04005172 &dev_attr_lpfc_sriov_hw_max_virtfn,
James Smart026abb82011-12-13 13:20:45 -05005173 &dev_attr_protocol,
James Smart1ba981f2014-02-20 09:56:45 -05005174 &dev_attr_lpfc_xlane_supported,
James Smart7bdedb32016-07-06 12:36:00 -07005175 &dev_attr_lpfc_enable_mds_diags,
dea31012005-04-17 16:05:31 -05005176 NULL,
5177};
5178
Tony Jonesee959b02008-02-22 00:13:36 +01005179struct device_attribute *lpfc_vport_attrs[] = {
5180 &dev_attr_info,
Hannes Reineckebbd1ae42008-03-18 14:32:28 +01005181 &dev_attr_link_state,
Tony Jonesee959b02008-02-22 00:13:36 +01005182 &dev_attr_num_discovered_ports,
5183 &dev_attr_lpfc_drvr_version,
5184 &dev_attr_lpfc_log_verbose,
5185 &dev_attr_lpfc_lun_queue_depth,
James Smart7dc517d2010-07-14 15:32:10 -04005186 &dev_attr_lpfc_tgt_queue_depth,
Tony Jonesee959b02008-02-22 00:13:36 +01005187 &dev_attr_lpfc_nodev_tmo,
5188 &dev_attr_lpfc_devloss_tmo,
5189 &dev_attr_lpfc_hba_queue_depth,
5190 &dev_attr_lpfc_peer_port_login,
5191 &dev_attr_lpfc_restrict_login,
5192 &dev_attr_lpfc_fcp_class,
5193 &dev_attr_lpfc_use_adisc,
James Smart3cb01c52013-07-15 18:35:04 -04005194 &dev_attr_lpfc_first_burst_size,
Tony Jonesee959b02008-02-22 00:13:36 +01005195 &dev_attr_lpfc_max_luns,
5196 &dev_attr_nport_evt_cnt,
5197 &dev_attr_npiv_info,
5198 &dev_attr_lpfc_enable_da_id,
James Smartea2151b2008-09-07 11:52:10 -04005199 &dev_attr_lpfc_max_scsicmpl_time,
5200 &dev_attr_lpfc_stat_data_ctrl,
James Smart21e9a0a2009-05-22 14:53:21 -04005201 &dev_attr_lpfc_static_vport,
James Smartbc739052010-08-04 16:11:18 -04005202 &dev_attr_lpfc_fips_level,
5203 &dev_attr_lpfc_fips_rev,
James Smart3de2a652007-08-02 11:09:59 -04005204 NULL,
5205};
5206
James Smarte59058c2008-08-24 21:49:00 -04005207/**
James Smart3621a712009-04-06 18:47:14 -04005208 * sysfs_ctlreg_write - Write method for writing to ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005209 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005210 * @kobj: kernel kobject that contains the kernel class device.
5211 * @bin_attr: kernel attributes passed to us.
5212 * @buf: contains the data to be written to the adapter IOREG space.
5213 * @off: offset into buffer to beginning of data.
5214 * @count: bytes to transfer.
5215 *
5216 * Description:
5217 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5218 * Uses the adapter io control registers to send buf contents to the adapter.
5219 *
5220 * Returns:
5221 * -ERANGE off and count combo out of range
5222 * -EINVAL off, count or buff address invalid
5223 * -EPERM adapter is offline
5224 * value of count, buf contents written
5225 **/
dea31012005-04-17 16:05:31 -05005226static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005227sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5228 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005229 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005230{
5231 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01005232 struct device *dev = container_of(kobj, struct device, kobj);
5233 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005234 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5235 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005236
James Smartf1126682009-06-10 17:22:44 -04005237 if (phba->sli_rev >= LPFC_SLI_REV4)
5238 return -EPERM;
5239
dea31012005-04-17 16:05:31 -05005240 if ((off + count) > FF_REG_AREA_SIZE)
5241 return -ERANGE;
5242
James Smartf7a919b2011-08-21 21:49:16 -04005243 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5244 return 0;
dea31012005-04-17 16:05:31 -05005245
5246 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5247 return -EINVAL;
5248
James Smartf7a919b2011-08-21 21:49:16 -04005249 /* This is to protect HBA registers from accidental writes. */
5250 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5251 return -EINVAL;
5252
5253 if (!(vport->fc_flag & FC_OFFLINE_MODE))
dea31012005-04-17 16:05:31 -05005254 return -EPERM;
dea31012005-04-17 16:05:31 -05005255
James Smart2e0fef82007-06-17 19:56:36 -05005256 spin_lock_irq(&phba->hbalock);
James Smartf7a919b2011-08-21 21:49:16 -04005257 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5258 buf_off += sizeof(uint32_t))
5259 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
dea31012005-04-17 16:05:31 -05005260 phba->ctrl_regs_memmap_p + off + buf_off);
5261
James Smart2e0fef82007-06-17 19:56:36 -05005262 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005263
5264 return count;
5265}
5266
James Smarte59058c2008-08-24 21:49:00 -04005267/**
James Smart3621a712009-04-06 18:47:14 -04005268 * sysfs_ctlreg_read - Read method for reading from ctlreg
Chris Wright2c3c8be2010-05-12 18:28:57 -07005269 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005270 * @kobj: kernel kobject that contains the kernel class device.
5271 * @bin_attr: kernel attributes passed to us.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005272 * @buf: if successful contains the data from the adapter IOREG space.
James Smarte59058c2008-08-24 21:49:00 -04005273 * @off: offset into buffer to beginning of data.
5274 * @count: bytes to transfer.
5275 *
5276 * Description:
5277 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5278 * Uses the adapter io control registers to read data into buf.
5279 *
5280 * Returns:
5281 * -ERANGE off and count combo out of range
5282 * -EINVAL off, count or buff address invalid
5283 * value of count, buf contents read
5284 **/
dea31012005-04-17 16:05:31 -05005285static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005286sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5287 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005288 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005289{
5290 size_t buf_off;
5291 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01005292 struct device *dev = container_of(kobj, struct device, kobj);
5293 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05005294 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5295 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005296
James Smartf1126682009-06-10 17:22:44 -04005297 if (phba->sli_rev >= LPFC_SLI_REV4)
5298 return -EPERM;
5299
dea31012005-04-17 16:05:31 -05005300 if (off > FF_REG_AREA_SIZE)
5301 return -ERANGE;
5302
5303 if ((off + count) > FF_REG_AREA_SIZE)
5304 count = FF_REG_AREA_SIZE - off;
5305
5306 if (count == 0) return 0;
5307
5308 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5309 return -EINVAL;
5310
James Smart2e0fef82007-06-17 19:56:36 -05005311 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005312
5313 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5314 tmp_ptr = (uint32_t *)(buf + buf_off);
5315 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5316 }
5317
James Smart2e0fef82007-06-17 19:56:36 -05005318 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005319
5320 return count;
5321}
5322
5323static struct bin_attribute sysfs_ctlreg_attr = {
5324 .attr = {
5325 .name = "ctlreg",
5326 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005327 },
5328 .size = 256,
5329 .read = sysfs_ctlreg_read,
5330 .write = sysfs_ctlreg_write,
5331};
5332
James Smarte59058c2008-08-24 21:49:00 -04005333/**
James Smart3621a712009-04-06 18:47:14 -04005334 * sysfs_mbox_write - Write method for writing information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005335 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005336 * @kobj: kernel kobject that contains the kernel class device.
5337 * @bin_attr: kernel attributes passed to us.
5338 * @buf: contains the data to be written to sysfs mbox.
5339 * @off: offset into buffer to beginning of data.
5340 * @count: bytes to transfer.
5341 *
5342 * Description:
James Smart026abb82011-12-13 13:20:45 -05005343 * Deprecated function. All mailbox access from user space is performed via the
5344 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005345 *
5346 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005347 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005348 **/
dea31012005-04-17 16:05:31 -05005349static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005350sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5351 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005352 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005353{
James Smart026abb82011-12-13 13:20:45 -05005354 return -EPERM;
dea31012005-04-17 16:05:31 -05005355}
5356
James Smarte59058c2008-08-24 21:49:00 -04005357/**
James Smart3621a712009-04-06 18:47:14 -04005358 * sysfs_mbox_read - Read method for reading information via mbox
Chris Wright2c3c8be2010-05-12 18:28:57 -07005359 * @filp: open sysfs file
James Smarte59058c2008-08-24 21:49:00 -04005360 * @kobj: kernel kobject that contains the kernel class device.
5361 * @bin_attr: kernel attributes passed to us.
5362 * @buf: contains the data to be read from sysfs mbox.
5363 * @off: offset into buffer to beginning of data.
5364 * @count: bytes to transfer.
5365 *
5366 * Description:
James Smart026abb82011-12-13 13:20:45 -05005367 * Deprecated function. All mailbox access from user space is performed via the
5368 * bsg interface.
James Smarte59058c2008-08-24 21:49:00 -04005369 *
5370 * Returns:
James Smart026abb82011-12-13 13:20:45 -05005371 * -EPERM operation not permitted
James Smarte59058c2008-08-24 21:49:00 -04005372 **/
dea31012005-04-17 16:05:31 -05005373static ssize_t
Chris Wright2c3c8be2010-05-12 18:28:57 -07005374sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5375 struct bin_attribute *bin_attr,
Zhang Rui91a69022007-06-09 13:57:22 +08005376 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05005377{
James Smart026abb82011-12-13 13:20:45 -05005378 return -EPERM;
dea31012005-04-17 16:05:31 -05005379}
5380
5381static struct bin_attribute sysfs_mbox_attr = {
5382 .attr = {
5383 .name = "mbox",
5384 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05005385 },
James Smartc0c11512011-05-24 11:41:34 -04005386 .size = MAILBOX_SYSFS_MAX,
dea31012005-04-17 16:05:31 -05005387 .read = sysfs_mbox_read,
5388 .write = sysfs_mbox_write,
5389};
5390
James Smarte59058c2008-08-24 21:49:00 -04005391/**
James Smart3621a712009-04-06 18:47:14 -04005392 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005393 * @vport: address of lpfc vport structure.
5394 *
5395 * Return codes:
5396 * zero on success
5397 * error return code from sysfs_create_bin_file()
5398 **/
dea31012005-04-17 16:05:31 -05005399int
James Smart2e0fef82007-06-17 19:56:36 -05005400lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005401{
James Smart2e0fef82007-06-17 19:56:36 -05005402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005403 int error;
5404
Tony Jonesee959b02008-02-22 00:13:36 +01005405 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smarteada2722008-12-04 22:39:13 -05005406 &sysfs_drvr_stat_data_attr);
5407
5408 /* Virtual ports do not need ctrl_reg and mbox */
5409 if (error || vport->port_type == LPFC_NPIV_PORT)
5410 goto out;
5411
5412 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005413 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005414 if (error)
James Smarteada2722008-12-04 22:39:13 -05005415 goto out_remove_stat_attr;
dea31012005-04-17 16:05:31 -05005416
Tony Jonesee959b02008-02-22 00:13:36 +01005417 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05005418 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05005419 if (error)
5420 goto out_remove_ctlreg_attr;
5421
5422 return 0;
5423out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01005424 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
James Smarteada2722008-12-04 22:39:13 -05005425out_remove_stat_attr:
5426 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5427 &sysfs_drvr_stat_data_attr);
dea31012005-04-17 16:05:31 -05005428out:
5429 return error;
5430}
5431
James Smarte59058c2008-08-24 21:49:00 -04005432/**
James Smart3621a712009-04-06 18:47:14 -04005433 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
James Smarte59058c2008-08-24 21:49:00 -04005434 * @vport: address of lpfc vport structure.
5435 **/
dea31012005-04-17 16:05:31 -05005436void
James Smart2e0fef82007-06-17 19:56:36 -05005437lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005438{
James Smart2e0fef82007-06-17 19:56:36 -05005439 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartea2151b2008-09-07 11:52:10 -04005440 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5441 &sysfs_drvr_stat_data_attr);
James Smarteada2722008-12-04 22:39:13 -05005442 /* Virtual ports do not need ctrl_reg and mbox */
5443 if (vport->port_type == LPFC_NPIV_PORT)
5444 return;
Tony Jonesee959b02008-02-22 00:13:36 +01005445 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5446 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05005447}
5448
dea31012005-04-17 16:05:31 -05005449/*
5450 * Dynamic FC Host Attributes Support
5451 */
5452
James Smarte59058c2008-08-24 21:49:00 -04005453/**
James Smart6c9231f2016-12-19 15:07:24 -08005454 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5455 * @shost: kernel scsi host pointer.
5456 **/
5457static void
5458lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5459{
5460 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5461
5462 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5463 sizeof fc_host_symbolic_name(shost));
5464}
5465
5466/**
James Smart3621a712009-04-06 18:47:14 -04005467 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
James Smarte59058c2008-08-24 21:49:00 -04005468 * @shost: kernel scsi host pointer.
5469 **/
dea31012005-04-17 16:05:31 -05005470static void
5471lpfc_get_host_port_id(struct Scsi_Host *shost)
5472{
James Smart2e0fef82007-06-17 19:56:36 -05005473 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5474
dea31012005-04-17 16:05:31 -05005475 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05005476 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05005477}
5478
James Smarte59058c2008-08-24 21:49:00 -04005479/**
James Smart3621a712009-04-06 18:47:14 -04005480 * lpfc_get_host_port_type - Set the value of the scsi host port type
James Smarte59058c2008-08-24 21:49:00 -04005481 * @shost: kernel scsi host pointer.
5482 **/
dea31012005-04-17 16:05:31 -05005483static void
5484lpfc_get_host_port_type(struct Scsi_Host *shost)
5485{
James Smart2e0fef82007-06-17 19:56:36 -05005486 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5487 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005488
5489 spin_lock_irq(shost->host_lock);
5490
James Smart92d7f7b2007-06-17 19:56:38 -05005491 if (vport->port_type == LPFC_NPIV_PORT) {
5492 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5493 } else if (lpfc_is_link_up(phba)) {
James Smart76a95d72010-11-20 23:11:48 -05005494 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05005495 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05005496 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5497 else
5498 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5499 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005500 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05005501 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5502 else
5503 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5504 }
5505 } else
5506 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5507
5508 spin_unlock_irq(shost->host_lock);
5509}
5510
James Smarte59058c2008-08-24 21:49:00 -04005511/**
James Smart3621a712009-04-06 18:47:14 -04005512 * lpfc_get_host_port_state - Set the value of the scsi host port state
James Smarte59058c2008-08-24 21:49:00 -04005513 * @shost: kernel scsi host pointer.
5514 **/
dea31012005-04-17 16:05:31 -05005515static void
5516lpfc_get_host_port_state(struct Scsi_Host *shost)
5517{
James Smart2e0fef82007-06-17 19:56:36 -05005518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5519 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005520
5521 spin_lock_irq(shost->host_lock);
5522
James Smart2e0fef82007-06-17 19:56:36 -05005523 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005524 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5525 else {
James Smart2e0fef82007-06-17 19:56:36 -05005526 switch (phba->link_state) {
5527 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05005528 case LPFC_LINK_DOWN:
5529 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5530 break;
5531 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05005532 case LPFC_CLEAR_LA:
5533 case LPFC_HBA_READY:
James Smart026abb82011-12-13 13:20:45 -05005534 /* Links up, reports port state accordingly */
5535 if (vport->port_state < LPFC_VPORT_READY)
5536 fc_host_port_state(shost) =
5537 FC_PORTSTATE_BYPASSED;
5538 else
5539 fc_host_port_state(shost) =
5540 FC_PORTSTATE_ONLINE;
dea31012005-04-17 16:05:31 -05005541 break;
5542 case LPFC_HBA_ERROR:
5543 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5544 break;
5545 default:
5546 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5547 break;
5548 }
5549 }
5550
5551 spin_unlock_irq(shost->host_lock);
5552}
5553
James Smarte59058c2008-08-24 21:49:00 -04005554/**
James Smart3621a712009-04-06 18:47:14 -04005555 * lpfc_get_host_speed - Set the value of the scsi host speed
James Smarte59058c2008-08-24 21:49:00 -04005556 * @shost: kernel scsi host pointer.
5557 **/
dea31012005-04-17 16:05:31 -05005558static void
5559lpfc_get_host_speed(struct Scsi_Host *shost)
5560{
James Smart2e0fef82007-06-17 19:56:36 -05005561 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5562 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005563
5564 spin_lock_irq(shost->host_lock);
5565
James Smarta085e872015-12-16 18:12:02 -05005566 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
dea31012005-04-17 16:05:31 -05005567 switch(phba->fc_linkspeed) {
James Smart76a95d72010-11-20 23:11:48 -05005568 case LPFC_LINK_SPEED_1GHZ:
5569 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
dea31012005-04-17 16:05:31 -05005570 break;
James Smart76a95d72010-11-20 23:11:48 -05005571 case LPFC_LINK_SPEED_2GHZ:
5572 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
dea31012005-04-17 16:05:31 -05005573 break;
James Smart76a95d72010-11-20 23:11:48 -05005574 case LPFC_LINK_SPEED_4GHZ:
5575 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
dea31012005-04-17 16:05:31 -05005576 break;
James Smart76a95d72010-11-20 23:11:48 -05005577 case LPFC_LINK_SPEED_8GHZ:
5578 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
James Smartb87eab32007-04-25 09:53:28 -04005579 break;
James Smart76a95d72010-11-20 23:11:48 -05005580 case LPFC_LINK_SPEED_10GHZ:
5581 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
James Smartf4b4c682009-05-22 14:53:12 -04005582 break;
James Smart76a95d72010-11-20 23:11:48 -05005583 case LPFC_LINK_SPEED_16GHZ:
5584 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5585 break;
James Smartd38dd522015-08-31 16:48:17 -04005586 case LPFC_LINK_SPEED_32GHZ:
5587 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5588 break;
James Smart76a95d72010-11-20 23:11:48 -05005589 default:
5590 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005591 break;
5592 }
James Smart09372822008-01-11 01:52:54 -05005593 } else
5594 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05005595
5596 spin_unlock_irq(shost->host_lock);
5597}
5598
James Smarte59058c2008-08-24 21:49:00 -04005599/**
James Smart3621a712009-04-06 18:47:14 -04005600 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
James Smarte59058c2008-08-24 21:49:00 -04005601 * @shost: kernel scsi host pointer.
5602 **/
dea31012005-04-17 16:05:31 -05005603static void
5604lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5605{
James Smart2e0fef82007-06-17 19:56:36 -05005606 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5607 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005608 u64 node_name;
dea31012005-04-17 16:05:31 -05005609
5610 spin_lock_irq(shost->host_lock);
5611
James Smart73d91e52011-10-10 21:32:10 -04005612 if ((vport->port_state > LPFC_FLOGI) &&
5613 ((vport->fc_flag & FC_FABRIC) ||
5614 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5615 (vport->fc_flag & FC_PUBLIC_LOOP))))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07005616 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05005617 else
5618 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05005619 node_name = 0;
dea31012005-04-17 16:05:31 -05005620
5621 spin_unlock_irq(shost->host_lock);
5622
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07005623 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05005624}
5625
James Smarte59058c2008-08-24 21:49:00 -04005626/**
James Smart3621a712009-04-06 18:47:14 -04005627 * lpfc_get_stats - Return statistical information about the adapter
James Smarte59058c2008-08-24 21:49:00 -04005628 * @shost: kernel scsi host pointer.
5629 *
5630 * Notes:
5631 * NULL on error for link down, no mbox pool, sli2 active,
5632 * management not allowed, memory allocation error, or mbox error.
5633 *
5634 * Returns:
5635 * NULL for error
5636 * address of the adapter host statistics
5637 **/
dea31012005-04-17 16:05:31 -05005638static struct fc_host_statistics *
5639lpfc_get_stats(struct Scsi_Host *shost)
5640{
James Smart2e0fef82007-06-17 19:56:36 -05005641 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5642 struct lpfc_hba *phba = vport->phba;
5643 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005644 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04005645 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05005646 LPFC_MBOXQ_t *pmboxq;
5647 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04005648 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005649 int rc = 0;
dea31012005-04-17 16:05:31 -05005650
James Smart92d7f7b2007-06-17 19:56:38 -05005651 /*
5652 * prevent udev from issuing mailbox commands until the port is
5653 * configured.
5654 */
James Smart2e0fef82007-06-17 19:56:36 -05005655 if (phba->link_state < LPFC_LINK_DOWN ||
5656 !phba->mbox_mem_pool ||
James Smartf4b4c682009-05-22 14:53:12 -04005657 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05005658 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005659
5660 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005661 return NULL;
5662
dea31012005-04-17 16:05:31 -05005663 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5664 if (!pmboxq)
5665 return NULL;
5666 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5667
James Smart04c68492009-05-22 14:52:52 -04005668 pmb = &pmboxq->u.mb;
dea31012005-04-17 16:05:31 -05005669 pmb->mbxCommand = MBX_READ_STATUS;
5670 pmb->mbxOwner = OWN_HOST;
5671 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005672 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005673
James Smart75baf692010-06-08 18:31:21 -04005674 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005675 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005676 else
dea31012005-04-17 16:05:31 -05005677 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5678
5679 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005680 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005681 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005682 return NULL;
5683 }
5684
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04005685 memset(hs, 0, sizeof (struct fc_host_statistics));
5686
dea31012005-04-17 16:05:31 -05005687 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005688 /*
5689 * The MBX_READ_STATUS returns tx_k_bytes which has to
5690 * converted to words
5691 */
5692 hs->tx_words = (uint64_t)
5693 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5694 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005695 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
James Smart73d91e52011-10-10 21:32:10 -04005696 hs->rx_words = (uint64_t)
5697 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5698 * (uint64_t)256);
dea31012005-04-17 16:05:31 -05005699
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005700 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05005701 pmb->mbxCommand = MBX_READ_LNK_STAT;
5702 pmb->mbxOwner = OWN_HOST;
5703 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005704 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05005705
James Smart75baf692010-06-08 18:31:21 -04005706 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05005707 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04005708 else
dea31012005-04-17 16:05:31 -05005709 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5710
5711 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005712 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05005713 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005714 return NULL;
5715 }
5716
5717 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5718 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5719 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5720 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5721 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5722 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5723 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5724
James Smart64ba8812006-08-02 15:24:34 -04005725 hs->link_failure_count -= lso->link_failure_count;
5726 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5727 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5728 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5729 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5730 hs->invalid_crc_count -= lso->invalid_crc_count;
5731 hs->error_frames -= lso->error_frames;
5732
James Smart76a95d72010-11-20 23:11:48 -05005733 if (phba->hba_flag & HBA_FCOE_MODE) {
James Smart4d9ab992009-10-02 15:16:39 -04005734 hs->lip_count = -1;
5735 hs->nos_count = (phba->link_events >> 1);
5736 hs->nos_count -= lso->link_events;
James Smart76a95d72010-11-20 23:11:48 -05005737 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005738 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005739 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005740 hs->nos_count = -1;
5741 } else {
5742 hs->lip_count = -1;
5743 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005744 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05005745 }
5746
5747 hs->dumped_frames = -1;
5748
James Smart64ba8812006-08-02 15:24:34 -04005749 seconds = get_seconds();
5750 if (seconds < psli->stats_start)
5751 hs->seconds_since_last_reset = seconds +
5752 ((unsigned long)-1 - psli->stats_start);
5753 else
5754 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05005755
James Smart1dcb58e2007-04-25 09:51:30 -04005756 mempool_free(pmboxq, phba->mbox_mem_pool);
5757
dea31012005-04-17 16:05:31 -05005758 return hs;
5759}
5760
James Smarte59058c2008-08-24 21:49:00 -04005761/**
James Smart3621a712009-04-06 18:47:14 -04005762 * lpfc_reset_stats - Copy the adapter link stats information
James Smarte59058c2008-08-24 21:49:00 -04005763 * @shost: kernel scsi host pointer.
5764 **/
James Smart64ba8812006-08-02 15:24:34 -04005765static void
5766lpfc_reset_stats(struct Scsi_Host *shost)
5767{
James Smart2e0fef82007-06-17 19:56:36 -05005768 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5769 struct lpfc_hba *phba = vport->phba;
5770 struct lpfc_sli *psli = &phba->sli;
5771 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04005772 LPFC_MBOXQ_t *pmboxq;
5773 MAILBOX_t *pmb;
5774 int rc = 0;
5775
James Smart2e0fef82007-06-17 19:56:36 -05005776 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04005777 return;
5778
James Smart64ba8812006-08-02 15:24:34 -04005779 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5780 if (!pmboxq)
5781 return;
5782 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5783
James Smart04c68492009-05-22 14:52:52 -04005784 pmb = &pmboxq->u.mb;
James Smart64ba8812006-08-02 15:24:34 -04005785 pmb->mbxCommand = MBX_READ_STATUS;
5786 pmb->mbxOwner = OWN_HOST;
5787 pmb->un.varWords[0] = 0x1; /* reset request */
5788 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005789 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005790
James Smart2e0fef82007-06-17 19:56:36 -05005791 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005792 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005793 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5794 else
5795 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5796
5797 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005798 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005799 mempool_free(pmboxq, phba->mbox_mem_pool);
5800 return;
5801 }
5802
5803 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5804 pmb->mbxCommand = MBX_READ_LNK_STAT;
5805 pmb->mbxOwner = OWN_HOST;
5806 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005807 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04005808
James Smart2e0fef82007-06-17 19:56:36 -05005809 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smartf4b4c682009-05-22 14:53:12 -04005810 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
James Smart64ba8812006-08-02 15:24:34 -04005811 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5812 else
5813 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5814
5815 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05005816 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04005817 mempool_free( pmboxq, phba->mbox_mem_pool);
5818 return;
5819 }
5820
5821 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5822 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5823 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5824 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5825 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5826 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5827 lso->error_frames = pmb->un.varRdLnk.crcCnt;
James Smart76a95d72010-11-20 23:11:48 -05005828 if (phba->hba_flag & HBA_FCOE_MODE)
James Smart4d9ab992009-10-02 15:16:39 -04005829 lso->link_events = (phba->link_events >> 1);
5830 else
5831 lso->link_events = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04005832
5833 psli->stats_start = get_seconds();
5834
James Smart1dcb58e2007-04-25 09:51:30 -04005835 mempool_free(pmboxq, phba->mbox_mem_pool);
5836
James Smart64ba8812006-08-02 15:24:34 -04005837 return;
5838}
dea31012005-04-17 16:05:31 -05005839
5840/*
5841 * The LPFC driver treats linkdown handling as target loss events so there
5842 * are no sysfs handlers for link_down_tmo.
5843 */
James Smart685f0bf2007-04-25 09:53:08 -04005844
James Smarte59058c2008-08-24 21:49:00 -04005845/**
James Smart3621a712009-04-06 18:47:14 -04005846 * lpfc_get_node_by_target - Return the nodelist for a target
James Smarte59058c2008-08-24 21:49:00 -04005847 * @starget: kernel scsi target pointer.
5848 *
5849 * Returns:
5850 * address of the node list if found
5851 * NULL target not found
5852 **/
James Smart685f0bf2007-04-25 09:53:08 -04005853static struct lpfc_nodelist *
5854lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05005855{
James Smart2e0fef82007-06-17 19:56:36 -05005856 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04005858 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005859
5860 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005861 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05005862 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005863 if (NLP_CHK_NODE_ACT(ndlp) &&
5864 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04005865 starget->id == ndlp->nlp_sid) {
5866 spin_unlock_irq(shost->host_lock);
5867 return ndlp;
dea31012005-04-17 16:05:31 -05005868 }
5869 }
5870 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04005871 return NULL;
5872}
dea31012005-04-17 16:05:31 -05005873
James Smarte59058c2008-08-24 21:49:00 -04005874/**
James Smart3621a712009-04-06 18:47:14 -04005875 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
James Smarte59058c2008-08-24 21:49:00 -04005876 * @starget: kernel scsi target pointer.
5877 **/
James Smart685f0bf2007-04-25 09:53:08 -04005878static void
5879lpfc_get_starget_port_id(struct scsi_target *starget)
5880{
5881 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5882
5883 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05005884}
5885
James Smarte59058c2008-08-24 21:49:00 -04005886/**
James Smart3621a712009-04-06 18:47:14 -04005887 * lpfc_get_starget_node_name - Set the target node name
James Smarte59058c2008-08-24 21:49:00 -04005888 * @starget: kernel scsi target pointer.
5889 *
5890 * Description: Set the target node name to the ndlp node name wwn or zero.
5891 **/
dea31012005-04-17 16:05:31 -05005892static void
5893lpfc_get_starget_node_name(struct scsi_target *starget)
5894{
James Smart685f0bf2007-04-25 09:53:08 -04005895 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005896
James Smart685f0bf2007-04-25 09:53:08 -04005897 fc_starget_node_name(starget) =
5898 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005899}
5900
James Smarte59058c2008-08-24 21:49:00 -04005901/**
James Smart3621a712009-04-06 18:47:14 -04005902 * lpfc_get_starget_port_name - Set the target port name
James Smarte59058c2008-08-24 21:49:00 -04005903 * @starget: kernel scsi target pointer.
5904 *
5905 * Description: set the target port name to the ndlp port name wwn or zero.
5906 **/
dea31012005-04-17 16:05:31 -05005907static void
5908lpfc_get_starget_port_name(struct scsi_target *starget)
5909{
James Smart685f0bf2007-04-25 09:53:08 -04005910 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05005911
James Smart685f0bf2007-04-25 09:53:08 -04005912 fc_starget_port_name(starget) =
5913 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05005914}
5915
James Smarte59058c2008-08-24 21:49:00 -04005916/**
James Smart3621a712009-04-06 18:47:14 -04005917 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
James Smarte59058c2008-08-24 21:49:00 -04005918 * @rport: fc rport address.
5919 * @timeout: new value for dev loss tmo.
5920 *
5921 * Description:
5922 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5923 * dev_loss_tmo to one.
5924 **/
dea31012005-04-17 16:05:31 -05005925static void
dea31012005-04-17 16:05:31 -05005926lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5927{
dea31012005-04-17 16:05:31 -05005928 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04005929 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05005930 else
James Smartc01f3202006-08-18 17:47:08 -04005931 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05005932}
5933
James Smarte59058c2008-08-24 21:49:00 -04005934/**
James Smart3621a712009-04-06 18:47:14 -04005935 * lpfc_rport_show_function - Return rport target information
James Smarte59058c2008-08-24 21:49:00 -04005936 *
5937 * Description:
5938 * Macro that uses field to generate a function with the name lpfc_show_rport_
5939 *
5940 * lpfc_show_rport_##field: returns the bytes formatted in buf
5941 * @cdev: class converted to an fc_rport.
5942 * @buf: on return contains the target_field or zero.
5943 *
5944 * Returns: size of formatted string.
5945 **/
dea31012005-04-17 16:05:31 -05005946#define lpfc_rport_show_function(field, format_string, sz, cast) \
5947static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01005948lpfc_show_rport_##field (struct device *dev, \
5949 struct device_attribute *attr, \
5950 char *buf) \
dea31012005-04-17 16:05:31 -05005951{ \
Tony Jonesee959b02008-02-22 00:13:36 +01005952 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05005953 struct lpfc_rport_data *rdata = rport->hostdata; \
5954 return snprintf(buf, sz, format_string, \
5955 (rdata->target) ? cast rdata->target->field : 0); \
5956}
5957
5958#define lpfc_rport_rd_attr(field, format_string, sz) \
5959 lpfc_rport_show_function(field, format_string, sz, ) \
5960static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
5961
James Smarteada2722008-12-04 22:39:13 -05005962/**
James Smart3621a712009-04-06 18:47:14 -04005963 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
James Smarteada2722008-12-04 22:39:13 -05005964 * @fc_vport: The fc_vport who's symbolic name has been changed.
5965 *
5966 * Description:
5967 * This function is called by the transport after the @fc_vport's symbolic name
5968 * has been changed. This function re-registers the symbolic name with the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005969 * switch to propagate the change into the fabric if the vport is active.
James Smarteada2722008-12-04 22:39:13 -05005970 **/
5971static void
5972lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
5973{
5974 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
5975
5976 if (vport->port_state == LPFC_VPORT_READY)
5977 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
5978}
dea31012005-04-17 16:05:31 -05005979
James Smartf4b4c682009-05-22 14:53:12 -04005980/**
5981 * lpfc_hba_log_verbose_init - Set hba's log verbose level
5982 * @phba: Pointer to lpfc_hba struct.
5983 *
5984 * This function is called by the lpfc_get_cfgparam() routine to set the
5985 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02005986 * log message according to the module's lpfc_log_verbose parameter setting
James Smartf4b4c682009-05-22 14:53:12 -04005987 * before hba port or vport created.
5988 **/
5989static void
5990lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
5991{
5992 phba->cfg_log_verbose = verbose;
5993}
5994
dea31012005-04-17 16:05:31 -05005995struct fc_function_template lpfc_transport_functions = {
5996 /* fixed attributes the driver supports */
5997 .show_host_node_name = 1,
5998 .show_host_port_name = 1,
5999 .show_host_supported_classes = 1,
6000 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05006001 .show_host_supported_speeds = 1,
6002 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006003
6004 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006005 .show_host_symbolic_name = 1,
dea31012005-04-17 16:05:31 -05006006
6007 /* dynamic attributes the driver supports */
6008 .get_host_port_id = lpfc_get_host_port_id,
6009 .show_host_port_id = 1,
6010
6011 .get_host_port_type = lpfc_get_host_port_type,
6012 .show_host_port_type = 1,
6013
6014 .get_host_port_state = lpfc_get_host_port_state,
6015 .show_host_port_state = 1,
6016
6017 /* active_fc4s is shown but doesn't change (thus no get function) */
6018 .show_host_active_fc4s = 1,
6019
6020 .get_host_speed = lpfc_get_host_speed,
6021 .show_host_speed = 1,
6022
6023 .get_host_fabric_name = lpfc_get_host_fabric_name,
6024 .show_host_fabric_name = 1,
6025
6026 /*
6027 * The LPFC driver treats linkdown handling as target loss events
6028 * so there are no sysfs handlers for link_down_tmo.
6029 */
6030
6031 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04006032 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05006033
6034 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6035 .show_rport_maxframe_size = 1,
6036 .show_rport_supported_classes = 1,
6037
dea31012005-04-17 16:05:31 -05006038 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6039 .show_rport_dev_loss_tmo = 1,
6040
6041 .get_starget_port_id = lpfc_get_starget_port_id,
6042 .show_starget_port_id = 1,
6043
6044 .get_starget_node_name = lpfc_get_starget_node_name,
6045 .show_starget_node_name = 1,
6046
6047 .get_starget_port_name = lpfc_get_starget_port_name,
6048 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07006049
6050 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04006051 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6052 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05006053
James Smart92d7f7b2007-06-17 19:56:38 -05006054 .dd_fcvport_size = sizeof(struct lpfc_vport *),
James Smarteada2722008-12-04 22:39:13 -05006055
6056 .vport_disable = lpfc_vport_disable,
6057
6058 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smartf1c3b0f2009-07-19 10:01:32 -04006059
6060 .bsg_request = lpfc_bsg_request,
6061 .bsg_timeout = lpfc_bsg_timeout,
James Smart92d7f7b2007-06-17 19:56:38 -05006062};
6063
James Smart98c9ea52007-10-27 13:37:33 -04006064struct fc_function_template lpfc_vport_transport_functions = {
6065 /* fixed attributes the driver supports */
6066 .show_host_node_name = 1,
6067 .show_host_port_name = 1,
6068 .show_host_supported_classes = 1,
6069 .show_host_supported_fc4s = 1,
6070 .show_host_supported_speeds = 1,
6071 .show_host_maxframe_size = 1,
James Smart6c9231f2016-12-19 15:07:24 -08006072
6073 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
James Smarteada2722008-12-04 22:39:13 -05006074 .show_host_symbolic_name = 1,
James Smart98c9ea52007-10-27 13:37:33 -04006075
6076 /* dynamic attributes the driver supports */
6077 .get_host_port_id = lpfc_get_host_port_id,
6078 .show_host_port_id = 1,
6079
6080 .get_host_port_type = lpfc_get_host_port_type,
6081 .show_host_port_type = 1,
6082
6083 .get_host_port_state = lpfc_get_host_port_state,
6084 .show_host_port_state = 1,
6085
6086 /* active_fc4s is shown but doesn't change (thus no get function) */
6087 .show_host_active_fc4s = 1,
6088
6089 .get_host_speed = lpfc_get_host_speed,
6090 .show_host_speed = 1,
6091
6092 .get_host_fabric_name = lpfc_get_host_fabric_name,
6093 .show_host_fabric_name = 1,
6094
6095 /*
6096 * The LPFC driver treats linkdown handling as target loss events
6097 * so there are no sysfs handlers for link_down_tmo.
6098 */
6099
6100 .get_fc_host_stats = lpfc_get_stats,
6101 .reset_fc_host_stats = lpfc_reset_stats,
6102
6103 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6104 .show_rport_maxframe_size = 1,
6105 .show_rport_supported_classes = 1,
6106
6107 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6108 .show_rport_dev_loss_tmo = 1,
6109
6110 .get_starget_port_id = lpfc_get_starget_port_id,
6111 .show_starget_port_id = 1,
6112
6113 .get_starget_node_name = lpfc_get_starget_node_name,
6114 .show_starget_node_name = 1,
6115
6116 .get_starget_port_name = lpfc_get_starget_port_name,
6117 .show_starget_port_name = 1,
6118
6119 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6120 .terminate_rport_io = lpfc_terminate_rport_io,
6121
6122 .vport_disable = lpfc_vport_disable,
James Smarteada2722008-12-04 22:39:13 -05006123
6124 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
James Smart98c9ea52007-10-27 13:37:33 -04006125};
6126
James Smarte59058c2008-08-24 21:49:00 -04006127/**
James Smart3621a712009-04-06 18:47:14 -04006128 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
James Smarte59058c2008-08-24 21:49:00 -04006129 * @phba: lpfc_hba pointer.
6130 **/
dea31012005-04-17 16:05:31 -05006131void
6132lpfc_get_cfgparam(struct lpfc_hba *phba)
6133{
James Smart49aa1432012-08-03 12:36:42 -04006134 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
James Smarta6571c62012-10-31 14:44:42 -04006135 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006136 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6137 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05006138 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05006139 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6140 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006141 lpfc_ack0_init(phba, lpfc_ack0);
6142 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04006143 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05006144 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart0c411222013-09-06 12:22:46 -04006145 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
James Smart78b2d852007-08-02 11:10:21 -04006146 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart7d791df2011-07-22 18:37:52 -04006147 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
James Smart19ca7602010-11-20 23:11:55 -05006148 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
James Smart4258e982015-12-16 18:11:58 -05006149 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6150 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
James Smart4ff43242006-12-02 13:34:56 -05006151 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart895427b2017-02-12 13:52:30 -08006152 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
James Smartda0436e2009-05-22 14:51:39 -04006153 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
James Smart7bb03bb2013-04-17 20:19:16 -04006154 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
James Smart13815c82008-01-11 01:52:48 -05006155 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6156 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James Smart2ea259e2017-02-12 13:52:27 -08006157
James Smart1ba981f2014-02-20 09:56:45 -05006158 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6159 if (phba->sli_rev != LPFC_SLI_REV4)
6160 phba->cfg_EnableXLane = 0;
6161 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
James Smart2ea259e2017-02-12 13:52:27 -08006162
James Smart1ba981f2014-02-20 09:56:45 -05006163 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6164 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6165 phba->cfg_oas_lun_state = 0;
6166 phba->cfg_oas_lun_status = 0;
6167 phba->cfg_oas_flags = 0;
James Smartc92c8412016-07-06 12:36:05 -07006168 phba->cfg_oas_priority = 0;
James Smart81301a92008-12-04 22:39:46 -05006169 lpfc_enable_bg_init(phba, lpfc_enable_bg);
James Smartb3b98b72016-10-13 15:06:06 -07006170 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6171 lpfc_prot_guard_init(phba, lpfc_prot_guard);
James Smart45ed1192009-10-02 15:17:02 -04006172 if (phba->sli_rev == LPFC_SLI_REV4)
6173 phba->cfg_poll = 0;
6174 else
James Smart1ba981f2014-02-20 09:56:45 -05006175 phba->cfg_poll = lpfc_poll;
James Smartf358dd02017-02-12 13:52:34 -08006176 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
James Smart4258e982015-12-16 18:11:58 -05006177
James Smart895427b2017-02-12 13:52:30 -08006178 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
James Smart2d7dbc42017-02-12 13:52:35 -08006179 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6180 lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post);
James Smart895427b2017-02-12 13:52:30 -08006181
6182 /* Initialize first burst. Target vs Initiator are different. */
6183 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
James Smart2d7dbc42017-02-12 13:52:35 -08006184 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
James Smart895427b2017-02-12 13:52:30 -08006185 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6186 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6187
6188 if (phba->sli_rev != LPFC_SLI_REV4) {
6189 /* NVME only supported on SLI4 */
6190 phba->nvmet_support = 0;
6191 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6192 } else {
6193 /* We MUST have FCP support */
6194 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6195 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6196 }
6197
6198 /* A value of 0 means use the number of CPUs found in the system */
James Smart895427b2017-02-12 13:52:30 -08006199 if (phba->cfg_fcp_io_channel == 0)
6200 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006201 if (phba->cfg_nvme_io_channel == 0)
6202 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smart895427b2017-02-12 13:52:30 -08006203
6204 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6205 phba->cfg_fcp_io_channel = 0;
6206
James Smartf358dd02017-02-12 13:52:34 -08006207 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6208 phba->cfg_nvme_io_channel = 0;
6209
James Smart895427b2017-02-12 13:52:30 -08006210 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6211 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6212 else
6213 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6214
James Smart352e5fd2016-12-30 06:57:47 -08006215 phba->cfg_soft_wwnn = 0L;
6216 phba->cfg_soft_wwpn = 0L;
James Smart895427b2017-02-12 13:52:30 -08006217 lpfc_xri_split_init(phba, lpfc_xri_split);
James Smart83108bd2008-01-11 01:53:09 -05006218 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
James Smart7054a602007-04-25 09:52:34 -04006219 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart6fb120a2009-05-22 14:52:59 -04006220 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
James Smart0d878412009-10-02 15:16:56 -04006221 lpfc_aer_support_init(phba, lpfc_aer_support);
James Smart912e3ac2011-05-24 11:42:11 -04006222 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
James Smartc71ab862012-10-31 14:44:33 -04006223 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
James Smart84d1b002010-02-12 14:42:33 -05006224 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
James Smart2a9bf3d2010-06-07 15:24:45 -04006225 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
James Smart8eb8b962016-07-06 12:36:08 -07006226 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
James Smart12247e82016-07-06 12:36:09 -07006227 lpfc_sli_mode_init(phba, lpfc_sli_mode);
James Smartab56dc22011-02-16 12:39:57 -05006228 phba->cfg_enable_dss = 1;
James Smart7bdedb32016-07-06 12:36:00 -07006229 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
James Smart3de2a652007-08-02 11:09:59 -04006230 return;
6231}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05006232
James Smarte59058c2008-08-24 21:49:00 -04006233/**
James Smart895427b2017-02-12 13:52:30 -08006234 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6235 * dependencies between protocols and roles.
6236 * @phba: lpfc_hba pointer.
6237 **/
6238void
6239lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6240{
James Smart895427b2017-02-12 13:52:30 -08006241 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6242 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
James Smartf358dd02017-02-12 13:52:34 -08006243
James Smart895427b2017-02-12 13:52:30 -08006244 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6245 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6246
James Smartf358dd02017-02-12 13:52:34 -08006247 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6248 phba->nvmet_support) {
6249 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6250 phba->cfg_fcp_io_channel = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006251
6252 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6253 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6254 "NVME Target PRLI ACC enable_fb ",
6255 phba->cfg_nvme_enable_fb,
6256 phba->cfg_nvmet_fb_size,
6257 LPFC_NVMET_FB_SZ_MAX);
6258
6259 if (phba->cfg_nvme_enable_fb == 0)
6260 phba->cfg_nvmet_fb_size = 0;
6261 else {
6262 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6263 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6264 }
6265
6266 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6267 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6268 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6269 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6270 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6271 phba->cfg_nvmet_mrq);
6272 }
6273 } else {
James Smartf358dd02017-02-12 13:52:34 -08006274 /* Not NVME Target mode. Turn off Target parameters. */
6275 phba->nvmet_support = 0;
James Smart2d7dbc42017-02-12 13:52:35 -08006276 phba->cfg_nvmet_mrq = 0;
6277 phba->cfg_nvmet_mrq_post = 0;
6278 phba->cfg_nvmet_fb_size = 0;
6279 }
James Smartf358dd02017-02-12 13:52:34 -08006280
James Smart895427b2017-02-12 13:52:30 -08006281 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6282 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6283 else
6284 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6285}
6286
6287/**
James Smart3621a712009-04-06 18:47:14 -04006288 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
James Smarte59058c2008-08-24 21:49:00 -04006289 * @vport: lpfc_vport pointer.
6290 **/
James Smart3de2a652007-08-02 11:09:59 -04006291void
6292lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6293{
James Smarte8b62012007-08-02 11:10:09 -04006294 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04006295 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
James Smart7dc517d2010-07-14 15:32:10 -04006296 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04006297 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6298 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6299 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6300 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6301 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6302 lpfc_use_adisc_init(vport, lpfc_use_adisc);
James Smart3cb01c52013-07-15 18:35:04 -04006303 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
James Smart977b5a02008-09-07 11:52:04 -04006304 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
James Smart3de2a652007-08-02 11:09:59 -04006305 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6306 lpfc_max_luns_init(vport, lpfc_max_luns);
6307 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04006308 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05006309 return;
6310}