blob: d384c16f4a87c6213b23ce3f91e70369d682adce [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));
James Smart4db621e2006-07-06 15:49:49 -0400222 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
223 pmboxq->mb.mbxOwner = OWN_HOST;
224
James Smart33ccf8d2006-08-17 11:57:58 -0400225 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500226
James Smart4db621e2006-07-06 15:49:49 -0400227 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
228 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
229 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
230 phba->cfg_link_speed);
231 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
232 phba->fc_ratov * 2);
233 }
234
dea31012005-04-17 16:05:31 -0500235 if (mbxstatus == MBX_TIMEOUT)
236 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
237 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400238 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500239
240 if (mbxstatus == MBXERR_ERROR)
241 return -EIO;
242
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700243 return 0;
dea31012005-04-17 16:05:31 -0500244}
245
James Smart40496f02006-07-06 15:50:22 -0400246static int
247lpfc_selective_reset(struct lpfc_hba *phba)
248{
249 struct completion online_compl;
250 int status = 0;
251
252 init_completion(&online_compl);
253 lpfc_workq_post_event(phba, &status, &online_compl,
254 LPFC_EVT_OFFLINE);
255 wait_for_completion(&online_compl);
256
257 if (status != 0)
258 return -EIO;
259
260 init_completion(&online_compl);
261 lpfc_workq_post_event(phba, &status, &online_compl,
262 LPFC_EVT_ONLINE);
263 wait_for_completion(&online_compl);
264
265 if (status != 0)
266 return -EIO;
267
268 return 0;
269}
270
271static ssize_t
272lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
273{
274 struct Scsi_Host *host = class_to_shost(cdev);
275 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
276 int status = -EINVAL;
277
278 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
279 status = lpfc_selective_reset(phba);
280
281 if (status == 0)
282 return strlen(buf);
283 else
284 return status;
285}
286
dea31012005-04-17 16:05:31 -0500287static ssize_t
288lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
289{
290 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500291 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500292 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
293}
294
295static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500296lpfc_board_mode_show(struct class_device *cdev, char *buf)
297{
298 struct Scsi_Host *host = class_to_shost(cdev);
299 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
300 char * state;
301
302 if (phba->hba_state == LPFC_HBA_ERROR)
303 state = "error";
304 else if (phba->hba_state == LPFC_WARM_START)
305 state = "warm start";
306 else if (phba->hba_state == LPFC_INIT_START)
307 state = "offline";
308 else
309 state = "online";
310
311 return snprintf(buf, PAGE_SIZE, "%s\n", state);
312}
313
314static ssize_t
315lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
316{
317 struct Scsi_Host *host = class_to_shost(cdev);
318 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
319 struct completion online_compl;
320 int status=0;
321
322 init_completion(&online_compl);
323
324 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
325 lpfc_workq_post_event(phba, &status, &online_compl,
326 LPFC_EVT_ONLINE);
327 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
328 lpfc_workq_post_event(phba, &status, &online_compl,
329 LPFC_EVT_OFFLINE);
330 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
331 lpfc_workq_post_event(phba, &status, &online_compl,
332 LPFC_EVT_WARM_START);
333 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
334 lpfc_workq_post_event(phba, &status, &online_compl,
335 LPFC_EVT_KILL);
336 else
337 return -EINVAL;
338
339 wait_for_completion(&online_compl);
340
341 if (!status)
342 return strlen(buf);
343 else
344 return -EIO;
345}
346
347static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500348lpfc_poll_show(struct class_device *cdev, char *buf)
349{
350 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500351 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500352
353 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
354}
355
356static ssize_t
357lpfc_poll_store(struct class_device *cdev, const char *buf,
358 size_t count)
359{
360 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500361 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500362 uint32_t creg_val;
363 uint32_t old_val;
364 int val=0;
365
366 if (!isdigit(buf[0]))
367 return -EINVAL;
368
369 if (sscanf(buf, "%i", &val) != 1)
370 return -EINVAL;
371
372 if ((val & 0x3) != val)
373 return -EINVAL;
374
375 spin_lock_irq(phba->host->host_lock);
376
377 old_val = phba->cfg_poll;
378
379 if (val & ENABLE_FCP_RING_POLLING) {
380 if ((val & DISABLE_FCP_RING_INT) &&
381 !(old_val & DISABLE_FCP_RING_INT)) {
382 creg_val = readl(phba->HCregaddr);
383 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
384 writel(creg_val, phba->HCregaddr);
385 readl(phba->HCregaddr); /* flush */
386
387 lpfc_poll_start_timer(phba);
388 }
389 } else if (val != 0x0) {
390 spin_unlock_irq(phba->host->host_lock);
391 return -EINVAL;
392 }
393
394 if (!(val & DISABLE_FCP_RING_INT) &&
395 (old_val & DISABLE_FCP_RING_INT))
396 {
397 spin_unlock_irq(phba->host->host_lock);
398 del_timer(&phba->fcp_poll_timer);
399 spin_lock_irq(phba->host->host_lock);
400 creg_val = readl(phba->HCregaddr);
401 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
402 writel(creg_val, phba->HCregaddr);
403 readl(phba->HCregaddr); /* flush */
404 }
405
406 phba->cfg_poll = val;
407
408 spin_unlock_irq(phba->host->host_lock);
409
410 return strlen(buf);
411}
dea31012005-04-17 16:05:31 -0500412
413#define lpfc_param_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;\
dea31012005-04-17 16:05:31 -0500419 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400420 val = phba->cfg_##attr;\
421 return snprintf(buf, PAGE_SIZE, "%d\n",\
422 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500423}
424
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400425#define lpfc_param_hex_show(attr) \
426static ssize_t \
427lpfc_##attr##_show(struct class_device *cdev, char *buf) \
428{ \
429 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500430 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400431 int val = 0;\
432 val = phba->cfg_##attr;\
433 return snprintf(buf, PAGE_SIZE, "%#x\n",\
434 phba->cfg_##attr);\
435}
436
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400437#define lpfc_param_init(attr, default, minval, maxval) \
438static int \
439lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
440{ \
441 if (val >= minval && val <= maxval) {\
442 phba->cfg_##attr = val;\
443 return 0;\
444 }\
445 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
446 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
447 "allowed range is ["#minval", "#maxval"]\n", \
448 phba->brd_no, val); \
449 phba->cfg_##attr = default;\
450 return -EINVAL;\
451}
452
453#define lpfc_param_set(attr, default, minval, maxval) \
454static int \
455lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
456{ \
457 if (val >= minval && val <= maxval) {\
458 phba->cfg_##attr = val;\
459 return 0;\
460 }\
461 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
462 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
463 "allowed range is ["#minval", "#maxval"]\n", \
464 phba->brd_no, val); \
465 return -EINVAL;\
466}
467
468#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500469static ssize_t \
470lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
471{ \
472 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500473 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400474 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400475 if (!isdigit(buf[0]))\
476 return -EINVAL;\
477 if (sscanf(buf, "%i", &val) != 1)\
478 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400479 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400480 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400481 else \
482 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500483}
484
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400485#define LPFC_ATTR(name, defval, minval, maxval, desc) \
486static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500487module_param(lpfc_##name, int, 0);\
488MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400489lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500490
491#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
492static int lpfc_##name = defval;\
493module_param(lpfc_##name, int, 0);\
494MODULE_PARM_DESC(lpfc_##name, desc);\
495lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400496lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500497static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
498
499#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
500static int lpfc_##name = defval;\
501module_param(lpfc_##name, int, 0);\
502MODULE_PARM_DESC(lpfc_##name, desc);\
503lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400504lpfc_param_init(name, defval, minval, maxval)\
505lpfc_param_set(name, defval, minval, maxval)\
506lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500507static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
508 lpfc_##name##_show, lpfc_##name##_store)
509
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400510#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
511static int lpfc_##name = defval;\
512module_param(lpfc_##name, int, 0);\
513MODULE_PARM_DESC(lpfc_##name, desc);\
514lpfc_param_hex_show(name)\
515lpfc_param_init(name, defval, minval, maxval)\
516static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
517
518#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
519static int lpfc_##name = defval;\
520module_param(lpfc_##name, int, 0);\
521MODULE_PARM_DESC(lpfc_##name, desc);\
522lpfc_param_hex_show(name)\
523lpfc_param_init(name, defval, minval, maxval)\
524lpfc_param_set(name, defval, minval, maxval)\
525lpfc_param_store(name)\
526static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
527 lpfc_##name##_show, lpfc_##name##_store)
528
dea31012005-04-17 16:05:31 -0500529static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
530static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
531static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
532static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
533static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
534static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
535static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
536static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
537static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
538static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
539 lpfc_option_rom_version_show, NULL);
540static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
541 lpfc_num_discovered_ports_show, NULL);
542static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
543static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
544 NULL);
545static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
546 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500547static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
548 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400549static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea31012005-04-17 16:05:31 -0500550
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500551static int lpfc_poll = 0;
552module_param(lpfc_poll, int, 0);
553MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
554 " 0 - none,"
555 " 1 - poll with interrupts enabled"
556 " 3 - poll and disable FCP ring interrupts");
557
558static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
559 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500560
561/*
562# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
563# deluged with LOTS of information.
564# You can set a bit mask to record specific types of verbose messages:
565#
566# LOG_ELS 0x1 ELS events
567# LOG_DISCOVERY 0x2 Link discovery events
568# LOG_MBOX 0x4 Mailbox events
569# LOG_INIT 0x8 Initialization events
570# LOG_LINK_EVENT 0x10 Link events
571# LOG_IP 0x20 IP traffic history
572# LOG_FCP 0x40 FCP traffic history
573# LOG_NODE 0x80 Node table events
574# LOG_MISC 0x400 Miscellaneous events
575# LOG_SLI 0x800 SLI events
576# LOG_CHK_COND 0x1000 FCP Check condition flag
577# LOG_LIBDFC 0x2000 LIBDFC events
578# LOG_ALL_MSG 0xffff LOG all messages
579*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400580LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500581
582/*
583# lun_queue_depth: This parameter is used to limit the number of outstanding
584# commands per FCP LUN. Value range is [1,128]. Default value is 30.
585*/
586LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
587 "Max number of FCP commands we can queue to a specific LUN");
588
589/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500590# hba_queue_depth: This parameter is used to limit the number of outstanding
591# commands per lpfc HBA. Value range is [32,8192]. If this parameter
592# value is greater than the maximum number of exchanges supported by the HBA,
593# then maximum number of exchanges supported by the HBA is used to determine
594# the hba_queue_depth.
595*/
596LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
597 "Max number of FCP commands we can queue to a lpfc HBA");
598
599/*
dea31012005-04-17 16:05:31 -0500600# Some disk devices have a "select ID" or "select Target" capability.
601# From a protocol standpoint "select ID" usually means select the
602# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
603# annex" which contains a table that maps a "select ID" (a number
604# between 0 and 7F) to an ALPA. By default, for compatibility with
605# older drivers, the lpfc driver scans this table from low ALPA to high
606# ALPA.
607#
608# Turning on the scan-down variable (on = 1, off = 0) will
609# cause the lpfc driver to use an inverted table, effectively
610# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
611#
612# (Note: This "select ID" functionality is a LOOP ONLY characteristic
613# and will not work across a fabric. Also this parameter will take
614# effect only in the case when ALPA map is not available.)
615*/
616LPFC_ATTR_R(scan_down, 1, 0, 1,
617 "Start scanning for devices from highest ALPA to lowest");
618
619/*
620# 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 -0400621# until the timer expires. Value range is [0,255]. Default value is 30.
dea31012005-04-17 16:05:31 -0500622# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
623*/
624LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
625 "Seconds driver will hold I/O waiting for a device to come back");
626
627/*
628# lpfc_topology: link topology for init link
629# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500630# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500631# 0x02 = attempt point-to-point mode only
632# 0x04 = attempt loop mode only
633# 0x06 = attempt point-to-point mode then loop
634# Set point-to-point mode if you want to run as an N_Port.
635# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
636# Default value is 0.
637*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500638LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500639
640/*
641# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
642# connection.
643# 0 = auto select (default)
644# 1 = 1 Gigabaud
645# 2 = 2 Gigabaud
646# 4 = 4 Gigabaud
647# Value range is [0,4]. Default value is 0.
648*/
649LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
650
651/*
652# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
653# Value range is [2,3]. Default value is 3.
654*/
655LPFC_ATTR_R(fcp_class, 3, 2, 3,
656 "Select Fibre Channel class of service for FCP sequences");
657
658/*
659# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
660# is [0,1]. Default value is 0.
661*/
662LPFC_ATTR_RW(use_adisc, 0, 0, 1,
663 "Use ADISC on rediscovery to authenticate FCP devices");
664
665/*
666# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
667# range is [0,1]. Default value is 0.
668*/
669LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
670
671/*
672# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
673# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
674# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
675# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
676# cr_delay is set to 0.
677*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500678LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -0500679 "interrupt response is generated");
680
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500681LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -0500682 "interrupt response is generated");
683
684/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500685# lpfc_multi_ring_support: Determines how many rings to spread available
686# cmd/rsp IOCB entries across.
687# Value range is [1,2]. Default value is 1.
688*/
689LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
690 "SLI rings to spread IOCB entries across");
691
692/*
dea31012005-04-17 16:05:31 -0500693# lpfc_fdmi_on: controls FDMI support.
694# 0 = no FDMI support
695# 1 = support FDMI without attribute of hostname
696# 2 = support FDMI with attribute of hostname
697# Value range [0,2]. Default value is 0.
698*/
699LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
700
701/*
702# Specifies the maximum number of ELS cmds we can have outstanding (for
703# discovery). Value range is [1,64]. Default value = 32.
704*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500705LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -0500706 "during discovery");
707
708/*
James Smart65a29c12006-07-06 15:50:50 -0400709# lpfc_max_luns: maximum allowed LUN.
710# Value range is [0,65535]. Default value is 255.
711# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -0500712*/
James Smart65a29c12006-07-06 15:50:50 -0400713LPFC_ATTR_R(max_luns, 255, 0, 65535,
714 "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -0500715
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500716/*
717# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
718# Value range is [1,255], default value is 10.
719*/
720LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
721 "Milliseconds driver will wait between polling FCP ring");
722
dea31012005-04-17 16:05:31 -0500723struct class_device_attribute *lpfc_host_attrs[] = {
724 &class_device_attr_info,
725 &class_device_attr_serialnum,
726 &class_device_attr_modeldesc,
727 &class_device_attr_modelname,
728 &class_device_attr_programtype,
729 &class_device_attr_portnum,
730 &class_device_attr_fwrev,
731 &class_device_attr_hdw,
732 &class_device_attr_option_rom_version,
733 &class_device_attr_state,
734 &class_device_attr_num_discovered_ports,
735 &class_device_attr_lpfc_drvr_version,
736 &class_device_attr_lpfc_log_verbose,
737 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500738 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -0500739 &class_device_attr_lpfc_nodev_tmo,
740 &class_device_attr_lpfc_fcp_class,
741 &class_device_attr_lpfc_use_adisc,
742 &class_device_attr_lpfc_ack0,
743 &class_device_attr_lpfc_topology,
744 &class_device_attr_lpfc_scan_down,
745 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500746 &class_device_attr_lpfc_cr_delay,
747 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500748 &class_device_attr_lpfc_multi_ring_support,
dea31012005-04-17 16:05:31 -0500749 &class_device_attr_lpfc_fdmi_on,
750 &class_device_attr_lpfc_max_luns,
751 &class_device_attr_nport_evt_cnt,
752 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500753 &class_device_attr_board_mode,
James Smart40496f02006-07-06 15:50:22 -0400754 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500755 &class_device_attr_lpfc_poll,
756 &class_device_attr_lpfc_poll_tmo,
dea31012005-04-17 16:05:31 -0500757 NULL,
758};
759
760static ssize_t
761sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
762{
763 size_t buf_off;
764 struct Scsi_Host *host = class_to_shost(container_of(kobj,
765 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500766 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500767
768 if ((off + count) > FF_REG_AREA_SIZE)
769 return -ERANGE;
770
771 if (count == 0) return 0;
772
773 if (off % 4 || count % 4 || (unsigned long)buf % 4)
774 return -EINVAL;
775
776 spin_lock_irq(phba->host->host_lock);
777
778 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
779 spin_unlock_irq(phba->host->host_lock);
780 return -EPERM;
781 }
782
783 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
784 writel(*((uint32_t *)(buf + buf_off)),
785 phba->ctrl_regs_memmap_p + off + buf_off);
786
787 spin_unlock_irq(phba->host->host_lock);
788
789 return count;
790}
791
792static ssize_t
793sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
794{
795 size_t buf_off;
796 uint32_t * tmp_ptr;
797 struct Scsi_Host *host = class_to_shost(container_of(kobj,
798 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500799 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500800
801 if (off > FF_REG_AREA_SIZE)
802 return -ERANGE;
803
804 if ((off + count) > FF_REG_AREA_SIZE)
805 count = FF_REG_AREA_SIZE - off;
806
807 if (count == 0) return 0;
808
809 if (off % 4 || count % 4 || (unsigned long)buf % 4)
810 return -EINVAL;
811
812 spin_lock_irq(phba->host->host_lock);
813
814 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
815 tmp_ptr = (uint32_t *)(buf + buf_off);
816 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
817 }
818
819 spin_unlock_irq(phba->host->host_lock);
820
821 return count;
822}
823
824static struct bin_attribute sysfs_ctlreg_attr = {
825 .attr = {
826 .name = "ctlreg",
827 .mode = S_IRUSR | S_IWUSR,
828 .owner = THIS_MODULE,
829 },
830 .size = 256,
831 .read = sysfs_ctlreg_read,
832 .write = sysfs_ctlreg_write,
833};
834
835
836static void
837sysfs_mbox_idle (struct lpfc_hba * phba)
838{
839 phba->sysfs_mbox.state = SMBOX_IDLE;
840 phba->sysfs_mbox.offset = 0;
841
842 if (phba->sysfs_mbox.mbox) {
843 mempool_free(phba->sysfs_mbox.mbox,
844 phba->mbox_mem_pool);
845 phba->sysfs_mbox.mbox = NULL;
846 }
847}
848
849static ssize_t
850sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
851{
852 struct Scsi_Host * host =
853 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500854 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500855 struct lpfcMboxq * mbox = NULL;
856
857 if ((count + off) > MAILBOX_CMD_SIZE)
858 return -ERANGE;
859
860 if (off % 4 || count % 4 || (unsigned long)buf % 4)
861 return -EINVAL;
862
863 if (count == 0)
864 return 0;
865
866 if (off == 0) {
867 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
868 if (!mbox)
869 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -0500870 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -0500871 }
872
873 spin_lock_irq(host->host_lock);
874
875 if (off == 0) {
876 if (phba->sysfs_mbox.mbox)
877 mempool_free(mbox, phba->mbox_mem_pool);
878 else
879 phba->sysfs_mbox.mbox = mbox;
880 phba->sysfs_mbox.state = SMBOX_WRITING;
881 } else {
882 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
883 phba->sysfs_mbox.offset != off ||
884 phba->sysfs_mbox.mbox == NULL ) {
885 sysfs_mbox_idle(phba);
886 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -0400887 return -EAGAIN;
dea31012005-04-17 16:05:31 -0500888 }
889 }
890
891 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
892 buf, count);
893
894 phba->sysfs_mbox.offset = off + count;
895
896 spin_unlock_irq(host->host_lock);
897
898 return count;
899}
900
901static ssize_t
902sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
903{
904 struct Scsi_Host *host =
905 class_to_shost(container_of(kobj, struct class_device,
906 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500907 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500908 int rc;
909
910 if (off > sizeof(MAILBOX_t))
911 return -ERANGE;
912
913 if ((count + off) > sizeof(MAILBOX_t))
914 count = sizeof(MAILBOX_t) - off;
915
916 if (off % 4 || count % 4 || (unsigned long)buf % 4)
917 return -EINVAL;
918
919 if (off && count == 0)
920 return 0;
921
922 spin_lock_irq(phba->host->host_lock);
923
924 if (off == 0 &&
925 phba->sysfs_mbox.state == SMBOX_WRITING &&
926 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
927
928 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
929 /* Offline only */
930 case MBX_WRITE_NV:
931 case MBX_INIT_LINK:
932 case MBX_DOWN_LINK:
933 case MBX_CONFIG_LINK:
934 case MBX_CONFIG_RING:
935 case MBX_RESET_RING:
936 case MBX_UNREG_LOGIN:
937 case MBX_CLEAR_LA:
938 case MBX_DUMP_CONTEXT:
939 case MBX_RUN_DIAGS:
940 case MBX_RESTART:
941 case MBX_FLASH_WR_ULA:
942 case MBX_SET_MASK:
943 case MBX_SET_SLIM:
944 case MBX_SET_DEBUG:
945 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
946 printk(KERN_WARNING "mbox_read:Command 0x%x "
947 "is illegal in on-line state\n",
948 phba->sysfs_mbox.mbox->mb.mbxCommand);
949 sysfs_mbox_idle(phba);
950 spin_unlock_irq(phba->host->host_lock);
951 return -EPERM;
952 }
953 case MBX_LOAD_SM:
954 case MBX_READ_NV:
955 case MBX_READ_CONFIG:
956 case MBX_READ_RCONFIG:
957 case MBX_READ_STATUS:
958 case MBX_READ_XRI:
959 case MBX_READ_REV:
960 case MBX_READ_LNK_STAT:
961 case MBX_DUMP_MEMORY:
962 case MBX_DOWN_LOAD:
963 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500964 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -0500965 case MBX_LOAD_AREA:
966 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500967 case MBX_BEACON:
968 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -0500969 break;
970 case MBX_READ_SPARM64:
971 case MBX_READ_LA:
972 case MBX_READ_LA64:
973 case MBX_REG_LOGIN:
974 case MBX_REG_LOGIN64:
975 case MBX_CONFIG_PORT:
976 case MBX_RUN_BIU_DIAG:
977 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
978 phba->sysfs_mbox.mbox->mb.mbxCommand);
979 sysfs_mbox_idle(phba);
980 spin_unlock_irq(phba->host->host_lock);
981 return -EPERM;
982 default:
983 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
984 phba->sysfs_mbox.mbox->mb.mbxCommand);
985 sysfs_mbox_idle(phba);
986 spin_unlock_irq(phba->host->host_lock);
987 return -EPERM;
988 }
989
990 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
991 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
992
993 spin_unlock_irq(phba->host->host_lock);
994 rc = lpfc_sli_issue_mbox (phba,
995 phba->sysfs_mbox.mbox,
996 MBX_POLL);
997 spin_lock_irq(phba->host->host_lock);
998
999 } else {
1000 spin_unlock_irq(phba->host->host_lock);
1001 rc = lpfc_sli_issue_mbox_wait (phba,
1002 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001003 lpfc_mbox_tmo_val(phba,
1004 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
dea31012005-04-17 16:05:31 -05001005 spin_lock_irq(phba->host->host_lock);
1006 }
1007
1008 if (rc != MBX_SUCCESS) {
1009 sysfs_mbox_idle(phba);
1010 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001011 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001012 }
1013 phba->sysfs_mbox.state = SMBOX_READING;
1014 }
1015 else if (phba->sysfs_mbox.offset != off ||
1016 phba->sysfs_mbox.state != SMBOX_READING) {
1017 printk(KERN_WARNING "mbox_read: Bad State\n");
1018 sysfs_mbox_idle(phba);
1019 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001020 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001021 }
1022
1023 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1024
1025 phba->sysfs_mbox.offset = off + count;
1026
1027 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1028 sysfs_mbox_idle(phba);
1029
1030 spin_unlock_irq(phba->host->host_lock);
1031
1032 return count;
1033}
1034
1035static struct bin_attribute sysfs_mbox_attr = {
1036 .attr = {
1037 .name = "mbox",
1038 .mode = S_IRUSR | S_IWUSR,
1039 .owner = THIS_MODULE,
1040 },
1041 .size = sizeof(MAILBOX_t),
1042 .read = sysfs_mbox_read,
1043 .write = sysfs_mbox_write,
1044};
1045
1046int
1047lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1048{
1049 struct Scsi_Host *host = phba->host;
1050 int error;
1051
1052 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1053 &sysfs_ctlreg_attr);
1054 if (error)
1055 goto out;
1056
1057 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1058 &sysfs_mbox_attr);
1059 if (error)
1060 goto out_remove_ctlreg_attr;
1061
1062 return 0;
1063out_remove_ctlreg_attr:
1064 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1065out:
1066 return error;
1067}
1068
1069void
1070lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1071{
1072 struct Scsi_Host *host = phba->host;
1073
1074 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1075 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1076}
1077
1078
1079/*
1080 * Dynamic FC Host Attributes Support
1081 */
1082
1083static void
1084lpfc_get_host_port_id(struct Scsi_Host *shost)
1085{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001086 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001087 /* note: fc_myDID already in cpu endianness */
1088 fc_host_port_id(shost) = phba->fc_myDID;
1089}
1090
1091static void
1092lpfc_get_host_port_type(struct Scsi_Host *shost)
1093{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001094 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001095
1096 spin_lock_irq(shost->host_lock);
1097
1098 if (phba->hba_state == LPFC_HBA_READY) {
1099 if (phba->fc_topology == TOPOLOGY_LOOP) {
1100 if (phba->fc_flag & FC_PUBLIC_LOOP)
1101 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1102 else
1103 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1104 } else {
1105 if (phba->fc_flag & FC_FABRIC)
1106 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1107 else
1108 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1109 }
1110 } else
1111 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1112
1113 spin_unlock_irq(shost->host_lock);
1114}
1115
1116static void
1117lpfc_get_host_port_state(struct Scsi_Host *shost)
1118{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001119 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001120
1121 spin_lock_irq(shost->host_lock);
1122
1123 if (phba->fc_flag & FC_OFFLINE_MODE)
1124 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1125 else {
1126 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001127 case LPFC_STATE_UNKNOWN:
1128 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001129 case LPFC_INIT_START:
1130 case LPFC_INIT_MBX_CMDS:
1131 case LPFC_LINK_DOWN:
1132 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1133 break;
1134 case LPFC_LINK_UP:
1135 case LPFC_LOCAL_CFG_LINK:
1136 case LPFC_FLOGI:
1137 case LPFC_FABRIC_CFG_LINK:
1138 case LPFC_NS_REG:
1139 case LPFC_NS_QRY:
1140 case LPFC_BUILD_DISC_LIST:
1141 case LPFC_DISC_AUTH:
1142 case LPFC_CLEAR_LA:
1143 case LPFC_HBA_READY:
1144 /* Links up, beyond this port_type reports state */
1145 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1146 break;
1147 case LPFC_HBA_ERROR:
1148 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1149 break;
1150 default:
1151 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1152 break;
1153 }
1154 }
1155
1156 spin_unlock_irq(shost->host_lock);
1157}
1158
1159static void
1160lpfc_get_host_speed(struct Scsi_Host *shost)
1161{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001162 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001163
1164 spin_lock_irq(shost->host_lock);
1165
1166 if (phba->hba_state == LPFC_HBA_READY) {
1167 switch(phba->fc_linkspeed) {
1168 case LA_1GHZ_LINK:
1169 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1170 break;
1171 case LA_2GHZ_LINK:
1172 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1173 break;
1174 case LA_4GHZ_LINK:
1175 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1176 break;
1177 default:
1178 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1179 break;
1180 }
1181 }
1182
1183 spin_unlock_irq(shost->host_lock);
1184}
1185
1186static void
1187lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1188{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001189 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001190 u64 node_name;
dea31012005-04-17 16:05:31 -05001191
1192 spin_lock_irq(shost->host_lock);
1193
1194 if ((phba->fc_flag & FC_FABRIC) ||
1195 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1196 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001197 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001198 else
1199 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001200 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001201
1202 spin_unlock_irq(shost->host_lock);
1203
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001204 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001205}
1206
1207
1208static struct fc_host_statistics *
1209lpfc_get_stats(struct Scsi_Host *shost)
1210{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001211 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001212 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001213 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04001214 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05001215 LPFC_MBOXQ_t *pmboxq;
1216 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04001217 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001218 int rc = 0;
dea31012005-04-17 16:05:31 -05001219
1220 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1221 if (!pmboxq)
1222 return NULL;
1223 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1224
1225 pmb = &pmboxq->mb;
1226 pmb->mbxCommand = MBX_READ_STATUS;
1227 pmb->mbxOwner = OWN_HOST;
1228 pmboxq->context1 = NULL;
1229
1230 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001231 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001232 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001233 else
dea31012005-04-17 16:05:31 -05001234 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1235
1236 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001237 if (rc == MBX_TIMEOUT)
1238 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1239 else
1240 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001241 return NULL;
1242 }
1243
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001244 memset(hs, 0, sizeof (struct fc_host_statistics));
1245
dea31012005-04-17 16:05:31 -05001246 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1247 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1248 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1249 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1250
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001251 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001252 pmb->mbxCommand = MBX_READ_LNK_STAT;
1253 pmb->mbxOwner = OWN_HOST;
1254 pmboxq->context1 = NULL;
1255
1256 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001257 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001258 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001259 else
dea31012005-04-17 16:05:31 -05001260 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1261
1262 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001263 if (rc == MBX_TIMEOUT)
1264 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1265 else
1266 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001267 return NULL;
1268 }
1269
1270 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1271 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1272 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1273 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1274 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1275 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1276 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1277
James Smart64ba8812006-08-02 15:24:34 -04001278 hs->link_failure_count -= lso->link_failure_count;
1279 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1280 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1281 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1282 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1283 hs->invalid_crc_count -= lso->invalid_crc_count;
1284 hs->error_frames -= lso->error_frames;
1285
dea31012005-04-17 16:05:31 -05001286 if (phba->fc_topology == TOPOLOGY_LOOP) {
1287 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001288 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001289 hs->nos_count = -1;
1290 } else {
1291 hs->lip_count = -1;
1292 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001293 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001294 }
1295
1296 hs->dumped_frames = -1;
1297
James Smart64ba8812006-08-02 15:24:34 -04001298 seconds = get_seconds();
1299 if (seconds < psli->stats_start)
1300 hs->seconds_since_last_reset = seconds +
1301 ((unsigned long)-1 - psli->stats_start);
1302 else
1303 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05001304
1305 return hs;
1306}
1307
James Smart64ba8812006-08-02 15:24:34 -04001308static void
1309lpfc_reset_stats(struct Scsi_Host *shost)
1310{
1311 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1312 struct lpfc_sli *psli = &phba->sli;
1313 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1314 LPFC_MBOXQ_t *pmboxq;
1315 MAILBOX_t *pmb;
1316 int rc = 0;
1317
1318 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1319 if (!pmboxq)
1320 return;
1321 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1322
1323 pmb = &pmboxq->mb;
1324 pmb->mbxCommand = MBX_READ_STATUS;
1325 pmb->mbxOwner = OWN_HOST;
1326 pmb->un.varWords[0] = 0x1; /* reset request */
1327 pmboxq->context1 = NULL;
1328
1329 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1330 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1331 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1332 else
1333 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1334
1335 if (rc != MBX_SUCCESS) {
1336 if (rc == MBX_TIMEOUT)
1337 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1338 else
1339 mempool_free(pmboxq, phba->mbox_mem_pool);
1340 return;
1341 }
1342
1343 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1344 pmb->mbxCommand = MBX_READ_LNK_STAT;
1345 pmb->mbxOwner = OWN_HOST;
1346 pmboxq->context1 = NULL;
1347
1348 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1349 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1350 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1351 else
1352 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1353
1354 if (rc != MBX_SUCCESS) {
1355 if (rc == MBX_TIMEOUT)
1356 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1357 else
1358 mempool_free( pmboxq, phba->mbox_mem_pool);
1359 return;
1360 }
1361
1362 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1363 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1364 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1365 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1366 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1367 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1368 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1369 lso->link_events = (phba->fc_eventTag >> 1);
1370
1371 psli->stats_start = get_seconds();
1372
1373 return;
1374}
dea31012005-04-17 16:05:31 -05001375
1376/*
1377 * The LPFC driver treats linkdown handling as target loss events so there
1378 * are no sysfs handlers for link_down_tmo.
1379 */
1380static void
1381lpfc_get_starget_port_id(struct scsi_target *starget)
1382{
1383 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001384 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea31012005-04-17 16:05:31 -05001385 uint32_t did = -1;
1386 struct lpfc_nodelist *ndlp = NULL;
1387
1388 spin_lock_irq(shost->host_lock);
1389 /* Search the mapped list for this target ID */
1390 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1391 if (starget->id == ndlp->nlp_sid) {
1392 did = ndlp->nlp_DID;
1393 break;
1394 }
1395 }
1396 spin_unlock_irq(shost->host_lock);
1397
1398 fc_starget_port_id(starget) = did;
1399}
1400
1401static void
1402lpfc_get_starget_node_name(struct scsi_target *starget)
1403{
1404 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001405 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001406 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001407 struct lpfc_nodelist *ndlp = NULL;
1408
1409 spin_lock_irq(shost->host_lock);
1410 /* Search the mapped list for this target ID */
1411 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1412 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001413 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001414 break;
1415 }
1416 }
1417 spin_unlock_irq(shost->host_lock);
1418
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001419 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001420}
1421
1422static void
1423lpfc_get_starget_port_name(struct scsi_target *starget)
1424{
1425 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001426 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001427 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001428 struct lpfc_nodelist *ndlp = NULL;
1429
1430 spin_lock_irq(shost->host_lock);
1431 /* Search the mapped list for this target ID */
1432 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1433 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001434 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001435 break;
1436 }
1437 }
1438 spin_unlock_irq(shost->host_lock);
1439
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001440 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001441}
1442
1443static void
1444lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1445{
1446 /*
1447 * Return the driver's global value for device loss timeout plus
1448 * five seconds to allow the driver's nodev timer to run.
1449 */
1450 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1451}
1452
1453static void
1454lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1455{
1456 /*
1457 * The driver doesn't have a per-target timeout setting. Set
1458 * this value globally. lpfc_nodev_tmo should be greater then 0.
1459 */
1460 if (timeout)
1461 lpfc_nodev_tmo = timeout;
1462 else
1463 lpfc_nodev_tmo = 1;
1464 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1465}
1466
1467
1468#define lpfc_rport_show_function(field, format_string, sz, cast) \
1469static ssize_t \
1470lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1471{ \
1472 struct fc_rport *rport = transport_class_to_rport(cdev); \
1473 struct lpfc_rport_data *rdata = rport->hostdata; \
1474 return snprintf(buf, sz, format_string, \
1475 (rdata->target) ? cast rdata->target->field : 0); \
1476}
1477
1478#define lpfc_rport_rd_attr(field, format_string, sz) \
1479 lpfc_rport_show_function(field, format_string, sz, ) \
1480static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1481
1482
1483struct fc_function_template lpfc_transport_functions = {
1484 /* fixed attributes the driver supports */
1485 .show_host_node_name = 1,
1486 .show_host_port_name = 1,
1487 .show_host_supported_classes = 1,
1488 .show_host_supported_fc4s = 1,
1489 .show_host_symbolic_name = 1,
1490 .show_host_supported_speeds = 1,
1491 .show_host_maxframe_size = 1,
1492
1493 /* dynamic attributes the driver supports */
1494 .get_host_port_id = lpfc_get_host_port_id,
1495 .show_host_port_id = 1,
1496
1497 .get_host_port_type = lpfc_get_host_port_type,
1498 .show_host_port_type = 1,
1499
1500 .get_host_port_state = lpfc_get_host_port_state,
1501 .show_host_port_state = 1,
1502
1503 /* active_fc4s is shown but doesn't change (thus no get function) */
1504 .show_host_active_fc4s = 1,
1505
1506 .get_host_speed = lpfc_get_host_speed,
1507 .show_host_speed = 1,
1508
1509 .get_host_fabric_name = lpfc_get_host_fabric_name,
1510 .show_host_fabric_name = 1,
1511
1512 /*
1513 * The LPFC driver treats linkdown handling as target loss events
1514 * so there are no sysfs handlers for link_down_tmo.
1515 */
1516
1517 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04001518 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05001519
1520 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1521 .show_rport_maxframe_size = 1,
1522 .show_rport_supported_classes = 1,
1523
1524 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1525 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1526 .show_rport_dev_loss_tmo = 1,
1527
1528 .get_starget_port_id = lpfc_get_starget_port_id,
1529 .show_starget_port_id = 1,
1530
1531 .get_starget_node_name = lpfc_get_starget_node_name,
1532 .show_starget_node_name = 1,
1533
1534 .get_starget_port_name = lpfc_get_starget_port_name,
1535 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001536
1537 .issue_fc_host_lip = lpfc_issue_lip,
dea31012005-04-17 16:05:31 -05001538};
1539
1540void
1541lpfc_get_cfgparam(struct lpfc_hba *phba)
1542{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001543 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1544 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1545 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001546 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001547 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1548 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1549 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1550 lpfc_ack0_init(phba, lpfc_ack0);
1551 lpfc_topology_init(phba, lpfc_topology);
1552 lpfc_scan_down_init(phba, lpfc_scan_down);
1553 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1554 lpfc_link_speed_init(phba, lpfc_link_speed);
1555 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1556 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1557 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001558 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1559
1560 phba->cfg_poll = lpfc_poll;
dea31012005-04-17 16:05:31 -05001561
1562 /*
1563 * The total number of segments is the configuration value plus 2
1564 * since the IOCB need a command and response bde.
1565 */
1566 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1567
1568 /*
1569 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1570 * used to create the sg_dma_buf_pool must be dynamically calculated
1571 */
1572 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1573 sizeof(struct fcp_rsp) +
1574 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1575
1576 switch (phba->pcidev->device) {
1577 case PCI_DEVICE_ID_LP101:
1578 case PCI_DEVICE_ID_BSMB:
1579 case PCI_DEVICE_ID_ZSMB:
1580 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1581 break;
1582 case PCI_DEVICE_ID_RFLY:
1583 case PCI_DEVICE_ID_PFLY:
1584 case PCI_DEVICE_ID_BMID:
1585 case PCI_DEVICE_ID_ZMID:
1586 case PCI_DEVICE_ID_TFLY:
1587 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1588 break;
1589 default:
1590 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1591 }
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001592
1593 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1594 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1595
dea31012005-04-17 16:05:31 -05001596 return;
1597}