blob: 5625a8c2a8fde79eaf3620d0ef1857fe2511f5f1 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#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);
82 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
90 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
98 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
197 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
198 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
199 phba->fc_unmap_cnt);
200}
201
202
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700203static int
204lpfc_issue_lip(struct Scsi_Host *host)
dea31012005-04-17 16:05:31 -0500205{
dea31012005-04-17 16:05:31 -0500206 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0];
dea31012005-04-17 16:05:31 -0500207 LPFC_MBOXQ_t *pmboxq;
208 int mbxstatus = MBXERR_ERROR;
209
dea31012005-04-17 16:05:31 -0500210 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
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400226 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500227
228 if (mbxstatus == MBXERR_ERROR)
229 return -EIO;
230
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700231 return 0;
dea31012005-04-17 16:05:31 -0500232}
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);
238 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
246 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
247
dea31012005-04-17 16:05:31 -0500248 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);
259 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
260 struct completion online_compl;
261 int val=0, status=0;
262
263 if (sscanf(buf, "%d", &val) != 1)
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400264 return -EINVAL;
dea31012005-04-17 16:05:31 -0500265
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
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400278 return -EIO;
dea31012005-04-17 16:05:31 -0500279}
280
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500281static ssize_t
282lpfc_poll_show(struct class_device *cdev, char *buf)
283{
284 struct Scsi_Host *host = class_to_shost(cdev);
285 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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);
295 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
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}
dea31012005-04-17 16:05:31 -0500346
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);\
352 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
353 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400354 val = phba->cfg_##attr;\
355 return snprintf(buf, PAGE_SIZE, "%d\n",\
356 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500357}
358
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400359#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);\
364 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
365 int val = 0;\
366 val = phba->cfg_##attr;\
367 return snprintf(buf, PAGE_SIZE, "%#x\n",\
368 phba->cfg_##attr);\
369}
370
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400371#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;\
378 }\
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;\
385}
386
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) \
dea31012005-04-17 16:05:31 -0500403static 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);\
407 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400408 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400409 if (!isdigit(buf[0]))\
410 return -EINVAL;\
411 if (sscanf(buf, "%i", &val) != 1)\
412 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400413 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400414 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400415 else \
416 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500417}
418
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400419#define LPFC_ATTR(name, defval, minval, maxval, desc) \
420static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500421module_param(lpfc_##name, int, 0);\
422MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400423lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500424
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)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400430lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500431static 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)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400438lpfc_param_init(name, defval, minval, maxval)\
439lpfc_param_set(name, defval, minval, maxval)\
440lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500441static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
442 lpfc_##name##_show, lpfc_##name##_store)
443
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400444#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
dea31012005-04-17 16:05:31 -0500463static 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);
dea31012005-04-17 16:05:31 -0500481static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
482 lpfc_board_online_show, lpfc_board_online_store);
483
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500484static 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);
dea31012005-04-17 16:05:31 -0500493
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*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400513LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500514
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
522/*
523# Some disk devices have a "select ID" or "select Target" capability.
524# From a protocol standpoint "select ID" usually means select the
525# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
526# annex" which contains a table that maps a "select ID" (a number
527# between 0 and 7F) to an ALPA. By default, for compatibility with
528# older drivers, the lpfc driver scans this table from low ALPA to high
529# ALPA.
530#
531# Turning on the scan-down variable (on = 1, off = 0) will
532# cause the lpfc driver to use an inverted table, effectively
533# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
534#
535# (Note: This "select ID" functionality is a LOOP ONLY characteristic
536# and will not work across a fabric. Also this parameter will take
537# effect only in the case when ALPA map is not available.)
538*/
539LPFC_ATTR_R(scan_down, 1, 0, 1,
540 "Start scanning for devices from highest ALPA to lowest");
541
542/*
543# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
James.Smart@Emulex.Com09703d32005-10-28 20:29:21 -0400544# until the timer expires. Value range is [0,255]. Default value is 30.
dea31012005-04-17 16:05:31 -0500545# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
546*/
547LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
548 "Seconds driver will hold I/O waiting for a device to come back");
549
550/*
551# lpfc_topology: link topology for init link
552# 0x0 = attempt loop mode then point-to-point
553# 0x02 = attempt point-to-point mode only
554# 0x04 = attempt loop mode only
555# 0x06 = attempt point-to-point mode then loop
556# Set point-to-point mode if you want to run as an N_Port.
557# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
558# Default value is 0.
559*/
560LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
561
562/*
563# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
564# connection.
565# 0 = auto select (default)
566# 1 = 1 Gigabaud
567# 2 = 2 Gigabaud
568# 4 = 4 Gigabaud
569# Value range is [0,4]. Default value is 0.
570*/
571LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
572
573/*
574# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
575# Value range is [2,3]. Default value is 3.
576*/
577LPFC_ATTR_R(fcp_class, 3, 2, 3,
578 "Select Fibre Channel class of service for FCP sequences");
579
580/*
581# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
582# is [0,1]. Default value is 0.
583*/
584LPFC_ATTR_RW(use_adisc, 0, 0, 1,
585 "Use ADISC on rediscovery to authenticate FCP devices");
586
587/*
588# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
589# range is [0,1]. Default value is 0.
590*/
591LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
592
593/*
594# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
595# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
596# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
597# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
598# cr_delay is set to 0.
599*/
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500600LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an"
dea31012005-04-17 16:05:31 -0500601 "interrupt response is generated");
602
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500603LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an"
dea31012005-04-17 16:05:31 -0500604 "interrupt response is generated");
605
606/*
607# lpfc_fdmi_on: controls FDMI support.
608# 0 = no FDMI support
609# 1 = support FDMI without attribute of hostname
610# 2 = support FDMI with attribute of hostname
611# Value range [0,2]. Default value is 0.
612*/
613LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
614
615/*
616# Specifies the maximum number of ELS cmds we can have outstanding (for
617# discovery). Value range is [1,64]. Default value = 32.
618*/
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400619LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands"
dea31012005-04-17 16:05:31 -0500620 "during discovery");
621
622/*
623# lpfc_max_luns: maximum number of LUNs per target driver will support
624# Value range is [1,32768]. Default value is 256.
625# NOTE: The SCSI layer will scan each target for this many luns
626*/
627LPFC_ATTR_R(max_luns, 256, 1, 32768,
628 "Maximum number of LUNs per target driver will support");
629
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500630/*
631# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
632# Value range is [1,255], default value is 10.
633*/
634LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
635 "Milliseconds driver will wait between polling FCP ring");
636
dea31012005-04-17 16:05:31 -0500637struct class_device_attribute *lpfc_host_attrs[] = {
638 &class_device_attr_info,
639 &class_device_attr_serialnum,
640 &class_device_attr_modeldesc,
641 &class_device_attr_modelname,
642 &class_device_attr_programtype,
643 &class_device_attr_portnum,
644 &class_device_attr_fwrev,
645 &class_device_attr_hdw,
646 &class_device_attr_option_rom_version,
647 &class_device_attr_state,
648 &class_device_attr_num_discovered_ports,
649 &class_device_attr_lpfc_drvr_version,
650 &class_device_attr_lpfc_log_verbose,
651 &class_device_attr_lpfc_lun_queue_depth,
652 &class_device_attr_lpfc_nodev_tmo,
653 &class_device_attr_lpfc_fcp_class,
654 &class_device_attr_lpfc_use_adisc,
655 &class_device_attr_lpfc_ack0,
656 &class_device_attr_lpfc_topology,
657 &class_device_attr_lpfc_scan_down,
658 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500659 &class_device_attr_lpfc_cr_delay,
660 &class_device_attr_lpfc_cr_count,
dea31012005-04-17 16:05:31 -0500661 &class_device_attr_lpfc_fdmi_on,
662 &class_device_attr_lpfc_max_luns,
663 &class_device_attr_nport_evt_cnt,
664 &class_device_attr_management_version,
dea31012005-04-17 16:05:31 -0500665 &class_device_attr_board_online,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500666 &class_device_attr_lpfc_poll,
667 &class_device_attr_lpfc_poll_tmo,
dea31012005-04-17 16:05:31 -0500668 NULL,
669};
670
671static ssize_t
672sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
673{
674 size_t buf_off;
675 struct Scsi_Host *host = class_to_shost(container_of(kobj,
676 struct class_device, kobj));
677 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
678
679 if ((off + count) > FF_REG_AREA_SIZE)
680 return -ERANGE;
681
682 if (count == 0) return 0;
683
684 if (off % 4 || count % 4 || (unsigned long)buf % 4)
685 return -EINVAL;
686
687 spin_lock_irq(phba->host->host_lock);
688
689 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
690 spin_unlock_irq(phba->host->host_lock);
691 return -EPERM;
692 }
693
694 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
695 writel(*((uint32_t *)(buf + buf_off)),
696 phba->ctrl_regs_memmap_p + off + buf_off);
697
698 spin_unlock_irq(phba->host->host_lock);
699
700 return count;
701}
702
703static ssize_t
704sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
705{
706 size_t buf_off;
707 uint32_t * tmp_ptr;
708 struct Scsi_Host *host = class_to_shost(container_of(kobj,
709 struct class_device, kobj));
710 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
711
712 if (off > FF_REG_AREA_SIZE)
713 return -ERANGE;
714
715 if ((off + count) > FF_REG_AREA_SIZE)
716 count = FF_REG_AREA_SIZE - off;
717
718 if (count == 0) return 0;
719
720 if (off % 4 || count % 4 || (unsigned long)buf % 4)
721 return -EINVAL;
722
723 spin_lock_irq(phba->host->host_lock);
724
725 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
726 tmp_ptr = (uint32_t *)(buf + buf_off);
727 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
728 }
729
730 spin_unlock_irq(phba->host->host_lock);
731
732 return count;
733}
734
735static struct bin_attribute sysfs_ctlreg_attr = {
736 .attr = {
737 .name = "ctlreg",
738 .mode = S_IRUSR | S_IWUSR,
739 .owner = THIS_MODULE,
740 },
741 .size = 256,
742 .read = sysfs_ctlreg_read,
743 .write = sysfs_ctlreg_write,
744};
745
746
747static void
748sysfs_mbox_idle (struct lpfc_hba * phba)
749{
750 phba->sysfs_mbox.state = SMBOX_IDLE;
751 phba->sysfs_mbox.offset = 0;
752
753 if (phba->sysfs_mbox.mbox) {
754 mempool_free(phba->sysfs_mbox.mbox,
755 phba->mbox_mem_pool);
756 phba->sysfs_mbox.mbox = NULL;
757 }
758}
759
760static ssize_t
761sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
762{
763 struct Scsi_Host * host =
764 class_to_shost(container_of(kobj, struct class_device, kobj));
765 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0];
766 struct lpfcMboxq * mbox = NULL;
767
768 if ((count + off) > MAILBOX_CMD_SIZE)
769 return -ERANGE;
770
771 if (off % 4 || count % 4 || (unsigned long)buf % 4)
772 return -EINVAL;
773
774 if (count == 0)
775 return 0;
776
777 if (off == 0) {
778 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
779 if (!mbox)
780 return -ENOMEM;
781
782 }
783
784 spin_lock_irq(host->host_lock);
785
786 if (off == 0) {
787 if (phba->sysfs_mbox.mbox)
788 mempool_free(mbox, phba->mbox_mem_pool);
789 else
790 phba->sysfs_mbox.mbox = mbox;
791 phba->sysfs_mbox.state = SMBOX_WRITING;
792 } else {
793 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
794 phba->sysfs_mbox.offset != off ||
795 phba->sysfs_mbox.mbox == NULL ) {
796 sysfs_mbox_idle(phba);
797 spin_unlock_irq(host->host_lock);
798 return -EINVAL;
799 }
800 }
801
802 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
803 buf, count);
804
805 phba->sysfs_mbox.offset = off + count;
806
807 spin_unlock_irq(host->host_lock);
808
809 return count;
810}
811
812static ssize_t
813sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
814{
815 struct Scsi_Host *host =
816 class_to_shost(container_of(kobj, struct class_device,
817 kobj));
818 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
819 int rc;
820
821 if (off > sizeof(MAILBOX_t))
822 return -ERANGE;
823
824 if ((count + off) > sizeof(MAILBOX_t))
825 count = sizeof(MAILBOX_t) - off;
826
827 if (off % 4 || count % 4 || (unsigned long)buf % 4)
828 return -EINVAL;
829
830 if (off && count == 0)
831 return 0;
832
833 spin_lock_irq(phba->host->host_lock);
834
835 if (off == 0 &&
836 phba->sysfs_mbox.state == SMBOX_WRITING &&
837 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
838
839 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
840 /* Offline only */
841 case MBX_WRITE_NV:
842 case MBX_INIT_LINK:
843 case MBX_DOWN_LINK:
844 case MBX_CONFIG_LINK:
845 case MBX_CONFIG_RING:
846 case MBX_RESET_RING:
847 case MBX_UNREG_LOGIN:
848 case MBX_CLEAR_LA:
849 case MBX_DUMP_CONTEXT:
850 case MBX_RUN_DIAGS:
851 case MBX_RESTART:
852 case MBX_FLASH_WR_ULA:
853 case MBX_SET_MASK:
854 case MBX_SET_SLIM:
855 case MBX_SET_DEBUG:
856 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
857 printk(KERN_WARNING "mbox_read:Command 0x%x "
858 "is illegal in on-line state\n",
859 phba->sysfs_mbox.mbox->mb.mbxCommand);
860 sysfs_mbox_idle(phba);
861 spin_unlock_irq(phba->host->host_lock);
862 return -EPERM;
863 }
864 case MBX_LOAD_SM:
865 case MBX_READ_NV:
866 case MBX_READ_CONFIG:
867 case MBX_READ_RCONFIG:
868 case MBX_READ_STATUS:
869 case MBX_READ_XRI:
870 case MBX_READ_REV:
871 case MBX_READ_LNK_STAT:
872 case MBX_DUMP_MEMORY:
873 case MBX_DOWN_LOAD:
874 case MBX_UPDATE_CFG:
875 case MBX_LOAD_AREA:
876 case MBX_LOAD_EXP_ROM:
877 break;
878 case MBX_READ_SPARM64:
879 case MBX_READ_LA:
880 case MBX_READ_LA64:
881 case MBX_REG_LOGIN:
882 case MBX_REG_LOGIN64:
883 case MBX_CONFIG_PORT:
884 case MBX_RUN_BIU_DIAG:
885 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
886 phba->sysfs_mbox.mbox->mb.mbxCommand);
887 sysfs_mbox_idle(phba);
888 spin_unlock_irq(phba->host->host_lock);
889 return -EPERM;
890 default:
891 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
892 phba->sysfs_mbox.mbox->mb.mbxCommand);
893 sysfs_mbox_idle(phba);
894 spin_unlock_irq(phba->host->host_lock);
895 return -EPERM;
896 }
897
898 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
899 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
900
901 spin_unlock_irq(phba->host->host_lock);
902 rc = lpfc_sli_issue_mbox (phba,
903 phba->sysfs_mbox.mbox,
904 MBX_POLL);
905 spin_lock_irq(phba->host->host_lock);
906
907 } else {
908 spin_unlock_irq(phba->host->host_lock);
909 rc = lpfc_sli_issue_mbox_wait (phba,
910 phba->sysfs_mbox.mbox,
911 phba->fc_ratov * 2);
912 spin_lock_irq(phba->host->host_lock);
913 }
914
915 if (rc != MBX_SUCCESS) {
916 sysfs_mbox_idle(phba);
917 spin_unlock_irq(host->host_lock);
918 return -ENODEV;
919 }
920 phba->sysfs_mbox.state = SMBOX_READING;
921 }
922 else if (phba->sysfs_mbox.offset != off ||
923 phba->sysfs_mbox.state != SMBOX_READING) {
924 printk(KERN_WARNING "mbox_read: Bad State\n");
925 sysfs_mbox_idle(phba);
926 spin_unlock_irq(host->host_lock);
927 return -EINVAL;
928 }
929
930 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
931
932 phba->sysfs_mbox.offset = off + count;
933
934 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
935 sysfs_mbox_idle(phba);
936
937 spin_unlock_irq(phba->host->host_lock);
938
939 return count;
940}
941
942static struct bin_attribute sysfs_mbox_attr = {
943 .attr = {
944 .name = "mbox",
945 .mode = S_IRUSR | S_IWUSR,
946 .owner = THIS_MODULE,
947 },
948 .size = sizeof(MAILBOX_t),
949 .read = sysfs_mbox_read,
950 .write = sysfs_mbox_write,
951};
952
953int
954lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
955{
956 struct Scsi_Host *host = phba->host;
957 int error;
958
959 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
960 &sysfs_ctlreg_attr);
961 if (error)
962 goto out;
963
964 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
965 &sysfs_mbox_attr);
966 if (error)
967 goto out_remove_ctlreg_attr;
968
969 return 0;
970out_remove_ctlreg_attr:
971 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
972out:
973 return error;
974}
975
976void
977lpfc_free_sysfs_attr(struct lpfc_hba *phba)
978{
979 struct Scsi_Host *host = phba->host;
980
981 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
982 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
983}
984
985
986/*
987 * Dynamic FC Host Attributes Support
988 */
989
990static void
991lpfc_get_host_port_id(struct Scsi_Host *shost)
992{
993 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
994 /* note: fc_myDID already in cpu endianness */
995 fc_host_port_id(shost) = phba->fc_myDID;
996}
997
998static void
999lpfc_get_host_port_type(struct Scsi_Host *shost)
1000{
1001 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
1002
1003 spin_lock_irq(shost->host_lock);
1004
1005 if (phba->hba_state == LPFC_HBA_READY) {
1006 if (phba->fc_topology == TOPOLOGY_LOOP) {
1007 if (phba->fc_flag & FC_PUBLIC_LOOP)
1008 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1009 else
1010 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1011 } else {
1012 if (phba->fc_flag & FC_FABRIC)
1013 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1014 else
1015 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1016 }
1017 } else
1018 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1019
1020 spin_unlock_irq(shost->host_lock);
1021}
1022
1023static void
1024lpfc_get_host_port_state(struct Scsi_Host *shost)
1025{
1026 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
1027
1028 spin_lock_irq(shost->host_lock);
1029
1030 if (phba->fc_flag & FC_OFFLINE_MODE)
1031 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1032 else {
1033 switch (phba->hba_state) {
1034 case LPFC_INIT_START:
1035 case LPFC_INIT_MBX_CMDS:
1036 case LPFC_LINK_DOWN:
1037 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1038 break;
1039 case LPFC_LINK_UP:
1040 case LPFC_LOCAL_CFG_LINK:
1041 case LPFC_FLOGI:
1042 case LPFC_FABRIC_CFG_LINK:
1043 case LPFC_NS_REG:
1044 case LPFC_NS_QRY:
1045 case LPFC_BUILD_DISC_LIST:
1046 case LPFC_DISC_AUTH:
1047 case LPFC_CLEAR_LA:
1048 case LPFC_HBA_READY:
1049 /* Links up, beyond this port_type reports state */
1050 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1051 break;
1052 case LPFC_HBA_ERROR:
1053 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1054 break;
1055 default:
1056 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1057 break;
1058 }
1059 }
1060
1061 spin_unlock_irq(shost->host_lock);
1062}
1063
1064static void
1065lpfc_get_host_speed(struct Scsi_Host *shost)
1066{
1067 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
1068
1069 spin_lock_irq(shost->host_lock);
1070
1071 if (phba->hba_state == LPFC_HBA_READY) {
1072 switch(phba->fc_linkspeed) {
1073 case LA_1GHZ_LINK:
1074 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1075 break;
1076 case LA_2GHZ_LINK:
1077 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1078 break;
1079 case LA_4GHZ_LINK:
1080 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1081 break;
1082 default:
1083 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1084 break;
1085 }
1086 }
1087
1088 spin_unlock_irq(shost->host_lock);
1089}
1090
1091static void
1092lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1093{
1094 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001095 u64 node_name;
dea31012005-04-17 16:05:31 -05001096
1097 spin_lock_irq(shost->host_lock);
1098
1099 if ((phba->fc_flag & FC_FABRIC) ||
1100 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1101 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001102 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001103 else
1104 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001105 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001106
1107 spin_unlock_irq(shost->host_lock);
1108
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001109 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001110}
1111
1112
1113static struct fc_host_statistics *
1114lpfc_get_stats(struct Scsi_Host *shost)
1115{
1116 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
1117 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001118 struct fc_host_statistics *hs = &phba->link_stats;
dea31012005-04-17 16:05:31 -05001119 LPFC_MBOXQ_t *pmboxq;
1120 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001121 int rc = 0;
dea31012005-04-17 16:05:31 -05001122
1123 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1124 if (!pmboxq)
1125 return NULL;
1126 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1127
1128 pmb = &pmboxq->mb;
1129 pmb->mbxCommand = MBX_READ_STATUS;
1130 pmb->mbxOwner = OWN_HOST;
1131 pmboxq->context1 = NULL;
1132
1133 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001134 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001135 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001136 else
dea31012005-04-17 16:05:31 -05001137 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1138
1139 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001140 if (rc == MBX_TIMEOUT)
1141 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1142 else
1143 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001144 return NULL;
1145 }
1146
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001147 memset(hs, 0, sizeof (struct fc_host_statistics));
1148
dea31012005-04-17 16:05:31 -05001149 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1150 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1151 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1152 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1153
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001154 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001155 pmb->mbxCommand = MBX_READ_LNK_STAT;
1156 pmb->mbxOwner = OWN_HOST;
1157 pmboxq->context1 = NULL;
1158
1159 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001160 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001161 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001162 else
dea31012005-04-17 16:05:31 -05001163 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1164
1165 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001166 if (rc == MBX_TIMEOUT)
1167 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1168 else
1169 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001170 return NULL;
1171 }
1172
1173 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1174 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1175 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1176 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1177 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1178 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1179 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1180
1181 if (phba->fc_topology == TOPOLOGY_LOOP) {
1182 hs->lip_count = (phba->fc_eventTag >> 1);
1183 hs->nos_count = -1;
1184 } else {
1185 hs->lip_count = -1;
1186 hs->nos_count = (phba->fc_eventTag >> 1);
1187 }
1188
1189 hs->dumped_frames = -1;
1190
1191/* FIX ME */
1192 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1193
1194 return hs;
1195}
1196
1197
1198/*
1199 * The LPFC driver treats linkdown handling as target loss events so there
1200 * are no sysfs handlers for link_down_tmo.
1201 */
1202static void
1203lpfc_get_starget_port_id(struct scsi_target *starget)
1204{
1205 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1206 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
1207 uint32_t did = -1;
1208 struct lpfc_nodelist *ndlp = NULL;
1209
1210 spin_lock_irq(shost->host_lock);
1211 /* Search the mapped list for this target ID */
1212 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1213 if (starget->id == ndlp->nlp_sid) {
1214 did = ndlp->nlp_DID;
1215 break;
1216 }
1217 }
1218 spin_unlock_irq(shost->host_lock);
1219
1220 fc_starget_port_id(starget) = did;
1221}
1222
1223static void
1224lpfc_get_starget_node_name(struct scsi_target *starget)
1225{
1226 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1227 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001228 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001229 struct lpfc_nodelist *ndlp = NULL;
1230
1231 spin_lock_irq(shost->host_lock);
1232 /* Search the mapped list for this target ID */
1233 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1234 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001235 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001236 break;
1237 }
1238 }
1239 spin_unlock_irq(shost->host_lock);
1240
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001241 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001242}
1243
1244static void
1245lpfc_get_starget_port_name(struct scsi_target *starget)
1246{
1247 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1248 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001249 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001250 struct lpfc_nodelist *ndlp = NULL;
1251
1252 spin_lock_irq(shost->host_lock);
1253 /* Search the mapped list for this target ID */
1254 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1255 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001256 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001257 break;
1258 }
1259 }
1260 spin_unlock_irq(shost->host_lock);
1261
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001262 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001263}
1264
1265static void
1266lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1267{
1268 /*
1269 * Return the driver's global value for device loss timeout plus
1270 * five seconds to allow the driver's nodev timer to run.
1271 */
1272 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1273}
1274
1275static void
1276lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1277{
1278 /*
1279 * The driver doesn't have a per-target timeout setting. Set
1280 * this value globally. lpfc_nodev_tmo should be greater then 0.
1281 */
1282 if (timeout)
1283 lpfc_nodev_tmo = timeout;
1284 else
1285 lpfc_nodev_tmo = 1;
1286 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1287}
1288
1289
1290#define lpfc_rport_show_function(field, format_string, sz, cast) \
1291static ssize_t \
1292lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1293{ \
1294 struct fc_rport *rport = transport_class_to_rport(cdev); \
1295 struct lpfc_rport_data *rdata = rport->hostdata; \
1296 return snprintf(buf, sz, format_string, \
1297 (rdata->target) ? cast rdata->target->field : 0); \
1298}
1299
1300#define lpfc_rport_rd_attr(field, format_string, sz) \
1301 lpfc_rport_show_function(field, format_string, sz, ) \
1302static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1303
1304
1305struct fc_function_template lpfc_transport_functions = {
1306 /* fixed attributes the driver supports */
1307 .show_host_node_name = 1,
1308 .show_host_port_name = 1,
1309 .show_host_supported_classes = 1,
1310 .show_host_supported_fc4s = 1,
1311 .show_host_symbolic_name = 1,
1312 .show_host_supported_speeds = 1,
1313 .show_host_maxframe_size = 1,
1314
1315 /* dynamic attributes the driver supports */
1316 .get_host_port_id = lpfc_get_host_port_id,
1317 .show_host_port_id = 1,
1318
1319 .get_host_port_type = lpfc_get_host_port_type,
1320 .show_host_port_type = 1,
1321
1322 .get_host_port_state = lpfc_get_host_port_state,
1323 .show_host_port_state = 1,
1324
1325 /* active_fc4s is shown but doesn't change (thus no get function) */
1326 .show_host_active_fc4s = 1,
1327
1328 .get_host_speed = lpfc_get_host_speed,
1329 .show_host_speed = 1,
1330
1331 .get_host_fabric_name = lpfc_get_host_fabric_name,
1332 .show_host_fabric_name = 1,
1333
1334 /*
1335 * The LPFC driver treats linkdown handling as target loss events
1336 * so there are no sysfs handlers for link_down_tmo.
1337 */
1338
1339 .get_fc_host_stats = lpfc_get_stats,
1340
1341 /* the LPFC driver doesn't support resetting stats yet */
1342
1343 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1344 .show_rport_maxframe_size = 1,
1345 .show_rport_supported_classes = 1,
1346
1347 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1348 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1349 .show_rport_dev_loss_tmo = 1,
1350
1351 .get_starget_port_id = lpfc_get_starget_port_id,
1352 .show_starget_port_id = 1,
1353
1354 .get_starget_node_name = lpfc_get_starget_node_name,
1355 .show_starget_node_name = 1,
1356
1357 .get_starget_port_name = lpfc_get_starget_port_name,
1358 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001359
1360 .issue_fc_host_lip = lpfc_issue_lip,
dea31012005-04-17 16:05:31 -05001361};
1362
1363void
1364lpfc_get_cfgparam(struct lpfc_hba *phba)
1365{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001366 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1367 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1368 lpfc_cr_count_init(phba, lpfc_cr_count);
1369 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1370 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1371 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1372 lpfc_ack0_init(phba, lpfc_ack0);
1373 lpfc_topology_init(phba, lpfc_topology);
1374 lpfc_scan_down_init(phba, lpfc_scan_down);
1375 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1376 lpfc_link_speed_init(phba, lpfc_link_speed);
1377 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1378 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1379 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001380 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1381
1382 phba->cfg_poll = lpfc_poll;
dea31012005-04-17 16:05:31 -05001383
1384 /*
1385 * The total number of segments is the configuration value plus 2
1386 * since the IOCB need a command and response bde.
1387 */
1388 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1389
1390 /*
1391 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1392 * used to create the sg_dma_buf_pool must be dynamically calculated
1393 */
1394 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1395 sizeof(struct fcp_rsp) +
1396 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1397
1398 switch (phba->pcidev->device) {
1399 case PCI_DEVICE_ID_LP101:
1400 case PCI_DEVICE_ID_BSMB:
1401 case PCI_DEVICE_ID_ZSMB:
1402 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1403 break;
1404 case PCI_DEVICE_ID_RFLY:
1405 case PCI_DEVICE_ID_PFLY:
1406 case PCI_DEVICE_ID_BMID:
1407 case PCI_DEVICE_ID_ZMID:
1408 case PCI_DEVICE_ID_TFLY:
1409 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1410 break;
1411 default:
1412 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1413 }
1414 return;
1415}