blob: ab49379b6abec8c8d22360cb2f6b082b6e9edebf [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. *
Jamie Wellnitz41415862006-02-28 19:25:27 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050082 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050083 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050090 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050091 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050098 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050099 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500107 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500115 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500123 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500134 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500143 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);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500150 int len = 0;
151 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500152 case LPFC_STATE_UNKNOWN:
153 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500154 case LPFC_INIT_START:
155 case LPFC_INIT_MBX_CMDS:
156 case LPFC_LINK_DOWN:
157 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
158 break;
159 case LPFC_LINK_UP:
160 case LPFC_LOCAL_CFG_LINK:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
162 break;
163 case LPFC_FLOGI:
164 case LPFC_FABRIC_CFG_LINK:
165 case LPFC_NS_REG:
166 case LPFC_NS_QRY:
167 case LPFC_BUILD_DISC_LIST:
168 case LPFC_DISC_AUTH:
169 case LPFC_CLEAR_LA:
170 len += snprintf(buf + len, PAGE_SIZE-len,
171 "Link Up - Discovery\n");
172 break;
173 case LPFC_HBA_READY:
174 len += snprintf(buf + len, PAGE_SIZE-len,
175 "Link Up - Ready:\n");
176 if (phba->fc_topology == TOPOLOGY_LOOP) {
177 if (phba->fc_flag & FC_PUBLIC_LOOP)
178 len += snprintf(buf + len, PAGE_SIZE-len,
179 " Public Loop\n");
180 else
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Private Loop\n");
183 } else {
184 if (phba->fc_flag & FC_FABRIC)
185 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Fabric\n");
187 else
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Point-2-Point\n");
190 }
191 }
192 return len;
193}
194
195static ssize_t
196lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
197{
198 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500199 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
201 phba->fc_unmap_cnt);
202}
203
204
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700205static int
206lpfc_issue_lip(struct Scsi_Host *host)
dea31012005-04-17 16:05:31 -0500207{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500208 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea31012005-04-17 16:05:31 -0500209 LPFC_MBOXQ_t *pmboxq;
210 int mbxstatus = MBXERR_ERROR;
211
dea31012005-04-17 16:05:31 -0500212 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
213 (phba->hba_state != LPFC_HBA_READY))
214 return -EPERM;
215
216 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
217
218 if (!pmboxq)
219 return -ENOMEM;
220
221 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
222 lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed);
223 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
224
225 if (mbxstatus == MBX_TIMEOUT)
226 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
227 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400228 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500229
230 if (mbxstatus == MBXERR_ERROR)
231 return -EIO;
232
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700233 return 0;
dea31012005-04-17 16:05:31 -0500234}
235
236static ssize_t
237lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
238{
239 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500240 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500241 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
242}
243
244static ssize_t
245lpfc_board_online_show(struct class_device *cdev, char *buf)
246{
247 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500248 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500249
dea31012005-04-17 16:05:31 -0500250 if (phba->fc_flag & FC_OFFLINE_MODE)
251 return snprintf(buf, PAGE_SIZE, "0\n");
252 else
253 return snprintf(buf, PAGE_SIZE, "1\n");
254}
255
256static ssize_t
257lpfc_board_online_store(struct class_device *cdev, const char *buf,
258 size_t count)
259{
260 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500261 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500262 struct completion online_compl;
263 int val=0, status=0;
264
265 if (sscanf(buf, "%d", &val) != 1)
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400266 return -EINVAL;
dea31012005-04-17 16:05:31 -0500267
268 init_completion(&online_compl);
269
270 if (val)
271 lpfc_workq_post_event(phba, &status, &online_compl,
272 LPFC_EVT_ONLINE);
273 else
274 lpfc_workq_post_event(phba, &status, &online_compl,
275 LPFC_EVT_OFFLINE);
276 wait_for_completion(&online_compl);
277 if (!status)
278 return strlen(buf);
279 else
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400280 return -EIO;
dea31012005-04-17 16:05:31 -0500281}
282
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500283static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500284lpfc_board_mode_show(struct class_device *cdev, char *buf)
285{
286 struct Scsi_Host *host = class_to_shost(cdev);
287 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
288 char * state;
289
290 if (phba->hba_state == LPFC_HBA_ERROR)
291 state = "error";
292 else if (phba->hba_state == LPFC_WARM_START)
293 state = "warm start";
294 else if (phba->hba_state == LPFC_INIT_START)
295 state = "offline";
296 else
297 state = "online";
298
299 return snprintf(buf, PAGE_SIZE, "%s\n", state);
300}
301
302static ssize_t
303lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
304{
305 struct Scsi_Host *host = class_to_shost(cdev);
306 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
307 struct completion online_compl;
308 int status=0;
309
310 init_completion(&online_compl);
311
312 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
313 lpfc_workq_post_event(phba, &status, &online_compl,
314 LPFC_EVT_ONLINE);
315 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
316 lpfc_workq_post_event(phba, &status, &online_compl,
317 LPFC_EVT_OFFLINE);
318 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
319 lpfc_workq_post_event(phba, &status, &online_compl,
320 LPFC_EVT_WARM_START);
321 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
322 lpfc_workq_post_event(phba, &status, &online_compl,
323 LPFC_EVT_KILL);
324 else
325 return -EINVAL;
326
327 wait_for_completion(&online_compl);
328
329 if (!status)
330 return strlen(buf);
331 else
332 return -EIO;
333}
334
335static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500336lpfc_poll_show(struct class_device *cdev, char *buf)
337{
338 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500339 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500340
341 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
342}
343
344static ssize_t
345lpfc_poll_store(struct class_device *cdev, const char *buf,
346 size_t count)
347{
348 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500349 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500350 uint32_t creg_val;
351 uint32_t old_val;
352 int val=0;
353
354 if (!isdigit(buf[0]))
355 return -EINVAL;
356
357 if (sscanf(buf, "%i", &val) != 1)
358 return -EINVAL;
359
360 if ((val & 0x3) != val)
361 return -EINVAL;
362
363 spin_lock_irq(phba->host->host_lock);
364
365 old_val = phba->cfg_poll;
366
367 if (val & ENABLE_FCP_RING_POLLING) {
368 if ((val & DISABLE_FCP_RING_INT) &&
369 !(old_val & DISABLE_FCP_RING_INT)) {
370 creg_val = readl(phba->HCregaddr);
371 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
372 writel(creg_val, phba->HCregaddr);
373 readl(phba->HCregaddr); /* flush */
374
375 lpfc_poll_start_timer(phba);
376 }
377 } else if (val != 0x0) {
378 spin_unlock_irq(phba->host->host_lock);
379 return -EINVAL;
380 }
381
382 if (!(val & DISABLE_FCP_RING_INT) &&
383 (old_val & DISABLE_FCP_RING_INT))
384 {
385 spin_unlock_irq(phba->host->host_lock);
386 del_timer(&phba->fcp_poll_timer);
387 spin_lock_irq(phba->host->host_lock);
388 creg_val = readl(phba->HCregaddr);
389 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
390 writel(creg_val, phba->HCregaddr);
391 readl(phba->HCregaddr); /* flush */
392 }
393
394 phba->cfg_poll = val;
395
396 spin_unlock_irq(phba->host->host_lock);
397
398 return strlen(buf);
399}
dea31012005-04-17 16:05:31 -0500400
401#define lpfc_param_show(attr) \
402static ssize_t \
403lpfc_##attr##_show(struct class_device *cdev, char *buf) \
404{ \
405 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500406 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea31012005-04-17 16:05:31 -0500407 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400408 val = phba->cfg_##attr;\
409 return snprintf(buf, PAGE_SIZE, "%d\n",\
410 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500411}
412
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400413#define lpfc_param_hex_show(attr) \
414static ssize_t \
415lpfc_##attr##_show(struct class_device *cdev, char *buf) \
416{ \
417 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500418 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400419 int val = 0;\
420 val = phba->cfg_##attr;\
421 return snprintf(buf, PAGE_SIZE, "%#x\n",\
422 phba->cfg_##attr);\
423}
424
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400425#define lpfc_param_init(attr, default, minval, maxval) \
426static int \
427lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
428{ \
429 if (val >= minval && val <= maxval) {\
430 phba->cfg_##attr = val;\
431 return 0;\
432 }\
433 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
434 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
435 "allowed range is ["#minval", "#maxval"]\n", \
436 phba->brd_no, val); \
437 phba->cfg_##attr = default;\
438 return -EINVAL;\
439}
440
441#define lpfc_param_set(attr, default, minval, maxval) \
442static int \
443lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
444{ \
445 if (val >= minval && val <= maxval) {\
446 phba->cfg_##attr = val;\
447 return 0;\
448 }\
449 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
450 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
451 "allowed range is ["#minval", "#maxval"]\n", \
452 phba->brd_no, val); \
453 return -EINVAL;\
454}
455
456#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500457static ssize_t \
458lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
459{ \
460 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500461 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400462 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400463 if (!isdigit(buf[0]))\
464 return -EINVAL;\
465 if (sscanf(buf, "%i", &val) != 1)\
466 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400467 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400468 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400469 else \
470 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500471}
472
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400473#define LPFC_ATTR(name, defval, minval, maxval, desc) \
474static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500475module_param(lpfc_##name, int, 0);\
476MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400477lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500478
479#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
480static int lpfc_##name = defval;\
481module_param(lpfc_##name, int, 0);\
482MODULE_PARM_DESC(lpfc_##name, desc);\
483lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400484lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500485static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
486
487#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
488static int lpfc_##name = defval;\
489module_param(lpfc_##name, int, 0);\
490MODULE_PARM_DESC(lpfc_##name, desc);\
491lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400492lpfc_param_init(name, defval, minval, maxval)\
493lpfc_param_set(name, defval, minval, maxval)\
494lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500495static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
496 lpfc_##name##_show, lpfc_##name##_store)
497
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400498#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
499static int lpfc_##name = defval;\
500module_param(lpfc_##name, int, 0);\
501MODULE_PARM_DESC(lpfc_##name, desc);\
502lpfc_param_hex_show(name)\
503lpfc_param_init(name, defval, minval, maxval)\
504static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
505
506#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
507static int lpfc_##name = defval;\
508module_param(lpfc_##name, int, 0);\
509MODULE_PARM_DESC(lpfc_##name, desc);\
510lpfc_param_hex_show(name)\
511lpfc_param_init(name, defval, minval, maxval)\
512lpfc_param_set(name, defval, minval, maxval)\
513lpfc_param_store(name)\
514static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
515 lpfc_##name##_show, lpfc_##name##_store)
516
dea31012005-04-17 16:05:31 -0500517static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
518static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
519static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
520static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
521static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
522static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
523static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
524static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
525static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
526static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
527 lpfc_option_rom_version_show, NULL);
528static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
529 lpfc_num_discovered_ports_show, NULL);
530static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
531static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
532 NULL);
533static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
534 NULL);
dea31012005-04-17 16:05:31 -0500535static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
536 lpfc_board_online_show, lpfc_board_online_store);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500537static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
538 lpfc_board_mode_show, lpfc_board_mode_store);
dea31012005-04-17 16:05:31 -0500539
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500540static int lpfc_poll = 0;
541module_param(lpfc_poll, int, 0);
542MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
543 " 0 - none,"
544 " 1 - poll with interrupts enabled"
545 " 3 - poll and disable FCP ring interrupts");
546
547static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
548 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500549
550/*
551# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
552# deluged with LOTS of information.
553# You can set a bit mask to record specific types of verbose messages:
554#
555# LOG_ELS 0x1 ELS events
556# LOG_DISCOVERY 0x2 Link discovery events
557# LOG_MBOX 0x4 Mailbox events
558# LOG_INIT 0x8 Initialization events
559# LOG_LINK_EVENT 0x10 Link events
560# LOG_IP 0x20 IP traffic history
561# LOG_FCP 0x40 FCP traffic history
562# LOG_NODE 0x80 Node table events
563# LOG_MISC 0x400 Miscellaneous events
564# LOG_SLI 0x800 SLI events
565# LOG_CHK_COND 0x1000 FCP Check condition flag
566# LOG_LIBDFC 0x2000 LIBDFC events
567# LOG_ALL_MSG 0xffff LOG all messages
568*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400569LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500570
571/*
572# lun_queue_depth: This parameter is used to limit the number of outstanding
573# commands per FCP LUN. Value range is [1,128]. Default value is 30.
574*/
575LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
576 "Max number of FCP commands we can queue to a specific LUN");
577
578/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500579# hba_queue_depth: This parameter is used to limit the number of outstanding
580# commands per lpfc HBA. Value range is [32,8192]. If this parameter
581# value is greater than the maximum number of exchanges supported by the HBA,
582# then maximum number of exchanges supported by the HBA is used to determine
583# the hba_queue_depth.
584*/
585LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
586 "Max number of FCP commands we can queue to a lpfc HBA");
587
588/*
dea31012005-04-17 16:05:31 -0500589# Some disk devices have a "select ID" or "select Target" capability.
590# From a protocol standpoint "select ID" usually means select the
591# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
592# annex" which contains a table that maps a "select ID" (a number
593# between 0 and 7F) to an ALPA. By default, for compatibility with
594# older drivers, the lpfc driver scans this table from low ALPA to high
595# ALPA.
596#
597# Turning on the scan-down variable (on = 1, off = 0) will
598# cause the lpfc driver to use an inverted table, effectively
599# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
600#
601# (Note: This "select ID" functionality is a LOOP ONLY characteristic
602# and will not work across a fabric. Also this parameter will take
603# effect only in the case when ALPA map is not available.)
604*/
605LPFC_ATTR_R(scan_down, 1, 0, 1,
606 "Start scanning for devices from highest ALPA to lowest");
607
608/*
609# 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 -0400610# until the timer expires. Value range is [0,255]. Default value is 30.
dea31012005-04-17 16:05:31 -0500611# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
612*/
613LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
614 "Seconds driver will hold I/O waiting for a device to come back");
615
616/*
617# lpfc_topology: link topology for init link
618# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500619# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500620# 0x02 = attempt point-to-point mode only
621# 0x04 = attempt loop mode only
622# 0x06 = attempt point-to-point mode then loop
623# Set point-to-point mode if you want to run as an N_Port.
624# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
625# Default value is 0.
626*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500627LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500628
629/*
630# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
631# connection.
632# 0 = auto select (default)
633# 1 = 1 Gigabaud
634# 2 = 2 Gigabaud
635# 4 = 4 Gigabaud
636# Value range is [0,4]. Default value is 0.
637*/
638LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
639
640/*
641# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
642# Value range is [2,3]. Default value is 3.
643*/
644LPFC_ATTR_R(fcp_class, 3, 2, 3,
645 "Select Fibre Channel class of service for FCP sequences");
646
647/*
648# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
649# is [0,1]. Default value is 0.
650*/
651LPFC_ATTR_RW(use_adisc, 0, 0, 1,
652 "Use ADISC on rediscovery to authenticate FCP devices");
653
654/*
655# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
656# range is [0,1]. Default value is 0.
657*/
658LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
659
660/*
661# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
662# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
663# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
664# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
665# cr_delay is set to 0.
666*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500667LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -0500668 "interrupt response is generated");
669
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500670LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -0500671 "interrupt response is generated");
672
673/*
674# lpfc_fdmi_on: controls FDMI support.
675# 0 = no FDMI support
676# 1 = support FDMI without attribute of hostname
677# 2 = support FDMI with attribute of hostname
678# Value range [0,2]. Default value is 0.
679*/
680LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
681
682/*
683# Specifies the maximum number of ELS cmds we can have outstanding (for
684# discovery). Value range is [1,64]. Default value = 32.
685*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500686LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -0500687 "during discovery");
688
689/*
690# lpfc_max_luns: maximum number of LUNs per target driver will support
691# Value range is [1,32768]. Default value is 256.
692# NOTE: The SCSI layer will scan each target for this many luns
693*/
694LPFC_ATTR_R(max_luns, 256, 1, 32768,
695 "Maximum number of LUNs per target driver will support");
696
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500697/*
698# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
699# Value range is [1,255], default value is 10.
700*/
701LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
702 "Milliseconds driver will wait between polling FCP ring");
703
dea31012005-04-17 16:05:31 -0500704struct class_device_attribute *lpfc_host_attrs[] = {
705 &class_device_attr_info,
706 &class_device_attr_serialnum,
707 &class_device_attr_modeldesc,
708 &class_device_attr_modelname,
709 &class_device_attr_programtype,
710 &class_device_attr_portnum,
711 &class_device_attr_fwrev,
712 &class_device_attr_hdw,
713 &class_device_attr_option_rom_version,
714 &class_device_attr_state,
715 &class_device_attr_num_discovered_ports,
716 &class_device_attr_lpfc_drvr_version,
717 &class_device_attr_lpfc_log_verbose,
718 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500719 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -0500720 &class_device_attr_lpfc_nodev_tmo,
721 &class_device_attr_lpfc_fcp_class,
722 &class_device_attr_lpfc_use_adisc,
723 &class_device_attr_lpfc_ack0,
724 &class_device_attr_lpfc_topology,
725 &class_device_attr_lpfc_scan_down,
726 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500727 &class_device_attr_lpfc_cr_delay,
728 &class_device_attr_lpfc_cr_count,
dea31012005-04-17 16:05:31 -0500729 &class_device_attr_lpfc_fdmi_on,
730 &class_device_attr_lpfc_max_luns,
731 &class_device_attr_nport_evt_cnt,
732 &class_device_attr_management_version,
dea31012005-04-17 16:05:31 -0500733 &class_device_attr_board_online,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500734 &class_device_attr_board_mode,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500735 &class_device_attr_lpfc_poll,
736 &class_device_attr_lpfc_poll_tmo,
dea31012005-04-17 16:05:31 -0500737 NULL,
738};
739
740static ssize_t
741sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
742{
743 size_t buf_off;
744 struct Scsi_Host *host = class_to_shost(container_of(kobj,
745 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500746 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500747
748 if ((off + count) > FF_REG_AREA_SIZE)
749 return -ERANGE;
750
751 if (count == 0) return 0;
752
753 if (off % 4 || count % 4 || (unsigned long)buf % 4)
754 return -EINVAL;
755
756 spin_lock_irq(phba->host->host_lock);
757
758 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
759 spin_unlock_irq(phba->host->host_lock);
760 return -EPERM;
761 }
762
763 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
764 writel(*((uint32_t *)(buf + buf_off)),
765 phba->ctrl_regs_memmap_p + off + buf_off);
766
767 spin_unlock_irq(phba->host->host_lock);
768
769 return count;
770}
771
772static ssize_t
773sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
774{
775 size_t buf_off;
776 uint32_t * tmp_ptr;
777 struct Scsi_Host *host = class_to_shost(container_of(kobj,
778 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500779 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500780
781 if (off > FF_REG_AREA_SIZE)
782 return -ERANGE;
783
784 if ((off + count) > FF_REG_AREA_SIZE)
785 count = FF_REG_AREA_SIZE - off;
786
787 if (count == 0) return 0;
788
789 if (off % 4 || count % 4 || (unsigned long)buf % 4)
790 return -EINVAL;
791
792 spin_lock_irq(phba->host->host_lock);
793
794 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
795 tmp_ptr = (uint32_t *)(buf + buf_off);
796 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
797 }
798
799 spin_unlock_irq(phba->host->host_lock);
800
801 return count;
802}
803
804static struct bin_attribute sysfs_ctlreg_attr = {
805 .attr = {
806 .name = "ctlreg",
807 .mode = S_IRUSR | S_IWUSR,
808 .owner = THIS_MODULE,
809 },
810 .size = 256,
811 .read = sysfs_ctlreg_read,
812 .write = sysfs_ctlreg_write,
813};
814
815
816static void
817sysfs_mbox_idle (struct lpfc_hba * phba)
818{
819 phba->sysfs_mbox.state = SMBOX_IDLE;
820 phba->sysfs_mbox.offset = 0;
821
822 if (phba->sysfs_mbox.mbox) {
823 mempool_free(phba->sysfs_mbox.mbox,
824 phba->mbox_mem_pool);
825 phba->sysfs_mbox.mbox = NULL;
826 }
827}
828
829static ssize_t
830sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
831{
832 struct Scsi_Host * host =
833 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500834 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500835 struct lpfcMboxq * mbox = NULL;
836
837 if ((count + off) > MAILBOX_CMD_SIZE)
838 return -ERANGE;
839
840 if (off % 4 || count % 4 || (unsigned long)buf % 4)
841 return -EINVAL;
842
843 if (count == 0)
844 return 0;
845
846 if (off == 0) {
847 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
848 if (!mbox)
849 return -ENOMEM;
850
851 }
852
853 spin_lock_irq(host->host_lock);
854
855 if (off == 0) {
856 if (phba->sysfs_mbox.mbox)
857 mempool_free(mbox, phba->mbox_mem_pool);
858 else
859 phba->sysfs_mbox.mbox = mbox;
860 phba->sysfs_mbox.state = SMBOX_WRITING;
861 } else {
862 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
863 phba->sysfs_mbox.offset != off ||
864 phba->sysfs_mbox.mbox == NULL ) {
865 sysfs_mbox_idle(phba);
866 spin_unlock_irq(host->host_lock);
867 return -EINVAL;
868 }
869 }
870
871 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
872 buf, count);
873
874 phba->sysfs_mbox.offset = off + count;
875
876 spin_unlock_irq(host->host_lock);
877
878 return count;
879}
880
881static ssize_t
882sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
883{
884 struct Scsi_Host *host =
885 class_to_shost(container_of(kobj, struct class_device,
886 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500887 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500888 int rc;
889
890 if (off > sizeof(MAILBOX_t))
891 return -ERANGE;
892
893 if ((count + off) > sizeof(MAILBOX_t))
894 count = sizeof(MAILBOX_t) - off;
895
896 if (off % 4 || count % 4 || (unsigned long)buf % 4)
897 return -EINVAL;
898
899 if (off && count == 0)
900 return 0;
901
902 spin_lock_irq(phba->host->host_lock);
903
904 if (off == 0 &&
905 phba->sysfs_mbox.state == SMBOX_WRITING &&
906 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
907
908 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
909 /* Offline only */
910 case MBX_WRITE_NV:
911 case MBX_INIT_LINK:
912 case MBX_DOWN_LINK:
913 case MBX_CONFIG_LINK:
914 case MBX_CONFIG_RING:
915 case MBX_RESET_RING:
916 case MBX_UNREG_LOGIN:
917 case MBX_CLEAR_LA:
918 case MBX_DUMP_CONTEXT:
919 case MBX_RUN_DIAGS:
920 case MBX_RESTART:
921 case MBX_FLASH_WR_ULA:
922 case MBX_SET_MASK:
923 case MBX_SET_SLIM:
924 case MBX_SET_DEBUG:
925 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
926 printk(KERN_WARNING "mbox_read:Command 0x%x "
927 "is illegal in on-line state\n",
928 phba->sysfs_mbox.mbox->mb.mbxCommand);
929 sysfs_mbox_idle(phba);
930 spin_unlock_irq(phba->host->host_lock);
931 return -EPERM;
932 }
933 case MBX_LOAD_SM:
934 case MBX_READ_NV:
935 case MBX_READ_CONFIG:
936 case MBX_READ_RCONFIG:
937 case MBX_READ_STATUS:
938 case MBX_READ_XRI:
939 case MBX_READ_REV:
940 case MBX_READ_LNK_STAT:
941 case MBX_DUMP_MEMORY:
942 case MBX_DOWN_LOAD:
943 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500944 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500945 case MBX_LOAD_AREA:
946 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500947 case MBX_BEACON:
948 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -0500949 break;
950 case MBX_READ_SPARM64:
951 case MBX_READ_LA:
952 case MBX_READ_LA64:
953 case MBX_REG_LOGIN:
954 case MBX_REG_LOGIN64:
955 case MBX_CONFIG_PORT:
956 case MBX_RUN_BIU_DIAG:
957 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
958 phba->sysfs_mbox.mbox->mb.mbxCommand);
959 sysfs_mbox_idle(phba);
960 spin_unlock_irq(phba->host->host_lock);
961 return -EPERM;
962 default:
963 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
964 phba->sysfs_mbox.mbox->mb.mbxCommand);
965 sysfs_mbox_idle(phba);
966 spin_unlock_irq(phba->host->host_lock);
967 return -EPERM;
968 }
969
970 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
971 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
972
973 spin_unlock_irq(phba->host->host_lock);
974 rc = lpfc_sli_issue_mbox (phba,
975 phba->sysfs_mbox.mbox,
976 MBX_POLL);
977 spin_lock_irq(phba->host->host_lock);
978
979 } else {
980 spin_unlock_irq(phba->host->host_lock);
981 rc = lpfc_sli_issue_mbox_wait (phba,
982 phba->sysfs_mbox.mbox,
983 phba->fc_ratov * 2);
984 spin_lock_irq(phba->host->host_lock);
985 }
986
987 if (rc != MBX_SUCCESS) {
988 sysfs_mbox_idle(phba);
989 spin_unlock_irq(host->host_lock);
990 return -ENODEV;
991 }
992 phba->sysfs_mbox.state = SMBOX_READING;
993 }
994 else if (phba->sysfs_mbox.offset != off ||
995 phba->sysfs_mbox.state != SMBOX_READING) {
996 printk(KERN_WARNING "mbox_read: Bad State\n");
997 sysfs_mbox_idle(phba);
998 spin_unlock_irq(host->host_lock);
999 return -EINVAL;
1000 }
1001
1002 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1003
1004 phba->sysfs_mbox.offset = off + count;
1005
1006 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1007 sysfs_mbox_idle(phba);
1008
1009 spin_unlock_irq(phba->host->host_lock);
1010
1011 return count;
1012}
1013
1014static struct bin_attribute sysfs_mbox_attr = {
1015 .attr = {
1016 .name = "mbox",
1017 .mode = S_IRUSR | S_IWUSR,
1018 .owner = THIS_MODULE,
1019 },
1020 .size = sizeof(MAILBOX_t),
1021 .read = sysfs_mbox_read,
1022 .write = sysfs_mbox_write,
1023};
1024
1025int
1026lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1027{
1028 struct Scsi_Host *host = phba->host;
1029 int error;
1030
1031 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1032 &sysfs_ctlreg_attr);
1033 if (error)
1034 goto out;
1035
1036 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1037 &sysfs_mbox_attr);
1038 if (error)
1039 goto out_remove_ctlreg_attr;
1040
1041 return 0;
1042out_remove_ctlreg_attr:
1043 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1044out:
1045 return error;
1046}
1047
1048void
1049lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1050{
1051 struct Scsi_Host *host = phba->host;
1052
1053 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1054 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1055}
1056
1057
1058/*
1059 * Dynamic FC Host Attributes Support
1060 */
1061
1062static void
1063lpfc_get_host_port_id(struct Scsi_Host *shost)
1064{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001065 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001066 /* note: fc_myDID already in cpu endianness */
1067 fc_host_port_id(shost) = phba->fc_myDID;
1068}
1069
1070static void
1071lpfc_get_host_port_type(struct Scsi_Host *shost)
1072{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001073 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001074
1075 spin_lock_irq(shost->host_lock);
1076
1077 if (phba->hba_state == LPFC_HBA_READY) {
1078 if (phba->fc_topology == TOPOLOGY_LOOP) {
1079 if (phba->fc_flag & FC_PUBLIC_LOOP)
1080 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1081 else
1082 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1083 } else {
1084 if (phba->fc_flag & FC_FABRIC)
1085 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1086 else
1087 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1088 }
1089 } else
1090 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1091
1092 spin_unlock_irq(shost->host_lock);
1093}
1094
1095static void
1096lpfc_get_host_port_state(struct Scsi_Host *shost)
1097{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001098 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001099
1100 spin_lock_irq(shost->host_lock);
1101
1102 if (phba->fc_flag & FC_OFFLINE_MODE)
1103 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1104 else {
1105 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001106 case LPFC_STATE_UNKNOWN:
1107 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001108 case LPFC_INIT_START:
1109 case LPFC_INIT_MBX_CMDS:
1110 case LPFC_LINK_DOWN:
1111 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1112 break;
1113 case LPFC_LINK_UP:
1114 case LPFC_LOCAL_CFG_LINK:
1115 case LPFC_FLOGI:
1116 case LPFC_FABRIC_CFG_LINK:
1117 case LPFC_NS_REG:
1118 case LPFC_NS_QRY:
1119 case LPFC_BUILD_DISC_LIST:
1120 case LPFC_DISC_AUTH:
1121 case LPFC_CLEAR_LA:
1122 case LPFC_HBA_READY:
1123 /* Links up, beyond this port_type reports state */
1124 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1125 break;
1126 case LPFC_HBA_ERROR:
1127 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1128 break;
1129 default:
1130 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1131 break;
1132 }
1133 }
1134
1135 spin_unlock_irq(shost->host_lock);
1136}
1137
1138static void
1139lpfc_get_host_speed(struct Scsi_Host *shost)
1140{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001141 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001142
1143 spin_lock_irq(shost->host_lock);
1144
1145 if (phba->hba_state == LPFC_HBA_READY) {
1146 switch(phba->fc_linkspeed) {
1147 case LA_1GHZ_LINK:
1148 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1149 break;
1150 case LA_2GHZ_LINK:
1151 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1152 break;
1153 case LA_4GHZ_LINK:
1154 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1155 break;
1156 default:
1157 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1158 break;
1159 }
1160 }
1161
1162 spin_unlock_irq(shost->host_lock);
1163}
1164
1165static void
1166lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1167{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001168 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001169 u64 node_name;
dea31012005-04-17 16:05:31 -05001170
1171 spin_lock_irq(shost->host_lock);
1172
1173 if ((phba->fc_flag & FC_FABRIC) ||
1174 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1175 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001176 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001177 else
1178 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001179 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001180
1181 spin_unlock_irq(shost->host_lock);
1182
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001183 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001184}
1185
1186
1187static struct fc_host_statistics *
1188lpfc_get_stats(struct Scsi_Host *shost)
1189{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001190 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001191 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001192 struct fc_host_statistics *hs = &phba->link_stats;
dea31012005-04-17 16:05:31 -05001193 LPFC_MBOXQ_t *pmboxq;
1194 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001195 int rc = 0;
dea31012005-04-17 16:05:31 -05001196
1197 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1198 if (!pmboxq)
1199 return NULL;
1200 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1201
1202 pmb = &pmboxq->mb;
1203 pmb->mbxCommand = MBX_READ_STATUS;
1204 pmb->mbxOwner = OWN_HOST;
1205 pmboxq->context1 = NULL;
1206
1207 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001208 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001209 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001210 else
dea31012005-04-17 16:05:31 -05001211 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1212
1213 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001214 if (rc == MBX_TIMEOUT)
1215 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1216 else
1217 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001218 return NULL;
1219 }
1220
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001221 memset(hs, 0, sizeof (struct fc_host_statistics));
1222
dea31012005-04-17 16:05:31 -05001223 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1224 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1225 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1226 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1227
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001228 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001229 pmb->mbxCommand = MBX_READ_LNK_STAT;
1230 pmb->mbxOwner = OWN_HOST;
1231 pmboxq->context1 = NULL;
1232
1233 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001234 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001235 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001236 else
dea31012005-04-17 16:05:31 -05001237 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1238
1239 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001240 if (rc == MBX_TIMEOUT)
1241 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1242 else
1243 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001244 return NULL;
1245 }
1246
1247 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1248 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1249 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1250 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1251 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1252 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1253 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1254
1255 if (phba->fc_topology == TOPOLOGY_LOOP) {
1256 hs->lip_count = (phba->fc_eventTag >> 1);
1257 hs->nos_count = -1;
1258 } else {
1259 hs->lip_count = -1;
1260 hs->nos_count = (phba->fc_eventTag >> 1);
1261 }
1262
1263 hs->dumped_frames = -1;
1264
1265/* FIX ME */
1266 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1267
1268 return hs;
1269}
1270
1271
1272/*
1273 * The LPFC driver treats linkdown handling as target loss events so there
1274 * are no sysfs handlers for link_down_tmo.
1275 */
1276static void
1277lpfc_get_starget_port_id(struct scsi_target *starget)
1278{
1279 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001280 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea31012005-04-17 16:05:31 -05001281 uint32_t did = -1;
1282 struct lpfc_nodelist *ndlp = NULL;
1283
1284 spin_lock_irq(shost->host_lock);
1285 /* Search the mapped list for this target ID */
1286 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1287 if (starget->id == ndlp->nlp_sid) {
1288 did = ndlp->nlp_DID;
1289 break;
1290 }
1291 }
1292 spin_unlock_irq(shost->host_lock);
1293
1294 fc_starget_port_id(starget) = did;
1295}
1296
1297static void
1298lpfc_get_starget_node_name(struct scsi_target *starget)
1299{
1300 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001301 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001302 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001303 struct lpfc_nodelist *ndlp = NULL;
1304
1305 spin_lock_irq(shost->host_lock);
1306 /* Search the mapped list for this target ID */
1307 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1308 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001309 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001310 break;
1311 }
1312 }
1313 spin_unlock_irq(shost->host_lock);
1314
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001315 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001316}
1317
1318static void
1319lpfc_get_starget_port_name(struct scsi_target *starget)
1320{
1321 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001322 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001323 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001324 struct lpfc_nodelist *ndlp = NULL;
1325
1326 spin_lock_irq(shost->host_lock);
1327 /* Search the mapped list for this target ID */
1328 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1329 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001330 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001331 break;
1332 }
1333 }
1334 spin_unlock_irq(shost->host_lock);
1335
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001336 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001337}
1338
1339static void
1340lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1341{
1342 /*
1343 * Return the driver's global value for device loss timeout plus
1344 * five seconds to allow the driver's nodev timer to run.
1345 */
1346 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1347}
1348
1349static void
1350lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1351{
1352 /*
1353 * The driver doesn't have a per-target timeout setting. Set
1354 * this value globally. lpfc_nodev_tmo should be greater then 0.
1355 */
1356 if (timeout)
1357 lpfc_nodev_tmo = timeout;
1358 else
1359 lpfc_nodev_tmo = 1;
1360 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1361}
1362
1363
1364#define lpfc_rport_show_function(field, format_string, sz, cast) \
1365static ssize_t \
1366lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1367{ \
1368 struct fc_rport *rport = transport_class_to_rport(cdev); \
1369 struct lpfc_rport_data *rdata = rport->hostdata; \
1370 return snprintf(buf, sz, format_string, \
1371 (rdata->target) ? cast rdata->target->field : 0); \
1372}
1373
1374#define lpfc_rport_rd_attr(field, format_string, sz) \
1375 lpfc_rport_show_function(field, format_string, sz, ) \
1376static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1377
1378
1379struct fc_function_template lpfc_transport_functions = {
1380 /* fixed attributes the driver supports */
1381 .show_host_node_name = 1,
1382 .show_host_port_name = 1,
1383 .show_host_supported_classes = 1,
1384 .show_host_supported_fc4s = 1,
1385 .show_host_symbolic_name = 1,
1386 .show_host_supported_speeds = 1,
1387 .show_host_maxframe_size = 1,
1388
1389 /* dynamic attributes the driver supports */
1390 .get_host_port_id = lpfc_get_host_port_id,
1391 .show_host_port_id = 1,
1392
1393 .get_host_port_type = lpfc_get_host_port_type,
1394 .show_host_port_type = 1,
1395
1396 .get_host_port_state = lpfc_get_host_port_state,
1397 .show_host_port_state = 1,
1398
1399 /* active_fc4s is shown but doesn't change (thus no get function) */
1400 .show_host_active_fc4s = 1,
1401
1402 .get_host_speed = lpfc_get_host_speed,
1403 .show_host_speed = 1,
1404
1405 .get_host_fabric_name = lpfc_get_host_fabric_name,
1406 .show_host_fabric_name = 1,
1407
1408 /*
1409 * The LPFC driver treats linkdown handling as target loss events
1410 * so there are no sysfs handlers for link_down_tmo.
1411 */
1412
1413 .get_fc_host_stats = lpfc_get_stats,
1414
1415 /* the LPFC driver doesn't support resetting stats yet */
1416
1417 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1418 .show_rport_maxframe_size = 1,
1419 .show_rport_supported_classes = 1,
1420
1421 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1422 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1423 .show_rport_dev_loss_tmo = 1,
1424
1425 .get_starget_port_id = lpfc_get_starget_port_id,
1426 .show_starget_port_id = 1,
1427
1428 .get_starget_node_name = lpfc_get_starget_node_name,
1429 .show_starget_node_name = 1,
1430
1431 .get_starget_port_name = lpfc_get_starget_port_name,
1432 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001433
1434 .issue_fc_host_lip = lpfc_issue_lip,
dea31012005-04-17 16:05:31 -05001435};
1436
1437void
1438lpfc_get_cfgparam(struct lpfc_hba *phba)
1439{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001440 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1441 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1442 lpfc_cr_count_init(phba, lpfc_cr_count);
1443 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1444 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1445 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1446 lpfc_ack0_init(phba, lpfc_ack0);
1447 lpfc_topology_init(phba, lpfc_topology);
1448 lpfc_scan_down_init(phba, lpfc_scan_down);
1449 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1450 lpfc_link_speed_init(phba, lpfc_link_speed);
1451 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1452 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1453 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001454 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1455
1456 phba->cfg_poll = lpfc_poll;
dea31012005-04-17 16:05:31 -05001457
1458 /*
1459 * The total number of segments is the configuration value plus 2
1460 * since the IOCB need a command and response bde.
1461 */
1462 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1463
1464 /*
1465 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1466 * used to create the sg_dma_buf_pool must be dynamically calculated
1467 */
1468 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1469 sizeof(struct fcp_rsp) +
1470 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1471
1472 switch (phba->pcidev->device) {
1473 case PCI_DEVICE_ID_LP101:
1474 case PCI_DEVICE_ID_BSMB:
1475 case PCI_DEVICE_ID_ZSMB:
1476 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1477 break;
1478 case PCI_DEVICE_ID_RFLY:
1479 case PCI_DEVICE_ID_PFLY:
1480 case PCI_DEVICE_ID_BMID:
1481 case PCI_DEVICE_ID_ZMID:
1482 case PCI_DEVICE_ID_TFLY:
1483 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1484 break;
1485 default:
1486 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1487 }
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001488
1489 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1490 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1491
dea31012005-04-17 16:05:31 -05001492 return;
1493}