blob: cdae011b2813c1ac39e1cd900d223bddd46cb9b6 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
Jamie Wellnitz41415862006-02-28 19:25:27 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_tcq.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_hw.h"
33#include "lpfc_sli.h"
34#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_version.h"
39#include "lpfc_compat.h"
40#include "lpfc_crtn.h"
41
42
43static void
44lpfc_jedec_to_ascii(int incr, char hdw[])
45{
46 int i, j;
47 for (i = 0; i < 8; i++) {
48 j = (incr & 0xf);
49 if (j <= 9)
50 hdw[7 - i] = 0x30 + j;
51 else
52 hdw[7 - i] = 0x61 + j - 10;
53 incr = (incr >> 4);
54 }
55 hdw[8] = 0;
56 return;
57}
58
59static ssize_t
60lpfc_drvr_version_show(struct class_device *cdev, char *buf)
61{
62 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
63}
64
65static ssize_t
66management_version_show(struct class_device *cdev, char *buf)
67{
68 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
69}
70
71static ssize_t
72lpfc_info_show(struct class_device *cdev, char *buf)
73{
74 struct Scsi_Host *host = class_to_shost(cdev);
75 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
76}
77
78static ssize_t
79lpfc_serialnum_show(struct class_device *cdev, char *buf)
80{
81 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050082 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050083 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
84}
85
86static ssize_t
87lpfc_modeldesc_show(struct class_device *cdev, char *buf)
88{
89 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050090 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050091 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
92}
93
94static ssize_t
95lpfc_modelname_show(struct class_device *cdev, char *buf)
96{
97 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -050098 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -050099 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
100}
101
102static ssize_t
103lpfc_programtype_show(struct class_device *cdev, char *buf)
104{
105 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500106 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500107 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
108}
109
110static ssize_t
111lpfc_portnum_show(struct class_device *cdev, char *buf)
112{
113 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500114 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500115 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
116}
117
118static ssize_t
119lpfc_fwrev_show(struct class_device *cdev, char *buf)
120{
121 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500122 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500123 char fwrev[32];
124 lpfc_decode_firmware_rev(phba, fwrev, 1);
125 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
126}
127
128static ssize_t
129lpfc_hdw_show(struct class_device *cdev, char *buf)
130{
131 char hdw[9];
132 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500133 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500134 lpfc_vpd_t *vp = &phba->vpd;
135 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
136 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
137}
138static ssize_t
139lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
140{
141 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500143 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
144}
145static ssize_t
146lpfc_state_show(struct class_device *cdev, char *buf)
147{
148 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500149 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500150 int len = 0;
151 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500152 case LPFC_STATE_UNKNOWN:
153 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500154 case LPFC_INIT_START:
155 case LPFC_INIT_MBX_CMDS:
156 case LPFC_LINK_DOWN:
157 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
158 break;
159 case LPFC_LINK_UP:
160 case LPFC_LOCAL_CFG_LINK:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
162 break;
163 case LPFC_FLOGI:
164 case LPFC_FABRIC_CFG_LINK:
165 case LPFC_NS_REG:
166 case LPFC_NS_QRY:
167 case LPFC_BUILD_DISC_LIST:
168 case LPFC_DISC_AUTH:
169 case LPFC_CLEAR_LA:
170 len += snprintf(buf + len, PAGE_SIZE-len,
171 "Link Up - Discovery\n");
172 break;
173 case LPFC_HBA_READY:
174 len += snprintf(buf + len, PAGE_SIZE-len,
175 "Link Up - Ready:\n");
176 if (phba->fc_topology == TOPOLOGY_LOOP) {
177 if (phba->fc_flag & FC_PUBLIC_LOOP)
178 len += snprintf(buf + len, PAGE_SIZE-len,
179 " Public Loop\n");
180 else
181 len += snprintf(buf + len, PAGE_SIZE-len,
182 " Private Loop\n");
183 } else {
184 if (phba->fc_flag & FC_FABRIC)
185 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Fabric\n");
187 else
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 " Point-2-Point\n");
190 }
191 }
192 return len;
193}
194
195static ssize_t
196lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
197{
198 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500199 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500200 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
201 phba->fc_unmap_cnt);
202}
203
204
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700205static int
206lpfc_issue_lip(struct Scsi_Host *host)
dea31012005-04-17 16:05:31 -0500207{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500208 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
dea31012005-04-17 16:05:31 -0500209 LPFC_MBOXQ_t *pmboxq;
210 int mbxstatus = MBXERR_ERROR;
211
dea31012005-04-17 16:05:31 -0500212 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
213 (phba->hba_state != LPFC_HBA_READY))
214 return -EPERM;
215
216 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
217
218 if (!pmboxq)
219 return -ENOMEM;
220
221 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400222 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
223 pmboxq->mb.mbxOwner = OWN_HOST;
224
dea31012005-04-17 16:05:31 -0500225 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
226
James Smart4db621e2006-07-06 15:49:49 -0400227 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
228 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
229 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
230 phba->cfg_link_speed);
231 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
232 phba->fc_ratov * 2);
233 }
234
dea31012005-04-17 16:05:31 -0500235 if (mbxstatus == MBX_TIMEOUT)
236 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
237 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400238 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500239
240 if (mbxstatus == MBXERR_ERROR)
241 return -EIO;
242
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700243 return 0;
dea31012005-04-17 16:05:31 -0500244}
245
James Smart40496f02006-07-06 15:50:22 -0400246static int
247lpfc_selective_reset(struct lpfc_hba *phba)
248{
249 struct completion online_compl;
250 int status = 0;
251
252 init_completion(&online_compl);
253 lpfc_workq_post_event(phba, &status, &online_compl,
254 LPFC_EVT_OFFLINE);
255 wait_for_completion(&online_compl);
256
257 if (status != 0)
258 return -EIO;
259
260 init_completion(&online_compl);
261 lpfc_workq_post_event(phba, &status, &online_compl,
262 LPFC_EVT_ONLINE);
263 wait_for_completion(&online_compl);
264
265 if (status != 0)
266 return -EIO;
267
268 return 0;
269}
270
271static ssize_t
272lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
273{
274 struct Scsi_Host *host = class_to_shost(cdev);
275 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
276 int status = -EINVAL;
277
278 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
279 status = lpfc_selective_reset(phba);
280
281 if (status == 0)
282 return strlen(buf);
283 else
284 return status;
285}
286
dea31012005-04-17 16:05:31 -0500287static ssize_t
288lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
289{
290 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500291 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500292 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
293}
294
295static ssize_t
296lpfc_board_online_show(struct class_device *cdev, char *buf)
297{
298 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500299 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500300
dea31012005-04-17 16:05:31 -0500301 if (phba->fc_flag & FC_OFFLINE_MODE)
302 return snprintf(buf, PAGE_SIZE, "0\n");
303 else
304 return snprintf(buf, PAGE_SIZE, "1\n");
305}
306
307static ssize_t
308lpfc_board_online_store(struct class_device *cdev, const char *buf,
309 size_t count)
310{
311 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500312 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500313 struct completion online_compl;
314 int val=0, status=0;
315
316 if (sscanf(buf, "%d", &val) != 1)
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400317 return -EINVAL;
dea31012005-04-17 16:05:31 -0500318
319 init_completion(&online_compl);
320
321 if (val)
322 lpfc_workq_post_event(phba, &status, &online_compl,
323 LPFC_EVT_ONLINE);
324 else
325 lpfc_workq_post_event(phba, &status, &online_compl,
326 LPFC_EVT_OFFLINE);
327 wait_for_completion(&online_compl);
328 if (!status)
329 return strlen(buf);
330 else
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400331 return -EIO;
dea31012005-04-17 16:05:31 -0500332}
333
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500334static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500335lpfc_board_mode_show(struct class_device *cdev, char *buf)
336{
337 struct Scsi_Host *host = class_to_shost(cdev);
338 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
339 char * state;
340
341 if (phba->hba_state == LPFC_HBA_ERROR)
342 state = "error";
343 else if (phba->hba_state == LPFC_WARM_START)
344 state = "warm start";
345 else if (phba->hba_state == LPFC_INIT_START)
346 state = "offline";
347 else
348 state = "online";
349
350 return snprintf(buf, PAGE_SIZE, "%s\n", state);
351}
352
353static ssize_t
354lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
355{
356 struct Scsi_Host *host = class_to_shost(cdev);
357 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
358 struct completion online_compl;
359 int status=0;
360
361 init_completion(&online_compl);
362
363 if(strncmp(buf, "online", sizeof("online") - 1) == 0)
364 lpfc_workq_post_event(phba, &status, &online_compl,
365 LPFC_EVT_ONLINE);
366 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
367 lpfc_workq_post_event(phba, &status, &online_compl,
368 LPFC_EVT_OFFLINE);
369 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
370 lpfc_workq_post_event(phba, &status, &online_compl,
371 LPFC_EVT_WARM_START);
372 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
373 lpfc_workq_post_event(phba, &status, &online_compl,
374 LPFC_EVT_KILL);
375 else
376 return -EINVAL;
377
378 wait_for_completion(&online_compl);
379
380 if (!status)
381 return strlen(buf);
382 else
383 return -EIO;
384}
385
386static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500387lpfc_poll_show(struct class_device *cdev, char *buf)
388{
389 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500390 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500391
392 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
393}
394
395static ssize_t
396lpfc_poll_store(struct class_device *cdev, const char *buf,
397 size_t count)
398{
399 struct Scsi_Host *host = class_to_shost(cdev);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500400 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500401 uint32_t creg_val;
402 uint32_t old_val;
403 int val=0;
404
405 if (!isdigit(buf[0]))
406 return -EINVAL;
407
408 if (sscanf(buf, "%i", &val) != 1)
409 return -EINVAL;
410
411 if ((val & 0x3) != val)
412 return -EINVAL;
413
414 spin_lock_irq(phba->host->host_lock);
415
416 old_val = phba->cfg_poll;
417
418 if (val & ENABLE_FCP_RING_POLLING) {
419 if ((val & DISABLE_FCP_RING_INT) &&
420 !(old_val & DISABLE_FCP_RING_INT)) {
421 creg_val = readl(phba->HCregaddr);
422 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
423 writel(creg_val, phba->HCregaddr);
424 readl(phba->HCregaddr); /* flush */
425
426 lpfc_poll_start_timer(phba);
427 }
428 } else if (val != 0x0) {
429 spin_unlock_irq(phba->host->host_lock);
430 return -EINVAL;
431 }
432
433 if (!(val & DISABLE_FCP_RING_INT) &&
434 (old_val & DISABLE_FCP_RING_INT))
435 {
436 spin_unlock_irq(phba->host->host_lock);
437 del_timer(&phba->fcp_poll_timer);
438 spin_lock_irq(phba->host->host_lock);
439 creg_val = readl(phba->HCregaddr);
440 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
441 writel(creg_val, phba->HCregaddr);
442 readl(phba->HCregaddr); /* flush */
443 }
444
445 phba->cfg_poll = val;
446
447 spin_unlock_irq(phba->host->host_lock);
448
449 return strlen(buf);
450}
dea31012005-04-17 16:05:31 -0500451
452#define lpfc_param_show(attr) \
453static ssize_t \
454lpfc_##attr##_show(struct class_device *cdev, char *buf) \
455{ \
456 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500457 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
dea31012005-04-17 16:05:31 -0500458 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400459 val = phba->cfg_##attr;\
460 return snprintf(buf, PAGE_SIZE, "%d\n",\
461 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500462}
463
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400464#define lpfc_param_hex_show(attr) \
465static ssize_t \
466lpfc_##attr##_show(struct class_device *cdev, char *buf) \
467{ \
468 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500469 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400470 int val = 0;\
471 val = phba->cfg_##attr;\
472 return snprintf(buf, PAGE_SIZE, "%#x\n",\
473 phba->cfg_##attr);\
474}
475
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400476#define lpfc_param_init(attr, default, minval, maxval) \
477static int \
478lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
479{ \
480 if (val >= minval && val <= maxval) {\
481 phba->cfg_##attr = val;\
482 return 0;\
483 }\
484 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
485 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
486 "allowed range is ["#minval", "#maxval"]\n", \
487 phba->brd_no, val); \
488 phba->cfg_##attr = default;\
489 return -EINVAL;\
490}
491
492#define lpfc_param_set(attr, default, minval, maxval) \
493static int \
494lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
495{ \
496 if (val >= minval && val <= maxval) {\
497 phba->cfg_##attr = val;\
498 return 0;\
499 }\
500 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
501 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
502 "allowed range is ["#minval", "#maxval"]\n", \
503 phba->brd_no, val); \
504 return -EINVAL;\
505}
506
507#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500508static ssize_t \
509lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
510{ \
511 struct Scsi_Host *host = class_to_shost(cdev);\
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500512 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400513 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400514 if (!isdigit(buf[0]))\
515 return -EINVAL;\
516 if (sscanf(buf, "%i", &val) != 1)\
517 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400518 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400519 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400520 else \
521 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500522}
523
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400524#define LPFC_ATTR(name, defval, minval, maxval, desc) \
525static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500526module_param(lpfc_##name, int, 0);\
527MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400528lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500529
530#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
531static int lpfc_##name = defval;\
532module_param(lpfc_##name, int, 0);\
533MODULE_PARM_DESC(lpfc_##name, desc);\
534lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400535lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500536static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
537
538#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
539static int lpfc_##name = defval;\
540module_param(lpfc_##name, int, 0);\
541MODULE_PARM_DESC(lpfc_##name, desc);\
542lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400543lpfc_param_init(name, defval, minval, maxval)\
544lpfc_param_set(name, defval, minval, maxval)\
545lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500546static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
547 lpfc_##name##_show, lpfc_##name##_store)
548
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400549#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
550static int lpfc_##name = defval;\
551module_param(lpfc_##name, int, 0);\
552MODULE_PARM_DESC(lpfc_##name, desc);\
553lpfc_param_hex_show(name)\
554lpfc_param_init(name, defval, minval, maxval)\
555static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
556
557#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
558static int lpfc_##name = defval;\
559module_param(lpfc_##name, int, 0);\
560MODULE_PARM_DESC(lpfc_##name, desc);\
561lpfc_param_hex_show(name)\
562lpfc_param_init(name, defval, minval, maxval)\
563lpfc_param_set(name, defval, minval, maxval)\
564lpfc_param_store(name)\
565static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
566 lpfc_##name##_show, lpfc_##name##_store)
567
dea31012005-04-17 16:05:31 -0500568static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
569static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
570static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
571static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
572static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
573static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
574static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
575static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
576static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
577static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
578 lpfc_option_rom_version_show, NULL);
579static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
580 lpfc_num_discovered_ports_show, NULL);
581static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
582static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
583 NULL);
584static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
585 NULL);
dea31012005-04-17 16:05:31 -0500586static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
587 lpfc_board_online_show, lpfc_board_online_store);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500588static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
589 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400590static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea31012005-04-17 16:05:31 -0500591
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500592static int lpfc_poll = 0;
593module_param(lpfc_poll, int, 0);
594MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
595 " 0 - none,"
596 " 1 - poll with interrupts enabled"
597 " 3 - poll and disable FCP ring interrupts");
598
599static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
600 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500601
602/*
603# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
604# deluged with LOTS of information.
605# You can set a bit mask to record specific types of verbose messages:
606#
607# LOG_ELS 0x1 ELS events
608# LOG_DISCOVERY 0x2 Link discovery events
609# LOG_MBOX 0x4 Mailbox events
610# LOG_INIT 0x8 Initialization events
611# LOG_LINK_EVENT 0x10 Link events
612# LOG_IP 0x20 IP traffic history
613# LOG_FCP 0x40 FCP traffic history
614# LOG_NODE 0x80 Node table events
615# LOG_MISC 0x400 Miscellaneous events
616# LOG_SLI 0x800 SLI events
617# LOG_CHK_COND 0x1000 FCP Check condition flag
618# LOG_LIBDFC 0x2000 LIBDFC events
619# LOG_ALL_MSG 0xffff LOG all messages
620*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400621LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -0500622
623/*
624# lun_queue_depth: This parameter is used to limit the number of outstanding
625# commands per FCP LUN. Value range is [1,128]. Default value is 30.
626*/
627LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
628 "Max number of FCP commands we can queue to a specific LUN");
629
630/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500631# hba_queue_depth: This parameter is used to limit the number of outstanding
632# commands per lpfc HBA. Value range is [32,8192]. If this parameter
633# value is greater than the maximum number of exchanges supported by the HBA,
634# then maximum number of exchanges supported by the HBA is used to determine
635# the hba_queue_depth.
636*/
637LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
638 "Max number of FCP commands we can queue to a lpfc HBA");
639
640/*
dea31012005-04-17 16:05:31 -0500641# Some disk devices have a "select ID" or "select Target" capability.
642# From a protocol standpoint "select ID" usually means select the
643# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
644# annex" which contains a table that maps a "select ID" (a number
645# between 0 and 7F) to an ALPA. By default, for compatibility with
646# older drivers, the lpfc driver scans this table from low ALPA to high
647# ALPA.
648#
649# Turning on the scan-down variable (on = 1, off = 0) will
650# cause the lpfc driver to use an inverted table, effectively
651# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
652#
653# (Note: This "select ID" functionality is a LOOP ONLY characteristic
654# and will not work across a fabric. Also this parameter will take
655# effect only in the case when ALPA map is not available.)
656*/
657LPFC_ATTR_R(scan_down, 1, 0, 1,
658 "Start scanning for devices from highest ALPA to lowest");
659
660/*
661# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
James.Smart@Emulex.Com09703d32005-10-28 20:29:21 -0400662# until the timer expires. Value range is [0,255]. Default value is 30.
dea31012005-04-17 16:05:31 -0500663# NOTE: this MUST be less then the SCSI Layer command timeout - 1.
664*/
665LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
666 "Seconds driver will hold I/O waiting for a device to come back");
667
668/*
669# lpfc_topology: link topology for init link
670# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500671# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -0500672# 0x02 = attempt point-to-point mode only
673# 0x04 = attempt loop mode only
674# 0x06 = attempt point-to-point mode then loop
675# Set point-to-point mode if you want to run as an N_Port.
676# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
677# Default value is 0.
678*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500679LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -0500680
681/*
682# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
683# connection.
684# 0 = auto select (default)
685# 1 = 1 Gigabaud
686# 2 = 2 Gigabaud
687# 4 = 4 Gigabaud
688# Value range is [0,4]. Default value is 0.
689*/
690LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
691
692/*
693# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
694# Value range is [2,3]. Default value is 3.
695*/
696LPFC_ATTR_R(fcp_class, 3, 2, 3,
697 "Select Fibre Channel class of service for FCP sequences");
698
699/*
700# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
701# is [0,1]. Default value is 0.
702*/
703LPFC_ATTR_RW(use_adisc, 0, 0, 1,
704 "Use ADISC on rediscovery to authenticate FCP devices");
705
706/*
707# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
708# range is [0,1]. Default value is 0.
709*/
710LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
711
712/*
713# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
714# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
715# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
716# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
717# cr_delay is set to 0.
718*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500719LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -0500720 "interrupt response is generated");
721
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500722LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -0500723 "interrupt response is generated");
724
725/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500726# lpfc_multi_ring_support: Determines how many rings to spread available
727# cmd/rsp IOCB entries across.
728# Value range is [1,2]. Default value is 1.
729*/
730LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
731 "SLI rings to spread IOCB entries across");
732
733/*
dea31012005-04-17 16:05:31 -0500734# lpfc_fdmi_on: controls FDMI support.
735# 0 = no FDMI support
736# 1 = support FDMI without attribute of hostname
737# 2 = support FDMI with attribute of hostname
738# Value range [0,2]. Default value is 0.
739*/
740LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
741
742/*
743# Specifies the maximum number of ELS cmds we can have outstanding (for
744# discovery). Value range is [1,64]. Default value = 32.
745*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -0500746LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -0500747 "during discovery");
748
749/*
750# lpfc_max_luns: maximum number of LUNs per target driver will support
751# Value range is [1,32768]. Default value is 256.
752# NOTE: The SCSI layer will scan each target for this many luns
753*/
754LPFC_ATTR_R(max_luns, 256, 1, 32768,
755 "Maximum number of LUNs per target driver will support");
756
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500757/*
758# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
759# Value range is [1,255], default value is 10.
760*/
761LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
762 "Milliseconds driver will wait between polling FCP ring");
763
dea31012005-04-17 16:05:31 -0500764struct class_device_attribute *lpfc_host_attrs[] = {
765 &class_device_attr_info,
766 &class_device_attr_serialnum,
767 &class_device_attr_modeldesc,
768 &class_device_attr_modelname,
769 &class_device_attr_programtype,
770 &class_device_attr_portnum,
771 &class_device_attr_fwrev,
772 &class_device_attr_hdw,
773 &class_device_attr_option_rom_version,
774 &class_device_attr_state,
775 &class_device_attr_num_discovered_ports,
776 &class_device_attr_lpfc_drvr_version,
777 &class_device_attr_lpfc_log_verbose,
778 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -0500779 &class_device_attr_lpfc_hba_queue_depth,
dea31012005-04-17 16:05:31 -0500780 &class_device_attr_lpfc_nodev_tmo,
781 &class_device_attr_lpfc_fcp_class,
782 &class_device_attr_lpfc_use_adisc,
783 &class_device_attr_lpfc_ack0,
784 &class_device_attr_lpfc_topology,
785 &class_device_attr_lpfc_scan_down,
786 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500787 &class_device_attr_lpfc_cr_delay,
788 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -0500789 &class_device_attr_lpfc_multi_ring_support,
dea31012005-04-17 16:05:31 -0500790 &class_device_attr_lpfc_fdmi_on,
791 &class_device_attr_lpfc_max_luns,
792 &class_device_attr_nport_evt_cnt,
793 &class_device_attr_management_version,
dea31012005-04-17 16:05:31 -0500794 &class_device_attr_board_online,
Jamie Wellnitz41415862006-02-28 19:25:27 -0500795 &class_device_attr_board_mode,
James Smart40496f02006-07-06 15:50:22 -0400796 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500797 &class_device_attr_lpfc_poll,
798 &class_device_attr_lpfc_poll_tmo,
dea31012005-04-17 16:05:31 -0500799 NULL,
800};
801
802static ssize_t
803sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
804{
805 size_t buf_off;
806 struct Scsi_Host *host = class_to_shost(container_of(kobj,
807 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500808 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500809
810 if ((off + count) > FF_REG_AREA_SIZE)
811 return -ERANGE;
812
813 if (count == 0) return 0;
814
815 if (off % 4 || count % 4 || (unsigned long)buf % 4)
816 return -EINVAL;
817
818 spin_lock_irq(phba->host->host_lock);
819
820 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
821 spin_unlock_irq(phba->host->host_lock);
822 return -EPERM;
823 }
824
825 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
826 writel(*((uint32_t *)(buf + buf_off)),
827 phba->ctrl_regs_memmap_p + off + buf_off);
828
829 spin_unlock_irq(phba->host->host_lock);
830
831 return count;
832}
833
834static ssize_t
835sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
836{
837 size_t buf_off;
838 uint32_t * tmp_ptr;
839 struct Scsi_Host *host = class_to_shost(container_of(kobj,
840 struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500841 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500842
843 if (off > FF_REG_AREA_SIZE)
844 return -ERANGE;
845
846 if ((off + count) > FF_REG_AREA_SIZE)
847 count = FF_REG_AREA_SIZE - off;
848
849 if (count == 0) return 0;
850
851 if (off % 4 || count % 4 || (unsigned long)buf % 4)
852 return -EINVAL;
853
854 spin_lock_irq(phba->host->host_lock);
855
856 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
857 tmp_ptr = (uint32_t *)(buf + buf_off);
858 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
859 }
860
861 spin_unlock_irq(phba->host->host_lock);
862
863 return count;
864}
865
866static struct bin_attribute sysfs_ctlreg_attr = {
867 .attr = {
868 .name = "ctlreg",
869 .mode = S_IRUSR | S_IWUSR,
870 .owner = THIS_MODULE,
871 },
872 .size = 256,
873 .read = sysfs_ctlreg_read,
874 .write = sysfs_ctlreg_write,
875};
876
877
878static void
879sysfs_mbox_idle (struct lpfc_hba * phba)
880{
881 phba->sysfs_mbox.state = SMBOX_IDLE;
882 phba->sysfs_mbox.offset = 0;
883
884 if (phba->sysfs_mbox.mbox) {
885 mempool_free(phba->sysfs_mbox.mbox,
886 phba->mbox_mem_pool);
887 phba->sysfs_mbox.mbox = NULL;
888 }
889}
890
891static ssize_t
892sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
893{
894 struct Scsi_Host * host =
895 class_to_shost(container_of(kobj, struct class_device, kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500896 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500897 struct lpfcMboxq * mbox = NULL;
898
899 if ((count + off) > MAILBOX_CMD_SIZE)
900 return -ERANGE;
901
902 if (off % 4 || count % 4 || (unsigned long)buf % 4)
903 return -EINVAL;
904
905 if (count == 0)
906 return 0;
907
908 if (off == 0) {
909 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
910 if (!mbox)
911 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -0500912 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -0500913 }
914
915 spin_lock_irq(host->host_lock);
916
917 if (off == 0) {
918 if (phba->sysfs_mbox.mbox)
919 mempool_free(mbox, phba->mbox_mem_pool);
920 else
921 phba->sysfs_mbox.mbox = mbox;
922 phba->sysfs_mbox.state = SMBOX_WRITING;
923 } else {
924 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
925 phba->sysfs_mbox.offset != off ||
926 phba->sysfs_mbox.mbox == NULL ) {
927 sysfs_mbox_idle(phba);
928 spin_unlock_irq(host->host_lock);
929 return -EINVAL;
930 }
931 }
932
933 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
934 buf, count);
935
936 phba->sysfs_mbox.offset = off + count;
937
938 spin_unlock_irq(host->host_lock);
939
940 return count;
941}
942
943static ssize_t
944sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
945{
946 struct Scsi_Host *host =
947 class_to_shost(container_of(kobj, struct class_device,
948 kobj));
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -0500949 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
dea31012005-04-17 16:05:31 -0500950 int rc;
951
952 if (off > sizeof(MAILBOX_t))
953 return -ERANGE;
954
955 if ((count + off) > sizeof(MAILBOX_t))
956 count = sizeof(MAILBOX_t) - off;
957
958 if (off % 4 || count % 4 || (unsigned long)buf % 4)
959 return -EINVAL;
960
961 if (off && count == 0)
962 return 0;
963
964 spin_lock_irq(phba->host->host_lock);
965
966 if (off == 0 &&
967 phba->sysfs_mbox.state == SMBOX_WRITING &&
968 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
969
970 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
971 /* Offline only */
972 case MBX_WRITE_NV:
973 case MBX_INIT_LINK:
974 case MBX_DOWN_LINK:
975 case MBX_CONFIG_LINK:
976 case MBX_CONFIG_RING:
977 case MBX_RESET_RING:
978 case MBX_UNREG_LOGIN:
979 case MBX_CLEAR_LA:
980 case MBX_DUMP_CONTEXT:
981 case MBX_RUN_DIAGS:
982 case MBX_RESTART:
983 case MBX_FLASH_WR_ULA:
984 case MBX_SET_MASK:
985 case MBX_SET_SLIM:
986 case MBX_SET_DEBUG:
987 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
988 printk(KERN_WARNING "mbox_read:Command 0x%x "
989 "is illegal in on-line state\n",
990 phba->sysfs_mbox.mbox->mb.mbxCommand);
991 sysfs_mbox_idle(phba);
992 spin_unlock_irq(phba->host->host_lock);
993 return -EPERM;
994 }
995 case MBX_LOAD_SM:
996 case MBX_READ_NV:
997 case MBX_READ_CONFIG:
998 case MBX_READ_RCONFIG:
999 case MBX_READ_STATUS:
1000 case MBX_READ_XRI:
1001 case MBX_READ_REV:
1002 case MBX_READ_LNK_STAT:
1003 case MBX_DUMP_MEMORY:
1004 case MBX_DOWN_LOAD:
1005 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001006 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001007 case MBX_LOAD_AREA:
1008 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001009 case MBX_BEACON:
1010 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001011 break;
1012 case MBX_READ_SPARM64:
1013 case MBX_READ_LA:
1014 case MBX_READ_LA64:
1015 case MBX_REG_LOGIN:
1016 case MBX_REG_LOGIN64:
1017 case MBX_CONFIG_PORT:
1018 case MBX_RUN_BIU_DIAG:
1019 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1020 phba->sysfs_mbox.mbox->mb.mbxCommand);
1021 sysfs_mbox_idle(phba);
1022 spin_unlock_irq(phba->host->host_lock);
1023 return -EPERM;
1024 default:
1025 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1026 phba->sysfs_mbox.mbox->mb.mbxCommand);
1027 sysfs_mbox_idle(phba);
1028 spin_unlock_irq(phba->host->host_lock);
1029 return -EPERM;
1030 }
1031
1032 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1033 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1034
1035 spin_unlock_irq(phba->host->host_lock);
1036 rc = lpfc_sli_issue_mbox (phba,
1037 phba->sysfs_mbox.mbox,
1038 MBX_POLL);
1039 spin_lock_irq(phba->host->host_lock);
1040
1041 } else {
1042 spin_unlock_irq(phba->host->host_lock);
1043 rc = lpfc_sli_issue_mbox_wait (phba,
1044 phba->sysfs_mbox.mbox,
1045 phba->fc_ratov * 2);
1046 spin_lock_irq(phba->host->host_lock);
1047 }
1048
1049 if (rc != MBX_SUCCESS) {
1050 sysfs_mbox_idle(phba);
1051 spin_unlock_irq(host->host_lock);
1052 return -ENODEV;
1053 }
1054 phba->sysfs_mbox.state = SMBOX_READING;
1055 }
1056 else if (phba->sysfs_mbox.offset != off ||
1057 phba->sysfs_mbox.state != SMBOX_READING) {
1058 printk(KERN_WARNING "mbox_read: Bad State\n");
1059 sysfs_mbox_idle(phba);
1060 spin_unlock_irq(host->host_lock);
1061 return -EINVAL;
1062 }
1063
1064 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1065
1066 phba->sysfs_mbox.offset = off + count;
1067
1068 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
1069 sysfs_mbox_idle(phba);
1070
1071 spin_unlock_irq(phba->host->host_lock);
1072
1073 return count;
1074}
1075
1076static struct bin_attribute sysfs_mbox_attr = {
1077 .attr = {
1078 .name = "mbox",
1079 .mode = S_IRUSR | S_IWUSR,
1080 .owner = THIS_MODULE,
1081 },
1082 .size = sizeof(MAILBOX_t),
1083 .read = sysfs_mbox_read,
1084 .write = sysfs_mbox_write,
1085};
1086
1087int
1088lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
1089{
1090 struct Scsi_Host *host = phba->host;
1091 int error;
1092
1093 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1094 &sysfs_ctlreg_attr);
1095 if (error)
1096 goto out;
1097
1098 error = sysfs_create_bin_file(&host->shost_classdev.kobj,
1099 &sysfs_mbox_attr);
1100 if (error)
1101 goto out_remove_ctlreg_attr;
1102
1103 return 0;
1104out_remove_ctlreg_attr:
1105 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1106out:
1107 return error;
1108}
1109
1110void
1111lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1112{
1113 struct Scsi_Host *host = phba->host;
1114
1115 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
1116 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
1117}
1118
1119
1120/*
1121 * Dynamic FC Host Attributes Support
1122 */
1123
1124static void
1125lpfc_get_host_port_id(struct Scsi_Host *shost)
1126{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001127 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001128 /* note: fc_myDID already in cpu endianness */
1129 fc_host_port_id(shost) = phba->fc_myDID;
1130}
1131
1132static void
1133lpfc_get_host_port_type(struct Scsi_Host *shost)
1134{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001135 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001136
1137 spin_lock_irq(shost->host_lock);
1138
1139 if (phba->hba_state == LPFC_HBA_READY) {
1140 if (phba->fc_topology == TOPOLOGY_LOOP) {
1141 if (phba->fc_flag & FC_PUBLIC_LOOP)
1142 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1143 else
1144 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1145 } else {
1146 if (phba->fc_flag & FC_FABRIC)
1147 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1148 else
1149 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1150 }
1151 } else
1152 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1153
1154 spin_unlock_irq(shost->host_lock);
1155}
1156
1157static void
1158lpfc_get_host_port_state(struct Scsi_Host *shost)
1159{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001160 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001161
1162 spin_lock_irq(shost->host_lock);
1163
1164 if (phba->fc_flag & FC_OFFLINE_MODE)
1165 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1166 else {
1167 switch (phba->hba_state) {
Jamie Wellnitz41415862006-02-28 19:25:27 -05001168 case LPFC_STATE_UNKNOWN:
1169 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -05001170 case LPFC_INIT_START:
1171 case LPFC_INIT_MBX_CMDS:
1172 case LPFC_LINK_DOWN:
1173 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1174 break;
1175 case LPFC_LINK_UP:
1176 case LPFC_LOCAL_CFG_LINK:
1177 case LPFC_FLOGI:
1178 case LPFC_FABRIC_CFG_LINK:
1179 case LPFC_NS_REG:
1180 case LPFC_NS_QRY:
1181 case LPFC_BUILD_DISC_LIST:
1182 case LPFC_DISC_AUTH:
1183 case LPFC_CLEAR_LA:
1184 case LPFC_HBA_READY:
1185 /* Links up, beyond this port_type reports state */
1186 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1187 break;
1188 case LPFC_HBA_ERROR:
1189 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1190 break;
1191 default:
1192 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1193 break;
1194 }
1195 }
1196
1197 spin_unlock_irq(shost->host_lock);
1198}
1199
1200static void
1201lpfc_get_host_speed(struct Scsi_Host *shost)
1202{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001203 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
dea31012005-04-17 16:05:31 -05001204
1205 spin_lock_irq(shost->host_lock);
1206
1207 if (phba->hba_state == LPFC_HBA_READY) {
1208 switch(phba->fc_linkspeed) {
1209 case LA_1GHZ_LINK:
1210 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1211 break;
1212 case LA_2GHZ_LINK:
1213 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1214 break;
1215 case LA_4GHZ_LINK:
1216 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1217 break;
1218 default:
1219 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1220 break;
1221 }
1222 }
1223
1224 spin_unlock_irq(shost->host_lock);
1225}
1226
1227static void
1228lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1229{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001230 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001231 u64 node_name;
dea31012005-04-17 16:05:31 -05001232
1233 spin_lock_irq(shost->host_lock);
1234
1235 if ((phba->fc_flag & FC_FABRIC) ||
1236 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1237 (phba->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001238 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001239 else
1240 /* fabric is local port if there is no F/FL_Port */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001241 node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001242
1243 spin_unlock_irq(shost->host_lock);
1244
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001245 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001246}
1247
1248
1249static struct fc_host_statistics *
1250lpfc_get_stats(struct Scsi_Host *shost)
1251{
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001252 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
dea31012005-04-17 16:05:31 -05001253 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001254 struct fc_host_statistics *hs = &phba->link_stats;
dea31012005-04-17 16:05:31 -05001255 LPFC_MBOXQ_t *pmboxq;
1256 MAILBOX_t *pmb;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001257 int rc = 0;
dea31012005-04-17 16:05:31 -05001258
1259 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1260 if (!pmboxq)
1261 return NULL;
1262 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1263
1264 pmb = &pmboxq->mb;
1265 pmb->mbxCommand = MBX_READ_STATUS;
1266 pmb->mbxOwner = OWN_HOST;
1267 pmboxq->context1 = NULL;
1268
1269 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001270 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001271 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001272 else
dea31012005-04-17 16:05:31 -05001273 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1274
1275 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001276 if (rc == MBX_TIMEOUT)
1277 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1278 else
1279 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001280 return NULL;
1281 }
1282
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001283 memset(hs, 0, sizeof (struct fc_host_statistics));
1284
dea31012005-04-17 16:05:31 -05001285 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1286 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1287 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1288 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1289
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001290 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001291 pmb->mbxCommand = MBX_READ_LNK_STAT;
1292 pmb->mbxOwner = OWN_HOST;
1293 pmboxq->context1 = NULL;
1294
1295 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001296 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001297 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001298 else
dea31012005-04-17 16:05:31 -05001299 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1300
1301 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001302 if (rc == MBX_TIMEOUT)
1303 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1304 else
1305 mempool_free( pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001306 return NULL;
1307 }
1308
1309 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1310 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1311 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1312 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1313 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1314 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1315 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1316
1317 if (phba->fc_topology == TOPOLOGY_LOOP) {
1318 hs->lip_count = (phba->fc_eventTag >> 1);
1319 hs->nos_count = -1;
1320 } else {
1321 hs->lip_count = -1;
1322 hs->nos_count = (phba->fc_eventTag >> 1);
1323 }
1324
1325 hs->dumped_frames = -1;
1326
1327/* FIX ME */
1328 /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
1329
1330 return hs;
1331}
1332
1333
1334/*
1335 * The LPFC driver treats linkdown handling as target loss events so there
1336 * are no sysfs handlers for link_down_tmo.
1337 */
1338static void
1339lpfc_get_starget_port_id(struct scsi_target *starget)
1340{
1341 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001342 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
dea31012005-04-17 16:05:31 -05001343 uint32_t did = -1;
1344 struct lpfc_nodelist *ndlp = NULL;
1345
1346 spin_lock_irq(shost->host_lock);
1347 /* Search the mapped list for this target ID */
1348 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1349 if (starget->id == ndlp->nlp_sid) {
1350 did = ndlp->nlp_DID;
1351 break;
1352 }
1353 }
1354 spin_unlock_irq(shost->host_lock);
1355
1356 fc_starget_port_id(starget) = did;
1357}
1358
1359static void
1360lpfc_get_starget_node_name(struct scsi_target *starget)
1361{
1362 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001363 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001364 u64 node_name = 0;
dea31012005-04-17 16:05:31 -05001365 struct lpfc_nodelist *ndlp = NULL;
1366
1367 spin_lock_irq(shost->host_lock);
1368 /* Search the mapped list for this target ID */
1369 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1370 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001371 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001372 break;
1373 }
1374 }
1375 spin_unlock_irq(shost->host_lock);
1376
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001377 fc_starget_node_name(starget) = node_name;
dea31012005-04-17 16:05:31 -05001378}
1379
1380static void
1381lpfc_get_starget_port_name(struct scsi_target *starget)
1382{
1383 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
Jamie Wellnitz7f0b5b12006-02-28 19:25:24 -05001384 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001385 u64 port_name = 0;
dea31012005-04-17 16:05:31 -05001386 struct lpfc_nodelist *ndlp = NULL;
1387
1388 spin_lock_irq(shost->host_lock);
1389 /* Search the mapped list for this target ID */
1390 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1391 if (starget->id == ndlp->nlp_sid) {
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001392 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001393 break;
1394 }
1395 }
1396 spin_unlock_irq(shost->host_lock);
1397
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001398 fc_starget_port_name(starget) = port_name;
dea31012005-04-17 16:05:31 -05001399}
1400
1401static void
1402lpfc_get_rport_loss_tmo(struct fc_rport *rport)
1403{
1404 /*
1405 * Return the driver's global value for device loss timeout plus
1406 * five seconds to allow the driver's nodev timer to run.
1407 */
1408 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1409}
1410
1411static void
1412lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1413{
1414 /*
1415 * The driver doesn't have a per-target timeout setting. Set
1416 * this value globally. lpfc_nodev_tmo should be greater then 0.
1417 */
1418 if (timeout)
1419 lpfc_nodev_tmo = timeout;
1420 else
1421 lpfc_nodev_tmo = 1;
1422 rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
1423}
1424
1425
1426#define lpfc_rport_show_function(field, format_string, sz, cast) \
1427static ssize_t \
1428lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1429{ \
1430 struct fc_rport *rport = transport_class_to_rport(cdev); \
1431 struct lpfc_rport_data *rdata = rport->hostdata; \
1432 return snprintf(buf, sz, format_string, \
1433 (rdata->target) ? cast rdata->target->field : 0); \
1434}
1435
1436#define lpfc_rport_rd_attr(field, format_string, sz) \
1437 lpfc_rport_show_function(field, format_string, sz, ) \
1438static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1439
1440
1441struct fc_function_template lpfc_transport_functions = {
1442 /* fixed attributes the driver supports */
1443 .show_host_node_name = 1,
1444 .show_host_port_name = 1,
1445 .show_host_supported_classes = 1,
1446 .show_host_supported_fc4s = 1,
1447 .show_host_symbolic_name = 1,
1448 .show_host_supported_speeds = 1,
1449 .show_host_maxframe_size = 1,
1450
1451 /* dynamic attributes the driver supports */
1452 .get_host_port_id = lpfc_get_host_port_id,
1453 .show_host_port_id = 1,
1454
1455 .get_host_port_type = lpfc_get_host_port_type,
1456 .show_host_port_type = 1,
1457
1458 .get_host_port_state = lpfc_get_host_port_state,
1459 .show_host_port_state = 1,
1460
1461 /* active_fc4s is shown but doesn't change (thus no get function) */
1462 .show_host_active_fc4s = 1,
1463
1464 .get_host_speed = lpfc_get_host_speed,
1465 .show_host_speed = 1,
1466
1467 .get_host_fabric_name = lpfc_get_host_fabric_name,
1468 .show_host_fabric_name = 1,
1469
1470 /*
1471 * The LPFC driver treats linkdown handling as target loss events
1472 * so there are no sysfs handlers for link_down_tmo.
1473 */
1474
1475 .get_fc_host_stats = lpfc_get_stats,
1476
1477 /* the LPFC driver doesn't support resetting stats yet */
1478
1479 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1480 .show_rport_maxframe_size = 1,
1481 .show_rport_supported_classes = 1,
1482
1483 .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
1484 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1485 .show_rport_dev_loss_tmo = 1,
1486
1487 .get_starget_port_id = lpfc_get_starget_port_id,
1488 .show_starget_port_id = 1,
1489
1490 .get_starget_node_name = lpfc_get_starget_node_name,
1491 .show_starget_node_name = 1,
1492
1493 .get_starget_port_name = lpfc_get_starget_port_name,
1494 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07001495
1496 .issue_fc_host_lip = lpfc_issue_lip,
dea31012005-04-17 16:05:31 -05001497};
1498
1499void
1500lpfc_get_cfgparam(struct lpfc_hba *phba)
1501{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001502 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1503 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1504 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001505 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04001506 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1507 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1508 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1509 lpfc_ack0_init(phba, lpfc_ack0);
1510 lpfc_topology_init(phba, lpfc_topology);
1511 lpfc_scan_down_init(phba, lpfc_scan_down);
1512 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
1513 lpfc_link_speed_init(phba, lpfc_link_speed);
1514 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1515 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1516 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001517 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
1518
1519 phba->cfg_poll = lpfc_poll;
dea31012005-04-17 16:05:31 -05001520
1521 /*
1522 * The total number of segments is the configuration value plus 2
1523 * since the IOCB need a command and response bde.
1524 */
1525 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1526
1527 /*
1528 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1529 * used to create the sg_dma_buf_pool must be dynamically calculated
1530 */
1531 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1532 sizeof(struct fcp_rsp) +
1533 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1534
1535 switch (phba->pcidev->device) {
1536 case PCI_DEVICE_ID_LP101:
1537 case PCI_DEVICE_ID_BSMB:
1538 case PCI_DEVICE_ID_ZSMB:
1539 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1540 break;
1541 case PCI_DEVICE_ID_RFLY:
1542 case PCI_DEVICE_ID_PFLY:
1543 case PCI_DEVICE_ID_BMID:
1544 case PCI_DEVICE_ID_ZMID:
1545 case PCI_DEVICE_ID_TFLY:
1546 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1547 break;
1548 default:
1549 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1550 }
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001551
1552 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
1553 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1554
dea31012005-04-17 16:05:31 -05001555 return;
1556}