]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/lpfc/lpfc_attr.c
[SCSI] lpfc 8.1.2: Remove hba_list from struct lpfc_hba
[mirror_ubuntu-bionic-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
JSEC
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 Emulex. All rights reserved. *
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
42
43static void
44lpfc_jedec_to_ascii(int incr, char hdw[])
45{
46 int i, j;
47 for (i = 0; i < 8; i++) {
48 j = (incr & 0xf);
49 if (j <= 9)
50 hdw[7 - i] = 0x30 + j;
51 else
52 hdw[7 - i] = 0x61 + j - 10;
53 incr = (incr >> 4);
54 }
55 hdw[8] = 0;
56 return;
57}
58
59static ssize_t
60lpfc_drvr_version_show(struct class_device *cdev, char *buf)
61{
62 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
63}
64
65static ssize_t
66management_version_show(struct class_device *cdev, char *buf)
67{
68 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
69}
70
71static ssize_t
72lpfc_info_show(struct class_device *cdev, char *buf)
73{
74 struct Scsi_Host *host = class_to_shost(cdev);
75 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
76}
77
78static ssize_t
79lpfc_serialnum_show(struct class_device *cdev, char *buf)
80{
81 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 82 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
83 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
84}
85
86static ssize_t
87lpfc_modeldesc_show(struct class_device *cdev, char *buf)
88{
89 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 90 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
91 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
92}
93
94static ssize_t
95lpfc_modelname_show(struct class_device *cdev, char *buf)
96{
97 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 98 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
99 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
100}
101
102static ssize_t
103lpfc_programtype_show(struct class_device *cdev, char *buf)
104{
105 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
107 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
108}
109
110static ssize_t
111lpfc_portnum_show(struct class_device *cdev, char *buf)
112{
113 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
115 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
116}
117
118static ssize_t
119lpfc_fwrev_show(struct class_device *cdev, char *buf)
120{
121 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
123 char fwrev[32];
124 lpfc_decode_firmware_rev(phba, fwrev, 1);
125 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
126}
127
128static ssize_t
129lpfc_hdw_show(struct class_device *cdev, char *buf)
130{
131 char hdw[9];
132 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
134 lpfc_vpd_t *vp = &phba->vpd;
135 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
136 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
137}
138static ssize_t
139lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
140{
141 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
143 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
144}
145static ssize_t
146lpfc_state_show(struct class_device *cdev, char *buf)
147{
148 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
150 int len = 0;
151 switch (phba->hba_state) {
152 case LPFC_INIT_START:
153 case LPFC_INIT_MBX_CMDS:
154 case LPFC_LINK_DOWN:
155 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
156 break;
157 case LPFC_LINK_UP:
158 case LPFC_LOCAL_CFG_LINK:
159 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
160 break;
161 case LPFC_FLOGI:
162 case LPFC_FABRIC_CFG_LINK:
163 case LPFC_NS_REG:
164 case LPFC_NS_QRY:
165 case LPFC_BUILD_DISC_LIST:
166 case LPFC_DISC_AUTH:
167 case LPFC_CLEAR_LA:
168 len += snprintf(buf + len, PAGE_SIZE-len,
169 "Link Up - Discovery\n");
170 break;
171 case LPFC_HBA_READY:
172 len += snprintf(buf + len, PAGE_SIZE-len,
173 "Link Up - Ready:\n");
174 if (phba->fc_topology == TOPOLOGY_LOOP) {
175 if (phba->fc_flag & FC_PUBLIC_LOOP)
176 len += snprintf(buf + len, PAGE_SIZE-len,
177 " Public Loop\n");
178 else
179 len += snprintf(buf + len, PAGE_SIZE-len,
180 " Private Loop\n");
181 } else {
182 if (phba->fc_flag & FC_FABRIC)
183 len += snprintf(buf + len, PAGE_SIZE-len,
184 " Fabric\n");
185 else
186 len += snprintf(buf + len, PAGE_SIZE-len,
187 " Point-2-Point\n");
188 }
189 }
190 return len;
191}
192
193static ssize_t
194lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
195{
196 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 197 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
198 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
199 phba->fc_unmap_cnt);
200}
201
202
91ca7b01
AV
203static int
204lpfc_issue_lip(struct Scsi_Host *host)
dea3101e 205{
7f0b5b19 206 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea3101e
JB
207 LPFC_MBOXQ_t *pmboxq;
208 int mbxstatus = MBXERR_ERROR;
209
dea3101e
JB
210 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
211 (phba->hba_state != LPFC_HBA_READY))
212 return -EPERM;
213
214 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
215
216 if (!pmboxq)
217 return -ENOMEM;
218
219 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
220 lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed);
221 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
222
223 if (mbxstatus == MBX_TIMEOUT)
224 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
225 else
433c3579 226 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
227
228 if (mbxstatus == MBXERR_ERROR)
229 return -EIO;
230
91ca7b01 231 return 0;
dea3101e
JB
232}
233
234static ssize_t
235lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
236{
237 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 238 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
239 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
240}
241
242static ssize_t
243lpfc_board_online_show(struct class_device *cdev, char *buf)
244{
245 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 246 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e 247
dea3101e
JB
248 if (phba->fc_flag & FC_OFFLINE_MODE)
249 return snprintf(buf, PAGE_SIZE, "0\n");
250 else
251 return snprintf(buf, PAGE_SIZE, "1\n");
252}
253
254static ssize_t
255lpfc_board_online_store(struct class_device *cdev, const char *buf,
256 size_t count)
257{
258 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 259 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
260 struct completion online_compl;
261 int val=0, status=0;
262
263 if (sscanf(buf, "%d", &val) != 1)
755c0d06 264 return -EINVAL;
dea3101e
JB
265
266 init_completion(&online_compl);
267
268 if (val)
269 lpfc_workq_post_event(phba, &status, &online_compl,
270 LPFC_EVT_ONLINE);
271 else
272 lpfc_workq_post_event(phba, &status, &online_compl,
273 LPFC_EVT_OFFLINE);
274 wait_for_completion(&online_compl);
275 if (!status)
276 return strlen(buf);
277 else
755c0d06 278 return -EIO;
dea3101e
JB
279}
280
875fbdfe
JSEC
281static ssize_t
282lpfc_poll_show(struct class_device *cdev, char *buf)
283{
284 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 285 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
875fbdfe
JSEC
286
287 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
288}
289
290static ssize_t
291lpfc_poll_store(struct class_device *cdev, const char *buf,
292 size_t count)
293{
294 struct Scsi_Host *host = class_to_shost(cdev);
7f0b5b19 295 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
875fbdfe
JSEC
296 uint32_t creg_val;
297 uint32_t old_val;
298 int val=0;
299
300 if (!isdigit(buf[0]))
301 return -EINVAL;
302
303 if (sscanf(buf, "%i", &val) != 1)
304 return -EINVAL;
305
306 if ((val & 0x3) != val)
307 return -EINVAL;
308
309 spin_lock_irq(phba->host->host_lock);
310
311 old_val = phba->cfg_poll;
312
313 if (val & ENABLE_FCP_RING_POLLING) {
314 if ((val & DISABLE_FCP_RING_INT) &&
315 !(old_val & DISABLE_FCP_RING_INT)) {
316 creg_val = readl(phba->HCregaddr);
317 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
318 writel(creg_val, phba->HCregaddr);
319 readl(phba->HCregaddr); /* flush */
320
321 lpfc_poll_start_timer(phba);
322 }
323 } else if (val != 0x0) {
324 spin_unlock_irq(phba->host->host_lock);
325 return -EINVAL;
326 }
327
328 if (!(val & DISABLE_FCP_RING_INT) &&
329 (old_val & DISABLE_FCP_RING_INT))
330 {
331 spin_unlock_irq(phba->host->host_lock);
332 del_timer(&phba->fcp_poll_timer);
333 spin_lock_irq(phba->host->host_lock);
334 creg_val = readl(phba->HCregaddr);
335 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
336 writel(creg_val, phba->HCregaddr);
337 readl(phba->HCregaddr); /* flush */
338 }
339
340 phba->cfg_poll = val;
341
342 spin_unlock_irq(phba->host->host_lock);
343
344 return strlen(buf);
345}
dea3101e
JB
346
347#define lpfc_param_show(attr) \
348static ssize_t \
349lpfc_##attr##_show(struct class_device *cdev, char *buf) \
350{ \
351 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 352 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea3101e 353 int val = 0;\
7bcbb752
JSEC
354 val = phba->cfg_##attr;\
355 return snprintf(buf, PAGE_SIZE, "%d\n",\
356 phba->cfg_##attr);\
357}
358
93a20f74
JSEC
359#define lpfc_param_hex_show(attr) \
360static ssize_t \
361lpfc_##attr##_show(struct class_device *cdev, char *buf) \
362{ \
363 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 364 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
93a20f74
JSEC
365 int val = 0;\
366 val = phba->cfg_##attr;\
367 return snprintf(buf, PAGE_SIZE, "%#x\n",\
368 phba->cfg_##attr);\
369}
370
7bcbb752
JSEC
371#define lpfc_param_init(attr, default, minval, maxval) \
372static int \
373lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
374{ \
375 if (val >= minval && val <= maxval) {\
376 phba->cfg_##attr = val;\
377 return 0;\
dea3101e 378 }\
7bcbb752
JSEC
379 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
380 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
381 "allowed range is ["#minval", "#maxval"]\n", \
382 phba->brd_no, val); \
383 phba->cfg_##attr = default;\
384 return -EINVAL;\
dea3101e
JB
385}
386
7bcbb752
JSEC
387#define lpfc_param_set(attr, default, minval, maxval) \
388static int \
389lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
390{ \
391 if (val >= minval && val <= maxval) {\
392 phba->cfg_##attr = val;\
393 return 0;\
394 }\
395 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
396 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
397 "allowed range is ["#minval", "#maxval"]\n", \
398 phba->brd_no, val); \
399 return -EINVAL;\
400}
401
402#define lpfc_param_store(attr) \
dea3101e
JB
403static ssize_t \
404lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
405{ \
406 struct Scsi_Host *host = class_to_shost(cdev);\
7f0b5b19 407 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
7bcbb752 408 int val=0;\
93a20f74
JSEC
409 if (!isdigit(buf[0]))\
410 return -EINVAL;\
411 if (sscanf(buf, "%i", &val) != 1)\
412 return -EINVAL;\
7bcbb752 413 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 414 return strlen(buf);\
7bcbb752
JSEC
415 else \
416 return -EINVAL;\
dea3101e
JB
417}
418
7bcbb752
JSEC
419#define LPFC_ATTR(name, defval, minval, maxval, desc) \
420static int lpfc_##name = defval;\
dea3101e
JB
421module_param(lpfc_##name, int, 0);\
422MODULE_PARM_DESC(lpfc_##name, desc);\
7bcbb752 423lpfc_param_init(name, defval, minval, maxval)
dea3101e
JB
424
425#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
426static int lpfc_##name = defval;\
427module_param(lpfc_##name, int, 0);\
428MODULE_PARM_DESC(lpfc_##name, desc);\
429lpfc_param_show(name)\
7bcbb752 430lpfc_param_init(name, defval, minval, maxval)\
dea3101e
JB
431static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
432
433#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
434static int lpfc_##name = defval;\
435module_param(lpfc_##name, int, 0);\
436MODULE_PARM_DESC(lpfc_##name, desc);\
437lpfc_param_show(name)\
7bcbb752
JSEC
438lpfc_param_init(name, defval, minval, maxval)\
439lpfc_param_set(name, defval, minval, maxval)\
440lpfc_param_store(name)\
dea3101e
JB
441static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
442 lpfc_##name##_show, lpfc_##name##_store)
443
93a20f74
JSEC
444#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
445static int lpfc_##name = defval;\
446module_param(lpfc_##name, int, 0);\
447MODULE_PARM_DESC(lpfc_##name, desc);\
448lpfc_param_hex_show(name)\
449lpfc_param_init(name, defval, minval, maxval)\
450static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
451
452#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
453static int lpfc_##name = defval;\
454module_param(lpfc_##name, int, 0);\
455MODULE_PARM_DESC(lpfc_##name, desc);\
456lpfc_param_hex_show(name)\
457lpfc_param_init(name, defval, minval, maxval)\
458lpfc_param_set(name, defval, minval, maxval)\
459lpfc_param_store(name)\
460static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
461 lpfc_##name##_show, lpfc_##name##_store)
462
dea3101e
JB
463static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
464static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
465static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
466static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
467static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
468static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
469static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
470static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
471static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
472static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
473 lpfc_option_rom_version_show, NULL);
474static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
475 lpfc_num_discovered_ports_show, NULL);
476static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
477static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
478 NULL);
479static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
480 NULL);
dea3101e
JB
481static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
482 lpfc_board_online_show, lpfc_board_online_store);
483
875fbdfe
JSEC
484static int lpfc_poll = 0;
485module_param(lpfc_poll, int, 0);
486MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
487 " 0 - none,"
488 " 1 - poll with interrupts enabled"
489 " 3 - poll and disable FCP ring interrupts");
490
491static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
492 lpfc_poll_show, lpfc_poll_store);
dea3101e
JB
493
494/*
495# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
496# deluged with LOTS of information.
497# You can set a bit mask to record specific types of verbose messages:
498#
499# LOG_ELS 0x1 ELS events
500# LOG_DISCOVERY 0x2 Link discovery events
501# LOG_MBOX 0x4 Mailbox events
502# LOG_INIT 0x8 Initialization events
503# LOG_LINK_EVENT 0x10 Link events
504# LOG_IP 0x20 IP traffic history
505# LOG_FCP 0x40 FCP traffic history
506# LOG_NODE 0x80 Node table events
507# LOG_MISC 0x400 Miscellaneous events
508# LOG_SLI 0x800 SLI events
509# LOG_CHK_COND 0x1000 FCP Check condition flag
510# LOG_LIBDFC 0x2000 LIBDFC events
511# LOG_ALL_MSG 0xffff LOG all messages
512*/
93a20f74 513LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea3101e
JB
514
515/*
516# lun_queue_depth: This parameter is used to limit the number of outstanding
517# commands per FCP LUN. Value range is [1,128]. Default value is 30.
518*/
519LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
520 "Max number of FCP commands we can queue to a specific LUN");
521
b28485ac
JW
522/*
523# hba_queue_depth: This parameter is used to limit the number of outstanding
524# commands per lpfc HBA. Value range is [32,8192]. If this parameter
525# value is greater than the maximum number of exchanges supported by the HBA,
526# then maximum number of exchanges supported by the HBA is used to determine
527# the hba_queue_depth.
528*/
529LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
530 "Max number of FCP commands we can queue to a lpfc HBA");
531
dea3101e
JB
532/*
533# Some disk devices have a "select ID" or "select Target" capability.
534# From a protocol standpoint "select ID" usually means select the
535# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
536# annex" which contains a table that maps a "select ID" (a number
537# between 0 and 7F) to an ALPA. By default, for compatibility with
538# older drivers, the lpfc driver scans this table from low ALPA to high
539# ALPA.
540#
541# Turning on the scan-down variable (on = 1, off = 0) will
542# cause the lpfc driver to use an inverted table, effectively
543# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
544#
545# (Note: This "select ID" functionality is a LOOP ONLY characteristic
546# and will not work across a fabric. Also this parameter will take
547# effect only in the case when ALPA map is not available.)
548*/
549LPFC_ATTR_R(scan_down, 1, 0, 1,
550 "Start scanning for devices from highest ALPA to lowest");
551
552/*
553# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
09703d38 554# until the timer expires. Value range is [0,255]. Default value is 30.
dea3101e
JB
555# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
556*/
557LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
558 "Seconds driver will hold I/O waiting for a device to come back");
559
560/*
561# lpfc_topology: link topology for init link
562# 0x0 = attempt loop mode then point-to-point
563# 0x02 = attempt point-to-point mode only
564# 0x04 = attempt loop mode only
565# 0x06 = attempt point-to-point mode then loop
566# Set point-to-point mode if you want to run as an N_Port.
567# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
568# Default value is 0.
569*/
570LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
571
572/*
573# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
574# connection.
575# 0 = auto select (default)
576# 1 = 1 Gigabaud
577# 2 = 2 Gigabaud
578# 4 = 4 Gigabaud
579# Value range is [0,4]. Default value is 0.
580*/
581LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
582
583/*
584# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
585# Value range is [2,3]. Default value is 3.
586*/
587LPFC_ATTR_R(fcp_class, 3, 2, 3,
588 "Select Fibre Channel class of service for FCP sequences");
589
590/*
591# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
592# is [0,1]. Default value is 0.
593*/
594LPFC_ATTR_RW(use_adisc, 0, 0, 1,
595 "Use ADISC on rediscovery to authenticate FCP devices");
596
597/*
598# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
599# range is [0,1]. Default value is 0.
600*/
601LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
602
603/*
604# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
605# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
606# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
607# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
608# cr_delay is set to 0.
609*/
875fbdfe 610LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an"
dea3101e
JB
611 "interrupt response is generated");
612
875fbdfe 613LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an"
dea3101e
JB
614 "interrupt response is generated");
615
616/*
617# lpfc_fdmi_on: controls FDMI support.
618# 0 = no FDMI support
619# 1 = support FDMI without attribute of hostname
620# 2 = support FDMI with attribute of hostname
621# Value range [0,2]. Default value is 0.
622*/
623LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
624
625/*
626# Specifies the maximum number of ELS cmds we can have outstanding (for
627# discovery). Value range is [1,64]. Default value = 32.
628*/
7bcbb752 629LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands"
dea3101e
JB
630 "during discovery");
631
632/*
633# lpfc_max_luns: maximum number of LUNs per target driver will support
634# Value range is [1,32768]. Default value is 256.
635# NOTE: The SCSI layer will scan each target for this many luns
636*/
637LPFC_ATTR_R(max_luns, 256, 1, 32768,
638 "Maximum number of LUNs per target driver will support");
639
875fbdfe
JSEC
640/*
641# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
642# Value range is [1,255], default value is 10.
643*/
644LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
645 "Milliseconds driver will wait between polling FCP ring");
646
dea3101e
JB
647struct class_device_attribute *lpfc_host_attrs[] = {
648 &class_device_attr_info,
649 &class_device_attr_serialnum,
650 &class_device_attr_modeldesc,
651 &class_device_attr_modelname,
652 &class_device_attr_programtype,
653 &class_device_attr_portnum,
654 &class_device_attr_fwrev,
655 &class_device_attr_hdw,
656 &class_device_attr_option_rom_version,
657 &class_device_attr_state,
658 &class_device_attr_num_discovered_ports,
659 &class_device_attr_lpfc_drvr_version,
660 &class_device_attr_lpfc_log_verbose,
661 &class_device_attr_lpfc_lun_queue_depth,
b28485ac 662 &class_device_attr_lpfc_hba_queue_depth,
dea3101e
JB
663 &class_device_attr_lpfc_nodev_tmo,
664 &class_device_attr_lpfc_fcp_class,
665 &class_device_attr_lpfc_use_adisc,
666 &class_device_attr_lpfc_ack0,
667 &class_device_attr_lpfc_topology,
668 &class_device_attr_lpfc_scan_down,
669 &class_device_attr_lpfc_link_speed,
875fbdfe
JSEC
670 &class_device_attr_lpfc_cr_delay,
671 &class_device_attr_lpfc_cr_count,
dea3101e
JB
672 &class_device_attr_lpfc_fdmi_on,
673 &class_device_attr_lpfc_max_luns,
674 &class_device_attr_nport_evt_cnt,
675 &class_device_attr_management_version,
dea3101e 676 &class_device_attr_board_online,
875fbdfe
JSEC
677 &class_device_attr_lpfc_poll,
678 &class_device_attr_lpfc_poll_tmo,
dea3101e
JB
679 NULL,
680};
681
682static ssize_t
683sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
684{
685 size_t buf_off;
686 struct Scsi_Host *host = class_to_shost(container_of(kobj,
687 struct class_device, kobj));
7f0b5b19 688 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
689
690 if ((off + count) > FF_REG_AREA_SIZE)
691 return -ERANGE;
692
693 if (count == 0) return 0;
694
695 if (off % 4 || count % 4 || (unsigned long)buf % 4)
696 return -EINVAL;
697
698 spin_lock_irq(phba->host->host_lock);
699
700 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
701 spin_unlock_irq(phba->host->host_lock);
702 return -EPERM;
703 }
704
705 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
706 writel(*((uint32_t *)(buf + buf_off)),
707 phba->ctrl_regs_memmap_p + off + buf_off);
708
709 spin_unlock_irq(phba->host->host_lock);
710
711 return count;
712}
713
714static ssize_t
715sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
716{
717 size_t buf_off;
718 uint32_t * tmp_ptr;
719 struct Scsi_Host *host = class_to_shost(container_of(kobj,
720 struct class_device, kobj));
7f0b5b19 721 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
722
723 if (off > FF_REG_AREA_SIZE)
724 return -ERANGE;
725
726 if ((off + count) > FF_REG_AREA_SIZE)
727 count = FF_REG_AREA_SIZE - off;
728
729 if (count == 0) return 0;
730
731 if (off % 4 || count % 4 || (unsigned long)buf % 4)
732 return -EINVAL;
733
734 spin_lock_irq(phba->host->host_lock);
735
736 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
737 tmp_ptr = (uint32_t *)(buf + buf_off);
738 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
739 }
740
741 spin_unlock_irq(phba->host->host_lock);
742
743 return count;
744}
745
746static struct bin_attribute sysfs_ctlreg_attr = {
747 .attr = {
748 .name = "ctlreg",
749 .mode = S_IRUSR | S_IWUSR,
750 .owner = THIS_MODULE,
751 },
752 .size = 256,
753 .read = sysfs_ctlreg_read,
754 .write = sysfs_ctlreg_write,
755};
756
757
758static void
759sysfs_mbox_idle (struct lpfc_hba * phba)
760{
761 phba->sysfs_mbox.state = SMBOX_IDLE;
762 phba->sysfs_mbox.offset = 0;
763
764 if (phba->sysfs_mbox.mbox) {
765 mempool_free(phba->sysfs_mbox.mbox,
766 phba->mbox_mem_pool);
767 phba->sysfs_mbox.mbox = NULL;
768 }
769}
770
771static ssize_t
772sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
773{
774 struct Scsi_Host * host =
775 class_to_shost(container_of(kobj, struct class_device, kobj));
7f0b5b19 776 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
777 struct lpfcMboxq * mbox = NULL;
778
779 if ((count + off) > MAILBOX_CMD_SIZE)
780 return -ERANGE;
781
782 if (off % 4 || count % 4 || (unsigned long)buf % 4)
783 return -EINVAL;
784
785 if (count == 0)
786 return 0;
787
788 if (off == 0) {
789 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
790 if (!mbox)
791 return -ENOMEM;
792
793 }
794
795 spin_lock_irq(host->host_lock);
796
797 if (off == 0) {
798 if (phba->sysfs_mbox.mbox)
799 mempool_free(mbox, phba->mbox_mem_pool);
800 else
801 phba->sysfs_mbox.mbox = mbox;
802 phba->sysfs_mbox.state = SMBOX_WRITING;
803 } else {
804 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
805 phba->sysfs_mbox.offset != off ||
806 phba->sysfs_mbox.mbox == NULL ) {
807 sysfs_mbox_idle(phba);
808 spin_unlock_irq(host->host_lock);
809 return -EINVAL;
810 }
811 }
812
813 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
814 buf, count);
815
816 phba->sysfs_mbox.offset = off + count;
817
818 spin_unlock_irq(host->host_lock);
819
820 return count;
821}
822
823static ssize_t
824sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
825{
826 struct Scsi_Host *host =
827 class_to_shost(container_of(kobj, struct class_device,
828 kobj));
7f0b5b19 829 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea3101e
JB
830 int rc;
831
832 if (off > sizeof(MAILBOX_t))
833 return -ERANGE;
834
835 if ((count + off) > sizeof(MAILBOX_t))
836 count = sizeof(MAILBOX_t) - off;
837
838 if (off % 4 || count % 4 || (unsigned long)buf % 4)
839 return -EINVAL;
840
841 if (off && count == 0)
842 return 0;
843
844 spin_lock_irq(phba->host->host_lock);
845
846 if (off == 0 &&
847 phba->sysfs_mbox.state == SMBOX_WRITING &&
848 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
849
850 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
851 /* Offline only */
852 case MBX_WRITE_NV:
853 case MBX_INIT_LINK:
854 case MBX_DOWN_LINK:
855 case MBX_CONFIG_LINK:
856 case MBX_CONFIG_RING:
857 case MBX_RESET_RING:
858 case MBX_UNREG_LOGIN:
859 case MBX_CLEAR_LA:
860 case MBX_DUMP_CONTEXT:
861 case MBX_RUN_DIAGS:
862 case MBX_RESTART:
863 case MBX_FLASH_WR_ULA:
864 case MBX_SET_MASK:
865 case MBX_SET_SLIM:
866 case MBX_SET_DEBUG:
867 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
868 printk(KERN_WARNING "mbox_read:Command 0x%x "
869 "is illegal in on-line state\n",
870 phba->sysfs_mbox.mbox->mb.mbxCommand);
871 sysfs_mbox_idle(phba);
872 spin_unlock_irq(phba->host->host_lock);
873 return -EPERM;
874 }
875 case MBX_LOAD_SM:
876 case MBX_READ_NV:
877 case MBX_READ_CONFIG:
878 case MBX_READ_RCONFIG:
879 case MBX_READ_STATUS:
880 case MBX_READ_XRI:
881 case MBX_READ_REV:
882 case MBX_READ_LNK_STAT:
883 case MBX_DUMP_MEMORY:
884 case MBX_DOWN_LOAD:
885 case MBX_UPDATE_CFG:
886 case MBX_LOAD_AREA:
887 case MBX_LOAD_EXP_ROM:
888 break;
889 case MBX_READ_SPARM64:
890 case MBX_READ_LA:
891 case MBX_READ_LA64:
892 case MBX_REG_LOGIN:
893 case MBX_REG_LOGIN64:
894 case MBX_CONFIG_PORT:
895 case MBX_RUN_BIU_DIAG:
896 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
897 phba->sysfs_mbox.mbox->mb.mbxCommand);
898 sysfs_mbox_idle(phba);
899 spin_unlock_irq(phba->host->host_lock);
900 return -EPERM;
901 default:
902 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
903 phba->sysfs_mbox.mbox->mb.mbxCommand);
904 sysfs_mbox_idle(phba);
905 spin_unlock_irq(phba->host->host_lock);
906 return -EPERM;
907 }
908
909 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
910 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
911
912 spin_unlock_irq(phba->host->host_lock);
913 rc = lpfc_sli_issue_mbox (phba,
914 phba->sysfs_mbox.mbox,
915 MBX_POLL);
916 spin_lock_irq(phba->host->host_lock);
917
918 } else {
919 spin_unlock_irq(phba->host->host_lock);
920 rc = lpfc_sli_issue_mbox_wait (phba,
921 phba->sysfs_mbox.mbox,
922 phba->fc_ratov * 2);
923 spin_lock_irq(phba->host->host_lock);
924 }
925
926 if (rc != MBX_SUCCESS) {
927 sysfs_mbox_idle(phba);
928 spin_unlock_irq(host->host_lock);
929 return -ENODEV;
930 }
931 phba->sysfs_mbox.state = SMBOX_READING;
932 }
933 else if (phba->sysfs_mbox.offset != off ||
934 phba->sysfs_mbox.state != SMBOX_READING) {
935 printk(KERN_WARNING "mbox_read: Bad State\n");
936 sysfs_mbox_idle(phba);
937 spin_unlock_irq(host->host_lock);
938 return -EINVAL;
939 }
940
941 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
942
943 phba->sysfs_mbox.offset = off + count;
944
945 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
946 sysfs_mbox_idle(phba);
947
948 spin_unlock_irq(phba->host->host_lock);
949
950 return count;
951}
952
953static struct bin_attribute sysfs_mbox_attr = {
954 .attr = {
955 .name = "mbox",
956 .mode = S_IRUSR | S_IWUSR,
957 .owner = THIS_MODULE,
958 },
959 .size = sizeof(MAILBOX_t),
960 .read = sysfs_mbox_read,
961 .write = sysfs_mbox_write,
962};
963
964int
965lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
966{
967 struct Scsi_Host *host = phba->host;
968 int error;
969
970 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
971 &sysfs_ctlreg_attr);
972 if (error)
973 goto out;
974
975 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
976 &sysfs_mbox_attr);
977 if (error)
978 goto out_remove_ctlreg_attr;
979
980 return 0;
981out_remove_ctlreg_attr:
982 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
983out:
984 return error;
985}
986
987void
988lpfc_free_sysfs_attr(struct lpfc_hba *phba)
989{
990 struct Scsi_Host *host = phba->host;
991
992 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
993 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
994}
995
996
997/*
998 * Dynamic FC Host Attributes Support
999 */
1000
1001static void
1002lpfc_get_host_port_id(struct Scsi_Host *shost)
1003{
7f0b5b19 1004 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1005 /* note: fc_myDID already in cpu endianness */
1006 fc_host_port_id(shost) = phba->fc_myDID;
1007}
1008
1009static void
1010lpfc_get_host_port_type(struct Scsi_Host *shost)
1011{
7f0b5b19 1012 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1013
1014 spin_lock_irq(shost->host_lock);
1015
1016 if (phba->hba_state == LPFC_HBA_READY) {
1017 if (phba->fc_topology == TOPOLOGY_LOOP) {
1018 if (phba->fc_flag & FC_PUBLIC_LOOP)
1019 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1020 else
1021 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1022 } else {
1023 if (phba->fc_flag & FC_FABRIC)
1024 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1025 else
1026 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1027 }
1028 } else
1029 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1030
1031 spin_unlock_irq(shost->host_lock);
1032}
1033
1034static void
1035lpfc_get_host_port_state(struct Scsi_Host *shost)
1036{
7f0b5b19 1037 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1038
1039 spin_lock_irq(shost->host_lock);
1040
1041 if (phba->fc_flag & FC_OFFLINE_MODE)
1042 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1043 else {
1044 switch (phba->hba_state) {
1045 case LPFC_INIT_START:
1046 case LPFC_INIT_MBX_CMDS:
1047 case LPFC_LINK_DOWN:
1048 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1049 break;
1050 case LPFC_LINK_UP:
1051 case LPFC_LOCAL_CFG_LINK:
1052 case LPFC_FLOGI:
1053 case LPFC_FABRIC_CFG_LINK:
1054 case LPFC_NS_REG:
1055 case LPFC_NS_QRY:
1056 case LPFC_BUILD_DISC_LIST:
1057 case LPFC_DISC_AUTH:
1058 case LPFC_CLEAR_LA:
1059 case LPFC_HBA_READY:
1060 /* Links up, beyond this port_type reports state */
1061 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1062 break;
1063 case LPFC_HBA_ERROR:
1064 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1065 break;
1066 default:
1067 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1068 break;
1069 }
1070 }
1071
1072 spin_unlock_irq(shost->host_lock);
1073}
1074
1075static void
1076lpfc_get_host_speed(struct Scsi_Host *shost)
1077{
7f0b5b19 1078 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea3101e
JB
1079
1080 spin_lock_irq(shost->host_lock);
1081
1082 if (phba->hba_state == LPFC_HBA_READY) {
1083 switch(phba->fc_linkspeed) {
1084 case LA_1GHZ_LINK:
1085 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1086 break;
1087 case LA_2GHZ_LINK:
1088 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1089 break;
1090 case LA_4GHZ_LINK:
1091 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1092 break;
1093 default:
1094 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1095 break;
1096 }
1097 }
1098
1099 spin_unlock_irq(shost->host_lock);
1100}
1101
1102static void
1103lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1104{
7f0b5b19 1105 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
f631b4be 1106 u64 node_name;
dea3101e
JB
1107
1108 spin_lock_irq(shost->host_lock);
1109
1110 if ((phba->fc_flag & FC_FABRIC) ||
1111 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1112 (phba->fc_flag & FC_PUBLIC_LOOP)))
68ce1eb5 1113 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e
JB
1114 else
1115 /* fabric is local port if there is no F/FL_Port */
68ce1eb5 1116 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea3101e
JB
1117
1118 spin_unlock_irq(shost->host_lock);
1119
f631b4be 1120 fc_host_fabric_name(shost) = node_name;
dea3101e
JB
1121}
1122
1123
1124static struct fc_host_statistics *
1125lpfc_get_stats(struct Scsi_Host *shost)
1126{
7f0b5b19 1127 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea3101e 1128 struct lpfc_sli *psli = &phba->sli;
f888ba3c 1129 struct fc_host_statistics *hs = &phba->link_stats;
dea3101e
JB
1130 LPFC_MBOXQ_t *pmboxq;
1131 MAILBOX_t *pmb;
433c3579 1132 int rc = 0;
dea3101e
JB
1133
1134 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1135 if (!pmboxq)
1136 return NULL;
1137 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1138
1139 pmb = &pmboxq->mb;
1140 pmb->mbxCommand = MBX_READ_STATUS;
1141 pmb->mbxOwner = OWN_HOST;
1142 pmboxq->context1 = NULL;
1143
1144 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1145 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1146 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1147 else
dea3101e
JB
1148 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1149
1150 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1151 if (rc == MBX_TIMEOUT)
1152 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1153 else
1154 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1155 return NULL;
1156 }
1157
f888ba3c
JSEC
1158 memset(hs, 0, sizeof (struct fc_host_statistics));
1159
dea3101e
JB
1160 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1161 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1162 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1163 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1164
433c3579 1165 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
1166 pmb->mbxCommand = MBX_READ_LNK_STAT;
1167 pmb->mbxOwner = OWN_HOST;
1168 pmboxq->context1 = NULL;
1169
1170 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1171 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1172 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1173 else
dea3101e
JB
1174 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1175
1176 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1177 if (rc == MBX_TIMEOUT)
1178 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1179 else
1180 mempool_free( pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1181 return NULL;
1182 }
1183
1184 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1185 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1186 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1187 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1188 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1189 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1190 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1191
1192 if (phba->fc_topology == TOPOLOGY_LOOP) {
1193 hs->lip_count = (phba->fc_eventTag >> 1);
1194 hs->nos_count = -1;
1195 } else {
1196 hs->lip_count = -1;
1197 hs->nos_count = (phba->fc_eventTag >> 1);
1198 }
1199
1200 hs->dumped_frames = -1;
1201
1202/* FIX ME */
1203 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1204
1205 return hs;
1206}
1207
1208
1209/*
1210 * The LPFC driver treats linkdown handling as target loss events so there
1211 * are no sysfs handlers for link_down_tmo.
1212 */
1213static void
1214lpfc_get_starget_port_id(struct scsi_target *starget)
1215{
1216 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1217 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea3101e
JB
1218 uint32_t did = -1;
1219 struct lpfc_nodelist *ndlp = NULL;
1220
1221 spin_lock_irq(shost->host_lock);
1222 /* Search the mapped list for this target ID */
1223 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1224 if (starget->id == ndlp->nlp_sid) {
1225 did = ndlp->nlp_DID;
1226 break;
1227 }
1228 }
1229 spin_unlock_irq(shost->host_lock);
1230
1231 fc_starget_port_id(starget) = did;
1232}
1233
1234static void
1235lpfc_get_starget_node_name(struct scsi_target *starget)
1236{
1237 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1238 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
f631b4be 1239 u64 node_name = 0;
dea3101e
JB
1240 struct lpfc_nodelist *ndlp = NULL;
1241
1242 spin_lock_irq(shost->host_lock);
1243 /* Search the mapped list for this target ID */
1244 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1245 if (starget->id == ndlp->nlp_sid) {
68ce1eb5 1246 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea3101e
JB
1247 break;
1248 }
1249 }
1250 spin_unlock_irq(shost->host_lock);
1251
f631b4be 1252 fc_starget_node_name(starget) = node_name;
dea3101e
JB
1253}
1254
1255static void
1256lpfc_get_starget_port_name(struct scsi_target *starget)
1257{
1258 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
7f0b5b19 1259 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
f631b4be 1260 u64 port_name = 0;
dea3101e
JB
1261 struct lpfc_nodelist *ndlp = NULL;
1262
1263 spin_lock_irq(shost->host_lock);
1264 /* Search the mapped list for this target ID */
1265 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1266 if (starget->id == ndlp->nlp_sid) {
68ce1eb5 1267 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea3101e
JB
1268 break;
1269 }
1270 }
1271 spin_unlock_irq(shost->host_lock);
1272
f631b4be 1273 fc_starget_port_name(starget) = port_name;
dea3101e
JB
1274}
1275
1276static void
1277lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1278{
1279 /*
1280 * Return the driver's global value for device loss timeout plus
1281 * five seconds to allow the driver's nodev timer to run.
1282 */
1283 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1284}
1285
1286static void
1287lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1288{
1289 /*
1290 * The driver doesn't have a per-target timeout setting. Set
1291 * this value globally. lpfc_nodev_tmo should be greater then 0.
1292 */
1293 if (timeout)
1294 lpfc_nodev_tmo = timeout;
1295 else
1296 lpfc_nodev_tmo = 1;
1297 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1298}
1299
1300
1301#define lpfc_rport_show_function(field, format_string, sz, cast) \
1302static ssize_t \
1303lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1304{ \
1305 struct fc_rport *rport = transport_class_to_rport(cdev); \
1306 struct lpfc_rport_data *rdata = rport->hostdata; \
1307 return snprintf(buf, sz, format_string, \
1308 (rdata->target) ? cast rdata->target->field : 0); \
1309}
1310
1311#define lpfc_rport_rd_attr(field, format_string, sz) \
1312 lpfc_rport_show_function(field, format_string, sz, ) \
1313static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1314
1315
1316struct fc_function_template lpfc_transport_functions = {
1317 /* fixed attributes the driver supports */
1318 .show_host_node_name = 1,
1319 .show_host_port_name = 1,
1320 .show_host_supported_classes = 1,
1321 .show_host_supported_fc4s = 1,
1322 .show_host_symbolic_name = 1,
1323 .show_host_supported_speeds = 1,
1324 .show_host_maxframe_size = 1,
1325
1326 /* dynamic attributes the driver supports */
1327 .get_host_port_id = lpfc_get_host_port_id,
1328 .show_host_port_id = 1,
1329
1330 .get_host_port_type = lpfc_get_host_port_type,
1331 .show_host_port_type = 1,
1332
1333 .get_host_port_state = lpfc_get_host_port_state,
1334 .show_host_port_state = 1,
1335
1336 /* active_fc4s is shown but doesn't change (thus no get function) */
1337 .show_host_active_fc4s = 1,
1338
1339 .get_host_speed = lpfc_get_host_speed,
1340 .show_host_speed = 1,
1341
1342 .get_host_fabric_name = lpfc_get_host_fabric_name,
1343 .show_host_fabric_name = 1,
1344
1345 /*
1346 * The LPFC driver treats linkdown handling as target loss events
1347 * so there are no sysfs handlers for link_down_tmo.
1348 */
1349
1350 .get_fc_host_stats = lpfc_get_stats,
1351
1352 /* the LPFC driver doesn't support resetting stats yet */
1353
1354 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1355 .show_rport_maxframe_size = 1,
1356 .show_rport_supported_classes = 1,
1357
1358 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1359 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1360 .show_rport_dev_loss_tmo = 1,
1361
1362 .get_starget_port_id = lpfc_get_starget_port_id,
1363 .show_starget_port_id = 1,
1364
1365 .get_starget_node_name = lpfc_get_starget_node_name,
1366 .show_starget_node_name = 1,
1367
1368 .get_starget_port_name = lpfc_get_starget_port_name,
1369 .show_starget_port_name = 1,
91ca7b01
AV
1370
1371 .issue_fc_host_lip = lpfc_issue_lip,
dea3101e
JB
1372};
1373
1374void
1375lpfc_get_cfgparam(struct lpfc_hba *phba)
1376{
7bcbb752
JSEC
1377 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1378 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1379 lpfc_cr_count_init(phba, lpfc_cr_count);
1380 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1381 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1382 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1383 lpfc_ack0_init(phba, lpfc_ack0);
1384 lpfc_topology_init(phba, lpfc_topology);
1385 lpfc_scan_down_init(phba, lpfc_scan_down);
1386 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1387 lpfc_link_speed_init(phba, lpfc_link_speed);
1388 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1389 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1390 lpfc_max_luns_init(phba, lpfc_max_luns);
875fbdfe
JSEC
1391 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1392
1393 phba->cfg_poll = lpfc_poll;
dea3101e
JB
1394
1395 /*
1396 * The total number of segments is the configuration value plus 2
1397 * since the IOCB need a command and response bde.
1398 */
1399 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1400
1401 /*
1402 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1403 * used to create the sg_dma_buf_pool must be dynamically calculated
1404 */
1405 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1406 sizeof(struct fcp_rsp) +
1407 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1408
1409 switch (phba->pcidev->device) {
1410 case PCI_DEVICE_ID_LP101:
1411 case PCI_DEVICE_ID_BSMB:
1412 case PCI_DEVICE_ID_ZSMB:
1413 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1414 break;
1415 case PCI_DEVICE_ID_RFLY:
1416 case PCI_DEVICE_ID_PFLY:
1417 case PCI_DEVICE_ID_BMID:
1418 case PCI_DEVICE_ID_ZMID:
1419 case PCI_DEVICE_ID_TFLY:
1420 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1421 break;
1422 default:
1423 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1424 }
b28485ac
JW
1425
1426 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1427 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1428
dea3101e
JB
1429 return;
1430}