blob: 5dfda9778c80b009b03ca242d23c0d9614099631 [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. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
32
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_logmsg.h"
39#include "lpfc_version.h"
40#include "lpfc_compat.h"
41#include "lpfc_crtn.h"
42
James Smartc01f3202006-08-18 17:47:08 -040043#define LPFC_DEF_DEVLOSS_TMO 30
44#define LPFC_MIN_DEVLOSS_TMO 1
45#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050046
47static void
48lpfc_jedec_to_ascii(int incr, char hdw[])
49{
50 int i, j;
51 for (i = 0; i < 8; i++) {
52 j = (incr & 0xf);
53 if (j <= 9)
54 hdw[7 - i] = 0x30 + j;
55 else
56 hdw[7 - i] = 0x61 + j - 10;
57 incr = (incr >> 4);
58 }
59 hdw[8] = 0;
60 return;
61}
62
63static ssize_t
64lpfc_drvr_version_show(struct class_device *cdev, char *buf)
65{
66 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
67}
68
69static ssize_t
70management_version_show(struct class_device *cdev, char *buf)
71{
72 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
73}
74
75static ssize_t
76lpfc_info_show(struct class_device *cdev, char *buf)
77{
78 struct Scsi_Host *host = class_to_shost(cdev);
79 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
80}
81
82static ssize_t
83lpfc_serialnum_show(struct class_device *cdev, char *buf)
84{
85 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050086 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050087 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
88}
89
90static ssize_t
91lpfc_modeldesc_show(struct class_device *cdev, char *buf)
92{
93 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050094 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050095 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
96}
97
98static ssize_t
99lpfc_modelname_show(struct class_device *cdev, char *buf)
100{
101 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500102 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500103 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
104}
105
106static ssize_t
107lpfc_programtype_show(struct class_device *cdev, char *buf)
108{
109 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500110 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
112}
113
114static ssize_t
115lpfc_portnum_show(struct class_device *cdev, char *buf)
116{
117 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500118 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500119 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
120}
121
122static ssize_t
123lpfc_fwrev_show(struct class_device *cdev, char *buf)
124{
125 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500126 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500127 char fwrev[32];
128 lpfc_decode_firmware_rev(phba, fwrev, 1);
129 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
130}
131
132static ssize_t
133lpfc_hdw_show(struct class_device *cdev, char *buf)
134{
135 char hdw[9];
136 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500137 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500138 lpfc_vpd_t *vp = &phba->vpd;
139 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
140 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
141}
142static ssize_t
143lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
144{
145 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500146 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500147 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
148}
149static ssize_t
150lpfc_state_show(struct class_device *cdev, char *buf)
151{
152 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500153 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500154 int len = 0;
155 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500156 case LPFC_STATE_UNKNOWN:
157 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500158 case LPFC_INIT_START:
159 case LPFC_INIT_MBX_CMDS:
160 case LPFC_LINK_DOWN:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
162 break;
163 case LPFC_LINK_UP:
164 case LPFC_LOCAL_CFG_LINK:
165 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
166 break;
167 case LPFC_FLOGI:
168 case LPFC_FABRIC_CFG_LINK:
169 case LPFC_NS_REG:
170 case LPFC_NS_QRY:
171 case LPFC_BUILD_DISC_LIST:
172 case LPFC_DISC_AUTH:
173 case LPFC_CLEAR_LA:
174 len += snprintf(buf + len, PAGE_SIZE-len,
175 "Link Up - Discovery\n");
176 break;
177 case LPFC_HBA_READY:
178 len += snprintf(buf + len, PAGE_SIZE-len,
179 "Link Up - Ready:\n");
180 if (phba->fc_topology == TOPOLOGY_LOOP) {
181 if (phba->fc_flag & FC_PUBLIC_LOOP)
182 len += snprintf(buf + len, PAGE_SIZE-len,
183 " Public Loop\n");
184 else
185 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Private Loop\n");
187 } else {
188 if (phba->fc_flag & FC_FABRIC)
189 len += snprintf(buf + len, PAGE_SIZE-len,
190 " Fabric\n");
191 else
192 len += snprintf(buf + len, PAGE_SIZE-len,
193 " Point-2-Point\n");
194 }
195 }
196 return len;
197}
198
199static ssize_t
200lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
201{
202 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500203 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500204 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
205 phba->fc_unmap_cnt);
206}
207
208
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700209static int
210lpfc_issue_lip(struct Scsi_Host *host)
dea31012005-04-17 16:05:31 -0500211{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500212 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea31012005-04-17 16:05:31 -0500213 LPFC_MBOXQ_t *pmboxq;
214 int mbxstatus = MBXERR_ERROR;
215
dea31012005-04-17 16:05:31 -0500216 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James Smart46fa3112007-04-25 09:51:45 -0400217 (phba->fc_flag & FC_BLOCK_MGMT_IO) ||
dea31012005-04-17 16:05:31 -0500218 (phba->hba_state != LPFC_HBA_READY))
219 return -EPERM;
220
221 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
222
223 if (!pmboxq)
224 return -ENOMEM;
225
226 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400227 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
228 pmboxq->mb.mbxOwner = OWN_HOST;
229
James Smart33ccf8d2006-08-17 11:57:58 -0400230 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500231
James Smart4db621e2006-07-06 15:49:49 -0400232 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
233 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
234 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
235 phba->cfg_link_speed);
236 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
237 phba->fc_ratov * 2);
238 }
239
James Smart5b8bd0c2007-04-25 09:52:49 -0400240 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -0500241 if (mbxstatus == MBX_TIMEOUT)
242 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
243 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400244 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500245
246 if (mbxstatus == MBXERR_ERROR)
247 return -EIO;
248
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700249 return 0;
dea31012005-04-17 16:05:31 -0500250}
251
James Smart40496f02006-07-06 15:50:22 -0400252static int
James Smart46fa3112007-04-25 09:51:45 -0400253lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
254{
255 struct completion online_compl;
256 struct lpfc_sli_ring *pring;
257 struct lpfc_sli *psli;
258 int status = 0;
259 int cnt = 0;
260 int i;
261
262 init_completion(&online_compl);
263 lpfc_workq_post_event(phba, &status, &online_compl,
264 LPFC_EVT_OFFLINE_PREP);
265 wait_for_completion(&online_compl);
266
267 if (status != 0)
268 return -EIO;
269
270 psli = &phba->sli;
271
272 for (i = 0; i < psli->num_rings; i++) {
273 pring = &psli->ring[i];
274 /* The linkdown event takes 30 seconds to timeout. */
275 while (pring->txcmplq_cnt) {
276 msleep(10);
277 if (cnt++ > 3000) {
278 lpfc_printf_log(phba,
279 KERN_WARNING, LOG_INIT,
280 "%d:0466 Outstanding IO when "
281 "bringing Adapter offline\n",
282 phba->brd_no);
283 break;
284 }
285 }
286 }
287
288 init_completion(&online_compl);
289 lpfc_workq_post_event(phba, &status, &online_compl, type);
290 wait_for_completion(&online_compl);
291
292 if (status != 0)
293 return -EIO;
294
295 return 0;
296}
297
298static int
James Smart40496f02006-07-06 15:50:22 -0400299lpfc_selective_reset(struct lpfc_hba *phba)
300{
301 struct completion online_compl;
302 int status = 0;
303
James Smart46fa3112007-04-25 09:51:45 -0400304 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400305
306 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400307 return status;
James Smart40496f02006-07-06 15:50:22 -0400308
309 init_completion(&online_compl);
310 lpfc_workq_post_event(phba, &status, &online_compl,
311 LPFC_EVT_ONLINE);
312 wait_for_completion(&online_compl);
313
314 if (status != 0)
315 return -EIO;
316
317 return 0;
318}
319
320static ssize_t
321lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
322{
323 struct Scsi_Host *host = class_to_shost(cdev);
324 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
325 int status = -EINVAL;
326
327 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
328 status = lpfc_selective_reset(phba);
329
330 if (status == 0)
331 return strlen(buf);
332 else
333 return status;
334}
335
dea31012005-04-17 16:05:31 -0500336static ssize_t
337lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
338{
339 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500340 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500341 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
342}
343
344static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500345lpfc_board_mode_show(struct class_device *cdev, char *buf)
346{
347 struct Scsi_Host *host = class_to_shost(cdev);
348 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
349 char * state;
350
351 if (phba->hba_state == LPFC_HBA_ERROR)
352 state = "error";
353 else if (phba->hba_state == LPFC_WARM_START)
354 state = "warm start";
355 else if (phba->hba_state == LPFC_INIT_START)
356 state = "offline";
357 else
358 state = "online";
359
360 return snprintf(buf, PAGE_SIZE, "%s\n", state);
361}
362
363static ssize_t
364lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
365{
366 struct Scsi_Host *host = class_to_shost(cdev);
367 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
368 struct completion online_compl;
369 int status=0;
370
371 init_completion(&online_compl);
372
James Smart46fa3112007-04-25 09:51:45 -0400373 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500374 lpfc_workq_post_event(phba, &status, &online_compl,
375 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400376 wait_for_completion(&online_compl);
377 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
378 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500379 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400380 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
381 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
382 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500383 else
384 return -EINVAL;
385
Jamie Wellnitz41415862006-02-28 19:25:27 -0500386 if (!status)
387 return strlen(buf);
388 else
389 return -EIO;
390}
391
392static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500393lpfc_poll_show(struct class_device *cdev, char *buf)
394{
395 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500396 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500397
398 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
399}
400
401static ssize_t
402lpfc_poll_store(struct class_device *cdev, const char *buf,
403 size_t count)
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;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500407 uint32_t creg_val;
408 uint32_t old_val;
409 int val=0;
410
411 if (!isdigit(buf[0]))
412 return -EINVAL;
413
414 if (sscanf(buf, "%i", &val) != 1)
415 return -EINVAL;
416
417 if ((val & 0x3) != val)
418 return -EINVAL;
419
420 spin_lock_irq(phba->host->host_lock);
421
422 old_val = phba->cfg_poll;
423
424 if (val & ENABLE_FCP_RING_POLLING) {
425 if ((val & DISABLE_FCP_RING_INT) &&
426 !(old_val & DISABLE_FCP_RING_INT)) {
427 creg_val = readl(phba->HCregaddr);
428 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
429 writel(creg_val, phba->HCregaddr);
430 readl(phba->HCregaddr); /* flush */
431
432 lpfc_poll_start_timer(phba);
433 }
434 } else if (val != 0x0) {
435 spin_unlock_irq(phba->host->host_lock);
436 return -EINVAL;
437 }
438
439 if (!(val & DISABLE_FCP_RING_INT) &&
440 (old_val & DISABLE_FCP_RING_INT))
441 {
442 spin_unlock_irq(phba->host->host_lock);
443 del_timer(&phba->fcp_poll_timer);
444 spin_lock_irq(phba->host->host_lock);
445 creg_val = readl(phba->HCregaddr);
446 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
447 writel(creg_val, phba->HCregaddr);
448 readl(phba->HCregaddr); /* flush */
449 }
450
451 phba->cfg_poll = val;
452
453 spin_unlock_irq(phba->host->host_lock);
454
455 return strlen(buf);
456}
dea31012005-04-17 16:05:31 -0500457
458#define lpfc_param_show(attr) \
459static ssize_t \
460lpfc_##attr##_show(struct class_device *cdev, char *buf) \
461{ \
462 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500463 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea31012005-04-17 16:05:31 -0500464 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400465 val = phba->cfg_##attr;\
466 return snprintf(buf, PAGE_SIZE, "%d\n",\
467 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500468}
469
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400470#define lpfc_param_hex_show(attr) \
471static ssize_t \
472lpfc_##attr##_show(struct class_device *cdev, char *buf) \
473{ \
474 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500475 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400476 int val = 0;\
477 val = phba->cfg_##attr;\
478 return snprintf(buf, PAGE_SIZE, "%#x\n",\
479 phba->cfg_##attr);\
480}
481
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400482#define lpfc_param_init(attr, default, minval, maxval) \
483static int \
484lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
485{ \
486 if (val >= minval && val <= maxval) {\
487 phba->cfg_##attr = val;\
488 return 0;\
489 }\
490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
491 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
492 "allowed range is ["#minval", "#maxval"]\n", \
493 phba->brd_no, val); \
494 phba->cfg_##attr = default;\
495 return -EINVAL;\
496}
497
498#define lpfc_param_set(attr, default, minval, maxval) \
499static int \
500lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
501{ \
502 if (val >= minval && val <= maxval) {\
503 phba->cfg_##attr = val;\
504 return 0;\
505 }\
506 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
507 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
508 "allowed range is ["#minval", "#maxval"]\n", \
509 phba->brd_no, val); \
510 return -EINVAL;\
511}
512
513#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500514static ssize_t \
515lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
516{ \
517 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500518 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400519 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400520 if (!isdigit(buf[0]))\
521 return -EINVAL;\
522 if (sscanf(buf, "%i", &val) != 1)\
523 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400524 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400525 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400526 else \
527 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500528}
529
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400530#define LPFC_ATTR(name, defval, minval, maxval, desc) \
531static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500532module_param(lpfc_##name, int, 0);\
533MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400534lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500535
536#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
537static int lpfc_##name = defval;\
538module_param(lpfc_##name, int, 0);\
539MODULE_PARM_DESC(lpfc_##name, desc);\
540lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400541lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500542static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
543
544#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
545static int lpfc_##name = defval;\
546module_param(lpfc_##name, int, 0);\
547MODULE_PARM_DESC(lpfc_##name, desc);\
548lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400549lpfc_param_init(name, defval, minval, maxval)\
550lpfc_param_set(name, defval, minval, maxval)\
551lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500552static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
553 lpfc_##name##_show, lpfc_##name##_store)
554
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400555#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
556static int lpfc_##name = defval;\
557module_param(lpfc_##name, int, 0);\
558MODULE_PARM_DESC(lpfc_##name, desc);\
559lpfc_param_hex_show(name)\
560lpfc_param_init(name, defval, minval, maxval)\
561static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
562
563#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
564static int lpfc_##name = defval;\
565module_param(lpfc_##name, int, 0);\
566MODULE_PARM_DESC(lpfc_##name, desc);\
567lpfc_param_hex_show(name)\
568lpfc_param_init(name, defval, minval, maxval)\
569lpfc_param_set(name, defval, minval, maxval)\
570lpfc_param_store(name)\
571static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
572 lpfc_##name##_show, lpfc_##name##_store)
573
dea31012005-04-17 16:05:31 -0500574static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
575static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
576static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
577static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
578static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
579static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
580static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
581static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
582static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
583static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
584 lpfc_option_rom_version_show, NULL);
585static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
586 lpfc_num_discovered_ports_show, NULL);
587static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
588static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
589 NULL);
590static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
591 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500592static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
593 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400594static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea31012005-04-17 16:05:31 -0500595
James Smartc3f28af2006-08-18 17:47:18 -0400596
James Smarta12e07b2006-12-02 13:35:30 -0500597static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400598
599static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500600lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400601 size_t count)
602{
603 struct Scsi_Host *host = class_to_shost(cdev);
604 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
605 unsigned int cnt = count;
606
607 /*
608 * We're doing a simple sanity check for soft_wwpn setting.
609 * We require that the user write a specific key to enable
610 * the soft_wwpn attribute to be settable. Once the attribute
611 * is written, the enable key resets. If further updates are
612 * desired, the key must be written again to re-enable the
613 * attribute.
614 *
615 * The "key" is not secret - it is a hardcoded string shown
616 * here. The intent is to protect against the random user or
617 * application that is just writing attributes.
618 */
619
620 /* count may include a LF at end of string */
621 if (buf[cnt-1] == '\n')
622 cnt--;
623
James Smarta12e07b2006-12-02 13:35:30 -0500624 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
625 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400626 return -EINVAL;
627
James Smarta12e07b2006-12-02 13:35:30 -0500628 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400629 return count;
630}
James Smarta12e07b2006-12-02 13:35:30 -0500631static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
632 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400633
634static ssize_t
635lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
636{
637 struct Scsi_Host *host = class_to_shost(cdev);
638 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
Randy Dunlapafc071e2006-10-23 21:47:13 -0700639 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
640 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400641}
642
643
644static ssize_t
645lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
646{
647 struct Scsi_Host *host = class_to_shost(cdev);
648 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
649 struct completion online_compl;
650 int stat1=0, stat2=0;
651 unsigned int i, j, cnt=count;
652 u8 wwpn[8];
653
654 /* count may include a LF at end of string */
655 if (buf[cnt-1] == '\n')
656 cnt--;
657
James Smarta12e07b2006-12-02 13:35:30 -0500658 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400659 ((cnt == 17) && (*buf++ != 'x')) ||
660 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
661 return -EINVAL;
662
James Smarta12e07b2006-12-02 13:35:30 -0500663 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400664
665 memset(wwpn, 0, sizeof(wwpn));
666
667 /* Validate and store the new name */
668 for (i=0, j=0; i < 16; i++) {
669 if ((*buf >= 'a') && (*buf <= 'f'))
670 j = ((j << 4) | ((*buf++ -'a') + 10));
671 else if ((*buf >= 'A') && (*buf <= 'F'))
672 j = ((j << 4) | ((*buf++ -'A') + 10));
673 else if ((*buf >= '0') && (*buf <= '9'))
674 j = ((j << 4) | (*buf++ -'0'));
675 else
676 return -EINVAL;
677 if (i % 2) {
678 wwpn[i/2] = j & 0xff;
679 j = 0;
680 }
681 }
682 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
683 fc_host_port_name(host) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -0500684 if (phba->cfg_soft_wwnn)
685 fc_host_node_name(host) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -0400686
687 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
688 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
689
James Smart46fa3112007-04-25 09:51:45 -0400690 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -0400691 if (stat1)
692 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
693 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
694 "adapter - %d\n", phba->brd_no, stat1);
695
696 init_completion(&online_compl);
697 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
698 wait_for_completion(&online_compl);
699 if (stat2)
700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
701 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
702 "adapter - %d\n", phba->brd_no, stat2);
703
704 return (stat1 || stat2) ? -EIO : count;
705}
706static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
707 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
708
James Smarta12e07b2006-12-02 13:35:30 -0500709static ssize_t
710lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
711{
712 struct Scsi_Host *host = class_to_shost(cdev);
713 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
714 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
715 (unsigned long long)phba->cfg_soft_wwnn);
716}
717
718
719static ssize_t
720lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
721{
722 struct Scsi_Host *host = class_to_shost(cdev);
723 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
724 unsigned int i, j, cnt=count;
725 u8 wwnn[8];
726
727 /* count may include a LF at end of string */
728 if (buf[cnt-1] == '\n')
729 cnt--;
730
731 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
732 ((cnt == 17) && (*buf++ != 'x')) ||
733 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
734 return -EINVAL;
735
736 /*
737 * Allow wwnn to be set many times, as long as the enable is set.
738 * However, once the wwpn is set, everything locks.
739 */
740
741 memset(wwnn, 0, sizeof(wwnn));
742
743 /* Validate and store the new name */
744 for (i=0, j=0; i < 16; i++) {
745 if ((*buf >= 'a') && (*buf <= 'f'))
746 j = ((j << 4) | ((*buf++ -'a') + 10));
747 else if ((*buf >= 'A') && (*buf <= 'F'))
748 j = ((j << 4) | ((*buf++ -'A') + 10));
749 else if ((*buf >= '0') && (*buf <= '9'))
750 j = ((j << 4) | (*buf++ -'0'));
751 else
752 return -EINVAL;
753 if (i % 2) {
754 wwnn[i/2] = j & 0xff;
755 j = 0;
756 }
757 }
758 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
759
760 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
761 "lpfc%d: soft_wwnn set. Value will take effect upon "
762 "setting of the soft_wwpn\n", phba->brd_no);
763
764 return count;
765}
766static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
767 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
768
James Smartc3f28af2006-08-18 17:47:18 -0400769
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500770static int lpfc_poll = 0;
771module_param(lpfc_poll, int, 0);
772MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
773 " 0 - none,"
774 " 1 - poll with interrupts enabled"
775 " 3 - poll and disable FCP ring interrupts");
776
777static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
778 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500779
780/*
James Smartc01f3202006-08-18 17:47:08 -0400781# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
782# until the timer expires. Value range is [0,255]. Default value is 30.
783*/
784static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
785static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
786module_param(lpfc_nodev_tmo, int, 0);
787MODULE_PARM_DESC(lpfc_nodev_tmo,
788 "Seconds driver will hold I/O waiting "
789 "for a device to come back");
790static ssize_t
791lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
792{
793 struct Scsi_Host *host = class_to_shost(cdev);
794 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
795 int val = 0;
796 val = phba->cfg_devloss_tmo;
797 return snprintf(buf, PAGE_SIZE, "%d\n",
798 phba->cfg_devloss_tmo);
799}
800
801static int
802lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
803{
804 static int warned;
805 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
806 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
807 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
808 warned = 1;
809 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
810 "%d:0402 Ignoring nodev_tmo module "
811 "parameter because devloss_tmo is"
812 " set.\n",
813 phba->brd_no);
814 }
815 return 0;
816 }
817
818 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
819 phba->cfg_nodev_tmo = val;
820 phba->cfg_devloss_tmo = val;
821 return 0;
822 }
823 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
824 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
825 "allowed range is [%d, %d]\n",
826 phba->brd_no, val,
827 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
828 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
829 return -EINVAL;
830}
831
James Smart7054a602007-04-25 09:52:34 -0400832static void
833lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba)
834{
835 struct lpfc_nodelist *ndlp;
836
837 spin_lock_irq(phba->host->host_lock);
838 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp)
839 if (ndlp->rport)
840 ndlp->rport->dev_loss_tmo = phba->cfg_devloss_tmo;
841 spin_unlock_irq(phba->host->host_lock);
842}
843
James Smartc01f3202006-08-18 17:47:08 -0400844static int
845lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
846{
847 if (phba->dev_loss_tmo_changed ||
848 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
849 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
850 "%d:0401 Ignoring change to nodev_tmo "
851 "because devloss_tmo is set.\n",
852 phba->brd_no);
853 return 0;
854 }
855
856 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
857 phba->cfg_nodev_tmo = val;
858 phba->cfg_devloss_tmo = val;
James Smart7054a602007-04-25 09:52:34 -0400859 lpfc_update_rport_devloss_tmo(phba);
James Smartc01f3202006-08-18 17:47:08 -0400860 return 0;
861 }
862
863 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
864 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
865 "allowed range is [%d, %d]\n",
866 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
867 LPFC_MAX_DEVLOSS_TMO);
868 return -EINVAL;
869}
870
871lpfc_param_store(nodev_tmo)
872
873static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
874 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
875
876/*
877# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
878# disappear until the timer expires. Value range is [0,255]. Default
879# value is 30.
880*/
881module_param(lpfc_devloss_tmo, int, 0);
882MODULE_PARM_DESC(lpfc_devloss_tmo,
883 "Seconds driver will hold I/O waiting "
884 "for a device to come back");
885lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
886 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
887lpfc_param_show(devloss_tmo)
888static int
889lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
890{
891 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
892 phba->cfg_nodev_tmo = val;
893 phba->cfg_devloss_tmo = val;
894 phba->dev_loss_tmo_changed = 1;
James Smart7054a602007-04-25 09:52:34 -0400895 lpfc_update_rport_devloss_tmo(phba);
James Smartc01f3202006-08-18 17:47:08 -0400896 return 0;
897 }
898
899 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
900 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
901 " %d, allowed range is [%d, %d]\n",
902 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
903 LPFC_MAX_DEVLOSS_TMO);
904 return -EINVAL;
905}
906
907lpfc_param_store(devloss_tmo)
908static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
909 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
910
911/*
dea31012005-04-17 16:05:31 -0500912# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
913# deluged with LOTS of information.
914# You can set a bit mask to record specific types of verbose messages:
915#
916# LOG_ELS 0x1 ELS events
917# LOG_DISCOVERY 0x2 Link discovery events
918# LOG_MBOX 0x4 Mailbox events
919# LOG_INIT 0x8 Initialization events
920# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -0500921# LOG_FCP 0x40 FCP traffic history
922# LOG_NODE 0x80 Node table events
923# LOG_MISC 0x400 Miscellaneous events
924# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -0500925# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -0500926# LOG_LIBDFC 0x2000 LIBDFC events
927# LOG_ALL_MSG 0xffff LOG all messages
928*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400929LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500930
931/*
932# lun_queue_depth: This parameter is used to limit the number of outstanding
933# commands per FCP LUN. Value range is [1,128]. Default value is 30.
934*/
935LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
936 "Max number of FCP commands we can queue to a specific LUN");
937
938/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500939# hba_queue_depth: This parameter is used to limit the number of outstanding
940# commands per lpfc HBA. Value range is [32,8192]. If this parameter
941# value is greater than the maximum number of exchanges supported by the HBA,
942# then maximum number of exchanges supported by the HBA is used to determine
943# the hba_queue_depth.
944*/
945LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
946 "Max number of FCP commands we can queue to a lpfc HBA");
947
948/*
dea31012005-04-17 16:05:31 -0500949# Some disk devices have a "select ID" or "select Target" capability.
950# From a protocol standpoint "select ID" usually means select the
951# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
952# annex" which contains a table that maps a "select ID" (a number
953# between 0 and 7F) to an ALPA. By default, for compatibility with
954# older drivers, the lpfc driver scans this table from low ALPA to high
955# ALPA.
956#
957# Turning on the scan-down variable (on = 1, off = 0) will
958# cause the lpfc driver to use an inverted table, effectively
959# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
960#
961# (Note: This "select ID" functionality is a LOOP ONLY characteristic
962# and will not work across a fabric. Also this parameter will take
963# effect only in the case when ALPA map is not available.)
964*/
965LPFC_ATTR_R(scan_down, 1, 0, 1,
966 "Start scanning for devices from highest ALPA to lowest");
967
968/*
dea31012005-04-17 16:05:31 -0500969# lpfc_topology: link topology for init link
970# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500971# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500972# 0x02 = attempt point-to-point mode only
973# 0x04 = attempt loop mode only
974# 0x06 = attempt point-to-point mode then loop
975# Set point-to-point mode if you want to run as an N_Port.
976# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
977# Default value is 0.
978*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500979LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500980
981/*
982# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
983# connection.
984# 0 = auto select (default)
985# 1 = 1 Gigabaud
986# 2 = 2 Gigabaud
987# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -0400988# 8 = 8 Gigabaud
989# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -0500990*/
James Smartb87eab32007-04-25 09:53:28 -0400991LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -0500992
993/*
994# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
995# Value range is [2,3]. Default value is 3.
996*/
997LPFC_ATTR_R(fcp_class, 3, 2, 3,
998 "Select Fibre Channel class of service for FCP sequences");
999
1000/*
1001# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1002# is [0,1]. Default value is 0.
1003*/
1004LPFC_ATTR_RW(use_adisc, 0, 0, 1,
1005 "Use ADISC on rediscovery to authenticate FCP devices");
1006
1007/*
1008# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1009# range is [0,1]. Default value is 0.
1010*/
1011LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1012
1013/*
1014# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1015# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001016# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001017# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1018# cr_delay is set to 0.
1019*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001020LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001021 "interrupt response is generated");
1022
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001023LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001024 "interrupt response is generated");
1025
1026/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001027# lpfc_multi_ring_support: Determines how many rings to spread available
1028# cmd/rsp IOCB entries across.
1029# Value range is [1,2]. Default value is 1.
1030*/
1031LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1032 "SLI rings to spread IOCB entries across");
1033
1034/*
James Smarta4bc3372006-12-02 13:34:16 -05001035# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1036# identifies what rctl value to configure the additional ring for.
1037# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1038*/
1039LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1040 255, "Identifies RCTL for additional ring configuration");
1041
1042/*
1043# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1044# identifies what type value to configure the additional ring for.
1045# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1046*/
1047LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1048 255, "Identifies TYPE for additional ring configuration");
1049
1050/*
dea31012005-04-17 16:05:31 -05001051# lpfc_fdmi_on: controls FDMI support.
1052# 0 = no FDMI support
1053# 1 = support FDMI without attribute of hostname
1054# 2 = support FDMI with attribute of hostname
1055# Value range [0,2]. Default value is 0.
1056*/
1057LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1058
1059/*
1060# Specifies the maximum number of ELS cmds we can have outstanding (for
1061# discovery). Value range is [1,64]. Default value = 32.
1062*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001063LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001064 "during discovery");
1065
1066/*
James Smart65a29c12006-07-06 15:50:50 -04001067# lpfc_max_luns: maximum allowed LUN.
1068# Value range is [0,65535]. Default value is 255.
1069# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001070*/
James Smart65a29c12006-07-06 15:50:50 -04001071LPFC_ATTR_R(max_luns, 255, 0, 65535,
1072 "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001073
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001074/*
1075# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1076# Value range is [1,255], default value is 10.
1077*/
1078LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1079 "Milliseconds driver will wait between polling FCP ring");
1080
James Smart4ff43242006-12-02 13:34:56 -05001081/*
1082# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1083# support this feature
1084# 0 = MSI disabled (default)
1085# 1 = MSI enabled
1086# Value range is [0,1]. Default value is 0.
1087*/
1088LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1089
James Smartc3f28af2006-08-18 17:47:18 -04001090
dea31012005-04-17 16:05:31 -05001091struct class_device_attribute *lpfc_host_attrs[] = {
1092 &class_device_attr_info,
1093 &class_device_attr_serialnum,
1094 &class_device_attr_modeldesc,
1095 &class_device_attr_modelname,
1096 &class_device_attr_programtype,
1097 &class_device_attr_portnum,
1098 &class_device_attr_fwrev,
1099 &class_device_attr_hdw,
1100 &class_device_attr_option_rom_version,
1101 &class_device_attr_state,
1102 &class_device_attr_num_discovered_ports,
1103 &class_device_attr_lpfc_drvr_version,
1104 &class_device_attr_lpfc_log_verbose,
1105 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001106 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -05001107 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001108 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001109 &class_device_attr_lpfc_fcp_class,
1110 &class_device_attr_lpfc_use_adisc,
1111 &class_device_attr_lpfc_ack0,
1112 &class_device_attr_lpfc_topology,
1113 &class_device_attr_lpfc_scan_down,
1114 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001115 &class_device_attr_lpfc_cr_delay,
1116 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001117 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001118 &class_device_attr_lpfc_multi_ring_rctl,
1119 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001120 &class_device_attr_lpfc_fdmi_on,
1121 &class_device_attr_lpfc_max_luns,
1122 &class_device_attr_nport_evt_cnt,
1123 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001124 &class_device_attr_board_mode,
James Smart40496f02006-07-06 15:50:22 -04001125 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001126 &class_device_attr_lpfc_poll,
1127 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001128 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001129 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001130 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001131 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001132 NULL,
1133};
1134
1135static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001136sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1137 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001138{
1139 size_t buf_off;
1140 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1141 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001143
1144 if ((off + count) > FF_REG_AREA_SIZE)
1145 return -ERANGE;
1146
1147 if (count == 0) return 0;
1148
1149 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1150 return -EINVAL;
1151
1152 spin_lock_irq(phba->host->host_lock);
1153
1154 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1155 spin_unlock_irq(phba->host->host_lock);
1156 return -EPERM;
1157 }
1158
1159 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1160 writel(*((uint32_t *)(buf + buf_off)),
1161 phba->ctrl_regs_memmap_p + off + buf_off);
1162
1163 spin_unlock_irq(phba->host->host_lock);
1164
1165 return count;
1166}
1167
1168static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001169sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1170 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001171{
1172 size_t buf_off;
1173 uint32_t * tmp_ptr;
1174 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1175 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001176 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001177
1178 if (off > FF_REG_AREA_SIZE)
1179 return -ERANGE;
1180
1181 if ((off + count) > FF_REG_AREA_SIZE)
1182 count = FF_REG_AREA_SIZE - off;
1183
1184 if (count == 0) return 0;
1185
1186 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1187 return -EINVAL;
1188
1189 spin_lock_irq(phba->host->host_lock);
1190
1191 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1192 tmp_ptr = (uint32_t *)(buf + buf_off);
1193 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1194 }
1195
1196 spin_unlock_irq(phba->host->host_lock);
1197
1198 return count;
1199}
1200
1201static struct bin_attribute sysfs_ctlreg_attr = {
1202 .attr = {
1203 .name = "ctlreg",
1204 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001205 },
1206 .size = 256,
1207 .read = sysfs_ctlreg_read,
1208 .write = sysfs_ctlreg_write,
1209};
1210
1211
1212static void
1213sysfs_mbox_idle (struct lpfc_hba * phba)
1214{
1215 phba->sysfs_mbox.state = SMBOX_IDLE;
1216 phba->sysfs_mbox.offset = 0;
1217
1218 if (phba->sysfs_mbox.mbox) {
1219 mempool_free(phba->sysfs_mbox.mbox,
1220 phba->mbox_mem_pool);
1221 phba->sysfs_mbox.mbox = NULL;
1222 }
1223}
1224
1225static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001226sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1227 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001228{
1229 struct Scsi_Host * host =
1230 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001231 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001232 struct lpfcMboxq * mbox = NULL;
1233
1234 if ((count + off) > MAILBOX_CMD_SIZE)
1235 return -ERANGE;
1236
1237 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1238 return -EINVAL;
1239
1240 if (count == 0)
1241 return 0;
1242
1243 if (off == 0) {
1244 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1245 if (!mbox)
1246 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001247 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001248 }
1249
1250 spin_lock_irq(host->host_lock);
1251
1252 if (off == 0) {
1253 if (phba->sysfs_mbox.mbox)
1254 mempool_free(mbox, phba->mbox_mem_pool);
1255 else
1256 phba->sysfs_mbox.mbox = mbox;
1257 phba->sysfs_mbox.state = SMBOX_WRITING;
1258 } else {
1259 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1260 phba->sysfs_mbox.offset != off ||
1261 phba->sysfs_mbox.mbox == NULL ) {
1262 sysfs_mbox_idle(phba);
1263 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001264 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001265 }
1266 }
1267
1268 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1269 buf, count);
1270
1271 phba->sysfs_mbox.offset = off + count;
1272
1273 spin_unlock_irq(host->host_lock);
1274
1275 return count;
1276}
1277
1278static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001279sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1280 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001281{
1282 struct Scsi_Host *host =
1283 class_to_shost(container_of(kobj, struct class_device,
1284 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001285 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001286 int rc;
1287
James Smart1dcb58e2007-04-25 09:51:30 -04001288 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001289 return -ERANGE;
1290
James Smart1dcb58e2007-04-25 09:51:30 -04001291 if ((count + off) > MAILBOX_CMD_SIZE)
1292 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001293
1294 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1295 return -EINVAL;
1296
1297 if (off && count == 0)
1298 return 0;
1299
1300 spin_lock_irq(phba->host->host_lock);
1301
1302 if (off == 0 &&
1303 phba->sysfs_mbox.state == SMBOX_WRITING &&
1304 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1305
1306 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1307 /* Offline only */
1308 case MBX_WRITE_NV:
1309 case MBX_INIT_LINK:
1310 case MBX_DOWN_LINK:
1311 case MBX_CONFIG_LINK:
1312 case MBX_CONFIG_RING:
1313 case MBX_RESET_RING:
1314 case MBX_UNREG_LOGIN:
1315 case MBX_CLEAR_LA:
1316 case MBX_DUMP_CONTEXT:
1317 case MBX_RUN_DIAGS:
1318 case MBX_RESTART:
1319 case MBX_FLASH_WR_ULA:
1320 case MBX_SET_MASK:
1321 case MBX_SET_SLIM:
1322 case MBX_SET_DEBUG:
1323 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1324 printk(KERN_WARNING "mbox_read:Command 0x%x "
1325 "is illegal in on-line state\n",
1326 phba->sysfs_mbox.mbox->mb.mbxCommand);
1327 sysfs_mbox_idle(phba);
1328 spin_unlock_irq(phba->host->host_lock);
1329 return -EPERM;
1330 }
1331 case MBX_LOAD_SM:
1332 case MBX_READ_NV:
1333 case MBX_READ_CONFIG:
1334 case MBX_READ_RCONFIG:
1335 case MBX_READ_STATUS:
1336 case MBX_READ_XRI:
1337 case MBX_READ_REV:
1338 case MBX_READ_LNK_STAT:
1339 case MBX_DUMP_MEMORY:
1340 case MBX_DOWN_LOAD:
1341 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001342 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001343 case MBX_LOAD_AREA:
1344 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001345 case MBX_BEACON:
1346 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001347 break;
1348 case MBX_READ_SPARM64:
1349 case MBX_READ_LA:
1350 case MBX_READ_LA64:
1351 case MBX_REG_LOGIN:
1352 case MBX_REG_LOGIN64:
1353 case MBX_CONFIG_PORT:
1354 case MBX_RUN_BIU_DIAG:
1355 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1356 phba->sysfs_mbox.mbox->mb.mbxCommand);
1357 sysfs_mbox_idle(phba);
1358 spin_unlock_irq(phba->host->host_lock);
1359 return -EPERM;
1360 default:
1361 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1362 phba->sysfs_mbox.mbox->mb.mbxCommand);
1363 sysfs_mbox_idle(phba);
1364 spin_unlock_irq(phba->host->host_lock);
1365 return -EPERM;
1366 }
1367
James Smart46fa3112007-04-25 09:51:45 -04001368 if (phba->fc_flag & FC_BLOCK_MGMT_IO) {
1369 sysfs_mbox_idle(phba);
1370 spin_unlock_irq(host->host_lock);
1371 return -EAGAIN;
1372 }
1373
dea31012005-04-17 16:05:31 -05001374 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1375 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1376
1377 spin_unlock_irq(phba->host->host_lock);
1378 rc = lpfc_sli_issue_mbox (phba,
1379 phba->sysfs_mbox.mbox,
1380 MBX_POLL);
1381 spin_lock_irq(phba->host->host_lock);
1382
1383 } else {
1384 spin_unlock_irq(phba->host->host_lock);
1385 rc = lpfc_sli_issue_mbox_wait (phba,
1386 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001387 lpfc_mbox_tmo_val(phba,
1388 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
dea31012005-04-17 16:05:31 -05001389 spin_lock_irq(phba->host->host_lock);
1390 }
1391
1392 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001393 if (rc == MBX_TIMEOUT) {
1394 phba->sysfs_mbox.mbox->mbox_cmpl =
1395 lpfc_sli_def_mbox_cmpl;
1396 phba->sysfs_mbox.mbox = NULL;
1397 }
dea31012005-04-17 16:05:31 -05001398 sysfs_mbox_idle(phba);
1399 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001400 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001401 }
1402 phba->sysfs_mbox.state = SMBOX_READING;
1403 }
1404 else if (phba->sysfs_mbox.offset != off ||
1405 phba->sysfs_mbox.state != SMBOX_READING) {
1406 printk(KERN_WARNING "mbox_read: Bad State\n");
1407 sysfs_mbox_idle(phba);
1408 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001409 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001410 }
1411
1412 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1413
1414 phba->sysfs_mbox.offset = off + count;
1415
James Smart1dcb58e2007-04-25 09:51:30 -04001416 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001417 sysfs_mbox_idle(phba);
1418
1419 spin_unlock_irq(phba->host->host_lock);
1420
1421 return count;
1422}
1423
1424static struct bin_attribute sysfs_mbox_attr = {
1425 .attr = {
1426 .name = "mbox",
1427 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001428 },
James Smart1dcb58e2007-04-25 09:51:30 -04001429 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001430 .read = sysfs_mbox_read,
1431 .write = sysfs_mbox_write,
1432};
1433
1434int
1435lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1436{
1437 struct Scsi_Host *host = phba->host;
1438 int error;
1439
1440 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1441 &sysfs_ctlreg_attr);
1442 if (error)
1443 goto out;
1444
1445 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1446 &sysfs_mbox_attr);
1447 if (error)
1448 goto out_remove_ctlreg_attr;
1449
1450 return 0;
1451out_remove_ctlreg_attr:
1452 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1453out:
1454 return error;
1455}
1456
1457void
1458lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1459{
1460 struct Scsi_Host *host = phba->host;
1461
1462 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1463 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1464}
1465
1466
1467/*
1468 * Dynamic FC Host Attributes Support
1469 */
1470
1471static void
1472lpfc_get_host_port_id(struct Scsi_Host *shost)
1473{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001474 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001475 /* note: fc_myDID already in cpu endianness */
1476 fc_host_port_id(shost) = phba->fc_myDID;
1477}
1478
1479static void
1480lpfc_get_host_port_type(struct Scsi_Host *shost)
1481{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001482 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001483
1484 spin_lock_irq(shost->host_lock);
1485
1486 if (phba->hba_state == LPFC_HBA_READY) {
1487 if (phba->fc_topology == TOPOLOGY_LOOP) {
1488 if (phba->fc_flag & FC_PUBLIC_LOOP)
1489 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1490 else
1491 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1492 } else {
1493 if (phba->fc_flag & FC_FABRIC)
1494 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1495 else
1496 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1497 }
1498 } else
1499 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1500
1501 spin_unlock_irq(shost->host_lock);
1502}
1503
1504static void
1505lpfc_get_host_port_state(struct Scsi_Host *shost)
1506{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001507 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001508
1509 spin_lock_irq(shost->host_lock);
1510
1511 if (phba->fc_flag & FC_OFFLINE_MODE)
1512 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1513 else {
1514 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001515 case LPFC_STATE_UNKNOWN:
1516 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001517 case LPFC_INIT_START:
1518 case LPFC_INIT_MBX_CMDS:
1519 case LPFC_LINK_DOWN:
1520 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1521 break;
1522 case LPFC_LINK_UP:
1523 case LPFC_LOCAL_CFG_LINK:
1524 case LPFC_FLOGI:
1525 case LPFC_FABRIC_CFG_LINK:
1526 case LPFC_NS_REG:
1527 case LPFC_NS_QRY:
1528 case LPFC_BUILD_DISC_LIST:
1529 case LPFC_DISC_AUTH:
1530 case LPFC_CLEAR_LA:
1531 case LPFC_HBA_READY:
1532 /* Links up, beyond this port_type reports state */
1533 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1534 break;
1535 case LPFC_HBA_ERROR:
1536 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1537 break;
1538 default:
1539 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1540 break;
1541 }
1542 }
1543
1544 spin_unlock_irq(shost->host_lock);
1545}
1546
1547static void
1548lpfc_get_host_speed(struct Scsi_Host *shost)
1549{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001550 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001551
1552 spin_lock_irq(shost->host_lock);
1553
1554 if (phba->hba_state == LPFC_HBA_READY) {
1555 switch(phba->fc_linkspeed) {
1556 case LA_1GHZ_LINK:
1557 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1558 break;
1559 case LA_2GHZ_LINK:
1560 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1561 break;
1562 case LA_4GHZ_LINK:
1563 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1564 break;
James Smartb87eab32007-04-25 09:53:28 -04001565 case LA_8GHZ_LINK:
1566 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1567 break;
dea31012005-04-17 16:05:31 -05001568 default:
1569 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1570 break;
1571 }
1572 }
1573
1574 spin_unlock_irq(shost->host_lock);
1575}
1576
1577static void
1578lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1579{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001580 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001581 u64 node_name;
dea31012005-04-17 16:05:31 -05001582
1583 spin_lock_irq(shost->host_lock);
1584
1585 if ((phba->fc_flag & FC_FABRIC) ||
1586 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1587 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001588 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001589 else
1590 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001591 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001592
1593 spin_unlock_irq(shost->host_lock);
1594
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001595 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001596}
1597
James Smartae367642006-08-18 17:46:53 -04001598static void
1599lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1600{
1601 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1602
1603 spin_lock_irq(shost->host_lock);
1604 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1605 spin_unlock_irq(shost->host_lock);
1606}
dea31012005-04-17 16:05:31 -05001607
1608static struct fc_host_statistics *
1609lpfc_get_stats(struct Scsi_Host *shost)
1610{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001611 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001612 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001613 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04001614 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05001615 LPFC_MBOXQ_t *pmboxq;
1616 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04001617 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001618 int rc = 0;
dea31012005-04-17 16:05:31 -05001619
James Smart46fa3112007-04-25 09:51:45 -04001620 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1621 return NULL;
1622
dea31012005-04-17 16:05:31 -05001623 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1624 if (!pmboxq)
1625 return NULL;
1626 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1627
1628 pmb = &pmboxq->mb;
1629 pmb->mbxCommand = MBX_READ_STATUS;
1630 pmb->mbxOwner = OWN_HOST;
1631 pmboxq->context1 = NULL;
1632
1633 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001634 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001635 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001636 else
dea31012005-04-17 16:05:31 -05001637 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1638
1639 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001640 if (rc == MBX_TIMEOUT)
1641 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1642 else
1643 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001644 return NULL;
1645 }
1646
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001647 memset(hs, 0, sizeof (struct fc_host_statistics));
1648
dea31012005-04-17 16:05:31 -05001649 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1650 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1651 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1652 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1653
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001654 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001655 pmb->mbxCommand = MBX_READ_LNK_STAT;
1656 pmb->mbxOwner = OWN_HOST;
1657 pmboxq->context1 = NULL;
1658
1659 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001660 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001661 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001662 else
dea31012005-04-17 16:05:31 -05001663 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1664
1665 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001666 if (rc == MBX_TIMEOUT)
1667 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1668 else
1669 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001670 return NULL;
1671 }
1672
1673 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1674 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1675 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1676 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1677 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1678 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1679 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1680
James Smart64ba8812006-08-02 15:24:34 -04001681 hs->link_failure_count -= lso->link_failure_count;
1682 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1683 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1684 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1685 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1686 hs->invalid_crc_count -= lso->invalid_crc_count;
1687 hs->error_frames -= lso->error_frames;
1688
dea31012005-04-17 16:05:31 -05001689 if (phba->fc_topology == TOPOLOGY_LOOP) {
1690 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001691 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001692 hs->nos_count = -1;
1693 } else {
1694 hs->lip_count = -1;
1695 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001696 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001697 }
1698
1699 hs->dumped_frames = -1;
1700
James Smart64ba8812006-08-02 15:24:34 -04001701 seconds = get_seconds();
1702 if (seconds < psli->stats_start)
1703 hs->seconds_since_last_reset = seconds +
1704 ((unsigned long)-1 - psli->stats_start);
1705 else
1706 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05001707
James Smart1dcb58e2007-04-25 09:51:30 -04001708 mempool_free(pmboxq, phba->mbox_mem_pool);
1709
dea31012005-04-17 16:05:31 -05001710 return hs;
1711}
1712
James Smart64ba8812006-08-02 15:24:34 -04001713static void
1714lpfc_reset_stats(struct Scsi_Host *shost)
1715{
1716 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1717 struct lpfc_sli *psli = &phba->sli;
1718 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1719 LPFC_MBOXQ_t *pmboxq;
1720 MAILBOX_t *pmb;
1721 int rc = 0;
1722
James Smart46fa3112007-04-25 09:51:45 -04001723 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1724 return;
1725
James Smart64ba8812006-08-02 15:24:34 -04001726 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1727 if (!pmboxq)
1728 return;
1729 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1730
1731 pmb = &pmboxq->mb;
1732 pmb->mbxCommand = MBX_READ_STATUS;
1733 pmb->mbxOwner = OWN_HOST;
1734 pmb->un.varWords[0] = 0x1; /* reset request */
1735 pmboxq->context1 = NULL;
1736
1737 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1738 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1739 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1740 else
1741 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1742
1743 if (rc != MBX_SUCCESS) {
1744 if (rc == MBX_TIMEOUT)
1745 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1746 else
1747 mempool_free(pmboxq, phba->mbox_mem_pool);
1748 return;
1749 }
1750
1751 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1752 pmb->mbxCommand = MBX_READ_LNK_STAT;
1753 pmb->mbxOwner = OWN_HOST;
1754 pmboxq->context1 = NULL;
1755
1756 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1757 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1758 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1759 else
1760 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1761
1762 if (rc != MBX_SUCCESS) {
1763 if (rc == MBX_TIMEOUT)
1764 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1765 else
1766 mempool_free( pmboxq, phba->mbox_mem_pool);
1767 return;
1768 }
1769
1770 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1771 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1772 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1773 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1774 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1775 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1776 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1777 lso->link_events = (phba->fc_eventTag >> 1);
1778
1779 psli->stats_start = get_seconds();
1780
James Smart1dcb58e2007-04-25 09:51:30 -04001781 mempool_free(pmboxq, phba->mbox_mem_pool);
1782
James Smart64ba8812006-08-02 15:24:34 -04001783 return;
1784}
dea31012005-04-17 16:05:31 -05001785
1786/*
1787 * The LPFC driver treats linkdown handling as target loss events so there
1788 * are no sysfs handlers for link_down_tmo.
1789 */
James Smart685f0bf2007-04-25 09:53:08 -04001790
1791static struct lpfc_nodelist *
1792lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05001793{
1794 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001795 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04001796 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001797
1798 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001799 /* Search for this, mapped, target ID */
1800 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
1801 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1802 starget->id == ndlp->nlp_sid) {
1803 spin_unlock_irq(shost->host_lock);
1804 return ndlp;
dea31012005-04-17 16:05:31 -05001805 }
1806 }
1807 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001808 return NULL;
1809}
dea31012005-04-17 16:05:31 -05001810
James Smart685f0bf2007-04-25 09:53:08 -04001811static void
1812lpfc_get_starget_port_id(struct scsi_target *starget)
1813{
1814 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1815
1816 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05001817}
1818
1819static void
1820lpfc_get_starget_node_name(struct scsi_target *starget)
1821{
James Smart685f0bf2007-04-25 09:53:08 -04001822 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05001823
James Smart685f0bf2007-04-25 09:53:08 -04001824 fc_starget_node_name(starget) =
1825 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05001826}
1827
1828static void
1829lpfc_get_starget_port_name(struct scsi_target *starget)
1830{
James Smart685f0bf2007-04-25 09:53:08 -04001831 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05001832
James Smart685f0bf2007-04-25 09:53:08 -04001833 fc_starget_port_name(starget) =
1834 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05001835}
1836
1837static void
dea31012005-04-17 16:05:31 -05001838lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1839{
dea31012005-04-17 16:05:31 -05001840 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04001841 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05001842 else
James Smartc01f3202006-08-18 17:47:08 -04001843 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05001844}
1845
1846
1847#define lpfc_rport_show_function(field, format_string, sz, cast) \
1848static ssize_t \
1849lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1850{ \
1851 struct fc_rport *rport = transport_class_to_rport(cdev); \
1852 struct lpfc_rport_data *rdata = rport->hostdata; \
1853 return snprintf(buf, sz, format_string, \
1854 (rdata->target) ? cast rdata->target->field : 0); \
1855}
1856
1857#define lpfc_rport_rd_attr(field, format_string, sz) \
1858 lpfc_rport_show_function(field, format_string, sz, ) \
1859static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1860
1861
1862struct fc_function_template lpfc_transport_functions = {
1863 /* fixed attributes the driver supports */
1864 .show_host_node_name = 1,
1865 .show_host_port_name = 1,
1866 .show_host_supported_classes = 1,
1867 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05001868 .show_host_supported_speeds = 1,
1869 .show_host_maxframe_size = 1,
1870
1871 /* dynamic attributes the driver supports */
1872 .get_host_port_id = lpfc_get_host_port_id,
1873 .show_host_port_id = 1,
1874
1875 .get_host_port_type = lpfc_get_host_port_type,
1876 .show_host_port_type = 1,
1877
1878 .get_host_port_state = lpfc_get_host_port_state,
1879 .show_host_port_state = 1,
1880
1881 /* active_fc4s is shown but doesn't change (thus no get function) */
1882 .show_host_active_fc4s = 1,
1883
1884 .get_host_speed = lpfc_get_host_speed,
1885 .show_host_speed = 1,
1886
1887 .get_host_fabric_name = lpfc_get_host_fabric_name,
1888 .show_host_fabric_name = 1,
1889
James Smartae367642006-08-18 17:46:53 -04001890 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1891 .show_host_symbolic_name = 1,
1892
dea31012005-04-17 16:05:31 -05001893 /*
1894 * The LPFC driver treats linkdown handling as target loss events
1895 * so there are no sysfs handlers for link_down_tmo.
1896 */
1897
1898 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04001899 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05001900
1901 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1902 .show_rport_maxframe_size = 1,
1903 .show_rport_supported_classes = 1,
1904
dea31012005-04-17 16:05:31 -05001905 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1906 .show_rport_dev_loss_tmo = 1,
1907
1908 .get_starget_port_id = lpfc_get_starget_port_id,
1909 .show_starget_port_id = 1,
1910
1911 .get_starget_node_name = lpfc_get_starget_node_name,
1912 .show_starget_node_name = 1,
1913
1914 .get_starget_port_name = lpfc_get_starget_port_name,
1915 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001916
1917 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04001918 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1919 .terminate_rport_io = lpfc_terminate_rport_io,
dea31012005-04-17 16:05:31 -05001920};
1921
1922void
1923lpfc_get_cfgparam(struct lpfc_hba *phba)
1924{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001925 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1926 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1927 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001928 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05001929 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1930 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001931 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1932 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1933 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1934 lpfc_ack0_init(phba, lpfc_ack0);
1935 lpfc_topology_init(phba, lpfc_topology);
1936 lpfc_scan_down_init(phba, lpfc_scan_down);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001937 lpfc_link_speed_init(phba, lpfc_link_speed);
1938 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1939 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1940 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001941 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart4ff43242006-12-02 13:34:56 -05001942 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartc01f3202006-08-18 17:47:08 -04001943 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1944 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001945 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05001946 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04001947 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05001948
1949 /*
1950 * The total number of segments is the configuration value plus 2
1951 * since the IOCB need a command and response bde.
1952 */
1953 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1954
1955 /*
1956 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1957 * used to create the sg_dma_buf_pool must be dynamically calculated
1958 */
1959 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1960 sizeof(struct fcp_rsp) +
1961 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1962
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001963
James Smart7054a602007-04-25 09:52:34 -04001964 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001965
dea31012005-04-17 16:05:31 -05001966 return;
1967}