blob: 7811aaf114d512106c1a99eb157880f9b0abe9de [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>
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
dea31012005-04-17 16:05:31 -0500240 if (mbxstatus == MBX_TIMEOUT)
241 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
242 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400243 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500244
245 if (mbxstatus == MBXERR_ERROR)
246 return -EIO;
247
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700248 return 0;
dea31012005-04-17 16:05:31 -0500249}
250
James Smart40496f02006-07-06 15:50:22 -0400251static int
James Smart46fa3112007-04-25 09:51:45 -0400252lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
253{
254 struct completion online_compl;
255 struct lpfc_sli_ring *pring;
256 struct lpfc_sli *psli;
257 int status = 0;
258 int cnt = 0;
259 int i;
260
261 init_completion(&online_compl);
262 lpfc_workq_post_event(phba, &status, &online_compl,
263 LPFC_EVT_OFFLINE_PREP);
264 wait_for_completion(&online_compl);
265
266 if (status != 0)
267 return -EIO;
268
269 psli = &phba->sli;
270
271 for (i = 0; i < psli->num_rings; i++) {
272 pring = &psli->ring[i];
273 /* The linkdown event takes 30 seconds to timeout. */
274 while (pring->txcmplq_cnt) {
275 msleep(10);
276 if (cnt++ > 3000) {
277 lpfc_printf_log(phba,
278 KERN_WARNING, LOG_INIT,
279 "%d:0466 Outstanding IO when "
280 "bringing Adapter offline\n",
281 phba->brd_no);
282 break;
283 }
284 }
285 }
286
287 init_completion(&online_compl);
288 lpfc_workq_post_event(phba, &status, &online_compl, type);
289 wait_for_completion(&online_compl);
290
291 if (status != 0)
292 return -EIO;
293
294 return 0;
295}
296
297static int
James Smart40496f02006-07-06 15:50:22 -0400298lpfc_selective_reset(struct lpfc_hba *phba)
299{
300 struct completion online_compl;
301 int status = 0;
302
James Smart46fa3112007-04-25 09:51:45 -0400303 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400304
305 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400306 return status;
James Smart40496f02006-07-06 15:50:22 -0400307
308 init_completion(&online_compl);
309 lpfc_workq_post_event(phba, &status, &online_compl,
310 LPFC_EVT_ONLINE);
311 wait_for_completion(&online_compl);
312
313 if (status != 0)
314 return -EIO;
315
316 return 0;
317}
318
319static ssize_t
320lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
321{
322 struct Scsi_Host *host = class_to_shost(cdev);
323 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
324 int status = -EINVAL;
325
326 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
327 status = lpfc_selective_reset(phba);
328
329 if (status == 0)
330 return strlen(buf);
331 else
332 return status;
333}
334
dea31012005-04-17 16:05:31 -0500335static ssize_t
336lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
337{
338 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500339 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500340 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
341}
342
343static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500344lpfc_board_mode_show(struct class_device *cdev, char *buf)
345{
346 struct Scsi_Host *host = class_to_shost(cdev);
347 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
348 char * state;
349
350 if (phba->hba_state == LPFC_HBA_ERROR)
351 state = "error";
352 else if (phba->hba_state == LPFC_WARM_START)
353 state = "warm start";
354 else if (phba->hba_state == LPFC_INIT_START)
355 state = "offline";
356 else
357 state = "online";
358
359 return snprintf(buf, PAGE_SIZE, "%s\n", state);
360}
361
362static ssize_t
363lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
364{
365 struct Scsi_Host *host = class_to_shost(cdev);
366 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
367 struct completion online_compl;
368 int status=0;
369
370 init_completion(&online_compl);
371
James Smart46fa3112007-04-25 09:51:45 -0400372 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500373 lpfc_workq_post_event(phba, &status, &online_compl,
374 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400375 wait_for_completion(&online_compl);
376 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
377 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500378 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400379 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
380 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
381 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500382 else
383 return -EINVAL;
384
Jamie Wellnitz41415862006-02-28 19:25:27 -0500385 if (!status)
386 return strlen(buf);
387 else
388 return -EIO;
389}
390
391static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500392lpfc_poll_show(struct class_device *cdev, char *buf)
393{
394 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500395 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500396
397 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
398}
399
400static ssize_t
401lpfc_poll_store(struct class_device *cdev, const char *buf,
402 size_t count)
403{
404 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500405 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500406 uint32_t creg_val;
407 uint32_t old_val;
408 int val=0;
409
410 if (!isdigit(buf[0]))
411 return -EINVAL;
412
413 if (sscanf(buf, "%i", &val) != 1)
414 return -EINVAL;
415
416 if ((val & 0x3) != val)
417 return -EINVAL;
418
419 spin_lock_irq(phba->host->host_lock);
420
421 old_val = phba->cfg_poll;
422
423 if (val & ENABLE_FCP_RING_POLLING) {
424 if ((val & DISABLE_FCP_RING_INT) &&
425 !(old_val & DISABLE_FCP_RING_INT)) {
426 creg_val = readl(phba->HCregaddr);
427 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
428 writel(creg_val, phba->HCregaddr);
429 readl(phba->HCregaddr); /* flush */
430
431 lpfc_poll_start_timer(phba);
432 }
433 } else if (val != 0x0) {
434 spin_unlock_irq(phba->host->host_lock);
435 return -EINVAL;
436 }
437
438 if (!(val & DISABLE_FCP_RING_INT) &&
439 (old_val & DISABLE_FCP_RING_INT))
440 {
441 spin_unlock_irq(phba->host->host_lock);
442 del_timer(&phba->fcp_poll_timer);
443 spin_lock_irq(phba->host->host_lock);
444 creg_val = readl(phba->HCregaddr);
445 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
446 writel(creg_val, phba->HCregaddr);
447 readl(phba->HCregaddr); /* flush */
448 }
449
450 phba->cfg_poll = val;
451
452 spin_unlock_irq(phba->host->host_lock);
453
454 return strlen(buf);
455}
dea31012005-04-17 16:05:31 -0500456
457#define lpfc_param_show(attr) \
458static ssize_t \
459lpfc_##attr##_show(struct class_device *cdev, char *buf) \
460{ \
461 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500462 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea31012005-04-17 16:05:31 -0500463 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400464 val = phba->cfg_##attr;\
465 return snprintf(buf, PAGE_SIZE, "%d\n",\
466 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500467}
468
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400469#define lpfc_param_hex_show(attr) \
470static ssize_t \
471lpfc_##attr##_show(struct class_device *cdev, char *buf) \
472{ \
473 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500474 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400475 int val = 0;\
476 val = phba->cfg_##attr;\
477 return snprintf(buf, PAGE_SIZE, "%#x\n",\
478 phba->cfg_##attr);\
479}
480
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400481#define lpfc_param_init(attr, default, minval, maxval) \
482static int \
483lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
484{ \
485 if (val >= minval && val <= maxval) {\
486 phba->cfg_##attr = val;\
487 return 0;\
488 }\
489 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
490 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
491 "allowed range is ["#minval", "#maxval"]\n", \
492 phba->brd_no, val); \
493 phba->cfg_##attr = default;\
494 return -EINVAL;\
495}
496
497#define lpfc_param_set(attr, default, minval, maxval) \
498static int \
499lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
500{ \
501 if (val >= minval && val <= maxval) {\
502 phba->cfg_##attr = val;\
503 return 0;\
504 }\
505 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
506 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
507 "allowed range is ["#minval", "#maxval"]\n", \
508 phba->brd_no, val); \
509 return -EINVAL;\
510}
511
512#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500513static ssize_t \
514lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
515{ \
516 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500517 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400518 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400519 if (!isdigit(buf[0]))\
520 return -EINVAL;\
521 if (sscanf(buf, "%i", &val) != 1)\
522 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400523 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400524 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400525 else \
526 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500527}
528
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400529#define LPFC_ATTR(name, defval, minval, maxval, desc) \
530static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500531module_param(lpfc_##name, int, 0);\
532MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400533lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500534
535#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
536static int lpfc_##name = defval;\
537module_param(lpfc_##name, int, 0);\
538MODULE_PARM_DESC(lpfc_##name, desc);\
539lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400540lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500541static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
542
543#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
544static int lpfc_##name = defval;\
545module_param(lpfc_##name, int, 0);\
546MODULE_PARM_DESC(lpfc_##name, desc);\
547lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400548lpfc_param_init(name, defval, minval, maxval)\
549lpfc_param_set(name, defval, minval, maxval)\
550lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500551static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
552 lpfc_##name##_show, lpfc_##name##_store)
553
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400554#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
555static int lpfc_##name = defval;\
556module_param(lpfc_##name, int, 0);\
557MODULE_PARM_DESC(lpfc_##name, desc);\
558lpfc_param_hex_show(name)\
559lpfc_param_init(name, defval, minval, maxval)\
560static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
561
562#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
563static int lpfc_##name = defval;\
564module_param(lpfc_##name, int, 0);\
565MODULE_PARM_DESC(lpfc_##name, desc);\
566lpfc_param_hex_show(name)\
567lpfc_param_init(name, defval, minval, maxval)\
568lpfc_param_set(name, defval, minval, maxval)\
569lpfc_param_store(name)\
570static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
571 lpfc_##name##_show, lpfc_##name##_store)
572
dea31012005-04-17 16:05:31 -0500573static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
574static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
575static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
576static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
577static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
578static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
579static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
580static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
581static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
582static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
583 lpfc_option_rom_version_show, NULL);
584static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
585 lpfc_num_discovered_ports_show, NULL);
586static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
587static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
588 NULL);
589static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
590 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500591static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
592 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400593static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea31012005-04-17 16:05:31 -0500594
James Smartc3f28af2006-08-18 17:47:18 -0400595
James Smarta12e07b2006-12-02 13:35:30 -0500596static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400597
598static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500599lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400600 size_t count)
601{
602 struct Scsi_Host *host = class_to_shost(cdev);
603 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
604 unsigned int cnt = count;
605
606 /*
607 * We're doing a simple sanity check for soft_wwpn setting.
608 * We require that the user write a specific key to enable
609 * the soft_wwpn attribute to be settable. Once the attribute
610 * is written, the enable key resets. If further updates are
611 * desired, the key must be written again to re-enable the
612 * attribute.
613 *
614 * The "key" is not secret - it is a hardcoded string shown
615 * here. The intent is to protect against the random user or
616 * application that is just writing attributes.
617 */
618
619 /* count may include a LF at end of string */
620 if (buf[cnt-1] == '\n')
621 cnt--;
622
James Smarta12e07b2006-12-02 13:35:30 -0500623 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
624 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400625 return -EINVAL;
626
James Smarta12e07b2006-12-02 13:35:30 -0500627 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400628 return count;
629}
James Smarta12e07b2006-12-02 13:35:30 -0500630static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
631 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400632
633static ssize_t
634lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
635{
636 struct Scsi_Host *host = class_to_shost(cdev);
637 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
Randy Dunlapafc071e2006-10-23 21:47:13 -0700638 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
639 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400640}
641
642
643static ssize_t
644lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
645{
646 struct Scsi_Host *host = class_to_shost(cdev);
647 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
648 struct completion online_compl;
649 int stat1=0, stat2=0;
650 unsigned int i, j, cnt=count;
651 u8 wwpn[8];
652
653 /* count may include a LF at end of string */
654 if (buf[cnt-1] == '\n')
655 cnt--;
656
James Smarta12e07b2006-12-02 13:35:30 -0500657 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400658 ((cnt == 17) && (*buf++ != 'x')) ||
659 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
660 return -EINVAL;
661
James Smarta12e07b2006-12-02 13:35:30 -0500662 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400663
664 memset(wwpn, 0, sizeof(wwpn));
665
666 /* Validate and store the new name */
667 for (i=0, j=0; i < 16; i++) {
668 if ((*buf >= 'a') && (*buf <= 'f'))
669 j = ((j << 4) | ((*buf++ -'a') + 10));
670 else if ((*buf >= 'A') && (*buf <= 'F'))
671 j = ((j << 4) | ((*buf++ -'A') + 10));
672 else if ((*buf >= '0') && (*buf <= '9'))
673 j = ((j << 4) | (*buf++ -'0'));
674 else
675 return -EINVAL;
676 if (i % 2) {
677 wwpn[i/2] = j & 0xff;
678 j = 0;
679 }
680 }
681 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
682 fc_host_port_name(host) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -0500683 if (phba->cfg_soft_wwnn)
684 fc_host_node_name(host) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -0400685
686 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
687 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
688
James Smart46fa3112007-04-25 09:51:45 -0400689 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -0400690 if (stat1)
691 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
692 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
693 "adapter - %d\n", phba->brd_no, stat1);
694
695 init_completion(&online_compl);
696 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
697 wait_for_completion(&online_compl);
698 if (stat2)
699 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
700 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
701 "adapter - %d\n", phba->brd_no, stat2);
702
703 return (stat1 || stat2) ? -EIO : count;
704}
705static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
706 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
707
James Smarta12e07b2006-12-02 13:35:30 -0500708static ssize_t
709lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
710{
711 struct Scsi_Host *host = class_to_shost(cdev);
712 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
713 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
714 (unsigned long long)phba->cfg_soft_wwnn);
715}
716
717
718static ssize_t
719lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
720{
721 struct Scsi_Host *host = class_to_shost(cdev);
722 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
723 unsigned int i, j, cnt=count;
724 u8 wwnn[8];
725
726 /* count may include a LF at end of string */
727 if (buf[cnt-1] == '\n')
728 cnt--;
729
730 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
731 ((cnt == 17) && (*buf++ != 'x')) ||
732 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
733 return -EINVAL;
734
735 /*
736 * Allow wwnn to be set many times, as long as the enable is set.
737 * However, once the wwpn is set, everything locks.
738 */
739
740 memset(wwnn, 0, sizeof(wwnn));
741
742 /* Validate and store the new name */
743 for (i=0, j=0; i < 16; i++) {
744 if ((*buf >= 'a') && (*buf <= 'f'))
745 j = ((j << 4) | ((*buf++ -'a') + 10));
746 else if ((*buf >= 'A') && (*buf <= 'F'))
747 j = ((j << 4) | ((*buf++ -'A') + 10));
748 else if ((*buf >= '0') && (*buf <= '9'))
749 j = ((j << 4) | (*buf++ -'0'));
750 else
751 return -EINVAL;
752 if (i % 2) {
753 wwnn[i/2] = j & 0xff;
754 j = 0;
755 }
756 }
757 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
758
759 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
760 "lpfc%d: soft_wwnn set. Value will take effect upon "
761 "setting of the soft_wwpn\n", phba->brd_no);
762
763 return count;
764}
765static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
766 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
767
James Smartc3f28af2006-08-18 17:47:18 -0400768
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500769static int lpfc_poll = 0;
770module_param(lpfc_poll, int, 0);
771MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
772 " 0 - none,"
773 " 1 - poll with interrupts enabled"
774 " 3 - poll and disable FCP ring interrupts");
775
776static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
777 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500778
779/*
James Smartc01f3202006-08-18 17:47:08 -0400780# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
781# until the timer expires. Value range is [0,255]. Default value is 30.
782*/
783static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
784static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
785module_param(lpfc_nodev_tmo, int, 0);
786MODULE_PARM_DESC(lpfc_nodev_tmo,
787 "Seconds driver will hold I/O waiting "
788 "for a device to come back");
789static ssize_t
790lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
791{
792 struct Scsi_Host *host = class_to_shost(cdev);
793 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
794 int val = 0;
795 val = phba->cfg_devloss_tmo;
796 return snprintf(buf, PAGE_SIZE, "%d\n",
797 phba->cfg_devloss_tmo);
798}
799
800static int
801lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
802{
803 static int warned;
804 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
805 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
806 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
807 warned = 1;
808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
809 "%d:0402 Ignoring nodev_tmo module "
810 "parameter because devloss_tmo is"
811 " set.\n",
812 phba->brd_no);
813 }
814 return 0;
815 }
816
817 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
818 phba->cfg_nodev_tmo = val;
819 phba->cfg_devloss_tmo = val;
820 return 0;
821 }
822 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
823 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
824 "allowed range is [%d, %d]\n",
825 phba->brd_no, val,
826 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
827 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
828 return -EINVAL;
829}
830
James Smart7054a602007-04-25 09:52:34 -0400831static void
832lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba)
833{
834 struct lpfc_nodelist *ndlp;
835
836 spin_lock_irq(phba->host->host_lock);
837 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp)
838 if (ndlp->rport)
839 ndlp->rport->dev_loss_tmo = phba->cfg_devloss_tmo;
840 spin_unlock_irq(phba->host->host_lock);
841}
842
James Smartc01f3202006-08-18 17:47:08 -0400843static int
844lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
845{
846 if (phba->dev_loss_tmo_changed ||
847 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
848 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
849 "%d:0401 Ignoring change to nodev_tmo "
850 "because devloss_tmo is set.\n",
851 phba->brd_no);
852 return 0;
853 }
854
855 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
856 phba->cfg_nodev_tmo = val;
857 phba->cfg_devloss_tmo = val;
James Smart7054a602007-04-25 09:52:34 -0400858 lpfc_update_rport_devloss_tmo(phba);
James Smartc01f3202006-08-18 17:47:08 -0400859 return 0;
860 }
861
862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
863 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
864 "allowed range is [%d, %d]\n",
865 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
866 LPFC_MAX_DEVLOSS_TMO);
867 return -EINVAL;
868}
869
870lpfc_param_store(nodev_tmo)
871
872static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
873 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
874
875/*
876# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
877# disappear until the timer expires. Value range is [0,255]. Default
878# value is 30.
879*/
880module_param(lpfc_devloss_tmo, int, 0);
881MODULE_PARM_DESC(lpfc_devloss_tmo,
882 "Seconds driver will hold I/O waiting "
883 "for a device to come back");
884lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
885 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
886lpfc_param_show(devloss_tmo)
887static int
888lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
889{
890 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
891 phba->cfg_nodev_tmo = val;
892 phba->cfg_devloss_tmo = val;
893 phba->dev_loss_tmo_changed = 1;
James Smart7054a602007-04-25 09:52:34 -0400894 lpfc_update_rport_devloss_tmo(phba);
James Smartc01f3202006-08-18 17:47:08 -0400895 return 0;
896 }
897
898 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
899 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
900 " %d, allowed range is [%d, %d]\n",
901 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
902 LPFC_MAX_DEVLOSS_TMO);
903 return -EINVAL;
904}
905
906lpfc_param_store(devloss_tmo)
907static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
908 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
909
910/*
dea31012005-04-17 16:05:31 -0500911# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
912# deluged with LOTS of information.
913# You can set a bit mask to record specific types of verbose messages:
914#
915# LOG_ELS 0x1 ELS events
916# LOG_DISCOVERY 0x2 Link discovery events
917# LOG_MBOX 0x4 Mailbox events
918# LOG_INIT 0x8 Initialization events
919# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -0500920# LOG_FCP 0x40 FCP traffic history
921# LOG_NODE 0x80 Node table events
922# LOG_MISC 0x400 Miscellaneous events
923# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -0500924# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -0500925# LOG_LIBDFC 0x2000 LIBDFC events
926# LOG_ALL_MSG 0xffff LOG all messages
927*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400928LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500929
930/*
931# lun_queue_depth: This parameter is used to limit the number of outstanding
932# commands per FCP LUN. Value range is [1,128]. Default value is 30.
933*/
934LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
935 "Max number of FCP commands we can queue to a specific LUN");
936
937/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500938# hba_queue_depth: This parameter is used to limit the number of outstanding
939# commands per lpfc HBA. Value range is [32,8192]. If this parameter
940# value is greater than the maximum number of exchanges supported by the HBA,
941# then maximum number of exchanges supported by the HBA is used to determine
942# the hba_queue_depth.
943*/
944LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
945 "Max number of FCP commands we can queue to a lpfc HBA");
946
947/*
dea31012005-04-17 16:05:31 -0500948# Some disk devices have a "select ID" or "select Target" capability.
949# From a protocol standpoint "select ID" usually means select the
950# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
951# annex" which contains a table that maps a "select ID" (a number
952# between 0 and 7F) to an ALPA. By default, for compatibility with
953# older drivers, the lpfc driver scans this table from low ALPA to high
954# ALPA.
955#
956# Turning on the scan-down variable (on = 1, off = 0) will
957# cause the lpfc driver to use an inverted table, effectively
958# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
959#
960# (Note: This "select ID" functionality is a LOOP ONLY characteristic
961# and will not work across a fabric. Also this parameter will take
962# effect only in the case when ALPA map is not available.)
963*/
964LPFC_ATTR_R(scan_down, 1, 0, 1,
965 "Start scanning for devices from highest ALPA to lowest");
966
967/*
dea31012005-04-17 16:05:31 -0500968# lpfc_topology: link topology for init link
969# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500970# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500971# 0x02 = attempt point-to-point mode only
972# 0x04 = attempt loop mode only
973# 0x06 = attempt point-to-point mode then loop
974# Set point-to-point mode if you want to run as an N_Port.
975# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
976# Default value is 0.
977*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500978LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500979
980/*
981# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
982# connection.
983# 0 = auto select (default)
984# 1 = 1 Gigabaud
985# 2 = 2 Gigabaud
986# 4 = 4 Gigabaud
987# Value range is [0,4]. Default value is 0.
988*/
989LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
990
991/*
992# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
993# Value range is [2,3]. Default value is 3.
994*/
995LPFC_ATTR_R(fcp_class, 3, 2, 3,
996 "Select Fibre Channel class of service for FCP sequences");
997
998/*
999# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1000# is [0,1]. Default value is 0.
1001*/
1002LPFC_ATTR_RW(use_adisc, 0, 0, 1,
1003 "Use ADISC on rediscovery to authenticate FCP devices");
1004
1005/*
1006# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1007# range is [0,1]. Default value is 0.
1008*/
1009LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1010
1011/*
1012# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1013# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001014# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001015# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1016# cr_delay is set to 0.
1017*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001018LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001019 "interrupt response is generated");
1020
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001021LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001022 "interrupt response is generated");
1023
1024/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001025# lpfc_multi_ring_support: Determines how many rings to spread available
1026# cmd/rsp IOCB entries across.
1027# Value range is [1,2]. Default value is 1.
1028*/
1029LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1030 "SLI rings to spread IOCB entries across");
1031
1032/*
James Smarta4bc3372006-12-02 13:34:16 -05001033# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1034# identifies what rctl value to configure the additional ring for.
1035# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1036*/
1037LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1038 255, "Identifies RCTL for additional ring configuration");
1039
1040/*
1041# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1042# identifies what type value to configure the additional ring for.
1043# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1044*/
1045LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1046 255, "Identifies TYPE for additional ring configuration");
1047
1048/*
dea31012005-04-17 16:05:31 -05001049# lpfc_fdmi_on: controls FDMI support.
1050# 0 = no FDMI support
1051# 1 = support FDMI without attribute of hostname
1052# 2 = support FDMI with attribute of hostname
1053# Value range [0,2]. Default value is 0.
1054*/
1055LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1056
1057/*
1058# Specifies the maximum number of ELS cmds we can have outstanding (for
1059# discovery). Value range is [1,64]. Default value = 32.
1060*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001061LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001062 "during discovery");
1063
1064/*
James Smart65a29c12006-07-06 15:50:50 -04001065# lpfc_max_luns: maximum allowed LUN.
1066# Value range is [0,65535]. Default value is 255.
1067# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001068*/
James Smart65a29c12006-07-06 15:50:50 -04001069LPFC_ATTR_R(max_luns, 255, 0, 65535,
1070 "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001071
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001072/*
1073# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1074# Value range is [1,255], default value is 10.
1075*/
1076LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1077 "Milliseconds driver will wait between polling FCP ring");
1078
James Smart4ff43242006-12-02 13:34:56 -05001079/*
1080# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1081# support this feature
1082# 0 = MSI disabled (default)
1083# 1 = MSI enabled
1084# Value range is [0,1]. Default value is 0.
1085*/
1086LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1087
James Smartc3f28af2006-08-18 17:47:18 -04001088
dea31012005-04-17 16:05:31 -05001089struct class_device_attribute *lpfc_host_attrs[] = {
1090 &class_device_attr_info,
1091 &class_device_attr_serialnum,
1092 &class_device_attr_modeldesc,
1093 &class_device_attr_modelname,
1094 &class_device_attr_programtype,
1095 &class_device_attr_portnum,
1096 &class_device_attr_fwrev,
1097 &class_device_attr_hdw,
1098 &class_device_attr_option_rom_version,
1099 &class_device_attr_state,
1100 &class_device_attr_num_discovered_ports,
1101 &class_device_attr_lpfc_drvr_version,
1102 &class_device_attr_lpfc_log_verbose,
1103 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001104 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -05001105 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001106 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001107 &class_device_attr_lpfc_fcp_class,
1108 &class_device_attr_lpfc_use_adisc,
1109 &class_device_attr_lpfc_ack0,
1110 &class_device_attr_lpfc_topology,
1111 &class_device_attr_lpfc_scan_down,
1112 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001113 &class_device_attr_lpfc_cr_delay,
1114 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001115 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001116 &class_device_attr_lpfc_multi_ring_rctl,
1117 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001118 &class_device_attr_lpfc_fdmi_on,
1119 &class_device_attr_lpfc_max_luns,
1120 &class_device_attr_nport_evt_cnt,
1121 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001122 &class_device_attr_board_mode,
James Smart40496f02006-07-06 15:50:22 -04001123 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001124 &class_device_attr_lpfc_poll,
1125 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001126 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001127 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001128 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001129 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001130 NULL,
1131};
1132
1133static ssize_t
1134sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1135{
1136 size_t buf_off;
1137 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1138 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001139 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001140
1141 if ((off + count) > FF_REG_AREA_SIZE)
1142 return -ERANGE;
1143
1144 if (count == 0) return 0;
1145
1146 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1147 return -EINVAL;
1148
1149 spin_lock_irq(phba->host->host_lock);
1150
1151 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1152 spin_unlock_irq(phba->host->host_lock);
1153 return -EPERM;
1154 }
1155
1156 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1157 writel(*((uint32_t *)(buf + buf_off)),
1158 phba->ctrl_regs_memmap_p + off + buf_off);
1159
1160 spin_unlock_irq(phba->host->host_lock);
1161
1162 return count;
1163}
1164
1165static ssize_t
1166sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1167{
1168 size_t buf_off;
1169 uint32_t * tmp_ptr;
1170 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1171 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001172 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001173
1174 if (off > FF_REG_AREA_SIZE)
1175 return -ERANGE;
1176
1177 if ((off + count) > FF_REG_AREA_SIZE)
1178 count = FF_REG_AREA_SIZE - off;
1179
1180 if (count == 0) return 0;
1181
1182 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1183 return -EINVAL;
1184
1185 spin_lock_irq(phba->host->host_lock);
1186
1187 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1188 tmp_ptr = (uint32_t *)(buf + buf_off);
1189 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1190 }
1191
1192 spin_unlock_irq(phba->host->host_lock);
1193
1194 return count;
1195}
1196
1197static struct bin_attribute sysfs_ctlreg_attr = {
1198 .attr = {
1199 .name = "ctlreg",
1200 .mode = S_IRUSR | S_IWUSR,
1201 .owner = THIS_MODULE,
1202 },
1203 .size = 256,
1204 .read = sysfs_ctlreg_read,
1205 .write = sysfs_ctlreg_write,
1206};
1207
1208
1209static void
1210sysfs_mbox_idle (struct lpfc_hba * phba)
1211{
1212 phba->sysfs_mbox.state = SMBOX_IDLE;
1213 phba->sysfs_mbox.offset = 0;
1214
1215 if (phba->sysfs_mbox.mbox) {
1216 mempool_free(phba->sysfs_mbox.mbox,
1217 phba->mbox_mem_pool);
1218 phba->sysfs_mbox.mbox = NULL;
1219 }
1220}
1221
1222static ssize_t
1223sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1224{
1225 struct Scsi_Host * host =
1226 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001227 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001228 struct lpfcMboxq * mbox = NULL;
1229
1230 if ((count + off) > MAILBOX_CMD_SIZE)
1231 return -ERANGE;
1232
1233 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1234 return -EINVAL;
1235
1236 if (count == 0)
1237 return 0;
1238
1239 if (off == 0) {
1240 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1241 if (!mbox)
1242 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001243 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001244 }
1245
1246 spin_lock_irq(host->host_lock);
1247
1248 if (off == 0) {
1249 if (phba->sysfs_mbox.mbox)
1250 mempool_free(mbox, phba->mbox_mem_pool);
1251 else
1252 phba->sysfs_mbox.mbox = mbox;
1253 phba->sysfs_mbox.state = SMBOX_WRITING;
1254 } else {
1255 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1256 phba->sysfs_mbox.offset != off ||
1257 phba->sysfs_mbox.mbox == NULL ) {
1258 sysfs_mbox_idle(phba);
1259 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001260 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001261 }
1262 }
1263
1264 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1265 buf, count);
1266
1267 phba->sysfs_mbox.offset = off + count;
1268
1269 spin_unlock_irq(host->host_lock);
1270
1271 return count;
1272}
1273
1274static ssize_t
1275sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1276{
1277 struct Scsi_Host *host =
1278 class_to_shost(container_of(kobj, struct class_device,
1279 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001280 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001281 int rc;
1282
James Smart1dcb58e2007-04-25 09:51:30 -04001283 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001284 return -ERANGE;
1285
James Smart1dcb58e2007-04-25 09:51:30 -04001286 if ((count + off) > MAILBOX_CMD_SIZE)
1287 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001288
1289 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1290 return -EINVAL;
1291
1292 if (off && count == 0)
1293 return 0;
1294
1295 spin_lock_irq(phba->host->host_lock);
1296
1297 if (off == 0 &&
1298 phba->sysfs_mbox.state == SMBOX_WRITING &&
1299 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1300
1301 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1302 /* Offline only */
1303 case MBX_WRITE_NV:
1304 case MBX_INIT_LINK:
1305 case MBX_DOWN_LINK:
1306 case MBX_CONFIG_LINK:
1307 case MBX_CONFIG_RING:
1308 case MBX_RESET_RING:
1309 case MBX_UNREG_LOGIN:
1310 case MBX_CLEAR_LA:
1311 case MBX_DUMP_CONTEXT:
1312 case MBX_RUN_DIAGS:
1313 case MBX_RESTART:
1314 case MBX_FLASH_WR_ULA:
1315 case MBX_SET_MASK:
1316 case MBX_SET_SLIM:
1317 case MBX_SET_DEBUG:
1318 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1319 printk(KERN_WARNING "mbox_read:Command 0x%x "
1320 "is illegal in on-line state\n",
1321 phba->sysfs_mbox.mbox->mb.mbxCommand);
1322 sysfs_mbox_idle(phba);
1323 spin_unlock_irq(phba->host->host_lock);
1324 return -EPERM;
1325 }
1326 case MBX_LOAD_SM:
1327 case MBX_READ_NV:
1328 case MBX_READ_CONFIG:
1329 case MBX_READ_RCONFIG:
1330 case MBX_READ_STATUS:
1331 case MBX_READ_XRI:
1332 case MBX_READ_REV:
1333 case MBX_READ_LNK_STAT:
1334 case MBX_DUMP_MEMORY:
1335 case MBX_DOWN_LOAD:
1336 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001337 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001338 case MBX_LOAD_AREA:
1339 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001340 case MBX_BEACON:
1341 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001342 break;
1343 case MBX_READ_SPARM64:
1344 case MBX_READ_LA:
1345 case MBX_READ_LA64:
1346 case MBX_REG_LOGIN:
1347 case MBX_REG_LOGIN64:
1348 case MBX_CONFIG_PORT:
1349 case MBX_RUN_BIU_DIAG:
1350 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1351 phba->sysfs_mbox.mbox->mb.mbxCommand);
1352 sysfs_mbox_idle(phba);
1353 spin_unlock_irq(phba->host->host_lock);
1354 return -EPERM;
1355 default:
1356 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1357 phba->sysfs_mbox.mbox->mb.mbxCommand);
1358 sysfs_mbox_idle(phba);
1359 spin_unlock_irq(phba->host->host_lock);
1360 return -EPERM;
1361 }
1362
James Smart46fa3112007-04-25 09:51:45 -04001363 if (phba->fc_flag & FC_BLOCK_MGMT_IO) {
1364 sysfs_mbox_idle(phba);
1365 spin_unlock_irq(host->host_lock);
1366 return -EAGAIN;
1367 }
1368
dea31012005-04-17 16:05:31 -05001369 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1370 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1371
1372 spin_unlock_irq(phba->host->host_lock);
1373 rc = lpfc_sli_issue_mbox (phba,
1374 phba->sysfs_mbox.mbox,
1375 MBX_POLL);
1376 spin_lock_irq(phba->host->host_lock);
1377
1378 } else {
1379 spin_unlock_irq(phba->host->host_lock);
1380 rc = lpfc_sli_issue_mbox_wait (phba,
1381 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001382 lpfc_mbox_tmo_val(phba,
1383 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
dea31012005-04-17 16:05:31 -05001384 spin_lock_irq(phba->host->host_lock);
1385 }
1386
1387 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001388 if (rc == MBX_TIMEOUT) {
1389 phba->sysfs_mbox.mbox->mbox_cmpl =
1390 lpfc_sli_def_mbox_cmpl;
1391 phba->sysfs_mbox.mbox = NULL;
1392 }
dea31012005-04-17 16:05:31 -05001393 sysfs_mbox_idle(phba);
1394 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001395 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001396 }
1397 phba->sysfs_mbox.state = SMBOX_READING;
1398 }
1399 else if (phba->sysfs_mbox.offset != off ||
1400 phba->sysfs_mbox.state != SMBOX_READING) {
1401 printk(KERN_WARNING "mbox_read: Bad State\n");
1402 sysfs_mbox_idle(phba);
1403 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001404 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001405 }
1406
1407 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1408
1409 phba->sysfs_mbox.offset = off + count;
1410
James Smart1dcb58e2007-04-25 09:51:30 -04001411 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001412 sysfs_mbox_idle(phba);
1413
1414 spin_unlock_irq(phba->host->host_lock);
1415
1416 return count;
1417}
1418
1419static struct bin_attribute sysfs_mbox_attr = {
1420 .attr = {
1421 .name = "mbox",
1422 .mode = S_IRUSR | S_IWUSR,
1423 .owner = THIS_MODULE,
1424 },
James Smart1dcb58e2007-04-25 09:51:30 -04001425 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001426 .read = sysfs_mbox_read,
1427 .write = sysfs_mbox_write,
1428};
1429
1430int
1431lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1432{
1433 struct Scsi_Host *host = phba->host;
1434 int error;
1435
1436 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1437 &sysfs_ctlreg_attr);
1438 if (error)
1439 goto out;
1440
1441 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1442 &sysfs_mbox_attr);
1443 if (error)
1444 goto out_remove_ctlreg_attr;
1445
1446 return 0;
1447out_remove_ctlreg_attr:
1448 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1449out:
1450 return error;
1451}
1452
1453void
1454lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1455{
1456 struct Scsi_Host *host = phba->host;
1457
1458 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1459 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1460}
1461
1462
1463/*
1464 * Dynamic FC Host Attributes Support
1465 */
1466
1467static void
1468lpfc_get_host_port_id(struct Scsi_Host *shost)
1469{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001470 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001471 /* note: fc_myDID already in cpu endianness */
1472 fc_host_port_id(shost) = phba->fc_myDID;
1473}
1474
1475static void
1476lpfc_get_host_port_type(struct Scsi_Host *shost)
1477{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001478 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001479
1480 spin_lock_irq(shost->host_lock);
1481
1482 if (phba->hba_state == LPFC_HBA_READY) {
1483 if (phba->fc_topology == TOPOLOGY_LOOP) {
1484 if (phba->fc_flag & FC_PUBLIC_LOOP)
1485 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1486 else
1487 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1488 } else {
1489 if (phba->fc_flag & FC_FABRIC)
1490 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1491 else
1492 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1493 }
1494 } else
1495 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1496
1497 spin_unlock_irq(shost->host_lock);
1498}
1499
1500static void
1501lpfc_get_host_port_state(struct Scsi_Host *shost)
1502{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001503 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001504
1505 spin_lock_irq(shost->host_lock);
1506
1507 if (phba->fc_flag & FC_OFFLINE_MODE)
1508 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1509 else {
1510 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001511 case LPFC_STATE_UNKNOWN:
1512 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001513 case LPFC_INIT_START:
1514 case LPFC_INIT_MBX_CMDS:
1515 case LPFC_LINK_DOWN:
1516 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1517 break;
1518 case LPFC_LINK_UP:
1519 case LPFC_LOCAL_CFG_LINK:
1520 case LPFC_FLOGI:
1521 case LPFC_FABRIC_CFG_LINK:
1522 case LPFC_NS_REG:
1523 case LPFC_NS_QRY:
1524 case LPFC_BUILD_DISC_LIST:
1525 case LPFC_DISC_AUTH:
1526 case LPFC_CLEAR_LA:
1527 case LPFC_HBA_READY:
1528 /* Links up, beyond this port_type reports state */
1529 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1530 break;
1531 case LPFC_HBA_ERROR:
1532 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1533 break;
1534 default:
1535 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1536 break;
1537 }
1538 }
1539
1540 spin_unlock_irq(shost->host_lock);
1541}
1542
1543static void
1544lpfc_get_host_speed(struct Scsi_Host *shost)
1545{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001546 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001547
1548 spin_lock_irq(shost->host_lock);
1549
1550 if (phba->hba_state == LPFC_HBA_READY) {
1551 switch(phba->fc_linkspeed) {
1552 case LA_1GHZ_LINK:
1553 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1554 break;
1555 case LA_2GHZ_LINK:
1556 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1557 break;
1558 case LA_4GHZ_LINK:
1559 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1560 break;
1561 default:
1562 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1563 break;
1564 }
1565 }
1566
1567 spin_unlock_irq(shost->host_lock);
1568}
1569
1570static void
1571lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1572{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001573 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001574 u64 node_name;
dea31012005-04-17 16:05:31 -05001575
1576 spin_lock_irq(shost->host_lock);
1577
1578 if ((phba->fc_flag & FC_FABRIC) ||
1579 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1580 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001581 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001582 else
1583 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001584 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001585
1586 spin_unlock_irq(shost->host_lock);
1587
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001588 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001589}
1590
James Smartae367642006-08-18 17:46:53 -04001591static void
1592lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1593{
1594 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1595
1596 spin_lock_irq(shost->host_lock);
1597 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1598 spin_unlock_irq(shost->host_lock);
1599}
dea31012005-04-17 16:05:31 -05001600
1601static struct fc_host_statistics *
1602lpfc_get_stats(struct Scsi_Host *shost)
1603{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001604 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001605 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001606 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04001607 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05001608 LPFC_MBOXQ_t *pmboxq;
1609 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04001610 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001611 int rc = 0;
dea31012005-04-17 16:05:31 -05001612
James Smart46fa3112007-04-25 09:51:45 -04001613 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1614 return NULL;
1615
dea31012005-04-17 16:05:31 -05001616 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1617 if (!pmboxq)
1618 return NULL;
1619 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1620
1621 pmb = &pmboxq->mb;
1622 pmb->mbxCommand = MBX_READ_STATUS;
1623 pmb->mbxOwner = OWN_HOST;
1624 pmboxq->context1 = NULL;
1625
1626 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001627 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001628 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001629 else
dea31012005-04-17 16:05:31 -05001630 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1631
1632 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001633 if (rc == MBX_TIMEOUT)
1634 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1635 else
1636 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001637 return NULL;
1638 }
1639
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001640 memset(hs, 0, sizeof (struct fc_host_statistics));
1641
dea31012005-04-17 16:05:31 -05001642 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1643 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1644 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1645 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1646
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001647 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001648 pmb->mbxCommand = MBX_READ_LNK_STAT;
1649 pmb->mbxOwner = OWN_HOST;
1650 pmboxq->context1 = NULL;
1651
1652 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001653 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001654 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001655 else
dea31012005-04-17 16:05:31 -05001656 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1657
1658 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001659 if (rc == MBX_TIMEOUT)
1660 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1661 else
1662 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001663 return NULL;
1664 }
1665
1666 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1667 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1668 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1669 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1670 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1671 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1672 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1673
James Smart64ba8812006-08-02 15:24:34 -04001674 hs->link_failure_count -= lso->link_failure_count;
1675 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1676 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1677 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1678 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1679 hs->invalid_crc_count -= lso->invalid_crc_count;
1680 hs->error_frames -= lso->error_frames;
1681
dea31012005-04-17 16:05:31 -05001682 if (phba->fc_topology == TOPOLOGY_LOOP) {
1683 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001684 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001685 hs->nos_count = -1;
1686 } else {
1687 hs->lip_count = -1;
1688 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001689 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001690 }
1691
1692 hs->dumped_frames = -1;
1693
James Smart64ba8812006-08-02 15:24:34 -04001694 seconds = get_seconds();
1695 if (seconds < psli->stats_start)
1696 hs->seconds_since_last_reset = seconds +
1697 ((unsigned long)-1 - psli->stats_start);
1698 else
1699 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05001700
James Smart1dcb58e2007-04-25 09:51:30 -04001701 mempool_free(pmboxq, phba->mbox_mem_pool);
1702
dea31012005-04-17 16:05:31 -05001703 return hs;
1704}
1705
James Smart64ba8812006-08-02 15:24:34 -04001706static void
1707lpfc_reset_stats(struct Scsi_Host *shost)
1708{
1709 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1710 struct lpfc_sli *psli = &phba->sli;
1711 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1712 LPFC_MBOXQ_t *pmboxq;
1713 MAILBOX_t *pmb;
1714 int rc = 0;
1715
James Smart46fa3112007-04-25 09:51:45 -04001716 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1717 return;
1718
James Smart64ba8812006-08-02 15:24:34 -04001719 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1720 if (!pmboxq)
1721 return;
1722 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1723
1724 pmb = &pmboxq->mb;
1725 pmb->mbxCommand = MBX_READ_STATUS;
1726 pmb->mbxOwner = OWN_HOST;
1727 pmb->un.varWords[0] = 0x1; /* reset request */
1728 pmboxq->context1 = NULL;
1729
1730 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1731 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1732 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1733 else
1734 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1735
1736 if (rc != MBX_SUCCESS) {
1737 if (rc == MBX_TIMEOUT)
1738 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1739 else
1740 mempool_free(pmboxq, phba->mbox_mem_pool);
1741 return;
1742 }
1743
1744 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1745 pmb->mbxCommand = MBX_READ_LNK_STAT;
1746 pmb->mbxOwner = OWN_HOST;
1747 pmboxq->context1 = NULL;
1748
1749 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1750 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1751 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1752 else
1753 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1754
1755 if (rc != MBX_SUCCESS) {
1756 if (rc == MBX_TIMEOUT)
1757 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1758 else
1759 mempool_free( pmboxq, phba->mbox_mem_pool);
1760 return;
1761 }
1762
1763 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1764 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1765 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1766 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1767 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1768 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1769 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1770 lso->link_events = (phba->fc_eventTag >> 1);
1771
1772 psli->stats_start = get_seconds();
1773
James Smart1dcb58e2007-04-25 09:51:30 -04001774 mempool_free(pmboxq, phba->mbox_mem_pool);
1775
James Smart64ba8812006-08-02 15:24:34 -04001776 return;
1777}
dea31012005-04-17 16:05:31 -05001778
1779/*
1780 * The LPFC driver treats linkdown handling as target loss events so there
1781 * are no sysfs handlers for link_down_tmo.
1782 */
1783static void
1784lpfc_get_starget_port_id(struct scsi_target *starget)
1785{
1786 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001787 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea31012005-04-17 16:05:31 -05001788 uint32_t did = -1;
1789 struct lpfc_nodelist *ndlp = NULL;
1790
1791 spin_lock_irq(shost->host_lock);
1792 /* Search the mapped list for this target ID */
1793 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1794 if (starget->id == ndlp->nlp_sid) {
1795 did = ndlp->nlp_DID;
1796 break;
1797 }
1798 }
1799 spin_unlock_irq(shost->host_lock);
1800
1801 fc_starget_port_id(starget) = did;
1802}
1803
1804static void
1805lpfc_get_starget_node_name(struct scsi_target *starget)
1806{
1807 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001808 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001809 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001810 struct lpfc_nodelist *ndlp = NULL;
1811
1812 spin_lock_irq(shost->host_lock);
1813 /* Search the mapped list for this target ID */
1814 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1815 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001816 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001817 break;
1818 }
1819 }
1820 spin_unlock_irq(shost->host_lock);
1821
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001822 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001823}
1824
1825static void
1826lpfc_get_starget_port_name(struct scsi_target *starget)
1827{
1828 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001829 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001830 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001831 struct lpfc_nodelist *ndlp = NULL;
1832
1833 spin_lock_irq(shost->host_lock);
1834 /* Search the mapped list for this target ID */
1835 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1836 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001837 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001838 break;
1839 }
1840 }
1841 spin_unlock_irq(shost->host_lock);
1842
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001843 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001844}
1845
1846static void
dea31012005-04-17 16:05:31 -05001847lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1848{
dea31012005-04-17 16:05:31 -05001849 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04001850 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05001851 else
James Smartc01f3202006-08-18 17:47:08 -04001852 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05001853}
1854
1855
1856#define lpfc_rport_show_function(field, format_string, sz, cast) \
1857static ssize_t \
1858lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1859{ \
1860 struct fc_rport *rport = transport_class_to_rport(cdev); \
1861 struct lpfc_rport_data *rdata = rport->hostdata; \
1862 return snprintf(buf, sz, format_string, \
1863 (rdata->target) ? cast rdata->target->field : 0); \
1864}
1865
1866#define lpfc_rport_rd_attr(field, format_string, sz) \
1867 lpfc_rport_show_function(field, format_string, sz, ) \
1868static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1869
1870
1871struct fc_function_template lpfc_transport_functions = {
1872 /* fixed attributes the driver supports */
1873 .show_host_node_name = 1,
1874 .show_host_port_name = 1,
1875 .show_host_supported_classes = 1,
1876 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05001877 .show_host_supported_speeds = 1,
1878 .show_host_maxframe_size = 1,
1879
1880 /* dynamic attributes the driver supports */
1881 .get_host_port_id = lpfc_get_host_port_id,
1882 .show_host_port_id = 1,
1883
1884 .get_host_port_type = lpfc_get_host_port_type,
1885 .show_host_port_type = 1,
1886
1887 .get_host_port_state = lpfc_get_host_port_state,
1888 .show_host_port_state = 1,
1889
1890 /* active_fc4s is shown but doesn't change (thus no get function) */
1891 .show_host_active_fc4s = 1,
1892
1893 .get_host_speed = lpfc_get_host_speed,
1894 .show_host_speed = 1,
1895
1896 .get_host_fabric_name = lpfc_get_host_fabric_name,
1897 .show_host_fabric_name = 1,
1898
James Smartae367642006-08-18 17:46:53 -04001899 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1900 .show_host_symbolic_name = 1,
1901
dea31012005-04-17 16:05:31 -05001902 /*
1903 * The LPFC driver treats linkdown handling as target loss events
1904 * so there are no sysfs handlers for link_down_tmo.
1905 */
1906
1907 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04001908 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05001909
1910 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1911 .show_rport_maxframe_size = 1,
1912 .show_rport_supported_classes = 1,
1913
dea31012005-04-17 16:05:31 -05001914 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1915 .show_rport_dev_loss_tmo = 1,
1916
1917 .get_starget_port_id = lpfc_get_starget_port_id,
1918 .show_starget_port_id = 1,
1919
1920 .get_starget_node_name = lpfc_get_starget_node_name,
1921 .show_starget_node_name = 1,
1922
1923 .get_starget_port_name = lpfc_get_starget_port_name,
1924 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001925
1926 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04001927 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1928 .terminate_rport_io = lpfc_terminate_rport_io,
dea31012005-04-17 16:05:31 -05001929};
1930
1931void
1932lpfc_get_cfgparam(struct lpfc_hba *phba)
1933{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001934 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1935 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1936 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001937 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05001938 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1939 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001940 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1941 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1942 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1943 lpfc_ack0_init(phba, lpfc_ack0);
1944 lpfc_topology_init(phba, lpfc_topology);
1945 lpfc_scan_down_init(phba, lpfc_scan_down);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001946 lpfc_link_speed_init(phba, lpfc_link_speed);
1947 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1948 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1949 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001950 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart4ff43242006-12-02 13:34:56 -05001951 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartc01f3202006-08-18 17:47:08 -04001952 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1953 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001954 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05001955 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04001956 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05001957
1958 /*
1959 * The total number of segments is the configuration value plus 2
1960 * since the IOCB need a command and response bde.
1961 */
1962 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1963
1964 /*
1965 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1966 * used to create the sg_dma_buf_pool must be dynamically calculated
1967 */
1968 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1969 sizeof(struct fcp_rsp) +
1970 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1971
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001972
James Smart7054a602007-04-25 09:52:34 -04001973 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001974
dea31012005-04-17 16:05:31 -05001975 return;
1976}