[SCSI] lpfc 8.3.22: T10-DIF corrections
[deliverable/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) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
8 * *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21
22 #include <linux/ctype.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
26 #include <linux/aer.h>
27 #include <linux/gfp.h>
28 #include <linux/kernel.h>
29
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsi_transport_fc.h>
35 #include <scsi/fc/fc_fs.h>
36
37 #include "lpfc_hw4.h"
38 #include "lpfc_hw.h"
39 #include "lpfc_sli.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_nl.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_version.h"
47 #include "lpfc_compat.h"
48 #include "lpfc_crtn.h"
49 #include "lpfc_vport.h"
50
51 #define LPFC_DEF_DEVLOSS_TMO 30
52 #define LPFC_MIN_DEVLOSS_TMO 1
53 #define LPFC_MAX_DEVLOSS_TMO 255
54
55 /**
56 * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules
57 * @incr: integer to convert.
58 * @hdw: ascii string holding converted integer plus a string terminator.
59 *
60 * Description:
61 * JEDEC Joint Electron Device Engineering Council.
62 * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii
63 * character string. The string is then terminated with a NULL in byte 9.
64 * Hex 0-9 becomes ascii '0' to '9'.
65 * Hex a-f becomes ascii '=' to 'B' capital B.
66 *
67 * Notes:
68 * Coded for 32 bit integers only.
69 **/
70 static void
71 lpfc_jedec_to_ascii(int incr, char hdw[])
72 {
73 int i, j;
74 for (i = 0; i < 8; i++) {
75 j = (incr & 0xf);
76 if (j <= 9)
77 hdw[7 - i] = 0x30 + j;
78 else
79 hdw[7 - i] = 0x61 + j - 10;
80 incr = (incr >> 4);
81 }
82 hdw[8] = 0;
83 return;
84 }
85
86 /**
87 * lpfc_drvr_version_show - Return the Emulex driver string with version number
88 * @dev: class unused variable.
89 * @attr: device attribute, not used.
90 * @buf: on return contains the module description text.
91 *
92 * Returns: size of formatted string.
93 **/
94 static ssize_t
95 lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
96 char *buf)
97 {
98 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
99 }
100
101 /**
102 * lpfc_enable_fip_show - Return the fip mode of the HBA
103 * @dev: class unused variable.
104 * @attr: device attribute, not used.
105 * @buf: on return contains the module description text.
106 *
107 * Returns: size of formatted string.
108 **/
109 static ssize_t
110 lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr,
111 char *buf)
112 {
113 struct Scsi_Host *shost = class_to_shost(dev);
114 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
115 struct lpfc_hba *phba = vport->phba;
116
117 if (phba->hba_flag & HBA_FIP_SUPPORT)
118 return snprintf(buf, PAGE_SIZE, "1\n");
119 else
120 return snprintf(buf, PAGE_SIZE, "0\n");
121 }
122
123 static ssize_t
124 lpfc_bg_info_show(struct device *dev, struct device_attribute *attr,
125 char *buf)
126 {
127 struct Scsi_Host *shost = class_to_shost(dev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
131 if (phba->cfg_enable_bg)
132 if (phba->sli3_options & LPFC_SLI3_BG_ENABLED)
133 return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n");
134 else
135 return snprintf(buf, PAGE_SIZE,
136 "BlockGuard Not Supported\n");
137 else
138 return snprintf(buf, PAGE_SIZE,
139 "BlockGuard Disabled\n");
140 }
141
142 static ssize_t
143 lpfc_bg_guard_err_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 = (struct lpfc_vport *) shost->hostdata;
148 struct lpfc_hba *phba = vport->phba;
149
150 return snprintf(buf, PAGE_SIZE, "%llu\n",
151 (unsigned long long)phba->bg_guard_err_cnt);
152 }
153
154 static ssize_t
155 lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr,
156 char *buf)
157 {
158 struct Scsi_Host *shost = class_to_shost(dev);
159 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
160 struct lpfc_hba *phba = vport->phba;
161
162 return snprintf(buf, PAGE_SIZE, "%llu\n",
163 (unsigned long long)phba->bg_apptag_err_cnt);
164 }
165
166 static ssize_t
167 lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr,
168 char *buf)
169 {
170 struct Scsi_Host *shost = class_to_shost(dev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173
174 return snprintf(buf, PAGE_SIZE, "%llu\n",
175 (unsigned long long)phba->bg_reftag_err_cnt);
176 }
177
178 /**
179 * lpfc_info_show - Return some pci info about the host in ascii
180 * @dev: class converted to a Scsi_host structure.
181 * @attr: device attribute, not used.
182 * @buf: on return contains the formatted text from lpfc_info().
183 *
184 * Returns: size of formatted string.
185 **/
186 static ssize_t
187 lpfc_info_show(struct device *dev, struct device_attribute *attr,
188 char *buf)
189 {
190 struct Scsi_Host *host = class_to_shost(dev);
191
192 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
193 }
194
195 /**
196 * lpfc_serialnum_show - Return the hba serial number in ascii
197 * @dev: class converted to a Scsi_host structure.
198 * @attr: device attribute, not used.
199 * @buf: on return contains the formatted text serial number.
200 *
201 * Returns: size of formatted string.
202 **/
203 static ssize_t
204 lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
205 char *buf)
206 {
207 struct Scsi_Host *shost = class_to_shost(dev);
208 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
209 struct lpfc_hba *phba = vport->phba;
210
211 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
212 }
213
214 /**
215 * lpfc_temp_sensor_show - Return the temperature sensor level
216 * @dev: class converted to a Scsi_host structure.
217 * @attr: device attribute, not used.
218 * @buf: on return contains the formatted support level.
219 *
220 * Description:
221 * Returns a number indicating the temperature sensor level currently
222 * supported, zero or one in ascii.
223 *
224 * Returns: size of formatted string.
225 **/
226 static ssize_t
227 lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
228 char *buf)
229 {
230 struct Scsi_Host *shost = class_to_shost(dev);
231 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
232 struct lpfc_hba *phba = vport->phba;
233 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
234 }
235
236 /**
237 * lpfc_modeldesc_show - Return the model description of the hba
238 * @dev: class converted to a Scsi_host structure.
239 * @attr: device attribute, not used.
240 * @buf: on return contains the scsi vpd model description.
241 *
242 * Returns: size of formatted string.
243 **/
244 static ssize_t
245 lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
246 char *buf)
247 {
248 struct Scsi_Host *shost = class_to_shost(dev);
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
251
252 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
253 }
254
255 /**
256 * lpfc_modelname_show - Return the model name of the hba
257 * @dev: class converted to a Scsi_host structure.
258 * @attr: device attribute, not used.
259 * @buf: on return contains the scsi vpd model name.
260 *
261 * Returns: size of formatted string.
262 **/
263 static ssize_t
264 lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
265 char *buf)
266 {
267 struct Scsi_Host *shost = class_to_shost(dev);
268 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
269 struct lpfc_hba *phba = vport->phba;
270
271 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
272 }
273
274 /**
275 * lpfc_programtype_show - Return the program type of the hba
276 * @dev: class converted to a Scsi_host structure.
277 * @attr: device attribute, not used.
278 * @buf: on return contains the scsi vpd program type.
279 *
280 * Returns: size of formatted string.
281 **/
282 static ssize_t
283 lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
284 char *buf)
285 {
286 struct Scsi_Host *shost = class_to_shost(dev);
287 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
288 struct lpfc_hba *phba = vport->phba;
289
290 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
291 }
292
293 /**
294 * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag
295 * @dev: class converted to a Scsi_host structure.
296 * @attr: device attribute, not used.
297 * @buf: on return contains the Menlo Maintenance sli flag.
298 *
299 * Returns: size of formatted string.
300 **/
301 static ssize_t
302 lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf)
303 {
304 struct Scsi_Host *shost = class_to_shost(dev);
305 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
306 struct lpfc_hba *phba = vport->phba;
307
308 return snprintf(buf, PAGE_SIZE, "%d\n",
309 (phba->sli.sli_flag & LPFC_MENLO_MAINT));
310 }
311
312 /**
313 * lpfc_vportnum_show - Return the port number in ascii of the hba
314 * @dev: class converted to a Scsi_host structure.
315 * @attr: device attribute, not used.
316 * @buf: on return contains scsi vpd program type.
317 *
318 * Returns: size of formatted string.
319 **/
320 static ssize_t
321 lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
322 char *buf)
323 {
324 struct Scsi_Host *shost = class_to_shost(dev);
325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
326 struct lpfc_hba *phba = vport->phba;
327
328 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
329 }
330
331 /**
332 * lpfc_fwrev_show - Return the firmware rev running in the hba
333 * @dev: class converted to a Scsi_host structure.
334 * @attr: device attribute, not used.
335 * @buf: on return contains the scsi vpd program type.
336 *
337 * Returns: size of formatted string.
338 **/
339 static ssize_t
340 lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
341 char *buf)
342 {
343 struct Scsi_Host *shost = class_to_shost(dev);
344 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
345 struct lpfc_hba *phba = vport->phba;
346 char fwrev[32];
347
348 lpfc_decode_firmware_rev(phba, fwrev, 1);
349 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
350 }
351
352 /**
353 * lpfc_hdw_show - Return the jedec information about the hba
354 * @dev: class converted to a Scsi_host structure.
355 * @attr: device attribute, not used.
356 * @buf: on return contains the scsi vpd program type.
357 *
358 * Returns: size of formatted string.
359 **/
360 static ssize_t
361 lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
362 {
363 char hdw[9];
364 struct Scsi_Host *shost = class_to_shost(dev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367 lpfc_vpd_t *vp = &phba->vpd;
368
369 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
370 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
371 }
372
373 /**
374 * lpfc_option_rom_version_show - Return the adapter ROM FCode version
375 * @dev: class converted to a Scsi_host structure.
376 * @attr: device attribute, not used.
377 * @buf: on return contains the ROM and FCode ascii strings.
378 *
379 * Returns: size of formatted string.
380 **/
381 static ssize_t
382 lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
383 char *buf)
384 {
385 struct Scsi_Host *shost = class_to_shost(dev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
389 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
390 }
391
392 /**
393 * lpfc_state_show - Return the link state of the port
394 * @dev: class converted to a Scsi_host structure.
395 * @attr: device attribute, not used.
396 * @buf: on return contains text describing the state of the link.
397 *
398 * Notes:
399 * The switch statement has no default so zero will be returned.
400 *
401 * Returns: size of formatted string.
402 **/
403 static ssize_t
404 lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
405 char *buf)
406 {
407 struct Scsi_Host *shost = class_to_shost(dev);
408 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
409 struct lpfc_hba *phba = vport->phba;
410 int len = 0;
411
412 switch (phba->link_state) {
413 case LPFC_LINK_UNKNOWN:
414 case LPFC_WARM_START:
415 case LPFC_INIT_START:
416 case LPFC_INIT_MBX_CMDS:
417 case LPFC_LINK_DOWN:
418 case LPFC_HBA_ERROR:
419 if (phba->hba_flag & LINK_DISABLED)
420 len += snprintf(buf + len, PAGE_SIZE-len,
421 "Link Down - User disabled\n");
422 else
423 len += snprintf(buf + len, PAGE_SIZE-len,
424 "Link Down\n");
425 break;
426 case LPFC_LINK_UP:
427 case LPFC_CLEAR_LA:
428 case LPFC_HBA_READY:
429 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
430
431 switch (vport->port_state) {
432 case LPFC_LOCAL_CFG_LINK:
433 len += snprintf(buf + len, PAGE_SIZE-len,
434 "Configuring Link\n");
435 break;
436 case LPFC_FDISC:
437 case LPFC_FLOGI:
438 case LPFC_FABRIC_CFG_LINK:
439 case LPFC_NS_REG:
440 case LPFC_NS_QRY:
441 case LPFC_BUILD_DISC_LIST:
442 case LPFC_DISC_AUTH:
443 len += snprintf(buf + len, PAGE_SIZE - len,
444 "Discovery\n");
445 break;
446 case LPFC_VPORT_READY:
447 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
448 break;
449
450 case LPFC_VPORT_FAILED:
451 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
452 break;
453
454 case LPFC_VPORT_UNKNOWN:
455 len += snprintf(buf + len, PAGE_SIZE - len,
456 "Unknown\n");
457 break;
458 }
459 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
460 len += snprintf(buf + len, PAGE_SIZE-len,
461 " Menlo Maint Mode\n");
462 else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
463 if (vport->fc_flag & FC_PUBLIC_LOOP)
464 len += snprintf(buf + len, PAGE_SIZE-len,
465 " Public Loop\n");
466 else
467 len += snprintf(buf + len, PAGE_SIZE-len,
468 " Private Loop\n");
469 } else {
470 if (vport->fc_flag & FC_FABRIC)
471 len += snprintf(buf + len, PAGE_SIZE-len,
472 " Fabric\n");
473 else
474 len += snprintf(buf + len, PAGE_SIZE-len,
475 " Point-2-Point\n");
476 }
477 }
478
479 return len;
480 }
481
482 /**
483 * lpfc_link_state_store - Transition the link_state on an HBA port
484 * @dev: class device that is converted into a Scsi_host.
485 * @attr: device attribute, not used.
486 * @buf: one or more lpfc_polling_flags values.
487 * @count: not used.
488 *
489 * Returns:
490 * -EINVAL if the buffer is not "up" or "down"
491 * return from link state change function if non-zero
492 * length of the buf on success
493 **/
494 static ssize_t
495 lpfc_link_state_store(struct device *dev, struct device_attribute *attr,
496 const char *buf, size_t count)
497 {
498 struct Scsi_Host *shost = class_to_shost(dev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501
502 int status = -EINVAL;
503
504 if ((strncmp(buf, "up", sizeof("up") - 1) == 0) &&
505 (phba->link_state == LPFC_LINK_DOWN))
506 status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
507 else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) &&
508 (phba->link_state >= LPFC_LINK_UP))
509 status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT);
510
511 if (status == 0)
512 return strlen(buf);
513 else
514 return status;
515 }
516
517 /**
518 * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports
519 * @dev: class device that is converted into a Scsi_host.
520 * @attr: device attribute, not used.
521 * @buf: on return contains the sum of fc mapped and unmapped.
522 *
523 * Description:
524 * Returns the ascii text number of the sum of the fc mapped and unmapped
525 * vport counts.
526 *
527 * Returns: size of formatted string.
528 **/
529 static ssize_t
530 lpfc_num_discovered_ports_show(struct device *dev,
531 struct device_attribute *attr, char *buf)
532 {
533 struct Scsi_Host *shost = class_to_shost(dev);
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535
536 return snprintf(buf, PAGE_SIZE, "%d\n",
537 vport->fc_map_cnt + vport->fc_unmap_cnt);
538 }
539
540 /**
541 * lpfc_issue_lip - Misnomer, name carried over from long ago
542 * @shost: Scsi_Host pointer.
543 *
544 * Description:
545 * Bring the link down gracefully then re-init the link. The firmware will
546 * re-init the fiber channel interface as required. Does not issue a LIP.
547 *
548 * Returns:
549 * -EPERM port offline or management commands are being blocked
550 * -ENOMEM cannot allocate memory for the mailbox command
551 * -EIO error sending the mailbox command
552 * zero for success
553 **/
554 static int
555 lpfc_issue_lip(struct Scsi_Host *shost)
556 {
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 LPFC_MBOXQ_t *pmboxq;
560 int mbxstatus = MBXERR_ERROR;
561
562 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
563 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
564 return -EPERM;
565
566 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
567
568 if (!pmboxq)
569 return -ENOMEM;
570
571 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
572 pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK;
573 pmboxq->u.mb.mbxOwner = OWN_HOST;
574
575 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
576
577 if ((mbxstatus == MBX_SUCCESS) &&
578 (pmboxq->u.mb.mbxStatus == 0 ||
579 pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) {
580 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
581 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
582 phba->cfg_link_speed);
583 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
584 phba->fc_ratov * 2);
585 if ((mbxstatus == MBX_SUCCESS) &&
586 (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
587 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
588 "2859 SLI authentication is required "
589 "for INIT_LINK but has not done yet\n");
590 }
591
592 lpfc_set_loopback_flag(phba);
593 if (mbxstatus != MBX_TIMEOUT)
594 mempool_free(pmboxq, phba->mbox_mem_pool);
595
596 if (mbxstatus == MBXERR_ERROR)
597 return -EIO;
598
599 return 0;
600 }
601
602 /**
603 * lpfc_do_offline - Issues a mailbox command to bring the link down
604 * @phba: lpfc_hba pointer.
605 * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL.
606 *
607 * Notes:
608 * Assumes any error from lpfc_do_offline() will be negative.
609 * Can wait up to 5 seconds for the port ring buffers count
610 * to reach zero, prints a warning if it is not zero and continues.
611 * lpfc_workq_post_event() returns a non-zero return code if call fails.
612 *
613 * Returns:
614 * -EIO error posting the event
615 * zero for success
616 **/
617 static int
618 lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
619 {
620 struct completion online_compl;
621 struct lpfc_sli_ring *pring;
622 struct lpfc_sli *psli;
623 int status = 0;
624 int cnt = 0;
625 int i;
626 int rc;
627
628 init_completion(&online_compl);
629 rc = lpfc_workq_post_event(phba, &status, &online_compl,
630 LPFC_EVT_OFFLINE_PREP);
631 if (rc == 0)
632 return -ENOMEM;
633
634 wait_for_completion(&online_compl);
635
636 if (status != 0)
637 return -EIO;
638
639 psli = &phba->sli;
640
641 /* Wait a little for things to settle down, but not
642 * long enough for dev loss timeout to expire.
643 */
644 for (i = 0; i < psli->num_rings; i++) {
645 pring = &psli->ring[i];
646 while (pring->txcmplq_cnt) {
647 msleep(10);
648 if (cnt++ > 500) { /* 5 secs */
649 lpfc_printf_log(phba,
650 KERN_WARNING, LOG_INIT,
651 "0466 Outstanding IO when "
652 "bringing Adapter offline\n");
653 break;
654 }
655 }
656 }
657
658 init_completion(&online_compl);
659 rc = lpfc_workq_post_event(phba, &status, &online_compl, type);
660 if (rc == 0)
661 return -ENOMEM;
662
663 wait_for_completion(&online_compl);
664
665 if (status != 0)
666 return -EIO;
667
668 return 0;
669 }
670
671 /**
672 * lpfc_selective_reset - Offline then onlines the port
673 * @phba: lpfc_hba pointer.
674 *
675 * Description:
676 * If the port is configured to allow a reset then the hba is brought
677 * offline then online.
678 *
679 * Notes:
680 * Assumes any error from lpfc_do_offline() will be negative.
681 * Do not make this function static.
682 *
683 * Returns:
684 * lpfc_do_offline() return code if not zero
685 * -EIO reset not configured or error posting the event
686 * zero for success
687 **/
688 int
689 lpfc_selective_reset(struct lpfc_hba *phba)
690 {
691 struct completion online_compl;
692 int status = 0;
693 int rc;
694
695 if (!phba->cfg_enable_hba_reset)
696 return -EIO;
697
698 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
699
700 if (status != 0)
701 return status;
702
703 init_completion(&online_compl);
704 rc = lpfc_workq_post_event(phba, &status, &online_compl,
705 LPFC_EVT_ONLINE);
706 if (rc == 0)
707 return -ENOMEM;
708
709 wait_for_completion(&online_compl);
710
711 if (status != 0)
712 return -EIO;
713
714 return 0;
715 }
716
717 /**
718 * lpfc_issue_reset - Selectively resets an adapter
719 * @dev: class device that is converted into a Scsi_host.
720 * @attr: device attribute, not used.
721 * @buf: containing the string "selective".
722 * @count: unused variable.
723 *
724 * Description:
725 * If the buf contains the string "selective" then lpfc_selective_reset()
726 * is called to perform the reset.
727 *
728 * Notes:
729 * Assumes any error from lpfc_selective_reset() will be negative.
730 * If lpfc_selective_reset() returns zero then the length of the buffer
731 * is returned which indicates success
732 *
733 * Returns:
734 * -EINVAL if the buffer does not contain the string "selective"
735 * length of buf if lpfc-selective_reset() if the call succeeds
736 * return value of lpfc_selective_reset() if the call fails
737 **/
738 static ssize_t
739 lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
740 const char *buf, size_t count)
741 {
742 struct Scsi_Host *shost = class_to_shost(dev);
743 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
744 struct lpfc_hba *phba = vport->phba;
745
746 int status = -EINVAL;
747
748 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
749 status = phba->lpfc_selective_reset(phba);
750
751 if (status == 0)
752 return strlen(buf);
753 else
754 return status;
755 }
756
757 /**
758 * lpfc_nport_evt_cnt_show - Return the number of nport events
759 * @dev: class device that is converted into a Scsi_host.
760 * @attr: device attribute, not used.
761 * @buf: on return contains the ascii number of nport events.
762 *
763 * Returns: size of formatted string.
764 **/
765 static ssize_t
766 lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
767 char *buf)
768 {
769 struct Scsi_Host *shost = class_to_shost(dev);
770 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
771 struct lpfc_hba *phba = vport->phba;
772
773 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
774 }
775
776 /**
777 * lpfc_board_mode_show - Return the state of the board
778 * @dev: class device that is converted into a Scsi_host.
779 * @attr: device attribute, not used.
780 * @buf: on return contains the state of the adapter.
781 *
782 * Returns: size of formatted string.
783 **/
784 static ssize_t
785 lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
786 char *buf)
787 {
788 struct Scsi_Host *shost = class_to_shost(dev);
789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
790 struct lpfc_hba *phba = vport->phba;
791 char * state;
792
793 if (phba->link_state == LPFC_HBA_ERROR)
794 state = "error";
795 else if (phba->link_state == LPFC_WARM_START)
796 state = "warm start";
797 else if (phba->link_state == LPFC_INIT_START)
798 state = "offline";
799 else
800 state = "online";
801
802 return snprintf(buf, PAGE_SIZE, "%s\n", state);
803 }
804
805 /**
806 * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state
807 * @dev: class device that is converted into a Scsi_host.
808 * @attr: device attribute, not used.
809 * @buf: containing one of the strings "online", "offline", "warm" or "error".
810 * @count: unused variable.
811 *
812 * Returns:
813 * -EACCES if enable hba reset not enabled
814 * -EINVAL if the buffer does not contain a valid string (see above)
815 * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails
816 * buf length greater than zero indicates success
817 **/
818 static ssize_t
819 lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
820 const char *buf, size_t count)
821 {
822 struct Scsi_Host *shost = class_to_shost(dev);
823 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
824 struct lpfc_hba *phba = vport->phba;
825 struct completion online_compl;
826 int status=0;
827 int rc;
828
829 if (!phba->cfg_enable_hba_reset)
830 return -EACCES;
831 init_completion(&online_compl);
832
833 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
834 rc = lpfc_workq_post_event(phba, &status, &online_compl,
835 LPFC_EVT_ONLINE);
836 if (rc == 0)
837 return -ENOMEM;
838 wait_for_completion(&online_compl);
839 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
840 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
841 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
842 if (phba->sli_rev == LPFC_SLI_REV4)
843 return -EINVAL;
844 else
845 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
846 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
847 if (phba->sli_rev == LPFC_SLI_REV4)
848 return -EINVAL;
849 else
850 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
851 else
852 return -EINVAL;
853
854 if (!status)
855 return strlen(buf);
856 else
857 return -EIO;
858 }
859
860 /**
861 * lpfc_get_hba_info - Return various bits of informaton about the adapter
862 * @phba: pointer to the adapter structure.
863 * @mxri: max xri count.
864 * @axri: available xri count.
865 * @mrpi: max rpi count.
866 * @arpi: available rpi count.
867 * @mvpi: max vpi count.
868 * @avpi: available vpi count.
869 *
870 * Description:
871 * If an integer pointer for an count is not null then the value for the
872 * count is returned.
873 *
874 * Returns:
875 * zero on error
876 * one for success
877 **/
878 static int
879 lpfc_get_hba_info(struct lpfc_hba *phba,
880 uint32_t *mxri, uint32_t *axri,
881 uint32_t *mrpi, uint32_t *arpi,
882 uint32_t *mvpi, uint32_t *avpi)
883 {
884 struct lpfc_mbx_read_config *rd_config;
885 LPFC_MBOXQ_t *pmboxq;
886 MAILBOX_t *pmb;
887 int rc = 0;
888 uint32_t max_vpi;
889
890 /*
891 * prevent udev from issuing mailbox commands until the port is
892 * configured.
893 */
894 if (phba->link_state < LPFC_LINK_DOWN ||
895 !phba->mbox_mem_pool ||
896 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
897 return 0;
898
899 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
900 return 0;
901
902 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
903 if (!pmboxq)
904 return 0;
905 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
906
907 pmb = &pmboxq->u.mb;
908 pmb->mbxCommand = MBX_READ_CONFIG;
909 pmb->mbxOwner = OWN_HOST;
910 pmboxq->context1 = NULL;
911
912 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
913 rc = MBX_NOT_FINISHED;
914 else
915 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
916
917 if (rc != MBX_SUCCESS) {
918 if (rc != MBX_TIMEOUT)
919 mempool_free(pmboxq, phba->mbox_mem_pool);
920 return 0;
921 }
922
923 if (phba->sli_rev == LPFC_SLI_REV4) {
924 rd_config = &pmboxq->u.mqe.un.rd_config;
925 if (mrpi)
926 *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
927 if (arpi)
928 *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) -
929 phba->sli4_hba.max_cfg_param.rpi_used;
930 if (mxri)
931 *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
932 if (axri)
933 *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) -
934 phba->sli4_hba.max_cfg_param.xri_used;
935
936 /* Account for differences with SLI-3. Get vpi count from
937 * mailbox data and subtract one for max vpi value.
938 */
939 max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ?
940 (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0;
941
942 if (mvpi)
943 *mvpi = max_vpi;
944 if (avpi)
945 *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used;
946 } else {
947 if (mrpi)
948 *mrpi = pmb->un.varRdConfig.max_rpi;
949 if (arpi)
950 *arpi = pmb->un.varRdConfig.avail_rpi;
951 if (mxri)
952 *mxri = pmb->un.varRdConfig.max_xri;
953 if (axri)
954 *axri = pmb->un.varRdConfig.avail_xri;
955 if (mvpi)
956 *mvpi = pmb->un.varRdConfig.max_vpi;
957 if (avpi)
958 *avpi = pmb->un.varRdConfig.avail_vpi;
959 }
960
961 mempool_free(pmboxq, phba->mbox_mem_pool);
962 return 1;
963 }
964
965 /**
966 * lpfc_max_rpi_show - Return maximum rpi
967 * @dev: class device that is converted into a Scsi_host.
968 * @attr: device attribute, not used.
969 * @buf: on return contains the maximum rpi count in decimal or "Unknown".
970 *
971 * Description:
972 * Calls lpfc_get_hba_info() asking for just the mrpi count.
973 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
974 * to "Unknown" and the buffer length is returned, therefore the caller
975 * must check for "Unknown" in the buffer to detect a failure.
976 *
977 * Returns: size of formatted string.
978 **/
979 static ssize_t
980 lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
981 char *buf)
982 {
983 struct Scsi_Host *shost = class_to_shost(dev);
984 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
985 struct lpfc_hba *phba = vport->phba;
986 uint32_t cnt;
987
988 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
989 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
990 return snprintf(buf, PAGE_SIZE, "Unknown\n");
991 }
992
993 /**
994 * lpfc_used_rpi_show - Return maximum rpi minus available rpi
995 * @dev: class device that is converted into a Scsi_host.
996 * @attr: device attribute, not used.
997 * @buf: containing the used rpi count in decimal or "Unknown".
998 *
999 * Description:
1000 * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts.
1001 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1002 * to "Unknown" and the buffer length is returned, therefore the caller
1003 * must check for "Unknown" in the buffer to detect a failure.
1004 *
1005 * Returns: size of formatted string.
1006 **/
1007 static ssize_t
1008 lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
1009 char *buf)
1010 {
1011 struct Scsi_Host *shost = class_to_shost(dev);
1012 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1013 struct lpfc_hba *phba = vport->phba;
1014 uint32_t cnt, acnt;
1015
1016 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
1017 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1018 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1019 }
1020
1021 /**
1022 * lpfc_max_xri_show - Return maximum xri
1023 * @dev: class device that is converted into a Scsi_host.
1024 * @attr: device attribute, not used.
1025 * @buf: on return contains the maximum xri count in decimal or "Unknown".
1026 *
1027 * Description:
1028 * Calls lpfc_get_hba_info() asking for just the mrpi count.
1029 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1030 * to "Unknown" and the buffer length is returned, therefore the caller
1031 * must check for "Unknown" in the buffer to detect a failure.
1032 *
1033 * Returns: size of formatted string.
1034 **/
1035 static ssize_t
1036 lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
1037 char *buf)
1038 {
1039 struct Scsi_Host *shost = class_to_shost(dev);
1040 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1041 struct lpfc_hba *phba = vport->phba;
1042 uint32_t cnt;
1043
1044 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
1045 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1046 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1047 }
1048
1049 /**
1050 * lpfc_used_xri_show - Return maximum xpi minus the available xpi
1051 * @dev: class device that is converted into a Scsi_host.
1052 * @attr: device attribute, not used.
1053 * @buf: on return contains the used xri count in decimal or "Unknown".
1054 *
1055 * Description:
1056 * Calls lpfc_get_hba_info() asking for just the mxri and axri counts.
1057 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1058 * to "Unknown" and the buffer length is returned, therefore the caller
1059 * must check for "Unknown" in the buffer to detect a failure.
1060 *
1061 * Returns: size of formatted string.
1062 **/
1063 static ssize_t
1064 lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
1065 char *buf)
1066 {
1067 struct Scsi_Host *shost = class_to_shost(dev);
1068 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1069 struct lpfc_hba *phba = vport->phba;
1070 uint32_t cnt, acnt;
1071
1072 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
1073 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1074 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1075 }
1076
1077 /**
1078 * lpfc_max_vpi_show - Return maximum vpi
1079 * @dev: class device that is converted into a Scsi_host.
1080 * @attr: device attribute, not used.
1081 * @buf: on return contains the maximum vpi count in decimal or "Unknown".
1082 *
1083 * Description:
1084 * Calls lpfc_get_hba_info() asking for just the mvpi count.
1085 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1086 * to "Unknown" and the buffer length is returned, therefore the caller
1087 * must check for "Unknown" in the buffer to detect a failure.
1088 *
1089 * Returns: size of formatted string.
1090 **/
1091 static ssize_t
1092 lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
1093 char *buf)
1094 {
1095 struct Scsi_Host *shost = class_to_shost(dev);
1096 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1097 struct lpfc_hba *phba = vport->phba;
1098 uint32_t cnt;
1099
1100 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
1101 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
1102 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1103 }
1104
1105 /**
1106 * lpfc_used_vpi_show - Return maximum vpi minus the available vpi
1107 * @dev: class device that is converted into a Scsi_host.
1108 * @attr: device attribute, not used.
1109 * @buf: on return contains the used vpi count in decimal or "Unknown".
1110 *
1111 * Description:
1112 * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts.
1113 * If lpfc_get_hba_info() returns zero (failure) the buffer text is set
1114 * to "Unknown" and the buffer length is returned, therefore the caller
1115 * must check for "Unknown" in the buffer to detect a failure.
1116 *
1117 * Returns: size of formatted string.
1118 **/
1119 static ssize_t
1120 lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
1121 char *buf)
1122 {
1123 struct Scsi_Host *shost = class_to_shost(dev);
1124 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1125 struct lpfc_hba *phba = vport->phba;
1126 uint32_t cnt, acnt;
1127
1128 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
1129 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
1130 return snprintf(buf, PAGE_SIZE, "Unknown\n");
1131 }
1132
1133 /**
1134 * lpfc_npiv_info_show - Return text about NPIV support for the adapter
1135 * @dev: class device that is converted into a Scsi_host.
1136 * @attr: device attribute, not used.
1137 * @buf: text that must be interpreted to determine if npiv is supported.
1138 *
1139 * Description:
1140 * Buffer will contain text indicating npiv is not suppoerted on the port,
1141 * the port is an NPIV physical port, or it is an npiv virtual port with
1142 * the id of the vport.
1143 *
1144 * Returns: size of formatted string.
1145 **/
1146 static ssize_t
1147 lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
1148 char *buf)
1149 {
1150 struct Scsi_Host *shost = class_to_shost(dev);
1151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1152 struct lpfc_hba *phba = vport->phba;
1153
1154 if (!(phba->max_vpi))
1155 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
1156 if (vport->port_type == LPFC_PHYSICAL_PORT)
1157 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
1158 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
1159 }
1160
1161 /**
1162 * lpfc_poll_show - Return text about poll support for the adapter
1163 * @dev: class device that is converted into a Scsi_host.
1164 * @attr: device attribute, not used.
1165 * @buf: on return contains the cfg_poll in hex.
1166 *
1167 * Notes:
1168 * cfg_poll should be a lpfc_polling_flags type.
1169 *
1170 * Returns: size of formatted string.
1171 **/
1172 static ssize_t
1173 lpfc_poll_show(struct device *dev, struct device_attribute *attr,
1174 char *buf)
1175 {
1176 struct Scsi_Host *shost = class_to_shost(dev);
1177 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1178 struct lpfc_hba *phba = vport->phba;
1179
1180 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
1181 }
1182
1183 /**
1184 * lpfc_poll_store - Set the value of cfg_poll for the adapter
1185 * @dev: class device that is converted into a Scsi_host.
1186 * @attr: device attribute, not used.
1187 * @buf: one or more lpfc_polling_flags values.
1188 * @count: not used.
1189 *
1190 * Notes:
1191 * buf contents converted to integer and checked for a valid value.
1192 *
1193 * Returns:
1194 * -EINVAL if the buffer connot be converted or is out of range
1195 * length of the buf on success
1196 **/
1197 static ssize_t
1198 lpfc_poll_store(struct device *dev, struct device_attribute *attr,
1199 const char *buf, size_t count)
1200 {
1201 struct Scsi_Host *shost = class_to_shost(dev);
1202 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1203 struct lpfc_hba *phba = vport->phba;
1204 uint32_t creg_val;
1205 uint32_t old_val;
1206 int val=0;
1207
1208 if (!isdigit(buf[0]))
1209 return -EINVAL;
1210
1211 if (sscanf(buf, "%i", &val) != 1)
1212 return -EINVAL;
1213
1214 if ((val & 0x3) != val)
1215 return -EINVAL;
1216
1217 if (phba->sli_rev == LPFC_SLI_REV4)
1218 val = 0;
1219
1220 spin_lock_irq(&phba->hbalock);
1221
1222 old_val = phba->cfg_poll;
1223
1224 if (val & ENABLE_FCP_RING_POLLING) {
1225 if ((val & DISABLE_FCP_RING_INT) &&
1226 !(old_val & DISABLE_FCP_RING_INT)) {
1227 creg_val = readl(phba->HCregaddr);
1228 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
1229 writel(creg_val, phba->HCregaddr);
1230 readl(phba->HCregaddr); /* flush */
1231
1232 lpfc_poll_start_timer(phba);
1233 }
1234 } else if (val != 0x0) {
1235 spin_unlock_irq(&phba->hbalock);
1236 return -EINVAL;
1237 }
1238
1239 if (!(val & DISABLE_FCP_RING_INT) &&
1240 (old_val & DISABLE_FCP_RING_INT))
1241 {
1242 spin_unlock_irq(&phba->hbalock);
1243 del_timer(&phba->fcp_poll_timer);
1244 spin_lock_irq(&phba->hbalock);
1245 creg_val = readl(phba->HCregaddr);
1246 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
1247 writel(creg_val, phba->HCregaddr);
1248 readl(phba->HCregaddr); /* flush */
1249 }
1250
1251 phba->cfg_poll = val;
1252
1253 spin_unlock_irq(&phba->hbalock);
1254
1255 return strlen(buf);
1256 }
1257
1258 /**
1259 * lpfc_fips_level_show - Return the current FIPS level for the HBA
1260 * @dev: class unused variable.
1261 * @attr: device attribute, not used.
1262 * @buf: on return contains the module description text.
1263 *
1264 * Returns: size of formatted string.
1265 **/
1266 static ssize_t
1267 lpfc_fips_level_show(struct device *dev, struct device_attribute *attr,
1268 char *buf)
1269 {
1270 struct Scsi_Host *shost = class_to_shost(dev);
1271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273
1274 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level);
1275 }
1276
1277 /**
1278 * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA
1279 * @dev: class unused variable.
1280 * @attr: device attribute, not used.
1281 * @buf: on return contains the module description text.
1282 *
1283 * Returns: size of formatted string.
1284 **/
1285 static ssize_t
1286 lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr,
1287 char *buf)
1288 {
1289 struct Scsi_Host *shost = class_to_shost(dev);
1290 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1291 struct lpfc_hba *phba = vport->phba;
1292
1293 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev);
1294 }
1295
1296 /**
1297 * lpfc_dss_show - Return the current state of dss and the configured state
1298 * @dev: class converted to a Scsi_host structure.
1299 * @attr: device attribute, not used.
1300 * @buf: on return contains the formatted text.
1301 *
1302 * Returns: size of formatted string.
1303 **/
1304 static ssize_t
1305 lpfc_dss_show(struct device *dev, struct device_attribute *attr,
1306 char *buf)
1307 {
1308 struct Scsi_Host *shost = class_to_shost(dev);
1309 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1310 struct lpfc_hba *phba = vport->phba;
1311
1312 return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n",
1313 (phba->cfg_enable_dss) ? "Enabled" : "Disabled",
1314 (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ?
1315 "" : "Not ");
1316 }
1317
1318 /**
1319 * lpfc_param_show - Return a cfg attribute value in decimal
1320 *
1321 * Description:
1322 * Macro that given an attr e.g. hba_queue_depth expands
1323 * into a function with the name lpfc_hba_queue_depth_show.
1324 *
1325 * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field.
1326 * @dev: class device that is converted into a Scsi_host.
1327 * @attr: device attribute, not used.
1328 * @buf: on return contains the attribute value in decimal.
1329 *
1330 * Returns: size of formatted string.
1331 **/
1332 #define lpfc_param_show(attr) \
1333 static ssize_t \
1334 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1335 char *buf) \
1336 { \
1337 struct Scsi_Host *shost = class_to_shost(dev);\
1338 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1339 struct lpfc_hba *phba = vport->phba;\
1340 uint val = 0;\
1341 val = phba->cfg_##attr;\
1342 return snprintf(buf, PAGE_SIZE, "%d\n",\
1343 phba->cfg_##attr);\
1344 }
1345
1346 /**
1347 * lpfc_param_hex_show - Return a cfg attribute value in hex
1348 *
1349 * Description:
1350 * Macro that given an attr e.g. hba_queue_depth expands
1351 * into a function with the name lpfc_hba_queue_depth_show
1352 *
1353 * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field.
1354 * @dev: class device that is converted into a Scsi_host.
1355 * @attr: device attribute, not used.
1356 * @buf: on return contains the attribute value in hexadecimal.
1357 *
1358 * Returns: size of formatted string.
1359 **/
1360 #define lpfc_param_hex_show(attr) \
1361 static ssize_t \
1362 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1363 char *buf) \
1364 { \
1365 struct Scsi_Host *shost = class_to_shost(dev);\
1366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1367 struct lpfc_hba *phba = vport->phba;\
1368 uint val = 0;\
1369 val = phba->cfg_##attr;\
1370 return snprintf(buf, PAGE_SIZE, "%#x\n",\
1371 phba->cfg_##attr);\
1372 }
1373
1374 /**
1375 * lpfc_param_init - Initializes a cfg attribute
1376 *
1377 * Description:
1378 * Macro that given an attr e.g. hba_queue_depth expands
1379 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1380 * takes a default argument, a minimum and maximum argument.
1381 *
1382 * lpfc_##attr##_init: Initializes an attribute.
1383 * @phba: pointer the the adapter structure.
1384 * @val: integer attribute value.
1385 *
1386 * Validates the min and max values then sets the adapter config field
1387 * accordingly, or uses the default if out of range and prints an error message.
1388 *
1389 * Returns:
1390 * zero on success
1391 * -EINVAL if default used
1392 **/
1393 #define lpfc_param_init(attr, default, minval, maxval) \
1394 static int \
1395 lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \
1396 { \
1397 if (val >= minval && val <= maxval) {\
1398 phba->cfg_##attr = val;\
1399 return 0;\
1400 }\
1401 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1402 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
1403 "allowed range is ["#minval", "#maxval"]\n", val); \
1404 phba->cfg_##attr = default;\
1405 return -EINVAL;\
1406 }
1407
1408 /**
1409 * lpfc_param_set - Set a cfg attribute value
1410 *
1411 * Description:
1412 * Macro that given an attr e.g. hba_queue_depth expands
1413 * into a function with the name lpfc_hba_queue_depth_set
1414 *
1415 * lpfc_##attr##_set: Sets an attribute value.
1416 * @phba: pointer the the adapter structure.
1417 * @val: integer attribute value.
1418 *
1419 * Description:
1420 * Validates the min and max values then sets the
1421 * adapter config field if in the valid range. prints error message
1422 * and does not set the parameter if invalid.
1423 *
1424 * Returns:
1425 * zero on success
1426 * -EINVAL if val is invalid
1427 **/
1428 #define lpfc_param_set(attr, default, minval, maxval) \
1429 static int \
1430 lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \
1431 { \
1432 if (val >= minval && val <= maxval) {\
1433 phba->cfg_##attr = val;\
1434 return 0;\
1435 }\
1436 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
1437 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
1438 "allowed range is ["#minval", "#maxval"]\n", val); \
1439 return -EINVAL;\
1440 }
1441
1442 /**
1443 * lpfc_param_store - Set a vport attribute value
1444 *
1445 * Description:
1446 * Macro that given an attr e.g. hba_queue_depth expands
1447 * into a function with the name lpfc_hba_queue_depth_store.
1448 *
1449 * lpfc_##attr##_store: Set an sttribute value.
1450 * @dev: class device that is converted into a Scsi_host.
1451 * @attr: device attribute, not used.
1452 * @buf: contains the attribute value in ascii.
1453 * @count: not used.
1454 *
1455 * Description:
1456 * Convert the ascii text number to an integer, then
1457 * use the lpfc_##attr##_set function to set the value.
1458 *
1459 * Returns:
1460 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1461 * length of buffer upon success.
1462 **/
1463 #define lpfc_param_store(attr) \
1464 static ssize_t \
1465 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1466 const char *buf, size_t count) \
1467 { \
1468 struct Scsi_Host *shost = class_to_shost(dev);\
1469 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1470 struct lpfc_hba *phba = vport->phba;\
1471 uint val = 0;\
1472 if (!isdigit(buf[0]))\
1473 return -EINVAL;\
1474 if (sscanf(buf, "%i", &val) != 1)\
1475 return -EINVAL;\
1476 if (lpfc_##attr##_set(phba, val) == 0) \
1477 return strlen(buf);\
1478 else \
1479 return -EINVAL;\
1480 }
1481
1482 /**
1483 * lpfc_vport_param_show - Return decimal formatted cfg attribute value
1484 *
1485 * Description:
1486 * Macro that given an attr e.g. hba_queue_depth expands
1487 * into a function with the name lpfc_hba_queue_depth_show
1488 *
1489 * lpfc_##attr##_show: prints the attribute value in decimal.
1490 * @dev: class device that is converted into a Scsi_host.
1491 * @attr: device attribute, not used.
1492 * @buf: on return contains the attribute value in decimal.
1493 *
1494 * Returns: length of formatted string.
1495 **/
1496 #define lpfc_vport_param_show(attr) \
1497 static ssize_t \
1498 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1499 char *buf) \
1500 { \
1501 struct Scsi_Host *shost = class_to_shost(dev);\
1502 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1503 uint val = 0;\
1504 val = vport->cfg_##attr;\
1505 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
1506 }
1507
1508 /**
1509 * lpfc_vport_param_hex_show - Return hex formatted attribute value
1510 *
1511 * Description:
1512 * Macro that given an attr e.g.
1513 * hba_queue_depth expands into a function with the name
1514 * lpfc_hba_queue_depth_show
1515 *
1516 * lpfc_##attr##_show: prints the attribute value in hexadecimal.
1517 * @dev: class device that is converted into a Scsi_host.
1518 * @attr: device attribute, not used.
1519 * @buf: on return contains the attribute value in hexadecimal.
1520 *
1521 * Returns: length of formatted string.
1522 **/
1523 #define lpfc_vport_param_hex_show(attr) \
1524 static ssize_t \
1525 lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
1526 char *buf) \
1527 { \
1528 struct Scsi_Host *shost = class_to_shost(dev);\
1529 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1530 uint val = 0;\
1531 val = vport->cfg_##attr;\
1532 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
1533 }
1534
1535 /**
1536 * lpfc_vport_param_init - Initialize a vport cfg attribute
1537 *
1538 * Description:
1539 * Macro that given an attr e.g. hba_queue_depth expands
1540 * into a function with the name lpfc_hba_queue_depth_init. The macro also
1541 * takes a default argument, a minimum and maximum argument.
1542 *
1543 * lpfc_##attr##_init: validates the min and max values then sets the
1544 * adapter config field accordingly, or uses the default if out of range
1545 * and prints an error message.
1546 * @phba: pointer the the adapter structure.
1547 * @val: integer attribute value.
1548 *
1549 * Returns:
1550 * zero on success
1551 * -EINVAL if default used
1552 **/
1553 #define lpfc_vport_param_init(attr, default, minval, maxval) \
1554 static int \
1555 lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \
1556 { \
1557 if (val >= minval && val <= maxval) {\
1558 vport->cfg_##attr = val;\
1559 return 0;\
1560 }\
1561 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1562 "0423 lpfc_"#attr" attribute cannot be set to %d, "\
1563 "allowed range is ["#minval", "#maxval"]\n", val); \
1564 vport->cfg_##attr = default;\
1565 return -EINVAL;\
1566 }
1567
1568 /**
1569 * lpfc_vport_param_set - Set a vport cfg attribute
1570 *
1571 * Description:
1572 * Macro that given an attr e.g. hba_queue_depth expands
1573 * into a function with the name lpfc_hba_queue_depth_set
1574 *
1575 * lpfc_##attr##_set: validates the min and max values then sets the
1576 * adapter config field if in the valid range. prints error message
1577 * and does not set the parameter if invalid.
1578 * @phba: pointer the the adapter structure.
1579 * @val: integer attribute value.
1580 *
1581 * Returns:
1582 * zero on success
1583 * -EINVAL if val is invalid
1584 **/
1585 #define lpfc_vport_param_set(attr, default, minval, maxval) \
1586 static int \
1587 lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \
1588 { \
1589 if (val >= minval && val <= maxval) {\
1590 vport->cfg_##attr = val;\
1591 return 0;\
1592 }\
1593 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
1594 "0424 lpfc_"#attr" attribute cannot be set to %d, "\
1595 "allowed range is ["#minval", "#maxval"]\n", val); \
1596 return -EINVAL;\
1597 }
1598
1599 /**
1600 * lpfc_vport_param_store - Set a vport attribute
1601 *
1602 * Description:
1603 * Macro that given an attr e.g. hba_queue_depth
1604 * expands into a function with the name lpfc_hba_queue_depth_store
1605 *
1606 * lpfc_##attr##_store: convert the ascii text number to an integer, then
1607 * use the lpfc_##attr##_set function to set the value.
1608 * @cdev: class device that is converted into a Scsi_host.
1609 * @buf: contains the attribute value in decimal.
1610 * @count: not used.
1611 *
1612 * Returns:
1613 * -EINVAL if val is invalid or lpfc_##attr##_set() fails
1614 * length of buffer upon success.
1615 **/
1616 #define lpfc_vport_param_store(attr) \
1617 static ssize_t \
1618 lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
1619 const char *buf, size_t count) \
1620 { \
1621 struct Scsi_Host *shost = class_to_shost(dev);\
1622 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
1623 uint val = 0;\
1624 if (!isdigit(buf[0]))\
1625 return -EINVAL;\
1626 if (sscanf(buf, "%i", &val) != 1)\
1627 return -EINVAL;\
1628 if (lpfc_##attr##_set(vport, val) == 0) \
1629 return strlen(buf);\
1630 else \
1631 return -EINVAL;\
1632 }
1633
1634
1635 #define LPFC_ATTR(name, defval, minval, maxval, desc) \
1636 static uint lpfc_##name = defval;\
1637 module_param(lpfc_##name, uint, S_IRUGO);\
1638 MODULE_PARM_DESC(lpfc_##name, desc);\
1639 lpfc_param_init(name, defval, minval, maxval)
1640
1641 #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
1642 static uint lpfc_##name = defval;\
1643 module_param(lpfc_##name, uint, S_IRUGO);\
1644 MODULE_PARM_DESC(lpfc_##name, desc);\
1645 lpfc_param_show(name)\
1646 lpfc_param_init(name, defval, minval, maxval)\
1647 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1648
1649 #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
1650 static uint lpfc_##name = defval;\
1651 module_param(lpfc_##name, uint, S_IRUGO);\
1652 MODULE_PARM_DESC(lpfc_##name, desc);\
1653 lpfc_param_show(name)\
1654 lpfc_param_init(name, defval, minval, maxval)\
1655 lpfc_param_set(name, defval, minval, maxval)\
1656 lpfc_param_store(name)\
1657 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1658 lpfc_##name##_show, lpfc_##name##_store)
1659
1660 #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1661 static uint lpfc_##name = defval;\
1662 module_param(lpfc_##name, uint, S_IRUGO);\
1663 MODULE_PARM_DESC(lpfc_##name, desc);\
1664 lpfc_param_hex_show(name)\
1665 lpfc_param_init(name, defval, minval, maxval)\
1666 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1667
1668 #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1669 static uint lpfc_##name = defval;\
1670 module_param(lpfc_##name, uint, S_IRUGO);\
1671 MODULE_PARM_DESC(lpfc_##name, desc);\
1672 lpfc_param_hex_show(name)\
1673 lpfc_param_init(name, defval, minval, maxval)\
1674 lpfc_param_set(name, defval, minval, maxval)\
1675 lpfc_param_store(name)\
1676 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1677 lpfc_##name##_show, lpfc_##name##_store)
1678
1679 #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
1680 static uint lpfc_##name = defval;\
1681 module_param(lpfc_##name, uint, S_IRUGO);\
1682 MODULE_PARM_DESC(lpfc_##name, desc);\
1683 lpfc_vport_param_init(name, defval, minval, maxval)
1684
1685 #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
1686 static uint lpfc_##name = defval;\
1687 module_param(lpfc_##name, uint, S_IRUGO);\
1688 MODULE_PARM_DESC(lpfc_##name, desc);\
1689 lpfc_vport_param_show(name)\
1690 lpfc_vport_param_init(name, defval, minval, maxval)\
1691 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1692
1693 #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
1694 static uint lpfc_##name = defval;\
1695 module_param(lpfc_##name, uint, S_IRUGO);\
1696 MODULE_PARM_DESC(lpfc_##name, desc);\
1697 lpfc_vport_param_show(name)\
1698 lpfc_vport_param_init(name, defval, minval, maxval)\
1699 lpfc_vport_param_set(name, defval, minval, maxval)\
1700 lpfc_vport_param_store(name)\
1701 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1702 lpfc_##name##_show, lpfc_##name##_store)
1703
1704 #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
1705 static uint lpfc_##name = defval;\
1706 module_param(lpfc_##name, uint, S_IRUGO);\
1707 MODULE_PARM_DESC(lpfc_##name, desc);\
1708 lpfc_vport_param_hex_show(name)\
1709 lpfc_vport_param_init(name, defval, minval, maxval)\
1710 static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
1711
1712 #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
1713 static uint lpfc_##name = defval;\
1714 module_param(lpfc_##name, uint, S_IRUGO);\
1715 MODULE_PARM_DESC(lpfc_##name, desc);\
1716 lpfc_vport_param_hex_show(name)\
1717 lpfc_vport_param_init(name, defval, minval, maxval)\
1718 lpfc_vport_param_set(name, defval, minval, maxval)\
1719 lpfc_vport_param_store(name)\
1720 static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
1721 lpfc_##name##_show, lpfc_##name##_store)
1722
1723 static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL);
1724 static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL);
1725 static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL);
1726 static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL);
1727 static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
1728 static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
1729 static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
1730 static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
1731 static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
1732 static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
1733 static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
1734 static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
1735 static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show,
1736 lpfc_link_state_store);
1737 static DEVICE_ATTR(option_rom_version, S_IRUGO,
1738 lpfc_option_rom_version_show, NULL);
1739 static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
1740 lpfc_num_discovered_ports_show, NULL);
1741 static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL);
1742 static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
1743 static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
1744 static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL);
1745 static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
1746 lpfc_board_mode_show, lpfc_board_mode_store);
1747 static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
1748 static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
1749 static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
1750 static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
1751 static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
1752 static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
1753 static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
1754 static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
1755 static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
1756 static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL);
1757 static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL);
1758 static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL);
1759
1760 static char *lpfc_soft_wwn_key = "C99G71SL8032A";
1761
1762 /**
1763 * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid
1764 * @dev: class device that is converted into a Scsi_host.
1765 * @attr: device attribute, not used.
1766 * @buf: containing the string lpfc_soft_wwn_key.
1767 * @count: must be size of lpfc_soft_wwn_key.
1768 *
1769 * Returns:
1770 * -EINVAL if the buffer does not contain lpfc_soft_wwn_key
1771 * length of buf indicates success
1772 **/
1773 static ssize_t
1774 lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
1775 const char *buf, size_t count)
1776 {
1777 struct Scsi_Host *shost = class_to_shost(dev);
1778 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1779 struct lpfc_hba *phba = vport->phba;
1780 unsigned int cnt = count;
1781
1782 /*
1783 * We're doing a simple sanity check for soft_wwpn setting.
1784 * We require that the user write a specific key to enable
1785 * the soft_wwpn attribute to be settable. Once the attribute
1786 * is written, the enable key resets. If further updates are
1787 * desired, the key must be written again to re-enable the
1788 * attribute.
1789 *
1790 * The "key" is not secret - it is a hardcoded string shown
1791 * here. The intent is to protect against the random user or
1792 * application that is just writing attributes.
1793 */
1794
1795 /* count may include a LF at end of string */
1796 if (buf[cnt-1] == '\n')
1797 cnt--;
1798
1799 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
1800 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
1801 return -EINVAL;
1802
1803 phba->soft_wwn_enable = 1;
1804 return count;
1805 }
1806 static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
1807 lpfc_soft_wwn_enable_store);
1808
1809 /**
1810 * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter
1811 * @dev: class device that is converted into a Scsi_host.
1812 * @attr: device attribute, not used.
1813 * @buf: on return contains the wwpn in hexadecimal.
1814 *
1815 * Returns: size of formatted string.
1816 **/
1817 static ssize_t
1818 lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
1819 char *buf)
1820 {
1821 struct Scsi_Host *shost = class_to_shost(dev);
1822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1823 struct lpfc_hba *phba = vport->phba;
1824
1825 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1826 (unsigned long long)phba->cfg_soft_wwpn);
1827 }
1828
1829 /**
1830 * lpfc_soft_wwpn_store - Set the ww port name of the adapter
1831 * @dev class device that is converted into a Scsi_host.
1832 * @attr: device attribute, not used.
1833 * @buf: contains the wwpn in hexadecimal.
1834 * @count: number of wwpn bytes in buf
1835 *
1836 * Returns:
1837 * -EACCES hba reset not enabled, adapter over temp
1838 * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid
1839 * -EIO error taking adapter offline or online
1840 * value of count on success
1841 **/
1842 static ssize_t
1843 lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1844 const char *buf, size_t count)
1845 {
1846 struct Scsi_Host *shost = class_to_shost(dev);
1847 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1848 struct lpfc_hba *phba = vport->phba;
1849 struct completion online_compl;
1850 int stat1=0, stat2=0;
1851 unsigned int i, j, cnt=count;
1852 u8 wwpn[8];
1853 int rc;
1854
1855 if (!phba->cfg_enable_hba_reset)
1856 return -EACCES;
1857 spin_lock_irq(&phba->hbalock);
1858 if (phba->over_temp_state == HBA_OVER_TEMP) {
1859 spin_unlock_irq(&phba->hbalock);
1860 return -EACCES;
1861 }
1862 spin_unlock_irq(&phba->hbalock);
1863 /* count may include a LF at end of string */
1864 if (buf[cnt-1] == '\n')
1865 cnt--;
1866
1867 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1868 ((cnt == 17) && (*buf++ != 'x')) ||
1869 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1870 return -EINVAL;
1871
1872 phba->soft_wwn_enable = 0;
1873
1874 memset(wwpn, 0, sizeof(wwpn));
1875
1876 /* Validate and store the new name */
1877 for (i=0, j=0; i < 16; i++) {
1878 int value;
1879
1880 value = hex_to_bin(*buf++);
1881 if (value >= 0)
1882 j = (j << 4) | value;
1883 else
1884 return -EINVAL;
1885 if (i % 2) {
1886 wwpn[i/2] = j & 0xff;
1887 j = 0;
1888 }
1889 }
1890 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
1891 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
1892 if (phba->cfg_soft_wwnn)
1893 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
1894
1895 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1896 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1897
1898 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
1899 if (stat1)
1900 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1901 "0463 lpfc_soft_wwpn attribute set failed to "
1902 "reinit adapter - %d\n", stat1);
1903 init_completion(&online_compl);
1904 rc = lpfc_workq_post_event(phba, &stat2, &online_compl,
1905 LPFC_EVT_ONLINE);
1906 if (rc == 0)
1907 return -ENOMEM;
1908
1909 wait_for_completion(&online_compl);
1910 if (stat2)
1911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1912 "0464 lpfc_soft_wwpn attribute set failed to "
1913 "reinit adapter - %d\n", stat2);
1914 return (stat1 || stat2) ? -EIO : count;
1915 }
1916 static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1917 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1918
1919 /**
1920 * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter
1921 * @dev: class device that is converted into a Scsi_host.
1922 * @attr: device attribute, not used.
1923 * @buf: on return contains the wwnn in hexadecimal.
1924 *
1925 * Returns: size of formatted string.
1926 **/
1927 static ssize_t
1928 lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1929 char *buf)
1930 {
1931 struct Scsi_Host *shost = class_to_shost(dev);
1932 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1933 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1934 (unsigned long long)phba->cfg_soft_wwnn);
1935 }
1936
1937 /**
1938 * lpfc_soft_wwnn_store - sets the ww node name of the adapter
1939 * @cdev: class device that is converted into a Scsi_host.
1940 * @buf: contains the ww node name in hexadecimal.
1941 * @count: number of wwnn bytes in buf.
1942 *
1943 * Returns:
1944 * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid
1945 * value of count on success
1946 **/
1947 static ssize_t
1948 lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1949 const char *buf, size_t count)
1950 {
1951 struct Scsi_Host *shost = class_to_shost(dev);
1952 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
1953 unsigned int i, j, cnt=count;
1954 u8 wwnn[8];
1955
1956 /* count may include a LF at end of string */
1957 if (buf[cnt-1] == '\n')
1958 cnt--;
1959
1960 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1961 ((cnt == 17) && (*buf++ != 'x')) ||
1962 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1963 return -EINVAL;
1964
1965 /*
1966 * Allow wwnn to be set many times, as long as the enable is set.
1967 * However, once the wwpn is set, everything locks.
1968 */
1969
1970 memset(wwnn, 0, sizeof(wwnn));
1971
1972 /* Validate and store the new name */
1973 for (i=0, j=0; i < 16; i++) {
1974 int value;
1975
1976 value = hex_to_bin(*buf++);
1977 if (value >= 0)
1978 j = (j << 4) | value;
1979 else
1980 return -EINVAL;
1981 if (i % 2) {
1982 wwnn[i/2] = j & 0xff;
1983 j = 0;
1984 }
1985 }
1986 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1987
1988 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1989 "lpfc%d: soft_wwnn set. Value will take effect upon "
1990 "setting of the soft_wwpn\n", phba->brd_no);
1991
1992 return count;
1993 }
1994 static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1995 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1996
1997
1998 static int lpfc_poll = 0;
1999 module_param(lpfc_poll, int, S_IRUGO);
2000 MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
2001 " 0 - none,"
2002 " 1 - poll with interrupts enabled"
2003 " 3 - poll and disable FCP ring interrupts");
2004
2005 static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
2006 lpfc_poll_show, lpfc_poll_store);
2007
2008 int lpfc_sli_mode = 0;
2009 module_param(lpfc_sli_mode, int, S_IRUGO);
2010 MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
2011 " 0 - auto (SLI-3 if supported),"
2012 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
2013 " 3 - select SLI-3");
2014
2015 int lpfc_enable_npiv = 1;
2016 module_param(lpfc_enable_npiv, int, S_IRUGO);
2017 MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
2018 lpfc_param_show(enable_npiv);
2019 lpfc_param_init(enable_npiv, 1, 0, 1);
2020 static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, lpfc_enable_npiv_show, NULL);
2021
2022 int lpfc_enable_rrq;
2023 module_param(lpfc_enable_rrq, int, S_IRUGO);
2024 MODULE_PARM_DESC(lpfc_enable_rrq, "Enable RRQ functionality");
2025 lpfc_param_show(enable_rrq);
2026 lpfc_param_init(enable_rrq, 0, 0, 1);
2027 static DEVICE_ATTR(lpfc_enable_rrq, S_IRUGO, lpfc_enable_rrq_show, NULL);
2028
2029 /*
2030 # lpfc_suppress_link_up: Bring link up at initialization
2031 # 0x0 = bring link up (issue MBX_INIT_LINK)
2032 # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK)
2033 # 0x2 = never bring up link
2034 # Default value is 0.
2035 */
2036 LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK,
2037 LPFC_DELAY_INIT_LINK_INDEFINITELY,
2038 "Suppress Link Up at initialization");
2039 /*
2040 # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS
2041 # 1 - (1024)
2042 # 2 - (2048)
2043 # 3 - (3072)
2044 # 4 - (4096)
2045 # 5 - (5120)
2046 */
2047 static ssize_t
2048 lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2049 {
2050 struct Scsi_Host *shost = class_to_shost(dev);
2051 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2052
2053 return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max);
2054 }
2055
2056 static DEVICE_ATTR(iocb_hw, S_IRUGO,
2057 lpfc_iocb_hw_show, NULL);
2058 static ssize_t
2059 lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf)
2060 {
2061 struct Scsi_Host *shost = class_to_shost(dev);
2062 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2063
2064 return snprintf(buf, PAGE_SIZE, "%d\n",
2065 phba->sli.ring[LPFC_ELS_RING].txq_max);
2066 }
2067
2068 static DEVICE_ATTR(txq_hw, S_IRUGO,
2069 lpfc_txq_hw_show, NULL);
2070 static ssize_t
2071 lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr,
2072 char *buf)
2073 {
2074 struct Scsi_Host *shost = class_to_shost(dev);
2075 struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba;
2076
2077 return snprintf(buf, PAGE_SIZE, "%d\n",
2078 phba->sli.ring[LPFC_ELS_RING].txcmplq_max);
2079 }
2080
2081 static DEVICE_ATTR(txcmplq_hw, S_IRUGO,
2082 lpfc_txcmplq_hw_show, NULL);
2083
2084 int lpfc_iocb_cnt = 2;
2085 module_param(lpfc_iocb_cnt, int, S_IRUGO);
2086 MODULE_PARM_DESC(lpfc_iocb_cnt,
2087 "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs");
2088 lpfc_param_show(iocb_cnt);
2089 lpfc_param_init(iocb_cnt, 2, 1, 5);
2090 static DEVICE_ATTR(lpfc_iocb_cnt, S_IRUGO,
2091 lpfc_iocb_cnt_show, NULL);
2092
2093 /*
2094 # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
2095 # until the timer expires. Value range is [0,255]. Default value is 30.
2096 */
2097 static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2098 static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
2099 module_param(lpfc_nodev_tmo, int, 0);
2100 MODULE_PARM_DESC(lpfc_nodev_tmo,
2101 "Seconds driver will hold I/O waiting "
2102 "for a device to come back");
2103
2104 /**
2105 * lpfc_nodev_tmo_show - Return the hba dev loss timeout value
2106 * @dev: class converted to a Scsi_host structure.
2107 * @attr: device attribute, not used.
2108 * @buf: on return contains the dev loss timeout in decimal.
2109 *
2110 * Returns: size of formatted string.
2111 **/
2112 static ssize_t
2113 lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
2114 char *buf)
2115 {
2116 struct Scsi_Host *shost = class_to_shost(dev);
2117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2118
2119 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
2120 }
2121
2122 /**
2123 * lpfc_nodev_tmo_init - Set the hba nodev timeout value
2124 * @vport: lpfc vport structure pointer.
2125 * @val: contains the nodev timeout value.
2126 *
2127 * Description:
2128 * If the devloss tmo is already set then nodev tmo is set to devloss tmo,
2129 * a kernel error message is printed and zero is returned.
2130 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2131 * Otherwise nodev tmo is set to the default value.
2132 *
2133 * Returns:
2134 * zero if already set or if val is in range
2135 * -EINVAL val out of range
2136 **/
2137 static int
2138 lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
2139 {
2140 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
2141 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
2142 if (val != LPFC_DEF_DEVLOSS_TMO)
2143 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2144 "0407 Ignoring nodev_tmo module "
2145 "parameter because devloss_tmo is "
2146 "set.\n");
2147 return 0;
2148 }
2149
2150 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2151 vport->cfg_nodev_tmo = val;
2152 vport->cfg_devloss_tmo = val;
2153 return 0;
2154 }
2155 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2156 "0400 lpfc_nodev_tmo attribute cannot be set to"
2157 " %d, allowed range is [%d, %d]\n",
2158 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2159 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
2160 return -EINVAL;
2161 }
2162
2163 /**
2164 * lpfc_update_rport_devloss_tmo - Update dev loss tmo value
2165 * @vport: lpfc vport structure pointer.
2166 *
2167 * Description:
2168 * Update all the ndlp's dev loss tmo with the vport devloss tmo value.
2169 **/
2170 static void
2171 lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
2172 {
2173 struct Scsi_Host *shost;
2174 struct lpfc_nodelist *ndlp;
2175
2176 shost = lpfc_shost_from_vport(vport);
2177 spin_lock_irq(shost->host_lock);
2178 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
2179 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
2180 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
2181 spin_unlock_irq(shost->host_lock);
2182 }
2183
2184 /**
2185 * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values
2186 * @vport: lpfc vport structure pointer.
2187 * @val: contains the tmo value.
2188 *
2189 * Description:
2190 * If the devloss tmo is already set or the vport dev loss tmo has changed
2191 * then a kernel error message is printed and zero is returned.
2192 * Else if val is in range then nodev tmo and devloss tmo are set to val.
2193 * Otherwise nodev tmo is set to the default value.
2194 *
2195 * Returns:
2196 * zero if already set or if val is in range
2197 * -EINVAL val out of range
2198 **/
2199 static int
2200 lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
2201 {
2202 if (vport->dev_loss_tmo_changed ||
2203 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
2204 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2205 "0401 Ignoring change to nodev_tmo "
2206 "because devloss_tmo is set.\n");
2207 return 0;
2208 }
2209 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2210 vport->cfg_nodev_tmo = val;
2211 vport->cfg_devloss_tmo = val;
2212 /*
2213 * For compat: set the fc_host dev loss so new rports
2214 * will get the value.
2215 */
2216 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2217 lpfc_update_rport_devloss_tmo(vport);
2218 return 0;
2219 }
2220 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2221 "0403 lpfc_nodev_tmo attribute cannot be set to"
2222 "%d, allowed range is [%d, %d]\n",
2223 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2224 return -EINVAL;
2225 }
2226
2227 lpfc_vport_param_store(nodev_tmo)
2228
2229 static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
2230 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
2231
2232 /*
2233 # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
2234 # disappear until the timer expires. Value range is [0,255]. Default
2235 # value is 30.
2236 */
2237 module_param(lpfc_devloss_tmo, int, S_IRUGO);
2238 MODULE_PARM_DESC(lpfc_devloss_tmo,
2239 "Seconds driver will hold I/O waiting "
2240 "for a device to come back");
2241 lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
2242 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
2243 lpfc_vport_param_show(devloss_tmo)
2244
2245 /**
2246 * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit
2247 * @vport: lpfc vport structure pointer.
2248 * @val: contains the tmo value.
2249 *
2250 * Description:
2251 * If val is in a valid range then set the vport nodev tmo,
2252 * devloss tmo, also set the vport dev loss tmo changed flag.
2253 * Else a kernel error message is printed.
2254 *
2255 * Returns:
2256 * zero if val is in range
2257 * -EINVAL val out of range
2258 **/
2259 static int
2260 lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
2261 {
2262 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
2263 vport->cfg_nodev_tmo = val;
2264 vport->cfg_devloss_tmo = val;
2265 vport->dev_loss_tmo_changed = 1;
2266 fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val;
2267 lpfc_update_rport_devloss_tmo(vport);
2268 return 0;
2269 }
2270
2271 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2272 "0404 lpfc_devloss_tmo attribute cannot be set to"
2273 " %d, allowed range is [%d, %d]\n",
2274 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
2275 return -EINVAL;
2276 }
2277
2278 lpfc_vport_param_store(devloss_tmo)
2279 static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
2280 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
2281
2282 /*
2283 # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
2284 # deluged with LOTS of information.
2285 # You can set a bit mask to record specific types of verbose messages:
2286 # See lpfc_logmsh.h for definitions.
2287 */
2288 LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff,
2289 "Verbose logging bit-mask");
2290
2291 /*
2292 # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
2293 # objects that have been registered with the nameserver after login.
2294 */
2295 LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
2296 "Deregister nameserver objects before LOGO");
2297
2298 /*
2299 # lun_queue_depth: This parameter is used to limit the number of outstanding
2300 # commands per FCP LUN. Value range is [1,128]. Default value is 30.
2301 */
2302 LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
2303 "Max number of FCP commands we can queue to a specific LUN");
2304
2305 /*
2306 # tgt_queue_depth: This parameter is used to limit the number of outstanding
2307 # commands per target port. Value range is [10,65535]. Default value is 65535.
2308 */
2309 LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535,
2310 "Max number of FCP commands we can queue to a specific target port");
2311
2312 /*
2313 # hba_queue_depth: This parameter is used to limit the number of outstanding
2314 # commands per lpfc HBA. Value range is [32,8192]. If this parameter
2315 # value is greater than the maximum number of exchanges supported by the HBA,
2316 # then maximum number of exchanges supported by the HBA is used to determine
2317 # the hba_queue_depth.
2318 */
2319 LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
2320 "Max number of FCP commands we can queue to a lpfc HBA");
2321
2322 /*
2323 # peer_port_login: This parameter allows/prevents logins
2324 # between peer ports hosted on the same physical port.
2325 # When this parameter is set 0 peer ports of same physical port
2326 # are not allowed to login to each other.
2327 # When this parameter is set 1 peer ports of same physical port
2328 # are allowed to login to each other.
2329 # Default value of this parameter is 0.
2330 */
2331 LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
2332 "Allow peer ports on the same physical port to login to each "
2333 "other.");
2334
2335 /*
2336 # restrict_login: This parameter allows/prevents logins
2337 # between Virtual Ports and remote initiators.
2338 # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
2339 # other initiators and will attempt to PLOGI all remote ports.
2340 # When this parameter is set (1) Virtual Ports will reject PLOGIs from
2341 # remote ports and will not attempt to PLOGI to other initiators.
2342 # This parameter does not restrict to the physical port.
2343 # This parameter does not restrict logins to Fabric resident remote ports.
2344 # Default value of this parameter is 1.
2345 */
2346 static int lpfc_restrict_login = 1;
2347 module_param(lpfc_restrict_login, int, S_IRUGO);
2348 MODULE_PARM_DESC(lpfc_restrict_login,
2349 "Restrict virtual ports login to remote initiators.");
2350 lpfc_vport_param_show(restrict_login);
2351
2352 /**
2353 * lpfc_restrict_login_init - Set the vport restrict login flag
2354 * @vport: lpfc vport structure pointer.
2355 * @val: contains the restrict login value.
2356 *
2357 * Description:
2358 * If val is not in a valid range then log a kernel error message and set
2359 * the vport restrict login to one.
2360 * If the port type is physical clear the restrict login flag and return.
2361 * Else set the restrict login flag to val.
2362 *
2363 * Returns:
2364 * zero if val is in range
2365 * -EINVAL val out of range
2366 **/
2367 static int
2368 lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
2369 {
2370 if (val < 0 || val > 1) {
2371 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2372 "0422 lpfc_restrict_login attribute cannot "
2373 "be set to %d, allowed range is [0, 1]\n",
2374 val);
2375 vport->cfg_restrict_login = 1;
2376 return -EINVAL;
2377 }
2378 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2379 vport->cfg_restrict_login = 0;
2380 return 0;
2381 }
2382 vport->cfg_restrict_login = val;
2383 return 0;
2384 }
2385
2386 /**
2387 * lpfc_restrict_login_set - Set the vport restrict login flag
2388 * @vport: lpfc vport structure pointer.
2389 * @val: contains the restrict login value.
2390 *
2391 * Description:
2392 * If val is not in a valid range then log a kernel error message and set
2393 * the vport restrict login to one.
2394 * If the port type is physical and the val is not zero log a kernel
2395 * error message, clear the restrict login flag and return zero.
2396 * Else set the restrict login flag to val.
2397 *
2398 * Returns:
2399 * zero if val is in range
2400 * -EINVAL val out of range
2401 **/
2402 static int
2403 lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
2404 {
2405 if (val < 0 || val > 1) {
2406 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2407 "0425 lpfc_restrict_login attribute cannot "
2408 "be set to %d, allowed range is [0, 1]\n",
2409 val);
2410 vport->cfg_restrict_login = 1;
2411 return -EINVAL;
2412 }
2413 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
2414 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
2415 "0468 lpfc_restrict_login must be 0 for "
2416 "Physical ports.\n");
2417 vport->cfg_restrict_login = 0;
2418 return 0;
2419 }
2420 vport->cfg_restrict_login = val;
2421 return 0;
2422 }
2423 lpfc_vport_param_store(restrict_login);
2424 static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
2425 lpfc_restrict_login_show, lpfc_restrict_login_store);
2426
2427 /*
2428 # Some disk devices have a "select ID" or "select Target" capability.
2429 # From a protocol standpoint "select ID" usually means select the
2430 # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
2431 # annex" which contains a table that maps a "select ID" (a number
2432 # between 0 and 7F) to an ALPA. By default, for compatibility with
2433 # older drivers, the lpfc driver scans this table from low ALPA to high
2434 # ALPA.
2435 #
2436 # Turning on the scan-down variable (on = 1, off = 0) will
2437 # cause the lpfc driver to use an inverted table, effectively
2438 # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
2439 #
2440 # (Note: This "select ID" functionality is a LOOP ONLY characteristic
2441 # and will not work across a fabric. Also this parameter will take
2442 # effect only in the case when ALPA map is not available.)
2443 */
2444 LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
2445 "Start scanning for devices from highest ALPA to lowest");
2446
2447 /*
2448 # lpfc_topology: link topology for init link
2449 # 0x0 = attempt loop mode then point-to-point
2450 # 0x01 = internal loopback mode
2451 # 0x02 = attempt point-to-point mode only
2452 # 0x04 = attempt loop mode only
2453 # 0x06 = attempt point-to-point mode then loop
2454 # Set point-to-point mode if you want to run as an N_Port.
2455 # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
2456 # Default value is 0.
2457 */
2458
2459 /**
2460 * lpfc_topology_set - Set the adapters topology field
2461 * @phba: lpfc_hba pointer.
2462 * @val: topology value.
2463 *
2464 * Description:
2465 * If val is in a valid range then set the adapter's topology field and
2466 * issue a lip; if the lip fails reset the topology to the old value.
2467 *
2468 * If the value is not in range log a kernel error message and return an error.
2469 *
2470 * Returns:
2471 * zero if val is in range and lip okay
2472 * non-zero return value from lpfc_issue_lip()
2473 * -EINVAL val out of range
2474 **/
2475 static ssize_t
2476 lpfc_topology_store(struct device *dev, struct device_attribute *attr,
2477 const char *buf, size_t count)
2478 {
2479 struct Scsi_Host *shost = class_to_shost(dev);
2480 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2481 struct lpfc_hba *phba = vport->phba;
2482 int val = 0;
2483 int nolip = 0;
2484 const char *val_buf = buf;
2485 int err;
2486 uint32_t prev_val;
2487
2488 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2489 nolip = 1;
2490 val_buf = &buf[strlen("nolip ")];
2491 }
2492
2493 if (!isdigit(val_buf[0]))
2494 return -EINVAL;
2495 if (sscanf(val_buf, "%i", &val) != 1)
2496 return -EINVAL;
2497
2498 if (val >= 0 && val <= 6) {
2499 prev_val = phba->cfg_topology;
2500 phba->cfg_topology = val;
2501 if (nolip)
2502 return strlen(buf);
2503
2504 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2505 if (err) {
2506 phba->cfg_topology = prev_val;
2507 return -EINVAL;
2508 } else
2509 return strlen(buf);
2510 }
2511 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2512 "%d:0467 lpfc_topology attribute cannot be set to %d, "
2513 "allowed range is [0, 6]\n",
2514 phba->brd_no, val);
2515 return -EINVAL;
2516 }
2517 static int lpfc_topology = 0;
2518 module_param(lpfc_topology, int, S_IRUGO);
2519 MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
2520 lpfc_param_show(topology)
2521 lpfc_param_init(topology, 0, 0, 6)
2522 static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
2523 lpfc_topology_show, lpfc_topology_store);
2524
2525 /**
2526 * lpfc_static_vport_show: Read callback function for
2527 * lpfc_static_vport sysfs file.
2528 * @dev: Pointer to class device object.
2529 * @attr: device attribute structure.
2530 * @buf: Data buffer.
2531 *
2532 * This function is the read call back function for
2533 * lpfc_static_vport sysfs file. The lpfc_static_vport
2534 * sysfs file report the mageability of the vport.
2535 **/
2536 static ssize_t
2537 lpfc_static_vport_show(struct device *dev, struct device_attribute *attr,
2538 char *buf)
2539 {
2540 struct Scsi_Host *shost = class_to_shost(dev);
2541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2542 if (vport->vport_flag & STATIC_VPORT)
2543 sprintf(buf, "1\n");
2544 else
2545 sprintf(buf, "0\n");
2546
2547 return strlen(buf);
2548 }
2549
2550 /*
2551 * Sysfs attribute to control the statistical data collection.
2552 */
2553 static DEVICE_ATTR(lpfc_static_vport, S_IRUGO,
2554 lpfc_static_vport_show, NULL);
2555
2556 /**
2557 * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file
2558 * @dev: Pointer to class device.
2559 * @buf: Data buffer.
2560 * @count: Size of the data buffer.
2561 *
2562 * This function get called when an user write to the lpfc_stat_data_ctrl
2563 * sysfs file. This function parse the command written to the sysfs file
2564 * and take appropriate action. These commands are used for controlling
2565 * driver statistical data collection.
2566 * Following are the command this function handles.
2567 *
2568 * setbucket <bucket_type> <base> <step>
2569 * = Set the latency buckets.
2570 * destroybucket = destroy all the buckets.
2571 * start = start data collection
2572 * stop = stop data collection
2573 * reset = reset the collected data
2574 **/
2575 static ssize_t
2576 lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr,
2577 const char *buf, size_t count)
2578 {
2579 struct Scsi_Host *shost = class_to_shost(dev);
2580 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2581 struct lpfc_hba *phba = vport->phba;
2582 #define LPFC_MAX_DATA_CTRL_LEN 1024
2583 static char bucket_data[LPFC_MAX_DATA_CTRL_LEN];
2584 unsigned long i;
2585 char *str_ptr, *token;
2586 struct lpfc_vport **vports;
2587 struct Scsi_Host *v_shost;
2588 char *bucket_type_str, *base_str, *step_str;
2589 unsigned long base, step, bucket_type;
2590
2591 if (!strncmp(buf, "setbucket", strlen("setbucket"))) {
2592 if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1))
2593 return -EINVAL;
2594
2595 strcpy(bucket_data, buf);
2596 str_ptr = &bucket_data[0];
2597 /* Ignore this token - this is command token */
2598 token = strsep(&str_ptr, "\t ");
2599 if (!token)
2600 return -EINVAL;
2601
2602 bucket_type_str = strsep(&str_ptr, "\t ");
2603 if (!bucket_type_str)
2604 return -EINVAL;
2605
2606 if (!strncmp(bucket_type_str, "linear", strlen("linear")))
2607 bucket_type = LPFC_LINEAR_BUCKET;
2608 else if (!strncmp(bucket_type_str, "power2", strlen("power2")))
2609 bucket_type = LPFC_POWER2_BUCKET;
2610 else
2611 return -EINVAL;
2612
2613 base_str = strsep(&str_ptr, "\t ");
2614 if (!base_str)
2615 return -EINVAL;
2616 base = simple_strtoul(base_str, NULL, 0);
2617
2618 step_str = strsep(&str_ptr, "\t ");
2619 if (!step_str)
2620 return -EINVAL;
2621 step = simple_strtoul(step_str, NULL, 0);
2622 if (!step)
2623 return -EINVAL;
2624
2625 /* Block the data collection for every vport */
2626 vports = lpfc_create_vport_work_array(phba);
2627 if (vports == NULL)
2628 return -ENOMEM;
2629
2630 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2631 v_shost = lpfc_shost_from_vport(vports[i]);
2632 spin_lock_irq(v_shost->host_lock);
2633 /* Block and reset data collection */
2634 vports[i]->stat_data_blocked = 1;
2635 if (vports[i]->stat_data_enabled)
2636 lpfc_vport_reset_stat_data(vports[i]);
2637 spin_unlock_irq(v_shost->host_lock);
2638 }
2639
2640 /* Set the bucket attributes */
2641 phba->bucket_type = bucket_type;
2642 phba->bucket_base = base;
2643 phba->bucket_step = step;
2644
2645 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2646 v_shost = lpfc_shost_from_vport(vports[i]);
2647
2648 /* Unblock data collection */
2649 spin_lock_irq(v_shost->host_lock);
2650 vports[i]->stat_data_blocked = 0;
2651 spin_unlock_irq(v_shost->host_lock);
2652 }
2653 lpfc_destroy_vport_work_array(phba, vports);
2654 return strlen(buf);
2655 }
2656
2657 if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) {
2658 vports = lpfc_create_vport_work_array(phba);
2659 if (vports == NULL)
2660 return -ENOMEM;
2661
2662 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2663 v_shost = lpfc_shost_from_vport(vports[i]);
2664 spin_lock_irq(shost->host_lock);
2665 vports[i]->stat_data_blocked = 1;
2666 lpfc_free_bucket(vport);
2667 vport->stat_data_enabled = 0;
2668 vports[i]->stat_data_blocked = 0;
2669 spin_unlock_irq(shost->host_lock);
2670 }
2671 lpfc_destroy_vport_work_array(phba, vports);
2672 phba->bucket_type = LPFC_NO_BUCKET;
2673 phba->bucket_base = 0;
2674 phba->bucket_step = 0;
2675 return strlen(buf);
2676 }
2677
2678 if (!strncmp(buf, "start", strlen("start"))) {
2679 /* If no buckets configured return error */
2680 if (phba->bucket_type == LPFC_NO_BUCKET)
2681 return -EINVAL;
2682 spin_lock_irq(shost->host_lock);
2683 if (vport->stat_data_enabled) {
2684 spin_unlock_irq(shost->host_lock);
2685 return strlen(buf);
2686 }
2687 lpfc_alloc_bucket(vport);
2688 vport->stat_data_enabled = 1;
2689 spin_unlock_irq(shost->host_lock);
2690 return strlen(buf);
2691 }
2692
2693 if (!strncmp(buf, "stop", strlen("stop"))) {
2694 spin_lock_irq(shost->host_lock);
2695 if (vport->stat_data_enabled == 0) {
2696 spin_unlock_irq(shost->host_lock);
2697 return strlen(buf);
2698 }
2699 lpfc_free_bucket(vport);
2700 vport->stat_data_enabled = 0;
2701 spin_unlock_irq(shost->host_lock);
2702 return strlen(buf);
2703 }
2704
2705 if (!strncmp(buf, "reset", strlen("reset"))) {
2706 if ((phba->bucket_type == LPFC_NO_BUCKET)
2707 || !vport->stat_data_enabled)
2708 return strlen(buf);
2709 spin_lock_irq(shost->host_lock);
2710 vport->stat_data_blocked = 1;
2711 lpfc_vport_reset_stat_data(vport);
2712 vport->stat_data_blocked = 0;
2713 spin_unlock_irq(shost->host_lock);
2714 return strlen(buf);
2715 }
2716 return -EINVAL;
2717 }
2718
2719
2720 /**
2721 * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file
2722 * @dev: Pointer to class device object.
2723 * @buf: Data buffer.
2724 *
2725 * This function is the read call back function for
2726 * lpfc_stat_data_ctrl sysfs file. This function report the
2727 * current statistical data collection state.
2728 **/
2729 static ssize_t
2730 lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr,
2731 char *buf)
2732 {
2733 struct Scsi_Host *shost = class_to_shost(dev);
2734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2735 struct lpfc_hba *phba = vport->phba;
2736 int index = 0;
2737 int i;
2738 char *bucket_type;
2739 unsigned long bucket_value;
2740
2741 switch (phba->bucket_type) {
2742 case LPFC_LINEAR_BUCKET:
2743 bucket_type = "linear";
2744 break;
2745 case LPFC_POWER2_BUCKET:
2746 bucket_type = "power2";
2747 break;
2748 default:
2749 bucket_type = "No Bucket";
2750 break;
2751 }
2752
2753 sprintf(&buf[index], "Statistical Data enabled :%d, "
2754 "blocked :%d, Bucket type :%s, Bucket base :%d,"
2755 " Bucket step :%d\nLatency Ranges :",
2756 vport->stat_data_enabled, vport->stat_data_blocked,
2757 bucket_type, phba->bucket_base, phba->bucket_step);
2758 index = strlen(buf);
2759 if (phba->bucket_type != LPFC_NO_BUCKET) {
2760 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2761 if (phba->bucket_type == LPFC_LINEAR_BUCKET)
2762 bucket_value = phba->bucket_base +
2763 phba->bucket_step * i;
2764 else
2765 bucket_value = phba->bucket_base +
2766 (1 << i) * phba->bucket_step;
2767
2768 if (index + 10 > PAGE_SIZE)
2769 break;
2770 sprintf(&buf[index], "%08ld ", bucket_value);
2771 index = strlen(buf);
2772 }
2773 }
2774 sprintf(&buf[index], "\n");
2775 return strlen(buf);
2776 }
2777
2778 /*
2779 * Sysfs attribute to control the statistical data collection.
2780 */
2781 static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR,
2782 lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store);
2783
2784 /*
2785 * lpfc_drvr_stat_data: sysfs attr to get driver statistical data.
2786 */
2787
2788 /*
2789 * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN
2790 * for each target.
2791 */
2792 #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18)
2793 #define MAX_STAT_DATA_SIZE_PER_TARGET \
2794 STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT)
2795
2796
2797 /**
2798 * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute
2799 * @filp: sysfs file
2800 * @kobj: Pointer to the kernel object
2801 * @bin_attr: Attribute object
2802 * @buff: Buffer pointer
2803 * @off: File offset
2804 * @count: Buffer size
2805 *
2806 * This function is the read call back function for lpfc_drvr_stat_data
2807 * sysfs file. This function export the statistical data to user
2808 * applications.
2809 **/
2810 static ssize_t
2811 sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj,
2812 struct bin_attribute *bin_attr,
2813 char *buf, loff_t off, size_t count)
2814 {
2815 struct device *dev = container_of(kobj, struct device,
2816 kobj);
2817 struct Scsi_Host *shost = class_to_shost(dev);
2818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2819 struct lpfc_hba *phba = vport->phba;
2820 int i = 0, index = 0;
2821 unsigned long nport_index;
2822 struct lpfc_nodelist *ndlp = NULL;
2823 nport_index = (unsigned long)off /
2824 MAX_STAT_DATA_SIZE_PER_TARGET;
2825
2826 if (!vport->stat_data_enabled || vport->stat_data_blocked
2827 || (phba->bucket_type == LPFC_NO_BUCKET))
2828 return 0;
2829
2830 spin_lock_irq(shost->host_lock);
2831 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2832 if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data)
2833 continue;
2834
2835 if (nport_index > 0) {
2836 nport_index--;
2837 continue;
2838 }
2839
2840 if ((index + MAX_STAT_DATA_SIZE_PER_TARGET)
2841 > count)
2842 break;
2843
2844 if (!ndlp->lat_data)
2845 continue;
2846
2847 /* Print the WWN */
2848 sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:",
2849 ndlp->nlp_portname.u.wwn[0],
2850 ndlp->nlp_portname.u.wwn[1],
2851 ndlp->nlp_portname.u.wwn[2],
2852 ndlp->nlp_portname.u.wwn[3],
2853 ndlp->nlp_portname.u.wwn[4],
2854 ndlp->nlp_portname.u.wwn[5],
2855 ndlp->nlp_portname.u.wwn[6],
2856 ndlp->nlp_portname.u.wwn[7]);
2857
2858 index = strlen(buf);
2859
2860 for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) {
2861 sprintf(&buf[index], "%010u,",
2862 ndlp->lat_data[i].cmd_count);
2863 index = strlen(buf);
2864 }
2865 sprintf(&buf[index], "\n");
2866 index = strlen(buf);
2867 }
2868 spin_unlock_irq(shost->host_lock);
2869 return index;
2870 }
2871
2872 static struct bin_attribute sysfs_drvr_stat_data_attr = {
2873 .attr = {
2874 .name = "lpfc_drvr_stat_data",
2875 .mode = S_IRUSR,
2876 },
2877 .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET,
2878 .read = sysfs_drvr_stat_data_read,
2879 .write = NULL,
2880 };
2881
2882 /*
2883 # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
2884 # connection.
2885 # Value range is [0,16]. Default value is 0.
2886 */
2887 /**
2888 * lpfc_link_speed_set - Set the adapters link speed
2889 * @phba: lpfc_hba pointer.
2890 * @val: link speed value.
2891 *
2892 * Description:
2893 * If val is in a valid range then set the adapter's link speed field and
2894 * issue a lip; if the lip fails reset the link speed to the old value.
2895 *
2896 * Notes:
2897 * If the value is not in range log a kernel error message and return an error.
2898 *
2899 * Returns:
2900 * zero if val is in range and lip okay.
2901 * non-zero return value from lpfc_issue_lip()
2902 * -EINVAL val out of range
2903 **/
2904 static ssize_t
2905 lpfc_link_speed_store(struct device *dev, struct device_attribute *attr,
2906 const char *buf, size_t count)
2907 {
2908 struct Scsi_Host *shost = class_to_shost(dev);
2909 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2910 struct lpfc_hba *phba = vport->phba;
2911 int val = LPFC_USER_LINK_SPEED_AUTO;
2912 int nolip = 0;
2913 const char *val_buf = buf;
2914 int err;
2915 uint32_t prev_val;
2916
2917 if (!strncmp(buf, "nolip ", strlen("nolip "))) {
2918 nolip = 1;
2919 val_buf = &buf[strlen("nolip ")];
2920 }
2921
2922 if (!isdigit(val_buf[0]))
2923 return -EINVAL;
2924 if (sscanf(val_buf, "%i", &val) != 1)
2925 return -EINVAL;
2926
2927 if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
2928 ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
2929 ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
2930 ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
2931 ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) ||
2932 ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb))) {
2933 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2934 "2879 lpfc_link_speed attribute cannot be set "
2935 "to %d. Speed is not supported by this port.\n",
2936 val);
2937 return -EINVAL;
2938 }
2939 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2940 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2941 prev_val = phba->cfg_link_speed;
2942 phba->cfg_link_speed = val;
2943 if (nolip)
2944 return strlen(buf);
2945
2946 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
2947 if (err) {
2948 phba->cfg_link_speed = prev_val;
2949 return -EINVAL;
2950 } else
2951 return strlen(buf);
2952 }
2953 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2954 "0469 lpfc_link_speed attribute cannot be set to %d, "
2955 "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val);
2956 return -EINVAL;
2957 }
2958
2959 static int lpfc_link_speed = 0;
2960 module_param(lpfc_link_speed, int, S_IRUGO);
2961 MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
2962 lpfc_param_show(link_speed)
2963
2964 /**
2965 * lpfc_link_speed_init - Set the adapters link speed
2966 * @phba: lpfc_hba pointer.
2967 * @val: link speed value.
2968 *
2969 * Description:
2970 * If val is in a valid range then set the adapter's link speed field.
2971 *
2972 * Notes:
2973 * If the value is not in range log a kernel error message, clear the link
2974 * speed and return an error.
2975 *
2976 * Returns:
2977 * zero if val saved.
2978 * -EINVAL val out of range
2979 **/
2980 static int
2981 lpfc_link_speed_init(struct lpfc_hba *phba, int val)
2982 {
2983 if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) &&
2984 (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) {
2985 phba->cfg_link_speed = val;
2986 return 0;
2987 }
2988 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2989 "0405 lpfc_link_speed attribute cannot "
2990 "be set to %d, allowed values are "
2991 "["LPFC_LINK_SPEED_STRING"]\n", val);
2992 phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO;
2993 return -EINVAL;
2994 }
2995
2996 static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
2997 lpfc_link_speed_show, lpfc_link_speed_store);
2998
2999 /*
3000 # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER)
3001 # 0 = aer disabled or not supported
3002 # 1 = aer supported and enabled (default)
3003 # Value range is [0,1]. Default value is 1.
3004 */
3005
3006 /**
3007 * lpfc_aer_support_store - Set the adapter for aer support
3008 *
3009 * @dev: class device that is converted into a Scsi_host.
3010 * @attr: device attribute, not used.
3011 * @buf: containing the string "selective".
3012 * @count: unused variable.
3013 *
3014 * Description:
3015 * If the val is 1 and currently the device's AER capability was not
3016 * enabled, invoke the kernel's enable AER helper routine, trying to
3017 * enable the device's AER capability. If the helper routine enabling
3018 * AER returns success, update the device's cfg_aer_support flag to
3019 * indicate AER is supported by the device; otherwise, if the device
3020 * AER capability is already enabled to support AER, then do nothing.
3021 *
3022 * If the val is 0 and currently the device's AER support was enabled,
3023 * invoke the kernel's disable AER helper routine. After that, update
3024 * the device's cfg_aer_support flag to indicate AER is not supported
3025 * by the device; otherwise, if the device AER capability is already
3026 * disabled from supporting AER, then do nothing.
3027 *
3028 * Returns:
3029 * length of the buf on success if val is in range the intended mode
3030 * is supported.
3031 * -EINVAL if val out of range or intended mode is not supported.
3032 **/
3033 static ssize_t
3034 lpfc_aer_support_store(struct device *dev, struct device_attribute *attr,
3035 const char *buf, size_t count)
3036 {
3037 struct Scsi_Host *shost = class_to_shost(dev);
3038 struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata;
3039 struct lpfc_hba *phba = vport->phba;
3040 int val = 0, rc = -EINVAL;
3041
3042 if (!isdigit(buf[0]))
3043 return -EINVAL;
3044 if (sscanf(buf, "%i", &val) != 1)
3045 return -EINVAL;
3046
3047 switch (val) {
3048 case 0:
3049 if (phba->hba_flag & HBA_AER_ENABLED) {
3050 rc = pci_disable_pcie_error_reporting(phba->pcidev);
3051 if (!rc) {
3052 spin_lock_irq(&phba->hbalock);
3053 phba->hba_flag &= ~HBA_AER_ENABLED;
3054 spin_unlock_irq(&phba->hbalock);
3055 phba->cfg_aer_support = 0;
3056 rc = strlen(buf);
3057 } else
3058 rc = -EPERM;
3059 } else {
3060 phba->cfg_aer_support = 0;
3061 rc = strlen(buf);
3062 }
3063 break;
3064 case 1:
3065 if (!(phba->hba_flag & HBA_AER_ENABLED)) {
3066 rc = pci_enable_pcie_error_reporting(phba->pcidev);
3067 if (!rc) {
3068 spin_lock_irq(&phba->hbalock);
3069 phba->hba_flag |= HBA_AER_ENABLED;
3070 spin_unlock_irq(&phba->hbalock);
3071 phba->cfg_aer_support = 1;
3072 rc = strlen(buf);
3073 } else
3074 rc = -EPERM;
3075 } else {
3076 phba->cfg_aer_support = 1;
3077 rc = strlen(buf);
3078 }
3079 break;
3080 default:
3081 rc = -EINVAL;
3082 break;
3083 }
3084 return rc;
3085 }
3086
3087 static int lpfc_aer_support = 1;
3088 module_param(lpfc_aer_support, int, S_IRUGO);
3089 MODULE_PARM_DESC(lpfc_aer_support, "Enable PCIe device AER support");
3090 lpfc_param_show(aer_support)
3091
3092 /**
3093 * lpfc_aer_support_init - Set the initial adapters aer support flag
3094 * @phba: lpfc_hba pointer.
3095 * @val: link speed value.
3096 *
3097 * Description:
3098 * If val is in a valid range [0,1], then set the adapter's initial
3099 * cfg_aer_support field. It will be up to the driver's probe_one
3100 * routine to determine whether the device's AER support can be set
3101 * or not.
3102 *
3103 * Notes:
3104 * If the value is not in range log a kernel error message, and
3105 * choose the default value of setting AER support and return.
3106 *
3107 * Returns:
3108 * zero if val saved.
3109 * -EINVAL val out of range
3110 **/
3111 static int
3112 lpfc_aer_support_init(struct lpfc_hba *phba, int val)
3113 {
3114 if (val == 0 || val == 1) {
3115 phba->cfg_aer_support = val;
3116 return 0;
3117 }
3118 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3119 "2712 lpfc_aer_support attribute value %d out "
3120 "of range, allowed values are 0|1, setting it "
3121 "to default value of 1\n", val);
3122 /* By default, try to enable AER on a device */
3123 phba->cfg_aer_support = 1;
3124 return -EINVAL;
3125 }
3126
3127 static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR,
3128 lpfc_aer_support_show, lpfc_aer_support_store);
3129
3130 /**
3131 * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device
3132 * @dev: class device that is converted into a Scsi_host.
3133 * @attr: device attribute, not used.
3134 * @buf: containing the string "selective".
3135 * @count: unused variable.
3136 *
3137 * Description:
3138 * If the @buf contains 1 and the device currently has the AER support
3139 * enabled, then invokes the kernel AER helper routine
3140 * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable
3141 * error status register.
3142 *
3143 * Notes:
3144 *
3145 * Returns:
3146 * -EINVAL if the buf does not contain the 1 or the device is not currently
3147 * enabled with the AER support.
3148 **/
3149 static ssize_t
3150 lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr,
3151 const char *buf, size_t count)
3152 {
3153 struct Scsi_Host *shost = class_to_shost(dev);
3154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3155 struct lpfc_hba *phba = vport->phba;
3156 int val, rc = -1;
3157
3158 if (!isdigit(buf[0]))
3159 return -EINVAL;
3160 if (sscanf(buf, "%i", &val) != 1)
3161 return -EINVAL;
3162 if (val != 1)
3163 return -EINVAL;
3164
3165 if (phba->hba_flag & HBA_AER_ENABLED)
3166 rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev);
3167
3168 if (rc == 0)
3169 return strlen(buf);
3170 else
3171 return -EPERM;
3172 }
3173
3174 static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL,
3175 lpfc_aer_cleanup_state);
3176
3177 /*
3178 # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
3179 # Value range is [2,3]. Default value is 3.
3180 */
3181 LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
3182 "Select Fibre Channel class of service for FCP sequences");
3183
3184 /*
3185 # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
3186 # is [0,1]. Default value is 0.
3187 */
3188 LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
3189 "Use ADISC on rediscovery to authenticate FCP devices");
3190
3191 /*
3192 # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue
3193 # depth. Default value is 0. When the value of this parameter is zero the
3194 # SCSI command completion time is not used for controlling I/O queue depth. When
3195 # the parameter is set to a non-zero value, the I/O queue depth is controlled
3196 # to limit the I/O completion time to the parameter value.
3197 # The value is set in milliseconds.
3198 */
3199 static int lpfc_max_scsicmpl_time;
3200 module_param(lpfc_max_scsicmpl_time, int, S_IRUGO);
3201 MODULE_PARM_DESC(lpfc_max_scsicmpl_time,
3202 "Use command completion time to control queue depth");
3203 lpfc_vport_param_show(max_scsicmpl_time);
3204 lpfc_vport_param_init(max_scsicmpl_time, 0, 0, 60000);
3205 static int
3206 lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val)
3207 {
3208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3209 struct lpfc_nodelist *ndlp, *next_ndlp;
3210
3211 if (val == vport->cfg_max_scsicmpl_time)
3212 return 0;
3213 if ((val < 0) || (val > 60000))
3214 return -EINVAL;
3215 vport->cfg_max_scsicmpl_time = val;
3216
3217 spin_lock_irq(shost->host_lock);
3218 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
3219 if (!NLP_CHK_NODE_ACT(ndlp))
3220 continue;
3221 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3222 continue;
3223 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3224 }
3225 spin_unlock_irq(shost->host_lock);
3226 return 0;
3227 }
3228 lpfc_vport_param_store(max_scsicmpl_time);
3229 static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR,
3230 lpfc_max_scsicmpl_time_show,
3231 lpfc_max_scsicmpl_time_store);
3232
3233 /*
3234 # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
3235 # range is [0,1]. Default value is 0.
3236 */
3237 LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
3238
3239 /*
3240 # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
3241 # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
3242 # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
3243 # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
3244 # cr_delay is set to 0.
3245 */
3246 LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
3247 "interrupt response is generated");
3248
3249 LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
3250 "interrupt response is generated");
3251
3252 /*
3253 # lpfc_multi_ring_support: Determines how many rings to spread available
3254 # cmd/rsp IOCB entries across.
3255 # Value range is [1,2]. Default value is 1.
3256 */
3257 LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
3258 "SLI rings to spread IOCB entries across");
3259
3260 /*
3261 # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
3262 # identifies what rctl value to configure the additional ring for.
3263 # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
3264 */
3265 LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1,
3266 255, "Identifies RCTL for additional ring configuration");
3267
3268 /*
3269 # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
3270 # identifies what type value to configure the additional ring for.
3271 # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
3272 */
3273 LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1,
3274 255, "Identifies TYPE for additional ring configuration");
3275
3276 /*
3277 # lpfc_fdmi_on: controls FDMI support.
3278 # 0 = no FDMI support
3279 # 1 = support FDMI without attribute of hostname
3280 # 2 = support FDMI with attribute of hostname
3281 # Value range [0,2]. Default value is 0.
3282 */
3283 LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
3284
3285 /*
3286 # Specifies the maximum number of ELS cmds we can have outstanding (for
3287 # discovery). Value range is [1,64]. Default value = 32.
3288 */
3289 LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
3290 "during discovery");
3291
3292 /*
3293 # lpfc_max_luns: maximum allowed LUN.
3294 # Value range is [0,65535]. Default value is 255.
3295 # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
3296 */
3297 LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
3298
3299 /*
3300 # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
3301 # Value range is [1,255], default value is 10.
3302 */
3303 LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
3304 "Milliseconds driver will wait between polling FCP ring");
3305
3306 /*
3307 # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
3308 # support this feature
3309 # 0 = MSI disabled
3310 # 1 = MSI enabled
3311 # 2 = MSI-X enabled (default)
3312 # Value range is [0,2]. Default value is 2.
3313 */
3314 LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or "
3315 "MSI-X (2), if possible");
3316
3317 /*
3318 # lpfc_fcp_imax: Set the maximum number of fast-path FCP interrupts per second
3319 #
3320 # Value range is [636,651042]. Default value is 10000.
3321 */
3322 LPFC_ATTR_R(fcp_imax, LPFC_FP_DEF_IMAX, LPFC_MIM_IMAX, LPFC_DMULT_CONST,
3323 "Set the maximum number of fast-path FCP interrupts per second");
3324
3325 /*
3326 # lpfc_fcp_wq_count: Set the number of fast-path FCP work queues
3327 #
3328 # Value range is [1,31]. Default value is 4.
3329 */
3330 LPFC_ATTR_R(fcp_wq_count, LPFC_FP_WQN_DEF, LPFC_FP_WQN_MIN, LPFC_FP_WQN_MAX,
3331 "Set the number of fast-path FCP work queues, if possible");
3332
3333 /*
3334 # lpfc_fcp_eq_count: Set the number of fast-path FCP event queues
3335 #
3336 # Value range is [1,7]. Default value is 1.
3337 */
3338 LPFC_ATTR_R(fcp_eq_count, LPFC_FP_EQN_DEF, LPFC_FP_EQN_MIN, LPFC_FP_EQN_MAX,
3339 "Set the number of fast-path FCP event queues, if possible");
3340
3341 /*
3342 # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
3343 # 0 = HBA resets disabled
3344 # 1 = HBA resets enabled (default)
3345 # Value range is [0,1]. Default value is 1.
3346 */
3347 LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
3348
3349 /*
3350 # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer..
3351 # 0 = HBA Heartbeat disabled
3352 # 1 = HBA Heartbeat enabled (default)
3353 # Value range is [0,1]. Default value is 1.
3354 */
3355 LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat.");
3356
3357 /*
3358 # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF)
3359 # 0 = BlockGuard disabled (default)
3360 # 1 = BlockGuard enabled
3361 # Value range is [0,1]. Default value is 0.
3362 */
3363 LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support");
3364
3365 /*
3366 # lpfc_prot_mask: i
3367 # - Bit mask of host protection capabilities used to register with the
3368 # SCSI mid-layer
3369 # - Only meaningful if BG is turned on (lpfc_enable_bg=1).
3370 # - Allows you to ultimately specify which profiles to use
3371 # - Default will result in registering capabilities for all profiles.
3372 #
3373 */
3374 unsigned int lpfc_prot_mask = SHOST_DIF_TYPE1_PROTECTION;
3375
3376 module_param(lpfc_prot_mask, uint, S_IRUGO);
3377 MODULE_PARM_DESC(lpfc_prot_mask, "host protection mask");
3378
3379 /*
3380 # lpfc_prot_guard: i
3381 # - Bit mask of protection guard types to register with the SCSI mid-layer
3382 # - Guard types are currently either 1) IP checksum 2) T10-DIF CRC
3383 # - Allows you to ultimately specify which profiles to use
3384 # - Default will result in registering capabilities for all guard types
3385 #
3386 */
3387 unsigned char lpfc_prot_guard = SHOST_DIX_GUARD_IP;
3388 module_param(lpfc_prot_guard, byte, S_IRUGO);
3389 MODULE_PARM_DESC(lpfc_prot_guard, "host protection guard type");
3390
3391 /*
3392 * Delay initial NPort discovery when Clean Address bit is cleared in
3393 * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed.
3394 * This parameter can have value 0 or 1.
3395 * When this parameter is set to 0, no delay is added to the initial
3396 * discovery.
3397 * When this parameter is set to non-zero value, initial Nport discovery is
3398 * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC
3399 * accept and FCID/Fabric name/Fabric portname is changed.
3400 * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion
3401 * when Clean Address bit is cleared in FLOGI/FDISC
3402 * accept and FCID/Fabric name/Fabric portname is changed.
3403 * Default value is 0.
3404 */
3405 int lpfc_delay_discovery;
3406 module_param(lpfc_delay_discovery, int, S_IRUGO);
3407 MODULE_PARM_DESC(lpfc_delay_discovery,
3408 "Delay NPort discovery when Clean Address bit is cleared. "
3409 "Allowed values: 0,1.");
3410
3411 /*
3412 * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count
3413 * This value can be set to values between 64 and 256. The default value is
3414 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
3415 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
3416 */
3417 LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
3418 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
3419
3420 LPFC_ATTR_R(prot_sg_seg_cnt, LPFC_DEFAULT_PROT_SG_SEG_CNT,
3421 LPFC_DEFAULT_PROT_SG_SEG_CNT, LPFC_MAX_PROT_SG_SEG_CNT,
3422 "Max Protection Scatter Gather Segment Count");
3423
3424 struct device_attribute *lpfc_hba_attrs[] = {
3425 &dev_attr_bg_info,
3426 &dev_attr_bg_guard_err,
3427 &dev_attr_bg_apptag_err,
3428 &dev_attr_bg_reftag_err,
3429 &dev_attr_info,
3430 &dev_attr_serialnum,
3431 &dev_attr_modeldesc,
3432 &dev_attr_modelname,
3433 &dev_attr_programtype,
3434 &dev_attr_portnum,
3435 &dev_attr_fwrev,
3436 &dev_attr_hdw,
3437 &dev_attr_option_rom_version,
3438 &dev_attr_link_state,
3439 &dev_attr_num_discovered_ports,
3440 &dev_attr_menlo_mgmt_mode,
3441 &dev_attr_lpfc_drvr_version,
3442 &dev_attr_lpfc_enable_fip,
3443 &dev_attr_lpfc_temp_sensor,
3444 &dev_attr_lpfc_log_verbose,
3445 &dev_attr_lpfc_lun_queue_depth,
3446 &dev_attr_lpfc_tgt_queue_depth,
3447 &dev_attr_lpfc_hba_queue_depth,
3448 &dev_attr_lpfc_peer_port_login,
3449 &dev_attr_lpfc_nodev_tmo,
3450 &dev_attr_lpfc_devloss_tmo,
3451 &dev_attr_lpfc_fcp_class,
3452 &dev_attr_lpfc_use_adisc,
3453 &dev_attr_lpfc_ack0,
3454 &dev_attr_lpfc_topology,
3455 &dev_attr_lpfc_scan_down,
3456 &dev_attr_lpfc_link_speed,
3457 &dev_attr_lpfc_cr_delay,
3458 &dev_attr_lpfc_cr_count,
3459 &dev_attr_lpfc_multi_ring_support,
3460 &dev_attr_lpfc_multi_ring_rctl,
3461 &dev_attr_lpfc_multi_ring_type,
3462 &dev_attr_lpfc_fdmi_on,
3463 &dev_attr_lpfc_max_luns,
3464 &dev_attr_lpfc_enable_npiv,
3465 &dev_attr_lpfc_enable_rrq,
3466 &dev_attr_nport_evt_cnt,
3467 &dev_attr_board_mode,
3468 &dev_attr_max_vpi,
3469 &dev_attr_used_vpi,
3470 &dev_attr_max_rpi,
3471 &dev_attr_used_rpi,
3472 &dev_attr_max_xri,
3473 &dev_attr_used_xri,
3474 &dev_attr_npiv_info,
3475 &dev_attr_issue_reset,
3476 &dev_attr_lpfc_poll,
3477 &dev_attr_lpfc_poll_tmo,
3478 &dev_attr_lpfc_use_msi,
3479 &dev_attr_lpfc_fcp_imax,
3480 &dev_attr_lpfc_fcp_wq_count,
3481 &dev_attr_lpfc_fcp_eq_count,
3482 &dev_attr_lpfc_enable_bg,
3483 &dev_attr_lpfc_soft_wwnn,
3484 &dev_attr_lpfc_soft_wwpn,
3485 &dev_attr_lpfc_soft_wwn_enable,
3486 &dev_attr_lpfc_enable_hba_reset,
3487 &dev_attr_lpfc_enable_hba_heartbeat,
3488 &dev_attr_lpfc_sg_seg_cnt,
3489 &dev_attr_lpfc_max_scsicmpl_time,
3490 &dev_attr_lpfc_stat_data_ctrl,
3491 &dev_attr_lpfc_prot_sg_seg_cnt,
3492 &dev_attr_lpfc_aer_support,
3493 &dev_attr_lpfc_aer_state_cleanup,
3494 &dev_attr_lpfc_suppress_link_up,
3495 &dev_attr_lpfc_iocb_cnt,
3496 &dev_attr_iocb_hw,
3497 &dev_attr_txq_hw,
3498 &dev_attr_txcmplq_hw,
3499 &dev_attr_lpfc_fips_level,
3500 &dev_attr_lpfc_fips_rev,
3501 &dev_attr_lpfc_dss,
3502 NULL,
3503 };
3504
3505 struct device_attribute *lpfc_vport_attrs[] = {
3506 &dev_attr_info,
3507 &dev_attr_link_state,
3508 &dev_attr_num_discovered_ports,
3509 &dev_attr_lpfc_drvr_version,
3510 &dev_attr_lpfc_log_verbose,
3511 &dev_attr_lpfc_lun_queue_depth,
3512 &dev_attr_lpfc_tgt_queue_depth,
3513 &dev_attr_lpfc_nodev_tmo,
3514 &dev_attr_lpfc_devloss_tmo,
3515 &dev_attr_lpfc_hba_queue_depth,
3516 &dev_attr_lpfc_peer_port_login,
3517 &dev_attr_lpfc_restrict_login,
3518 &dev_attr_lpfc_fcp_class,
3519 &dev_attr_lpfc_use_adisc,
3520 &dev_attr_lpfc_fdmi_on,
3521 &dev_attr_lpfc_max_luns,
3522 &dev_attr_nport_evt_cnt,
3523 &dev_attr_npiv_info,
3524 &dev_attr_lpfc_enable_da_id,
3525 &dev_attr_lpfc_max_scsicmpl_time,
3526 &dev_attr_lpfc_stat_data_ctrl,
3527 &dev_attr_lpfc_static_vport,
3528 &dev_attr_lpfc_fips_level,
3529 &dev_attr_lpfc_fips_rev,
3530 NULL,
3531 };
3532
3533 /**
3534 * sysfs_ctlreg_write - Write method for writing to ctlreg
3535 * @filp: open sysfs file
3536 * @kobj: kernel kobject that contains the kernel class device.
3537 * @bin_attr: kernel attributes passed to us.
3538 * @buf: contains the data to be written to the adapter IOREG space.
3539 * @off: offset into buffer to beginning of data.
3540 * @count: bytes to transfer.
3541 *
3542 * Description:
3543 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3544 * Uses the adapter io control registers to send buf contents to the adapter.
3545 *
3546 * Returns:
3547 * -ERANGE off and count combo out of range
3548 * -EINVAL off, count or buff address invalid
3549 * -EPERM adapter is offline
3550 * value of count, buf contents written
3551 **/
3552 static ssize_t
3553 sysfs_ctlreg_write(struct file *filp, struct kobject *kobj,
3554 struct bin_attribute *bin_attr,
3555 char *buf, loff_t off, size_t count)
3556 {
3557 size_t buf_off;
3558 struct device *dev = container_of(kobj, struct device, kobj);
3559 struct Scsi_Host *shost = class_to_shost(dev);
3560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3561 struct lpfc_hba *phba = vport->phba;
3562
3563 if (phba->sli_rev >= LPFC_SLI_REV4)
3564 return -EPERM;
3565
3566 if ((off + count) > FF_REG_AREA_SIZE)
3567 return -ERANGE;
3568
3569 if (count == 0) return 0;
3570
3571 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3572 return -EINVAL;
3573
3574 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3575 return -EPERM;
3576 }
3577
3578 spin_lock_irq(&phba->hbalock);
3579 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
3580 writel(*((uint32_t *)(buf + buf_off)),
3581 phba->ctrl_regs_memmap_p + off + buf_off);
3582
3583 spin_unlock_irq(&phba->hbalock);
3584
3585 return count;
3586 }
3587
3588 /**
3589 * sysfs_ctlreg_read - Read method for reading from ctlreg
3590 * @filp: open sysfs file
3591 * @kobj: kernel kobject that contains the kernel class device.
3592 * @bin_attr: kernel attributes passed to us.
3593 * @buf: if successful contains the data from the adapter IOREG space.
3594 * @off: offset into buffer to beginning of data.
3595 * @count: bytes to transfer.
3596 *
3597 * Description:
3598 * Accessed via /sys/class/scsi_host/hostxxx/ctlreg.
3599 * Uses the adapter io control registers to read data into buf.
3600 *
3601 * Returns:
3602 * -ERANGE off and count combo out of range
3603 * -EINVAL off, count or buff address invalid
3604 * value of count, buf contents read
3605 **/
3606 static ssize_t
3607 sysfs_ctlreg_read(struct file *filp, struct kobject *kobj,
3608 struct bin_attribute *bin_attr,
3609 char *buf, loff_t off, size_t count)
3610 {
3611 size_t buf_off;
3612 uint32_t * tmp_ptr;
3613 struct device *dev = container_of(kobj, struct device, kobj);
3614 struct Scsi_Host *shost = class_to_shost(dev);
3615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3616 struct lpfc_hba *phba = vport->phba;
3617
3618 if (phba->sli_rev >= LPFC_SLI_REV4)
3619 return -EPERM;
3620
3621 if (off > FF_REG_AREA_SIZE)
3622 return -ERANGE;
3623
3624 if ((off + count) > FF_REG_AREA_SIZE)
3625 count = FF_REG_AREA_SIZE - off;
3626
3627 if (count == 0) return 0;
3628
3629 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3630 return -EINVAL;
3631
3632 spin_lock_irq(&phba->hbalock);
3633
3634 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
3635 tmp_ptr = (uint32_t *)(buf + buf_off);
3636 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
3637 }
3638
3639 spin_unlock_irq(&phba->hbalock);
3640
3641 return count;
3642 }
3643
3644 static struct bin_attribute sysfs_ctlreg_attr = {
3645 .attr = {
3646 .name = "ctlreg",
3647 .mode = S_IRUSR | S_IWUSR,
3648 },
3649 .size = 256,
3650 .read = sysfs_ctlreg_read,
3651 .write = sysfs_ctlreg_write,
3652 };
3653
3654 /**
3655 * sysfs_mbox_idle - frees the sysfs mailbox
3656 * @phba: lpfc_hba pointer
3657 **/
3658 static void
3659 sysfs_mbox_idle(struct lpfc_hba *phba)
3660 {
3661 phba->sysfs_mbox.state = SMBOX_IDLE;
3662 phba->sysfs_mbox.offset = 0;
3663
3664 if (phba->sysfs_mbox.mbox) {
3665 mempool_free(phba->sysfs_mbox.mbox,
3666 phba->mbox_mem_pool);
3667 phba->sysfs_mbox.mbox = NULL;
3668 }
3669 }
3670
3671 /**
3672 * sysfs_mbox_write - Write method for writing information via mbox
3673 * @filp: open sysfs file
3674 * @kobj: kernel kobject that contains the kernel class device.
3675 * @bin_attr: kernel attributes passed to us.
3676 * @buf: contains the data to be written to sysfs mbox.
3677 * @off: offset into buffer to beginning of data.
3678 * @count: bytes to transfer.
3679 *
3680 * Description:
3681 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3682 * Uses the sysfs mbox to send buf contents to the adapter.
3683 *
3684 * Returns:
3685 * -ERANGE off and count combo out of range
3686 * -EINVAL off, count or buff address invalid
3687 * zero if count is zero
3688 * -EPERM adapter is offline
3689 * -ENOMEM failed to allocate memory for the mail box
3690 * -EAGAIN offset, state or mbox is NULL
3691 * count number of bytes transferred
3692 **/
3693 static ssize_t
3694 sysfs_mbox_write(struct file *filp, struct kobject *kobj,
3695 struct bin_attribute *bin_attr,
3696 char *buf, loff_t off, size_t count)
3697 {
3698 struct device *dev = container_of(kobj, struct device, kobj);
3699 struct Scsi_Host *shost = class_to_shost(dev);
3700 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3701 struct lpfc_hba *phba = vport->phba;
3702 struct lpfcMboxq *mbox = NULL;
3703
3704 if ((count + off) > MAILBOX_CMD_SIZE)
3705 return -ERANGE;
3706
3707 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3708 return -EINVAL;
3709
3710 if (count == 0)
3711 return 0;
3712
3713 if (off == 0) {
3714 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3715 if (!mbox)
3716 return -ENOMEM;
3717 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
3718 }
3719
3720 spin_lock_irq(&phba->hbalock);
3721
3722 if (off == 0) {
3723 if (phba->sysfs_mbox.mbox)
3724 mempool_free(mbox, phba->mbox_mem_pool);
3725 else
3726 phba->sysfs_mbox.mbox = mbox;
3727 phba->sysfs_mbox.state = SMBOX_WRITING;
3728 } else {
3729 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
3730 phba->sysfs_mbox.offset != off ||
3731 phba->sysfs_mbox.mbox == NULL) {
3732 sysfs_mbox_idle(phba);
3733 spin_unlock_irq(&phba->hbalock);
3734 return -EAGAIN;
3735 }
3736 }
3737
3738 memcpy((uint8_t *) &phba->sysfs_mbox.mbox->u.mb + off,
3739 buf, count);
3740
3741 phba->sysfs_mbox.offset = off + count;
3742
3743 spin_unlock_irq(&phba->hbalock);
3744
3745 return count;
3746 }
3747
3748 /**
3749 * sysfs_mbox_read - Read method for reading information via mbox
3750 * @filp: open sysfs file
3751 * @kobj: kernel kobject that contains the kernel class device.
3752 * @bin_attr: kernel attributes passed to us.
3753 * @buf: contains the data to be read from sysfs mbox.
3754 * @off: offset into buffer to beginning of data.
3755 * @count: bytes to transfer.
3756 *
3757 * Description:
3758 * Accessed via /sys/class/scsi_host/hostxxx/mbox.
3759 * Uses the sysfs mbox to receive data from to the adapter.
3760 *
3761 * Returns:
3762 * -ERANGE off greater than mailbox command size
3763 * -EINVAL off, count or buff address invalid
3764 * zero if off and count are zero
3765 * -EACCES adapter over temp
3766 * -EPERM garbage can value to catch a multitude of errors
3767 * -EAGAIN management IO not permitted, state or off error
3768 * -ETIME mailbox timeout
3769 * -ENODEV mailbox error
3770 * count number of bytes transferred
3771 **/
3772 static ssize_t
3773 sysfs_mbox_read(struct file *filp, struct kobject *kobj,
3774 struct bin_attribute *bin_attr,
3775 char *buf, loff_t off, size_t count)
3776 {
3777 struct device *dev = container_of(kobj, struct device, kobj);
3778 struct Scsi_Host *shost = class_to_shost(dev);
3779 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
3780 struct lpfc_hba *phba = vport->phba;
3781 int rc;
3782 MAILBOX_t *pmb;
3783
3784 if (off > MAILBOX_CMD_SIZE)
3785 return -ERANGE;
3786
3787 if ((count + off) > MAILBOX_CMD_SIZE)
3788 count = MAILBOX_CMD_SIZE - off;
3789
3790 if (off % 4 || count % 4 || (unsigned long)buf % 4)
3791 return -EINVAL;
3792
3793 if (off && count == 0)
3794 return 0;
3795
3796 spin_lock_irq(&phba->hbalock);
3797
3798 if (phba->over_temp_state == HBA_OVER_TEMP) {
3799 sysfs_mbox_idle(phba);
3800 spin_unlock_irq(&phba->hbalock);
3801 return -EACCES;
3802 }
3803
3804 if (off == 0 &&
3805 phba->sysfs_mbox.state == SMBOX_WRITING &&
3806 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
3807 pmb = &phba->sysfs_mbox.mbox->u.mb;
3808 switch (pmb->mbxCommand) {
3809 /* Offline only */
3810 case MBX_INIT_LINK:
3811 case MBX_DOWN_LINK:
3812 case MBX_CONFIG_LINK:
3813 case MBX_CONFIG_RING:
3814 case MBX_RESET_RING:
3815 case MBX_UNREG_LOGIN:
3816 case MBX_CLEAR_LA:
3817 case MBX_DUMP_CONTEXT:
3818 case MBX_RUN_DIAGS:
3819 case MBX_RESTART:
3820 case MBX_SET_MASK:
3821 case MBX_SET_DEBUG:
3822 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
3823 printk(KERN_WARNING "mbox_read:Command 0x%x "
3824 "is illegal in on-line state\n",
3825 pmb->mbxCommand);
3826 sysfs_mbox_idle(phba);
3827 spin_unlock_irq(&phba->hbalock);
3828 return -EPERM;
3829 }
3830 case MBX_WRITE_NV:
3831 case MBX_WRITE_VPARMS:
3832 case MBX_LOAD_SM:
3833 case MBX_READ_NV:
3834 case MBX_READ_CONFIG:
3835 case MBX_READ_RCONFIG:
3836 case MBX_READ_STATUS:
3837 case MBX_READ_XRI:
3838 case MBX_READ_REV:
3839 case MBX_READ_LNK_STAT:
3840 case MBX_DUMP_MEMORY:
3841 case MBX_DOWN_LOAD:
3842 case MBX_UPDATE_CFG:
3843 case MBX_KILL_BOARD:
3844 case MBX_LOAD_AREA:
3845 case MBX_LOAD_EXP_ROM:
3846 case MBX_BEACON:
3847 case MBX_DEL_LD_ENTRY:
3848 case MBX_SET_VARIABLE:
3849 case MBX_WRITE_WWN:
3850 case MBX_PORT_CAPABILITIES:
3851 case MBX_PORT_IOV_CONTROL:
3852 break;
3853 case MBX_SECURITY_MGMT:
3854 case MBX_AUTH_PORT:
3855 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
3856 printk(KERN_WARNING "mbox_read:Command 0x%x "
3857 "is not permitted\n", pmb->mbxCommand);
3858 sysfs_mbox_idle(phba);
3859 spin_unlock_irq(&phba->hbalock);
3860 return -EPERM;
3861 }
3862 break;
3863 case MBX_READ_SPARM64:
3864 case MBX_READ_TOPOLOGY:
3865 case MBX_REG_LOGIN:
3866 case MBX_REG_LOGIN64:
3867 case MBX_CONFIG_PORT:
3868 case MBX_RUN_BIU_DIAG:
3869 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
3870 pmb->mbxCommand);
3871 sysfs_mbox_idle(phba);
3872 spin_unlock_irq(&phba->hbalock);
3873 return -EPERM;
3874 default:
3875 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
3876 pmb->mbxCommand);
3877 sysfs_mbox_idle(phba);
3878 spin_unlock_irq(&phba->hbalock);
3879 return -EPERM;
3880 }
3881
3882 /* If HBA encountered an error attention, allow only DUMP
3883 * or RESTART mailbox commands until the HBA is restarted.
3884 */
3885 if (phba->pport->stopped &&
3886 pmb->mbxCommand != MBX_DUMP_MEMORY &&
3887 pmb->mbxCommand != MBX_RESTART &&
3888 pmb->mbxCommand != MBX_WRITE_VPARMS &&
3889 pmb->mbxCommand != MBX_WRITE_WWN)
3890 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
3891 "1259 mbox: Issued mailbox cmd "
3892 "0x%x while in stopped state.\n",
3893 pmb->mbxCommand);
3894
3895 phba->sysfs_mbox.mbox->vport = vport;
3896
3897 /* Don't allow mailbox commands to be sent when blocked
3898 * or when in the middle of discovery
3899 */
3900 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
3901 sysfs_mbox_idle(phba);
3902 spin_unlock_irq(&phba->hbalock);
3903 return -EAGAIN;
3904 }
3905
3906 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
3907 (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE))) {
3908
3909 spin_unlock_irq(&phba->hbalock);
3910 rc = lpfc_sli_issue_mbox (phba,
3911 phba->sysfs_mbox.mbox,
3912 MBX_POLL);
3913 spin_lock_irq(&phba->hbalock);
3914
3915 } else {
3916 spin_unlock_irq(&phba->hbalock);
3917 rc = lpfc_sli_issue_mbox_wait (phba,
3918 phba->sysfs_mbox.mbox,
3919 lpfc_mbox_tmo_val(phba, pmb->mbxCommand) * HZ);
3920 spin_lock_irq(&phba->hbalock);
3921 }
3922
3923 if (rc != MBX_SUCCESS) {
3924 if (rc == MBX_TIMEOUT) {
3925 phba->sysfs_mbox.mbox = NULL;
3926 }
3927 sysfs_mbox_idle(phba);
3928 spin_unlock_irq(&phba->hbalock);
3929 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
3930 }
3931 phba->sysfs_mbox.state = SMBOX_READING;
3932 }
3933 else if (phba->sysfs_mbox.offset != off ||
3934 phba->sysfs_mbox.state != SMBOX_READING) {
3935 printk(KERN_WARNING "mbox_read: Bad State\n");
3936 sysfs_mbox_idle(phba);
3937 spin_unlock_irq(&phba->hbalock);
3938 return -EAGAIN;
3939 }
3940
3941 memcpy(buf, (uint8_t *) &pmb + off, count);
3942
3943 phba->sysfs_mbox.offset = off + count;
3944
3945 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
3946 sysfs_mbox_idle(phba);
3947
3948 spin_unlock_irq(&phba->hbalock);
3949
3950 return count;
3951 }
3952
3953 static struct bin_attribute sysfs_mbox_attr = {
3954 .attr = {
3955 .name = "mbox",
3956 .mode = S_IRUSR | S_IWUSR,
3957 },
3958 .size = MAILBOX_CMD_SIZE,
3959 .read = sysfs_mbox_read,
3960 .write = sysfs_mbox_write,
3961 };
3962
3963 /**
3964 * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries
3965 * @vport: address of lpfc vport structure.
3966 *
3967 * Return codes:
3968 * zero on success
3969 * error return code from sysfs_create_bin_file()
3970 **/
3971 int
3972 lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
3973 {
3974 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3975 int error;
3976
3977 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3978 &sysfs_drvr_stat_data_attr);
3979
3980 /* Virtual ports do not need ctrl_reg and mbox */
3981 if (error || vport->port_type == LPFC_NPIV_PORT)
3982 goto out;
3983
3984 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3985 &sysfs_ctlreg_attr);
3986 if (error)
3987 goto out_remove_stat_attr;
3988
3989 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
3990 &sysfs_mbox_attr);
3991 if (error)
3992 goto out_remove_ctlreg_attr;
3993
3994 return 0;
3995 out_remove_ctlreg_attr:
3996 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
3997 out_remove_stat_attr:
3998 sysfs_remove_bin_file(&shost->shost_dev.kobj,
3999 &sysfs_drvr_stat_data_attr);
4000 out:
4001 return error;
4002 }
4003
4004 /**
4005 * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries
4006 * @vport: address of lpfc vport structure.
4007 **/
4008 void
4009 lpfc_free_sysfs_attr(struct lpfc_vport *vport)
4010 {
4011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4012 sysfs_remove_bin_file(&shost->shost_dev.kobj,
4013 &sysfs_drvr_stat_data_attr);
4014 /* Virtual ports do not need ctrl_reg and mbox */
4015 if (vport->port_type == LPFC_NPIV_PORT)
4016 return;
4017 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
4018 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
4019 }
4020
4021
4022 /*
4023 * Dynamic FC Host Attributes Support
4024 */
4025
4026 /**
4027 * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id
4028 * @shost: kernel scsi host pointer.
4029 **/
4030 static void
4031 lpfc_get_host_port_id(struct Scsi_Host *shost)
4032 {
4033 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4034
4035 /* note: fc_myDID already in cpu endianness */
4036 fc_host_port_id(shost) = vport->fc_myDID;
4037 }
4038
4039 /**
4040 * lpfc_get_host_port_type - Set the value of the scsi host port type
4041 * @shost: kernel scsi host pointer.
4042 **/
4043 static void
4044 lpfc_get_host_port_type(struct Scsi_Host *shost)
4045 {
4046 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4047 struct lpfc_hba *phba = vport->phba;
4048
4049 spin_lock_irq(shost->host_lock);
4050
4051 if (vport->port_type == LPFC_NPIV_PORT) {
4052 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
4053 } else if (lpfc_is_link_up(phba)) {
4054 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4055 if (vport->fc_flag & FC_PUBLIC_LOOP)
4056 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
4057 else
4058 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
4059 } else {
4060 if (vport->fc_flag & FC_FABRIC)
4061 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
4062 else
4063 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
4064 }
4065 } else
4066 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
4067
4068 spin_unlock_irq(shost->host_lock);
4069 }
4070
4071 /**
4072 * lpfc_get_host_port_state - Set the value of the scsi host port state
4073 * @shost: kernel scsi host pointer.
4074 **/
4075 static void
4076 lpfc_get_host_port_state(struct Scsi_Host *shost)
4077 {
4078 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4079 struct lpfc_hba *phba = vport->phba;
4080
4081 spin_lock_irq(shost->host_lock);
4082
4083 if (vport->fc_flag & FC_OFFLINE_MODE)
4084 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
4085 else {
4086 switch (phba->link_state) {
4087 case LPFC_LINK_UNKNOWN:
4088 case LPFC_LINK_DOWN:
4089 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
4090 break;
4091 case LPFC_LINK_UP:
4092 case LPFC_CLEAR_LA:
4093 case LPFC_HBA_READY:
4094 /* Links up, beyond this port_type reports state */
4095 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
4096 break;
4097 case LPFC_HBA_ERROR:
4098 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
4099 break;
4100 default:
4101 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
4102 break;
4103 }
4104 }
4105
4106 spin_unlock_irq(shost->host_lock);
4107 }
4108
4109 /**
4110 * lpfc_get_host_speed - Set the value of the scsi host speed
4111 * @shost: kernel scsi host pointer.
4112 **/
4113 static void
4114 lpfc_get_host_speed(struct Scsi_Host *shost)
4115 {
4116 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4117 struct lpfc_hba *phba = vport->phba;
4118
4119 spin_lock_irq(shost->host_lock);
4120
4121 if (lpfc_is_link_up(phba)) {
4122 switch(phba->fc_linkspeed) {
4123 case LPFC_LINK_SPEED_1GHZ:
4124 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
4125 break;
4126 case LPFC_LINK_SPEED_2GHZ:
4127 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
4128 break;
4129 case LPFC_LINK_SPEED_4GHZ:
4130 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
4131 break;
4132 case LPFC_LINK_SPEED_8GHZ:
4133 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
4134 break;
4135 case LPFC_LINK_SPEED_10GHZ:
4136 fc_host_speed(shost) = FC_PORTSPEED_10GBIT;
4137 break;
4138 case LPFC_LINK_SPEED_16GHZ:
4139 fc_host_speed(shost) = FC_PORTSPEED_16GBIT;
4140 break;
4141 default:
4142 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4143 break;
4144 }
4145 } else
4146 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
4147
4148 spin_unlock_irq(shost->host_lock);
4149 }
4150
4151 /**
4152 * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name
4153 * @shost: kernel scsi host pointer.
4154 **/
4155 static void
4156 lpfc_get_host_fabric_name (struct Scsi_Host *shost)
4157 {
4158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4159 struct lpfc_hba *phba = vport->phba;
4160 u64 node_name;
4161
4162 spin_lock_irq(shost->host_lock);
4163
4164 if ((vport->fc_flag & FC_FABRIC) ||
4165 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
4166 (vport->fc_flag & FC_PUBLIC_LOOP)))
4167 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
4168 else
4169 /* fabric is local port if there is no F/FL_Port */
4170 node_name = 0;
4171
4172 spin_unlock_irq(shost->host_lock);
4173
4174 fc_host_fabric_name(shost) = node_name;
4175 }
4176
4177 /**
4178 * lpfc_get_stats - Return statistical information about the adapter
4179 * @shost: kernel scsi host pointer.
4180 *
4181 * Notes:
4182 * NULL on error for link down, no mbox pool, sli2 active,
4183 * management not allowed, memory allocation error, or mbox error.
4184 *
4185 * Returns:
4186 * NULL for error
4187 * address of the adapter host statistics
4188 **/
4189 static struct fc_host_statistics *
4190 lpfc_get_stats(struct Scsi_Host *shost)
4191 {
4192 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4193 struct lpfc_hba *phba = vport->phba;
4194 struct lpfc_sli *psli = &phba->sli;
4195 struct fc_host_statistics *hs = &phba->link_stats;
4196 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
4197 LPFC_MBOXQ_t *pmboxq;
4198 MAILBOX_t *pmb;
4199 unsigned long seconds;
4200 int rc = 0;
4201
4202 /*
4203 * prevent udev from issuing mailbox commands until the port is
4204 * configured.
4205 */
4206 if (phba->link_state < LPFC_LINK_DOWN ||
4207 !phba->mbox_mem_pool ||
4208 (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0)
4209 return NULL;
4210
4211 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4212 return NULL;
4213
4214 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4215 if (!pmboxq)
4216 return NULL;
4217 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4218
4219 pmb = &pmboxq->u.mb;
4220 pmb->mbxCommand = MBX_READ_STATUS;
4221 pmb->mbxOwner = OWN_HOST;
4222 pmboxq->context1 = NULL;
4223 pmboxq->vport = vport;
4224
4225 if (vport->fc_flag & FC_OFFLINE_MODE)
4226 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4227 else
4228 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4229
4230 if (rc != MBX_SUCCESS) {
4231 if (rc != MBX_TIMEOUT)
4232 mempool_free(pmboxq, phba->mbox_mem_pool);
4233 return NULL;
4234 }
4235
4236 memset(hs, 0, sizeof (struct fc_host_statistics));
4237
4238 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
4239 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
4240 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
4241 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
4242
4243 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4244 pmb->mbxCommand = MBX_READ_LNK_STAT;
4245 pmb->mbxOwner = OWN_HOST;
4246 pmboxq->context1 = NULL;
4247 pmboxq->vport = vport;
4248
4249 if (vport->fc_flag & FC_OFFLINE_MODE)
4250 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4251 else
4252 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4253
4254 if (rc != MBX_SUCCESS) {
4255 if (rc != MBX_TIMEOUT)
4256 mempool_free(pmboxq, phba->mbox_mem_pool);
4257 return NULL;
4258 }
4259
4260 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4261 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4262 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4263 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4264 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4265 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4266 hs->error_frames = pmb->un.varRdLnk.crcCnt;
4267
4268 hs->link_failure_count -= lso->link_failure_count;
4269 hs->loss_of_sync_count -= lso->loss_of_sync_count;
4270 hs->loss_of_signal_count -= lso->loss_of_signal_count;
4271 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
4272 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
4273 hs->invalid_crc_count -= lso->invalid_crc_count;
4274 hs->error_frames -= lso->error_frames;
4275
4276 if (phba->hba_flag & HBA_FCOE_MODE) {
4277 hs->lip_count = -1;
4278 hs->nos_count = (phba->link_events >> 1);
4279 hs->nos_count -= lso->link_events;
4280 } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4281 hs->lip_count = (phba->fc_eventTag >> 1);
4282 hs->lip_count -= lso->link_events;
4283 hs->nos_count = -1;
4284 } else {
4285 hs->lip_count = -1;
4286 hs->nos_count = (phba->fc_eventTag >> 1);
4287 hs->nos_count -= lso->link_events;
4288 }
4289
4290 hs->dumped_frames = -1;
4291
4292 seconds = get_seconds();
4293 if (seconds < psli->stats_start)
4294 hs->seconds_since_last_reset = seconds +
4295 ((unsigned long)-1 - psli->stats_start);
4296 else
4297 hs->seconds_since_last_reset = seconds - psli->stats_start;
4298
4299 mempool_free(pmboxq, phba->mbox_mem_pool);
4300
4301 return hs;
4302 }
4303
4304 /**
4305 * lpfc_reset_stats - Copy the adapter link stats information
4306 * @shost: kernel scsi host pointer.
4307 **/
4308 static void
4309 lpfc_reset_stats(struct Scsi_Host *shost)
4310 {
4311 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4312 struct lpfc_hba *phba = vport->phba;
4313 struct lpfc_sli *psli = &phba->sli;
4314 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
4315 LPFC_MBOXQ_t *pmboxq;
4316 MAILBOX_t *pmb;
4317 int rc = 0;
4318
4319 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
4320 return;
4321
4322 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4323 if (!pmboxq)
4324 return;
4325 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4326
4327 pmb = &pmboxq->u.mb;
4328 pmb->mbxCommand = MBX_READ_STATUS;
4329 pmb->mbxOwner = OWN_HOST;
4330 pmb->un.varWords[0] = 0x1; /* reset request */
4331 pmboxq->context1 = NULL;
4332 pmboxq->vport = vport;
4333
4334 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4335 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4336 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4337 else
4338 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4339
4340 if (rc != MBX_SUCCESS) {
4341 if (rc != MBX_TIMEOUT)
4342 mempool_free(pmboxq, phba->mbox_mem_pool);
4343 return;
4344 }
4345
4346 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
4347 pmb->mbxCommand = MBX_READ_LNK_STAT;
4348 pmb->mbxOwner = OWN_HOST;
4349 pmboxq->context1 = NULL;
4350 pmboxq->vport = vport;
4351
4352 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
4353 (!(psli->sli_flag & LPFC_SLI_ACTIVE)))
4354 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
4355 else
4356 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
4357
4358 if (rc != MBX_SUCCESS) {
4359 if (rc != MBX_TIMEOUT)
4360 mempool_free( pmboxq, phba->mbox_mem_pool);
4361 return;
4362 }
4363
4364 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
4365 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
4366 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
4367 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
4368 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
4369 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
4370 lso->error_frames = pmb->un.varRdLnk.crcCnt;
4371 if (phba->hba_flag & HBA_FCOE_MODE)
4372 lso->link_events = (phba->link_events >> 1);
4373 else
4374 lso->link_events = (phba->fc_eventTag >> 1);
4375
4376 psli->stats_start = get_seconds();
4377
4378 mempool_free(pmboxq, phba->mbox_mem_pool);
4379
4380 return;
4381 }
4382
4383 /*
4384 * The LPFC driver treats linkdown handling as target loss events so there
4385 * are no sysfs handlers for link_down_tmo.
4386 */
4387
4388 /**
4389 * lpfc_get_node_by_target - Return the nodelist for a target
4390 * @starget: kernel scsi target pointer.
4391 *
4392 * Returns:
4393 * address of the node list if found
4394 * NULL target not found
4395 **/
4396 static struct lpfc_nodelist *
4397 lpfc_get_node_by_target(struct scsi_target *starget)
4398 {
4399 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
4400 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
4401 struct lpfc_nodelist *ndlp;
4402
4403 spin_lock_irq(shost->host_lock);
4404 /* Search for this, mapped, target ID */
4405 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4406 if (NLP_CHK_NODE_ACT(ndlp) &&
4407 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
4408 starget->id == ndlp->nlp_sid) {
4409 spin_unlock_irq(shost->host_lock);
4410 return ndlp;
4411 }
4412 }
4413 spin_unlock_irq(shost->host_lock);
4414 return NULL;
4415 }
4416
4417 /**
4418 * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1
4419 * @starget: kernel scsi target pointer.
4420 **/
4421 static void
4422 lpfc_get_starget_port_id(struct scsi_target *starget)
4423 {
4424 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4425
4426 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
4427 }
4428
4429 /**
4430 * lpfc_get_starget_node_name - Set the target node name
4431 * @starget: kernel scsi target pointer.
4432 *
4433 * Description: Set the target node name to the ndlp node name wwn or zero.
4434 **/
4435 static void
4436 lpfc_get_starget_node_name(struct scsi_target *starget)
4437 {
4438 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4439
4440 fc_starget_node_name(starget) =
4441 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
4442 }
4443
4444 /**
4445 * lpfc_get_starget_port_name - Set the target port name
4446 * @starget: kernel scsi target pointer.
4447 *
4448 * Description: set the target port name to the ndlp port name wwn or zero.
4449 **/
4450 static void
4451 lpfc_get_starget_port_name(struct scsi_target *starget)
4452 {
4453 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
4454
4455 fc_starget_port_name(starget) =
4456 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
4457 }
4458
4459 /**
4460 * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo
4461 * @rport: fc rport address.
4462 * @timeout: new value for dev loss tmo.
4463 *
4464 * Description:
4465 * If timeout is non zero set the dev_loss_tmo to timeout, else set
4466 * dev_loss_tmo to one.
4467 **/
4468 static void
4469 lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
4470 {
4471 if (timeout)
4472 rport->dev_loss_tmo = timeout;
4473 else
4474 rport->dev_loss_tmo = 1;
4475 }
4476
4477 /**
4478 * lpfc_rport_show_function - Return rport target information
4479 *
4480 * Description:
4481 * Macro that uses field to generate a function with the name lpfc_show_rport_
4482 *
4483 * lpfc_show_rport_##field: returns the bytes formatted in buf
4484 * @cdev: class converted to an fc_rport.
4485 * @buf: on return contains the target_field or zero.
4486 *
4487 * Returns: size of formatted string.
4488 **/
4489 #define lpfc_rport_show_function(field, format_string, sz, cast) \
4490 static ssize_t \
4491 lpfc_show_rport_##field (struct device *dev, \
4492 struct device_attribute *attr, \
4493 char *buf) \
4494 { \
4495 struct fc_rport *rport = transport_class_to_rport(dev); \
4496 struct lpfc_rport_data *rdata = rport->hostdata; \
4497 return snprintf(buf, sz, format_string, \
4498 (rdata->target) ? cast rdata->target->field : 0); \
4499 }
4500
4501 #define lpfc_rport_rd_attr(field, format_string, sz) \
4502 lpfc_rport_show_function(field, format_string, sz, ) \
4503 static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
4504
4505 /**
4506 * lpfc_set_vport_symbolic_name - Set the vport's symbolic name
4507 * @fc_vport: The fc_vport who's symbolic name has been changed.
4508 *
4509 * Description:
4510 * This function is called by the transport after the @fc_vport's symbolic name
4511 * has been changed. This function re-registers the symbolic name with the
4512 * switch to propogate the change into the fabric if the vport is active.
4513 **/
4514 static void
4515 lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport)
4516 {
4517 struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data;
4518
4519 if (vport->port_state == LPFC_VPORT_READY)
4520 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4521 }
4522
4523 /**
4524 * lpfc_hba_log_verbose_init - Set hba's log verbose level
4525 * @phba: Pointer to lpfc_hba struct.
4526 *
4527 * This function is called by the lpfc_get_cfgparam() routine to set the
4528 * module lpfc_log_verbose into the @phba cfg_log_verbose for use with
4529 * log messsage according to the module's lpfc_log_verbose parameter setting
4530 * before hba port or vport created.
4531 **/
4532 static void
4533 lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose)
4534 {
4535 phba->cfg_log_verbose = verbose;
4536 }
4537
4538 struct fc_function_template lpfc_transport_functions = {
4539 /* fixed attributes the driver supports */
4540 .show_host_node_name = 1,
4541 .show_host_port_name = 1,
4542 .show_host_supported_classes = 1,
4543 .show_host_supported_fc4s = 1,
4544 .show_host_supported_speeds = 1,
4545 .show_host_maxframe_size = 1,
4546 .show_host_symbolic_name = 1,
4547
4548 /* dynamic attributes the driver supports */
4549 .get_host_port_id = lpfc_get_host_port_id,
4550 .show_host_port_id = 1,
4551
4552 .get_host_port_type = lpfc_get_host_port_type,
4553 .show_host_port_type = 1,
4554
4555 .get_host_port_state = lpfc_get_host_port_state,
4556 .show_host_port_state = 1,
4557
4558 /* active_fc4s is shown but doesn't change (thus no get function) */
4559 .show_host_active_fc4s = 1,
4560
4561 .get_host_speed = lpfc_get_host_speed,
4562 .show_host_speed = 1,
4563
4564 .get_host_fabric_name = lpfc_get_host_fabric_name,
4565 .show_host_fabric_name = 1,
4566
4567 /*
4568 * The LPFC driver treats linkdown handling as target loss events
4569 * so there are no sysfs handlers for link_down_tmo.
4570 */
4571
4572 .get_fc_host_stats = lpfc_get_stats,
4573 .reset_fc_host_stats = lpfc_reset_stats,
4574
4575 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4576 .show_rport_maxframe_size = 1,
4577 .show_rport_supported_classes = 1,
4578
4579 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4580 .show_rport_dev_loss_tmo = 1,
4581
4582 .get_starget_port_id = lpfc_get_starget_port_id,
4583 .show_starget_port_id = 1,
4584
4585 .get_starget_node_name = lpfc_get_starget_node_name,
4586 .show_starget_node_name = 1,
4587
4588 .get_starget_port_name = lpfc_get_starget_port_name,
4589 .show_starget_port_name = 1,
4590
4591 .issue_fc_host_lip = lpfc_issue_lip,
4592 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4593 .terminate_rport_io = lpfc_terminate_rport_io,
4594
4595 .dd_fcvport_size = sizeof(struct lpfc_vport *),
4596
4597 .vport_disable = lpfc_vport_disable,
4598
4599 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4600
4601 .bsg_request = lpfc_bsg_request,
4602 .bsg_timeout = lpfc_bsg_timeout,
4603 };
4604
4605 struct fc_function_template lpfc_vport_transport_functions = {
4606 /* fixed attributes the driver supports */
4607 .show_host_node_name = 1,
4608 .show_host_port_name = 1,
4609 .show_host_supported_classes = 1,
4610 .show_host_supported_fc4s = 1,
4611 .show_host_supported_speeds = 1,
4612 .show_host_maxframe_size = 1,
4613 .show_host_symbolic_name = 1,
4614
4615 /* dynamic attributes the driver supports */
4616 .get_host_port_id = lpfc_get_host_port_id,
4617 .show_host_port_id = 1,
4618
4619 .get_host_port_type = lpfc_get_host_port_type,
4620 .show_host_port_type = 1,
4621
4622 .get_host_port_state = lpfc_get_host_port_state,
4623 .show_host_port_state = 1,
4624
4625 /* active_fc4s is shown but doesn't change (thus no get function) */
4626 .show_host_active_fc4s = 1,
4627
4628 .get_host_speed = lpfc_get_host_speed,
4629 .show_host_speed = 1,
4630
4631 .get_host_fabric_name = lpfc_get_host_fabric_name,
4632 .show_host_fabric_name = 1,
4633
4634 /*
4635 * The LPFC driver treats linkdown handling as target loss events
4636 * so there are no sysfs handlers for link_down_tmo.
4637 */
4638
4639 .get_fc_host_stats = lpfc_get_stats,
4640 .reset_fc_host_stats = lpfc_reset_stats,
4641
4642 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
4643 .show_rport_maxframe_size = 1,
4644 .show_rport_supported_classes = 1,
4645
4646 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
4647 .show_rport_dev_loss_tmo = 1,
4648
4649 .get_starget_port_id = lpfc_get_starget_port_id,
4650 .show_starget_port_id = 1,
4651
4652 .get_starget_node_name = lpfc_get_starget_node_name,
4653 .show_starget_node_name = 1,
4654
4655 .get_starget_port_name = lpfc_get_starget_port_name,
4656 .show_starget_port_name = 1,
4657
4658 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
4659 .terminate_rport_io = lpfc_terminate_rport_io,
4660
4661 .vport_disable = lpfc_vport_disable,
4662
4663 .set_vport_symbolic_name = lpfc_set_vport_symbolic_name,
4664 };
4665
4666 /**
4667 * lpfc_get_cfgparam - Used during probe_one to init the adapter structure
4668 * @phba: lpfc_hba pointer.
4669 **/
4670 void
4671 lpfc_get_cfgparam(struct lpfc_hba *phba)
4672 {
4673 lpfc_cr_delay_init(phba, lpfc_cr_delay);
4674 lpfc_cr_count_init(phba, lpfc_cr_count);
4675 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
4676 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
4677 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
4678 lpfc_ack0_init(phba, lpfc_ack0);
4679 lpfc_topology_init(phba, lpfc_topology);
4680 lpfc_link_speed_init(phba, lpfc_link_speed);
4681 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4682 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
4683 lpfc_enable_rrq_init(phba, lpfc_enable_rrq);
4684 lpfc_use_msi_init(phba, lpfc_use_msi);
4685 lpfc_fcp_imax_init(phba, lpfc_fcp_imax);
4686 lpfc_fcp_wq_count_init(phba, lpfc_fcp_wq_count);
4687 lpfc_fcp_eq_count_init(phba, lpfc_fcp_eq_count);
4688 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
4689 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
4690 lpfc_enable_bg_init(phba, lpfc_enable_bg);
4691 if (phba->sli_rev == LPFC_SLI_REV4)
4692 phba->cfg_poll = 0;
4693 else
4694 phba->cfg_poll = lpfc_poll;
4695 phba->cfg_soft_wwnn = 0L;
4696 phba->cfg_soft_wwpn = 0L;
4697 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
4698 lpfc_prot_sg_seg_cnt_init(phba, lpfc_prot_sg_seg_cnt);
4699 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
4700 lpfc_hba_log_verbose_init(phba, lpfc_log_verbose);
4701 lpfc_aer_support_init(phba, lpfc_aer_support);
4702 lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up);
4703 lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt);
4704 phba->cfg_enable_dss = 1;
4705 return;
4706 }
4707
4708 /**
4709 * lpfc_get_vport_cfgparam - Used during port create, init the vport structure
4710 * @vport: lpfc_vport pointer.
4711 **/
4712 void
4713 lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
4714 {
4715 lpfc_log_verbose_init(vport, lpfc_log_verbose);
4716 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
4717 lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth);
4718 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
4719 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
4720 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
4721 lpfc_restrict_login_init(vport, lpfc_restrict_login);
4722 lpfc_fcp_class_init(vport, lpfc_fcp_class);
4723 lpfc_use_adisc_init(vport, lpfc_use_adisc);
4724 lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time);
4725 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
4726 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
4727 lpfc_max_luns_init(vport, lpfc_max_luns);
4728 lpfc_scan_down_init(vport, lpfc_scan_down);
4729 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
4730 return;
4731 }
This page took 0.170705 seconds and 5 git commands to generate.