blob: 9496e87c135ea2fcd8ee56afe1b603f703806da7 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
Jamie Wellnitz41415862006-02-28 19:25:27 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_tcq.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_hw.h"
33#include "lpfc_sli.h"
34#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_version.h"
39#include "lpfc_compat.h"
40#include "lpfc_crtn.h"
41
James Smartc01f3202006-08-18 17:47:08 -040042#define LPFC_DEF_DEVLOSS_TMO 30
43#define LPFC_MIN_DEVLOSS_TMO 1
44#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050045
46static void
47lpfc_jedec_to_ascii(int incr, char hdw[])
48{
49 int i, j;
50 for (i = 0; i < 8; i++) {
51 j = (incr & 0xf);
52 if (j <= 9)
53 hdw[7 - i] = 0x30 + j;
54 else
55 hdw[7 - i] = 0x61 + j - 10;
56 incr = (incr >> 4);
57 }
58 hdw[8] = 0;
59 return;
60}
61
62static ssize_t
63lpfc_drvr_version_show(struct class_device *cdev, char *buf)
64{
65 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
66}
67
68static ssize_t
69management_version_show(struct class_device *cdev, char *buf)
70{
71 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
72}
73
74static ssize_t
75lpfc_info_show(struct class_device *cdev, char *buf)
76{
77 struct Scsi_Host *host = class_to_shost(cdev);
78 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
79}
80
81static ssize_t
82lpfc_serialnum_show(struct class_device *cdev, char *buf)
83{
84 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050085 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050086 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
87}
88
89static ssize_t
90lpfc_modeldesc_show(struct class_device *cdev, char *buf)
91{
92 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050093 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050094 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
95}
96
97static ssize_t
98lpfc_modelname_show(struct class_device *cdev, char *buf)
99{
100 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500101 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500102 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
103}
104
105static ssize_t
106lpfc_programtype_show(struct class_device *cdev, char *buf)
107{
108 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500109 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
111}
112
113static ssize_t
114lpfc_portnum_show(struct class_device *cdev, char *buf)
115{
116 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500117 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500118 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
119}
120
121static ssize_t
122lpfc_fwrev_show(struct class_device *cdev, char *buf)
123{
124 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500125 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500126 char fwrev[32];
127 lpfc_decode_firmware_rev(phba, fwrev, 1);
128 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
129}
130
131static ssize_t
132lpfc_hdw_show(struct class_device *cdev, char *buf)
133{
134 char hdw[9];
135 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500136 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500137 lpfc_vpd_t *vp = &phba->vpd;
138 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
139 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
140}
141static ssize_t
142lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
143{
144 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500145 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500146 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
147}
148static ssize_t
149lpfc_state_show(struct class_device *cdev, char *buf)
150{
151 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500152 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500153 int len = 0;
154 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500155 case LPFC_STATE_UNKNOWN:
156 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500157 case LPFC_INIT_START:
158 case LPFC_INIT_MBX_CMDS:
159 case LPFC_LINK_DOWN:
160 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
161 break;
162 case LPFC_LINK_UP:
163 case LPFC_LOCAL_CFG_LINK:
164 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
165 break;
166 case LPFC_FLOGI:
167 case LPFC_FABRIC_CFG_LINK:
168 case LPFC_NS_REG:
169 case LPFC_NS_QRY:
170 case LPFC_BUILD_DISC_LIST:
171 case LPFC_DISC_AUTH:
172 case LPFC_CLEAR_LA:
173 len += snprintf(buf + len, PAGE_SIZE-len,
174 "Link Up - Discovery\n");
175 break;
176 case LPFC_HBA_READY:
177 len += snprintf(buf + len, PAGE_SIZE-len,
178 "Link Up - Ready:\n");
179 if (phba->fc_topology == TOPOLOGY_LOOP) {
180 if (phba->fc_flag & FC_PUBLIC_LOOP)
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Public Loop\n");
183 else
184 len += snprintf(buf + len, PAGE_SIZE-len,
185 " Private Loop\n");
186 } else {
187 if (phba->fc_flag & FC_FABRIC)
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Fabric\n");
190 else
191 len += snprintf(buf + len, PAGE_SIZE-len,
192 " Point-2-Point\n");
193 }
194 }
195 return len;
196}
197
198static ssize_t
199lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
200{
201 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500202 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500203 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
204 phba->fc_unmap_cnt);
205}
206
207
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700208static int
209lpfc_issue_lip(struct Scsi_Host *host)
dea31012005-04-17 16:05:31 -0500210{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500211 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea31012005-04-17 16:05:31 -0500212 LPFC_MBOXQ_t *pmboxq;
213 int mbxstatus = MBXERR_ERROR;
214
dea31012005-04-17 16:05:31 -0500215 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
216 (phba->hba_state != LPFC_HBA_READY))
217 return -EPERM;
218
219 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
220
221 if (!pmboxq)
222 return -ENOMEM;
223
224 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400225 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
226 pmboxq->mb.mbxOwner = OWN_HOST;
227
James Smart33ccf8d2006-08-17 11:57:58 -0400228 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500229
James Smart4db621e2006-07-06 15:49:49 -0400230 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
231 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
232 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
233 phba->cfg_link_speed);
234 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
235 phba->fc_ratov * 2);
236 }
237
dea31012005-04-17 16:05:31 -0500238 if (mbxstatus == MBX_TIMEOUT)
239 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
240 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400241 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500242
243 if (mbxstatus == MBXERR_ERROR)
244 return -EIO;
245
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700246 return 0;
dea31012005-04-17 16:05:31 -0500247}
248
James Smart40496f02006-07-06 15:50:22 -0400249static int
250lpfc_selective_reset(struct lpfc_hba *phba)
251{
252 struct completion online_compl;
253 int status = 0;
254
255 init_completion(&online_compl);
256 lpfc_workq_post_event(phba, &status, &online_compl,
257 LPFC_EVT_OFFLINE);
258 wait_for_completion(&online_compl);
259
260 if (status != 0)
261 return -EIO;
262
263 init_completion(&online_compl);
264 lpfc_workq_post_event(phba, &status, &online_compl,
265 LPFC_EVT_ONLINE);
266 wait_for_completion(&online_compl);
267
268 if (status != 0)
269 return -EIO;
270
271 return 0;
272}
273
274static ssize_t
275lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
276{
277 struct Scsi_Host *host = class_to_shost(cdev);
278 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
279 int status = -EINVAL;
280
281 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
282 status = lpfc_selective_reset(phba);
283
284 if (status == 0)
285 return strlen(buf);
286 else
287 return status;
288}
289
dea31012005-04-17 16:05:31 -0500290static ssize_t
291lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
292{
293 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500294 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500295 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
296}
297
298static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500299lpfc_board_mode_show(struct class_device *cdev, char *buf)
300{
301 struct Scsi_Host *host = class_to_shost(cdev);
302 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
303 char * state;
304
305 if (phba->hba_state == LPFC_HBA_ERROR)
306 state = "error";
307 else if (phba->hba_state == LPFC_WARM_START)
308 state = "warm start";
309 else if (phba->hba_state == LPFC_INIT_START)
310 state = "offline";
311 else
312 state = "online";
313
314 return snprintf(buf, PAGE_SIZE, "%s\n", state);
315}
316
317static ssize_t
318lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
319{
320 struct Scsi_Host *host = class_to_shost(cdev);
321 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
322 struct completion online_compl;
323 int status=0;
324
325 init_completion(&online_compl);
326
327 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
328 lpfc_workq_post_event(phba, &status, &online_compl,
329 LPFC_EVT_ONLINE);
330 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
331 lpfc_workq_post_event(phba, &status, &online_compl,
332 LPFC_EVT_OFFLINE);
333 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
334 lpfc_workq_post_event(phba, &status, &online_compl,
335 LPFC_EVT_WARM_START);
336 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
337 lpfc_workq_post_event(phba, &status, &online_compl,
338 LPFC_EVT_KILL);
339 else
340 return -EINVAL;
341
342 wait_for_completion(&online_compl);
343
344 if (!status)
345 return strlen(buf);
346 else
347 return -EIO;
348}
349
350static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500351lpfc_poll_show(struct class_device *cdev, char *buf)
352{
353 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500354 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500355
356 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
357}
358
359static ssize_t
360lpfc_poll_store(struct class_device *cdev, const char *buf,
361 size_t count)
362{
363 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500364 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500365 uint32_t creg_val;
366 uint32_t old_val;
367 int val=0;
368
369 if (!isdigit(buf[0]))
370 return -EINVAL;
371
372 if (sscanf(buf, "%i", &val) != 1)
373 return -EINVAL;
374
375 if ((val & 0x3) != val)
376 return -EINVAL;
377
378 spin_lock_irq(phba->host->host_lock);
379
380 old_val = phba->cfg_poll;
381
382 if (val & ENABLE_FCP_RING_POLLING) {
383 if ((val & DISABLE_FCP_RING_INT) &&
384 !(old_val & DISABLE_FCP_RING_INT)) {
385 creg_val = readl(phba->HCregaddr);
386 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
387 writel(creg_val, phba->HCregaddr);
388 readl(phba->HCregaddr); /* flush */
389
390 lpfc_poll_start_timer(phba);
391 }
392 } else if (val != 0x0) {
393 spin_unlock_irq(phba->host->host_lock);
394 return -EINVAL;
395 }
396
397 if (!(val & DISABLE_FCP_RING_INT) &&
398 (old_val & DISABLE_FCP_RING_INT))
399 {
400 spin_unlock_irq(phba->host->host_lock);
401 del_timer(&phba->fcp_poll_timer);
402 spin_lock_irq(phba->host->host_lock);
403 creg_val = readl(phba->HCregaddr);
404 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
405 writel(creg_val, phba->HCregaddr);
406 readl(phba->HCregaddr); /* flush */
407 }
408
409 phba->cfg_poll = val;
410
411 spin_unlock_irq(phba->host->host_lock);
412
413 return strlen(buf);
414}
dea31012005-04-17 16:05:31 -0500415
416#define lpfc_param_show(attr) \
417static ssize_t \
418lpfc_##attr##_show(struct class_device *cdev, char *buf) \
419{ \
420 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500421 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea31012005-04-17 16:05:31 -0500422 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400423 val = phba->cfg_##attr;\
424 return snprintf(buf, PAGE_SIZE, "%d\n",\
425 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500426}
427
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400428#define lpfc_param_hex_show(attr) \
429static ssize_t \
430lpfc_##attr##_show(struct class_device *cdev, char *buf) \
431{ \
432 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500433 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400434 int val = 0;\
435 val = phba->cfg_##attr;\
436 return snprintf(buf, PAGE_SIZE, "%#x\n",\
437 phba->cfg_##attr);\
438}
439
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400440#define lpfc_param_init(attr, default, minval, maxval) \
441static int \
442lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
443{ \
444 if (val >= minval && val <= maxval) {\
445 phba->cfg_##attr = val;\
446 return 0;\
447 }\
448 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
449 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
450 "allowed range is ["#minval", "#maxval"]\n", \
451 phba->brd_no, val); \
452 phba->cfg_##attr = default;\
453 return -EINVAL;\
454}
455
456#define lpfc_param_set(attr, default, minval, maxval) \
457static int \
458lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
459{ \
460 if (val >= minval && val <= maxval) {\
461 phba->cfg_##attr = val;\
462 return 0;\
463 }\
464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
465 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
466 "allowed range is ["#minval", "#maxval"]\n", \
467 phba->brd_no, val); \
468 return -EINVAL;\
469}
470
471#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500472static ssize_t \
473lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
474{ \
475 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500476 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400477 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400478 if (!isdigit(buf[0]))\
479 return -EINVAL;\
480 if (sscanf(buf, "%i", &val) != 1)\
481 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400482 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400483 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400484 else \
485 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500486}
487
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400488#define LPFC_ATTR(name, defval, minval, maxval, desc) \
489static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500490module_param(lpfc_##name, int, 0);\
491MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400492lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500493
494#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
495static int lpfc_##name = defval;\
496module_param(lpfc_##name, int, 0);\
497MODULE_PARM_DESC(lpfc_##name, desc);\
498lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400499lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500500static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
501
502#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
503static int lpfc_##name = defval;\
504module_param(lpfc_##name, int, 0);\
505MODULE_PARM_DESC(lpfc_##name, desc);\
506lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400507lpfc_param_init(name, defval, minval, maxval)\
508lpfc_param_set(name, defval, minval, maxval)\
509lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500510static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
511 lpfc_##name##_show, lpfc_##name##_store)
512
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400513#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
514static int lpfc_##name = defval;\
515module_param(lpfc_##name, int, 0);\
516MODULE_PARM_DESC(lpfc_##name, desc);\
517lpfc_param_hex_show(name)\
518lpfc_param_init(name, defval, minval, maxval)\
519static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
520
521#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
522static int lpfc_##name = defval;\
523module_param(lpfc_##name, int, 0);\
524MODULE_PARM_DESC(lpfc_##name, desc);\
525lpfc_param_hex_show(name)\
526lpfc_param_init(name, defval, minval, maxval)\
527lpfc_param_set(name, defval, minval, maxval)\
528lpfc_param_store(name)\
529static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
530 lpfc_##name##_show, lpfc_##name##_store)
531
dea31012005-04-17 16:05:31 -0500532static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
533static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
534static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
535static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
536static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
537static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
538static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
539static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
540static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
541static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
542 lpfc_option_rom_version_show, NULL);
543static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
544 lpfc_num_discovered_ports_show, NULL);
545static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
546static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
547 NULL);
548static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
549 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500550static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
551 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400552static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea31012005-04-17 16:05:31 -0500553
James Smartc3f28af2006-08-18 17:47:18 -0400554
555static char *lpfc_soft_wwpn_key = "C99G71SL8032A";
556
557static ssize_t
558lpfc_soft_wwpn_enable_store(struct class_device *cdev, const char *buf,
559 size_t count)
560{
561 struct Scsi_Host *host = class_to_shost(cdev);
562 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
563 unsigned int cnt = count;
564
565 /*
566 * We're doing a simple sanity check for soft_wwpn setting.
567 * We require that the user write a specific key to enable
568 * the soft_wwpn attribute to be settable. Once the attribute
569 * is written, the enable key resets. If further updates are
570 * desired, the key must be written again to re-enable the
571 * attribute.
572 *
573 * The "key" is not secret - it is a hardcoded string shown
574 * here. The intent is to protect against the random user or
575 * application that is just writing attributes.
576 */
577
578 /* count may include a LF at end of string */
579 if (buf[cnt-1] == '\n')
580 cnt--;
581
582 if ((cnt != strlen(lpfc_soft_wwpn_key)) ||
583 (strncmp(buf, lpfc_soft_wwpn_key, strlen(lpfc_soft_wwpn_key)) != 0))
584 return -EINVAL;
585
586 phba->soft_wwpn_enable = 1;
587 return count;
588}
589static CLASS_DEVICE_ATTR(lpfc_soft_wwpn_enable, S_IWUSR, NULL,
590 lpfc_soft_wwpn_enable_store);
591
592static ssize_t
593lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
594{
595 struct Scsi_Host *host = class_to_shost(cdev);
596 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
597 return snprintf(buf, PAGE_SIZE, "0x%llx\n", phba->cfg_soft_wwpn);
598}
599
600
601static ssize_t
602lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
603{
604 struct Scsi_Host *host = class_to_shost(cdev);
605 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
606 struct completion online_compl;
607 int stat1=0, stat2=0;
608 unsigned int i, j, cnt=count;
609 u8 wwpn[8];
610
611 /* count may include a LF at end of string */
612 if (buf[cnt-1] == '\n')
613 cnt--;
614
615 if (!phba->soft_wwpn_enable || (cnt < 16) || (cnt > 18) ||
616 ((cnt == 17) && (*buf++ != 'x')) ||
617 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
618 return -EINVAL;
619
620 phba->soft_wwpn_enable = 0;
621
622 memset(wwpn, 0, sizeof(wwpn));
623
624 /* Validate and store the new name */
625 for (i=0, j=0; i < 16; i++) {
626 if ((*buf >= 'a') && (*buf <= 'f'))
627 j = ((j << 4) | ((*buf++ -'a') + 10));
628 else if ((*buf >= 'A') && (*buf <= 'F'))
629 j = ((j << 4) | ((*buf++ -'A') + 10));
630 else if ((*buf >= '0') && (*buf <= '9'))
631 j = ((j << 4) | (*buf++ -'0'));
632 else
633 return -EINVAL;
634 if (i % 2) {
635 wwpn[i/2] = j & 0xff;
636 j = 0;
637 }
638 }
639 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
640 fc_host_port_name(host) = phba->cfg_soft_wwpn;
641
642 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
643 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
644
645 init_completion(&online_compl);
646 lpfc_workq_post_event(phba, &stat1, &online_compl, LPFC_EVT_OFFLINE);
647 wait_for_completion(&online_compl);
648 if (stat1)
649 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
650 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
651 "adapter - %d\n", phba->brd_no, stat1);
652
653 init_completion(&online_compl);
654 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
655 wait_for_completion(&online_compl);
656 if (stat2)
657 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
658 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
659 "adapter - %d\n", phba->brd_no, stat2);
660
661 return (stat1 || stat2) ? -EIO : count;
662}
663static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
664 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
665
666
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500667static int lpfc_poll = 0;
668module_param(lpfc_poll, int, 0);
669MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
670 " 0 - none,"
671 " 1 - poll with interrupts enabled"
672 " 3 - poll and disable FCP ring interrupts");
673
674static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
675 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500676
677/*
James Smartc01f3202006-08-18 17:47:08 -0400678# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
679# until the timer expires. Value range is [0,255]. Default value is 30.
680*/
681static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
682static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
683module_param(lpfc_nodev_tmo, int, 0);
684MODULE_PARM_DESC(lpfc_nodev_tmo,
685 "Seconds driver will hold I/O waiting "
686 "for a device to come back");
687static ssize_t
688lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
689{
690 struct Scsi_Host *host = class_to_shost(cdev);
691 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
692 int val = 0;
693 val = phba->cfg_devloss_tmo;
694 return snprintf(buf, PAGE_SIZE, "%d\n",
695 phba->cfg_devloss_tmo);
696}
697
698static int
699lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
700{
701 static int warned;
702 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
703 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
704 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
705 warned = 1;
706 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
707 "%d:0402 Ignoring nodev_tmo module "
708 "parameter because devloss_tmo is"
709 " set.\n",
710 phba->brd_no);
711 }
712 return 0;
713 }
714
715 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
716 phba->cfg_nodev_tmo = val;
717 phba->cfg_devloss_tmo = val;
718 return 0;
719 }
720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
721 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
722 "allowed range is [%d, %d]\n",
723 phba->brd_no, val,
724 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
725 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
726 return -EINVAL;
727}
728
729static int
730lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
731{
732 if (phba->dev_loss_tmo_changed ||
733 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
734 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
735 "%d:0401 Ignoring change to nodev_tmo "
736 "because devloss_tmo is set.\n",
737 phba->brd_no);
738 return 0;
739 }
740
741 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
742 phba->cfg_nodev_tmo = val;
743 phba->cfg_devloss_tmo = val;
744 return 0;
745 }
746
747 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
748 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
749 "allowed range is [%d, %d]\n",
750 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
751 LPFC_MAX_DEVLOSS_TMO);
752 return -EINVAL;
753}
754
755lpfc_param_store(nodev_tmo)
756
757static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
758 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
759
760/*
761# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
762# disappear until the timer expires. Value range is [0,255]. Default
763# value is 30.
764*/
765module_param(lpfc_devloss_tmo, int, 0);
766MODULE_PARM_DESC(lpfc_devloss_tmo,
767 "Seconds driver will hold I/O waiting "
768 "for a device to come back");
769lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
770 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
771lpfc_param_show(devloss_tmo)
772static int
773lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
774{
775 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
776 phba->cfg_nodev_tmo = val;
777 phba->cfg_devloss_tmo = val;
778 phba->dev_loss_tmo_changed = 1;
779 return 0;
780 }
781
782 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
783 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
784 " %d, allowed range is [%d, %d]\n",
785 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
786 LPFC_MAX_DEVLOSS_TMO);
787 return -EINVAL;
788}
789
790lpfc_param_store(devloss_tmo)
791static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
792 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
793
794/*
dea31012005-04-17 16:05:31 -0500795# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
796# deluged with LOTS of information.
797# You can set a bit mask to record specific types of verbose messages:
798#
799# LOG_ELS 0x1 ELS events
800# LOG_DISCOVERY 0x2 Link discovery events
801# LOG_MBOX 0x4 Mailbox events
802# LOG_INIT 0x8 Initialization events
803# LOG_LINK_EVENT 0x10 Link events
804# LOG_IP 0x20 IP traffic history
805# LOG_FCP 0x40 FCP traffic history
806# LOG_NODE 0x80 Node table events
807# LOG_MISC 0x400 Miscellaneous events
808# LOG_SLI 0x800 SLI events
809# LOG_CHK_COND 0x1000 FCP Check condition flag
810# LOG_LIBDFC 0x2000 LIBDFC events
811# LOG_ALL_MSG 0xffff LOG all messages
812*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400813LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500814
815/*
816# lun_queue_depth: This parameter is used to limit the number of outstanding
817# commands per FCP LUN. Value range is [1,128]. Default value is 30.
818*/
819LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
820 "Max number of FCP commands we can queue to a specific LUN");
821
822/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500823# hba_queue_depth: This parameter is used to limit the number of outstanding
824# commands per lpfc HBA. Value range is [32,8192]. If this parameter
825# value is greater than the maximum number of exchanges supported by the HBA,
826# then maximum number of exchanges supported by the HBA is used to determine
827# the hba_queue_depth.
828*/
829LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
830 "Max number of FCP commands we can queue to a lpfc HBA");
831
832/*
dea31012005-04-17 16:05:31 -0500833# Some disk devices have a "select ID" or "select Target" capability.
834# From a protocol standpoint "select ID" usually means select the
835# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
836# annex" which contains a table that maps a "select ID" (a number
837# between 0 and 7F) to an ALPA. By default, for compatibility with
838# older drivers, the lpfc driver scans this table from low ALPA to high
839# ALPA.
840#
841# Turning on the scan-down variable (on = 1, off = 0) will
842# cause the lpfc driver to use an inverted table, effectively
843# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
844#
845# (Note: This "select ID" functionality is a LOOP ONLY characteristic
846# and will not work across a fabric. Also this parameter will take
847# effect only in the case when ALPA map is not available.)
848*/
849LPFC_ATTR_R(scan_down, 1, 0, 1,
850 "Start scanning for devices from highest ALPA to lowest");
851
852/*
dea31012005-04-17 16:05:31 -0500853# lpfc_topology: link topology for init link
854# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500855# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500856# 0x02 = attempt point-to-point mode only
857# 0x04 = attempt loop mode only
858# 0x06 = attempt point-to-point mode then loop
859# Set point-to-point mode if you want to run as an N_Port.
860# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
861# Default value is 0.
862*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500863LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500864
865/*
866# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
867# connection.
868# 0 = auto select (default)
869# 1 = 1 Gigabaud
870# 2 = 2 Gigabaud
871# 4 = 4 Gigabaud
872# Value range is [0,4]. Default value is 0.
873*/
874LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
875
876/*
877# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
878# Value range is [2,3]. Default value is 3.
879*/
880LPFC_ATTR_R(fcp_class, 3, 2, 3,
881 "Select Fibre Channel class of service for FCP sequences");
882
883/*
884# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
885# is [0,1]. Default value is 0.
886*/
887LPFC_ATTR_RW(use_adisc, 0, 0, 1,
888 "Use ADISC on rediscovery to authenticate FCP devices");
889
890/*
891# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
892# range is [0,1]. Default value is 0.
893*/
894LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
895
896/*
897# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
898# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
899# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
900# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
901# cr_delay is set to 0.
902*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500903LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -0500904 "interrupt response is generated");
905
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500906LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -0500907 "interrupt response is generated");
908
909/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500910# lpfc_multi_ring_support: Determines how many rings to spread available
911# cmd/rsp IOCB entries across.
912# Value range is [1,2]. Default value is 1.
913*/
914LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
915 "SLI rings to spread IOCB entries across");
916
917/*
dea31012005-04-17 16:05:31 -0500918# lpfc_fdmi_on: controls FDMI support.
919# 0 = no FDMI support
920# 1 = support FDMI without attribute of hostname
921# 2 = support FDMI with attribute of hostname
922# Value range [0,2]. Default value is 0.
923*/
924LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
925
926/*
927# Specifies the maximum number of ELS cmds we can have outstanding (for
928# discovery). Value range is [1,64]. Default value = 32.
929*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500930LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -0500931 "during discovery");
932
933/*
James Smart65a29c12006-07-06 15:50:50 -0400934# lpfc_max_luns: maximum allowed LUN.
935# Value range is [0,65535]. Default value is 255.
936# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -0500937*/
James Smart65a29c12006-07-06 15:50:50 -0400938LPFC_ATTR_R(max_luns, 255, 0, 65535,
939 "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -0500940
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500941/*
942# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
943# Value range is [1,255], default value is 10.
944*/
945LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
946 "Milliseconds driver will wait between polling FCP ring");
947
James Smartc3f28af2006-08-18 17:47:18 -0400948
dea31012005-04-17 16:05:31 -0500949struct class_device_attribute *lpfc_host_attrs[] = {
950 &class_device_attr_info,
951 &class_device_attr_serialnum,
952 &class_device_attr_modeldesc,
953 &class_device_attr_modelname,
954 &class_device_attr_programtype,
955 &class_device_attr_portnum,
956 &class_device_attr_fwrev,
957 &class_device_attr_hdw,
958 &class_device_attr_option_rom_version,
959 &class_device_attr_state,
960 &class_device_attr_num_discovered_ports,
961 &class_device_attr_lpfc_drvr_version,
962 &class_device_attr_lpfc_log_verbose,
963 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500964 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -0500965 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -0400966 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -0500967 &class_device_attr_lpfc_fcp_class,
968 &class_device_attr_lpfc_use_adisc,
969 &class_device_attr_lpfc_ack0,
970 &class_device_attr_lpfc_topology,
971 &class_device_attr_lpfc_scan_down,
972 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500973 &class_device_attr_lpfc_cr_delay,
974 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500975 &class_device_attr_lpfc_multi_ring_support,
dea31012005-04-17 16:05:31 -0500976 &class_device_attr_lpfc_fdmi_on,
977 &class_device_attr_lpfc_max_luns,
978 &class_device_attr_nport_evt_cnt,
979 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500980 &class_device_attr_board_mode,
James Smart40496f02006-07-06 15:50:22 -0400981 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500982 &class_device_attr_lpfc_poll,
983 &class_device_attr_lpfc_poll_tmo,
James Smartc3f28af2006-08-18 17:47:18 -0400984 &class_device_attr_lpfc_soft_wwpn,
985 &class_device_attr_lpfc_soft_wwpn_enable,
dea31012005-04-17 16:05:31 -0500986 NULL,
987};
988
989static ssize_t
990sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
991{
992 size_t buf_off;
993 struct Scsi_Host *host = class_to_shost(container_of(kobj,
994 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500995 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500996
997 if ((off + count) > FF_REG_AREA_SIZE)
998 return -ERANGE;
999
1000 if (count == 0) return 0;
1001
1002 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1003 return -EINVAL;
1004
1005 spin_lock_irq(phba->host->host_lock);
1006
1007 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1008 spin_unlock_irq(phba->host->host_lock);
1009 return -EPERM;
1010 }
1011
1012 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1013 writel(*((uint32_t *)(buf + buf_off)),
1014 phba->ctrl_regs_memmap_p + off + buf_off);
1015
1016 spin_unlock_irq(phba->host->host_lock);
1017
1018 return count;
1019}
1020
1021static ssize_t
1022sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1023{
1024 size_t buf_off;
1025 uint32_t * tmp_ptr;
1026 struct Scsi_Host *host = class_to_shost(container_of(kobj,
1027 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001028 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001029
1030 if (off > FF_REG_AREA_SIZE)
1031 return -ERANGE;
1032
1033 if ((off + count) > FF_REG_AREA_SIZE)
1034 count = FF_REG_AREA_SIZE - off;
1035
1036 if (count == 0) return 0;
1037
1038 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1039 return -EINVAL;
1040
1041 spin_lock_irq(phba->host->host_lock);
1042
1043 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1044 tmp_ptr = (uint32_t *)(buf + buf_off);
1045 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1046 }
1047
1048 spin_unlock_irq(phba->host->host_lock);
1049
1050 return count;
1051}
1052
1053static struct bin_attribute sysfs_ctlreg_attr = {
1054 .attr = {
1055 .name = "ctlreg",
1056 .mode = S_IRUSR | S_IWUSR,
1057 .owner = THIS_MODULE,
1058 },
1059 .size = 256,
1060 .read = sysfs_ctlreg_read,
1061 .write = sysfs_ctlreg_write,
1062};
1063
1064
1065static void
1066sysfs_mbox_idle (struct lpfc_hba * phba)
1067{
1068 phba->sysfs_mbox.state = SMBOX_IDLE;
1069 phba->sysfs_mbox.offset = 0;
1070
1071 if (phba->sysfs_mbox.mbox) {
1072 mempool_free(phba->sysfs_mbox.mbox,
1073 phba->mbox_mem_pool);
1074 phba->sysfs_mbox.mbox = NULL;
1075 }
1076}
1077
1078static ssize_t
1079sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1080{
1081 struct Scsi_Host * host =
1082 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001083 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001084 struct lpfcMboxq * mbox = NULL;
1085
1086 if ((count + off) > MAILBOX_CMD_SIZE)
1087 return -ERANGE;
1088
1089 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1090 return -EINVAL;
1091
1092 if (count == 0)
1093 return 0;
1094
1095 if (off == 0) {
1096 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1097 if (!mbox)
1098 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001099 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001100 }
1101
1102 spin_lock_irq(host->host_lock);
1103
1104 if (off == 0) {
1105 if (phba->sysfs_mbox.mbox)
1106 mempool_free(mbox, phba->mbox_mem_pool);
1107 else
1108 phba->sysfs_mbox.mbox = mbox;
1109 phba->sysfs_mbox.state = SMBOX_WRITING;
1110 } else {
1111 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1112 phba->sysfs_mbox.offset != off ||
1113 phba->sysfs_mbox.mbox == NULL ) {
1114 sysfs_mbox_idle(phba);
1115 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001116 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001117 }
1118 }
1119
1120 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1121 buf, count);
1122
1123 phba->sysfs_mbox.offset = off + count;
1124
1125 spin_unlock_irq(host->host_lock);
1126
1127 return count;
1128}
1129
1130static ssize_t
1131sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1132{
1133 struct Scsi_Host *host =
1134 class_to_shost(container_of(kobj, struct class_device,
1135 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001136 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -05001137 int rc;
1138
1139 if (off > sizeof(MAILBOX_t))
1140 return -ERANGE;
1141
1142 if ((count + off) > sizeof(MAILBOX_t))
1143 count = sizeof(MAILBOX_t) - off;
1144
1145 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1146 return -EINVAL;
1147
1148 if (off && count == 0)
1149 return 0;
1150
1151 spin_lock_irq(phba->host->host_lock);
1152
1153 if (off == 0 &&
1154 phba->sysfs_mbox.state == SMBOX_WRITING &&
1155 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1156
1157 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1158 /* Offline only */
1159 case MBX_WRITE_NV:
1160 case MBX_INIT_LINK:
1161 case MBX_DOWN_LINK:
1162 case MBX_CONFIG_LINK:
1163 case MBX_CONFIG_RING:
1164 case MBX_RESET_RING:
1165 case MBX_UNREG_LOGIN:
1166 case MBX_CLEAR_LA:
1167 case MBX_DUMP_CONTEXT:
1168 case MBX_RUN_DIAGS:
1169 case MBX_RESTART:
1170 case MBX_FLASH_WR_ULA:
1171 case MBX_SET_MASK:
1172 case MBX_SET_SLIM:
1173 case MBX_SET_DEBUG:
1174 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1175 printk(KERN_WARNING "mbox_read:Command 0x%x "
1176 "is illegal in on-line state\n",
1177 phba->sysfs_mbox.mbox->mb.mbxCommand);
1178 sysfs_mbox_idle(phba);
1179 spin_unlock_irq(phba->host->host_lock);
1180 return -EPERM;
1181 }
1182 case MBX_LOAD_SM:
1183 case MBX_READ_NV:
1184 case MBX_READ_CONFIG:
1185 case MBX_READ_RCONFIG:
1186 case MBX_READ_STATUS:
1187 case MBX_READ_XRI:
1188 case MBX_READ_REV:
1189 case MBX_READ_LNK_STAT:
1190 case MBX_DUMP_MEMORY:
1191 case MBX_DOWN_LOAD:
1192 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001193 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001194 case MBX_LOAD_AREA:
1195 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001196 case MBX_BEACON:
1197 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001198 break;
1199 case MBX_READ_SPARM64:
1200 case MBX_READ_LA:
1201 case MBX_READ_LA64:
1202 case MBX_REG_LOGIN:
1203 case MBX_REG_LOGIN64:
1204 case MBX_CONFIG_PORT:
1205 case MBX_RUN_BIU_DIAG:
1206 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1207 phba->sysfs_mbox.mbox->mb.mbxCommand);
1208 sysfs_mbox_idle(phba);
1209 spin_unlock_irq(phba->host->host_lock);
1210 return -EPERM;
1211 default:
1212 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1213 phba->sysfs_mbox.mbox->mb.mbxCommand);
1214 sysfs_mbox_idle(phba);
1215 spin_unlock_irq(phba->host->host_lock);
1216 return -EPERM;
1217 }
1218
1219 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1220 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1221
1222 spin_unlock_irq(phba->host->host_lock);
1223 rc = lpfc_sli_issue_mbox (phba,
1224 phba->sysfs_mbox.mbox,
1225 MBX_POLL);
1226 spin_lock_irq(phba->host->host_lock);
1227
1228 } else {
1229 spin_unlock_irq(phba->host->host_lock);
1230 rc = lpfc_sli_issue_mbox_wait (phba,
1231 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001232 lpfc_mbox_tmo_val(phba,
1233 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
dea31012005-04-17 16:05:31 -05001234 spin_lock_irq(phba->host->host_lock);
1235 }
1236
1237 if (rc != MBX_SUCCESS) {
1238 sysfs_mbox_idle(phba);
1239 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001240 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001241 }
1242 phba->sysfs_mbox.state = SMBOX_READING;
1243 }
1244 else if (phba->sysfs_mbox.offset != off ||
1245 phba->sysfs_mbox.state != SMBOX_READING) {
1246 printk(KERN_WARNING "mbox_read: Bad State\n");
1247 sysfs_mbox_idle(phba);
1248 spin_unlock_irq(host->host_lock);
James Smart8f6d98d2006-08-01 07:34:00 -04001249 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001250 }
1251
1252 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1253
1254 phba->sysfs_mbox.offset = off + count;
1255
1256 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1257 sysfs_mbox_idle(phba);
1258
1259 spin_unlock_irq(phba->host->host_lock);
1260
1261 return count;
1262}
1263
1264static struct bin_attribute sysfs_mbox_attr = {
1265 .attr = {
1266 .name = "mbox",
1267 .mode = S_IRUSR | S_IWUSR,
1268 .owner = THIS_MODULE,
1269 },
1270 .size = sizeof(MAILBOX_t),
1271 .read = sysfs_mbox_read,
1272 .write = sysfs_mbox_write,
1273};
1274
1275int
1276lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1277{
1278 struct Scsi_Host *host = phba->host;
1279 int error;
1280
1281 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1282 &sysfs_ctlreg_attr);
1283 if (error)
1284 goto out;
1285
1286 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1287 &sysfs_mbox_attr);
1288 if (error)
1289 goto out_remove_ctlreg_attr;
1290
1291 return 0;
1292out_remove_ctlreg_attr:
1293 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1294out:
1295 return error;
1296}
1297
1298void
1299lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1300{
1301 struct Scsi_Host *host = phba->host;
1302
1303 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1304 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1305}
1306
1307
1308/*
1309 * Dynamic FC Host Attributes Support
1310 */
1311
1312static void
1313lpfc_get_host_port_id(struct Scsi_Host *shost)
1314{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001315 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001316 /* note: fc_myDID already in cpu endianness */
1317 fc_host_port_id(shost) = phba->fc_myDID;
1318}
1319
1320static void
1321lpfc_get_host_port_type(struct Scsi_Host *shost)
1322{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001323 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001324
1325 spin_lock_irq(shost->host_lock);
1326
1327 if (phba->hba_state == LPFC_HBA_READY) {
1328 if (phba->fc_topology == TOPOLOGY_LOOP) {
1329 if (phba->fc_flag & FC_PUBLIC_LOOP)
1330 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1331 else
1332 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1333 } else {
1334 if (phba->fc_flag & FC_FABRIC)
1335 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1336 else
1337 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1338 }
1339 } else
1340 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1341
1342 spin_unlock_irq(shost->host_lock);
1343}
1344
1345static void
1346lpfc_get_host_port_state(struct Scsi_Host *shost)
1347{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001348 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001349
1350 spin_lock_irq(shost->host_lock);
1351
1352 if (phba->fc_flag & FC_OFFLINE_MODE)
1353 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1354 else {
1355 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001356 case LPFC_STATE_UNKNOWN:
1357 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001358 case LPFC_INIT_START:
1359 case LPFC_INIT_MBX_CMDS:
1360 case LPFC_LINK_DOWN:
1361 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1362 break;
1363 case LPFC_LINK_UP:
1364 case LPFC_LOCAL_CFG_LINK:
1365 case LPFC_FLOGI:
1366 case LPFC_FABRIC_CFG_LINK:
1367 case LPFC_NS_REG:
1368 case LPFC_NS_QRY:
1369 case LPFC_BUILD_DISC_LIST:
1370 case LPFC_DISC_AUTH:
1371 case LPFC_CLEAR_LA:
1372 case LPFC_HBA_READY:
1373 /* Links up, beyond this port_type reports state */
1374 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1375 break;
1376 case LPFC_HBA_ERROR:
1377 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1378 break;
1379 default:
1380 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1381 break;
1382 }
1383 }
1384
1385 spin_unlock_irq(shost->host_lock);
1386}
1387
1388static void
1389lpfc_get_host_speed(struct Scsi_Host *shost)
1390{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001391 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001392
1393 spin_lock_irq(shost->host_lock);
1394
1395 if (phba->hba_state == LPFC_HBA_READY) {
1396 switch(phba->fc_linkspeed) {
1397 case LA_1GHZ_LINK:
1398 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1399 break;
1400 case LA_2GHZ_LINK:
1401 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1402 break;
1403 case LA_4GHZ_LINK:
1404 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1405 break;
1406 default:
1407 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1408 break;
1409 }
1410 }
1411
1412 spin_unlock_irq(shost->host_lock);
1413}
1414
1415static void
1416lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1417{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001418 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001419 u64 node_name;
dea31012005-04-17 16:05:31 -05001420
1421 spin_lock_irq(shost->host_lock);
1422
1423 if ((phba->fc_flag & FC_FABRIC) ||
1424 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1425 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001426 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001427 else
1428 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001429 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001430
1431 spin_unlock_irq(shost->host_lock);
1432
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001433 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001434}
1435
James Smartae367642006-08-18 17:46:53 -04001436static void
1437lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1438{
1439 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1440
1441 spin_lock_irq(shost->host_lock);
1442 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1443 spin_unlock_irq(shost->host_lock);
1444}
dea31012005-04-17 16:05:31 -05001445
1446static struct fc_host_statistics *
1447lpfc_get_stats(struct Scsi_Host *shost)
1448{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001449 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001450 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001451 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04001452 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05001453 LPFC_MBOXQ_t *pmboxq;
1454 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04001455 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001456 int rc = 0;
dea31012005-04-17 16:05:31 -05001457
1458 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1459 if (!pmboxq)
1460 return NULL;
1461 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1462
1463 pmb = &pmboxq->mb;
1464 pmb->mbxCommand = MBX_READ_STATUS;
1465 pmb->mbxOwner = OWN_HOST;
1466 pmboxq->context1 = NULL;
1467
1468 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001469 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001470 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001471 else
dea31012005-04-17 16:05:31 -05001472 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1473
1474 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001475 if (rc == MBX_TIMEOUT)
1476 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1477 else
1478 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001479 return NULL;
1480 }
1481
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001482 memset(hs, 0, sizeof (struct fc_host_statistics));
1483
dea31012005-04-17 16:05:31 -05001484 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1485 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1486 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1487 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1488
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001489 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001490 pmb->mbxCommand = MBX_READ_LNK_STAT;
1491 pmb->mbxOwner = OWN_HOST;
1492 pmboxq->context1 = NULL;
1493
1494 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001495 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001496 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001497 else
dea31012005-04-17 16:05:31 -05001498 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1499
1500 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001501 if (rc == MBX_TIMEOUT)
1502 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1503 else
1504 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001505 return NULL;
1506 }
1507
1508 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1509 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1510 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1511 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1512 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1513 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1514 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1515
James Smart64ba8812006-08-02 15:24:34 -04001516 hs->link_failure_count -= lso->link_failure_count;
1517 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1518 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1519 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1520 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1521 hs->invalid_crc_count -= lso->invalid_crc_count;
1522 hs->error_frames -= lso->error_frames;
1523
dea31012005-04-17 16:05:31 -05001524 if (phba->fc_topology == TOPOLOGY_LOOP) {
1525 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001526 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001527 hs->nos_count = -1;
1528 } else {
1529 hs->lip_count = -1;
1530 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001531 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001532 }
1533
1534 hs->dumped_frames = -1;
1535
James Smart64ba8812006-08-02 15:24:34 -04001536 seconds = get_seconds();
1537 if (seconds < psli->stats_start)
1538 hs->seconds_since_last_reset = seconds +
1539 ((unsigned long)-1 - psli->stats_start);
1540 else
1541 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05001542
1543 return hs;
1544}
1545
James Smart64ba8812006-08-02 15:24:34 -04001546static void
1547lpfc_reset_stats(struct Scsi_Host *shost)
1548{
1549 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1550 struct lpfc_sli *psli = &phba->sli;
1551 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1552 LPFC_MBOXQ_t *pmboxq;
1553 MAILBOX_t *pmb;
1554 int rc = 0;
1555
1556 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1557 if (!pmboxq)
1558 return;
1559 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1560
1561 pmb = &pmboxq->mb;
1562 pmb->mbxCommand = MBX_READ_STATUS;
1563 pmb->mbxOwner = OWN_HOST;
1564 pmb->un.varWords[0] = 0x1; /* reset request */
1565 pmboxq->context1 = NULL;
1566
1567 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1568 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1569 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1570 else
1571 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1572
1573 if (rc != MBX_SUCCESS) {
1574 if (rc == MBX_TIMEOUT)
1575 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1576 else
1577 mempool_free(pmboxq, phba->mbox_mem_pool);
1578 return;
1579 }
1580
1581 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1582 pmb->mbxCommand = MBX_READ_LNK_STAT;
1583 pmb->mbxOwner = OWN_HOST;
1584 pmboxq->context1 = NULL;
1585
1586 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1587 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1588 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1589 else
1590 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1591
1592 if (rc != MBX_SUCCESS) {
1593 if (rc == MBX_TIMEOUT)
1594 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1595 else
1596 mempool_free( pmboxq, phba->mbox_mem_pool);
1597 return;
1598 }
1599
1600 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1601 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1602 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1603 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1604 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1605 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1606 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1607 lso->link_events = (phba->fc_eventTag >> 1);
1608
1609 psli->stats_start = get_seconds();
1610
1611 return;
1612}
dea31012005-04-17 16:05:31 -05001613
1614/*
1615 * The LPFC driver treats linkdown handling as target loss events so there
1616 * are no sysfs handlers for link_down_tmo.
1617 */
1618static void
1619lpfc_get_starget_port_id(struct scsi_target *starget)
1620{
1621 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001622 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea31012005-04-17 16:05:31 -05001623 uint32_t did = -1;
1624 struct lpfc_nodelist *ndlp = NULL;
1625
1626 spin_lock_irq(shost->host_lock);
1627 /* Search the mapped list for this target ID */
1628 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1629 if (starget->id == ndlp->nlp_sid) {
1630 did = ndlp->nlp_DID;
1631 break;
1632 }
1633 }
1634 spin_unlock_irq(shost->host_lock);
1635
1636 fc_starget_port_id(starget) = did;
1637}
1638
1639static void
1640lpfc_get_starget_node_name(struct scsi_target *starget)
1641{
1642 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001643 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001644 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001645 struct lpfc_nodelist *ndlp = NULL;
1646
1647 spin_lock_irq(shost->host_lock);
1648 /* Search the mapped list for this target ID */
1649 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1650 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001651 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001652 break;
1653 }
1654 }
1655 spin_unlock_irq(shost->host_lock);
1656
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001657 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001658}
1659
1660static void
1661lpfc_get_starget_port_name(struct scsi_target *starget)
1662{
1663 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001664 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001665 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001666 struct lpfc_nodelist *ndlp = NULL;
1667
1668 spin_lock_irq(shost->host_lock);
1669 /* Search the mapped list for this target ID */
1670 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1671 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001672 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001673 break;
1674 }
1675 }
1676 spin_unlock_irq(shost->host_lock);
1677
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001678 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001679}
1680
1681static void
dea31012005-04-17 16:05:31 -05001682lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1683{
dea31012005-04-17 16:05:31 -05001684 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04001685 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05001686 else
James Smartc01f3202006-08-18 17:47:08 -04001687 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05001688}
1689
1690
1691#define lpfc_rport_show_function(field, format_string, sz, cast) \
1692static ssize_t \
1693lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1694{ \
1695 struct fc_rport *rport = transport_class_to_rport(cdev); \
1696 struct lpfc_rport_data *rdata = rport->hostdata; \
1697 return snprintf(buf, sz, format_string, \
1698 (rdata->target) ? cast rdata->target->field : 0); \
1699}
1700
1701#define lpfc_rport_rd_attr(field, format_string, sz) \
1702 lpfc_rport_show_function(field, format_string, sz, ) \
1703static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1704
1705
1706struct fc_function_template lpfc_transport_functions = {
1707 /* fixed attributes the driver supports */
1708 .show_host_node_name = 1,
1709 .show_host_port_name = 1,
1710 .show_host_supported_classes = 1,
1711 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05001712 .show_host_supported_speeds = 1,
1713 .show_host_maxframe_size = 1,
1714
1715 /* dynamic attributes the driver supports */
1716 .get_host_port_id = lpfc_get_host_port_id,
1717 .show_host_port_id = 1,
1718
1719 .get_host_port_type = lpfc_get_host_port_type,
1720 .show_host_port_type = 1,
1721
1722 .get_host_port_state = lpfc_get_host_port_state,
1723 .show_host_port_state = 1,
1724
1725 /* active_fc4s is shown but doesn't change (thus no get function) */
1726 .show_host_active_fc4s = 1,
1727
1728 .get_host_speed = lpfc_get_host_speed,
1729 .show_host_speed = 1,
1730
1731 .get_host_fabric_name = lpfc_get_host_fabric_name,
1732 .show_host_fabric_name = 1,
1733
James Smartae367642006-08-18 17:46:53 -04001734 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1735 .show_host_symbolic_name = 1,
1736
dea31012005-04-17 16:05:31 -05001737 /*
1738 * The LPFC driver treats linkdown handling as target loss events
1739 * so there are no sysfs handlers for link_down_tmo.
1740 */
1741
1742 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04001743 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05001744
1745 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1746 .show_rport_maxframe_size = 1,
1747 .show_rport_supported_classes = 1,
1748
dea31012005-04-17 16:05:31 -05001749 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1750 .show_rport_dev_loss_tmo = 1,
1751
1752 .get_starget_port_id = lpfc_get_starget_port_id,
1753 .show_starget_port_id = 1,
1754
1755 .get_starget_node_name = lpfc_get_starget_node_name,
1756 .show_starget_node_name = 1,
1757
1758 .get_starget_port_name = lpfc_get_starget_port_name,
1759 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001760
1761 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04001762 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1763 .terminate_rport_io = lpfc_terminate_rport_io,
dea31012005-04-17 16:05:31 -05001764};
1765
1766void
1767lpfc_get_cfgparam(struct lpfc_hba *phba)
1768{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001769 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1770 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1771 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001772 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001773 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1774 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1775 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1776 lpfc_ack0_init(phba, lpfc_ack0);
1777 lpfc_topology_init(phba, lpfc_topology);
1778 lpfc_scan_down_init(phba, lpfc_scan_down);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001779 lpfc_link_speed_init(phba, lpfc_link_speed);
1780 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1781 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1782 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001783 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001784 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1785 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001786 phba->cfg_poll = lpfc_poll;
James Smartc3f28af2006-08-18 17:47:18 -04001787 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05001788
1789 /*
1790 * The total number of segments is the configuration value plus 2
1791 * since the IOCB need a command and response bde.
1792 */
1793 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1794
1795 /*
1796 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1797 * used to create the sg_dma_buf_pool must be dynamically calculated
1798 */
1799 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1800 sizeof(struct fcp_rsp) +
1801 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1802
1803 switch (phba->pcidev->device) {
1804 case PCI_DEVICE_ID_LP101:
1805 case PCI_DEVICE_ID_BSMB:
1806 case PCI_DEVICE_ID_ZSMB:
1807 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1808 break;
1809 case PCI_DEVICE_ID_RFLY:
1810 case PCI_DEVICE_ID_PFLY:
1811 case PCI_DEVICE_ID_BMID:
1812 case PCI_DEVICE_ID_ZMID:
1813 case PCI_DEVICE_ID_TFLY:
1814 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1815 break;
1816 default:
1817 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1818 }
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001819
1820 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1821 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1822
dea31012005-04-17 16:05:31 -05001823 return;
1824}