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