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