]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/scsi/lpfc/lpfc_attr.c
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / lpfc / lpfc_attr.c
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
8 * www.broadcom.com *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
10 * *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23
24 #include <linux/ctype.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/aer.h>
30 #include <linux/gfp.h>
31 #include <linux/kernel.h>
32
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_tcq.h>
37 #include <scsi/scsi_transport_fc.h>
38 #include <scsi/fc/fc_fs.h>
39
40 #include <linux/nvme-fc-driver.h>
41
42 #include "lpfc_hw4.h"
43 #include "lpfc_hw.h"
44 #include "lpfc_sli.h"
45 #include "lpfc_sli4.h"
46 #include "lpfc_nl.h"
47 #include "lpfc_disc.h"
48 #include "lpfc.h"
49 #include "lpfc_scsi.h"
50 #include "lpfc_nvme.h"
51 #include "lpfc_nvmet.h"
52 #include "lpfc_logmsg.h"
53 #include "lpfc_version.h"
54 #include "lpfc_compat.h"
55 #include "lpfc_crtn.h"
56 #include "lpfc_vport.h"
57 #include "lpfc_attr.h"
58
59 #define LPFC_DEF_DEVLOSS_TMO 30
60 #define LPFC_MIN_DEVLOSS_TMO 1
61 #define LPFC_MAX_DEVLOSS_TMO 255
62
63 #define LPFC_DEF_MRQ_POST 512
64 #define LPFC_MIN_MRQ_POST 512
65 #define LPFC_MAX_MRQ_POST 2048
66
67 /*
68 * Write key size should be multiple of 4. If write key is changed
69 * make sure that library write key is also changed.
70 */
71 #define LPFC_REG_WRITE_KEY_SIZE 4
72 #define LPFC_REG_WRITE_KEY "EMLX"
73
74 /**
75 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
76 * @incr: integer to convert.
77 * @hdw: ascii string holding converted integer plus a string terminator.
78 *
79 * Description:
80 * JEDEC Joint Electron Device Engineering Council.
81 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
82 * character string. The string is then terminated with a NULL in byte 9.
83 * Hex 0-9 becomes ascii '0' to '9'.
84 * Hex a-f becomes ascii '=' to 'B' capital B.
85 *
86 * Notes:
87 * Coded for 32 bit integers only.
88 **/
89 static void
90 lpfc_jedec_to_ascii(int incr, char hdw[])
91 {
92 int i, j;
93 for (i = 0; i < 8; i++) {
94 j = (incr & 0xf);
95 if (j <= 9)
96 hdw[7 - i] = 0x30 + j;
97 else
98 hdw[7 - i] = 0x61 + j - 10;
99 incr = (incr >> 4);
100 }
101 hdw[8] = 0;
102 return;
103 }
104
105 /**
106 * lpfc_drvr_version_show - Return the Emulex driver string with version number
107 * @dev: class unused variable.
108 * @attr: device attribute, not used.
109 * @buf: on return contains the module description text.
110 *
111 * Returns: size of formatted string.
112 **/
113 static ssize_t
114 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
115 char *buf)
116 {
117 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
118 }
119
120 /**
121 * lpfc_enable_fip_show - Return the fip mode of the HBA
122 * @dev: class unused variable.
123 * @attr: device attribute, not used.
124 * @buf: on return contains the module description text.
125 *
126 * Returns: size of formatted string.
127 **/
128 static ssize_t
129 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
130 char *buf)
131 {
132 struct Scsi_Host *shost = class_to_shost(dev);
133 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
134 struct lpfc_hba *phba = vport->phba;
135
136 if (phba->hba_flag & HBA_FIP_SUPPORT)
137 return snprintf(buf, PAGE_SIZE, "1\n");
138 else
139 return snprintf(buf, PAGE_SIZE, "0\n");
140 }
141
142 static ssize_t
143 lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr,
144 char *buf)
145 {
146 struct Scsi_Host *shost = class_to_shost(dev);
147 struct lpfc_vport *vport = shost_priv(shost);
148 struct lpfc_hba *phba = vport->phba;
149 struct lpfc_nvmet_tgtport *tgtp;
150 struct nvme_fc_local_port *localport;
151 struct lpfc_nodelist *ndlp;
152 struct nvme_fc_remote_port *nrport;
153 uint64_t data1, data2, data3, tot;
154 char *statep;
155 int len = 0;
156
157 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
158 len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n");
159 return len;
160 }
161 if (phba->nvmet_support) {
162 if (!phba->targetport) {
163 len = snprintf(buf, PAGE_SIZE,
164 "NVME Target: x%llx is not allocated\n",
165 wwn_to_u64(vport->fc_portname.u.wwn));
166 return len;
167 }
168 /* Port state is only one of two values for now. */
169 if (phba->targetport->port_id)
170 statep = "REGISTERED";
171 else
172 statep = "INIT";
173 len += snprintf(buf + len, PAGE_SIZE - len,
174 "NVME Target Enabled State %s\n",
175 statep);
176 len += snprintf(buf + len, PAGE_SIZE - len,
177 "%s%d WWPN x%llx WWNN x%llx DID x%06x\n",
178 "NVME Target: lpfc",
179 phba->brd_no,
180 wwn_to_u64(vport->fc_portname.u.wwn),
181 wwn_to_u64(vport->fc_nodename.u.wwn),
182 phba->targetport->port_id);
183
184 len += snprintf(buf + len, PAGE_SIZE - len,
185 "\nNVME Target: Statistics\n");
186 tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private;
187 len += snprintf(buf+len, PAGE_SIZE-len,
188 "LS: Rcv %08x Drop %08x Abort %08x\n",
189 atomic_read(&tgtp->rcv_ls_req_in),
190 atomic_read(&tgtp->rcv_ls_req_drop),
191 atomic_read(&tgtp->xmt_ls_abort));
192 if (atomic_read(&tgtp->rcv_ls_req_in) !=
193 atomic_read(&tgtp->rcv_ls_req_out)) {
194 len += snprintf(buf+len, PAGE_SIZE-len,
195 "Rcv LS: in %08x != out %08x\n",
196 atomic_read(&tgtp->rcv_ls_req_in),
197 atomic_read(&tgtp->rcv_ls_req_out));
198 }
199
200 len += snprintf(buf+len, PAGE_SIZE-len,
201 "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n",
202 atomic_read(&tgtp->xmt_ls_rsp),
203 atomic_read(&tgtp->xmt_ls_drop),
204 atomic_read(&tgtp->xmt_ls_rsp_cmpl),
205 atomic_read(&tgtp->xmt_ls_rsp_error));
206
207 len += snprintf(buf+len, PAGE_SIZE-len,
208 "FCP: Rcv %08x Defer %08x Release %08x "
209 "Drop %08x\n",
210 atomic_read(&tgtp->rcv_fcp_cmd_in),
211 atomic_read(&tgtp->rcv_fcp_cmd_defer),
212 atomic_read(&tgtp->xmt_fcp_release),
213 atomic_read(&tgtp->rcv_fcp_cmd_drop));
214
215 if (atomic_read(&tgtp->rcv_fcp_cmd_in) !=
216 atomic_read(&tgtp->rcv_fcp_cmd_out)) {
217 len += snprintf(buf+len, PAGE_SIZE-len,
218 "Rcv FCP: in %08x != out %08x\n",
219 atomic_read(&tgtp->rcv_fcp_cmd_in),
220 atomic_read(&tgtp->rcv_fcp_cmd_out));
221 }
222
223 len += snprintf(buf+len, PAGE_SIZE-len,
224 "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x "
225 "drop %08x\n",
226 atomic_read(&tgtp->xmt_fcp_read),
227 atomic_read(&tgtp->xmt_fcp_read_rsp),
228 atomic_read(&tgtp->xmt_fcp_write),
229 atomic_read(&tgtp->xmt_fcp_rsp),
230 atomic_read(&tgtp->xmt_fcp_drop));
231
232 len += snprintf(buf+len, PAGE_SIZE-len,
233 "FCP Rsp Cmpl: %08x err %08x drop %08x\n",
234 atomic_read(&tgtp->xmt_fcp_rsp_cmpl),
235 atomic_read(&tgtp->xmt_fcp_rsp_error),
236 atomic_read(&tgtp->xmt_fcp_rsp_drop));
237
238 len += snprintf(buf+len, PAGE_SIZE-len,
239 "ABORT: Xmt %08x Cmpl %08x\n",
240 atomic_read(&tgtp->xmt_fcp_abort),
241 atomic_read(&tgtp->xmt_fcp_abort_cmpl));
242
243 len += snprintf(buf + len, PAGE_SIZE - len,
244 "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x",
245 atomic_read(&tgtp->xmt_abort_sol),
246 atomic_read(&tgtp->xmt_abort_unsol),
247 atomic_read(&tgtp->xmt_abort_rsp),
248 atomic_read(&tgtp->xmt_abort_rsp_error));
249
250 spin_lock(&phba->sli4_hba.nvmet_ctx_get_lock);
251 spin_lock(&phba->sli4_hba.nvmet_ctx_put_lock);
252 tot = phba->sli4_hba.nvmet_xri_cnt -
253 (phba->sli4_hba.nvmet_ctx_get_cnt +
254 phba->sli4_hba.nvmet_ctx_put_cnt);
255 spin_unlock(&phba->sli4_hba.nvmet_ctx_put_lock);
256 spin_unlock(&phba->sli4_hba.nvmet_ctx_get_lock);
257
258 len += snprintf(buf + len, PAGE_SIZE - len,
259 "IO_CTX: %08x WAIT: cur %08x tot %08x\n"
260 "CTX Outstanding %08llx\n",
261 phba->sli4_hba.nvmet_xri_cnt,
262 phba->sli4_hba.nvmet_io_wait_cnt,
263 phba->sli4_hba.nvmet_io_wait_total,
264 tot);
265
266 len += snprintf(buf+len, PAGE_SIZE-len, "\n");
267 return len;
268 }
269
270 localport = vport->localport;
271 if (!localport) {
272 len = snprintf(buf, PAGE_SIZE,
273 "NVME Initiator x%llx is not allocated\n",
274 wwn_to_u64(vport->fc_portname.u.wwn));
275 return len;
276 }
277 len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n");
278
279 spin_lock_irq(shost->host_lock);
280
281 /* Port state is only one of two values for now. */
282 if (localport->port_id)
283 statep = "ONLINE";
284 else
285 statep = "UNKNOWN ";
286
287 len += snprintf(buf + len, PAGE_SIZE - len,
288 "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n",
289 "NVME LPORT lpfc",
290 phba->brd_no,
291 wwn_to_u64(vport->fc_portname.u.wwn),
292 wwn_to_u64(vport->fc_nodename.u.wwn),
293 localport->port_id, statep);
294
295 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
296 if (!ndlp->nrport)
297 continue;
298
299 /* local short-hand pointer. */
300 nrport = ndlp->nrport->remoteport;
301
302 /* Port state is only one of two values for now. */
303 switch (nrport->port_state) {
304 case FC_OBJSTATE_ONLINE:
305 statep = "ONLINE";
306 break;
307 case FC_OBJSTATE_UNKNOWN:
308 statep = "UNKNOWN ";
309 break;
310 default:
311 statep = "UNSUPPORTED";
312 break;
313 }
314
315 /* Tab in to show lport ownership. */
316 len += snprintf(buf + len, PAGE_SIZE - len,
317 "NVME RPORT ");
318 if (phba->brd_no >= 10)
319 len += snprintf(buf + len, PAGE_SIZE - len, " ");
320
321 len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ",
322 nrport->port_name);
323 len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ",
324 nrport->node_name);
325 len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ",
326 nrport->port_id);
327
328 /* An NVME rport can have multiple roles. */
329 if (nrport->port_role & FC_PORT_ROLE_NVME_INITIATOR)
330 len += snprintf(buf + len, PAGE_SIZE - len,
331 "INITIATOR ");
332 if (nrport->port_role & FC_PORT_ROLE_NVME_TARGET)
333 len += snprintf(buf + len, PAGE_SIZE - len,
334 "TARGET ");
335 if (nrport->port_role & FC_PORT_ROLE_NVME_DISCOVERY)
336 len += snprintf(buf + len, PAGE_SIZE - len,
337 "DISCSRVC ");
338 if (nrport->port_role & ~(FC_PORT_ROLE_NVME_INITIATOR |
339 FC_PORT_ROLE_NVME_TARGET |
340 FC_PORT_ROLE_NVME_DISCOVERY))
341 len += snprintf(buf + len, PAGE_SIZE - len,
342 "UNKNOWN ROLE x%x",
343 nrport->port_role);
344
345 len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep);
346 /* Terminate the string. */
347 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
348 }
349 spin_unlock_irq(shost->host_lock);
350
351 len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n");
352 len += snprintf(buf+len, PAGE_SIZE-len,
353 "LS: Xmt %016x Cmpl %016x\n",
354 atomic_read(&phba->fc4NvmeLsRequests),
355 atomic_read(&phba->fc4NvmeLsCmpls));
356
357 tot = atomic_read(&phba->fc4NvmeIoCmpls);
358 data1 = atomic_read(&phba->fc4NvmeInputRequests);
359 data2 = atomic_read(&phba->fc4NvmeOutputRequests);
360 data3 = atomic_read(&phba->fc4NvmeControlRequests);
361 len += snprintf(buf+len, PAGE_SIZE-len,
362 "FCP: Rd %016llx Wr %016llx IO %016llx\n",
363 data1, data2, data3);
364
365 len += snprintf(buf+len, PAGE_SIZE-len,
366 " Cmpl %016llx Outstanding %016llx\n",
367 tot, (data1 + data2 + data3) - tot);
368 return len;
369 }
370
371 static ssize_t
372 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
373 char *buf)
374 {
375 struct Scsi_Host *shost = class_to_shost(dev);
376 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
377 struct lpfc_hba *phba = vport->phba;
378
379 if (phba->cfg_enable_bg)
380 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
381 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
382 else
383 return snprintf(buf, PAGE_SIZE,
384 "BlockGuard Not Supported\n");
385 else
386 return snprintf(buf, PAGE_SIZE,
387 "BlockGuard Disabled\n");
388 }
389
390 static ssize_t
391 lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr,
392 char *buf)
393 {
394 struct Scsi_Host *shost = class_to_shost(dev);
395 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
396 struct lpfc_hba *phba = vport->phba;
397
398 return snprintf(buf, PAGE_SIZE, "%llu\n",
399 (unsigned long long)phba->bg_guard_err_cnt);
400 }
401
402 static ssize_t
403 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
404 char *buf)
405 {
406 struct Scsi_Host *shost = class_to_shost(dev);
407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
409
410 return snprintf(buf, PAGE_SIZE, "%llu\n",
411 (unsigned long long)phba->bg_apptag_err_cnt);
412 }
413
414 static ssize_t
415 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
416 char *buf)
417 {
418 struct Scsi_Host *shost = class_to_shost(dev);
419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
420 struct lpfc_hba *phba = vport->phba;
421
422 return snprintf(buf, PAGE_SIZE, "%llu\n",
423 (unsigned long long)phba->bg_reftag_err_cnt);
424 }
425
426 /**
427 * lpfc_info_show - Return some pci info about the host in ascii
428 * @dev: class converted to a Scsi_host structure.
429 * @attr: device attribute, not used.
430 * @buf: on return contains the formatted text from lpfc_info().
431 *
432 * Returns: size of formatted string.
433 **/
434 static ssize_t
435 lpfc_info_show(struct device *dev, struct device_attribute *attr,
436 char *buf)
437 {
438 struct Scsi_Host *host = class_to_shost(dev);
439
440 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
441 }
442
443 /**
444 * lpfc_serialnum_show - Return the hba serial number in ascii
445 * @dev: class converted to a Scsi_host structure.
446 * @attr: device attribute, not used.
447 * @buf: on return contains the formatted text serial number.
448 *
449 * Returns: size of formatted string.
450 **/
451 static ssize_t
452 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
453 char *buf)
454 {
455 struct Scsi_Host *shost = class_to_shost(dev);
456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
457 struct lpfc_hba *phba = vport->phba;
458
459 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
460 }
461
462 /**
463 * lpfc_temp_sensor_show - Return the temperature sensor level
464 * @dev: class converted to a Scsi_host structure.
465 * @attr: device attribute, not used.
466 * @buf: on return contains the formatted support level.
467 *
468 * Description:
469 * Returns a number indicating the temperature sensor level currently
470 * supported, zero or one in ascii.
471 *
472 * Returns: size of formatted string.
473 **/
474 static ssize_t
475 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
476 char *buf)
477 {
478 struct Scsi_Host *shost = class_to_shost(dev);
479 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
480 struct lpfc_hba *phba = vport->phba;
481 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
482 }
483
484 /**
485 * lpfc_modeldesc_show - Return the model description of the hba
486 * @dev: class converted to a Scsi_host structure.
487 * @attr: device attribute, not used.
488 * @buf: on return contains the scsi vpd model description.
489 *
490 * Returns: size of formatted string.
491 **/
492 static ssize_t
493 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
494 char *buf)
495 {
496 struct Scsi_Host *shost = class_to_shost(dev);
497 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
498 struct lpfc_hba *phba = vport->phba;
499
500 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
501 }
502
503 /**
504 * lpfc_modelname_show - Return the model name of the hba
505 * @dev: class converted to a Scsi_host structure.
506 * @attr: device attribute, not used.
507 * @buf: on return contains the scsi vpd model name.
508 *
509 * Returns: size of formatted string.
510 **/
511 static ssize_t
512 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
513 char *buf)
514 {
515 struct Scsi_Host *shost = class_to_shost(dev);
516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
517 struct lpfc_hba *phba = vport->phba;
518
519 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
520 }
521
522 /**
523 * lpfc_programtype_show - Return the program type of the hba
524 * @dev: class converted to a Scsi_host structure.
525 * @attr: device attribute, not used.
526 * @buf: on return contains the scsi vpd program type.
527 *
528 * Returns: size of formatted string.
529 **/
530 static ssize_t
531 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
532 char *buf)
533 {
534 struct Scsi_Host *shost = class_to_shost(dev);
535 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
536 struct lpfc_hba *phba = vport->phba;
537
538 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
539 }
540
541 /**
542 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
543 * @dev: class converted to a Scsi_host structure.
544 * @attr: device attribute, not used.
545 * @buf: on return contains the Menlo Maintenance sli flag.
546 *
547 * Returns: size of formatted string.
548 **/
549 static ssize_t
550 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
551 {
552 struct Scsi_Host *shost = class_to_shost(dev);
553 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
554 struct lpfc_hba *phba = vport->phba;
555
556 return snprintf(buf, PAGE_SIZE, "%d\n",
557 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
558 }
559
560 /**
561 * lpfc_vportnum_show - Return the port number in ascii of the hba
562 * @dev: class converted to a Scsi_host structure.
563 * @attr: device attribute, not used.
564 * @buf: on return contains scsi vpd program type.
565 *
566 * Returns: size of formatted string.
567 **/
568 static ssize_t
569 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
570 char *buf)
571 {
572 struct Scsi_Host *shost = class_to_shost(dev);
573 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
574 struct lpfc_hba *phba = vport->phba;
575
576 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
577 }
578
579 /**
580 * lpfc_fwrev_show - Return the firmware rev running in the hba
581 * @dev: class converted to a Scsi_host structure.
582 * @attr: device attribute, not used.
583 * @buf: on return contains the scsi vpd program type.
584 *
585 * Returns: size of formatted string.
586 **/
587 static ssize_t
588 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
589 char *buf)
590 {
591 struct Scsi_Host *shost = class_to_shost(dev);
592 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
593 struct lpfc_hba *phba = vport->phba;
594 uint32_t if_type;
595 uint8_t sli_family;
596 char fwrev[FW_REV_STR_SIZE];
597 int len;
598
599 lpfc_decode_firmware_rev(phba, fwrev, 1);
600 if_type = phba->sli4_hba.pc_sli4_params.if_type;
601 sli_family = phba->sli4_hba.pc_sli4_params.sli_family;
602
603 if (phba->sli_rev < LPFC_SLI_REV4)
604 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n",
605 fwrev, phba->sli_rev);
606 else
607 len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n",
608 fwrev, phba->sli_rev, if_type, sli_family);
609
610 return len;
611 }
612
613 /**
614 * lpfc_hdw_show - Return the jedec information about the hba
615 * @dev: class converted to a Scsi_host structure.
616 * @attr: device attribute, not used.
617 * @buf: on return contains the scsi vpd program type.
618 *
619 * Returns: size of formatted string.
620 **/
621 static ssize_t
622 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
623 {
624 char hdw[9];
625 struct Scsi_Host *shost = class_to_shost(dev);
626 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
627 struct lpfc_hba *phba = vport->phba;
628 lpfc_vpd_t *vp = &phba->vpd;
629
630 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
631 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
632 }
633
634 /**
635 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
636 * @dev: class converted to a Scsi_host structure.
637 * @attr: device attribute, not used.
638 * @buf: on return contains the ROM and FCode ascii strings.
639 *
640 * Returns: size of formatted string.
641 **/
642 static ssize_t
643 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
644 char *buf)
645 {
646 struct Scsi_Host *shost = class_to_shost(dev);
647 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
648 struct lpfc_hba *phba = vport->phba;
649 char fwrev[FW_REV_STR_SIZE];
650
651 if (phba->sli_rev < LPFC_SLI_REV4)
652 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
653
654 lpfc_decode_firmware_rev(phba, fwrev, 1);
655 return snprintf(buf, PAGE_SIZE, "%s\n", fwrev);
656 }
657
658 /**
659 * lpfc_state_show - Return the link state of the port
660 * @dev: class converted to a Scsi_host structure.
661 * @attr: device attribute, not used.
662 * @buf: on return contains text describing the state of the link.
663 *
664 * Notes:
665 * The switch statement has no default so zero will be returned.
666 *
667 * Returns: size of formatted string.
668 **/
669 static ssize_t
670 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
671 char *buf)
672 {
673 struct Scsi_Host *shost = class_to_shost(dev);
674 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
675 struct lpfc_hba *phba = vport->phba;
676 int len = 0;
677
678 switch (phba->link_state) {
679 case LPFC_LINK_UNKNOWN:
680 case LPFC_WARM_START:
681 case LPFC_INIT_START:
682 case LPFC_INIT_MBX_CMDS:
683 case LPFC_LINK_DOWN:
684 case LPFC_HBA_ERROR:
685 if (phba->hba_flag & LINK_DISABLED)
686 len += snprintf(buf + len, PAGE_SIZE-len,
687 "Link Down - User disabled\n");
688 else
689 len += snprintf(buf + len, PAGE_SIZE-len,
690 "Link Down\n");
691 break;
692 case LPFC_LINK_UP:
693 case LPFC_CLEAR_LA:
694 case LPFC_HBA_READY:
695 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
696
697 switch (vport->port_state) {
698 case LPFC_LOCAL_CFG_LINK:
699 len += snprintf(buf + len, PAGE_SIZE-len,
700 "Configuring Link\n");
701 break;
702 case LPFC_FDISC:
703 case LPFC_FLOGI:
704 case LPFC_FABRIC_CFG_LINK:
705 case LPFC_NS_REG:
706 case LPFC_NS_QRY:
707 case LPFC_BUILD_DISC_LIST:
708 case LPFC_DISC_AUTH:
709 len += snprintf(buf + len, PAGE_SIZE - len,
710 "Discovery\n");
711 break;
712 case LPFC_VPORT_READY:
713 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
714 break;
715
716 case LPFC_VPORT_FAILED:
717 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
718 break;
719
720 case LPFC_VPORT_UNKNOWN:
721 len += snprintf(buf + len, PAGE_SIZE - len,
722 "Unknown\n");
723 break;
724 }
725 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
726 len += snprintf(buf + len, PAGE_SIZE-len,
727 " Menlo Maint Mode\n");
728 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
729 if (vport->fc_flag & FC_PUBLIC_LOOP)
730 len += snprintf(buf + len, PAGE_SIZE-len,
731 " Public Loop\n");
732 else
733 len += snprintf(buf + len, PAGE_SIZE-len,
734 " Private Loop\n");
735 } else {
736 if (vport->fc_flag & FC_FABRIC)
737 len += snprintf(buf + len, PAGE_SIZE-len,
738 " Fabric\n");
739 else
740 len += snprintf(buf + len, PAGE_SIZE-len,
741 " Point-2-Point\n");
742 }
743 }
744
745 return len;
746 }
747
748 /**
749 * lpfc_sli4_protocol_show - Return the fip mode of the HBA
750 * @dev: class unused variable.
751 * @attr: device attribute, not used.
752 * @buf: on return contains the module description text.
753 *
754 * Returns: size of formatted string.
755 **/
756 static ssize_t
757 lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr,
758 char *buf)
759 {
760 struct Scsi_Host *shost = class_to_shost(dev);
761 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
762 struct lpfc_hba *phba = vport->phba;
763
764 if (phba->sli_rev < LPFC_SLI_REV4)
765 return snprintf(buf, PAGE_SIZE, "fc\n");
766
767 if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) {
768 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE)
769 return snprintf(buf, PAGE_SIZE, "fcoe\n");
770 if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)
771 return snprintf(buf, PAGE_SIZE, "fc\n");
772 }
773 return snprintf(buf, PAGE_SIZE, "unknown\n");
774 }
775
776 /**
777 * lpfc_oas_supported_show - Return whether or not Optimized Access Storage
778 * (OAS) is supported.
779 * @dev: class unused variable.
780 * @attr: device attribute, not used.
781 * @buf: on return contains the module description text.
782 *
783 * Returns: size of formatted string.
784 **/
785 static ssize_t
786 lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr,
787 char *buf)
788 {
789 struct Scsi_Host *shost = class_to_shost(dev);
790 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
791 struct lpfc_hba *phba = vport->phba;
792
793 return snprintf(buf, PAGE_SIZE, "%d\n",
794 phba->sli4_hba.pc_sli4_params.oas_supported);
795 }
796
797 /**
798 * lpfc_link_state_store - Transition the link_state on an HBA port
799 * @dev: class device that is converted into a Scsi_host.
800 * @attr: device attribute, not used.
801 * @buf: one or more lpfc_polling_flags values.
802 * @count: not used.
803 *
804 * Returns:
805 * -EINVAL if the buffer is not "up" or "down"
806 * return from link state change function if non-zero
807 * length of the buf on success
808 **/
809 static ssize_t
810 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
811 const char *buf, size_t count)
812 {
813 struct Scsi_Host *shost = class_to_shost(dev);
814 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
815 struct lpfc_hba *phba = vport->phba;
816
817 int status = -EINVAL;
818
819 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
820 (phba->link_state == LPFC_LINK_DOWN))
821 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
822 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
823 (phba->link_state >= LPFC_LINK_UP))
824 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
825
826 if (status == 0)
827 return strlen(buf);
828 else
829 return status;
830 }
831
832 /**
833 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
834 * @dev: class device that is converted into a Scsi_host.
835 * @attr: device attribute, not used.
836 * @buf: on return contains the sum of fc mapped and unmapped.
837 *
838 * Description:
839 * Returns the ascii text number of the sum of the fc mapped and unmapped
840 * vport counts.
841 *
842 * Returns: size of formatted string.
843 **/
844 static ssize_t
845 lpfc_num_discovered_ports_show(struct device *dev,
846 struct device_attribute *attr, char *buf)
847 {
848 struct Scsi_Host *shost = class_to_shost(dev);
849 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
850
851 return snprintf(buf, PAGE_SIZE, "%d\n",
852 vport->fc_map_cnt + vport->fc_unmap_cnt);
853 }
854
855 /**
856 * lpfc_issue_lip - Misnomer, name carried over from long ago
857 * @shost: Scsi_Host pointer.
858 *
859 * Description:
860 * Bring the link down gracefully then re-init the link. The firmware will
861 * re-init the fiber channel interface as required. Does not issue a LIP.
862 *
863 * Returns:
864 * -EPERM port offline or management commands are being blocked
865 * -ENOMEM cannot allocate memory for the mailbox command
866 * -EIO error sending the mailbox command
867 * zero for success
868 **/
869 static int
870 lpfc_issue_lip(struct Scsi_Host *shost)
871 {
872 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
873 struct lpfc_hba *phba = vport->phba;
874 LPFC_MBOXQ_t *pmboxq;
875 int mbxstatus = MBXERR_ERROR;
876
877 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
878 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
879 return -EPERM;
880
881 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
882
883 if (!pmboxq)
884 return -ENOMEM;
885
886 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
887 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
888 pmboxq->u.mb.mbxOwner = OWN_HOST;
889
890 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
891
892 if ((mbxstatus == MBX_SUCCESS) &&
893 (pmboxq->u.mb.mbxStatus == 0 ||
894 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
895 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
896 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
897 phba->cfg_link_speed);
898 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
899 phba->fc_ratov * 2);
900 if ((mbxstatus == MBX_SUCCESS) &&
901 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
902 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
903 "2859 SLI authentication is required "
904 "for INIT_LINK but has not done yet\n");
905 }
906
907 lpfc_set_loopback_flag(phba);
908 if (mbxstatus != MBX_TIMEOUT)
909 mempool_free(pmboxq, phba->mbox_mem_pool);
910
911 if (mbxstatus == MBXERR_ERROR)
912 return -EIO;
913
914 return 0;
915 }
916
917 int
918 lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock)
919 {
920 int cnt = 0;
921
922 spin_lock_irq(lock);
923 while (!list_empty(q)) {
924 spin_unlock_irq(lock);
925 msleep(20);
926 if (cnt++ > 250) { /* 5 secs */
927 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
928 "0466 %s %s\n",
929 "Outstanding IO when ",
930 "bringing Adapter offline\n");
931 return 0;
932 }
933 spin_lock_irq(lock);
934 }
935 spin_unlock_irq(lock);
936 return 1;
937 }
938
939 /**
940 * lpfc_do_offline - Issues a mailbox command to bring the link down
941 * @phba: lpfc_hba pointer.
942 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
943 *
944 * Notes:
945 * Assumes any error from lpfc_do_offline() will be negative.
946 * Can wait up to 5 seconds for the port ring buffers count
947 * to reach zero, prints a warning if it is not zero and continues.
948 * lpfc_workq_post_event() returns a non-zero return code if call fails.
949 *
950 * Returns:
951 * -EIO error posting the event
952 * zero for success
953 **/
954 static int
955 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
956 {
957 struct completion online_compl;
958 struct lpfc_queue *qp = NULL;
959 struct lpfc_sli_ring *pring;
960 struct lpfc_sli *psli;
961 int status = 0;
962 int i;
963 int rc;
964
965 init_completion(&online_compl);
966 rc = lpfc_workq_post_event(phba, &status, &online_compl,
967 LPFC_EVT_OFFLINE_PREP);
968 if (rc == 0)
969 return -ENOMEM;
970
971 wait_for_completion(&online_compl);
972
973 if (status != 0)
974 return -EIO;
975
976 psli = &phba->sli;
977
978 /* Wait a little for things to settle down, but not
979 * long enough for dev loss timeout to expire.
980 */
981 if (phba->sli_rev != LPFC_SLI_REV4) {
982 for (i = 0; i < psli->num_rings; i++) {
983 pring = &psli->sli3_ring[i];
984 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
985 &phba->hbalock))
986 goto out;
987 }
988 } else {
989 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
990 pring = qp->pring;
991 if (!pring)
992 continue;
993 if (!lpfc_emptyq_wait(phba, &pring->txcmplq,
994 &pring->ring_lock))
995 goto out;
996 }
997 }
998 out:
999 init_completion(&online_compl);
1000 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
1001 if (rc == 0)
1002 return -ENOMEM;
1003
1004 wait_for_completion(&online_compl);
1005
1006 if (status != 0)
1007 return -EIO;
1008
1009 return 0;
1010 }
1011
1012 /**
1013 * lpfc_selective_reset - Offline then onlines the port
1014 * @phba: lpfc_hba pointer.
1015 *
1016 * Description:
1017 * If the port is configured to allow a reset then the hba is brought
1018 * offline then online.
1019 *
1020 * Notes:
1021 * Assumes any error from lpfc_do_offline() will be negative.
1022 * Do not make this function static.
1023 *
1024 * Returns:
1025 * lpfc_do_offline() return code if not zero
1026 * -EIO reset not configured or error posting the event
1027 * zero for success
1028 **/
1029 int
1030 lpfc_selective_reset(struct lpfc_hba *phba)
1031 {
1032 struct completion online_compl;
1033 int status = 0;
1034 int rc;
1035
1036 if (!phba->cfg_enable_hba_reset)
1037 return -EACCES;
1038
1039 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) {
1040 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1041
1042 if (status != 0)
1043 return status;
1044 }
1045
1046 init_completion(&online_compl);
1047 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1048 LPFC_EVT_ONLINE);
1049 if (rc == 0)
1050 return -ENOMEM;
1051
1052 wait_for_completion(&online_compl);
1053
1054 if (status != 0)
1055 return -EIO;
1056
1057 return 0;
1058 }
1059
1060 /**
1061 * lpfc_issue_reset - Selectively resets an adapter
1062 * @dev: class device that is converted into a Scsi_host.
1063 * @attr: device attribute, not used.
1064 * @buf: containing the string "selective".
1065 * @count: unused variable.
1066 *
1067 * Description:
1068 * If the buf contains the string "selective" then lpfc_selective_reset()
1069 * is called to perform the reset.
1070 *
1071 * Notes:
1072 * Assumes any error from lpfc_selective_reset() will be negative.
1073 * If lpfc_selective_reset() returns zero then the length of the buffer
1074 * is returned which indicates success
1075 *
1076 * Returns:
1077 * -EINVAL if the buffer does not contain the string "selective"
1078 * length of buf if lpfc-selective_reset() if the call succeeds
1079 * return value of lpfc_selective_reset() if the call fails
1080 **/
1081 static ssize_t
1082 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
1083 const char *buf, size_t count)
1084 {
1085 struct Scsi_Host *shost = class_to_shost(dev);
1086 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1087 struct lpfc_hba *phba = vport->phba;
1088 int status = -EINVAL;
1089
1090 if (!phba->cfg_enable_hba_reset)
1091 return -EACCES;
1092
1093 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
1094 status = phba->lpfc_selective_reset(phba);
1095
1096 if (status == 0)
1097 return strlen(buf);
1098 else
1099 return status;
1100 }
1101
1102 /**
1103 * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness
1104 * @phba: lpfc_hba pointer.
1105 *
1106 * Description:
1107 * SLI4 interface type-2 device to wait on the sliport status register for
1108 * the readyness after performing a firmware reset.
1109 *
1110 * Returns:
1111 * zero for success, -EPERM when port does not have privilege to perform the
1112 * reset, -EIO when port timeout from recovering from the reset.
1113 *
1114 * Note:
1115 * As the caller will interpret the return code by value, be careful in making
1116 * change or addition to return codes.
1117 **/
1118 int
1119 lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba)
1120 {
1121 struct lpfc_register portstat_reg = {0};
1122 int i;
1123
1124 msleep(100);
1125 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1126 &portstat_reg.word0);
1127
1128 /* verify if privileged for the request operation */
1129 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) &&
1130 !bf_get(lpfc_sliport_status_err, &portstat_reg))
1131 return -EPERM;
1132
1133 /* wait for the SLI port firmware ready after firmware reset */
1134 for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) {
1135 msleep(10);
1136 lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
1137 &portstat_reg.word0);
1138 if (!bf_get(lpfc_sliport_status_err, &portstat_reg))
1139 continue;
1140 if (!bf_get(lpfc_sliport_status_rn, &portstat_reg))
1141 continue;
1142 if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg))
1143 continue;
1144 break;
1145 }
1146
1147 if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT)
1148 return 0;
1149 else
1150 return -EIO;
1151 }
1152
1153 /**
1154 * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc
1155 * @phba: lpfc_hba pointer.
1156 *
1157 * Description:
1158 * Request SLI4 interface type-2 device to perform a physical register set
1159 * access.
1160 *
1161 * Returns:
1162 * zero for success
1163 **/
1164 static ssize_t
1165 lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode)
1166 {
1167 struct completion online_compl;
1168 struct pci_dev *pdev = phba->pcidev;
1169 uint32_t before_fc_flag;
1170 uint32_t sriov_nr_virtfn;
1171 uint32_t reg_val;
1172 int status = 0, rc = 0;
1173 int job_posted = 1, sriov_err;
1174
1175 if (!phba->cfg_enable_hba_reset)
1176 return -EACCES;
1177
1178 if ((phba->sli_rev < LPFC_SLI_REV4) ||
1179 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
1180 LPFC_SLI_INTF_IF_TYPE_2))
1181 return -EPERM;
1182
1183 /* Keep state if we need to restore back */
1184 before_fc_flag = phba->pport->fc_flag;
1185 sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn;
1186
1187 /* Disable SR-IOV virtual functions if enabled */
1188 if (phba->cfg_sriov_nr_virtfn) {
1189 pci_disable_sriov(pdev);
1190 phba->cfg_sriov_nr_virtfn = 0;
1191 }
1192
1193 if (opcode == LPFC_FW_DUMP)
1194 phba->hba_flag |= HBA_FW_DUMP_OP;
1195
1196 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1197
1198 if (status != 0) {
1199 phba->hba_flag &= ~HBA_FW_DUMP_OP;
1200 return status;
1201 }
1202
1203 /* wait for the device to be quiesced before firmware reset */
1204 msleep(100);
1205
1206 reg_val = readl(phba->sli4_hba.conf_regs_memmap_p +
1207 LPFC_CTL_PDEV_CTL_OFFSET);
1208
1209 if (opcode == LPFC_FW_DUMP)
1210 reg_val |= LPFC_FW_DUMP_REQUEST;
1211 else if (opcode == LPFC_FW_RESET)
1212 reg_val |= LPFC_CTL_PDEV_CTL_FRST;
1213 else if (opcode == LPFC_DV_RESET)
1214 reg_val |= LPFC_CTL_PDEV_CTL_DRST;
1215
1216 writel(reg_val, phba->sli4_hba.conf_regs_memmap_p +
1217 LPFC_CTL_PDEV_CTL_OFFSET);
1218 /* flush */
1219 readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
1220
1221 /* delay driver action following IF_TYPE_2 reset */
1222 rc = lpfc_sli4_pdev_status_reg_wait(phba);
1223
1224 if (rc == -EPERM) {
1225 /* no privilege for reset */
1226 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1227 "3150 No privilege to perform the requested "
1228 "access: x%x\n", reg_val);
1229 } else if (rc == -EIO) {
1230 /* reset failed, there is nothing more we can do */
1231 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1232 "3153 Fail to perform the requested "
1233 "access: x%x\n", reg_val);
1234 return rc;
1235 }
1236
1237 /* keep the original port state */
1238 if (before_fc_flag & FC_OFFLINE_MODE)
1239 goto out;
1240
1241 init_completion(&online_compl);
1242 job_posted = lpfc_workq_post_event(phba, &status, &online_compl,
1243 LPFC_EVT_ONLINE);
1244 if (!job_posted)
1245 goto out;
1246
1247 wait_for_completion(&online_compl);
1248
1249 out:
1250 /* in any case, restore the virtual functions enabled as before */
1251 if (sriov_nr_virtfn) {
1252 sriov_err =
1253 lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn);
1254 if (!sriov_err)
1255 phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn;
1256 }
1257
1258 /* return proper error code */
1259 if (!rc) {
1260 if (!job_posted)
1261 rc = -ENOMEM;
1262 else if (status)
1263 rc = -EIO;
1264 }
1265 return rc;
1266 }
1267
1268 /**
1269 * lpfc_nport_evt_cnt_show - Return the number of nport events
1270 * @dev: class device that is converted into a Scsi_host.
1271 * @attr: device attribute, not used.
1272 * @buf: on return contains the ascii number of nport events.
1273 *
1274 * Returns: size of formatted string.
1275 **/
1276 static ssize_t
1277 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
1278 char *buf)
1279 {
1280 struct Scsi_Host *shost = class_to_shost(dev);
1281 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1282 struct lpfc_hba *phba = vport->phba;
1283
1284 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
1285 }
1286
1287 /**
1288 * lpfc_board_mode_show - Return the state of the board
1289 * @dev: class device that is converted into a Scsi_host.
1290 * @attr: device attribute, not used.
1291 * @buf: on return contains the state of the adapter.
1292 *
1293 * Returns: size of formatted string.
1294 **/
1295 static ssize_t
1296 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
1297 char *buf)
1298 {
1299 struct Scsi_Host *shost = class_to_shost(dev);
1300 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1301 struct lpfc_hba *phba = vport->phba;
1302 char * state;
1303
1304 if (phba->link_state == LPFC_HBA_ERROR)
1305 state = "error";
1306 else if (phba->link_state == LPFC_WARM_START)
1307 state = "warm start";
1308 else if (phba->link_state == LPFC_INIT_START)
1309 state = "offline";
1310 else
1311 state = "online";
1312
1313 return snprintf(buf, PAGE_SIZE, "%s\n", state);
1314 }
1315
1316 /**
1317 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
1318 * @dev: class device that is converted into a Scsi_host.
1319 * @attr: device attribute, not used.
1320 * @buf: containing one of the strings "online", "offline", "warm" or "error".
1321 * @count: unused variable.
1322 *
1323 * Returns:
1324 * -EACCES if enable hba reset not enabled
1325 * -EINVAL if the buffer does not contain a valid string (see above)
1326 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
1327 * buf length greater than zero indicates success
1328 **/
1329 static ssize_t
1330 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
1331 const char *buf, size_t count)
1332 {
1333 struct Scsi_Host *shost = class_to_shost(dev);
1334 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1335 struct lpfc_hba *phba = vport->phba;
1336 struct completion online_compl;
1337 char *board_mode_str = NULL;
1338 int status = 0;
1339 int rc;
1340
1341 if (!phba->cfg_enable_hba_reset) {
1342 status = -EACCES;
1343 goto board_mode_out;
1344 }
1345
1346 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1347 "3050 lpfc_board_mode set to %s\n", buf);
1348
1349 init_completion(&online_compl);
1350
1351 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
1352 rc = lpfc_workq_post_event(phba, &status, &online_compl,
1353 LPFC_EVT_ONLINE);
1354 if (rc == 0) {
1355 status = -ENOMEM;
1356 goto board_mode_out;
1357 }
1358 wait_for_completion(&online_compl);
1359 if (status)
1360 status = -EIO;
1361 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
1362 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1363 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
1364 if (phba->sli_rev == LPFC_SLI_REV4)
1365 status = -EINVAL;
1366 else
1367 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
1368 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
1369 if (phba->sli_rev == LPFC_SLI_REV4)
1370 status = -EINVAL;
1371 else
1372 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
1373 else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0)
1374 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP);
1375 else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0)
1376 status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET);
1377 else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0)
1378 status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET);
1379 else
1380 status = -EINVAL;
1381
1382 board_mode_out:
1383 if (!status)
1384 return strlen(buf);
1385 else {
1386 board_mode_str = strchr(buf, '\n');
1387 if (board_mode_str)
1388 *board_mode_str = '\0';
1389 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1390 "3097 Failed \"%s\", status(%d), "
1391 "fc_flag(x%x)\n",
1392 buf, status, phba->pport->fc_flag);
1393 return status;
1394 }
1395 }
1396
1397 /**
1398 * lpfc_get_hba_info - Return various bits of informaton about the adapter
1399 * @phba: pointer to the adapter structure.
1400 * @mxri: max xri count.
1401 * @axri: available xri count.
1402 * @mrpi: max rpi count.
1403 * @arpi: available rpi count.
1404 * @mvpi: max vpi count.
1405 * @avpi: available vpi count.
1406 *
1407 * Description:
1408 * If an integer pointer for an count is not null then the value for the
1409 * count is returned.
1410 *
1411 * Returns:
1412 * zero on error
1413 * one for success
1414 **/
1415 static int
1416 lpfc_get_hba_info(struct lpfc_hba *phba,
1417 uint32_t *mxri, uint32_t *axri,
1418 uint32_t *mrpi, uint32_t *arpi,
1419 uint32_t *mvpi, uint32_t *avpi)
1420 {
1421 struct lpfc_mbx_read_config *rd_config;
1422 LPFC_MBOXQ_t *pmboxq;
1423 MAILBOX_t *pmb;
1424 int rc = 0;
1425 uint32_t max_vpi;
1426
1427 /*
1428 * prevent udev from issuing mailbox commands until the port is
1429 * configured.
1430 */
1431 if (phba->link_state < LPFC_LINK_DOWN ||
1432 !phba->mbox_mem_pool ||
1433 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
1434 return 0;
1435
1436 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1437 return 0;
1438
1439 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1440 if (!pmboxq)
1441 return 0;
1442 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1443
1444 pmb = &pmboxq->u.mb;
1445 pmb->mbxCommand = MBX_READ_CONFIG;
1446 pmb->mbxOwner = OWN_HOST;
1447 pmboxq->context1 = NULL;
1448
1449 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
1450 rc = MBX_NOT_FINISHED;
1451 else
1452 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1453
1454 if (rc != MBX_SUCCESS) {
1455 if (rc != MBX_TIMEOUT)
1456 mempool_free(pmboxq, phba->mbox_mem_pool);
1457 return 0;
1458 }
1459
1460 if (phba->sli_rev == LPFC_SLI_REV4) {
1461 rd_config = &pmboxq->u.mqe.un.rd_config;
1462 if (mrpi)
1463 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
1464 if (arpi)
1465 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
1466 phba->sli4_hba.max_cfg_param.rpi_used;
1467 if (mxri)
1468 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
1469 if (axri)
1470 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
1471 phba->sli4_hba.max_cfg_param.xri_used;
1472
1473 /* Account for differences with SLI-3. Get vpi count from
1474 * mailbox data and subtract one for max vpi value.
1475 */
1476 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
1477 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
1478
1479 if (mvpi)
1480 *mvpi = max_vpi;
1481 if (avpi)
1482 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
1483 } else {
1484 if (mrpi)
1485 *mrpi = pmb->un.varRdConfig.max_rpi;
1486 if (arpi)
1487 *arpi = pmb->un.varRdConfig.avail_rpi;
1488 if (mxri)
1489 *mxri = pmb->un.varRdConfig.max_xri;
1490 if (axri)
1491 *axri = pmb->un.varRdConfig.avail_xri;
1492 if (mvpi)
1493 *mvpi = pmb->un.varRdConfig.max_vpi;
1494 if (avpi)
1495 *avpi = pmb->un.varRdConfig.avail_vpi;
1496 }
1497
1498 mempool_free(pmboxq, phba->mbox_mem_pool);
1499 return 1;
1500 }
1501
1502 /**
1503 * lpfc_max_rpi_show - Return maximum rpi
1504 * @dev: class device that is converted into a Scsi_host.
1505 * @attr: device attribute, not used.
1506 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
1507 *
1508 * Description:
1509 * Calls lpfc_get_hba_info() asking for just the mrpi count.
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 **/
1516 static ssize_t
1517 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
1518 char *buf)
1519 {
1520 struct Scsi_Host *shost = class_to_shost(dev);
1521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1522 struct lpfc_hba *phba = vport->phba;
1523 uint32_t cnt;
1524
1525 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
1526 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1527 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1528 }
1529
1530 /**
1531 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
1532 * @dev: class device that is converted into a Scsi_host.
1533 * @attr: device attribute, not used.
1534 * @buf: containing the used rpi count in decimal or "Unknown".
1535 *
1536 * Description:
1537 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
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 **/
1544 static ssize_t
1545 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1546 char *buf)
1547 {
1548 struct Scsi_Host *shost = class_to_shost(dev);
1549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1550 struct lpfc_hba *phba = vport->phba;
1551 uint32_t cnt, acnt;
1552
1553 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1554 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1555 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1556 }
1557
1558 /**
1559 * lpfc_max_xri_show - Return maximum xri
1560 * @dev: class device that is converted into a Scsi_host.
1561 * @attr: device attribute, not used.
1562 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1563 *
1564 * Description:
1565 * Calls lpfc_get_hba_info() asking for just the mrpi count.
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 **/
1572 static ssize_t
1573 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1574 char *buf)
1575 {
1576 struct Scsi_Host *shost = class_to_shost(dev);
1577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1578 struct lpfc_hba *phba = vport->phba;
1579 uint32_t cnt;
1580
1581 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1582 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1583 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1584 }
1585
1586 /**
1587 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1588 * @dev: class device that is converted into a Scsi_host.
1589 * @attr: device attribute, not used.
1590 * @buf: on return contains the used xri count in decimal or "Unknown".
1591 *
1592 * Description:
1593 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
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 **/
1600 static ssize_t
1601 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1602 char *buf)
1603 {
1604 struct Scsi_Host *shost = class_to_shost(dev);
1605 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1606 struct lpfc_hba *phba = vport->phba;
1607 uint32_t cnt, acnt;
1608
1609 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1610 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1611 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1612 }
1613
1614 /**
1615 * lpfc_max_vpi_show - Return maximum vpi
1616 * @dev: class device that is converted into a Scsi_host.
1617 * @attr: device attribute, not used.
1618 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1619 *
1620 * Description:
1621 * Calls lpfc_get_hba_info() asking for just the mvpi count.
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 **/
1628 static ssize_t
1629 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1630 char *buf)
1631 {
1632 struct Scsi_Host *shost = class_to_shost(dev);
1633 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1634 struct lpfc_hba *phba = vport->phba;
1635 uint32_t cnt;
1636
1637 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1638 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1639 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1640 }
1641
1642 /**
1643 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1644 * @dev: class device that is converted into a Scsi_host.
1645 * @attr: device attribute, not used.
1646 * @buf: on return contains the used vpi count in decimal or "Unknown".
1647 *
1648 * Description:
1649 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1650 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1651 * to "Unknown" and the buffer length is returned, therefore the caller
1652 * must check for "Unknown" in the buffer to detect a failure.
1653 *
1654 * Returns: size of formatted string.
1655 **/
1656 static ssize_t
1657 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1658 char *buf)
1659 {
1660 struct Scsi_Host *shost = class_to_shost(dev);
1661 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1662 struct lpfc_hba *phba = vport->phba;
1663 uint32_t cnt, acnt;
1664
1665 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1666 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1667 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1668 }
1669
1670 /**
1671 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1672 * @dev: class device that is converted into a Scsi_host.
1673 * @attr: device attribute, not used.
1674 * @buf: text that must be interpreted to determine if npiv is supported.
1675 *
1676 * Description:
1677 * Buffer will contain text indicating npiv is not suppoerted on the port,
1678 * the port is an NPIV physical port, or it is an npiv virtual port with
1679 * the id of the vport.
1680 *
1681 * Returns: size of formatted string.
1682 **/
1683 static ssize_t
1684 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1685 char *buf)
1686 {
1687 struct Scsi_Host *shost = class_to_shost(dev);
1688 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1689 struct lpfc_hba *phba = vport->phba;
1690
1691 if (!(phba->max_vpi))
1692 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1693 if (vport->port_type == LPFC_PHYSICAL_PORT)
1694 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1695 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1696 }
1697
1698 /**
1699 * lpfc_poll_show - Return text about poll support for the adapter
1700 * @dev: class device that is converted into a Scsi_host.
1701 * @attr: device attribute, not used.
1702 * @buf: on return contains the cfg_poll in hex.
1703 *
1704 * Notes:
1705 * cfg_poll should be a lpfc_polling_flags type.
1706 *
1707 * Returns: size of formatted string.
1708 **/
1709 static ssize_t
1710 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1711 char *buf)
1712 {
1713 struct Scsi_Host *shost = class_to_shost(dev);
1714 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1715 struct lpfc_hba *phba = vport->phba;
1716
1717 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1718 }
1719
1720 /**
1721 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1722 * @dev: class device that is converted into a Scsi_host.
1723 * @attr: device attribute, not used.
1724 * @buf: one or more lpfc_polling_flags values.
1725 * @count: not used.
1726 *
1727 * Notes:
1728 * buf contents converted to integer and checked for a valid value.
1729 *
1730 * Returns:
1731 * -EINVAL if the buffer connot be converted or is out of range
1732 * length of the buf on success
1733 **/
1734 static ssize_t
1735 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1736 const char *buf, size_t count)
1737 {
1738 struct Scsi_Host *shost = class_to_shost(dev);
1739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1740 struct lpfc_hba *phba = vport->phba;
1741 uint32_t creg_val;
1742 uint32_t old_val;
1743 int val=0;
1744
1745 if (!isdigit(buf[0]))
1746 return -EINVAL;
1747
1748 if (sscanf(buf, "%i", &val) != 1)
1749 return -EINVAL;
1750
1751 if ((val & 0x3) != val)
1752 return -EINVAL;
1753
1754 if (phba->sli_rev == LPFC_SLI_REV4)
1755 val = 0;
1756
1757 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1758 "3051 lpfc_poll changed from %d to %d\n",
1759 phba->cfg_poll, val);
1760
1761 spin_lock_irq(&phba->hbalock);
1762
1763 old_val = phba->cfg_poll;
1764
1765 if (val & ENABLE_FCP_RING_POLLING) {
1766 if ((val & DISABLE_FCP_RING_INT) &&
1767 !(old_val & DISABLE_FCP_RING_INT)) {
1768 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1769 spin_unlock_irq(&phba->hbalock);
1770 return -EINVAL;
1771 }
1772 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1773 writel(creg_val, phba->HCregaddr);
1774 readl(phba->HCregaddr); /* flush */
1775
1776 lpfc_poll_start_timer(phba);
1777 }
1778 } else if (val != 0x0) {
1779 spin_unlock_irq(&phba->hbalock);
1780 return -EINVAL;
1781 }
1782
1783 if (!(val & DISABLE_FCP_RING_INT) &&
1784 (old_val & DISABLE_FCP_RING_INT))
1785 {
1786 spin_unlock_irq(&phba->hbalock);
1787 del_timer(&phba->fcp_poll_timer);
1788 spin_lock_irq(&phba->hbalock);
1789 if (lpfc_readl(phba->HCregaddr, &creg_val)) {
1790 spin_unlock_irq(&phba->hbalock);
1791 return -EINVAL;
1792 }
1793 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1794 writel(creg_val, phba->HCregaddr);
1795 readl(phba->HCregaddr); /* flush */
1796 }
1797
1798 phba->cfg_poll = val;
1799
1800 spin_unlock_irq(&phba->hbalock);
1801
1802 return strlen(buf);
1803 }
1804
1805 /**
1806 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1807 * @dev: class unused variable.
1808 * @attr: device attribute, not used.
1809 * @buf: on return contains the module description text.
1810 *
1811 * Returns: size of formatted string.
1812 **/
1813 static ssize_t
1814 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1815 char *buf)
1816 {
1817 struct Scsi_Host *shost = class_to_shost(dev);
1818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1819 struct lpfc_hba *phba = vport->phba;
1820
1821 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1822 }
1823
1824 /**
1825 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1826 * @dev: class unused variable.
1827 * @attr: device attribute, not used.
1828 * @buf: on return contains the module description text.
1829 *
1830 * Returns: size of formatted string.
1831 **/
1832 static ssize_t
1833 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1834 char *buf)
1835 {
1836 struct Scsi_Host *shost = class_to_shost(dev);
1837 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1838 struct lpfc_hba *phba = vport->phba;
1839
1840 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1841 }
1842
1843 /**
1844 * lpfc_dss_show - Return the current state of dss and the configured state
1845 * @dev: class converted to a Scsi_host structure.
1846 * @attr: device attribute, not used.
1847 * @buf: on return contains the formatted text.
1848 *
1849 * Returns: size of formatted string.
1850 **/
1851 static ssize_t
1852 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1853 char *buf)
1854 {
1855 struct Scsi_Host *shost = class_to_shost(dev);
1856 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1857 struct lpfc_hba *phba = vport->phba;
1858
1859 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1860 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1861 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1862 "" : "Not ");
1863 }
1864
1865 /**
1866 * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions
1867 * @dev: class converted to a Scsi_host structure.
1868 * @attr: device attribute, not used.
1869 * @buf: on return contains the formatted support level.
1870 *
1871 * Description:
1872 * Returns the maximum number of virtual functions a physical function can
1873 * support, 0 will be returned if called on virtual function.
1874 *
1875 * Returns: size of formatted string.
1876 **/
1877 static ssize_t
1878 lpfc_sriov_hw_max_virtfn_show(struct device *dev,
1879 struct device_attribute *attr,
1880 char *buf)
1881 {
1882 struct Scsi_Host *shost = class_to_shost(dev);
1883 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1884 struct lpfc_hba *phba = vport->phba;
1885 uint16_t max_nr_virtfn;
1886
1887 max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba);
1888 return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn);
1889 }
1890
1891 static inline bool lpfc_rangecheck(uint val, uint min, uint max)
1892 {
1893 return val >= min && val <= max;
1894 }
1895
1896 /**
1897 * lpfc_param_show - Return a cfg attribute value in decimal
1898 *
1899 * Description:
1900 * Macro that given an attr e.g. hba_queue_depth expands
1901 * into a function with the name lpfc_hba_queue_depth_show.
1902 *
1903 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1904 * @dev: class device that is converted into a Scsi_host.
1905 * @attr: device attribute, not used.
1906 * @buf: on return contains the attribute value in decimal.
1907 *
1908 * Returns: size of formatted string.
1909 **/
1910 #define lpfc_param_show(attr) \
1911 static ssize_t \
1912 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1913 char *buf) \
1914 { \
1915 struct Scsi_Host *shost = class_to_shost(dev);\
1916 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1917 struct lpfc_hba *phba = vport->phba;\
1918 return snprintf(buf, PAGE_SIZE, "%d\n",\
1919 phba->cfg_##attr);\
1920 }
1921
1922 /**
1923 * lpfc_param_hex_show - Return a cfg attribute value in hex
1924 *
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_show
1928 *
1929 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1930 * @dev: class device that is converted into a Scsi_host.
1931 * @attr: device attribute, not used.
1932 * @buf: on return contains the attribute value in hexadecimal.
1933 *
1934 * Returns: size of formatted string.
1935 **/
1936 #define lpfc_param_hex_show(attr) \
1937 static ssize_t \
1938 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1939 char *buf) \
1940 { \
1941 struct Scsi_Host *shost = class_to_shost(dev);\
1942 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1943 struct lpfc_hba *phba = vport->phba;\
1944 uint val = 0;\
1945 val = phba->cfg_##attr;\
1946 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1947 phba->cfg_##attr);\
1948 }
1949
1950 /**
1951 * lpfc_param_init - Initializes a cfg attribute
1952 *
1953 * Description:
1954 * Macro that given an attr e.g. hba_queue_depth expands
1955 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1956 * takes a default argument, a minimum and maximum argument.
1957 *
1958 * lpfc_##attr##_init: Initializes an attribute.
1959 * @phba: pointer the the adapter structure.
1960 * @val: integer attribute value.
1961 *
1962 * Validates the min and max values then sets the adapter config field
1963 * accordingly, or uses the default if out of range and prints an error message.
1964 *
1965 * Returns:
1966 * zero on success
1967 * -EINVAL if default used
1968 **/
1969 #define lpfc_param_init(attr, default, minval, maxval) \
1970 static int \
1971 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1972 { \
1973 if (lpfc_rangecheck(val, minval, maxval)) {\
1974 phba->cfg_##attr = val;\
1975 return 0;\
1976 }\
1977 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1978 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1979 "allowed range is ["#minval", "#maxval"]\n", val); \
1980 phba->cfg_##attr = default;\
1981 return -EINVAL;\
1982 }
1983
1984 /**
1985 * lpfc_param_set - Set a cfg attribute value
1986 *
1987 * Description:
1988 * Macro that given an attr e.g. hba_queue_depth expands
1989 * into a function with the name lpfc_hba_queue_depth_set
1990 *
1991 * lpfc_##attr##_set: Sets an attribute value.
1992 * @phba: pointer the the adapter structure.
1993 * @val: integer attribute value.
1994 *
1995 * Description:
1996 * Validates the min and max values then sets the
1997 * adapter config field if in the valid range. prints error message
1998 * and does not set the parameter if invalid.
1999 *
2000 * Returns:
2001 * zero on success
2002 * -EINVAL if val is invalid
2003 **/
2004 #define lpfc_param_set(attr, default, minval, maxval) \
2005 static int \
2006 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
2007 { \
2008 if (lpfc_rangecheck(val, minval, maxval)) {\
2009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2010 "3052 lpfc_" #attr " changed from %d to %d\n", \
2011 phba->cfg_##attr, val); \
2012 phba->cfg_##attr = val;\
2013 return 0;\
2014 }\
2015 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
2016 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
2017 "allowed range is ["#minval", "#maxval"]\n", val); \
2018 return -EINVAL;\
2019 }
2020
2021 /**
2022 * lpfc_param_store - Set a vport attribute value
2023 *
2024 * Description:
2025 * Macro that given an attr e.g. hba_queue_depth expands
2026 * into a function with the name lpfc_hba_queue_depth_store.
2027 *
2028 * lpfc_##attr##_store: Set an sttribute value.
2029 * @dev: class device that is converted into a Scsi_host.
2030 * @attr: device attribute, not used.
2031 * @buf: contains the attribute value in ascii.
2032 * @count: not used.
2033 *
2034 * Description:
2035 * Convert the ascii text number to an integer, then
2036 * use the lpfc_##attr##_set function to set the value.
2037 *
2038 * Returns:
2039 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2040 * length of buffer upon success.
2041 **/
2042 #define lpfc_param_store(attr) \
2043 static ssize_t \
2044 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2045 const char *buf, size_t count) \
2046 { \
2047 struct Scsi_Host *shost = class_to_shost(dev);\
2048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2049 struct lpfc_hba *phba = vport->phba;\
2050 uint val = 0;\
2051 if (!isdigit(buf[0]))\
2052 return -EINVAL;\
2053 if (sscanf(buf, "%i", &val) != 1)\
2054 return -EINVAL;\
2055 if (lpfc_##attr##_set(phba, val) == 0) \
2056 return strlen(buf);\
2057 else \
2058 return -EINVAL;\
2059 }
2060
2061 /**
2062 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
2063 *
2064 * Description:
2065 * Macro that given an attr e.g. hba_queue_depth expands
2066 * into a function with the name lpfc_hba_queue_depth_show
2067 *
2068 * lpfc_##attr##_show: prints the attribute value in decimal.
2069 * @dev: class device that is converted into a Scsi_host.
2070 * @attr: device attribute, not used.
2071 * @buf: on return contains the attribute value in decimal.
2072 *
2073 * Returns: length of formatted string.
2074 **/
2075 #define lpfc_vport_param_show(attr) \
2076 static ssize_t \
2077 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2078 char *buf) \
2079 { \
2080 struct Scsi_Host *shost = class_to_shost(dev);\
2081 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2082 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
2083 }
2084
2085 /**
2086 * lpfc_vport_param_hex_show - Return hex formatted attribute value
2087 *
2088 * Description:
2089 * Macro that given an attr e.g.
2090 * hba_queue_depth expands into a function with the name
2091 * lpfc_hba_queue_depth_show
2092 *
2093 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
2094 * @dev: class device that is converted into a Scsi_host.
2095 * @attr: device attribute, not used.
2096 * @buf: on return contains the attribute value in hexadecimal.
2097 *
2098 * Returns: length of formatted string.
2099 **/
2100 #define lpfc_vport_param_hex_show(attr) \
2101 static ssize_t \
2102 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
2103 char *buf) \
2104 { \
2105 struct Scsi_Host *shost = class_to_shost(dev);\
2106 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2107 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
2108 }
2109
2110 /**
2111 * lpfc_vport_param_init - Initialize a vport cfg attribute
2112 *
2113 * Description:
2114 * Macro that given an attr e.g. hba_queue_depth expands
2115 * into a function with the name lpfc_hba_queue_depth_init. The macro also
2116 * takes a default argument, a minimum and maximum argument.
2117 *
2118 * lpfc_##attr##_init: validates the min and max values then sets the
2119 * adapter config field accordingly, or uses the default if out of range
2120 * and prints an error message.
2121 * @phba: pointer the the adapter structure.
2122 * @val: integer attribute value.
2123 *
2124 * Returns:
2125 * zero on success
2126 * -EINVAL if default used
2127 **/
2128 #define lpfc_vport_param_init(attr, default, minval, maxval) \
2129 static int \
2130 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
2131 { \
2132 if (lpfc_rangecheck(val, minval, maxval)) {\
2133 vport->cfg_##attr = val;\
2134 return 0;\
2135 }\
2136 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2137 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
2138 "allowed range is ["#minval", "#maxval"]\n", val); \
2139 vport->cfg_##attr = default;\
2140 return -EINVAL;\
2141 }
2142
2143 /**
2144 * lpfc_vport_param_set - Set a vport cfg attribute
2145 *
2146 * Description:
2147 * Macro that given an attr e.g. hba_queue_depth expands
2148 * into a function with the name lpfc_hba_queue_depth_set
2149 *
2150 * lpfc_##attr##_set: validates the min and max values then sets the
2151 * adapter config field if in the valid range. prints error message
2152 * and does not set the parameter if invalid.
2153 * @phba: pointer the the adapter structure.
2154 * @val: integer attribute value.
2155 *
2156 * Returns:
2157 * zero on success
2158 * -EINVAL if val is invalid
2159 **/
2160 #define lpfc_vport_param_set(attr, default, minval, maxval) \
2161 static int \
2162 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
2163 { \
2164 if (lpfc_rangecheck(val, minval, maxval)) {\
2165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2166 "3053 lpfc_" #attr \
2167 " changed from %d (x%x) to %d (x%x)\n", \
2168 vport->cfg_##attr, vport->cfg_##attr, \
2169 val, val); \
2170 vport->cfg_##attr = val;\
2171 return 0;\
2172 }\
2173 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
2174 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
2175 "allowed range is ["#minval", "#maxval"]\n", val); \
2176 return -EINVAL;\
2177 }
2178
2179 /**
2180 * lpfc_vport_param_store - Set a vport attribute
2181 *
2182 * Description:
2183 * Macro that given an attr e.g. hba_queue_depth
2184 * expands into a function with the name lpfc_hba_queue_depth_store
2185 *
2186 * lpfc_##attr##_store: convert the ascii text number to an integer, then
2187 * use the lpfc_##attr##_set function to set the value.
2188 * @cdev: class device that is converted into a Scsi_host.
2189 * @buf: contains the attribute value in decimal.
2190 * @count: not used.
2191 *
2192 * Returns:
2193 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
2194 * length of buffer upon success.
2195 **/
2196 #define lpfc_vport_param_store(attr) \
2197 static ssize_t \
2198 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
2199 const char *buf, size_t count) \
2200 { \
2201 struct Scsi_Host *shost = class_to_shost(dev);\
2202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
2203 uint val = 0;\
2204 if (!isdigit(buf[0]))\
2205 return -EINVAL;\
2206 if (sscanf(buf, "%i", &val) != 1)\
2207 return -EINVAL;\
2208 if (lpfc_##attr##_set(vport, val) == 0) \
2209 return strlen(buf);\
2210 else \
2211 return -EINVAL;\
2212 }
2213
2214
2215 static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL);
2216 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
2217 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
2218 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
2219 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
2220 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
2221 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
2222 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
2223 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
2224 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2225 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
2226 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
2227 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
2228 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
2229 lpfc_link_state_store);
2230 static DEVICE_ATTR(option_rom_version, S_IRUGO,
2231 lpfc_option_rom_version_show, NULL);
2232 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
2233 lpfc_num_discovered_ports_show, NULL);
2234 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
2235 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
2236 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
2237 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
2238 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
2239 lpfc_board_mode_show, lpfc_board_mode_store);
2240 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
2241 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
2242 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
2243 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
2244 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
2245 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
2246 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
2247 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
2248 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
2249 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
2250 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
2251 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
2252 static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO,
2253 lpfc_sriov_hw_max_virtfn_show, NULL);
2254 static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL);
2255 static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show,
2256 NULL);
2257
2258 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
2259 #define WWN_SZ 8
2260 /**
2261 * lpfc_wwn_set - Convert string to the 8 byte WWN value.
2262 * @buf: WWN string.
2263 * @cnt: Length of string.
2264 * @wwn: Array to receive converted wwn value.
2265 *
2266 * Returns:
2267 * -EINVAL if the buffer does not contain a valid wwn
2268 * 0 success
2269 **/
2270 static size_t
2271 lpfc_wwn_set(const char *buf, size_t cnt, char wwn[])
2272 {
2273 unsigned int i, j;
2274
2275 /* Count may include a LF at end of string */
2276 if (buf[cnt-1] == '\n')
2277 cnt--;
2278
2279 if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) ||
2280 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
2281 return -EINVAL;
2282
2283 memset(wwn, 0, WWN_SZ);
2284
2285 /* Validate and store the new name */
2286 for (i = 0, j = 0; i < 16; i++) {
2287 if ((*buf >= 'a') && (*buf <= 'f'))
2288 j = ((j << 4) | ((*buf++ - 'a') + 10));
2289 else if ((*buf >= 'A') && (*buf <= 'F'))
2290 j = ((j << 4) | ((*buf++ - 'A') + 10));
2291 else if ((*buf >= '0') && (*buf <= '9'))
2292 j = ((j << 4) | (*buf++ - '0'));
2293 else
2294 return -EINVAL;
2295 if (i % 2) {
2296 wwn[i/2] = j & 0xff;
2297 j = 0;
2298 }
2299 }
2300 return 0;
2301 }
2302 /**
2303 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
2304 * @dev: class device that is converted into a Scsi_host.
2305 * @attr: device attribute, not used.
2306 * @buf: containing the string lpfc_soft_wwn_key.
2307 * @count: must be size of lpfc_soft_wwn_key.
2308 *
2309 * Returns:
2310 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
2311 * length of buf indicates success
2312 **/
2313 static ssize_t
2314 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
2315 const char *buf, size_t count)
2316 {
2317 struct Scsi_Host *shost = class_to_shost(dev);
2318 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2319 struct lpfc_hba *phba = vport->phba;
2320 unsigned int cnt = count;
2321 uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level;
2322 u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0];
2323
2324 /*
2325 * We're doing a simple sanity check for soft_wwpn setting.
2326 * We require that the user write a specific key to enable
2327 * the soft_wwpn attribute to be settable. Once the attribute
2328 * is written, the enable key resets. If further updates are
2329 * desired, the key must be written again to re-enable the
2330 * attribute.
2331 *
2332 * The "key" is not secret - it is a hardcoded string shown
2333 * here. The intent is to protect against the random user or
2334 * application that is just writing attributes.
2335 */
2336 if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) {
2337 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2338 "0051 "LPFC_DRIVER_NAME" soft wwpn can not"
2339 " be enabled: fawwpn is enabled\n");
2340 return -EINVAL;
2341 }
2342
2343 /* count may include a LF at end of string */
2344 if (buf[cnt-1] == '\n')
2345 cnt--;
2346
2347 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
2348 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
2349 return -EINVAL;
2350
2351 phba->soft_wwn_enable = 1;
2352
2353 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2354 "lpfc%d: soft_wwpn assignment has been enabled.\n",
2355 phba->brd_no);
2356 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2357 " The soft_wwpn feature is not supported by Broadcom.");
2358
2359 return count;
2360 }
2361 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
2362 lpfc_soft_wwn_enable_store);
2363
2364 /**
2365 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
2366 * @dev: class device that is converted into a Scsi_host.
2367 * @attr: device attribute, not used.
2368 * @buf: on return contains the wwpn in hexadecimal.
2369 *
2370 * Returns: size of formatted string.
2371 **/
2372 static ssize_t
2373 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
2374 char *buf)
2375 {
2376 struct Scsi_Host *shost = class_to_shost(dev);
2377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2378 struct lpfc_hba *phba = vport->phba;
2379
2380 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2381 (unsigned long long)phba->cfg_soft_wwpn);
2382 }
2383
2384 /**
2385 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
2386 * @dev class device that is converted into a Scsi_host.
2387 * @attr: device attribute, not used.
2388 * @buf: contains the wwpn in hexadecimal.
2389 * @count: number of wwpn bytes in buf
2390 *
2391 * Returns:
2392 * -EACCES hba reset not enabled, adapter over temp
2393 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
2394 * -EIO error taking adapter offline or online
2395 * value of count on success
2396 **/
2397 static ssize_t
2398 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
2399 const char *buf, size_t count)
2400 {
2401 struct Scsi_Host *shost = class_to_shost(dev);
2402 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2403 struct lpfc_hba *phba = vport->phba;
2404 struct completion online_compl;
2405 int stat1 = 0, stat2 = 0;
2406 unsigned int cnt = count;
2407 u8 wwpn[WWN_SZ];
2408 int rc;
2409
2410 if (!phba->cfg_enable_hba_reset)
2411 return -EACCES;
2412 spin_lock_irq(&phba->hbalock);
2413 if (phba->over_temp_state == HBA_OVER_TEMP) {
2414 spin_unlock_irq(&phba->hbalock);
2415 return -EACCES;
2416 }
2417 spin_unlock_irq(&phba->hbalock);
2418 /* count may include a LF at end of string */
2419 if (buf[cnt-1] == '\n')
2420 cnt--;
2421
2422 if (!phba->soft_wwn_enable)
2423 return -EINVAL;
2424
2425 /* lock setting wwpn, wwnn down */
2426 phba->soft_wwn_enable = 0;
2427
2428 rc = lpfc_wwn_set(buf, cnt, wwpn);
2429 if (rc) {
2430 /* not able to set wwpn, unlock it */
2431 phba->soft_wwn_enable = 1;
2432 return rc;
2433 }
2434
2435 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2436 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
2437 if (phba->cfg_soft_wwnn)
2438 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
2439
2440 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2441 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
2442
2443 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
2444 if (stat1)
2445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2446 "0463 lpfc_soft_wwpn attribute set failed to "
2447 "reinit adapter - %d\n", stat1);
2448 init_completion(&online_compl);
2449 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
2450 LPFC_EVT_ONLINE);
2451 if (rc == 0)
2452 return -ENOMEM;
2453
2454 wait_for_completion(&online_compl);
2455 if (stat2)
2456 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2457 "0464 lpfc_soft_wwpn attribute set failed to "
2458 "reinit adapter - %d\n", stat2);
2459 return (stat1 || stat2) ? -EIO : count;
2460 }
2461 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,
2462 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
2463
2464 /**
2465 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
2466 * @dev: class device that is converted into a Scsi_host.
2467 * @attr: device attribute, not used.
2468 * @buf: on return contains the wwnn in hexadecimal.
2469 *
2470 * Returns: size of formatted string.
2471 **/
2472 static ssize_t
2473 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
2474 char *buf)
2475 {
2476 struct Scsi_Host *shost = class_to_shost(dev);
2477 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2478 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2479 (unsigned long long)phba->cfg_soft_wwnn);
2480 }
2481
2482 /**
2483 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
2484 * @cdev: class device that is converted into a Scsi_host.
2485 * @buf: contains the ww node name in hexadecimal.
2486 * @count: number of wwnn bytes in buf.
2487 *
2488 * Returns:
2489 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
2490 * value of count on success
2491 **/
2492 static ssize_t
2493 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
2494 const char *buf, size_t count)
2495 {
2496 struct Scsi_Host *shost = class_to_shost(dev);
2497 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2498 unsigned int cnt = count;
2499 u8 wwnn[WWN_SZ];
2500 int rc;
2501
2502 /* count may include a LF at end of string */
2503 if (buf[cnt-1] == '\n')
2504 cnt--;
2505
2506 if (!phba->soft_wwn_enable)
2507 return -EINVAL;
2508
2509 rc = lpfc_wwn_set(buf, cnt, wwnn);
2510 if (rc) {
2511 /* Allow wwnn to be set many times, as long as the enable
2512 * is set. However, once the wwpn is set, everything locks.
2513 */
2514 return rc;
2515 }
2516
2517 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
2518
2519 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
2520 "lpfc%d: soft_wwnn set. Value will take effect upon "
2521 "setting of the soft_wwpn\n", phba->brd_no);
2522
2523 return count;
2524 }
2525 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,
2526 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
2527
2528 /**
2529 * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for
2530 * Optimized Access Storage (OAS) operations.
2531 * @dev: class device that is converted into a Scsi_host.
2532 * @attr: device attribute, not used.
2533 * @buf: buffer for passing information.
2534 *
2535 * Returns:
2536 * value of count
2537 **/
2538 static ssize_t
2539 lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr,
2540 char *buf)
2541 {
2542 struct Scsi_Host *shost = class_to_shost(dev);
2543 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2544
2545 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2546 wwn_to_u64(phba->cfg_oas_tgt_wwpn));
2547 }
2548
2549 /**
2550 * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for
2551 * Optimized Access Storage (OAS) operations.
2552 * @dev: class device that is converted into a Scsi_host.
2553 * @attr: device attribute, not used.
2554 * @buf: buffer for passing information.
2555 * @count: Size of the data buffer.
2556 *
2557 * Returns:
2558 * -EINVAL count is invalid, invalid wwpn byte invalid
2559 * -EPERM oas is not supported by hba
2560 * value of count on success
2561 **/
2562 static ssize_t
2563 lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr,
2564 const char *buf, size_t count)
2565 {
2566 struct Scsi_Host *shost = class_to_shost(dev);
2567 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2568 unsigned int cnt = count;
2569 uint8_t wwpn[WWN_SZ];
2570 int rc;
2571
2572 if (!phba->cfg_fof)
2573 return -EPERM;
2574
2575 /* count may include a LF at end of string */
2576 if (buf[cnt-1] == '\n')
2577 cnt--;
2578
2579 rc = lpfc_wwn_set(buf, cnt, wwpn);
2580 if (rc)
2581 return rc;
2582
2583 memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2584 memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2585 if (wwn_to_u64(wwpn) == 0)
2586 phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET;
2587 else
2588 phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET;
2589 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2590 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2591 return count;
2592 }
2593 static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR,
2594 lpfc_oas_tgt_show, lpfc_oas_tgt_store);
2595
2596 /**
2597 * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for
2598 * Optimized Access Storage (OAS) operations.
2599 * @dev: class device that is converted into a Scsi_host.
2600 * @attr: device attribute, not used.
2601 * @buf: buffer for passing information.
2602 *
2603 * Returns:
2604 * value of count
2605 **/
2606 static ssize_t
2607 lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr,
2608 char *buf)
2609 {
2610 struct Scsi_Host *shost = class_to_shost(dev);
2611 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2612
2613 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority);
2614 }
2615
2616 /**
2617 * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for
2618 * Optimized Access Storage (OAS) operations.
2619 * @dev: class device that is converted into a Scsi_host.
2620 * @attr: device attribute, not used.
2621 * @buf: buffer for passing information.
2622 * @count: Size of the data buffer.
2623 *
2624 * Returns:
2625 * -EINVAL count is invalid, invalid wwpn byte invalid
2626 * -EPERM oas is not supported by hba
2627 * value of count on success
2628 **/
2629 static ssize_t
2630 lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr,
2631 const char *buf, size_t count)
2632 {
2633 struct Scsi_Host *shost = class_to_shost(dev);
2634 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2635 unsigned int cnt = count;
2636 unsigned long val;
2637 int ret;
2638
2639 if (!phba->cfg_fof)
2640 return -EPERM;
2641
2642 /* count may include a LF at end of string */
2643 if (buf[cnt-1] == '\n')
2644 cnt--;
2645
2646 ret = kstrtoul(buf, 0, &val);
2647 if (ret || (val > 0x7f))
2648 return -EINVAL;
2649
2650 if (val)
2651 phba->cfg_oas_priority = (uint8_t)val;
2652 else
2653 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2654 return count;
2655 }
2656 static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR,
2657 lpfc_oas_priority_show, lpfc_oas_priority_store);
2658
2659 /**
2660 * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled
2661 * for Optimized Access Storage (OAS) operations.
2662 * @dev: class device that is converted into a Scsi_host.
2663 * @attr: device attribute, not used.
2664 * @buf: buffer for passing information.
2665 *
2666 * Returns:
2667 * value of count on success
2668 **/
2669 static ssize_t
2670 lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr,
2671 char *buf)
2672 {
2673 struct Scsi_Host *shost = class_to_shost(dev);
2674 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2675
2676 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
2677 wwn_to_u64(phba->cfg_oas_vpt_wwpn));
2678 }
2679
2680 /**
2681 * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled
2682 * for Optimized Access Storage (OAS) operations.
2683 * @dev: class device that is converted into a Scsi_host.
2684 * @attr: device attribute, not used.
2685 * @buf: buffer for passing information.
2686 * @count: Size of the data buffer.
2687 *
2688 * Returns:
2689 * -EINVAL count is invalid, invalid wwpn byte invalid
2690 * -EPERM oas is not supported by hba
2691 * value of count on success
2692 **/
2693 static ssize_t
2694 lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr,
2695 const char *buf, size_t count)
2696 {
2697 struct Scsi_Host *shost = class_to_shost(dev);
2698 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2699 unsigned int cnt = count;
2700 uint8_t wwpn[WWN_SZ];
2701 int rc;
2702
2703 if (!phba->cfg_fof)
2704 return -EPERM;
2705
2706 /* count may include a LF at end of string */
2707 if (buf[cnt-1] == '\n')
2708 cnt--;
2709
2710 rc = lpfc_wwn_set(buf, cnt, wwpn);
2711 if (rc)
2712 return rc;
2713
2714 memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2715 memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t)));
2716 if (wwn_to_u64(wwpn) == 0)
2717 phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT;
2718 else
2719 phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT;
2720 phba->cfg_oas_flags &= ~OAS_LUN_VALID;
2721 if (phba->cfg_oas_priority == 0)
2722 phba->cfg_oas_priority = phba->cfg_XLanePriority;
2723 phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN;
2724 return count;
2725 }
2726 static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR,
2727 lpfc_oas_vpt_show, lpfc_oas_vpt_store);
2728
2729 /**
2730 * lpfc_oas_lun_state_show - Return the current state (enabled or disabled)
2731 * of whether luns will be enabled or disabled
2732 * for Optimized Access Storage (OAS) operations.
2733 * @dev: class device that is converted into a Scsi_host.
2734 * @attr: device attribute, not used.
2735 * @buf: buffer for passing information.
2736 *
2737 * Returns:
2738 * size of formatted string.
2739 **/
2740 static ssize_t
2741 lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr,
2742 char *buf)
2743 {
2744 struct Scsi_Host *shost = class_to_shost(dev);
2745 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2746
2747 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state);
2748 }
2749
2750 /**
2751 * lpfc_oas_lun_state_store - Store the state (enabled or disabled)
2752 * of whether luns will be enabled or disabled
2753 * for Optimized Access Storage (OAS) operations.
2754 * @dev: class device that is converted into a Scsi_host.
2755 * @attr: device attribute, not used.
2756 * @buf: buffer for passing information.
2757 * @count: Size of the data buffer.
2758 *
2759 * Returns:
2760 * -EINVAL count is invalid, invalid wwpn byte invalid
2761 * -EPERM oas is not supported by hba
2762 * value of count on success
2763 **/
2764 static ssize_t
2765 lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr,
2766 const char *buf, size_t count)
2767 {
2768 struct Scsi_Host *shost = class_to_shost(dev);
2769 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2770 int val = 0;
2771
2772 if (!phba->cfg_fof)
2773 return -EPERM;
2774
2775 if (!isdigit(buf[0]))
2776 return -EINVAL;
2777
2778 if (sscanf(buf, "%i", &val) != 1)
2779 return -EINVAL;
2780
2781 if ((val != 0) && (val != 1))
2782 return -EINVAL;
2783
2784 phba->cfg_oas_lun_state = val;
2785 return strlen(buf);
2786 }
2787 static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR,
2788 lpfc_oas_lun_state_show, lpfc_oas_lun_state_store);
2789
2790 /**
2791 * lpfc_oas_lun_status_show - Return the status of the Optimized Access
2792 * Storage (OAS) lun returned by the
2793 * lpfc_oas_lun_show function.
2794 * @dev: class device that is converted into a Scsi_host.
2795 * @attr: device attribute, not used.
2796 * @buf: buffer for passing information.
2797 *
2798 * Returns:
2799 * size of formatted string.
2800 **/
2801 static ssize_t
2802 lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr,
2803 char *buf)
2804 {
2805 struct Scsi_Host *shost = class_to_shost(dev);
2806 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2807
2808 if (!(phba->cfg_oas_flags & OAS_LUN_VALID))
2809 return -EFAULT;
2810
2811 return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status);
2812 }
2813 static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO,
2814 lpfc_oas_lun_status_show, NULL);
2815
2816
2817 /**
2818 * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage
2819 * (OAS) operations.
2820 * @phba: lpfc_hba pointer.
2821 * @ndlp: pointer to fcp target node.
2822 * @lun: the fc lun for setting oas state.
2823 * @oas_state: the oas state to be set to the lun.
2824 *
2825 * Returns:
2826 * SUCCESS : 0
2827 * -EPERM OAS is not enabled or not supported by this port.
2828 *
2829 */
2830 static size_t
2831 lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2832 uint8_t tgt_wwpn[], uint64_t lun,
2833 uint32_t oas_state, uint8_t pri)
2834 {
2835
2836 int rc = 0;
2837
2838 if (!phba->cfg_fof)
2839 return -EPERM;
2840
2841 if (oas_state) {
2842 if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2843 (struct lpfc_name *)tgt_wwpn,
2844 lun, pri))
2845 rc = -ENOMEM;
2846 } else {
2847 lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn,
2848 (struct lpfc_name *)tgt_wwpn, lun, pri);
2849 }
2850 return rc;
2851
2852 }
2853
2854 /**
2855 * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized
2856 * Access Storage (OAS) operations.
2857 * @phba: lpfc_hba pointer.
2858 * @vpt_wwpn: wwpn of the vport associated with the returned lun
2859 * @tgt_wwpn: wwpn of the target associated with the returned lun
2860 * @lun_status: status of the lun returned lun
2861 *
2862 * Returns the first or next lun enabled for OAS operations for the vport/target
2863 * specified. If a lun is found, its vport wwpn, target wwpn and status is
2864 * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned.
2865 *
2866 * Return:
2867 * lun that is OAS enabled for the vport/target
2868 * NOT_OAS_ENABLED_LUN when no oas enabled lun found.
2869 */
2870 static uint64_t
2871 lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2872 uint8_t tgt_wwpn[], uint32_t *lun_status,
2873 uint32_t *lun_pri)
2874 {
2875 uint64_t found_lun;
2876
2877 if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn)
2878 return NOT_OAS_ENABLED_LUN;
2879 if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *)
2880 phba->sli4_hba.oas_next_vpt_wwpn,
2881 (struct lpfc_name *)
2882 phba->sli4_hba.oas_next_tgt_wwpn,
2883 &phba->sli4_hba.oas_next_lun,
2884 (struct lpfc_name *)vpt_wwpn,
2885 (struct lpfc_name *)tgt_wwpn,
2886 &found_lun, lun_status, lun_pri))
2887 return found_lun;
2888 else
2889 return NOT_OAS_ENABLED_LUN;
2890 }
2891
2892 /**
2893 * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations
2894 * @phba: lpfc_hba pointer.
2895 * @vpt_wwpn: vport wwpn by reference.
2896 * @tgt_wwpn: target wwpn by reference.
2897 * @lun: the fc lun for setting oas state.
2898 * @oas_state: the oas state to be set to the oas_lun.
2899 *
2900 * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE)
2901 * a lun for OAS operations.
2902 *
2903 * Return:
2904 * SUCCESS: 0
2905 * -ENOMEM: failed to enable an lun for OAS operations
2906 * -EPERM: OAS is not enabled
2907 */
2908 static ssize_t
2909 lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[],
2910 uint8_t tgt_wwpn[], uint64_t lun,
2911 uint32_t oas_state, uint8_t pri)
2912 {
2913
2914 int rc;
2915
2916 rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun,
2917 oas_state, pri);
2918 return rc;
2919 }
2920
2921 /**
2922 * lpfc_oas_lun_show - Return oas enabled luns from a chosen target
2923 * @dev: class device that is converted into a Scsi_host.
2924 * @attr: device attribute, not used.
2925 * @buf: buffer for passing information.
2926 *
2927 * This routine returns a lun enabled for OAS each time the function
2928 * is called.
2929 *
2930 * Returns:
2931 * SUCCESS: size of formatted string.
2932 * -EFAULT: target or vport wwpn was not set properly.
2933 * -EPERM: oas is not enabled.
2934 **/
2935 static ssize_t
2936 lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr,
2937 char *buf)
2938 {
2939 struct Scsi_Host *shost = class_to_shost(dev);
2940 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2941
2942 uint64_t oas_lun;
2943 int len = 0;
2944
2945 if (!phba->cfg_fof)
2946 return -EPERM;
2947
2948 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2949 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT))
2950 return -EFAULT;
2951
2952 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
2953 if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET))
2954 return -EFAULT;
2955
2956 oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn,
2957 phba->cfg_oas_tgt_wwpn,
2958 &phba->cfg_oas_lun_status,
2959 &phba->cfg_oas_priority);
2960 if (oas_lun != NOT_OAS_ENABLED_LUN)
2961 phba->cfg_oas_flags |= OAS_LUN_VALID;
2962
2963 len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun);
2964
2965 return len;
2966 }
2967
2968 /**
2969 * lpfc_oas_lun_store - Sets the OAS state for lun
2970 * @dev: class device that is converted into a Scsi_host.
2971 * @attr: device attribute, not used.
2972 * @buf: buffer for passing information.
2973 *
2974 * This function sets the OAS state for lun. Before this function is called,
2975 * the vport wwpn, target wwpn, and oas state need to be set.
2976 *
2977 * Returns:
2978 * SUCCESS: size of formatted string.
2979 * -EFAULT: target or vport wwpn was not set properly.
2980 * -EPERM: oas is not enabled.
2981 * size of formatted string.
2982 **/
2983 static ssize_t
2984 lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr,
2985 const char *buf, size_t count)
2986 {
2987 struct Scsi_Host *shost = class_to_shost(dev);
2988 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
2989 uint64_t scsi_lun;
2990 uint32_t pri;
2991 ssize_t rc;
2992
2993 if (!phba->cfg_fof)
2994 return -EPERM;
2995
2996 if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0)
2997 return -EFAULT;
2998
2999 if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0)
3000 return -EFAULT;
3001
3002 if (!isdigit(buf[0]))
3003 return -EINVAL;
3004
3005 if (sscanf(buf, "0x%llx", &scsi_lun) != 1)
3006 return -EINVAL;
3007
3008 pri = phba->cfg_oas_priority;
3009 if (pri == 0)
3010 pri = phba->cfg_XLanePriority;
3011
3012 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3013 "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx "
3014 "priority 0x%x with oas state %d\n",
3015 wwn_to_u64(phba->cfg_oas_vpt_wwpn),
3016 wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun,
3017 pri, phba->cfg_oas_lun_state);
3018
3019 rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn,
3020 phba->cfg_oas_tgt_wwpn, scsi_lun,
3021 phba->cfg_oas_lun_state, pri);
3022 if (rc)
3023 return rc;
3024
3025 return count;
3026 }
3027 static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR,
3028 lpfc_oas_lun_show, lpfc_oas_lun_store);
3029
3030 int lpfc_enable_nvmet_cnt;
3031 unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = {
3032 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3034 module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444);
3035 MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target");
3036
3037 static int lpfc_poll = 0;
3038 module_param(lpfc_poll, int, S_IRUGO);
3039 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
3040 " 0 - none,"
3041 " 1 - poll with interrupts enabled"
3042 " 3 - poll and disable FCP ring interrupts");
3043
3044 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
3045 lpfc_poll_show, lpfc_poll_store);
3046
3047 int lpfc_no_hba_reset_cnt;
3048 unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = {
3049 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3050 module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444);
3051 MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset");
3052
3053 LPFC_ATTR(sli_mode, 0, 0, 3,
3054 "SLI mode selector:"
3055 " 0 - auto (SLI-3 if supported),"
3056 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
3057 " 3 - select SLI-3");
3058
3059 LPFC_ATTR_R(enable_npiv, 1, 0, 1,
3060 "Enable NPIV functionality");
3061
3062 LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2,
3063 "FCF Fast failover=1 Priority failover=2");
3064
3065 /*
3066 # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures
3067 # 0x0 = disabled, XRI/OXID use not tracked.
3068 # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent.
3069 # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent.
3070 */
3071 LPFC_ATTR_R(enable_rrq, 2, 0, 2,
3072 "Enable RRQ functionality");
3073
3074 /*
3075 # lpfc_suppress_link_up: Bring link up at initialization
3076 # 0x0 = bring link up (issue MBX_INIT_LINK)
3077 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
3078 # 0x2 = never bring up link
3079 # Default value is 0.
3080 */
3081 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
3082 LPFC_DELAY_INIT_LINK_INDEFINITELY,
3083 "Suppress Link Up at initialization");
3084 /*
3085 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
3086 # 1 - (1024)
3087 # 2 - (2048)
3088 # 3 - (3072)
3089 # 4 - (4096)
3090 # 5 - (5120)
3091 */
3092 static ssize_t
3093 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3094 {
3095 struct Scsi_Host *shost = class_to_shost(dev);
3096 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3097
3098 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
3099 }
3100
3101 static DEVICE_ATTR(iocb_hw, S_IRUGO,
3102 lpfc_iocb_hw_show, NULL);
3103 static ssize_t
3104 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
3105 {
3106 struct Scsi_Host *shost = class_to_shost(dev);
3107 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3108 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3109
3110 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max);
3111 }
3112
3113 static DEVICE_ATTR(txq_hw, S_IRUGO,
3114 lpfc_txq_hw_show, NULL);
3115 static ssize_t
3116 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
3117 char *buf)
3118 {
3119 struct Scsi_Host *shost = class_to_shost(dev);
3120 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
3121 struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba);
3122
3123 return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max);
3124 }
3125
3126 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
3127 lpfc_txcmplq_hw_show, NULL);
3128
3129 LPFC_ATTR_R(iocb_cnt, 2, 1, 5,
3130 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
3131
3132 /*
3133 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
3134 # until the timer expires. Value range is [0,255]. Default value is 30.
3135 */
3136 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3137 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
3138 module_param(lpfc_nodev_tmo, int, 0);
3139 MODULE_PARM_DESC(lpfc_nodev_tmo,
3140 "Seconds driver will hold I/O waiting "
3141 "for a device to come back");
3142
3143 /**
3144 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
3145 * @dev: class converted to a Scsi_host structure.
3146 * @attr: device attribute, not used.
3147 * @buf: on return contains the dev loss timeout in decimal.
3148 *
3149 * Returns: size of formatted string.
3150 **/
3151 static ssize_t
3152 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
3153 char *buf)
3154 {
3155 struct Scsi_Host *shost = class_to_shost(dev);
3156 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3157
3158 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
3159 }
3160
3161 /**
3162 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
3163 * @vport: lpfc vport structure pointer.
3164 * @val: contains the nodev timeout value.
3165 *
3166 * Description:
3167 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
3168 * a kernel error message is printed and zero is returned.
3169 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3170 * Otherwise nodev tmo is set to the default value.
3171 *
3172 * Returns:
3173 * zero if already set or if val is in range
3174 * -EINVAL val out of range
3175 **/
3176 static int
3177 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
3178 {
3179 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
3180 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
3181 if (val != LPFC_DEF_DEVLOSS_TMO)
3182 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3183 "0407 Ignoring lpfc_nodev_tmo module "
3184 "parameter because lpfc_devloss_tmo "
3185 "is set.\n");
3186 return 0;
3187 }
3188
3189 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3190 vport->cfg_nodev_tmo = val;
3191 vport->cfg_devloss_tmo = val;
3192 return 0;
3193 }
3194 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3195 "0400 lpfc_nodev_tmo attribute cannot be set to"
3196 " %d, allowed range is [%d, %d]\n",
3197 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3198 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
3199 return -EINVAL;
3200 }
3201
3202 /**
3203 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
3204 * @vport: lpfc vport structure pointer.
3205 *
3206 * Description:
3207 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
3208 **/
3209 static void
3210 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
3211 {
3212 struct Scsi_Host *shost;
3213 struct lpfc_nodelist *ndlp;
3214
3215 shost = lpfc_shost_from_vport(vport);
3216 spin_lock_irq(shost->host_lock);
3217 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3218 if (!NLP_CHK_NODE_ACT(ndlp))
3219 continue;
3220 if (ndlp->rport)
3221 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
3222 }
3223 spin_unlock_irq(shost->host_lock);
3224 }
3225
3226 /**
3227 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
3228 * @vport: lpfc vport structure pointer.
3229 * @val: contains the tmo value.
3230 *
3231 * Description:
3232 * If the devloss tmo is already set or the vport dev loss tmo has changed
3233 * then a kernel error message is printed and zero is returned.
3234 * Else if val is in range then nodev tmo and devloss tmo are set to val.
3235 * Otherwise nodev tmo is set to the default value.
3236 *
3237 * Returns:
3238 * zero if already set or if val is in range
3239 * -EINVAL val out of range
3240 **/
3241 static int
3242 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
3243 {
3244 if (vport->dev_loss_tmo_changed ||
3245 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
3246 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3247 "0401 Ignoring change to lpfc_nodev_tmo "
3248 "because lpfc_devloss_tmo is set.\n");
3249 return 0;
3250 }
3251 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3252 vport->cfg_nodev_tmo = val;
3253 vport->cfg_devloss_tmo = val;
3254 /*
3255 * For compat: set the fc_host dev loss so new rports
3256 * will get the value.
3257 */
3258 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3259 lpfc_update_rport_devloss_tmo(vport);
3260 return 0;
3261 }
3262 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3263 "0403 lpfc_nodev_tmo attribute cannot be set to "
3264 "%d, allowed range is [%d, %d]\n",
3265 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3266 return -EINVAL;
3267 }
3268
3269 lpfc_vport_param_store(nodev_tmo)
3270
3271 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
3272 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
3273
3274 /*
3275 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
3276 # disappear until the timer expires. Value range is [0,255]. Default
3277 # value is 30.
3278 */
3279 module_param(lpfc_devloss_tmo, int, S_IRUGO);
3280 MODULE_PARM_DESC(lpfc_devloss_tmo,
3281 "Seconds driver will hold I/O waiting "
3282 "for a device to come back");
3283 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
3284 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
3285 lpfc_vport_param_show(devloss_tmo)
3286
3287 /**
3288 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
3289 * @vport: lpfc vport structure pointer.
3290 * @val: contains the tmo value.
3291 *
3292 * Description:
3293 * If val is in a valid range then set the vport nodev tmo,
3294 * devloss tmo, also set the vport dev loss tmo changed flag.
3295 * Else a kernel error message is printed.
3296 *
3297 * Returns:
3298 * zero if val is in range
3299 * -EINVAL val out of range
3300 **/
3301 static int
3302 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
3303 {
3304 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
3305 vport->cfg_nodev_tmo = val;
3306 vport->cfg_devloss_tmo = val;
3307 vport->dev_loss_tmo_changed = 1;
3308 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
3309 lpfc_update_rport_devloss_tmo(vport);
3310 return 0;
3311 }
3312
3313 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3314 "0404 lpfc_devloss_tmo attribute cannot be set to "
3315 "%d, allowed range is [%d, %d]\n",
3316 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
3317 return -EINVAL;
3318 }
3319
3320 lpfc_vport_param_store(devloss_tmo)
3321 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
3322 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
3323
3324 /*
3325 * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it
3326 * lpfc_suppress_rsp = 0 Disable
3327 * lpfc_suppress_rsp = 1 Enable (default)
3328 *
3329 */
3330 LPFC_ATTR_R(suppress_rsp, 1, 0, 1,
3331 "Enable suppress rsp feature is firmware supports it");
3332
3333 /*
3334 * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds
3335 * lpfc_nvmet_mrq = 1 use a single RQ pair
3336 * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ
3337 *
3338 */
3339 LPFC_ATTR_R(nvmet_mrq,
3340 1, 1, 16,
3341 "Specify number of RQ pairs for processing NVMET cmds");
3342
3343 /*
3344 * lpfc_enable_fc4_type: Defines what FC4 types are supported.
3345 * Supported Values: 1 - register just FCP
3346 * 3 - register both FCP and NVME
3347 * Supported values are [1,3]. Default value is 1
3348 */
3349 LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP,
3350 LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH,
3351 "Define fc4 type to register with fabric.");
3352
3353 /*
3354 * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME
3355 * This parameter is only used if:
3356 * lpfc_enable_fc4_type is 3 - register both FCP and NVME and
3357 * port is not configured for NVMET.
3358 *
3359 * ELS/CT always get 10% of XRIs, up to a maximum of 250
3360 * The remaining XRIs get split up based on lpfc_xri_split per port:
3361 *
3362 * Supported Values are in percentages
3363 * the xri_split value is the percentage the SCSI port will get. The remaining
3364 * percentage will go to NVME.
3365 */
3366 LPFC_ATTR_R(xri_split, 50, 10, 90,
3367 "Division of XRI resources between SCSI and NVME");
3368
3369 /*
3370 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
3371 # deluged with LOTS of information.
3372 # You can set a bit mask to record specific types of verbose messages:
3373 # See lpfc_logmsh.h for definitions.
3374 */
3375 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
3376 "Verbose logging bit-mask");
3377
3378 /*
3379 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
3380 # objects that have been registered with the nameserver after login.
3381 */
3382 LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1,
3383 "Deregister nameserver objects before LOGO");
3384
3385 /*
3386 # lun_queue_depth: This parameter is used to limit the number of outstanding
3387 # commands per FCP LUN. Value range is [1,512]. Default value is 30.
3388 # If this parameter value is greater than 1/8th the maximum number of exchanges
3389 # supported by the HBA port, then the lun queue depth will be reduced to
3390 # 1/8th the maximum number of exchanges.
3391 */
3392 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512,
3393 "Max number of FCP commands we can queue to a specific LUN");
3394
3395 /*
3396 # tgt_queue_depth: This parameter is used to limit the number of outstanding
3397 # commands per target port. Value range is [10,65535]. Default value is 65535.
3398 */
3399 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
3400 "Max number of FCP commands we can queue to a specific target port");
3401
3402 /*
3403 # hba_queue_depth: This parameter is used to limit the number of outstanding
3404 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
3405 # value is greater than the maximum number of exchanges supported by the HBA,
3406 # then maximum number of exchanges supported by the HBA is used to determine
3407 # the hba_queue_depth.
3408 */
3409 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
3410 "Max number of FCP commands we can queue to a lpfc HBA");
3411
3412 /*
3413 # peer_port_login: This parameter allows/prevents logins
3414 # between peer ports hosted on the same physical port.
3415 # When this parameter is set 0 peer ports of same physical port
3416 # are not allowed to login to each other.
3417 # When this parameter is set 1 peer ports of same physical port
3418 # are allowed to login to each other.
3419 # Default value of this parameter is 0.
3420 */
3421 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
3422 "Allow peer ports on the same physical port to login to each "
3423 "other.");
3424
3425 /*
3426 # restrict_login: This parameter allows/prevents logins
3427 # between Virtual Ports and remote initiators.
3428 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
3429 # other initiators and will attempt to PLOGI all remote ports.
3430 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
3431 # remote ports and will not attempt to PLOGI to other initiators.
3432 # This parameter does not restrict to the physical port.
3433 # This parameter does not restrict logins to Fabric resident remote ports.
3434 # Default value of this parameter is 1.
3435 */
3436 static int lpfc_restrict_login = 1;
3437 module_param(lpfc_restrict_login, int, S_IRUGO);
3438 MODULE_PARM_DESC(lpfc_restrict_login,
3439 "Restrict virtual ports login to remote initiators.");
3440 lpfc_vport_param_show(restrict_login);
3441
3442 /**
3443 * lpfc_restrict_login_init - Set the vport restrict login flag
3444 * @vport: lpfc vport structure pointer.
3445 * @val: contains the restrict login value.
3446 *
3447 * Description:
3448 * If val is not in a valid range then log a kernel error message and set
3449 * the vport restrict login to one.
3450 * If the port type is physical clear the restrict login flag and return.
3451 * Else set the restrict login flag to val.
3452 *
3453 * Returns:
3454 * zero if val is in range
3455 * -EINVAL val out of range
3456 **/
3457 static int
3458 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
3459 {
3460 if (val < 0 || val > 1) {
3461 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3462 "0422 lpfc_restrict_login attribute cannot "
3463 "be set to %d, allowed range is [0, 1]\n",
3464 val);
3465 vport->cfg_restrict_login = 1;
3466 return -EINVAL;
3467 }
3468 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3469 vport->cfg_restrict_login = 0;
3470 return 0;
3471 }
3472 vport->cfg_restrict_login = val;
3473 return 0;
3474 }
3475
3476 /**
3477 * lpfc_restrict_login_set - Set the vport restrict login flag
3478 * @vport: lpfc vport structure pointer.
3479 * @val: contains the restrict login value.
3480 *
3481 * Description:
3482 * If val is not in a valid range then log a kernel error message and set
3483 * the vport restrict login to one.
3484 * If the port type is physical and the val is not zero log a kernel
3485 * error message, clear the restrict login flag and return zero.
3486 * Else set the restrict login flag to val.
3487 *
3488 * Returns:
3489 * zero if val is in range
3490 * -EINVAL val out of range
3491 **/
3492 static int
3493 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
3494 {
3495 if (val < 0 || val > 1) {
3496 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3497 "0425 lpfc_restrict_login attribute cannot "
3498 "be set to %d, allowed range is [0, 1]\n",
3499 val);
3500 vport->cfg_restrict_login = 1;
3501 return -EINVAL;
3502 }
3503 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
3504 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3505 "0468 lpfc_restrict_login must be 0 for "
3506 "Physical ports.\n");
3507 vport->cfg_restrict_login = 0;
3508 return 0;
3509 }
3510 vport->cfg_restrict_login = val;
3511 return 0;
3512 }
3513 lpfc_vport_param_store(restrict_login);
3514 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
3515 lpfc_restrict_login_show, lpfc_restrict_login_store);
3516
3517 /*
3518 # Some disk devices have a "select ID" or "select Target" capability.
3519 # From a protocol standpoint "select ID" usually means select the
3520 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
3521 # annex" which contains a table that maps a "select ID" (a number
3522 # between 0 and 7F) to an ALPA. By default, for compatibility with
3523 # older drivers, the lpfc driver scans this table from low ALPA to high
3524 # ALPA.
3525 #
3526 # Turning on the scan-down variable (on = 1, off = 0) will
3527 # cause the lpfc driver to use an inverted table, effectively
3528 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
3529 #
3530 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
3531 # and will not work across a fabric. Also this parameter will take
3532 # effect only in the case when ALPA map is not available.)
3533 */
3534 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
3535 "Start scanning for devices from highest ALPA to lowest");
3536
3537 /*
3538 # lpfc_topology: link topology for init link
3539 # 0x0 = attempt loop mode then point-to-point
3540 # 0x01 = internal loopback mode
3541 # 0x02 = attempt point-to-point mode only
3542 # 0x04 = attempt loop mode only
3543 # 0x06 = attempt point-to-point mode then loop
3544 # Set point-to-point mode if you want to run as an N_Port.
3545 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
3546 # Default value is 0.
3547 */
3548 LPFC_ATTR(topology, 0, 0, 6,
3549 "Select Fibre Channel topology");
3550
3551 /**
3552 * lpfc_topology_set - Set the adapters topology field
3553 * @phba: lpfc_hba pointer.
3554 * @val: topology value.
3555 *
3556 * Description:
3557 * If val is in a valid range then set the adapter's topology field and
3558 * issue a lip; if the lip fails reset the topology to the old value.
3559 *
3560 * If the value is not in range log a kernel error message and return an error.
3561 *
3562 * Returns:
3563 * zero if val is in range and lip okay
3564 * non-zero return value from lpfc_issue_lip()
3565 * -EINVAL val out of range
3566 **/
3567 static ssize_t
3568 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
3569 const char *buf, size_t count)
3570 {
3571 struct Scsi_Host *shost = class_to_shost(dev);
3572 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3573 struct lpfc_hba *phba = vport->phba;
3574 int val = 0;
3575 int nolip = 0;
3576 const char *val_buf = buf;
3577 int err;
3578 uint32_t prev_val;
3579
3580 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
3581 nolip = 1;
3582 val_buf = &buf[strlen("nolip ")];
3583 }
3584
3585 if (!isdigit(val_buf[0]))
3586 return -EINVAL;
3587 if (sscanf(val_buf, "%i", &val) != 1)
3588 return -EINVAL;
3589
3590 if (val >= 0 && val <= 6) {
3591 prev_val = phba->cfg_topology;
3592 if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G &&
3593 val == 4) {
3594 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3595 "3113 Loop mode not supported at speed %d\n",
3596 val);
3597 return -EINVAL;
3598 }
3599 if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
3600 val == 4) {
3601 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3602 "3114 Loop mode not supported\n");
3603 return -EINVAL;
3604 }
3605 phba->cfg_topology = val;
3606 if (nolip)
3607 return strlen(buf);
3608
3609 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
3610 "3054 lpfc_topology changed from %d to %d\n",
3611 prev_val, val);
3612 if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4)
3613 phba->fc_topology_changed = 1;
3614 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
3615 if (err) {
3616 phba->cfg_topology = prev_val;
3617 return -EINVAL;
3618 } else
3619 return strlen(buf);
3620 }
3621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3622 "%d:0467 lpfc_topology attribute cannot be set to %d, "
3623 "allowed range is [0, 6]\n",
3624 phba->brd_no, val);
3625 return -EINVAL;
3626 }
3627
3628 lpfc_param_show(topology)
3629 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
3630 lpfc_topology_show, lpfc_topology_store);
3631
3632 /**
3633 * lpfc_static_vport_show: Read callback function for
3634 * lpfc_static_vport sysfs file.
3635 * @dev: Pointer to class device object.
3636 * @attr: device attribute structure.
3637 * @buf: Data buffer.
3638 *
3639 * This function is the read call back function for
3640 * lpfc_static_vport sysfs file. The lpfc_static_vport
3641 * sysfs file report the mageability of the vport.
3642 **/
3643 static ssize_t
3644 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
3645 char *buf)
3646 {
3647 struct Scsi_Host *shost = class_to_shost(dev);
3648 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3649 if (vport->vport_flag & STATIC_VPORT)
3650 sprintf(buf, "1\n");
3651 else
3652 sprintf(buf, "0\n");
3653
3654 return strlen(buf);
3655 }
3656
3657 /*
3658 * Sysfs attribute to control the statistical data collection.
3659 */
3660 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
3661 lpfc_static_vport_show, NULL);
3662
3663 /**
3664 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
3665 * @dev: Pointer to class device.
3666 * @buf: Data buffer.
3667 * @count: Size of the data buffer.
3668 *
3669 * This function get called when a user write to the lpfc_stat_data_ctrl
3670 * sysfs file. This function parse the command written to the sysfs file
3671 * and take appropriate action. These commands are used for controlling
3672 * driver statistical data collection.
3673 * Following are the command this function handles.
3674 *
3675 * setbucket <bucket_type> <base> <step>
3676 * = Set the latency buckets.
3677 * destroybucket = destroy all the buckets.
3678 * start = start data collection
3679 * stop = stop data collection
3680 * reset = reset the collected data
3681 **/
3682 static ssize_t
3683 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
3684 const char *buf, size_t count)
3685 {
3686 struct Scsi_Host *shost = class_to_shost(dev);
3687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3688 struct lpfc_hba *phba = vport->phba;
3689 #define LPFC_MAX_DATA_CTRL_LEN 1024
3690 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
3691 unsigned long i;
3692 char *str_ptr, *token;
3693 struct lpfc_vport **vports;
3694 struct Scsi_Host *v_shost;
3695 char *bucket_type_str, *base_str, *step_str;
3696 unsigned long base, step, bucket_type;
3697
3698 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
3699 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
3700 return -EINVAL;
3701
3702 strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN);
3703 str_ptr = &bucket_data[0];
3704 /* Ignore this token - this is command token */
3705 token = strsep(&str_ptr, "\t ");
3706 if (!token)
3707 return -EINVAL;
3708
3709 bucket_type_str = strsep(&str_ptr, "\t ");
3710 if (!bucket_type_str)
3711 return -EINVAL;
3712
3713 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
3714 bucket_type = LPFC_LINEAR_BUCKET;
3715 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
3716 bucket_type = LPFC_POWER2_BUCKET;
3717 else
3718 return -EINVAL;
3719
3720 base_str = strsep(&str_ptr, "\t ");
3721 if (!base_str)
3722 return -EINVAL;
3723 base = simple_strtoul(base_str, NULL, 0);
3724
3725 step_str = strsep(&str_ptr, "\t ");
3726 if (!step_str)
3727 return -EINVAL;
3728 step = simple_strtoul(step_str, NULL, 0);
3729 if (!step)
3730 return -EINVAL;
3731
3732 /* Block the data collection for every vport */
3733 vports = lpfc_create_vport_work_array(phba);
3734 if (vports == NULL)
3735 return -ENOMEM;
3736
3737 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3738 v_shost = lpfc_shost_from_vport(vports[i]);
3739 spin_lock_irq(v_shost->host_lock);
3740 /* Block and reset data collection */
3741 vports[i]->stat_data_blocked = 1;
3742 if (vports[i]->stat_data_enabled)
3743 lpfc_vport_reset_stat_data(vports[i]);
3744 spin_unlock_irq(v_shost->host_lock);
3745 }
3746
3747 /* Set the bucket attributes */
3748 phba->bucket_type = bucket_type;
3749 phba->bucket_base = base;
3750 phba->bucket_step = step;
3751
3752 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3753 v_shost = lpfc_shost_from_vport(vports[i]);
3754
3755 /* Unblock data collection */
3756 spin_lock_irq(v_shost->host_lock);
3757 vports[i]->stat_data_blocked = 0;
3758 spin_unlock_irq(v_shost->host_lock);
3759 }
3760 lpfc_destroy_vport_work_array(phba, vports);
3761 return strlen(buf);
3762 }
3763
3764 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
3765 vports = lpfc_create_vport_work_array(phba);
3766 if (vports == NULL)
3767 return -ENOMEM;
3768
3769 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3770 v_shost = lpfc_shost_from_vport(vports[i]);
3771 spin_lock_irq(shost->host_lock);
3772 vports[i]->stat_data_blocked = 1;
3773 lpfc_free_bucket(vport);
3774 vport->stat_data_enabled = 0;
3775 vports[i]->stat_data_blocked = 0;
3776 spin_unlock_irq(shost->host_lock);
3777 }
3778 lpfc_destroy_vport_work_array(phba, vports);
3779 phba->bucket_type = LPFC_NO_BUCKET;
3780 phba->bucket_base = 0;
3781 phba->bucket_step = 0;
3782 return strlen(buf);
3783 }
3784
3785 if (!strncmp(buf, "start", strlen("start"))) {
3786 /* If no buckets configured return error */
3787 if (phba->bucket_type == LPFC_NO_BUCKET)
3788 return -EINVAL;
3789 spin_lock_irq(shost->host_lock);
3790 if (vport->stat_data_enabled) {
3791 spin_unlock_irq(shost->host_lock);
3792 return strlen(buf);
3793 }
3794 lpfc_alloc_bucket(vport);
3795 vport->stat_data_enabled = 1;
3796 spin_unlock_irq(shost->host_lock);
3797 return strlen(buf);
3798 }
3799
3800 if (!strncmp(buf, "stop", strlen("stop"))) {
3801 spin_lock_irq(shost->host_lock);
3802 if (vport->stat_data_enabled == 0) {
3803 spin_unlock_irq(shost->host_lock);
3804 return strlen(buf);
3805 }
3806 lpfc_free_bucket(vport);
3807 vport->stat_data_enabled = 0;
3808 spin_unlock_irq(shost->host_lock);
3809 return strlen(buf);
3810 }
3811
3812 if (!strncmp(buf, "reset", strlen("reset"))) {
3813 if ((phba->bucket_type == LPFC_NO_BUCKET)
3814 || !vport->stat_data_enabled)
3815 return strlen(buf);
3816 spin_lock_irq(shost->host_lock);
3817 vport->stat_data_blocked = 1;
3818 lpfc_vport_reset_stat_data(vport);
3819 vport->stat_data_blocked = 0;
3820 spin_unlock_irq(shost->host_lock);
3821 return strlen(buf);
3822 }
3823 return -EINVAL;
3824 }
3825
3826
3827 /**
3828 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
3829 * @dev: Pointer to class device object.
3830 * @buf: Data buffer.
3831 *
3832 * This function is the read call back function for
3833 * lpfc_stat_data_ctrl sysfs file. This function report the
3834 * current statistical data collection state.
3835 **/
3836 static ssize_t
3837 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
3838 char *buf)
3839 {
3840 struct Scsi_Host *shost = class_to_shost(dev);
3841 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3842 struct lpfc_hba *phba = vport->phba;
3843 int index = 0;
3844 int i;
3845 char *bucket_type;
3846 unsigned long bucket_value;
3847
3848 switch (phba->bucket_type) {
3849 case LPFC_LINEAR_BUCKET:
3850 bucket_type = "linear";
3851 break;
3852 case LPFC_POWER2_BUCKET:
3853 bucket_type = "power2";
3854 break;
3855 default:
3856 bucket_type = "No Bucket";
3857 break;
3858 }
3859
3860 sprintf(&buf[index], "Statistical Data enabled :%d, "
3861 "blocked :%d, Bucket type :%s, Bucket base :%d,"
3862 " Bucket step :%d\nLatency Ranges :",
3863 vport->stat_data_enabled, vport->stat_data_blocked,
3864 bucket_type, phba->bucket_base, phba->bucket_step);
3865 index = strlen(buf);
3866 if (phba->bucket_type != LPFC_NO_BUCKET) {
3867 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3868 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
3869 bucket_value = phba->bucket_base +
3870 phba->bucket_step * i;
3871 else
3872 bucket_value = phba->bucket_base +
3873 (1 << i) * phba->bucket_step;
3874
3875 if (index + 10 > PAGE_SIZE)
3876 break;
3877 sprintf(&buf[index], "%08ld ", bucket_value);
3878 index = strlen(buf);
3879 }
3880 }
3881 sprintf(&buf[index], "\n");
3882 return strlen(buf);
3883 }
3884
3885 /*
3886 * Sysfs attribute to control the statistical data collection.
3887 */
3888 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
3889 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
3890
3891 /*
3892 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
3893 */
3894
3895 /*
3896 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
3897 * for each target.
3898 */
3899 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
3900 #define MAX_STAT_DATA_SIZE_PER_TARGET \
3901 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
3902
3903
3904 /**
3905 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
3906 * @filp: sysfs file
3907 * @kobj: Pointer to the kernel object
3908 * @bin_attr: Attribute object
3909 * @buff: Buffer pointer
3910 * @off: File offset
3911 * @count: Buffer size
3912 *
3913 * This function is the read call back function for lpfc_drvr_stat_data
3914 * sysfs file. This function export the statistical data to user
3915 * applications.
3916 **/
3917 static ssize_t
3918 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
3919 struct bin_attribute *bin_attr,
3920 char *buf, loff_t off, size_t count)
3921 {
3922 struct device *dev = container_of(kobj, struct device,
3923 kobj);
3924 struct Scsi_Host *shost = class_to_shost(dev);
3925 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3926 struct lpfc_hba *phba = vport->phba;
3927 int i = 0, index = 0;
3928 unsigned long nport_index;
3929 struct lpfc_nodelist *ndlp = NULL;
3930 nport_index = (unsigned long)off /
3931 MAX_STAT_DATA_SIZE_PER_TARGET;
3932
3933 if (!vport->stat_data_enabled || vport->stat_data_blocked
3934 || (phba->bucket_type == LPFC_NO_BUCKET))
3935 return 0;
3936
3937 spin_lock_irq(shost->host_lock);
3938 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3939 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
3940 continue;
3941
3942 if (nport_index > 0) {
3943 nport_index--;
3944 continue;
3945 }
3946
3947 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
3948 > count)
3949 break;
3950
3951 if (!ndlp->lat_data)
3952 continue;
3953
3954 /* Print the WWN */
3955 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
3956 ndlp->nlp_portname.u.wwn[0],
3957 ndlp->nlp_portname.u.wwn[1],
3958 ndlp->nlp_portname.u.wwn[2],
3959 ndlp->nlp_portname.u.wwn[3],
3960 ndlp->nlp_portname.u.wwn[4],
3961 ndlp->nlp_portname.u.wwn[5],
3962 ndlp->nlp_portname.u.wwn[6],
3963 ndlp->nlp_portname.u.wwn[7]);
3964
3965 index = strlen(buf);
3966
3967 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
3968 sprintf(&buf[index], "%010u,",
3969 ndlp->lat_data[i].cmd_count);
3970 index = strlen(buf);
3971 }
3972 sprintf(&buf[index], "\n");
3973 index = strlen(buf);
3974 }
3975 spin_unlock_irq(shost->host_lock);
3976 return index;
3977 }
3978
3979 static struct bin_attribute sysfs_drvr_stat_data_attr = {
3980 .attr = {
3981 .name = "lpfc_drvr_stat_data",
3982 .mode = S_IRUSR,
3983 },
3984 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
3985 .read = sysfs_drvr_stat_data_read,
3986 .write = NULL,
3987 };
3988
3989 /*
3990 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
3991 # connection.
3992 # Value range is [0,16]. Default value is 0.
3993 */
3994 /**
3995 * lpfc_link_speed_set - Set the adapters link speed
3996 * @phba: lpfc_hba pointer.
3997 * @val: link speed value.
3998 *
3999 * Description:
4000 * If val is in a valid range then set the adapter's link speed field and
4001 * issue a lip; if the lip fails reset the link speed to the old value.
4002 *
4003 * Notes:
4004 * If the value is not in range log a kernel error message and return an error.
4005 *
4006 * Returns:
4007 * zero if val is in range and lip okay.
4008 * non-zero return value from lpfc_issue_lip()
4009 * -EINVAL val out of range
4010 **/
4011 static ssize_t
4012 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
4013 const char *buf, size_t count)
4014 {
4015 struct Scsi_Host *shost = class_to_shost(dev);
4016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4017 struct lpfc_hba *phba = vport->phba;
4018 int val = LPFC_USER_LINK_SPEED_AUTO;
4019 int nolip = 0;
4020 const char *val_buf = buf;
4021 int err;
4022 uint32_t prev_val, if_type;
4023
4024 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
4025 if (if_type == LPFC_SLI_INTF_IF_TYPE_2 &&
4026 phba->hba_flag & HBA_FORCED_LINK_SPEED)
4027 return -EPERM;
4028
4029 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
4030 nolip = 1;
4031 val_buf = &buf[strlen("nolip ")];
4032 }
4033
4034 if (!isdigit(val_buf[0]))
4035 return -EINVAL;
4036 if (sscanf(val_buf, "%i", &val) != 1)
4037 return -EINVAL;
4038
4039 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
4040 "3055 lpfc_link_speed changed from %d to %d %s\n",
4041 phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)");
4042
4043 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
4044 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
4045 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
4046 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
4047 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
4048 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) ||
4049 ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) {
4050 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4051 "2879 lpfc_link_speed attribute cannot be set "
4052 "to %d. Speed is not supported by this port.\n",
4053 val);
4054 return -EINVAL;
4055 }
4056 if (val == LPFC_USER_LINK_SPEED_16G &&
4057 phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4059 "3112 lpfc_link_speed attribute cannot be set "
4060 "to %d. Speed is not supported in loop mode.\n",
4061 val);
4062 return -EINVAL;
4063 }
4064 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4065 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4066 prev_val = phba->cfg_link_speed;
4067 phba->cfg_link_speed = val;
4068 if (nolip)
4069 return strlen(buf);
4070
4071 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
4072 if (err) {
4073 phba->cfg_link_speed = prev_val;
4074 return -EINVAL;
4075 } else
4076 return strlen(buf);
4077 }
4078 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4079 "0469 lpfc_link_speed attribute cannot be set to %d, "
4080 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
4081 return -EINVAL;
4082 }
4083
4084 static int lpfc_link_speed = 0;
4085 module_param(lpfc_link_speed, int, S_IRUGO);
4086 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
4087 lpfc_param_show(link_speed)
4088
4089 /**
4090 * lpfc_link_speed_init - Set the adapters link speed
4091 * @phba: lpfc_hba pointer.
4092 * @val: link speed value.
4093 *
4094 * Description:
4095 * If val is in a valid range then set the adapter's link speed field.
4096 *
4097 * Notes:
4098 * If the value is not in range log a kernel error message, clear the link
4099 * speed and return an error.
4100 *
4101 * Returns:
4102 * zero if val saved.
4103 * -EINVAL val out of range
4104 **/
4105 static int
4106 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
4107 {
4108 if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) {
4109 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4110 "3111 lpfc_link_speed of %d cannot "
4111 "support loop mode, setting topology to default.\n",
4112 val);
4113 phba->cfg_topology = 0;
4114 }
4115 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
4116 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
4117 phba->cfg_link_speed = val;
4118 return 0;
4119 }
4120 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4121 "0405 lpfc_link_speed attribute cannot "
4122 "be set to %d, allowed values are "
4123 "["LPFC_LINK_SPEED_STRING"]\n", val);
4124 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
4125 return -EINVAL;
4126 }
4127
4128 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
4129 lpfc_link_speed_show, lpfc_link_speed_store);
4130
4131 /*
4132 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
4133 # 0 = aer disabled or not supported
4134 # 1 = aer supported and enabled (default)
4135 # Value range is [0,1]. Default value is 1.
4136 */
4137 LPFC_ATTR(aer_support, 1, 0, 1,
4138 "Enable PCIe device AER support");
4139 lpfc_param_show(aer_support)
4140
4141 /**
4142 * lpfc_aer_support_store - Set the adapter for aer support
4143 *
4144 * @dev: class device that is converted into a Scsi_host.
4145 * @attr: device attribute, not used.
4146 * @buf: containing enable or disable aer flag.
4147 * @count: unused variable.
4148 *
4149 * Description:
4150 * If the val is 1 and currently the device's AER capability was not
4151 * enabled, invoke the kernel's enable AER helper routine, trying to
4152 * enable the device's AER capability. If the helper routine enabling
4153 * AER returns success, update the device's cfg_aer_support flag to
4154 * indicate AER is supported by the device; otherwise, if the device
4155 * AER capability is already enabled to support AER, then do nothing.
4156 *
4157 * If the val is 0 and currently the device's AER support was enabled,
4158 * invoke the kernel's disable AER helper routine. After that, update
4159 * the device's cfg_aer_support flag to indicate AER is not supported
4160 * by the device; otherwise, if the device AER capability is already
4161 * disabled from supporting AER, then do nothing.
4162 *
4163 * Returns:
4164 * length of the buf on success if val is in range the intended mode
4165 * is supported.
4166 * -EINVAL if val out of range or intended mode is not supported.
4167 **/
4168 static ssize_t
4169 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
4170 const char *buf, size_t count)
4171 {
4172 struct Scsi_Host *shost = class_to_shost(dev);
4173 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4174 struct lpfc_hba *phba = vport->phba;
4175 int val = 0, rc = -EINVAL;
4176
4177 if (!isdigit(buf[0]))
4178 return -EINVAL;
4179 if (sscanf(buf, "%i", &val) != 1)
4180 return -EINVAL;
4181
4182 switch (val) {
4183 case 0:
4184 if (phba->hba_flag & HBA_AER_ENABLED) {
4185 rc = pci_disable_pcie_error_reporting(phba->pcidev);
4186 if (!rc) {
4187 spin_lock_irq(&phba->hbalock);
4188 phba->hba_flag &= ~HBA_AER_ENABLED;
4189 spin_unlock_irq(&phba->hbalock);
4190 phba->cfg_aer_support = 0;
4191 rc = strlen(buf);
4192 } else
4193 rc = -EPERM;
4194 } else {
4195 phba->cfg_aer_support = 0;
4196 rc = strlen(buf);
4197 }
4198 break;
4199 case 1:
4200 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
4201 rc = pci_enable_pcie_error_reporting(phba->pcidev);
4202 if (!rc) {
4203 spin_lock_irq(&phba->hbalock);
4204 phba->hba_flag |= HBA_AER_ENABLED;
4205 spin_unlock_irq(&phba->hbalock);
4206 phba->cfg_aer_support = 1;
4207 rc = strlen(buf);
4208 } else
4209 rc = -EPERM;
4210 } else {
4211 phba->cfg_aer_support = 1;
4212 rc = strlen(buf);
4213 }
4214 break;
4215 default:
4216 rc = -EINVAL;
4217 break;
4218 }
4219 return rc;
4220 }
4221
4222 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
4223 lpfc_aer_support_show, lpfc_aer_support_store);
4224
4225 /**
4226 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
4227 * @dev: class device that is converted into a Scsi_host.
4228 * @attr: device attribute, not used.
4229 * @buf: containing flag 1 for aer cleanup state.
4230 * @count: unused variable.
4231 *
4232 * Description:
4233 * If the @buf contains 1 and the device currently has the AER support
4234 * enabled, then invokes the kernel AER helper routine
4235 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
4236 * error status register.
4237 *
4238 * Notes:
4239 *
4240 * Returns:
4241 * -EINVAL if the buf does not contain the 1 or the device is not currently
4242 * enabled with the AER support.
4243 **/
4244 static ssize_t
4245 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
4246 const char *buf, size_t count)
4247 {
4248 struct Scsi_Host *shost = class_to_shost(dev);
4249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4250 struct lpfc_hba *phba = vport->phba;
4251 int val, rc = -1;
4252
4253 if (!isdigit(buf[0]))
4254 return -EINVAL;
4255 if (sscanf(buf, "%i", &val) != 1)
4256 return -EINVAL;
4257 if (val != 1)
4258 return -EINVAL;
4259
4260 if (phba->hba_flag & HBA_AER_ENABLED)
4261 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
4262
4263 if (rc == 0)
4264 return strlen(buf);
4265 else
4266 return -EPERM;
4267 }
4268
4269 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
4270 lpfc_aer_cleanup_state);
4271
4272 /**
4273 * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions
4274 *
4275 * @dev: class device that is converted into a Scsi_host.
4276 * @attr: device attribute, not used.
4277 * @buf: containing the string the number of vfs to be enabled.
4278 * @count: unused variable.
4279 *
4280 * Description:
4281 * When this api is called either through user sysfs, the driver shall
4282 * try to enable or disable SR-IOV virtual functions according to the
4283 * following:
4284 *
4285 * If zero virtual function has been enabled to the physical function,
4286 * the driver shall invoke the pci enable virtual function api trying
4287 * to enable the virtual functions. If the nr_vfn provided is greater
4288 * than the maximum supported, the maximum virtual function number will
4289 * be used for invoking the api; otherwise, the nr_vfn provided shall
4290 * be used for invoking the api. If the api call returned success, the
4291 * actual number of virtual functions enabled will be set to the driver
4292 * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver
4293 * cfg_sriov_nr_virtfn remains zero.
4294 *
4295 * If none-zero virtual functions have already been enabled to the
4296 * physical function, as reflected by the driver's cfg_sriov_nr_virtfn,
4297 * -EINVAL will be returned and the driver does nothing;
4298 *
4299 * If the nr_vfn provided is zero and none-zero virtual functions have
4300 * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the
4301 * disabling virtual function api shall be invoded to disable all the
4302 * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to
4303 * zero. Otherwise, if zero virtual function has been enabled, do
4304 * nothing.
4305 *
4306 * Returns:
4307 * length of the buf on success if val is in range the intended mode
4308 * is supported.
4309 * -EINVAL if val out of range or intended mode is not supported.
4310 **/
4311 static ssize_t
4312 lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr,
4313 const char *buf, size_t count)
4314 {
4315 struct Scsi_Host *shost = class_to_shost(dev);
4316 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4317 struct lpfc_hba *phba = vport->phba;
4318 struct pci_dev *pdev = phba->pcidev;
4319 int val = 0, rc = -EINVAL;
4320
4321 /* Sanity check on user data */
4322 if (!isdigit(buf[0]))
4323 return -EINVAL;
4324 if (sscanf(buf, "%i", &val) != 1)
4325 return -EINVAL;
4326 if (val < 0)
4327 return -EINVAL;
4328
4329 /* Request disabling virtual functions */
4330 if (val == 0) {
4331 if (phba->cfg_sriov_nr_virtfn > 0) {
4332 pci_disable_sriov(pdev);
4333 phba->cfg_sriov_nr_virtfn = 0;
4334 }
4335 return strlen(buf);
4336 }
4337
4338 /* Request enabling virtual functions */
4339 if (phba->cfg_sriov_nr_virtfn > 0) {
4340 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4341 "3018 There are %d virtual functions "
4342 "enabled on physical function.\n",
4343 phba->cfg_sriov_nr_virtfn);
4344 return -EEXIST;
4345 }
4346
4347 if (val <= LPFC_MAX_VFN_PER_PFN)
4348 phba->cfg_sriov_nr_virtfn = val;
4349 else {
4350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4351 "3019 Enabling %d virtual functions is not "
4352 "allowed.\n", val);
4353 return -EINVAL;
4354 }
4355
4356 rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn);
4357 if (rc) {
4358 phba->cfg_sriov_nr_virtfn = 0;
4359 rc = -EPERM;
4360 } else
4361 rc = strlen(buf);
4362
4363 return rc;
4364 }
4365
4366 LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN,
4367 "Enable PCIe device SR-IOV virtual fn");
4368
4369 lpfc_param_show(sriov_nr_virtfn)
4370 static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR,
4371 lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store);
4372
4373 /**
4374 * lpfc_request_firmware_store - Request for Linux generic firmware upgrade
4375 *
4376 * @dev: class device that is converted into a Scsi_host.
4377 * @attr: device attribute, not used.
4378 * @buf: containing the string the number of vfs to be enabled.
4379 * @count: unused variable.
4380 *
4381 * Description:
4382 *
4383 * Returns:
4384 * length of the buf on success if val is in range the intended mode
4385 * is supported.
4386 * -EINVAL if val out of range or intended mode is not supported.
4387 **/
4388 static ssize_t
4389 lpfc_request_firmware_upgrade_store(struct device *dev,
4390 struct device_attribute *attr,
4391 const char *buf, size_t count)
4392 {
4393 struct Scsi_Host *shost = class_to_shost(dev);
4394 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4395 struct lpfc_hba *phba = vport->phba;
4396 int val = 0, rc = -EINVAL;
4397
4398 /* Sanity check on user data */
4399 if (!isdigit(buf[0]))
4400 return -EINVAL;
4401 if (sscanf(buf, "%i", &val) != 1)
4402 return -EINVAL;
4403 if (val != 1)
4404 return -EINVAL;
4405
4406 rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE);
4407 if (rc)
4408 rc = -EPERM;
4409 else
4410 rc = strlen(buf);
4411 return rc;
4412 }
4413
4414 static int lpfc_req_fw_upgrade;
4415 module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR);
4416 MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade");
4417 lpfc_param_show(request_firmware_upgrade)
4418
4419 /**
4420 * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade
4421 * @phba: lpfc_hba pointer.
4422 * @val: 0 or 1.
4423 *
4424 * Description:
4425 * Set the initial Linux generic firmware upgrade enable or disable flag.
4426 *
4427 * Returns:
4428 * zero if val saved.
4429 * -EINVAL val out of range
4430 **/
4431 static int
4432 lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val)
4433 {
4434 if (val >= 0 && val <= 1) {
4435 phba->cfg_request_firmware_upgrade = val;
4436 return 0;
4437 }
4438 return -EINVAL;
4439 }
4440 static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR,
4441 lpfc_request_firmware_upgrade_show,
4442 lpfc_request_firmware_upgrade_store);
4443
4444 /**
4445 * lpfc_fcp_imax_store
4446 *
4447 * @dev: class device that is converted into a Scsi_host.
4448 * @attr: device attribute, not used.
4449 * @buf: string with the number of fast-path FCP interrupts per second.
4450 * @count: unused variable.
4451 *
4452 * Description:
4453 * If val is in a valid range [636,651042], then set the adapter's
4454 * maximum number of fast-path FCP interrupts per second.
4455 *
4456 * Returns:
4457 * length of the buf on success if val is in range the intended mode
4458 * is supported.
4459 * -EINVAL if val out of range or intended mode is not supported.
4460 **/
4461 static ssize_t
4462 lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr,
4463 const char *buf, size_t count)
4464 {
4465 struct Scsi_Host *shost = class_to_shost(dev);
4466 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4467 struct lpfc_hba *phba = vport->phba;
4468 int val = 0, i;
4469
4470 /* fcp_imax is only valid for SLI4 */
4471 if (phba->sli_rev != LPFC_SLI_REV4)
4472 return -EINVAL;
4473
4474 /* Sanity check on user data */
4475 if (!isdigit(buf[0]))
4476 return -EINVAL;
4477 if (sscanf(buf, "%i", &val) != 1)
4478 return -EINVAL;
4479
4480 /*
4481 * Value range for the HBA is [5000,5000000]
4482 * The value for each EQ depends on how many EQs are configured.
4483 * Allow value == 0
4484 */
4485 if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX))
4486 return -EINVAL;
4487
4488 phba->cfg_fcp_imax = (uint32_t)val;
4489 phba->initial_imax = phba->cfg_fcp_imax;
4490
4491 for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT)
4492 lpfc_modify_hba_eq_delay(phba, i, LPFC_MAX_EQ_DELAY_EQID_CNT,
4493 val);
4494
4495 return strlen(buf);
4496 }
4497
4498 /*
4499 # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second
4500 # for the HBA.
4501 #
4502 # Value range is [5,000 to 5,000,000]. Default value is 50,000.
4503 */
4504 static int lpfc_fcp_imax = LPFC_DEF_IMAX;
4505 module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR);
4506 MODULE_PARM_DESC(lpfc_fcp_imax,
4507 "Set the maximum number of FCP interrupts per second per HBA");
4508 lpfc_param_show(fcp_imax)
4509
4510 /**
4511 * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable
4512 * @phba: lpfc_hba pointer.
4513 * @val: link speed value.
4514 *
4515 * Description:
4516 * If val is in a valid range [636,651042], then initialize the adapter's
4517 * maximum number of fast-path FCP interrupts per second.
4518 *
4519 * Returns:
4520 * zero if val saved.
4521 * -EINVAL val out of range
4522 **/
4523 static int
4524 lpfc_fcp_imax_init(struct lpfc_hba *phba, int val)
4525 {
4526 if (phba->sli_rev != LPFC_SLI_REV4) {
4527 phba->cfg_fcp_imax = 0;
4528 return 0;
4529 }
4530
4531 if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) ||
4532 (val == 0)) {
4533 phba->cfg_fcp_imax = val;
4534 return 0;
4535 }
4536
4537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4538 "3016 lpfc_fcp_imax: %d out of range, using default\n",
4539 val);
4540 phba->cfg_fcp_imax = LPFC_DEF_IMAX;
4541
4542 return 0;
4543 }
4544
4545 static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR,
4546 lpfc_fcp_imax_show, lpfc_fcp_imax_store);
4547
4548 /*
4549 * lpfc_auto_imax: Controls Auto-interrupt coalescing values support.
4550 * 0 No auto_imax support
4551 * 1 auto imax on
4552 * Auto imax will change the value of fcp_imax on a per EQ basis, using
4553 * the EQ Delay Multiplier, depending on the activity for that EQ.
4554 * Value range [0,1]. Default value is 1.
4555 */
4556 LPFC_ATTR_RW(auto_imax, 1, 0, 1, "Enable Auto imax");
4557
4558 /**
4559 * lpfc_state_show - Display current driver CPU affinity
4560 * @dev: class converted to a Scsi_host structure.
4561 * @attr: device attribute, not used.
4562 * @buf: on return contains text describing the state of the link.
4563 *
4564 * Returns: size of formatted string.
4565 **/
4566 static ssize_t
4567 lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr,
4568 char *buf)
4569 {
4570 struct Scsi_Host *shost = class_to_shost(dev);
4571 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
4572 struct lpfc_hba *phba = vport->phba;
4573 struct lpfc_vector_map_info *cpup;
4574 int len = 0;
4575
4576 if ((phba->sli_rev != LPFC_SLI_REV4) ||
4577 (phba->intr_type != MSIX))
4578 return len;
4579
4580 switch (phba->cfg_fcp_cpu_map) {
4581 case 0:
4582 len += snprintf(buf + len, PAGE_SIZE-len,
4583 "fcp_cpu_map: No mapping (%d)\n",
4584 phba->cfg_fcp_cpu_map);
4585 return len;
4586 case 1:
4587 len += snprintf(buf + len, PAGE_SIZE-len,
4588 "fcp_cpu_map: HBA centric mapping (%d): "
4589 "%d online CPUs\n",
4590 phba->cfg_fcp_cpu_map,
4591 phba->sli4_hba.num_online_cpu);
4592 break;
4593 case 2:
4594 len += snprintf(buf + len, PAGE_SIZE-len,
4595 "fcp_cpu_map: Driver centric mapping (%d): "
4596 "%d online CPUs\n",
4597 phba->cfg_fcp_cpu_map,
4598 phba->sli4_hba.num_online_cpu);
4599 break;
4600 }
4601
4602 while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) {
4603 cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu];
4604
4605 /* margin should fit in this and the truncated message */
4606 if (cpup->irq == LPFC_VECTOR_MAP_EMPTY)
4607 len += snprintf(buf + len, PAGE_SIZE-len,
4608 "CPU %02d io_chan %02d "
4609 "physid %d coreid %d\n",
4610 phba->sli4_hba.curr_disp_cpu,
4611 cpup->channel_id, cpup->phys_id,
4612 cpup->core_id);
4613 else
4614 len += snprintf(buf + len, PAGE_SIZE-len,
4615 "CPU %02d io_chan %02d "
4616 "physid %d coreid %d IRQ %d\n",
4617 phba->sli4_hba.curr_disp_cpu,
4618 cpup->channel_id, cpup->phys_id,
4619 cpup->core_id, cpup->irq);
4620
4621 phba->sli4_hba.curr_disp_cpu++;
4622
4623 /* display max number of CPUs keeping some margin */
4624 if (phba->sli4_hba.curr_disp_cpu <
4625 phba->sli4_hba.num_present_cpu &&
4626 (len >= (PAGE_SIZE - 64))) {
4627 len += snprintf(buf + len, PAGE_SIZE-len, "more...\n");
4628 break;
4629 }
4630 }
4631
4632 if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu)
4633 phba->sli4_hba.curr_disp_cpu = 0;
4634
4635 return len;
4636 }
4637
4638 /**
4639 * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors
4640 * @dev: class device that is converted into a Scsi_host.
4641 * @attr: device attribute, not used.
4642 * @buf: one or more lpfc_polling_flags values.
4643 * @count: not used.
4644 *
4645 * Returns:
4646 * -EINVAL - Not implemented yet.
4647 **/
4648 static ssize_t
4649 lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr,
4650 const char *buf, size_t count)
4651 {
4652 int status = -EINVAL;
4653 return status;
4654 }
4655
4656 /*
4657 # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors
4658 # for the HBA.
4659 #
4660 # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2).
4661 # 0 - Do not affinitze IRQ vectors
4662 # 1 - Affintize HBA vectors with respect to each HBA
4663 # (start with CPU0 for each HBA)
4664 # 2 - Affintize HBA vectors with respect to the entire driver
4665 # (round robin thru all CPUs across all HBAs)
4666 */
4667 static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4668 module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR);
4669 MODULE_PARM_DESC(lpfc_fcp_cpu_map,
4670 "Defines how to map CPUs to IRQ vectors per HBA");
4671
4672 /**
4673 * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable
4674 * @phba: lpfc_hba pointer.
4675 * @val: link speed value.
4676 *
4677 * Description:
4678 * If val is in a valid range [0-2], then affinitze the adapter's
4679 * MSIX vectors.
4680 *
4681 * Returns:
4682 * zero if val saved.
4683 * -EINVAL val out of range
4684 **/
4685 static int
4686 lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val)
4687 {
4688 if (phba->sli_rev != LPFC_SLI_REV4) {
4689 phba->cfg_fcp_cpu_map = 0;
4690 return 0;
4691 }
4692
4693 if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) {
4694 phba->cfg_fcp_cpu_map = val;
4695 return 0;
4696 }
4697
4698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4699 "3326 lpfc_fcp_cpu_map: %d out of range, using "
4700 "default\n", val);
4701 phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP;
4702
4703 return 0;
4704 }
4705
4706 static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR,
4707 lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store);
4708
4709 /*
4710 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
4711 # Value range is [2,3]. Default value is 3.
4712 */
4713 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
4714 "Select Fibre Channel class of service for FCP sequences");
4715
4716 /*
4717 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
4718 # is [0,1]. Default value is 0.
4719 */
4720 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
4721 "Use ADISC on rediscovery to authenticate FCP devices");
4722
4723 /*
4724 # lpfc_first_burst_size: First burst size to use on the NPorts
4725 # that support first burst.
4726 # Value range is [0,65536]. Default value is 0.
4727 */
4728 LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536,
4729 "First burst size for Targets that support first burst");
4730
4731 /*
4732 * lpfc_nvmet_fb_size: NVME Target mode supported first burst size.
4733 * When the driver is configured as an NVME target, this value is
4734 * communicated to the NVME initiator in the PRLI response. It is
4735 * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support
4736 * parameters are set and the target is sending the PRLI RSP.
4737 * Parameter supported on physical port only - no NPIV support.
4738 * Value range is [0,65536]. Default value is 0.
4739 */
4740 LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536,
4741 "NVME Target mode first burst size in 512B increments.");
4742
4743 /*
4744 * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions.
4745 * For the Initiator (I), enabling this parameter means that an NVMET
4746 * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be
4747 * processed by the initiator for subsequent NVME FCP IO. For the target
4748 * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size
4749 * driver parameter as the target function's first burst size returned to the
4750 * initiator in the target's NVME PRLI response. Parameter supported on physical
4751 * port only - no NPIV support.
4752 * Value range is [0,1]. Default value is 0 (disabled).
4753 */
4754 LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1,
4755 "Enable First Burst feature on I and T functions.");
4756
4757 /*
4758 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
4759 # depth. Default value is 0. When the value of this parameter is zero the
4760 # SCSI command completion time is not used for controlling I/O queue depth. When
4761 # the parameter is set to a non-zero value, the I/O queue depth is controlled
4762 # to limit the I/O completion time to the parameter value.
4763 # The value is set in milliseconds.
4764 */
4765 LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000,
4766 "Use command completion time to control queue depth");
4767
4768 lpfc_vport_param_show(max_scsicmpl_time);
4769 static int
4770 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
4771 {
4772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4773 struct lpfc_nodelist *ndlp, *next_ndlp;
4774
4775 if (val == vport->cfg_max_scsicmpl_time)
4776 return 0;
4777 if ((val < 0) || (val > 60000))
4778 return -EINVAL;
4779 vport->cfg_max_scsicmpl_time = val;
4780
4781 spin_lock_irq(shost->host_lock);
4782 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4783 if (!NLP_CHK_NODE_ACT(ndlp))
4784 continue;
4785 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4786 continue;
4787 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4788 }
4789 spin_unlock_irq(shost->host_lock);
4790 return 0;
4791 }
4792 lpfc_vport_param_store(max_scsicmpl_time);
4793 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
4794 lpfc_max_scsicmpl_time_show,
4795 lpfc_max_scsicmpl_time_store);
4796
4797 /*
4798 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
4799 # range is [0,1]. Default value is 0.
4800 */
4801 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
4802
4803 /*
4804 * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds
4805 * range is [0,1]. Default value is 0.
4806 * For [0], FCP commands are issued to Work Queues ina round robin fashion.
4807 * For [1], FCP commands are issued to a Work Queue associated with the
4808 * current CPU.
4809 *
4810 * LPFC_FCP_SCHED_ROUND_ROBIN == 0
4811 * LPFC_FCP_SCHED_BY_CPU == 1
4812 *
4813 * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu
4814 * affinity for FCP/NVME I/Os through Work Queues associated with the current
4815 * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os
4816 * through WQs will be used.
4817 */
4818 LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN,
4819 LPFC_FCP_SCHED_ROUND_ROBIN,
4820 LPFC_FCP_SCHED_BY_CPU,
4821 "Determine scheduling algorithm for "
4822 "issuing commands [0] - Round Robin, [1] - Current CPU");
4823
4824 /*
4825 # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior
4826 # range is [0,1]. Default value is 0.
4827 # For [0], bus reset issues target reset to ALL devices
4828 # For [1], bus reset issues target reset to non-FCP2 devices
4829 */
4830 LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for "
4831 "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset");
4832
4833
4834 /*
4835 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
4836 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
4837 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
4838 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
4839 # cr_delay is set to 0.
4840 */
4841 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
4842 "interrupt response is generated");
4843
4844 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
4845 "interrupt response is generated");
4846
4847 /*
4848 # lpfc_multi_ring_support: Determines how many rings to spread available
4849 # cmd/rsp IOCB entries across.
4850 # Value range is [1,2]. Default value is 1.
4851 */
4852 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
4853 "SLI rings to spread IOCB entries across");
4854
4855 /*
4856 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
4857 # identifies what rctl value to configure the additional ring for.
4858 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
4859 */
4860 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
4861 255, "Identifies RCTL for additional ring configuration");
4862
4863 /*
4864 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
4865 # identifies what type value to configure the additional ring for.
4866 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
4867 */
4868 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
4869 255, "Identifies TYPE for additional ring configuration");
4870
4871 /*
4872 # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN
4873 # 0 = SmartSAN functionality disabled (default)
4874 # 1 = SmartSAN functionality enabled
4875 # This parameter will override the value of lpfc_fdmi_on module parameter.
4876 # Value range is [0,1]. Default value is 0.
4877 */
4878 LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality");
4879
4880 /*
4881 # lpfc_fdmi_on: Controls FDMI support.
4882 # 0 No FDMI support (default)
4883 # 1 Traditional FDMI support
4884 # Traditional FDMI support means the driver will assume FDMI-2 support;
4885 # however, if that fails, it will fallback to FDMI-1.
4886 # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on.
4887 # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of
4888 # lpfc_fdmi_on.
4889 # Value range [0,1]. Default value is 0.
4890 */
4891 LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support");
4892
4893 /*
4894 # Specifies the maximum number of ELS cmds we can have outstanding (for
4895 # discovery). Value range is [1,64]. Default value = 32.
4896 */
4897 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
4898 "during discovery");
4899
4900 /*
4901 # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that
4902 # will be scanned by the SCSI midlayer when sequential scanning is
4903 # used; and is also the highest LUN ID allowed when the SCSI midlayer
4904 # parses REPORT_LUN responses. The lpfc driver has no LUN count or
4905 # LUN ID limit, but the SCSI midlayer requires this field for the uses
4906 # above. The lpfc driver limits the default value to 255 for two reasons.
4907 # As it bounds the sequential scan loop, scanning for thousands of luns
4908 # on a target can take minutes of wall clock time. Additionally,
4909 # there are FC targets, such as JBODs, that only recognize 8-bits of
4910 # LUN ID. When they receive a value greater than 8 bits, they chop off
4911 # the high order bits. In other words, they see LUN IDs 0, 256, 512,
4912 # and so on all as LUN ID 0. This causes the linux kernel, which sees
4913 # valid responses at each of the LUN IDs, to believe there are multiple
4914 # devices present, when in fact, there is only 1.
4915 # A customer that is aware of their target behaviors, and the results as
4916 # indicated above, is welcome to increase the lpfc_max_luns value.
4917 # As mentioned, this value is not used by the lpfc driver, only the
4918 # SCSI midlayer.
4919 # Value range is [0,65535]. Default value is 255.
4920 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
4921 */
4922 LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID");
4923
4924 /*
4925 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
4926 # Value range is [1,255], default value is 10.
4927 */
4928 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
4929 "Milliseconds driver will wait between polling FCP ring");
4930
4931 /*
4932 # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands
4933 # to complete in seconds. Value range is [5,180], default value is 60.
4934 */
4935 LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180,
4936 "Maximum time to wait for task management commands to complete");
4937 /*
4938 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
4939 # support this feature
4940 # 0 = MSI disabled
4941 # 1 = MSI enabled
4942 # 2 = MSI-X enabled (default)
4943 # Value range is [0,2]. Default value is 2.
4944 */
4945 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
4946 "MSI-X (2), if possible");
4947
4948 /*
4949 * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs
4950 *
4951 * 0 = NVME OAS disabled
4952 * 1 = NVME OAS enabled
4953 *
4954 * Value range is [0,1]. Default value is 0.
4955 */
4956 LPFC_ATTR_RW(nvme_oas, 0, 0, 1,
4957 "Use OAS bit on NVME IOs");
4958
4959 /*
4960 * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver
4961 * will advertise it supports to the SCSI layer. This also will map to
4962 * the number of WQs the driver will create.
4963 *
4964 * 0 = Configure the number of io channels to the number of active CPUs.
4965 * 1,32 = Manually specify how many io channels to use.
4966 *
4967 * Value range is [0,32]. Default value is 4.
4968 */
4969 LPFC_ATTR_R(fcp_io_channel,
4970 LPFC_FCP_IO_CHAN_DEF,
4971 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4972 "Set the number of FCP I/O channels");
4973
4974 /*
4975 * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver
4976 * will advertise it supports to the NVME layer. This also will map to
4977 * the number of WQs the driver will create.
4978 *
4979 * This module parameter is valid when lpfc_enable_fc4_type is set
4980 * to support NVME.
4981 *
4982 * The NVME Layer will try to create this many, plus 1 administrative
4983 * hardware queue. The administrative queue will always map to WQ 0
4984 * A hardware IO queue maps (qidx) to a specific driver WQ.
4985 *
4986 * 0 = Configure the number of io channels to the number of active CPUs.
4987 * 1,32 = Manually specify how many io channels to use.
4988 *
4989 * Value range is [0,32]. Default value is 0.
4990 */
4991 LPFC_ATTR_R(nvme_io_channel,
4992 LPFC_NVME_IO_CHAN_DEF,
4993 LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX,
4994 "Set the number of NVME I/O channels");
4995
4996 /*
4997 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
4998 # 0 = HBA resets disabled
4999 # 1 = HBA resets enabled (default)
5000 # Value range is [0,1]. Default value is 1.
5001 */
5002 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
5003
5004 /*
5005 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
5006 # 0 = HBA Heartbeat disabled
5007 # 1 = HBA Heartbeat enabled (default)
5008 # Value range is [0,1]. Default value is 1.
5009 */
5010 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
5011
5012 /*
5013 # lpfc_EnableXLane: Enable Express Lane Feature
5014 # 0x0 Express Lane Feature disabled
5015 # 0x1 Express Lane Feature enabled
5016 # Value range is [0,1]. Default value is 0.
5017 */
5018 LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature.");
5019
5020 /*
5021 # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature
5022 # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits)
5023 # Value range is [0x0,0x7f]. Default value is 0
5024 */
5025 LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature.");
5026
5027 /*
5028 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
5029 # 0 = BlockGuard disabled (default)
5030 # 1 = BlockGuard enabled
5031 # Value range is [0,1]. Default value is 0.
5032 */
5033 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
5034
5035 /*
5036 # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine
5037 # 0 = disabled (default)
5038 # 1 = enabled
5039 # Value range is [0,1]. Default value is 0.
5040 #
5041 # This feature in under investigation and may be supported in the future.
5042 */
5043 unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF;
5044
5045 /*
5046 # lpfc_prot_mask: i
5047 # - Bit mask of host protection capabilities used to register with the
5048 # SCSI mid-layer
5049 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
5050 # - Allows you to ultimately specify which profiles to use
5051 # - Default will result in registering capabilities for all profiles.
5052 # - SHOST_DIF_TYPE1_PROTECTION 1
5053 # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection
5054 # - SHOST_DIX_TYPE0_PROTECTION 8
5055 # HBA supports DIX Type 0: Host to HBA protection only
5056 # - SHOST_DIX_TYPE1_PROTECTION 16
5057 # HBA supports DIX Type 1: Host to HBA Type 1 protection
5058 #
5059 */
5060 LPFC_ATTR(prot_mask,
5061 (SHOST_DIF_TYPE1_PROTECTION |
5062 SHOST_DIX_TYPE0_PROTECTION |
5063 SHOST_DIX_TYPE1_PROTECTION),
5064 0,
5065 (SHOST_DIF_TYPE1_PROTECTION |
5066 SHOST_DIX_TYPE0_PROTECTION |
5067 SHOST_DIX_TYPE1_PROTECTION),
5068 "T10-DIF host protection capabilities mask");
5069
5070 /*
5071 # lpfc_prot_guard: i
5072 # - Bit mask of protection guard types to register with the SCSI mid-layer
5073 # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum
5074 # - Allows you to ultimately specify which profiles to use
5075 # - Default will result in registering capabilities for all guard types
5076 #
5077 */
5078 LPFC_ATTR(prot_guard,
5079 SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP,
5080 "T10-DIF host protection guard type");
5081
5082 /*
5083 * Delay initial NPort discovery when Clean Address bit is cleared in
5084 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
5085 * This parameter can have value 0 or 1.
5086 * When this parameter is set to 0, no delay is added to the initial
5087 * discovery.
5088 * When this parameter is set to non-zero value, initial Nport discovery is
5089 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
5090 * accept and FCID/Fabric name/Fabric portname is changed.
5091 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
5092 * when Clean Address bit is cleared in FLOGI/FDISC
5093 * accept and FCID/Fabric name/Fabric portname is changed.
5094 * Default value is 0.
5095 */
5096 LPFC_ATTR(delay_discovery, 0, 0, 1,
5097 "Delay NPort discovery when Clean Address bit is cleared.");
5098
5099 /*
5100 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
5101 * This value can be set to values between 64 and 4096. The default value is
5102 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
5103 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
5104 * Because of the additional overhead involved in setting up T10-DIF,
5105 * this parameter will be limited to 128 if BlockGuard is enabled under SLI4
5106 * and will be limited to 512 if BlockGuard is enabled under SLI3.
5107 */
5108 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
5109 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
5110
5111 /*
5112 * lpfc_enable_mds_diags: Enable MDS Diagnostics
5113 * 0 = MDS Diagnostics disabled (default)
5114 * 1 = MDS Diagnostics enabled
5115 * Value range is [0,1]. Default value is 0.
5116 */
5117 LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics");
5118
5119 struct device_attribute *lpfc_hba_attrs[] = {
5120 &dev_attr_nvme_info,
5121 &dev_attr_bg_info,
5122 &dev_attr_bg_guard_err,
5123 &dev_attr_bg_apptag_err,
5124 &dev_attr_bg_reftag_err,
5125 &dev_attr_info,
5126 &dev_attr_serialnum,
5127 &dev_attr_modeldesc,
5128 &dev_attr_modelname,
5129 &dev_attr_programtype,
5130 &dev_attr_portnum,
5131 &dev_attr_fwrev,
5132 &dev_attr_hdw,
5133 &dev_attr_option_rom_version,
5134 &dev_attr_link_state,
5135 &dev_attr_num_discovered_ports,
5136 &dev_attr_menlo_mgmt_mode,
5137 &dev_attr_lpfc_drvr_version,
5138 &dev_attr_lpfc_enable_fip,
5139 &dev_attr_lpfc_temp_sensor,
5140 &dev_attr_lpfc_log_verbose,
5141 &dev_attr_lpfc_lun_queue_depth,
5142 &dev_attr_lpfc_tgt_queue_depth,
5143 &dev_attr_lpfc_hba_queue_depth,
5144 &dev_attr_lpfc_peer_port_login,
5145 &dev_attr_lpfc_nodev_tmo,
5146 &dev_attr_lpfc_devloss_tmo,
5147 &dev_attr_lpfc_enable_fc4_type,
5148 &dev_attr_lpfc_xri_split,
5149 &dev_attr_lpfc_fcp_class,
5150 &dev_attr_lpfc_use_adisc,
5151 &dev_attr_lpfc_first_burst_size,
5152 &dev_attr_lpfc_ack0,
5153 &dev_attr_lpfc_topology,
5154 &dev_attr_lpfc_scan_down,
5155 &dev_attr_lpfc_link_speed,
5156 &dev_attr_lpfc_fcp_io_sched,
5157 &dev_attr_lpfc_fcp2_no_tgt_reset,
5158 &dev_attr_lpfc_cr_delay,
5159 &dev_attr_lpfc_cr_count,
5160 &dev_attr_lpfc_multi_ring_support,
5161 &dev_attr_lpfc_multi_ring_rctl,
5162 &dev_attr_lpfc_multi_ring_type,
5163 &dev_attr_lpfc_fdmi_on,
5164 &dev_attr_lpfc_enable_SmartSAN,
5165 &dev_attr_lpfc_max_luns,
5166 &dev_attr_lpfc_enable_npiv,
5167 &dev_attr_lpfc_fcf_failover_policy,
5168 &dev_attr_lpfc_enable_rrq,
5169 &dev_attr_nport_evt_cnt,
5170 &dev_attr_board_mode,
5171 &dev_attr_max_vpi,
5172 &dev_attr_used_vpi,
5173 &dev_attr_max_rpi,
5174 &dev_attr_used_rpi,
5175 &dev_attr_max_xri,
5176 &dev_attr_used_xri,
5177 &dev_attr_npiv_info,
5178 &dev_attr_issue_reset,
5179 &dev_attr_lpfc_poll,
5180 &dev_attr_lpfc_poll_tmo,
5181 &dev_attr_lpfc_task_mgmt_tmo,
5182 &dev_attr_lpfc_use_msi,
5183 &dev_attr_lpfc_nvme_oas,
5184 &dev_attr_lpfc_auto_imax,
5185 &dev_attr_lpfc_fcp_imax,
5186 &dev_attr_lpfc_fcp_cpu_map,
5187 &dev_attr_lpfc_fcp_io_channel,
5188 &dev_attr_lpfc_suppress_rsp,
5189 &dev_attr_lpfc_nvme_io_channel,
5190 &dev_attr_lpfc_nvmet_mrq,
5191 &dev_attr_lpfc_nvme_enable_fb,
5192 &dev_attr_lpfc_nvmet_fb_size,
5193 &dev_attr_lpfc_enable_bg,
5194 &dev_attr_lpfc_soft_wwnn,
5195 &dev_attr_lpfc_soft_wwpn,
5196 &dev_attr_lpfc_soft_wwn_enable,
5197 &dev_attr_lpfc_enable_hba_reset,
5198 &dev_attr_lpfc_enable_hba_heartbeat,
5199 &dev_attr_lpfc_EnableXLane,
5200 &dev_attr_lpfc_XLanePriority,
5201 &dev_attr_lpfc_xlane_lun,
5202 &dev_attr_lpfc_xlane_tgt,
5203 &dev_attr_lpfc_xlane_vpt,
5204 &dev_attr_lpfc_xlane_lun_state,
5205 &dev_attr_lpfc_xlane_lun_status,
5206 &dev_attr_lpfc_xlane_priority,
5207 &dev_attr_lpfc_sg_seg_cnt,
5208 &dev_attr_lpfc_max_scsicmpl_time,
5209 &dev_attr_lpfc_stat_data_ctrl,
5210 &dev_attr_lpfc_aer_support,
5211 &dev_attr_lpfc_aer_state_cleanup,
5212 &dev_attr_lpfc_sriov_nr_virtfn,
5213 &dev_attr_lpfc_req_fw_upgrade,
5214 &dev_attr_lpfc_suppress_link_up,
5215 &dev_attr_lpfc_iocb_cnt,
5216 &dev_attr_iocb_hw,
5217 &dev_attr_txq_hw,
5218 &dev_attr_txcmplq_hw,
5219 &dev_attr_lpfc_fips_level,
5220 &dev_attr_lpfc_fips_rev,
5221 &dev_attr_lpfc_dss,
5222 &dev_attr_lpfc_sriov_hw_max_virtfn,
5223 &dev_attr_protocol,
5224 &dev_attr_lpfc_xlane_supported,
5225 &dev_attr_lpfc_enable_mds_diags,
5226 NULL,
5227 };
5228
5229 struct device_attribute *lpfc_vport_attrs[] = {
5230 &dev_attr_info,
5231 &dev_attr_link_state,
5232 &dev_attr_num_discovered_ports,
5233 &dev_attr_lpfc_drvr_version,
5234 &dev_attr_lpfc_log_verbose,
5235 &dev_attr_lpfc_lun_queue_depth,
5236 &dev_attr_lpfc_tgt_queue_depth,
5237 &dev_attr_lpfc_nodev_tmo,
5238 &dev_attr_lpfc_devloss_tmo,
5239 &dev_attr_lpfc_hba_queue_depth,
5240 &dev_attr_lpfc_peer_port_login,
5241 &dev_attr_lpfc_restrict_login,
5242 &dev_attr_lpfc_fcp_class,
5243 &dev_attr_lpfc_use_adisc,
5244 &dev_attr_lpfc_first_burst_size,
5245 &dev_attr_lpfc_max_luns,
5246 &dev_attr_nport_evt_cnt,
5247 &dev_attr_npiv_info,
5248 &dev_attr_lpfc_enable_da_id,
5249 &dev_attr_lpfc_max_scsicmpl_time,
5250 &dev_attr_lpfc_stat_data_ctrl,
5251 &dev_attr_lpfc_static_vport,
5252 &dev_attr_lpfc_fips_level,
5253 &dev_attr_lpfc_fips_rev,
5254 NULL,
5255 };
5256
5257 /**
5258 * sysfs_ctlreg_write - Write method for writing to ctlreg
5259 * @filp: open sysfs file
5260 * @kobj: kernel kobject that contains the kernel class device.
5261 * @bin_attr: kernel attributes passed to us.
5262 * @buf: contains the data to be written to the adapter IOREG space.
5263 * @off: offset into buffer to beginning of data.
5264 * @count: bytes to transfer.
5265 *
5266 * Description:
5267 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5268 * Uses the adapter io control registers to send buf contents to the adapter.
5269 *
5270 * Returns:
5271 * -ERANGE off and count combo out of range
5272 * -EINVAL off, count or buff address invalid
5273 * -EPERM adapter is offline
5274 * value of count, buf contents written
5275 **/
5276 static ssize_t
5277 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
5278 struct bin_attribute *bin_attr,
5279 char *buf, loff_t off, size_t count)
5280 {
5281 size_t buf_off;
5282 struct device *dev = container_of(kobj, struct device, kobj);
5283 struct Scsi_Host *shost = class_to_shost(dev);
5284 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5285 struct lpfc_hba *phba = vport->phba;
5286
5287 if (phba->sli_rev >= LPFC_SLI_REV4)
5288 return -EPERM;
5289
5290 if ((off + count) > FF_REG_AREA_SIZE)
5291 return -ERANGE;
5292
5293 if (count <= LPFC_REG_WRITE_KEY_SIZE)
5294 return 0;
5295
5296 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5297 return -EINVAL;
5298
5299 /* This is to protect HBA registers from accidental writes. */
5300 if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE))
5301 return -EINVAL;
5302
5303 if (!(vport->fc_flag & FC_OFFLINE_MODE))
5304 return -EPERM;
5305
5306 spin_lock_irq(&phba->hbalock);
5307 for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE;
5308 buf_off += sizeof(uint32_t))
5309 writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)),
5310 phba->ctrl_regs_memmap_p + off + buf_off);
5311
5312 spin_unlock_irq(&phba->hbalock);
5313
5314 return count;
5315 }
5316
5317 /**
5318 * sysfs_ctlreg_read - Read method for reading from ctlreg
5319 * @filp: open sysfs file
5320 * @kobj: kernel kobject that contains the kernel class device.
5321 * @bin_attr: kernel attributes passed to us.
5322 * @buf: if successful contains the data from the adapter IOREG space.
5323 * @off: offset into buffer to beginning of data.
5324 * @count: bytes to transfer.
5325 *
5326 * Description:
5327 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
5328 * Uses the adapter io control registers to read data into buf.
5329 *
5330 * Returns:
5331 * -ERANGE off and count combo out of range
5332 * -EINVAL off, count or buff address invalid
5333 * value of count, buf contents read
5334 **/
5335 static ssize_t
5336 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
5337 struct bin_attribute *bin_attr,
5338 char *buf, loff_t off, size_t count)
5339 {
5340 size_t buf_off;
5341 uint32_t * tmp_ptr;
5342 struct device *dev = container_of(kobj, struct device, kobj);
5343 struct Scsi_Host *shost = class_to_shost(dev);
5344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5345 struct lpfc_hba *phba = vport->phba;
5346
5347 if (phba->sli_rev >= LPFC_SLI_REV4)
5348 return -EPERM;
5349
5350 if (off > FF_REG_AREA_SIZE)
5351 return -ERANGE;
5352
5353 if ((off + count) > FF_REG_AREA_SIZE)
5354 count = FF_REG_AREA_SIZE - off;
5355
5356 if (count == 0) return 0;
5357
5358 if (off % 4 || count % 4 || (unsigned long)buf % 4)
5359 return -EINVAL;
5360
5361 spin_lock_irq(&phba->hbalock);
5362
5363 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
5364 tmp_ptr = (uint32_t *)(buf + buf_off);
5365 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
5366 }
5367
5368 spin_unlock_irq(&phba->hbalock);
5369
5370 return count;
5371 }
5372
5373 static struct bin_attribute sysfs_ctlreg_attr = {
5374 .attr = {
5375 .name = "ctlreg",
5376 .mode = S_IRUSR | S_IWUSR,
5377 },
5378 .size = 256,
5379 .read = sysfs_ctlreg_read,
5380 .write = sysfs_ctlreg_write,
5381 };
5382
5383 /**
5384 * sysfs_mbox_write - Write method for writing information via mbox
5385 * @filp: open sysfs file
5386 * @kobj: kernel kobject that contains the kernel class device.
5387 * @bin_attr: kernel attributes passed to us.
5388 * @buf: contains the data to be written to sysfs mbox.
5389 * @off: offset into buffer to beginning of data.
5390 * @count: bytes to transfer.
5391 *
5392 * Description:
5393 * Deprecated function. All mailbox access from user space is performed via the
5394 * bsg interface.
5395 *
5396 * Returns:
5397 * -EPERM operation not permitted
5398 **/
5399 static ssize_t
5400 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
5401 struct bin_attribute *bin_attr,
5402 char *buf, loff_t off, size_t count)
5403 {
5404 return -EPERM;
5405 }
5406
5407 /**
5408 * sysfs_mbox_read - Read method for reading information via mbox
5409 * @filp: open sysfs file
5410 * @kobj: kernel kobject that contains the kernel class device.
5411 * @bin_attr: kernel attributes passed to us.
5412 * @buf: contains the data to be read from sysfs mbox.
5413 * @off: offset into buffer to beginning of data.
5414 * @count: bytes to transfer.
5415 *
5416 * Description:
5417 * Deprecated function. All mailbox access from user space is performed via the
5418 * bsg interface.
5419 *
5420 * Returns:
5421 * -EPERM operation not permitted
5422 **/
5423 static ssize_t
5424 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
5425 struct bin_attribute *bin_attr,
5426 char *buf, loff_t off, size_t count)
5427 {
5428 return -EPERM;
5429 }
5430
5431 static struct bin_attribute sysfs_mbox_attr = {
5432 .attr = {
5433 .name = "mbox",
5434 .mode = S_IRUSR | S_IWUSR,
5435 },
5436 .size = MAILBOX_SYSFS_MAX,
5437 .read = sysfs_mbox_read,
5438 .write = sysfs_mbox_write,
5439 };
5440
5441 /**
5442 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
5443 * @vport: address of lpfc vport structure.
5444 *
5445 * Return codes:
5446 * zero on success
5447 * error return code from sysfs_create_bin_file()
5448 **/
5449 int
5450 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
5451 {
5452 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5453 int error;
5454
5455 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5456 &sysfs_drvr_stat_data_attr);
5457
5458 /* Virtual ports do not need ctrl_reg and mbox */
5459 if (error || vport->port_type == LPFC_NPIV_PORT)
5460 goto out;
5461
5462 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5463 &sysfs_ctlreg_attr);
5464 if (error)
5465 goto out_remove_stat_attr;
5466
5467 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
5468 &sysfs_mbox_attr);
5469 if (error)
5470 goto out_remove_ctlreg_attr;
5471
5472 return 0;
5473 out_remove_ctlreg_attr:
5474 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5475 out_remove_stat_attr:
5476 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5477 &sysfs_drvr_stat_data_attr);
5478 out:
5479 return error;
5480 }
5481
5482 /**
5483 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
5484 * @vport: address of lpfc vport structure.
5485 **/
5486 void
5487 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
5488 {
5489 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5490 sysfs_remove_bin_file(&shost->shost_dev.kobj,
5491 &sysfs_drvr_stat_data_attr);
5492 /* Virtual ports do not need ctrl_reg and mbox */
5493 if (vport->port_type == LPFC_NPIV_PORT)
5494 return;
5495 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
5496 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
5497 }
5498
5499 /*
5500 * Dynamic FC Host Attributes Support
5501 */
5502
5503 /**
5504 * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host
5505 * @shost: kernel scsi host pointer.
5506 **/
5507 static void
5508 lpfc_get_host_symbolic_name(struct Scsi_Host *shost)
5509 {
5510 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
5511
5512 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
5513 sizeof fc_host_symbolic_name(shost));
5514 }
5515
5516 /**
5517 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
5518 * @shost: kernel scsi host pointer.
5519 **/
5520 static void
5521 lpfc_get_host_port_id(struct Scsi_Host *shost)
5522 {
5523 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5524
5525 /* note: fc_myDID already in cpu endianness */
5526 fc_host_port_id(shost) = vport->fc_myDID;
5527 }
5528
5529 /**
5530 * lpfc_get_host_port_type - Set the value of the scsi host port type
5531 * @shost: kernel scsi host pointer.
5532 **/
5533 static void
5534 lpfc_get_host_port_type(struct Scsi_Host *shost)
5535 {
5536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5537 struct lpfc_hba *phba = vport->phba;
5538
5539 spin_lock_irq(shost->host_lock);
5540
5541 if (vport->port_type == LPFC_NPIV_PORT) {
5542 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
5543 } else if (lpfc_is_link_up(phba)) {
5544 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5545 if (vport->fc_flag & FC_PUBLIC_LOOP)
5546 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
5547 else
5548 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
5549 } else {
5550 if (vport->fc_flag & FC_FABRIC)
5551 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
5552 else
5553 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
5554 }
5555 } else
5556 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
5557
5558 spin_unlock_irq(shost->host_lock);
5559 }
5560
5561 /**
5562 * lpfc_get_host_port_state - Set the value of the scsi host port state
5563 * @shost: kernel scsi host pointer.
5564 **/
5565 static void
5566 lpfc_get_host_port_state(struct Scsi_Host *shost)
5567 {
5568 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5569 struct lpfc_hba *phba = vport->phba;
5570
5571 spin_lock_irq(shost->host_lock);
5572
5573 if (vport->fc_flag & FC_OFFLINE_MODE)
5574 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
5575 else {
5576 switch (phba->link_state) {
5577 case LPFC_LINK_UNKNOWN:
5578 case LPFC_LINK_DOWN:
5579 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
5580 break;
5581 case LPFC_LINK_UP:
5582 case LPFC_CLEAR_LA:
5583 case LPFC_HBA_READY:
5584 /* Links up, reports port state accordingly */
5585 if (vport->port_state < LPFC_VPORT_READY)
5586 fc_host_port_state(shost) =
5587 FC_PORTSTATE_BYPASSED;
5588 else
5589 fc_host_port_state(shost) =
5590 FC_PORTSTATE_ONLINE;
5591 break;
5592 case LPFC_HBA_ERROR:
5593 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
5594 break;
5595 default:
5596 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
5597 break;
5598 }
5599 }
5600
5601 spin_unlock_irq(shost->host_lock);
5602 }
5603
5604 /**
5605 * lpfc_get_host_speed - Set the value of the scsi host speed
5606 * @shost: kernel scsi host pointer.
5607 **/
5608 static void
5609 lpfc_get_host_speed(struct Scsi_Host *shost)
5610 {
5611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5612 struct lpfc_hba *phba = vport->phba;
5613
5614 spin_lock_irq(shost->host_lock);
5615
5616 if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) {
5617 switch(phba->fc_linkspeed) {
5618 case LPFC_LINK_SPEED_1GHZ:
5619 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
5620 break;
5621 case LPFC_LINK_SPEED_2GHZ:
5622 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
5623 break;
5624 case LPFC_LINK_SPEED_4GHZ:
5625 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
5626 break;
5627 case LPFC_LINK_SPEED_8GHZ:
5628 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
5629 break;
5630 case LPFC_LINK_SPEED_10GHZ:
5631 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
5632 break;
5633 case LPFC_LINK_SPEED_16GHZ:
5634 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
5635 break;
5636 case LPFC_LINK_SPEED_32GHZ:
5637 fc_host_speed(shost) = FC_PORTSPEED_32GBIT;
5638 break;
5639 default:
5640 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5641 break;
5642 }
5643 } else
5644 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
5645
5646 spin_unlock_irq(shost->host_lock);
5647 }
5648
5649 /**
5650 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
5651 * @shost: kernel scsi host pointer.
5652 **/
5653 static void
5654 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
5655 {
5656 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5657 struct lpfc_hba *phba = vport->phba;
5658 u64 node_name;
5659
5660 spin_lock_irq(shost->host_lock);
5661
5662 if ((vport->port_state > LPFC_FLOGI) &&
5663 ((vport->fc_flag & FC_FABRIC) ||
5664 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
5665 (vport->fc_flag & FC_PUBLIC_LOOP))))
5666 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
5667 else
5668 /* fabric is local port if there is no F/FL_Port */
5669 node_name = 0;
5670
5671 spin_unlock_irq(shost->host_lock);
5672
5673 fc_host_fabric_name(shost) = node_name;
5674 }
5675
5676 /**
5677 * lpfc_get_stats - Return statistical information about the adapter
5678 * @shost: kernel scsi host pointer.
5679 *
5680 * Notes:
5681 * NULL on error for link down, no mbox pool, sli2 active,
5682 * management not allowed, memory allocation error, or mbox error.
5683 *
5684 * Returns:
5685 * NULL for error
5686 * address of the adapter host statistics
5687 **/
5688 static struct fc_host_statistics *
5689 lpfc_get_stats(struct Scsi_Host *shost)
5690 {
5691 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5692 struct lpfc_hba *phba = vport->phba;
5693 struct lpfc_sli *psli = &phba->sli;
5694 struct fc_host_statistics *hs = &phba->link_stats;
5695 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
5696 LPFC_MBOXQ_t *pmboxq;
5697 MAILBOX_t *pmb;
5698 unsigned long seconds;
5699 int rc = 0;
5700
5701 /*
5702 * prevent udev from issuing mailbox commands until the port is
5703 * configured.
5704 */
5705 if (phba->link_state < LPFC_LINK_DOWN ||
5706 !phba->mbox_mem_pool ||
5707 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
5708 return NULL;
5709
5710 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5711 return NULL;
5712
5713 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5714 if (!pmboxq)
5715 return NULL;
5716 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5717
5718 pmb = &pmboxq->u.mb;
5719 pmb->mbxCommand = MBX_READ_STATUS;
5720 pmb->mbxOwner = OWN_HOST;
5721 pmboxq->context1 = NULL;
5722 pmboxq->vport = vport;
5723
5724 if (vport->fc_flag & FC_OFFLINE_MODE)
5725 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5726 else
5727 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5728
5729 if (rc != MBX_SUCCESS) {
5730 if (rc != MBX_TIMEOUT)
5731 mempool_free(pmboxq, phba->mbox_mem_pool);
5732 return NULL;
5733 }
5734
5735 memset(hs, 0, sizeof (struct fc_host_statistics));
5736
5737 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
5738 /*
5739 * The MBX_READ_STATUS returns tx_k_bytes which has to
5740 * converted to words
5741 */
5742 hs->tx_words = (uint64_t)
5743 ((uint64_t)pmb->un.varRdStatus.xmitByteCnt
5744 * (uint64_t)256);
5745 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
5746 hs->rx_words = (uint64_t)
5747 ((uint64_t)pmb->un.varRdStatus.rcvByteCnt
5748 * (uint64_t)256);
5749
5750 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
5751 pmb->mbxCommand = MBX_READ_LNK_STAT;
5752 pmb->mbxOwner = OWN_HOST;
5753 pmboxq->context1 = NULL;
5754 pmboxq->vport = vport;
5755
5756 if (vport->fc_flag & FC_OFFLINE_MODE)
5757 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5758 else
5759 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5760
5761 if (rc != MBX_SUCCESS) {
5762 if (rc != MBX_TIMEOUT)
5763 mempool_free(pmboxq, phba->mbox_mem_pool);
5764 return NULL;
5765 }
5766
5767 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5768 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5769 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5770 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5771 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5772 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5773 hs->error_frames = pmb->un.varRdLnk.crcCnt;
5774
5775 hs->link_failure_count -= lso->link_failure_count;
5776 hs->loss_of_sync_count -= lso->loss_of_sync_count;
5777 hs->loss_of_signal_count -= lso->loss_of_signal_count;
5778 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
5779 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
5780 hs->invalid_crc_count -= lso->invalid_crc_count;
5781 hs->error_frames -= lso->error_frames;
5782
5783 if (phba->hba_flag & HBA_FCOE_MODE) {
5784 hs->lip_count = -1;
5785 hs->nos_count = (phba->link_events >> 1);
5786 hs->nos_count -= lso->link_events;
5787 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
5788 hs->lip_count = (phba->fc_eventTag >> 1);
5789 hs->lip_count -= lso->link_events;
5790 hs->nos_count = -1;
5791 } else {
5792 hs->lip_count = -1;
5793 hs->nos_count = (phba->fc_eventTag >> 1);
5794 hs->nos_count -= lso->link_events;
5795 }
5796
5797 hs->dumped_frames = -1;
5798
5799 seconds = get_seconds();
5800 if (seconds < psli->stats_start)
5801 hs->seconds_since_last_reset = seconds +
5802 ((unsigned long)-1 - psli->stats_start);
5803 else
5804 hs->seconds_since_last_reset = seconds - psli->stats_start;
5805
5806 mempool_free(pmboxq, phba->mbox_mem_pool);
5807
5808 return hs;
5809 }
5810
5811 /**
5812 * lpfc_reset_stats - Copy the adapter link stats information
5813 * @shost: kernel scsi host pointer.
5814 **/
5815 static void
5816 lpfc_reset_stats(struct Scsi_Host *shost)
5817 {
5818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5819 struct lpfc_hba *phba = vport->phba;
5820 struct lpfc_sli *psli = &phba->sli;
5821 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
5822 LPFC_MBOXQ_t *pmboxq;
5823 MAILBOX_t *pmb;
5824 int rc = 0;
5825
5826 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
5827 return;
5828
5829 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5830 if (!pmboxq)
5831 return;
5832 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5833
5834 pmb = &pmboxq->u.mb;
5835 pmb->mbxCommand = MBX_READ_STATUS;
5836 pmb->mbxOwner = OWN_HOST;
5837 pmb->un.varWords[0] = 0x1; /* reset request */
5838 pmboxq->context1 = NULL;
5839 pmboxq->vport = vport;
5840
5841 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5842 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5843 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5844 else
5845 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5846
5847 if (rc != MBX_SUCCESS) {
5848 if (rc != MBX_TIMEOUT)
5849 mempool_free(pmboxq, phba->mbox_mem_pool);
5850 return;
5851 }
5852
5853 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
5854 pmb->mbxCommand = MBX_READ_LNK_STAT;
5855 pmb->mbxOwner = OWN_HOST;
5856 pmboxq->context1 = NULL;
5857 pmboxq->vport = vport;
5858
5859 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
5860 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
5861 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
5862 else
5863 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
5864
5865 if (rc != MBX_SUCCESS) {
5866 if (rc != MBX_TIMEOUT)
5867 mempool_free( pmboxq, phba->mbox_mem_pool);
5868 return;
5869 }
5870
5871 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
5872 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
5873 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
5874 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
5875 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
5876 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
5877 lso->error_frames = pmb->un.varRdLnk.crcCnt;
5878 if (phba->hba_flag & HBA_FCOE_MODE)
5879 lso->link_events = (phba->link_events >> 1);
5880 else
5881 lso->link_events = (phba->fc_eventTag >> 1);
5882
5883 psli->stats_start = get_seconds();
5884
5885 mempool_free(pmboxq, phba->mbox_mem_pool);
5886
5887 return;
5888 }
5889
5890 /*
5891 * The LPFC driver treats linkdown handling as target loss events so there
5892 * are no sysfs handlers for link_down_tmo.
5893 */
5894
5895 /**
5896 * lpfc_get_node_by_target - Return the nodelist for a target
5897 * @starget: kernel scsi target pointer.
5898 *
5899 * Returns:
5900 * address of the node list if found
5901 * NULL target not found
5902 **/
5903 static struct lpfc_nodelist *
5904 lpfc_get_node_by_target(struct scsi_target *starget)
5905 {
5906 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
5907 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
5908 struct lpfc_nodelist *ndlp;
5909
5910 spin_lock_irq(shost->host_lock);
5911 /* Search for this, mapped, target ID */
5912 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5913 if (NLP_CHK_NODE_ACT(ndlp) &&
5914 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
5915 starget->id == ndlp->nlp_sid) {
5916 spin_unlock_irq(shost->host_lock);
5917 return ndlp;
5918 }
5919 }
5920 spin_unlock_irq(shost->host_lock);
5921 return NULL;
5922 }
5923
5924 /**
5925 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
5926 * @starget: kernel scsi target pointer.
5927 **/
5928 static void
5929 lpfc_get_starget_port_id(struct scsi_target *starget)
5930 {
5931 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5932
5933 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
5934 }
5935
5936 /**
5937 * lpfc_get_starget_node_name - Set the target node name
5938 * @starget: kernel scsi target pointer.
5939 *
5940 * Description: Set the target node name to the ndlp node name wwn or zero.
5941 **/
5942 static void
5943 lpfc_get_starget_node_name(struct scsi_target *starget)
5944 {
5945 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5946
5947 fc_starget_node_name(starget) =
5948 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
5949 }
5950
5951 /**
5952 * lpfc_get_starget_port_name - Set the target port name
5953 * @starget: kernel scsi target pointer.
5954 *
5955 * Description: set the target port name to the ndlp port name wwn or zero.
5956 **/
5957 static void
5958 lpfc_get_starget_port_name(struct scsi_target *starget)
5959 {
5960 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
5961
5962 fc_starget_port_name(starget) =
5963 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
5964 }
5965
5966 /**
5967 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
5968 * @rport: fc rport address.
5969 * @timeout: new value for dev loss tmo.
5970 *
5971 * Description:
5972 * If timeout is non zero set the dev_loss_tmo to timeout, else set
5973 * dev_loss_tmo to one.
5974 **/
5975 static void
5976 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
5977 {
5978 if (timeout)
5979 rport->dev_loss_tmo = timeout;
5980 else
5981 rport->dev_loss_tmo = 1;
5982 }
5983
5984 /**
5985 * lpfc_rport_show_function - Return rport target information
5986 *
5987 * Description:
5988 * Macro that uses field to generate a function with the name lpfc_show_rport_
5989 *
5990 * lpfc_show_rport_##field: returns the bytes formatted in buf
5991 * @cdev: class converted to an fc_rport.
5992 * @buf: on return contains the target_field or zero.
5993 *
5994 * Returns: size of formatted string.
5995 **/
5996 #define lpfc_rport_show_function(field, format_string, sz, cast) \
5997 static ssize_t \
5998 lpfc_show_rport_##field (struct device *dev, \
5999 struct device_attribute *attr, \
6000 char *buf) \
6001 { \
6002 struct fc_rport *rport = transport_class_to_rport(dev); \
6003 struct lpfc_rport_data *rdata = rport->hostdata; \
6004 return snprintf(buf, sz, format_string, \
6005 (rdata->target) ? cast rdata->target->field : 0); \
6006 }
6007
6008 #define lpfc_rport_rd_attr(field, format_string, sz) \
6009 lpfc_rport_show_function(field, format_string, sz, ) \
6010 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
6011
6012 /**
6013 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
6014 * @fc_vport: The fc_vport who's symbolic name has been changed.
6015 *
6016 * Description:
6017 * This function is called by the transport after the @fc_vport's symbolic name
6018 * has been changed. This function re-registers the symbolic name with the
6019 * switch to propagate the change into the fabric if the vport is active.
6020 **/
6021 static void
6022 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
6023 {
6024 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
6025
6026 if (vport->port_state == LPFC_VPORT_READY)
6027 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
6028 }
6029
6030 /**
6031 * lpfc_hba_log_verbose_init - Set hba's log verbose level
6032 * @phba: Pointer to lpfc_hba struct.
6033 *
6034 * This function is called by the lpfc_get_cfgparam() routine to set the
6035 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
6036 * log message according to the module's lpfc_log_verbose parameter setting
6037 * before hba port or vport created.
6038 **/
6039 static void
6040 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
6041 {
6042 phba->cfg_log_verbose = verbose;
6043 }
6044
6045 struct fc_function_template lpfc_transport_functions = {
6046 /* fixed attributes the driver supports */
6047 .show_host_node_name = 1,
6048 .show_host_port_name = 1,
6049 .show_host_supported_classes = 1,
6050 .show_host_supported_fc4s = 1,
6051 .show_host_supported_speeds = 1,
6052 .show_host_maxframe_size = 1,
6053
6054 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6055 .show_host_symbolic_name = 1,
6056
6057 /* dynamic attributes the driver supports */
6058 .get_host_port_id = lpfc_get_host_port_id,
6059 .show_host_port_id = 1,
6060
6061 .get_host_port_type = lpfc_get_host_port_type,
6062 .show_host_port_type = 1,
6063
6064 .get_host_port_state = lpfc_get_host_port_state,
6065 .show_host_port_state = 1,
6066
6067 /* active_fc4s is shown but doesn't change (thus no get function) */
6068 .show_host_active_fc4s = 1,
6069
6070 .get_host_speed = lpfc_get_host_speed,
6071 .show_host_speed = 1,
6072
6073 .get_host_fabric_name = lpfc_get_host_fabric_name,
6074 .show_host_fabric_name = 1,
6075
6076 /*
6077 * The LPFC driver treats linkdown handling as target loss events
6078 * so there are no sysfs handlers for link_down_tmo.
6079 */
6080
6081 .get_fc_host_stats = lpfc_get_stats,
6082 .reset_fc_host_stats = lpfc_reset_stats,
6083
6084 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6085 .show_rport_maxframe_size = 1,
6086 .show_rport_supported_classes = 1,
6087
6088 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6089 .show_rport_dev_loss_tmo = 1,
6090
6091 .get_starget_port_id = lpfc_get_starget_port_id,
6092 .show_starget_port_id = 1,
6093
6094 .get_starget_node_name = lpfc_get_starget_node_name,
6095 .show_starget_node_name = 1,
6096
6097 .get_starget_port_name = lpfc_get_starget_port_name,
6098 .show_starget_port_name = 1,
6099
6100 .issue_fc_host_lip = lpfc_issue_lip,
6101 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6102 .terminate_rport_io = lpfc_terminate_rport_io,
6103
6104 .dd_fcvport_size = sizeof(struct lpfc_vport *),
6105
6106 .vport_disable = lpfc_vport_disable,
6107
6108 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6109
6110 .bsg_request = lpfc_bsg_request,
6111 .bsg_timeout = lpfc_bsg_timeout,
6112 };
6113
6114 struct fc_function_template lpfc_vport_transport_functions = {
6115 /* fixed attributes the driver supports */
6116 .show_host_node_name = 1,
6117 .show_host_port_name = 1,
6118 .show_host_supported_classes = 1,
6119 .show_host_supported_fc4s = 1,
6120 .show_host_supported_speeds = 1,
6121 .show_host_maxframe_size = 1,
6122
6123 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
6124 .show_host_symbolic_name = 1,
6125
6126 /* dynamic attributes the driver supports */
6127 .get_host_port_id = lpfc_get_host_port_id,
6128 .show_host_port_id = 1,
6129
6130 .get_host_port_type = lpfc_get_host_port_type,
6131 .show_host_port_type = 1,
6132
6133 .get_host_port_state = lpfc_get_host_port_state,
6134 .show_host_port_state = 1,
6135
6136 /* active_fc4s is shown but doesn't change (thus no get function) */
6137 .show_host_active_fc4s = 1,
6138
6139 .get_host_speed = lpfc_get_host_speed,
6140 .show_host_speed = 1,
6141
6142 .get_host_fabric_name = lpfc_get_host_fabric_name,
6143 .show_host_fabric_name = 1,
6144
6145 /*
6146 * The LPFC driver treats linkdown handling as target loss events
6147 * so there are no sysfs handlers for link_down_tmo.
6148 */
6149
6150 .get_fc_host_stats = lpfc_get_stats,
6151 .reset_fc_host_stats = lpfc_reset_stats,
6152
6153 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
6154 .show_rport_maxframe_size = 1,
6155 .show_rport_supported_classes = 1,
6156
6157 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
6158 .show_rport_dev_loss_tmo = 1,
6159
6160 .get_starget_port_id = lpfc_get_starget_port_id,
6161 .show_starget_port_id = 1,
6162
6163 .get_starget_node_name = lpfc_get_starget_node_name,
6164 .show_starget_node_name = 1,
6165
6166 .get_starget_port_name = lpfc_get_starget_port_name,
6167 .show_starget_port_name = 1,
6168
6169 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
6170 .terminate_rport_io = lpfc_terminate_rport_io,
6171
6172 .vport_disable = lpfc_vport_disable,
6173
6174 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
6175 };
6176
6177 /**
6178 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
6179 * @phba: lpfc_hba pointer.
6180 **/
6181 void
6182 lpfc_get_cfgparam(struct lpfc_hba *phba)
6183 {
6184 lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched);
6185 lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset);
6186 lpfc_cr_delay_init(phba, lpfc_cr_delay);
6187 lpfc_cr_count_init(phba, lpfc_cr_count);
6188 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
6189 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
6190 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
6191 lpfc_ack0_init(phba, lpfc_ack0);
6192 lpfc_topology_init(phba, lpfc_topology);
6193 lpfc_link_speed_init(phba, lpfc_link_speed);
6194 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
6195 lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo);
6196 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
6197 lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy);
6198 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
6199 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
6200 lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN);
6201 lpfc_use_msi_init(phba, lpfc_use_msi);
6202 lpfc_nvme_oas_init(phba, lpfc_nvme_oas);
6203 lpfc_auto_imax_init(phba, lpfc_auto_imax);
6204 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
6205 lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map);
6206 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
6207 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
6208
6209 lpfc_EnableXLane_init(phba, lpfc_EnableXLane);
6210 if (phba->sli_rev != LPFC_SLI_REV4)
6211 phba->cfg_EnableXLane = 0;
6212 lpfc_XLanePriority_init(phba, lpfc_XLanePriority);
6213
6214 memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t)));
6215 memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t)));
6216 phba->cfg_oas_lun_state = 0;
6217 phba->cfg_oas_lun_status = 0;
6218 phba->cfg_oas_flags = 0;
6219 phba->cfg_oas_priority = 0;
6220 lpfc_enable_bg_init(phba, lpfc_enable_bg);
6221 lpfc_prot_mask_init(phba, lpfc_prot_mask);
6222 lpfc_prot_guard_init(phba, lpfc_prot_guard);
6223 if (phba->sli_rev == LPFC_SLI_REV4)
6224 phba->cfg_poll = 0;
6225 else
6226 phba->cfg_poll = lpfc_poll;
6227 lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp);
6228
6229 lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type);
6230 lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq);
6231
6232 /* Initialize first burst. Target vs Initiator are different. */
6233 lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb);
6234 lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size);
6235 lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel);
6236 lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel);
6237
6238 if (phba->sli_rev != LPFC_SLI_REV4) {
6239 /* NVME only supported on SLI4 */
6240 phba->nvmet_support = 0;
6241 phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP;
6242 } else {
6243 /* We MUST have FCP support */
6244 if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP))
6245 phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP;
6246 }
6247
6248 if (phba->cfg_auto_imax && !phba->cfg_fcp_imax)
6249 phba->cfg_auto_imax = 0;
6250 phba->initial_imax = phba->cfg_fcp_imax;
6251
6252 /* A value of 0 means use the number of CPUs found in the system */
6253 if (phba->cfg_fcp_io_channel == 0)
6254 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6255 if (phba->cfg_nvme_io_channel == 0)
6256 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6257
6258 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
6259 phba->cfg_fcp_io_channel = 0;
6260
6261 if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP)
6262 phba->cfg_nvme_io_channel = 0;
6263
6264 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6265 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6266 else
6267 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6268
6269 phba->cfg_soft_wwnn = 0L;
6270 phba->cfg_soft_wwpn = 0L;
6271 lpfc_xri_split_init(phba, lpfc_xri_split);
6272 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
6273 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
6274 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
6275 lpfc_aer_support_init(phba, lpfc_aer_support);
6276 lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn);
6277 lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade);
6278 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
6279 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
6280 lpfc_delay_discovery_init(phba, lpfc_delay_discovery);
6281 lpfc_sli_mode_init(phba, lpfc_sli_mode);
6282 phba->cfg_enable_dss = 1;
6283 lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags);
6284 return;
6285 }
6286
6287 /**
6288 * lpfc_nvme_mod_param_dep - Adjust module parameter value based on
6289 * dependencies between protocols and roles.
6290 * @phba: lpfc_hba pointer.
6291 **/
6292 void
6293 lpfc_nvme_mod_param_dep(struct lpfc_hba *phba)
6294 {
6295 if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu)
6296 phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu;
6297
6298 if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu)
6299 phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu;
6300
6301 if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME &&
6302 phba->nvmet_support) {
6303 phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP;
6304 phba->cfg_fcp_io_channel = 0;
6305
6306 lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC,
6307 "6013 %s x%x fb_size x%x, fb_max x%x\n",
6308 "NVME Target PRLI ACC enable_fb ",
6309 phba->cfg_nvme_enable_fb,
6310 phba->cfg_nvmet_fb_size,
6311 LPFC_NVMET_FB_SZ_MAX);
6312
6313 if (phba->cfg_nvme_enable_fb == 0)
6314 phba->cfg_nvmet_fb_size = 0;
6315 else {
6316 if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX)
6317 phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX;
6318 }
6319
6320 /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */
6321 if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) {
6322 phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel;
6323 lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
6324 "6018 Adjust lpfc_nvmet_mrq to %d\n",
6325 phba->cfg_nvmet_mrq);
6326 }
6327 } else {
6328 /* Not NVME Target mode. Turn off Target parameters. */
6329 phba->nvmet_support = 0;
6330 phba->cfg_nvmet_mrq = 0;
6331 phba->cfg_nvmet_fb_size = 0;
6332 }
6333
6334 if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel)
6335 phba->io_channel_irqs = phba->cfg_fcp_io_channel;
6336 else
6337 phba->io_channel_irqs = phba->cfg_nvme_io_channel;
6338 }
6339
6340 /**
6341 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
6342 * @vport: lpfc_vport pointer.
6343 **/
6344 void
6345 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
6346 {
6347 lpfc_log_verbose_init(vport, lpfc_log_verbose);
6348 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
6349 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
6350 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
6351 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
6352 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
6353 lpfc_restrict_login_init(vport, lpfc_restrict_login);
6354 lpfc_fcp_class_init(vport, lpfc_fcp_class);
6355 lpfc_use_adisc_init(vport, lpfc_use_adisc);
6356 lpfc_first_burst_size_init(vport, lpfc_first_burst_size);
6357 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
6358 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
6359 lpfc_max_luns_init(vport, lpfc_max_luns);
6360 lpfc_scan_down_init(vport, lpfc_scan_down);
6361 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
6362 return;
6363 }