]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/scsi/lpfc/lpfc_attr.c
[SCSI] lpfc 8.1.12 : Modify ELS abort handling to prevent double completion
[mirror_ubuntu-jammy-kernel.git] / drivers / scsi / lpfc / lpfc_attr.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
41415862 4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
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. *
dea3101e
JB
20 *******************************************************************/
21
dea3101e
JB
22#include <linux/ctype.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
91886523 26#include <scsi/scsi.h>
dea3101e
JB
27#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_tcq.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_hw.h"
33#include "lpfc_sli.h"
34#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_version.h"
39#include "lpfc_compat.h"
40#include "lpfc_crtn.h"
41
c01f3208
JS
42#define LPFC_DEF_DEVLOSS_TMO 30
43#define LPFC_MIN_DEVLOSS_TMO 1
44#define LPFC_MAX_DEVLOSS_TMO 255
dea3101e
JB
45
46static void
47lpfc_jedec_to_ascii(int incr, char hdw[])
48{
49 int i, j;
50 for (i = 0; i < 8; i++) {
51 j = (incr & 0xf);
52 if (j <= 9)
53 hdw[7 - i] = 0x30 + j;
54 else
55 hdw[7 - i] = 0x61 + j - 10;
56 incr = (incr >> 4);
57 }
58 hdw[8] = 0;
59 return;
60}
61
62static ssize_t
63lpfc_drvr_version_show(struct class_device *cdev, char *buf)
64{
65 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
66}
67
68static ssize_t
69management_version_show(struct class_device *cdev, char *buf)
70{
71 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
72}
73
74static ssize_t
75lpfc_info_show(struct class_device *cdev, char *buf)
76{
77 struct Scsi_Host *host = class_to_shost(cdev);
78 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
79}
80
81static ssize_t
82lpfc_serialnum_show(struct class_device *cdev, char *buf)
83{
84 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 85 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
86 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
87}
88
89static ssize_t
90lpfc_modeldesc_show(struct class_device *cdev, char *buf)
91{
92 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 93 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
94 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
95}
96
97static ssize_t
98lpfc_modelname_show(struct class_device *cdev, char *buf)
99{
100 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 101 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
102 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
103}
104
105static ssize_t
106lpfc_programtype_show(struct class_device *cdev, char *buf)
107{
108 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 109 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
111}
112
113static ssize_t
114lpfc_portnum_show(struct class_device *cdev, char *buf)
115{
116 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 117 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
118 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
119}
120
121static ssize_t
122lpfc_fwrev_show(struct class_device *cdev, char *buf)
123{
124 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 125 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
126 char fwrev[32];
127 lpfc_decode_firmware_rev(phba, fwrev, 1);
128 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
129}
130
131static ssize_t
132lpfc_hdw_show(struct class_device *cdev, char *buf)
133{
134 char hdw[9];
135 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 136 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
137 lpfc_vpd_t *vp = &phba->vpd;
138 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
139 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
140}
141static ssize_t
142lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
143{
144 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 145 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
146 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
147}
148static ssize_t
149lpfc_state_show(struct class_device *cdev, char *buf)
150{
151 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 152 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
153 int len = 0;
154 switch (phba->hba_state) {
41415862
JW
155 case LPFC_STATE_UNKNOWN:
156 case LPFC_WARM_START:
dea3101e
JB
157 case LPFC_INIT_START:
158 case LPFC_INIT_MBX_CMDS:
159 case LPFC_LINK_DOWN:
160 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
161 break;
162 case LPFC_LINK_UP:
163 case LPFC_LOCAL_CFG_LINK:
164 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
165 break;
166 case LPFC_FLOGI:
167 case LPFC_FABRIC_CFG_LINK:
168 case LPFC_NS_REG:
169 case LPFC_NS_QRY:
170 case LPFC_BUILD_DISC_LIST:
171 case LPFC_DISC_AUTH:
172 case LPFC_CLEAR_LA:
173 len += snprintf(buf + len, PAGE_SIZE-len,
174 "Link Up - Discovery\n");
175 break;
176 case LPFC_HBA_READY:
177 len += snprintf(buf + len, PAGE_SIZE-len,
178 "Link Up - Ready:\n");
179 if (phba->fc_topology == TOPOLOGY_LOOP) {
180 if (phba->fc_flag & FC_PUBLIC_LOOP)
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Public Loop\n");
183 else
184 len += snprintf(buf + len, PAGE_SIZE-len,
185 " Private Loop\n");
186 } else {
187 if (phba->fc_flag & FC_FABRIC)
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Fabric\n");
190 else
191 len += snprintf(buf + len, PAGE_SIZE-len,
192 " Point-2-Point\n");
193 }
194 }
195 return len;
196}
197
198static ssize_t
199lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
200{
201 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 202 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
203 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
204 phba->fc_unmap_cnt);
205}
206
207
91ca7b01
AV
208static int
209lpfc_issue_lip(struct Scsi_Host *host)
dea3101e 210{
7f0b5b19 211 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea3101e
JB
212 LPFC_MBOXQ_t *pmboxq;
213 int mbxstatus = MBXERR_ERROR;
214
dea3101e
JB
215 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
216 (phba->hba_state != LPFC_HBA_READY))
217 return -EPERM;
218
219 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
220
221 if (!pmboxq)
222 return -ENOMEM;
223
224 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4db621e0
JS
225 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
226 pmboxq->mb.mbxOwner = OWN_HOST;
227
33ccf8d1 228 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea3101e 229
4db621e0
JS
230 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
231 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
232 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
233 phba->cfg_link_speed);
234 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
235 phba->fc_ratov * 2);
236 }
237
dea3101e
JB
238 if (mbxstatus == MBX_TIMEOUT)
239 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
240 else
433c3579 241 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
242
243 if (mbxstatus == MBXERR_ERROR)
244 return -EIO;
245
91ca7b01 246 return 0;
dea3101e
JB
247}
248
40496f07
JS
249static int
250lpfc_selective_reset(struct lpfc_hba *phba)
251{
252 struct completion online_compl;
253 int status = 0;
254
255 init_completion(&online_compl);
256 lpfc_workq_post_event(phba, &status, &online_compl,
257 LPFC_EVT_OFFLINE);
258 wait_for_completion(&online_compl);
259
260 if (status != 0)
261 return -EIO;
262
263 init_completion(&online_compl);
264 lpfc_workq_post_event(phba, &status, &online_compl,
265 LPFC_EVT_ONLINE);
266 wait_for_completion(&online_compl);
267
268 if (status != 0)
269 return -EIO;
270
271 return 0;
272}
273
274static ssize_t
275lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
276{
277 struct Scsi_Host *host = class_to_shost(cdev);
278 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
279 int status = -EINVAL;
280
281 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
282 status = lpfc_selective_reset(phba);
283
284 if (status == 0)
285 return strlen(buf);
286 else
287 return status;
288}
289
dea3101e
JB
290static ssize_t
291lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
292{
293 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 294 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
295 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
296}
297
41415862
JW
298static ssize_t
299lpfc_board_mode_show(struct class_device *cdev, char *buf)
300{
301 struct Scsi_Host *host = class_to_shost(cdev);
302 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
303 char * state;
304
305 if (phba->hba_state == LPFC_HBA_ERROR)
306 state = "error";
307 else if (phba->hba_state == LPFC_WARM_START)
308 state = "warm start";
309 else if (phba->hba_state == LPFC_INIT_START)
310 state = "offline";
311 else
312 state = "online";
313
314 return snprintf(buf, PAGE_SIZE, "%s\n", state);
315}
316
317static ssize_t
318lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
319{
320 struct Scsi_Host *host = class_to_shost(cdev);
321 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
322 struct completion online_compl;
323 int status=0;
324
325 init_completion(&online_compl);
326
327 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
328 lpfc_workq_post_event(phba, &status, &online_compl,
329 LPFC_EVT_ONLINE);
330 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
331 lpfc_workq_post_event(phba, &status, &online_compl,
332 LPFC_EVT_OFFLINE);
333 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
334 lpfc_workq_post_event(phba, &status, &online_compl,
335 LPFC_EVT_WARM_START);
336 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
337 lpfc_workq_post_event(phba, &status, &online_compl,
338 LPFC_EVT_KILL);
339 else
340 return -EINVAL;
341
342 wait_for_completion(&online_compl);
343
344 if (!status)
345 return strlen(buf);
346 else
347 return -EIO;
348}
349
875fbdfe
JSEC
350static ssize_t
351lpfc_poll_show(struct class_device *cdev, char *buf)
352{
353 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 354 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
875fbdfe
JSEC
355
356 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
357}
358
359static ssize_t
360lpfc_poll_store(struct class_device *cdev, const char *buf,
361 size_t count)
362{
363 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 364 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
875fbdfe
JSEC
365 uint32_t creg_val;
366 uint32_t old_val;
367 int val=0;
368
369 if (!isdigit(buf[0]))
370 return -EINVAL;
371
372 if (sscanf(buf, "%i", &val) != 1)
373 return -EINVAL;
374
375 if ((val & 0x3) != val)
376 return -EINVAL;
377
378 spin_lock_irq(phba->host->host_lock);
379
380 old_val = phba->cfg_poll;
381
382 if (val & ENABLE_FCP_RING_POLLING) {
383 if ((val & DISABLE_FCP_RING_INT) &&
384 !(old_val & DISABLE_FCP_RING_INT)) {
385 creg_val = readl(phba->HCregaddr);
386 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
387 writel(creg_val, phba->HCregaddr);
388 readl(phba->HCregaddr); /* flush */
389
390 lpfc_poll_start_timer(phba);
391 }
392 } else if (val != 0x0) {
393 spin_unlock_irq(phba->host->host_lock);
394 return -EINVAL;
395 }
396
397 if (!(val & DISABLE_FCP_RING_INT) &&
398 (old_val & DISABLE_FCP_RING_INT))
399 {
400 spin_unlock_irq(phba->host->host_lock);
401 del_timer(&phba->fcp_poll_timer);
402 spin_lock_irq(phba->host->host_lock);
403 creg_val = readl(phba->HCregaddr);
404 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
405 writel(creg_val, phba->HCregaddr);
406 readl(phba->HCregaddr); /* flush */
407 }
408
409 phba->cfg_poll = val;
410
411 spin_unlock_irq(phba->host->host_lock);
412
413 return strlen(buf);
414}
dea3101e
JB
415
416#define lpfc_param_show(attr) \
417static ssize_t \
418lpfc_##attr##_show(struct class_device *cdev, char *buf) \
419{ \
420 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 421 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea3101e 422 int val = 0;\
7bcbb752
JSEC
423 val = phba->cfg_##attr;\
424 return snprintf(buf, PAGE_SIZE, "%d\n",\
425 phba->cfg_##attr);\
426}
427
93a20f74
JSEC
428#define lpfc_param_hex_show(attr) \
429static ssize_t \
430lpfc_##attr##_show(struct class_device *cdev, char *buf) \
431{ \
432 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 433 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
93a20f74
JSEC
434 int val = 0;\
435 val = phba->cfg_##attr;\
436 return snprintf(buf, PAGE_SIZE, "%#x\n",\
437 phba->cfg_##attr);\
438}
439
7bcbb752
JSEC
440#define lpfc_param_init(attr, default, minval, maxval) \
441static int \
442lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
443{ \
444 if (val >= minval && val <= maxval) {\
445 phba->cfg_##attr = val;\
446 return 0;\
dea3101e 447 }\
7bcbb752
JSEC
448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
449 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
450 "allowed range is ["#minval", "#maxval"]\n", \
451 phba->brd_no, val); \
452 phba->cfg_##attr = default;\
453 return -EINVAL;\
dea3101e
JB
454}
455
7bcbb752
JSEC
456#define lpfc_param_set(attr, default, minval, maxval) \
457static int \
458lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
459{ \
460 if (val >= minval && val <= maxval) {\
461 phba->cfg_##attr = val;\
462 return 0;\
463 }\
464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
465 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
466 "allowed range is ["#minval", "#maxval"]\n", \
467 phba->brd_no, val); \
468 return -EINVAL;\
469}
470
471#define lpfc_param_store(attr) \
dea3101e
JB
472static ssize_t \
473lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
474{ \
475 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 476 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
7bcbb752 477 int val=0;\
93a20f74
JSEC
478 if (!isdigit(buf[0]))\
479 return -EINVAL;\
480 if (sscanf(buf, "%i", &val) != 1)\
481 return -EINVAL;\
7bcbb752 482 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 483 return strlen(buf);\
7bcbb752
JSEC
484 else \
485 return -EINVAL;\
dea3101e
JB
486}
487
7bcbb752
JSEC
488#define LPFC_ATTR(name, defval, minval, maxval, desc) \
489static int lpfc_##name = defval;\
dea3101e
JB
490module_param(lpfc_##name, int, 0);\
491MODULE_PARM_DESC(lpfc_##name, desc);\
7bcbb752 492lpfc_param_init(name, defval, minval, maxval)
dea3101e
JB
493
494#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
495static int lpfc_##name = defval;\
496module_param(lpfc_##name, int, 0);\
497MODULE_PARM_DESC(lpfc_##name, desc);\
498lpfc_param_show(name)\
7bcbb752 499lpfc_param_init(name, defval, minval, maxval)\
dea3101e
JB
500static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
501
502#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
503static int lpfc_##name = defval;\
504module_param(lpfc_##name, int, 0);\
505MODULE_PARM_DESC(lpfc_##name, desc);\
506lpfc_param_show(name)\
7bcbb752
JSEC
507lpfc_param_init(name, defval, minval, maxval)\
508lpfc_param_set(name, defval, minval, maxval)\
509lpfc_param_store(name)\
dea3101e
JB
510static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
511 lpfc_##name##_show, lpfc_##name##_store)
512
93a20f74
JSEC
513#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
514static int lpfc_##name = defval;\
515module_param(lpfc_##name, int, 0);\
516MODULE_PARM_DESC(lpfc_##name, desc);\
517lpfc_param_hex_show(name)\
518lpfc_param_init(name, defval, minval, maxval)\
519static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
520
521#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
522static int lpfc_##name = defval;\
523module_param(lpfc_##name, int, 0);\
524MODULE_PARM_DESC(lpfc_##name, desc);\
525lpfc_param_hex_show(name)\
526lpfc_param_init(name, defval, minval, maxval)\
527lpfc_param_set(name, defval, minval, maxval)\
528lpfc_param_store(name)\
529static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
530 lpfc_##name##_show, lpfc_##name##_store)
531
dea3101e
JB
532static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
533static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
534static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
535static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
536static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
537static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
538static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
539static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
540static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
541static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
542 lpfc_option_rom_version_show, NULL);
543static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
544 lpfc_num_discovered_ports_show, NULL);
545static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
546static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
547 NULL);
548static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
549 NULL);
41415862
JW
550static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
551 lpfc_board_mode_show, lpfc_board_mode_store);
40496f07 552static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea3101e 553
c3f28afa 554
a12e07bc 555static char *lpfc_soft_wwn_key = "C99G71SL8032A";
c3f28afa
JS
556
557static ssize_t
a12e07bc 558lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
c3f28afa
JS
559 size_t count)
560{
561 struct Scsi_Host *host = class_to_shost(cdev);
562 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
563 unsigned int cnt = count;
564
565 /*
566 * We're doing a simple sanity check for soft_wwpn setting.
567 * We require that the user write a specific key to enable
568 * the soft_wwpn attribute to be settable. Once the attribute
569 * is written, the enable key resets. If further updates are
570 * desired, the key must be written again to re-enable the
571 * attribute.
572 *
573 * The "key" is not secret - it is a hardcoded string shown
574 * here. The intent is to protect against the random user or
575 * application that is just writing attributes.
576 */
577
578 /* count may include a LF at end of string */
579 if (buf[cnt-1] == '\n')
580 cnt--;
581
a12e07bc
JS
582 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
583 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
c3f28afa
JS
584 return -EINVAL;
585
a12e07bc 586 phba->soft_wwn_enable = 1;
c3f28afa
JS
587 return count;
588}
a12e07bc
JS
589static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
590 lpfc_soft_wwn_enable_store);
c3f28afa
JS
591
592static ssize_t
593lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
594{
595 struct Scsi_Host *host = class_to_shost(cdev);
596 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
afc071e6
RD
597 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
598 (unsigned long long)phba->cfg_soft_wwpn);
c3f28afa
JS
599}
600
601
602static ssize_t
603lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
604{
605 struct Scsi_Host *host = class_to_shost(cdev);
606 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
607 struct completion online_compl;
608 int stat1=0, stat2=0;
609 unsigned int i, j, cnt=count;
610 u8 wwpn[8];
611
612 /* count may include a LF at end of string */
613 if (buf[cnt-1] == '\n')
614 cnt--;
615
a12e07bc 616 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
c3f28afa
JS
617 ((cnt == 17) && (*buf++ != 'x')) ||
618 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
619 return -EINVAL;
620
a12e07bc 621 phba->soft_wwn_enable = 0;
c3f28afa
JS
622
623 memset(wwpn, 0, sizeof(wwpn));
624
625 /* Validate and store the new name */
626 for (i=0, j=0; i < 16; i++) {
627 if ((*buf >= 'a') && (*buf <= 'f'))
628 j = ((j << 4) | ((*buf++ -'a') + 10));
629 else if ((*buf >= 'A') && (*buf <= 'F'))
630 j = ((j << 4) | ((*buf++ -'A') + 10));
631 else if ((*buf >= '0') && (*buf <= '9'))
632 j = ((j << 4) | (*buf++ -'0'));
633 else
634 return -EINVAL;
635 if (i % 2) {
636 wwpn[i/2] = j & 0xff;
637 j = 0;
638 }
639 }
640 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
641 fc_host_port_name(host) = phba->cfg_soft_wwpn;
a12e07bc
JS
642 if (phba->cfg_soft_wwnn)
643 fc_host_node_name(host) = phba->cfg_soft_wwnn;
c3f28afa
JS
644
645 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
646 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
647
648 init_completion(&online_compl);
649 lpfc_workq_post_event(phba, &stat1, &online_compl, LPFC_EVT_OFFLINE);
650 wait_for_completion(&online_compl);
651 if (stat1)
652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
653 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
654 "adapter - %d\n", phba->brd_no, stat1);
655
656 init_completion(&online_compl);
657 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
658 wait_for_completion(&online_compl);
659 if (stat2)
660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
661 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
662 "adapter - %d\n", phba->brd_no, stat2);
663
664 return (stat1 || stat2) ? -EIO : count;
665}
666static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
667 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
668
a12e07bc
JS
669static ssize_t
670lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
671{
672 struct Scsi_Host *host = class_to_shost(cdev);
673 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
674 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
675 (unsigned long long)phba->cfg_soft_wwnn);
676}
677
678
679static ssize_t
680lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
681{
682 struct Scsi_Host *host = class_to_shost(cdev);
683 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
684 unsigned int i, j, cnt=count;
685 u8 wwnn[8];
686
687 /* count may include a LF at end of string */
688 if (buf[cnt-1] == '\n')
689 cnt--;
690
691 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
692 ((cnt == 17) && (*buf++ != 'x')) ||
693 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
694 return -EINVAL;
695
696 /*
697 * Allow wwnn to be set many times, as long as the enable is set.
698 * However, once the wwpn is set, everything locks.
699 */
700
701 memset(wwnn, 0, sizeof(wwnn));
702
703 /* Validate and store the new name */
704 for (i=0, j=0; i < 16; i++) {
705 if ((*buf >= 'a') && (*buf <= 'f'))
706 j = ((j << 4) | ((*buf++ -'a') + 10));
707 else if ((*buf >= 'A') && (*buf <= 'F'))
708 j = ((j << 4) | ((*buf++ -'A') + 10));
709 else if ((*buf >= '0') && (*buf <= '9'))
710 j = ((j << 4) | (*buf++ -'0'));
711 else
712 return -EINVAL;
713 if (i % 2) {
714 wwnn[i/2] = j & 0xff;
715 j = 0;
716 }
717 }
718 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
719
720 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
721 "lpfc%d: soft_wwnn set. Value will take effect upon "
722 "setting of the soft_wwpn\n", phba->brd_no);
723
724 return count;
725}
726static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
727 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
728
c3f28afa 729
875fbdfe
JSEC
730static int lpfc_poll = 0;
731module_param(lpfc_poll, int, 0);
732MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
733 " 0 - none,"
734 " 1 - poll with interrupts enabled"
735 " 3 - poll and disable FCP ring interrupts");
736
737static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
738 lpfc_poll_show, lpfc_poll_store);
dea3101e 739
c01f3208
JS
740/*
741# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
742# until the timer expires. Value range is [0,255]. Default value is 30.
743*/
744static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
745static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
746module_param(lpfc_nodev_tmo, int, 0);
747MODULE_PARM_DESC(lpfc_nodev_tmo,
748 "Seconds driver will hold I/O waiting "
749 "for a device to come back");
750static ssize_t
751lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
752{
753 struct Scsi_Host *host = class_to_shost(cdev);
754 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
755 int val = 0;
756 val = phba->cfg_devloss_tmo;
757 return snprintf(buf, PAGE_SIZE, "%d\n",
758 phba->cfg_devloss_tmo);
759}
760
761static int
762lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
763{
764 static int warned;
765 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
766 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
767 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
768 warned = 1;
769 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
770 "%d:0402 Ignoring nodev_tmo module "
771 "parameter because devloss_tmo is"
772 " set.\n",
773 phba->brd_no);
774 }
775 return 0;
776 }
777
778 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
779 phba->cfg_nodev_tmo = val;
780 phba->cfg_devloss_tmo = val;
781 return 0;
782 }
783 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
784 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
785 "allowed range is [%d, %d]\n",
786 phba->brd_no, val,
787 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
788 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
789 return -EINVAL;
790}
791
792static int
793lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
794{
795 if (phba->dev_loss_tmo_changed ||
796 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
797 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
798 "%d:0401 Ignoring change to nodev_tmo "
799 "because devloss_tmo is set.\n",
800 phba->brd_no);
801 return 0;
802 }
803
804 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
805 phba->cfg_nodev_tmo = val;
806 phba->cfg_devloss_tmo = val;
807 return 0;
808 }
809
810 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
811 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
812 "allowed range is [%d, %d]\n",
813 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
814 LPFC_MAX_DEVLOSS_TMO);
815 return -EINVAL;
816}
817
818lpfc_param_store(nodev_tmo)
819
820static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
821 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
822
823/*
824# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
825# disappear until the timer expires. Value range is [0,255]. Default
826# value is 30.
827*/
828module_param(lpfc_devloss_tmo, int, 0);
829MODULE_PARM_DESC(lpfc_devloss_tmo,
830 "Seconds driver will hold I/O waiting "
831 "for a device to come back");
832lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
833 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
834lpfc_param_show(devloss_tmo)
835static int
836lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
837{
838 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
839 phba->cfg_nodev_tmo = val;
840 phba->cfg_devloss_tmo = val;
841 phba->dev_loss_tmo_changed = 1;
842 return 0;
843 }
844
845 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
846 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
847 " %d, allowed range is [%d, %d]\n",
848 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
849 LPFC_MAX_DEVLOSS_TMO);
850 return -EINVAL;
851}
852
853lpfc_param_store(devloss_tmo)
854static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
855 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
856
dea3101e
JB
857/*
858# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
859# deluged with LOTS of information.
860# You can set a bit mask to record specific types of verbose messages:
861#
862# LOG_ELS 0x1 ELS events
863# LOG_DISCOVERY 0x2 Link discovery events
864# LOG_MBOX 0x4 Mailbox events
865# LOG_INIT 0x8 Initialization events
866# LOG_LINK_EVENT 0x10 Link events
dea3101e
JB
867# LOG_FCP 0x40 FCP traffic history
868# LOG_NODE 0x80 Node table events
869# LOG_MISC 0x400 Miscellaneous events
870# LOG_SLI 0x800 SLI events
c7743956 871# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea3101e
JB
872# LOG_LIBDFC 0x2000 LIBDFC events
873# LOG_ALL_MSG 0xffff LOG all messages
874*/
93a20f74 875LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea3101e
JB
876
877/*
878# lun_queue_depth: This parameter is used to limit the number of outstanding
879# commands per FCP LUN. Value range is [1,128]. Default value is 30.
880*/
881LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
882 "Max number of FCP commands we can queue to a specific LUN");
883
b28485ac
JW
884/*
885# hba_queue_depth: This parameter is used to limit the number of outstanding
886# commands per lpfc HBA. Value range is [32,8192]. If this parameter
887# value is greater than the maximum number of exchanges supported by the HBA,
888# then maximum number of exchanges supported by the HBA is used to determine
889# the hba_queue_depth.
890*/
891LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
892 "Max number of FCP commands we can queue to a lpfc HBA");
893
dea3101e
JB
894/*
895# Some disk devices have a "select ID" or "select Target" capability.
896# From a protocol standpoint "select ID" usually means select the
897# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
898# annex" which contains a table that maps a "select ID" (a number
899# between 0 and 7F) to an ALPA. By default, for compatibility with
900# older drivers, the lpfc driver scans this table from low ALPA to high
901# ALPA.
902#
903# Turning on the scan-down variable (on = 1, off = 0) will
904# cause the lpfc driver to use an inverted table, effectively
905# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
906#
907# (Note: This "select ID" functionality is a LOOP ONLY characteristic
908# and will not work across a fabric. Also this parameter will take
909# effect only in the case when ALPA map is not available.)
910*/
911LPFC_ATTR_R(scan_down, 1, 0, 1,
912 "Start scanning for devices from highest ALPA to lowest");
913
dea3101e
JB
914/*
915# lpfc_topology: link topology for init link
916# 0x0 = attempt loop mode then point-to-point
367c2713 917# 0x01 = internal loopback mode
dea3101e
JB
918# 0x02 = attempt point-to-point mode only
919# 0x04 = attempt loop mode only
920# 0x06 = attempt point-to-point mode then loop
921# Set point-to-point mode if you want to run as an N_Port.
922# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
923# Default value is 0.
924*/
367c2713 925LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea3101e
JB
926
927/*
928# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
929# connection.
930# 0 = auto select (default)
931# 1 = 1 Gigabaud
932# 2 = 2 Gigabaud
933# 4 = 4 Gigabaud
934# Value range is [0,4]. Default value is 0.
935*/
936LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
937
938/*
939# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
940# Value range is [2,3]. Default value is 3.
941*/
942LPFC_ATTR_R(fcp_class, 3, 2, 3,
943 "Select Fibre Channel class of service for FCP sequences");
944
945/*
946# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
947# is [0,1]. Default value is 0.
948*/
949LPFC_ATTR_RW(use_adisc, 0, 0, 1,
950 "Use ADISC on rediscovery to authenticate FCP devices");
951
952/*
953# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
954# range is [0,1]. Default value is 0.
955*/
956LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
957
958/*
959# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
960# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
961# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
962# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
963# cr_delay is set to 0.
964*/
8189fd19 965LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e
JB
966 "interrupt response is generated");
967
8189fd19 968LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e
JB
969 "interrupt response is generated");
970
cf5bf97e
JW
971/*
972# lpfc_multi_ring_support: Determines how many rings to spread available
973# cmd/rsp IOCB entries across.
974# Value range is [1,2]. Default value is 1.
975*/
976LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
977 "SLI rings to spread IOCB entries across");
978
a4bc3379
JS
979/*
980# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
981# identifies what rctl value to configure the additional ring for.
982# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
983*/
984LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
985 255, "Identifies RCTL for additional ring configuration");
986
987/*
988# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
989# identifies what type value to configure the additional ring for.
990# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
991*/
992LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
993 255, "Identifies TYPE for additional ring configuration");
994
dea3101e
JB
995/*
996# lpfc_fdmi_on: controls FDMI support.
997# 0 = no FDMI support
998# 1 = support FDMI without attribute of hostname
999# 2 = support FDMI with attribute of hostname
1000# Value range [0,2]. Default value is 0.
1001*/
1002LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1003
1004/*
1005# Specifies the maximum number of ELS cmds we can have outstanding (for
1006# discovery). Value range is [1,64]. Default value = 32.
1007*/
8189fd19 1008LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e
JB
1009 "during discovery");
1010
1011/*
65a29c16
JS
1012# lpfc_max_luns: maximum allowed LUN.
1013# Value range is [0,65535]. Default value is 255.
1014# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 1015*/
65a29c16
JS
1016LPFC_ATTR_R(max_luns, 255, 0, 65535,
1017 "Maximum allowed LUN");
dea3101e 1018
875fbdfe
JSEC
1019/*
1020# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1021# Value range is [1,255], default value is 10.
1022*/
1023LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1024 "Milliseconds driver will wait between polling FCP ring");
1025
4ff43246
JS
1026/*
1027# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1028# support this feature
1029# 0 = MSI disabled (default)
1030# 1 = MSI enabled
1031# Value range is [0,1]. Default value is 0.
1032*/
1033LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1034
c3f28afa 1035
dea3101e
JB
1036struct class_device_attribute *lpfc_host_attrs[] = {
1037 &class_device_attr_info,
1038 &class_device_attr_serialnum,
1039 &class_device_attr_modeldesc,
1040 &class_device_attr_modelname,
1041 &class_device_attr_programtype,
1042 &class_device_attr_portnum,
1043 &class_device_attr_fwrev,
1044 &class_device_attr_hdw,
1045 &class_device_attr_option_rom_version,
1046 &class_device_attr_state,
1047 &class_device_attr_num_discovered_ports,
1048 &class_device_attr_lpfc_drvr_version,
1049 &class_device_attr_lpfc_log_verbose,
1050 &class_device_attr_lpfc_lun_queue_depth,
b28485ac 1051 &class_device_attr_lpfc_hba_queue_depth,
dea3101e 1052 &class_device_attr_lpfc_nodev_tmo,
c01f3208 1053 &class_device_attr_lpfc_devloss_tmo,
dea3101e
JB
1054 &class_device_attr_lpfc_fcp_class,
1055 &class_device_attr_lpfc_use_adisc,
1056 &class_device_attr_lpfc_ack0,
1057 &class_device_attr_lpfc_topology,
1058 &class_device_attr_lpfc_scan_down,
1059 &class_device_attr_lpfc_link_speed,
875fbdfe
JSEC
1060 &class_device_attr_lpfc_cr_delay,
1061 &class_device_attr_lpfc_cr_count,
cf5bf97e 1062 &class_device_attr_lpfc_multi_ring_support,
a4bc3379
JS
1063 &class_device_attr_lpfc_multi_ring_rctl,
1064 &class_device_attr_lpfc_multi_ring_type,
dea3101e
JB
1065 &class_device_attr_lpfc_fdmi_on,
1066 &class_device_attr_lpfc_max_luns,
1067 &class_device_attr_nport_evt_cnt,
1068 &class_device_attr_management_version,
41415862 1069 &class_device_attr_board_mode,
40496f07 1070 &class_device_attr_issue_reset,
875fbdfe
JSEC
1071 &class_device_attr_lpfc_poll,
1072 &class_device_attr_lpfc_poll_tmo,
4ff43246 1073 &class_device_attr_lpfc_use_msi,
a12e07bc 1074 &class_device_attr_lpfc_soft_wwnn,
c3f28afa 1075 &class_device_attr_lpfc_soft_wwpn,
a12e07bc 1076 &class_device_attr_lpfc_soft_wwn_enable,
dea3101e
JB
1077 NULL,
1078};
1079
1080static ssize_t
1081sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1082{
1083 size_t buf_off;
1084 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1085 struct class_device, kobj));
7f0b5b19 1086 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
1087
1088 if ((off + count) > FF_REG_AREA_SIZE)
1089 return -ERANGE;
1090
1091 if (count == 0) return 0;
1092
1093 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1094 return -EINVAL;
1095
1096 spin_lock_irq(phba->host->host_lock);
1097
1098 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1099 spin_unlock_irq(phba->host->host_lock);
1100 return -EPERM;
1101 }
1102
1103 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1104 writel(*((uint32_t *)(buf + buf_off)),
1105 phba->ctrl_regs_memmap_p + off + buf_off);
1106
1107 spin_unlock_irq(phba->host->host_lock);
1108
1109 return count;
1110}
1111
1112static ssize_t
1113sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1114{
1115 size_t buf_off;
1116 uint32_t * tmp_ptr;
1117 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1118 struct class_device, kobj));
7f0b5b19 1119 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
1120
1121 if (off > FF_REG_AREA_SIZE)
1122 return -ERANGE;
1123
1124 if ((off + count) > FF_REG_AREA_SIZE)
1125 count = FF_REG_AREA_SIZE - off;
1126
1127 if (count == 0) return 0;
1128
1129 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1130 return -EINVAL;
1131
1132 spin_lock_irq(phba->host->host_lock);
1133
1134 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1135 tmp_ptr = (uint32_t *)(buf + buf_off);
1136 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1137 }
1138
1139 spin_unlock_irq(phba->host->host_lock);
1140
1141 return count;
1142}
1143
1144static struct bin_attribute sysfs_ctlreg_attr = {
1145 .attr = {
1146 .name = "ctlreg",
1147 .mode = S_IRUSR | S_IWUSR,
1148 .owner = THIS_MODULE,
1149 },
1150 .size = 256,
1151 .read = sysfs_ctlreg_read,
1152 .write = sysfs_ctlreg_write,
1153};
1154
1155
1156static void
1157sysfs_mbox_idle (struct lpfc_hba * phba)
1158{
1159 phba->sysfs_mbox.state = SMBOX_IDLE;
1160 phba->sysfs_mbox.offset = 0;
1161
1162 if (phba->sysfs_mbox.mbox) {
1163 mempool_free(phba->sysfs_mbox.mbox,
1164 phba->mbox_mem_pool);
1165 phba->sysfs_mbox.mbox = NULL;
1166 }
1167}
1168
1169static ssize_t
1170sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1171{
1172 struct Scsi_Host * host =
1173 class_to_shost(container_of(kobj, struct class_device, kobj));
7f0b5b19 1174 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
1175 struct lpfcMboxq * mbox = NULL;
1176
1177 if ((count + off) > MAILBOX_CMD_SIZE)
1178 return -ERANGE;
1179
1180 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1181 return -EINVAL;
1182
1183 if (count == 0)
1184 return 0;
1185
1186 if (off == 0) {
1187 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1188 if (!mbox)
1189 return -ENOMEM;
fc6c12bc 1190 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
1191 }
1192
1193 spin_lock_irq(host->host_lock);
1194
1195 if (off == 0) {
1196 if (phba->sysfs_mbox.mbox)
1197 mempool_free(mbox, phba->mbox_mem_pool);
1198 else
1199 phba->sysfs_mbox.mbox = mbox;
1200 phba->sysfs_mbox.state = SMBOX_WRITING;
1201 } else {
1202 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1203 phba->sysfs_mbox.offset != off ||
1204 phba->sysfs_mbox.mbox == NULL ) {
1205 sysfs_mbox_idle(phba);
1206 spin_unlock_irq(host->host_lock);
8f6d98d2 1207 return -EAGAIN;
dea3101e
JB
1208 }
1209 }
1210
1211 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1212 buf, count);
1213
1214 phba->sysfs_mbox.offset = off + count;
1215
1216 spin_unlock_irq(host->host_lock);
1217
1218 return count;
1219}
1220
1221static ssize_t
1222sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1223{
1224 struct Scsi_Host *host =
1225 class_to_shost(container_of(kobj, struct class_device,
1226 kobj));
7f0b5b19 1227 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
1228 int rc;
1229
1dcb58e5 1230 if (off > MAILBOX_CMD_SIZE)
dea3101e
JB
1231 return -ERANGE;
1232
1dcb58e5
JS
1233 if ((count + off) > MAILBOX_CMD_SIZE)
1234 count = MAILBOX_CMD_SIZE - off;
dea3101e
JB
1235
1236 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1237 return -EINVAL;
1238
1239 if (off && count == 0)
1240 return 0;
1241
1242 spin_lock_irq(phba->host->host_lock);
1243
1244 if (off == 0 &&
1245 phba->sysfs_mbox.state == SMBOX_WRITING &&
1246 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1247
1248 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1249 /* Offline only */
1250 case MBX_WRITE_NV:
1251 case MBX_INIT_LINK:
1252 case MBX_DOWN_LINK:
1253 case MBX_CONFIG_LINK:
1254 case MBX_CONFIG_RING:
1255 case MBX_RESET_RING:
1256 case MBX_UNREG_LOGIN:
1257 case MBX_CLEAR_LA:
1258 case MBX_DUMP_CONTEXT:
1259 case MBX_RUN_DIAGS:
1260 case MBX_RESTART:
1261 case MBX_FLASH_WR_ULA:
1262 case MBX_SET_MASK:
1263 case MBX_SET_SLIM:
1264 case MBX_SET_DEBUG:
1265 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1266 printk(KERN_WARNING "mbox_read:Command 0x%x "
1267 "is illegal in on-line state\n",
1268 phba->sysfs_mbox.mbox->mb.mbxCommand);
1269 sysfs_mbox_idle(phba);
1270 spin_unlock_irq(phba->host->host_lock);
1271 return -EPERM;
1272 }
1273 case MBX_LOAD_SM:
1274 case MBX_READ_NV:
1275 case MBX_READ_CONFIG:
1276 case MBX_READ_RCONFIG:
1277 case MBX_READ_STATUS:
1278 case MBX_READ_XRI:
1279 case MBX_READ_REV:
1280 case MBX_READ_LNK_STAT:
1281 case MBX_DUMP_MEMORY:
1282 case MBX_DOWN_LOAD:
1283 case MBX_UPDATE_CFG:
41415862 1284 case MBX_KILL_BOARD:
dea3101e
JB
1285 case MBX_LOAD_AREA:
1286 case MBX_LOAD_EXP_ROM:
41415862
JW
1287 case MBX_BEACON:
1288 case MBX_DEL_LD_ENTRY:
dea3101e
JB
1289 break;
1290 case MBX_READ_SPARM64:
1291 case MBX_READ_LA:
1292 case MBX_READ_LA64:
1293 case MBX_REG_LOGIN:
1294 case MBX_REG_LOGIN64:
1295 case MBX_CONFIG_PORT:
1296 case MBX_RUN_BIU_DIAG:
1297 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1298 phba->sysfs_mbox.mbox->mb.mbxCommand);
1299 sysfs_mbox_idle(phba);
1300 spin_unlock_irq(phba->host->host_lock);
1301 return -EPERM;
1302 default:
1303 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1304 phba->sysfs_mbox.mbox->mb.mbxCommand);
1305 sysfs_mbox_idle(phba);
1306 spin_unlock_irq(phba->host->host_lock);
1307 return -EPERM;
1308 }
1309
1310 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1311 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1312
1313 spin_unlock_irq(phba->host->host_lock);
1314 rc = lpfc_sli_issue_mbox (phba,
1315 phba->sysfs_mbox.mbox,
1316 MBX_POLL);
1317 spin_lock_irq(phba->host->host_lock);
1318
1319 } else {
1320 spin_unlock_irq(phba->host->host_lock);
1321 rc = lpfc_sli_issue_mbox_wait (phba,
1322 phba->sysfs_mbox.mbox,
a309a6b6
JS
1323 lpfc_mbox_tmo_val(phba,
1324 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
dea3101e
JB
1325 spin_lock_irq(phba->host->host_lock);
1326 }
1327
1328 if (rc != MBX_SUCCESS) {
1dcb58e5
JS
1329 if (rc == MBX_TIMEOUT) {
1330 phba->sysfs_mbox.mbox->mbox_cmpl =
1331 lpfc_sli_def_mbox_cmpl;
1332 phba->sysfs_mbox.mbox = NULL;
1333 }
dea3101e
JB
1334 sysfs_mbox_idle(phba);
1335 spin_unlock_irq(host->host_lock);
8f6d98d2 1336 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea3101e
JB
1337 }
1338 phba->sysfs_mbox.state = SMBOX_READING;
1339 }
1340 else if (phba->sysfs_mbox.offset != off ||
1341 phba->sysfs_mbox.state != SMBOX_READING) {
1342 printk(KERN_WARNING "mbox_read: Bad State\n");
1343 sysfs_mbox_idle(phba);
1344 spin_unlock_irq(host->host_lock);
8f6d98d2 1345 return -EAGAIN;
dea3101e
JB
1346 }
1347
1348 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1349
1350 phba->sysfs_mbox.offset = off + count;
1351
1dcb58e5 1352 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea3101e
JB
1353 sysfs_mbox_idle(phba);
1354
1355 spin_unlock_irq(phba->host->host_lock);
1356
1357 return count;
1358}
1359
1360static struct bin_attribute sysfs_mbox_attr = {
1361 .attr = {
1362 .name = "mbox",
1363 .mode = S_IRUSR | S_IWUSR,
1364 .owner = THIS_MODULE,
1365 },
1dcb58e5 1366 .size = MAILBOX_CMD_SIZE,
dea3101e
JB
1367 .read = sysfs_mbox_read,
1368 .write = sysfs_mbox_write,
1369};
1370
1371int
1372lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1373{
1374 struct Scsi_Host *host = phba->host;
1375 int error;
1376
1377 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1378 &sysfs_ctlreg_attr);
1379 if (error)
1380 goto out;
1381
1382 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1383 &sysfs_mbox_attr);
1384 if (error)
1385 goto out_remove_ctlreg_attr;
1386
1387 return 0;
1388out_remove_ctlreg_attr:
1389 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1390out:
1391 return error;
1392}
1393
1394void
1395lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1396{
1397 struct Scsi_Host *host = phba->host;
1398
1399 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1400 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1401}
1402
1403
1404/*
1405 * Dynamic FC Host Attributes Support
1406 */
1407
1408static void
1409lpfc_get_host_port_id(struct Scsi_Host *shost)
1410{
7f0b5b19 1411 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1412 /* note: fc_myDID already in cpu endianness */
1413 fc_host_port_id(shost) = phba->fc_myDID;
1414}
1415
1416static void
1417lpfc_get_host_port_type(struct Scsi_Host *shost)
1418{
7f0b5b19 1419 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1420
1421 spin_lock_irq(shost->host_lock);
1422
1423 if (phba->hba_state == LPFC_HBA_READY) {
1424 if (phba->fc_topology == TOPOLOGY_LOOP) {
1425 if (phba->fc_flag & FC_PUBLIC_LOOP)
1426 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1427 else
1428 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1429 } else {
1430 if (phba->fc_flag & FC_FABRIC)
1431 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1432 else
1433 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1434 }
1435 } else
1436 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1437
1438 spin_unlock_irq(shost->host_lock);
1439}
1440
1441static void
1442lpfc_get_host_port_state(struct Scsi_Host *shost)
1443{
7f0b5b19 1444 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1445
1446 spin_lock_irq(shost->host_lock);
1447
1448 if (phba->fc_flag & FC_OFFLINE_MODE)
1449 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1450 else {
1451 switch (phba->hba_state) {
41415862
JW
1452 case LPFC_STATE_UNKNOWN:
1453 case LPFC_WARM_START:
dea3101e
JB
1454 case LPFC_INIT_START:
1455 case LPFC_INIT_MBX_CMDS:
1456 case LPFC_LINK_DOWN:
1457 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1458 break;
1459 case LPFC_LINK_UP:
1460 case LPFC_LOCAL_CFG_LINK:
1461 case LPFC_FLOGI:
1462 case LPFC_FABRIC_CFG_LINK:
1463 case LPFC_NS_REG:
1464 case LPFC_NS_QRY:
1465 case LPFC_BUILD_DISC_LIST:
1466 case LPFC_DISC_AUTH:
1467 case LPFC_CLEAR_LA:
1468 case LPFC_HBA_READY:
1469 /* Links up, beyond this port_type reports state */
1470 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1471 break;
1472 case LPFC_HBA_ERROR:
1473 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1474 break;
1475 default:
1476 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1477 break;
1478 }
1479 }
1480
1481 spin_unlock_irq(shost->host_lock);
1482}
1483
1484static void
1485lpfc_get_host_speed(struct Scsi_Host *shost)
1486{
7f0b5b19 1487 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1488
1489 spin_lock_irq(shost->host_lock);
1490
1491 if (phba->hba_state == LPFC_HBA_READY) {
1492 switch(phba->fc_linkspeed) {
1493 case LA_1GHZ_LINK:
1494 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1495 break;
1496 case LA_2GHZ_LINK:
1497 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1498 break;
1499 case LA_4GHZ_LINK:
1500 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1501 break;
1502 default:
1503 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1504 break;
1505 }
1506 }
1507
1508 spin_unlock_irq(shost->host_lock);
1509}
1510
1511static void
1512lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1513{
7f0b5b19 1514 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
f631b4be 1515 u64 node_name;
dea3101e
JB
1516
1517 spin_lock_irq(shost->host_lock);
1518
1519 if ((phba->fc_flag & FC_FABRIC) ||
1520 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1521 (phba->fc_flag & FC_PUBLIC_LOOP)))
68ce1eb5 1522 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e
JB
1523 else
1524 /* fabric is local port if there is no F/FL_Port */
68ce1eb5 1525 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea3101e
JB
1526
1527 spin_unlock_irq(shost->host_lock);
1528
f631b4be 1529 fc_host_fabric_name(shost) = node_name;
dea3101e
JB
1530}
1531
ae36764a
JS
1532static void
1533lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1534{
1535 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1536
1537 spin_lock_irq(shost->host_lock);
1538 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1539 spin_unlock_irq(shost->host_lock);
1540}
dea3101e
JB
1541
1542static struct fc_host_statistics *
1543lpfc_get_stats(struct Scsi_Host *shost)
1544{
7f0b5b19 1545 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea3101e 1546 struct lpfc_sli *psli = &phba->sli;
f888ba3c 1547 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 1548 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e
JB
1549 LPFC_MBOXQ_t *pmboxq;
1550 MAILBOX_t *pmb;
64ba8818 1551 unsigned long seconds;
433c3579 1552 int rc = 0;
dea3101e
JB
1553
1554 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1555 if (!pmboxq)
1556 return NULL;
1557 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1558
1559 pmb = &pmboxq->mb;
1560 pmb->mbxCommand = MBX_READ_STATUS;
1561 pmb->mbxOwner = OWN_HOST;
1562 pmboxq->context1 = NULL;
1563
1564 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1565 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1566 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1567 else
dea3101e
JB
1568 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1569
1570 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1571 if (rc == MBX_TIMEOUT)
1572 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1573 else
1574 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1575 return NULL;
1576 }
1577
f888ba3c
JSEC
1578 memset(hs, 0, sizeof (struct fc_host_statistics));
1579
dea3101e
JB
1580 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1581 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1582 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1583 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1584
433c3579 1585 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
1586 pmb->mbxCommand = MBX_READ_LNK_STAT;
1587 pmb->mbxOwner = OWN_HOST;
1588 pmboxq->context1 = NULL;
1589
1590 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1591 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1592 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1593 else
dea3101e
JB
1594 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1595
1596 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1597 if (rc == MBX_TIMEOUT)
1598 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1599 else
1600 mempool_free( pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1601 return NULL;
1602 }
1603
1604 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1605 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1606 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1607 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1608 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1609 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1610 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1611
64ba8818
JS
1612 hs->link_failure_count -= lso->link_failure_count;
1613 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1614 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1615 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1616 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1617 hs->invalid_crc_count -= lso->invalid_crc_count;
1618 hs->error_frames -= lso->error_frames;
1619
dea3101e
JB
1620 if (phba->fc_topology == TOPOLOGY_LOOP) {
1621 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 1622 hs->lip_count -= lso->link_events;
dea3101e
JB
1623 hs->nos_count = -1;
1624 } else {
1625 hs->lip_count = -1;
1626 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 1627 hs->nos_count -= lso->link_events;
dea3101e
JB
1628 }
1629
1630 hs->dumped_frames = -1;
1631
64ba8818
JS
1632 seconds = get_seconds();
1633 if (seconds < psli->stats_start)
1634 hs->seconds_since_last_reset = seconds +
1635 ((unsigned long)-1 - psli->stats_start);
1636 else
1637 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 1638
1dcb58e5
JS
1639 mempool_free(pmboxq, phba->mbox_mem_pool);
1640
dea3101e
JB
1641 return hs;
1642}
1643
64ba8818
JS
1644static void
1645lpfc_reset_stats(struct Scsi_Host *shost)
1646{
1647 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1648 struct lpfc_sli *psli = &phba->sli;
1649 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1650 LPFC_MBOXQ_t *pmboxq;
1651 MAILBOX_t *pmb;
1652 int rc = 0;
1653
1654 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1655 if (!pmboxq)
1656 return;
1657 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1658
1659 pmb = &pmboxq->mb;
1660 pmb->mbxCommand = MBX_READ_STATUS;
1661 pmb->mbxOwner = OWN_HOST;
1662 pmb->un.varWords[0] = 0x1; /* reset request */
1663 pmboxq->context1 = NULL;
1664
1665 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1666 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1667 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1668 else
1669 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1670
1671 if (rc != MBX_SUCCESS) {
1672 if (rc == MBX_TIMEOUT)
1673 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1674 else
1675 mempool_free(pmboxq, phba->mbox_mem_pool);
1676 return;
1677 }
1678
1679 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1680 pmb->mbxCommand = MBX_READ_LNK_STAT;
1681 pmb->mbxOwner = OWN_HOST;
1682 pmboxq->context1 = NULL;
1683
1684 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1685 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1686 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1687 else
1688 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1689
1690 if (rc != MBX_SUCCESS) {
1691 if (rc == MBX_TIMEOUT)
1692 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1693 else
1694 mempool_free( pmboxq, phba->mbox_mem_pool);
1695 return;
1696 }
1697
1698 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1699 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1700 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1701 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1702 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1703 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1704 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1705 lso->link_events = (phba->fc_eventTag >> 1);
1706
1707 psli->stats_start = get_seconds();
1708
1dcb58e5
JS
1709 mempool_free(pmboxq, phba->mbox_mem_pool);
1710
64ba8818
JS
1711 return;
1712}
dea3101e
JB
1713
1714/*
1715 * The LPFC driver treats linkdown handling as target loss events so there
1716 * are no sysfs handlers for link_down_tmo.
1717 */
1718static void
1719lpfc_get_starget_port_id(struct scsi_target *starget)
1720{
1721 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1722 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea3101e
JB
1723 uint32_t did = -1;
1724 struct lpfc_nodelist *ndlp = NULL;
1725
1726 spin_lock_irq(shost->host_lock);
1727 /* Search the mapped list for this target ID */
1728 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1729 if (starget->id == ndlp->nlp_sid) {
1730 did = ndlp->nlp_DID;
1731 break;
1732 }
1733 }
1734 spin_unlock_irq(shost->host_lock);
1735
1736 fc_starget_port_id(starget) = did;
1737}
1738
1739static void
1740lpfc_get_starget_node_name(struct scsi_target *starget)
1741{
1742 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1743 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
f631b4be 1744 u64 node_name = 0;
dea3101e
JB
1745 struct lpfc_nodelist *ndlp = NULL;
1746
1747 spin_lock_irq(shost->host_lock);
1748 /* Search the mapped list for this target ID */
1749 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1750 if (starget->id == ndlp->nlp_sid) {
68ce1eb5 1751 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea3101e
JB
1752 break;
1753 }
1754 }
1755 spin_unlock_irq(shost->host_lock);
1756
f631b4be 1757 fc_starget_node_name(starget) = node_name;
dea3101e
JB
1758}
1759
1760static void
1761lpfc_get_starget_port_name(struct scsi_target *starget)
1762{
1763 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1764 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
f631b4be 1765 u64 port_name = 0;
dea3101e
JB
1766 struct lpfc_nodelist *ndlp = NULL;
1767
1768 spin_lock_irq(shost->host_lock);
1769 /* Search the mapped list for this target ID */
1770 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1771 if (starget->id == ndlp->nlp_sid) {
68ce1eb5 1772 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea3101e
JB
1773 break;
1774 }
1775 }
1776 spin_unlock_irq(shost->host_lock);
1777
f631b4be 1778 fc_starget_port_name(starget) = port_name;
dea3101e
JB
1779}
1780
dea3101e
JB
1781static void
1782lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1783{
dea3101e 1784 if (timeout)
c01f3208 1785 rport->dev_loss_tmo = timeout;
dea3101e 1786 else
c01f3208 1787 rport->dev_loss_tmo = 1;
dea3101e
JB
1788}
1789
1790
1791#define lpfc_rport_show_function(field, format_string, sz, cast) \
1792static ssize_t \
1793lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1794{ \
1795 struct fc_rport *rport = transport_class_to_rport(cdev); \
1796 struct lpfc_rport_data *rdata = rport->hostdata; \
1797 return snprintf(buf, sz, format_string, \
1798 (rdata->target) ? cast rdata->target->field : 0); \
1799}
1800
1801#define lpfc_rport_rd_attr(field, format_string, sz) \
1802 lpfc_rport_show_function(field, format_string, sz, ) \
1803static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1804
1805
1806struct fc_function_template lpfc_transport_functions = {
1807 /* fixed attributes the driver supports */
1808 .show_host_node_name = 1,
1809 .show_host_port_name = 1,
1810 .show_host_supported_classes = 1,
1811 .show_host_supported_fc4s = 1,
dea3101e
JB
1812 .show_host_supported_speeds = 1,
1813 .show_host_maxframe_size = 1,
1814
1815 /* dynamic attributes the driver supports */
1816 .get_host_port_id = lpfc_get_host_port_id,
1817 .show_host_port_id = 1,
1818
1819 .get_host_port_type = lpfc_get_host_port_type,
1820 .show_host_port_type = 1,
1821
1822 .get_host_port_state = lpfc_get_host_port_state,
1823 .show_host_port_state = 1,
1824
1825 /* active_fc4s is shown but doesn't change (thus no get function) */
1826 .show_host_active_fc4s = 1,
1827
1828 .get_host_speed = lpfc_get_host_speed,
1829 .show_host_speed = 1,
1830
1831 .get_host_fabric_name = lpfc_get_host_fabric_name,
1832 .show_host_fabric_name = 1,
1833
ae36764a
JS
1834 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1835 .show_host_symbolic_name = 1,
1836
dea3101e
JB
1837 /*
1838 * The LPFC driver treats linkdown handling as target loss events
1839 * so there are no sysfs handlers for link_down_tmo.
1840 */
1841
1842 .get_fc_host_stats = lpfc_get_stats,
64ba8818 1843 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e
JB
1844
1845 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1846 .show_rport_maxframe_size = 1,
1847 .show_rport_supported_classes = 1,
1848
dea3101e
JB
1849 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1850 .show_rport_dev_loss_tmo = 1,
1851
1852 .get_starget_port_id = lpfc_get_starget_port_id,
1853 .show_starget_port_id = 1,
1854
1855 .get_starget_node_name = lpfc_get_starget_node_name,
1856 .show_starget_node_name = 1,
1857
1858 .get_starget_port_name = lpfc_get_starget_port_name,
1859 .show_starget_port_name = 1,
91ca7b01
AV
1860
1861 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
1862 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1863 .terminate_rport_io = lpfc_terminate_rport_io,
dea3101e
JB
1864};
1865
1866void
1867lpfc_get_cfgparam(struct lpfc_hba *phba)
1868{
7bcbb752
JSEC
1869 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1870 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1871 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 1872 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
1873 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1874 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
1875 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1876 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1877 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1878 lpfc_ack0_init(phba, lpfc_ack0);
1879 lpfc_topology_init(phba, lpfc_topology);
1880 lpfc_scan_down_init(phba, lpfc_scan_down);
7bcbb752
JSEC
1881 lpfc_link_speed_init(phba, lpfc_link_speed);
1882 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1883 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1884 lpfc_max_luns_init(phba, lpfc_max_luns);
875fbdfe 1885 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4ff43246 1886 lpfc_use_msi_init(phba, lpfc_use_msi);
c01f3208
JS
1887 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1888 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
875fbdfe 1889 phba->cfg_poll = lpfc_poll;
a12e07bc 1890 phba->cfg_soft_wwnn = 0L;
c3f28afa 1891 phba->cfg_soft_wwpn = 0L;
dea3101e
JB
1892
1893 /*
1894 * The total number of segments is the configuration value plus 2
1895 * since the IOCB need a command and response bde.
1896 */
1897 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1898
1899 /*
1900 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1901 * used to create the sg_dma_buf_pool must be dynamically calculated
1902 */
1903 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1904 sizeof(struct fcp_rsp) +
1905 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1906
1907 switch (phba->pcidev->device) {
1908 case PCI_DEVICE_ID_LP101:
1909 case PCI_DEVICE_ID_BSMB:
1910 case PCI_DEVICE_ID_ZSMB:
1911 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1912 break;
1913 case PCI_DEVICE_ID_RFLY:
1914 case PCI_DEVICE_ID_PFLY:
1915 case PCI_DEVICE_ID_BMID:
1916 case PCI_DEVICE_ID_ZMID:
1917 case PCI_DEVICE_ID_TFLY:
1918 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1919 break;
1920 default:
1921 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1922 }
b28485ac
JW
1923
1924 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1925 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1926
dea3101e
JB
1927 return;
1928}