blob: 5cb7924fe3d7d82a0eca71f11b43dbf180cf8473 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
32
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_logmsg.h"
39#include "lpfc_version.h"
40#include "lpfc_compat.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050043
James Smartc01f3202006-08-18 17:47:08 -040044#define LPFC_DEF_DEVLOSS_TMO 30
45#define LPFC_MIN_DEVLOSS_TMO 1
46#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050047
48static void
49lpfc_jedec_to_ascii(int incr, char hdw[])
50{
51 int i, j;
52 for (i = 0; i < 8; i++) {
53 j = (incr & 0xf);
54 if (j <= 9)
55 hdw[7 - i] = 0x30 + j;
56 else
57 hdw[7 - i] = 0x61 + j - 10;
58 incr = (incr >> 4);
59 }
60 hdw[8] = 0;
61 return;
62}
63
64static ssize_t
65lpfc_drvr_version_show(struct class_device *cdev, char *buf)
66{
67 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
68}
69
70static ssize_t
71management_version_show(struct class_device *cdev, char *buf)
72{
73 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
74}
75
76static ssize_t
77lpfc_info_show(struct class_device *cdev, char *buf)
78{
79 struct Scsi_Host *host = class_to_shost(cdev);
James Smart2e0fef82007-06-17 19:56:36 -050080
dea31012005-04-17 16:05:31 -050081 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
82}
83
84static ssize_t
85lpfc_serialnum_show(struct class_device *cdev, char *buf)
86{
James Smart2e0fef82007-06-17 19:56:36 -050087 struct Scsi_Host *shost = class_to_shost(cdev);
88 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
89 struct lpfc_hba *phba = vport->phba;
90
dea31012005-04-17 16:05:31 -050091 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
92}
93
94static ssize_t
95lpfc_modeldesc_show(struct class_device *cdev, char *buf)
96{
James Smart2e0fef82007-06-17 19:56:36 -050097 struct Scsi_Host *shost = class_to_shost(cdev);
98 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
99 struct lpfc_hba *phba = vport->phba;
100
dea31012005-04-17 16:05:31 -0500101 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
102}
103
104static ssize_t
105lpfc_modelname_show(struct class_device *cdev, char *buf)
106{
James Smart2e0fef82007-06-17 19:56:36 -0500107 struct Scsi_Host *shost = class_to_shost(cdev);
108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
110
dea31012005-04-17 16:05:31 -0500111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
112}
113
114static ssize_t
115lpfc_programtype_show(struct class_device *cdev, char *buf)
116{
James Smart2e0fef82007-06-17 19:56:36 -0500117 struct Scsi_Host *shost = class_to_shost(cdev);
118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
119 struct lpfc_hba *phba = vport->phba;
120
dea31012005-04-17 16:05:31 -0500121 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
122}
123
124static ssize_t
James Smart2e0fef82007-06-17 19:56:36 -0500125lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea31012005-04-17 16:05:31 -0500126{
James Smart2e0fef82007-06-17 19:56:36 -0500127 struct Scsi_Host *shost = class_to_shost(cdev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
dea31012005-04-17 16:05:31 -0500131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
132}
133
134static ssize_t
135lpfc_fwrev_show(struct class_device *cdev, char *buf)
136{
James Smart2e0fef82007-06-17 19:56:36 -0500137 struct Scsi_Host *shost = class_to_shost(cdev);
138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500140 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500141
dea31012005-04-17 16:05:31 -0500142 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500143 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500144}
145
146static ssize_t
147lpfc_hdw_show(struct class_device *cdev, char *buf)
148{
149 char hdw[9];
James Smart2e0fef82007-06-17 19:56:36 -0500150 struct Scsi_Host *shost = class_to_shost(cdev);
151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500153 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500154
dea31012005-04-17 16:05:31 -0500155 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
156 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
157}
158static ssize_t
159lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
160{
James Smart2e0fef82007-06-17 19:56:36 -0500161 struct Scsi_Host *shost = class_to_shost(cdev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
164
dea31012005-04-17 16:05:31 -0500165 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
166}
167static ssize_t
168lpfc_state_show(struct class_device *cdev, char *buf)
169{
James Smart2e0fef82007-06-17 19:56:36 -0500170 struct Scsi_Host *shost = class_to_shost(cdev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173 int len = 0;
174
175 switch (phba->link_state) {
176 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500177 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500178 case LPFC_INIT_START:
179 case LPFC_INIT_MBX_CMDS:
180 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500181 case LPFC_HBA_ERROR:
James Smart92d7f7b2007-06-17 19:56:38 -0500182 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
dea31012005-04-17 16:05:31 -0500183 break;
184 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500185 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -0500186 case LPFC_HBA_READY:
James Smart2e0fef82007-06-17 19:56:36 -0500187 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
188
189 switch (vport->port_state) {
190 len += snprintf(buf + len, PAGE_SIZE-len,
191 "initializing\n");
192 break;
193 case LPFC_LOCAL_CFG_LINK:
194 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500195 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500196 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500197 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500198 case LPFC_FLOGI:
199 case LPFC_FABRIC_CFG_LINK:
200 case LPFC_NS_REG:
201 case LPFC_NS_QRY:
202 case LPFC_BUILD_DISC_LIST:
203 case LPFC_DISC_AUTH:
204 len += snprintf(buf + len, PAGE_SIZE - len,
205 "Discovery\n");
206 break;
207 case LPFC_VPORT_READY:
208 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
209 break;
210
James Smart92d7f7b2007-06-17 19:56:38 -0500211 case LPFC_VPORT_FAILED:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
213 break;
214
215 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "Unknown\n");
218 break;
219 }
220
dea31012005-04-17 16:05:31 -0500221 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500222 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500223 len += snprintf(buf + len, PAGE_SIZE-len,
224 " Public Loop\n");
225 else
226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Private Loop\n");
228 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500229 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500230 len += snprintf(buf + len, PAGE_SIZE-len,
231 " Fabric\n");
232 else
233 len += snprintf(buf + len, PAGE_SIZE-len,
234 " Point-2-Point\n");
235 }
236 }
James Smart2e0fef82007-06-17 19:56:36 -0500237
dea31012005-04-17 16:05:31 -0500238 return len;
239}
240
241static ssize_t
242lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
243{
James Smart2e0fef82007-06-17 19:56:36 -0500244 struct Scsi_Host *shost = class_to_shost(cdev);
245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246
247 return snprintf(buf, PAGE_SIZE, "%d\n",
248 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500249}
250
251
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700252static int
James Smart2e0fef82007-06-17 19:56:36 -0500253lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500254{
James Smart2e0fef82007-06-17 19:56:36 -0500255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
256 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500257 LPFC_MBOXQ_t *pmboxq;
258 int mbxstatus = MBXERR_ERROR;
259
James Smart2e0fef82007-06-17 19:56:36 -0500260 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
261 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
262 (vport->port_state != LPFC_VPORT_READY))
dea31012005-04-17 16:05:31 -0500263 return -EPERM;
264
265 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
266
267 if (!pmboxq)
268 return -ENOMEM;
269
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400271 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
272 pmboxq->mb.mbxOwner = OWN_HOST;
273
James Smart33ccf8d2006-08-17 11:57:58 -0400274 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500275
James Smart4db621e2006-07-06 15:49:49 -0400276 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
277 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
278 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
279 phba->cfg_link_speed);
280 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
281 phba->fc_ratov * 2);
282 }
283
James Smart5b8bd0c2007-04-25 09:52:49 -0400284 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -0500285 if (mbxstatus == MBX_TIMEOUT)
286 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
287 else
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400288 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500289
290 if (mbxstatus == MBXERR_ERROR)
291 return -EIO;
292
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700293 return 0;
dea31012005-04-17 16:05:31 -0500294}
295
James Smart40496f02006-07-06 15:50:22 -0400296static int
James Smart46fa3112007-04-25 09:51:45 -0400297lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
298{
299 struct completion online_compl;
300 struct lpfc_sli_ring *pring;
301 struct lpfc_sli *psli;
302 int status = 0;
303 int cnt = 0;
304 int i;
305
306 init_completion(&online_compl);
307 lpfc_workq_post_event(phba, &status, &online_compl,
308 LPFC_EVT_OFFLINE_PREP);
309 wait_for_completion(&online_compl);
310
311 if (status != 0)
312 return -EIO;
313
314 psli = &phba->sli;
315
316 for (i = 0; i < psli->num_rings; i++) {
317 pring = &psli->ring[i];
318 /* The linkdown event takes 30 seconds to timeout. */
319 while (pring->txcmplq_cnt) {
320 msleep(10);
321 if (cnt++ > 3000) {
322 lpfc_printf_log(phba,
323 KERN_WARNING, LOG_INIT,
324 "%d:0466 Outstanding IO when "
325 "bringing Adapter offline\n",
326 phba->brd_no);
327 break;
328 }
329 }
330 }
331
332 init_completion(&online_compl);
333 lpfc_workq_post_event(phba, &status, &online_compl, type);
334 wait_for_completion(&online_compl);
335
336 if (status != 0)
337 return -EIO;
338
339 return 0;
340}
341
342static int
James Smart40496f02006-07-06 15:50:22 -0400343lpfc_selective_reset(struct lpfc_hba *phba)
344{
345 struct completion online_compl;
346 int status = 0;
347
James Smart46fa3112007-04-25 09:51:45 -0400348 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400349
350 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400351 return status;
James Smart40496f02006-07-06 15:50:22 -0400352
353 init_completion(&online_compl);
354 lpfc_workq_post_event(phba, &status, &online_compl,
355 LPFC_EVT_ONLINE);
356 wait_for_completion(&online_compl);
357
358 if (status != 0)
359 return -EIO;
360
361 return 0;
362}
363
364static ssize_t
365lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
366{
James Smart2e0fef82007-06-17 19:56:36 -0500367 struct Scsi_Host *shost = class_to_shost(cdev);
368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
369 struct lpfc_hba *phba = vport->phba;
370
James Smart40496f02006-07-06 15:50:22 -0400371 int status = -EINVAL;
372
373 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
374 status = lpfc_selective_reset(phba);
375
376 if (status == 0)
377 return strlen(buf);
378 else
379 return status;
380}
381
dea31012005-04-17 16:05:31 -0500382static ssize_t
383lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
384{
James Smart2e0fef82007-06-17 19:56:36 -0500385 struct Scsi_Host *shost = class_to_shost(cdev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
390}
391
392static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500393lpfc_board_mode_show(struct class_device *cdev, char *buf)
394{
James Smart2e0fef82007-06-17 19:56:36 -0500395 struct Scsi_Host *shost = class_to_shost(cdev);
396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
397 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500398 char * state;
399
James Smart2e0fef82007-06-17 19:56:36 -0500400 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500401 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500402 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500403 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500404 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500405 state = "offline";
406 else
407 state = "online";
408
409 return snprintf(buf, PAGE_SIZE, "%s\n", state);
410}
411
412static ssize_t
413lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
414{
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct Scsi_Host *shost = class_to_shost(cdev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500418 struct completion online_compl;
419 int status=0;
420
421 init_completion(&online_compl);
422
James Smart46fa3112007-04-25 09:51:45 -0400423 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500424 lpfc_workq_post_event(phba, &status, &online_compl,
425 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400426 wait_for_completion(&online_compl);
427 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
428 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500429 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400430 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
431 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
432 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500433 else
434 return -EINVAL;
435
Jamie Wellnitz41415862006-02-28 19:25:27 -0500436 if (!status)
437 return strlen(buf);
438 else
439 return -EIO;
440}
441
442static ssize_t
James Smart92d7f7b2007-06-17 19:56:38 -0500443lpfc_max_vpi_show(struct class_device *cdev, char *buf)
444{
445 struct Scsi_Host *shost = class_to_shost(cdev);
446 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
447 struct lpfc_hba *phba = vport->phba;
448
449 return snprintf(buf, PAGE_SIZE, "%d\n", phba->max_vpi);
450}
451
452static ssize_t
453lpfc_used_vpi_show(struct class_device *cdev, char *buf)
454{
455 struct Scsi_Host *shost = class_to_shost(cdev);
456 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
457 struct lpfc_hba *phba = vport->phba;
458
459 /* Don't count the physical port */
460 return snprintf(buf, PAGE_SIZE, "%d\n", phba->vpi_cnt-1);
461}
462
463int
464lpfc_get_hba_info(struct lpfc_hba *phba, uint32_t *mxri,
465 uint32_t *axri, uint32_t *mrpi, uint32_t *arpi)
466{
467 struct lpfc_sli *psli = &phba->sli;
468 LPFC_MBOXQ_t *pmboxq;
469 MAILBOX_t *pmb;
470 int rc = 0;
471
472 /*
473 * prevent udev from issuing mailbox commands until the port is
474 * configured.
475 */
476 if (phba->link_state < LPFC_LINK_DOWN ||
477 !phba->mbox_mem_pool ||
478 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
479 return 0;
480
481 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
482 return 0;
483
484 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
485 if (!pmboxq)
486 return 0;
487 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
488
489 pmb = &pmboxq->mb;
490 pmb->mbxCommand = MBX_READ_CONFIG;
491 pmb->mbxOwner = OWN_HOST;
492 pmboxq->context1 = NULL;
493
494 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
495 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
496 rc = MBX_NOT_FINISHED;
497 else
498 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
499
500 if (rc != MBX_SUCCESS) {
501 if (rc == MBX_TIMEOUT)
502 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
503 else
504 mempool_free(pmboxq, phba->mbox_mem_pool);
505 return 0;
506 }
507
508 if (mrpi)
509 *mrpi = pmb->un.varRdConfig.max_rpi;
510 if (arpi)
511 *arpi = pmb->un.varRdConfig.avail_rpi;
512 if (mxri)
513 *mxri = pmb->un.varRdConfig.max_xri;
514 if (axri)
515 *axri = pmb->un.varRdConfig.avail_xri;
516
517 mempool_free(pmboxq, phba->mbox_mem_pool);
518 return 1;
519}
520
521static ssize_t
522lpfc_max_rpi_show(struct class_device *cdev, char *buf)
523{
524 struct Scsi_Host *shost = class_to_shost(cdev);
525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
526 struct lpfc_hba *phba = vport->phba;
527 uint32_t cnt;
528
529 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL))
530 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
531 return snprintf(buf, PAGE_SIZE, "Unknown\n");
532}
533
534static ssize_t
535lpfc_used_rpi_show(struct class_device *cdev, char *buf)
536{
537 struct Scsi_Host *shost = class_to_shost(cdev);
538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
539 struct lpfc_hba *phba = vport->phba;
540 uint32_t cnt, acnt;
541
542 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt))
543 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
544 return snprintf(buf, PAGE_SIZE, "Unknown\n");
545}
546
547static ssize_t
548lpfc_max_xri_show(struct class_device *cdev, char *buf)
549{
550 struct Scsi_Host *shost = class_to_shost(cdev);
551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
552 struct lpfc_hba *phba = vport->phba;
553 uint32_t cnt;
554
555 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL))
556 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
557 return snprintf(buf, PAGE_SIZE, "Unknown\n");
558}
559
560static ssize_t
561lpfc_used_xri_show(struct class_device *cdev, char *buf)
562{
563 struct Scsi_Host *shost = class_to_shost(cdev);
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
566 uint32_t cnt, acnt;
567
568 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL))
569 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
570 return snprintf(buf, PAGE_SIZE, "Unknown\n");
571}
572
573static ssize_t
574lpfc_npiv_info_show(struct class_device *cdev, char *buf)
575{
576 struct Scsi_Host *shost = class_to_shost(cdev);
577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
578 struct lpfc_hba *phba = vport->phba;
579
580 if (!(phba->max_vpi))
581 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
582 if (vport->port_type == LPFC_PHYSICAL_PORT)
583 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
584 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
585}
586
587static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500588lpfc_poll_show(struct class_device *cdev, char *buf)
589{
James Smart2e0fef82007-06-17 19:56:36 -0500590 struct Scsi_Host *shost = class_to_shost(cdev);
591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
592 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500593
594 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
595}
596
597static ssize_t
598lpfc_poll_store(struct class_device *cdev, const char *buf,
599 size_t count)
600{
James Smart2e0fef82007-06-17 19:56:36 -0500601 struct Scsi_Host *shost = class_to_shost(cdev);
602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500604 uint32_t creg_val;
605 uint32_t old_val;
606 int val=0;
607
608 if (!isdigit(buf[0]))
609 return -EINVAL;
610
611 if (sscanf(buf, "%i", &val) != 1)
612 return -EINVAL;
613
614 if ((val & 0x3) != val)
615 return -EINVAL;
616
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500618
619 old_val = phba->cfg_poll;
620
621 if (val & ENABLE_FCP_RING_POLLING) {
622 if ((val & DISABLE_FCP_RING_INT) &&
623 !(old_val & DISABLE_FCP_RING_INT)) {
624 creg_val = readl(phba->HCregaddr);
625 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
626 writel(creg_val, phba->HCregaddr);
627 readl(phba->HCregaddr); /* flush */
628
629 lpfc_poll_start_timer(phba);
630 }
631 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500632 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500633 return -EINVAL;
634 }
635
636 if (!(val & DISABLE_FCP_RING_INT) &&
637 (old_val & DISABLE_FCP_RING_INT))
638 {
James Smart2e0fef82007-06-17 19:56:36 -0500639 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500640 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500642 creg_val = readl(phba->HCregaddr);
643 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
644 writel(creg_val, phba->HCregaddr);
645 readl(phba->HCregaddr); /* flush */
646 }
647
648 phba->cfg_poll = val;
649
James Smart2e0fef82007-06-17 19:56:36 -0500650 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500651
652 return strlen(buf);
653}
dea31012005-04-17 16:05:31 -0500654
655#define lpfc_param_show(attr) \
656static ssize_t \
657lpfc_##attr##_show(struct class_device *cdev, char *buf) \
658{ \
James Smart2e0fef82007-06-17 19:56:36 -0500659 struct Scsi_Host *shost = class_to_shost(cdev);\
660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
661 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500662 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400663 val = phba->cfg_##attr;\
664 return snprintf(buf, PAGE_SIZE, "%d\n",\
665 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500666}
667
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400668#define lpfc_param_hex_show(attr) \
669static ssize_t \
670lpfc_##attr##_show(struct class_device *cdev, char *buf) \
671{ \
James Smart2e0fef82007-06-17 19:56:36 -0500672 struct Scsi_Host *shost = class_to_shost(cdev);\
673 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
674 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400675 int val = 0;\
676 val = phba->cfg_##attr;\
677 return snprintf(buf, PAGE_SIZE, "%#x\n",\
678 phba->cfg_##attr);\
679}
680
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400681#define lpfc_param_init(attr, default, minval, maxval) \
682static int \
683lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
684{ \
685 if (val >= minval && val <= maxval) {\
686 phba->cfg_##attr = val;\
687 return 0;\
688 }\
689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
690 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
691 "allowed range is ["#minval", "#maxval"]\n", \
692 phba->brd_no, val); \
693 phba->cfg_##attr = default;\
694 return -EINVAL;\
695}
696
697#define lpfc_param_set(attr, default, minval, maxval) \
698static int \
699lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
700{ \
701 if (val >= minval && val <= maxval) {\
702 phba->cfg_##attr = val;\
703 return 0;\
704 }\
705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
706 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
707 "allowed range is ["#minval", "#maxval"]\n", \
708 phba->brd_no, val); \
709 return -EINVAL;\
710}
711
712#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500713static ssize_t \
714lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
715{ \
James Smart2e0fef82007-06-17 19:56:36 -0500716 struct Scsi_Host *shost = class_to_shost(cdev);\
717 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
718 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400719 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400720 if (!isdigit(buf[0]))\
721 return -EINVAL;\
722 if (sscanf(buf, "%i", &val) != 1)\
723 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400724 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400725 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400726 else \
727 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500728}
729
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400730#define LPFC_ATTR(name, defval, minval, maxval, desc) \
731static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500732module_param(lpfc_##name, int, 0);\
733MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400734lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500735
736#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
737static int lpfc_##name = defval;\
738module_param(lpfc_##name, int, 0);\
739MODULE_PARM_DESC(lpfc_##name, desc);\
740lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400741lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500742static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
743
744#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
745static int lpfc_##name = defval;\
746module_param(lpfc_##name, int, 0);\
747MODULE_PARM_DESC(lpfc_##name, desc);\
748lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400749lpfc_param_init(name, defval, minval, maxval)\
750lpfc_param_set(name, defval, minval, maxval)\
751lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500752static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
753 lpfc_##name##_show, lpfc_##name##_store)
754
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400755#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
756static int lpfc_##name = defval;\
757module_param(lpfc_##name, int, 0);\
758MODULE_PARM_DESC(lpfc_##name, desc);\
759lpfc_param_hex_show(name)\
760lpfc_param_init(name, defval, minval, maxval)\
761static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
762
763#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
764static int lpfc_##name = defval;\
765module_param(lpfc_##name, int, 0);\
766MODULE_PARM_DESC(lpfc_##name, desc);\
767lpfc_param_hex_show(name)\
768lpfc_param_init(name, defval, minval, maxval)\
769lpfc_param_set(name, defval, minval, maxval)\
770lpfc_param_store(name)\
771static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
772 lpfc_##name##_show, lpfc_##name##_store)
773
dea31012005-04-17 16:05:31 -0500774static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
775static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
776static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
777static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
778static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500779static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500780static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
781static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
782static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
783static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
784 lpfc_option_rom_version_show, NULL);
785static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
786 lpfc_num_discovered_ports_show, NULL);
787static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
788static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
789 NULL);
790static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
791 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500792static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
793 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400794static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500795static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
796static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
797static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
798static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
799static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
800static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
801static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
dea31012005-04-17 16:05:31 -0500802
James Smartc3f28af2006-08-18 17:47:18 -0400803
James Smarta12e07b2006-12-02 13:35:30 -0500804static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400805
806static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500807lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400808 size_t count)
809{
James Smart2e0fef82007-06-17 19:56:36 -0500810 struct Scsi_Host *shost = class_to_shost(cdev);
811 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
812 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400813 unsigned int cnt = count;
814
815 /*
816 * We're doing a simple sanity check for soft_wwpn setting.
817 * We require that the user write a specific key to enable
818 * the soft_wwpn attribute to be settable. Once the attribute
819 * is written, the enable key resets. If further updates are
820 * desired, the key must be written again to re-enable the
821 * attribute.
822 *
823 * The "key" is not secret - it is a hardcoded string shown
824 * here. The intent is to protect against the random user or
825 * application that is just writing attributes.
826 */
827
828 /* count may include a LF at end of string */
829 if (buf[cnt-1] == '\n')
830 cnt--;
831
James Smarta12e07b2006-12-02 13:35:30 -0500832 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
833 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400834 return -EINVAL;
835
James Smarta12e07b2006-12-02 13:35:30 -0500836 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400837 return count;
838}
James Smarta12e07b2006-12-02 13:35:30 -0500839static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
840 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400841
842static ssize_t
843lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
844{
James Smart2e0fef82007-06-17 19:56:36 -0500845 struct Scsi_Host *shost = class_to_shost(cdev);
846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
848
Randy Dunlapafc071e2006-10-23 21:47:13 -0700849 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
850 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400851}
852
853
854static ssize_t
855lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
856{
James Smart2e0fef82007-06-17 19:56:36 -0500857 struct Scsi_Host *shost = class_to_shost(cdev);
858 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
859 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400860 struct completion online_compl;
861 int stat1=0, stat2=0;
862 unsigned int i, j, cnt=count;
863 u8 wwpn[8];
864
865 /* count may include a LF at end of string */
866 if (buf[cnt-1] == '\n')
867 cnt--;
868
James Smarta12e07b2006-12-02 13:35:30 -0500869 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400870 ((cnt == 17) && (*buf++ != 'x')) ||
871 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
872 return -EINVAL;
873
James Smarta12e07b2006-12-02 13:35:30 -0500874 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400875
876 memset(wwpn, 0, sizeof(wwpn));
877
878 /* Validate and store the new name */
879 for (i=0, j=0; i < 16; i++) {
880 if ((*buf >= 'a') && (*buf <= 'f'))
881 j = ((j << 4) | ((*buf++ -'a') + 10));
882 else if ((*buf >= 'A') && (*buf <= 'F'))
883 j = ((j << 4) | ((*buf++ -'A') + 10));
884 else if ((*buf >= '0') && (*buf <= '9'))
885 j = ((j << 4) | (*buf++ -'0'));
886 else
887 return -EINVAL;
888 if (i % 2) {
889 wwpn[i/2] = j & 0xff;
890 j = 0;
891 }
892 }
893 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -0500894 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -0500895 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500896 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -0400897
898 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
899 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
900
James Smart46fa3112007-04-25 09:51:45 -0400901 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -0400902 if (stat1)
903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
904 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
905 "adapter - %d\n", phba->brd_no, stat1);
906
907 init_completion(&online_compl);
908 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
909 wait_for_completion(&online_compl);
910 if (stat2)
911 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
912 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
913 "adapter - %d\n", phba->brd_no, stat2);
914
915 return (stat1 || stat2) ? -EIO : count;
916}
917static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
918 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
919
James Smarta12e07b2006-12-02 13:35:30 -0500920static ssize_t
921lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
922{
923 struct Scsi_Host *host = class_to_shost(cdev);
924 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
925 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
926 (unsigned long long)phba->cfg_soft_wwnn);
927}
928
929
930static ssize_t
931lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
932{
933 struct Scsi_Host *host = class_to_shost(cdev);
934 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
935 unsigned int i, j, cnt=count;
936 u8 wwnn[8];
937
938 /* count may include a LF at end of string */
939 if (buf[cnt-1] == '\n')
940 cnt--;
941
942 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
943 ((cnt == 17) && (*buf++ != 'x')) ||
944 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
945 return -EINVAL;
946
947 /*
948 * Allow wwnn to be set many times, as long as the enable is set.
949 * However, once the wwpn is set, everything locks.
950 */
951
952 memset(wwnn, 0, sizeof(wwnn));
953
954 /* Validate and store the new name */
955 for (i=0, j=0; i < 16; i++) {
956 if ((*buf >= 'a') && (*buf <= 'f'))
957 j = ((j << 4) | ((*buf++ -'a') + 10));
958 else if ((*buf >= 'A') && (*buf <= 'F'))
959 j = ((j << 4) | ((*buf++ -'A') + 10));
960 else if ((*buf >= '0') && (*buf <= '9'))
961 j = ((j << 4) | (*buf++ -'0'));
962 else
963 return -EINVAL;
964 if (i % 2) {
965 wwnn[i/2] = j & 0xff;
966 j = 0;
967 }
968 }
969 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
970
971 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
972 "lpfc%d: soft_wwnn set. Value will take effect upon "
973 "setting of the soft_wwpn\n", phba->brd_no);
974
975 return count;
976}
977static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
978 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
979
James Smartc3f28af2006-08-18 17:47:18 -0400980
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500981static int lpfc_poll = 0;
982module_param(lpfc_poll, int, 0);
983MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
984 " 0 - none,"
985 " 1 - poll with interrupts enabled"
986 " 3 - poll and disable FCP ring interrupts");
987
988static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
989 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -0500990
James Smart92d7f7b2007-06-17 19:56:38 -0500991int lpfc_sli_mode = 0;
992module_param(lpfc_sli_mode, int, 0);
993MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
994 " 0 - auto (SLI-3 if supported),"
995 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
996 " 3 - select SLI-3");
997
998int lpfc_npiv_enable = 0;
999module_param(lpfc_npiv_enable, int, 0);
1000MODULE_PARM_DESC(lpfc_npiv_enable, "Enable NPIV functionality");
1001
dea31012005-04-17 16:05:31 -05001002/*
James Smartc01f3202006-08-18 17:47:08 -04001003# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1004# until the timer expires. Value range is [0,255]. Default value is 30.
1005*/
1006static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1007static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1008module_param(lpfc_nodev_tmo, int, 0);
1009MODULE_PARM_DESC(lpfc_nodev_tmo,
1010 "Seconds driver will hold I/O waiting "
1011 "for a device to come back");
1012static ssize_t
1013lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1014{
James Smart2e0fef82007-06-17 19:56:36 -05001015 struct Scsi_Host *shost = class_to_shost(cdev);
1016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1017 struct lpfc_hba *phba = vport->phba;
James Smartc01f3202006-08-18 17:47:08 -04001018 int val = 0;
1019 val = phba->cfg_devloss_tmo;
1020 return snprintf(buf, PAGE_SIZE, "%d\n",
1021 phba->cfg_devloss_tmo);
1022}
1023
1024static int
1025lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
1026{
1027 static int warned;
1028 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1029 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
1030 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
1031 warned = 1;
1032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1033 "%d:0402 Ignoring nodev_tmo module "
1034 "parameter because devloss_tmo is"
1035 " set.\n",
1036 phba->brd_no);
1037 }
1038 return 0;
1039 }
1040
1041 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1042 phba->cfg_nodev_tmo = val;
1043 phba->cfg_devloss_tmo = val;
1044 return 0;
1045 }
1046 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1047 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
1048 "allowed range is [%d, %d]\n",
1049 phba->brd_no, val,
1050 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
1051 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1052 return -EINVAL;
1053}
1054
1055static int
1056lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
1057{
1058 if (phba->dev_loss_tmo_changed ||
1059 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
1060 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1061 "%d:0401 Ignoring change to nodev_tmo "
1062 "because devloss_tmo is set.\n",
1063 phba->brd_no);
1064 return 0;
1065 }
1066
1067 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1068 phba->cfg_nodev_tmo = val;
1069 phba->cfg_devloss_tmo = val;
1070 return 0;
1071 }
1072
1073 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1074 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
1075 "allowed range is [%d, %d]\n",
1076 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
1077 LPFC_MAX_DEVLOSS_TMO);
1078 return -EINVAL;
1079}
1080
1081lpfc_param_store(nodev_tmo)
1082
1083static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1084 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1085
1086/*
1087# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1088# disappear until the timer expires. Value range is [0,255]. Default
1089# value is 30.
1090*/
1091module_param(lpfc_devloss_tmo, int, 0);
1092MODULE_PARM_DESC(lpfc_devloss_tmo,
1093 "Seconds driver will hold I/O waiting "
1094 "for a device to come back");
1095lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1096 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1097lpfc_param_show(devloss_tmo)
1098static int
1099lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
1100{
1101 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
1102 phba->cfg_nodev_tmo = val;
1103 phba->cfg_devloss_tmo = val;
1104 phba->dev_loss_tmo_changed = 1;
1105 return 0;
1106 }
1107
1108 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1109 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
1110 " %d, allowed range is [%d, %d]\n",
1111 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
1112 LPFC_MAX_DEVLOSS_TMO);
1113 return -EINVAL;
1114}
1115
1116lpfc_param_store(devloss_tmo)
1117static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1118 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1119
1120/*
dea31012005-04-17 16:05:31 -05001121# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1122# deluged with LOTS of information.
1123# You can set a bit mask to record specific types of verbose messages:
1124#
1125# LOG_ELS 0x1 ELS events
1126# LOG_DISCOVERY 0x2 Link discovery events
1127# LOG_MBOX 0x4 Mailbox events
1128# LOG_INIT 0x8 Initialization events
1129# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001130# LOG_FCP 0x40 FCP traffic history
1131# LOG_NODE 0x80 Node table events
1132# LOG_MISC 0x400 Miscellaneous events
1133# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001134# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001135# LOG_LIBDFC 0x2000 LIBDFC events
1136# LOG_ALL_MSG 0xffff LOG all messages
1137*/
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -04001138LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001139
1140/*
1141# lun_queue_depth: This parameter is used to limit the number of outstanding
1142# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1143*/
1144LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
1145 "Max number of FCP commands we can queue to a specific LUN");
1146
1147/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001148# hba_queue_depth: This parameter is used to limit the number of outstanding
1149# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1150# value is greater than the maximum number of exchanges supported by the HBA,
1151# then maximum number of exchanges supported by the HBA is used to determine
1152# the hba_queue_depth.
1153*/
1154LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1155 "Max number of FCP commands we can queue to a lpfc HBA");
1156
1157/*
James Smart92d7f7b2007-06-17 19:56:38 -05001158# peer_port_login: This parameter allows/prevents logins
1159# between peer ports hosted on the same physical port.
1160# When this parameter is set 0 peer ports of same physical port
1161# are not allowed to login to each other.
1162# When this parameter is set 1 peer ports of same physical port
1163# are allowed to login to each other.
1164# Default value of this parameter is 0.
1165*/
1166LPFC_ATTR_R(peer_port_login, 0, 0, 1,
1167 "Allow peer ports on the same physical port to login to each "
1168 "other.");
1169
1170/*
1171# vport_restrict_login: This parameter allows/prevents logins
1172# between Virtual Ports and remote initiators.
1173# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1174# other initiators and will attempt to PLOGI all remote ports.
1175# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1176# remote ports and will not attempt to PLOGI to other initiators.
1177# This parameter does not restrict to the physical port.
1178# This parameter does not restrict logins to Fabric resident remote ports.
1179# Default value of this parameter is 1.
1180*/
1181LPFC_ATTR_RW(vport_restrict_login, 1, 0, 1,
1182 "Restrict virtual ports login to remote initiators.");
1183
1184/*
dea31012005-04-17 16:05:31 -05001185# Some disk devices have a "select ID" or "select Target" capability.
1186# From a protocol standpoint "select ID" usually means select the
1187# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1188# annex" which contains a table that maps a "select ID" (a number
1189# between 0 and 7F) to an ALPA. By default, for compatibility with
1190# older drivers, the lpfc driver scans this table from low ALPA to high
1191# ALPA.
1192#
1193# Turning on the scan-down variable (on = 1, off = 0) will
1194# cause the lpfc driver to use an inverted table, effectively
1195# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1196#
1197# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1198# and will not work across a fabric. Also this parameter will take
1199# effect only in the case when ALPA map is not available.)
1200*/
1201LPFC_ATTR_R(scan_down, 1, 0, 1,
1202 "Start scanning for devices from highest ALPA to lowest");
1203
1204/*
dea31012005-04-17 16:05:31 -05001205# lpfc_topology: link topology for init link
1206# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001207# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001208# 0x02 = attempt point-to-point mode only
1209# 0x04 = attempt loop mode only
1210# 0x06 = attempt point-to-point mode then loop
1211# Set point-to-point mode if you want to run as an N_Port.
1212# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1213# Default value is 0.
1214*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001215LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001216
1217/*
1218# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1219# connection.
1220# 0 = auto select (default)
1221# 1 = 1 Gigabaud
1222# 2 = 2 Gigabaud
1223# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001224# 8 = 8 Gigabaud
1225# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001226*/
James Smartb87eab32007-04-25 09:53:28 -04001227LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001228
1229/*
1230# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1231# Value range is [2,3]. Default value is 3.
1232*/
1233LPFC_ATTR_R(fcp_class, 3, 2, 3,
1234 "Select Fibre Channel class of service for FCP sequences");
1235
1236/*
1237# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1238# is [0,1]. Default value is 0.
1239*/
1240LPFC_ATTR_RW(use_adisc, 0, 0, 1,
1241 "Use ADISC on rediscovery to authenticate FCP devices");
1242
1243/*
1244# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1245# range is [0,1]. Default value is 0.
1246*/
1247LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1248
1249/*
1250# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1251# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001252# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001253# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1254# cr_delay is set to 0.
1255*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001256LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001257 "interrupt response is generated");
1258
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001259LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001260 "interrupt response is generated");
1261
1262/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001263# lpfc_multi_ring_support: Determines how many rings to spread available
1264# cmd/rsp IOCB entries across.
1265# Value range is [1,2]. Default value is 1.
1266*/
1267LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1268 "SLI rings to spread IOCB entries across");
1269
1270/*
James Smarta4bc3372006-12-02 13:34:16 -05001271# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1272# identifies what rctl value to configure the additional ring for.
1273# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1274*/
1275LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1276 255, "Identifies RCTL for additional ring configuration");
1277
1278/*
1279# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1280# identifies what type value to configure the additional ring for.
1281# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1282*/
1283LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1284 255, "Identifies TYPE for additional ring configuration");
1285
1286/*
dea31012005-04-17 16:05:31 -05001287# lpfc_fdmi_on: controls FDMI support.
1288# 0 = no FDMI support
1289# 1 = support FDMI without attribute of hostname
1290# 2 = support FDMI with attribute of hostname
1291# Value range [0,2]. Default value is 0.
1292*/
1293LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1294
1295/*
1296# Specifies the maximum number of ELS cmds we can have outstanding (for
1297# discovery). Value range is [1,64]. Default value = 32.
1298*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001299LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001300 "during discovery");
1301
1302/*
James Smart65a29c12006-07-06 15:50:50 -04001303# lpfc_max_luns: maximum allowed LUN.
1304# Value range is [0,65535]. Default value is 255.
1305# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001306*/
James Smart65a29c12006-07-06 15:50:50 -04001307LPFC_ATTR_R(max_luns, 255, 0, 65535,
1308 "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001309
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001310/*
1311# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1312# Value range is [1,255], default value is 10.
1313*/
1314LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1315 "Milliseconds driver will wait between polling FCP ring");
1316
James Smart4ff43242006-12-02 13:34:56 -05001317/*
1318# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1319# support this feature
1320# 0 = MSI disabled (default)
1321# 1 = MSI enabled
1322# Value range is [0,1]. Default value is 0.
1323*/
1324LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1325
James Smartc3f28af2006-08-18 17:47:18 -04001326
James Smart92d7f7b2007-06-17 19:56:38 -05001327
James Smart2e0fef82007-06-17 19:56:36 -05001328struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001329 &class_device_attr_info,
1330 &class_device_attr_serialnum,
1331 &class_device_attr_modeldesc,
1332 &class_device_attr_modelname,
1333 &class_device_attr_programtype,
1334 &class_device_attr_portnum,
1335 &class_device_attr_fwrev,
1336 &class_device_attr_hdw,
1337 &class_device_attr_option_rom_version,
1338 &class_device_attr_state,
1339 &class_device_attr_num_discovered_ports,
1340 &class_device_attr_lpfc_drvr_version,
1341 &class_device_attr_lpfc_log_verbose,
1342 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001343 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001344 &class_device_attr_lpfc_peer_port_login,
1345 &class_device_attr_lpfc_vport_restrict_login,
dea31012005-04-17 16:05:31 -05001346 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001347 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001348 &class_device_attr_lpfc_fcp_class,
1349 &class_device_attr_lpfc_use_adisc,
1350 &class_device_attr_lpfc_ack0,
1351 &class_device_attr_lpfc_topology,
1352 &class_device_attr_lpfc_scan_down,
1353 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001354 &class_device_attr_lpfc_cr_delay,
1355 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001356 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001357 &class_device_attr_lpfc_multi_ring_rctl,
1358 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001359 &class_device_attr_lpfc_fdmi_on,
1360 &class_device_attr_lpfc_max_luns,
1361 &class_device_attr_nport_evt_cnt,
1362 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001363 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001364 &class_device_attr_max_vpi,
1365 &class_device_attr_used_vpi,
1366 &class_device_attr_max_rpi,
1367 &class_device_attr_used_rpi,
1368 &class_device_attr_max_xri,
1369 &class_device_attr_used_xri,
1370 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001371 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001372 &class_device_attr_lpfc_poll,
1373 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001374 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001375 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001376 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001377 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001378 NULL,
1379};
1380
1381static ssize_t
1382sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1383{
1384 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001385 struct class_device *cdev = container_of(kobj, struct class_device,
1386 kobj);
1387 struct Scsi_Host *shost = class_to_shost(cdev);
1388 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1389 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001390
1391 if ((off + count) > FF_REG_AREA_SIZE)
1392 return -ERANGE;
1393
1394 if (count == 0) return 0;
1395
1396 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1397 return -EINVAL;
1398
James Smart2e0fef82007-06-17 19:56:36 -05001399 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001400 return -EPERM;
1401 }
1402
James Smart2e0fef82007-06-17 19:56:36 -05001403 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001404 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1405 writel(*((uint32_t *)(buf + buf_off)),
1406 phba->ctrl_regs_memmap_p + off + buf_off);
1407
James Smart2e0fef82007-06-17 19:56:36 -05001408 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001409
1410 return count;
1411}
1412
1413static ssize_t
1414sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1415{
1416 size_t buf_off;
1417 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001418 struct class_device *cdev = container_of(kobj, struct class_device,
1419 kobj);
1420 struct Scsi_Host *shost = class_to_shost(cdev);
1421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1422 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001423
1424 if (off > FF_REG_AREA_SIZE)
1425 return -ERANGE;
1426
1427 if ((off + count) > FF_REG_AREA_SIZE)
1428 count = FF_REG_AREA_SIZE - off;
1429
1430 if (count == 0) return 0;
1431
1432 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1433 return -EINVAL;
1434
James Smart2e0fef82007-06-17 19:56:36 -05001435 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001436
1437 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1438 tmp_ptr = (uint32_t *)(buf + buf_off);
1439 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1440 }
1441
James Smart2e0fef82007-06-17 19:56:36 -05001442 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001443
1444 return count;
1445}
1446
1447static struct bin_attribute sysfs_ctlreg_attr = {
1448 .attr = {
1449 .name = "ctlreg",
1450 .mode = S_IRUSR | S_IWUSR,
1451 .owner = THIS_MODULE,
1452 },
1453 .size = 256,
1454 .read = sysfs_ctlreg_read,
1455 .write = sysfs_ctlreg_write,
1456};
1457
1458
1459static void
James Smart2e0fef82007-06-17 19:56:36 -05001460sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001461{
1462 phba->sysfs_mbox.state = SMBOX_IDLE;
1463 phba->sysfs_mbox.offset = 0;
1464
1465 if (phba->sysfs_mbox.mbox) {
1466 mempool_free(phba->sysfs_mbox.mbox,
1467 phba->mbox_mem_pool);
1468 phba->sysfs_mbox.mbox = NULL;
1469 }
1470}
1471
1472static ssize_t
1473sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1474{
James Smart2e0fef82007-06-17 19:56:36 -05001475 struct class_device *cdev = container_of(kobj, struct class_device,
1476 kobj);
1477 struct Scsi_Host *shost = class_to_shost(cdev);
1478 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1479 struct lpfc_hba *phba = vport->phba;
1480 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001481
1482 if ((count + off) > MAILBOX_CMD_SIZE)
1483 return -ERANGE;
1484
1485 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1486 return -EINVAL;
1487
1488 if (count == 0)
1489 return 0;
1490
1491 if (off == 0) {
1492 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1493 if (!mbox)
1494 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001495 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001496 }
1497
James Smart2e0fef82007-06-17 19:56:36 -05001498 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001499
1500 if (off == 0) {
1501 if (phba->sysfs_mbox.mbox)
1502 mempool_free(mbox, phba->mbox_mem_pool);
1503 else
1504 phba->sysfs_mbox.mbox = mbox;
1505 phba->sysfs_mbox.state = SMBOX_WRITING;
1506 } else {
1507 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1508 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001509 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001510 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001511 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001512 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001513 }
1514 }
1515
1516 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1517 buf, count);
1518
1519 phba->sysfs_mbox.offset = off + count;
1520
James Smart2e0fef82007-06-17 19:56:36 -05001521 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001522
1523 return count;
1524}
1525
1526static ssize_t
1527sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1528{
James Smart2e0fef82007-06-17 19:56:36 -05001529 struct class_device *cdev = container_of(kobj, struct class_device,
1530 kobj);
1531 struct Scsi_Host *shost = class_to_shost(cdev);
1532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1533 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001534 int rc;
1535
James Smart1dcb58e2007-04-25 09:51:30 -04001536 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001537 return -ERANGE;
1538
James Smart1dcb58e2007-04-25 09:51:30 -04001539 if ((count + off) > MAILBOX_CMD_SIZE)
1540 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001541
1542 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1543 return -EINVAL;
1544
1545 if (off && count == 0)
1546 return 0;
1547
James Smart2e0fef82007-06-17 19:56:36 -05001548 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001549
1550 if (off == 0 &&
1551 phba->sysfs_mbox.state == SMBOX_WRITING &&
1552 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1553
1554 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1555 /* Offline only */
1556 case MBX_WRITE_NV:
1557 case MBX_INIT_LINK:
1558 case MBX_DOWN_LINK:
1559 case MBX_CONFIG_LINK:
1560 case MBX_CONFIG_RING:
1561 case MBX_RESET_RING:
1562 case MBX_UNREG_LOGIN:
1563 case MBX_CLEAR_LA:
1564 case MBX_DUMP_CONTEXT:
1565 case MBX_RUN_DIAGS:
1566 case MBX_RESTART:
1567 case MBX_FLASH_WR_ULA:
1568 case MBX_SET_MASK:
1569 case MBX_SET_SLIM:
1570 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001571 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001572 printk(KERN_WARNING "mbox_read:Command 0x%x "
1573 "is illegal in on-line state\n",
1574 phba->sysfs_mbox.mbox->mb.mbxCommand);
1575 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001576 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001577 return -EPERM;
1578 }
1579 case MBX_LOAD_SM:
1580 case MBX_READ_NV:
1581 case MBX_READ_CONFIG:
1582 case MBX_READ_RCONFIG:
1583 case MBX_READ_STATUS:
1584 case MBX_READ_XRI:
1585 case MBX_READ_REV:
1586 case MBX_READ_LNK_STAT:
1587 case MBX_DUMP_MEMORY:
1588 case MBX_DOWN_LOAD:
1589 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001590 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001591 case MBX_LOAD_AREA:
1592 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001593 case MBX_BEACON:
1594 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001595 break;
1596 case MBX_READ_SPARM64:
1597 case MBX_READ_LA:
1598 case MBX_READ_LA64:
1599 case MBX_REG_LOGIN:
1600 case MBX_REG_LOGIN64:
1601 case MBX_CONFIG_PORT:
1602 case MBX_RUN_BIU_DIAG:
1603 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1604 phba->sysfs_mbox.mbox->mb.mbxCommand);
1605 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001606 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001607 return -EPERM;
1608 default:
1609 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1610 phba->sysfs_mbox.mbox->mb.mbxCommand);
1611 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001612 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001613 return -EPERM;
1614 }
1615
James Smart92d7f7b2007-06-17 19:56:38 -05001616 phba->sysfs_mbox.mbox->vport = vport;
1617
James Smart2e0fef82007-06-17 19:56:36 -05001618 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001619 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001620 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001621 return -EAGAIN;
1622 }
1623
James Smart2e0fef82007-06-17 19:56:36 -05001624 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001625 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1626
James Smart2e0fef82007-06-17 19:56:36 -05001627 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001628 rc = lpfc_sli_issue_mbox (phba,
1629 phba->sysfs_mbox.mbox,
1630 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001631 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001632
1633 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001634 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001635 rc = lpfc_sli_issue_mbox_wait (phba,
1636 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001637 lpfc_mbox_tmo_val(phba,
1638 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001639 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001640 }
1641
1642 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001643 if (rc == MBX_TIMEOUT) {
1644 phba->sysfs_mbox.mbox->mbox_cmpl =
1645 lpfc_sli_def_mbox_cmpl;
1646 phba->sysfs_mbox.mbox = NULL;
1647 }
dea31012005-04-17 16:05:31 -05001648 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001649 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001650 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001651 }
1652 phba->sysfs_mbox.state = SMBOX_READING;
1653 }
1654 else if (phba->sysfs_mbox.offset != off ||
1655 phba->sysfs_mbox.state != SMBOX_READING) {
1656 printk(KERN_WARNING "mbox_read: Bad State\n");
1657 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001658 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001659 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001660 }
1661
1662 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1663
1664 phba->sysfs_mbox.offset = off + count;
1665
James Smart1dcb58e2007-04-25 09:51:30 -04001666 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001667 sysfs_mbox_idle(phba);
1668
James Smart2e0fef82007-06-17 19:56:36 -05001669 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001670
1671 return count;
1672}
1673
1674static struct bin_attribute sysfs_mbox_attr = {
1675 .attr = {
1676 .name = "mbox",
1677 .mode = S_IRUSR | S_IWUSR,
1678 .owner = THIS_MODULE,
1679 },
James Smart1dcb58e2007-04-25 09:51:30 -04001680 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001681 .read = sysfs_mbox_read,
1682 .write = sysfs_mbox_write,
1683};
1684
1685int
James Smart2e0fef82007-06-17 19:56:36 -05001686lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001689 int error;
1690
James Smart2e0fef82007-06-17 19:56:36 -05001691 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001692 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001693 if (error)
1694 goto out;
1695
James Smart2e0fef82007-06-17 19:56:36 -05001696 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001697 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001698 if (error)
1699 goto out_remove_ctlreg_attr;
1700
1701 return 0;
1702out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001703 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001704out:
1705 return error;
1706}
1707
1708void
James Smart2e0fef82007-06-17 19:56:36 -05001709lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001710{
James Smart2e0fef82007-06-17 19:56:36 -05001711 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001712
James Smart2e0fef82007-06-17 19:56:36 -05001713 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1714 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001715}
1716
1717
1718/*
1719 * Dynamic FC Host Attributes Support
1720 */
1721
1722static void
1723lpfc_get_host_port_id(struct Scsi_Host *shost)
1724{
James Smart2e0fef82007-06-17 19:56:36 -05001725 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1726
dea31012005-04-17 16:05:31 -05001727 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001728 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001729}
1730
1731static void
1732lpfc_get_host_port_type(struct Scsi_Host *shost)
1733{
James Smart2e0fef82007-06-17 19:56:36 -05001734 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1735 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001736
1737 spin_lock_irq(shost->host_lock);
1738
James Smart92d7f7b2007-06-17 19:56:38 -05001739 if (vport->port_type == LPFC_NPIV_PORT) {
1740 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1741 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001742 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001743 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001744 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1745 else
1746 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1747 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001748 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001749 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1750 else
1751 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1752 }
1753 } else
1754 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1755
1756 spin_unlock_irq(shost->host_lock);
1757}
1758
1759static void
1760lpfc_get_host_port_state(struct Scsi_Host *shost)
1761{
James Smart2e0fef82007-06-17 19:56:36 -05001762 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1763 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001764
1765 spin_lock_irq(shost->host_lock);
1766
James Smart2e0fef82007-06-17 19:56:36 -05001767 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05001768 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1769 else {
James Smart2e0fef82007-06-17 19:56:36 -05001770 switch (phba->link_state) {
1771 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05001772 case LPFC_LINK_DOWN:
1773 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1774 break;
1775 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05001776 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05001777 case LPFC_HBA_READY:
dea31012005-04-17 16:05:31 -05001778 /* Links up, beyond this port_type reports state */
1779 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1780 break;
1781 case LPFC_HBA_ERROR:
1782 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1783 break;
1784 default:
1785 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1786 break;
1787 }
1788 }
1789
1790 spin_unlock_irq(shost->host_lock);
1791}
1792
1793static void
1794lpfc_get_host_speed(struct Scsi_Host *shost)
1795{
James Smart2e0fef82007-06-17 19:56:36 -05001796 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1797 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001798
1799 spin_lock_irq(shost->host_lock);
1800
James Smart2e0fef82007-06-17 19:56:36 -05001801 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001802 switch(phba->fc_linkspeed) {
1803 case LA_1GHZ_LINK:
1804 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1805 break;
1806 case LA_2GHZ_LINK:
1807 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1808 break;
1809 case LA_4GHZ_LINK:
1810 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1811 break;
James Smartb87eab32007-04-25 09:53:28 -04001812 case LA_8GHZ_LINK:
1813 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1814 break;
dea31012005-04-17 16:05:31 -05001815 default:
1816 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1817 break;
1818 }
1819 }
1820
1821 spin_unlock_irq(shost->host_lock);
1822}
1823
1824static void
1825lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1826{
James Smart2e0fef82007-06-17 19:56:36 -05001827 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1828 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001829 u64 node_name;
dea31012005-04-17 16:05:31 -05001830
1831 spin_lock_irq(shost->host_lock);
1832
James Smart2e0fef82007-06-17 19:56:36 -05001833 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05001834 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05001835 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001836 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05001837 else
1838 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05001839 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05001840
1841 spin_unlock_irq(shost->host_lock);
1842
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07001843 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05001844}
1845
dea31012005-04-17 16:05:31 -05001846static struct fc_host_statistics *
1847lpfc_get_stats(struct Scsi_Host *shost)
1848{
James Smart2e0fef82007-06-17 19:56:36 -05001849 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1850 struct lpfc_hba *phba = vport->phba;
1851 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001852 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04001853 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05001854 LPFC_MBOXQ_t *pmboxq;
1855 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04001856 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001857 int rc = 0;
dea31012005-04-17 16:05:31 -05001858
James Smart92d7f7b2007-06-17 19:56:38 -05001859 /*
1860 * prevent udev from issuing mailbox commands until the port is
1861 * configured.
1862 */
James Smart2e0fef82007-06-17 19:56:36 -05001863 if (phba->link_state < LPFC_LINK_DOWN ||
1864 !phba->mbox_mem_pool ||
1865 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001866 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001867
1868 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04001869 return NULL;
1870
dea31012005-04-17 16:05:31 -05001871 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1872 if (!pmboxq)
1873 return NULL;
1874 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1875
1876 pmb = &pmboxq->mb;
1877 pmb->mbxCommand = MBX_READ_STATUS;
1878 pmb->mbxOwner = OWN_HOST;
1879 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001880 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05001881
James Smart2e0fef82007-06-17 19:56:36 -05001882 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001883 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001884 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001885 else
dea31012005-04-17 16:05:31 -05001886 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1887
1888 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001889 if (rc == MBX_TIMEOUT)
1890 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1891 else
1892 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001893 return NULL;
1894 }
1895
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04001896 memset(hs, 0, sizeof (struct fc_host_statistics));
1897
dea31012005-04-17 16:05:31 -05001898 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1899 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1900 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1901 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1902
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001903 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001904 pmb->mbxCommand = MBX_READ_LNK_STAT;
1905 pmb->mbxOwner = OWN_HOST;
1906 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001907 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05001908
James Smart2e0fef82007-06-17 19:56:36 -05001909 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001910 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05001911 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001912 else
dea31012005-04-17 16:05:31 -05001913 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1914
1915 if (rc != MBX_SUCCESS) {
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04001916 if (rc == MBX_TIMEOUT)
1917 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1918 else
James Smart92d7f7b2007-06-17 19:56:38 -05001919 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001920 return NULL;
1921 }
1922
1923 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1924 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1925 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1926 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1927 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1928 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1929 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1930
James Smart64ba8812006-08-02 15:24:34 -04001931 hs->link_failure_count -= lso->link_failure_count;
1932 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1933 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1934 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1935 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1936 hs->invalid_crc_count -= lso->invalid_crc_count;
1937 hs->error_frames -= lso->error_frames;
1938
dea31012005-04-17 16:05:31 -05001939 if (phba->fc_topology == TOPOLOGY_LOOP) {
1940 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001941 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001942 hs->nos_count = -1;
1943 } else {
1944 hs->lip_count = -1;
1945 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04001946 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05001947 }
1948
1949 hs->dumped_frames = -1;
1950
James Smart64ba8812006-08-02 15:24:34 -04001951 seconds = get_seconds();
1952 if (seconds < psli->stats_start)
1953 hs->seconds_since_last_reset = seconds +
1954 ((unsigned long)-1 - psli->stats_start);
1955 else
1956 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05001957
James Smart1dcb58e2007-04-25 09:51:30 -04001958 mempool_free(pmboxq, phba->mbox_mem_pool);
1959
dea31012005-04-17 16:05:31 -05001960 return hs;
1961}
1962
James Smart64ba8812006-08-02 15:24:34 -04001963static void
1964lpfc_reset_stats(struct Scsi_Host *shost)
1965{
James Smart2e0fef82007-06-17 19:56:36 -05001966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1967 struct lpfc_hba *phba = vport->phba;
1968 struct lpfc_sli *psli = &phba->sli;
1969 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04001970 LPFC_MBOXQ_t *pmboxq;
1971 MAILBOX_t *pmb;
1972 int rc = 0;
1973
James Smart2e0fef82007-06-17 19:56:36 -05001974 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04001975 return;
1976
James Smart64ba8812006-08-02 15:24:34 -04001977 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1978 if (!pmboxq)
1979 return;
1980 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1981
1982 pmb = &pmboxq->mb;
1983 pmb->mbxCommand = MBX_READ_STATUS;
1984 pmb->mbxOwner = OWN_HOST;
1985 pmb->un.varWords[0] = 0x1; /* reset request */
1986 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05001987 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04001988
James Smart2e0fef82007-06-17 19:56:36 -05001989 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04001990 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1991 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1992 else
1993 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1994
1995 if (rc != MBX_SUCCESS) {
1996 if (rc == MBX_TIMEOUT)
1997 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1998 else
1999 mempool_free(pmboxq, phba->mbox_mem_pool);
2000 return;
2001 }
2002
2003 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2004 pmb->mbxCommand = MBX_READ_LNK_STAT;
2005 pmb->mbxOwner = OWN_HOST;
2006 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002007 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002008
James Smart2e0fef82007-06-17 19:56:36 -05002009 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002010 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2011 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2012 else
2013 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2014
2015 if (rc != MBX_SUCCESS) {
2016 if (rc == MBX_TIMEOUT)
2017 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2018 else
2019 mempool_free( pmboxq, phba->mbox_mem_pool);
2020 return;
2021 }
2022
2023 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2024 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2025 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2026 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2027 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2028 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2029 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2030 lso->link_events = (phba->fc_eventTag >> 1);
2031
2032 psli->stats_start = get_seconds();
2033
James Smart1dcb58e2007-04-25 09:51:30 -04002034 mempool_free(pmboxq, phba->mbox_mem_pool);
2035
James Smart64ba8812006-08-02 15:24:34 -04002036 return;
2037}
dea31012005-04-17 16:05:31 -05002038
2039/*
2040 * The LPFC driver treats linkdown handling as target loss events so there
2041 * are no sysfs handlers for link_down_tmo.
2042 */
James Smart685f0bf2007-04-25 09:53:08 -04002043
2044static struct lpfc_nodelist *
2045lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002046{
James Smart2e0fef82007-06-17 19:56:36 -05002047 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2048 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002049 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002050
2051 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002052 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002053 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002054 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2055 starget->id == ndlp->nlp_sid) {
2056 spin_unlock_irq(shost->host_lock);
2057 return ndlp;
dea31012005-04-17 16:05:31 -05002058 }
2059 }
2060 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002061 return NULL;
2062}
dea31012005-04-17 16:05:31 -05002063
James Smart685f0bf2007-04-25 09:53:08 -04002064static void
2065lpfc_get_starget_port_id(struct scsi_target *starget)
2066{
2067 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2068
2069 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002070}
2071
2072static void
2073lpfc_get_starget_node_name(struct scsi_target *starget)
2074{
James Smart685f0bf2007-04-25 09:53:08 -04002075 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002076
James Smart685f0bf2007-04-25 09:53:08 -04002077 fc_starget_node_name(starget) =
2078 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002079}
2080
2081static void
2082lpfc_get_starget_port_name(struct scsi_target *starget)
2083{
James Smart685f0bf2007-04-25 09:53:08 -04002084 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002085
James Smart685f0bf2007-04-25 09:53:08 -04002086 fc_starget_port_name(starget) =
2087 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002088}
2089
2090static void
dea31012005-04-17 16:05:31 -05002091lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2092{
dea31012005-04-17 16:05:31 -05002093 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002094 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002095 else
James Smartc01f3202006-08-18 17:47:08 -04002096 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002097}
2098
2099
2100#define lpfc_rport_show_function(field, format_string, sz, cast) \
2101static ssize_t \
2102lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2103{ \
2104 struct fc_rport *rport = transport_class_to_rport(cdev); \
2105 struct lpfc_rport_data *rdata = rport->hostdata; \
2106 return snprintf(buf, sz, format_string, \
2107 (rdata->target) ? cast rdata->target->field : 0); \
2108}
2109
2110#define lpfc_rport_rd_attr(field, format_string, sz) \
2111 lpfc_rport_show_function(field, format_string, sz, ) \
2112static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2113
2114
2115struct fc_function_template lpfc_transport_functions = {
2116 /* fixed attributes the driver supports */
2117 .show_host_node_name = 1,
2118 .show_host_port_name = 1,
2119 .show_host_supported_classes = 1,
2120 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002121 .show_host_supported_speeds = 1,
2122 .show_host_maxframe_size = 1,
2123
2124 /* dynamic attributes the driver supports */
2125 .get_host_port_id = lpfc_get_host_port_id,
2126 .show_host_port_id = 1,
2127
2128 .get_host_port_type = lpfc_get_host_port_type,
2129 .show_host_port_type = 1,
2130
2131 .get_host_port_state = lpfc_get_host_port_state,
2132 .show_host_port_state = 1,
2133
2134 /* active_fc4s is shown but doesn't change (thus no get function) */
2135 .show_host_active_fc4s = 1,
2136
2137 .get_host_speed = lpfc_get_host_speed,
2138 .show_host_speed = 1,
2139
2140 .get_host_fabric_name = lpfc_get_host_fabric_name,
2141 .show_host_fabric_name = 1,
2142
2143 /*
2144 * The LPFC driver treats linkdown handling as target loss events
2145 * so there are no sysfs handlers for link_down_tmo.
2146 */
2147
2148 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002149 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002150
2151 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2152 .show_rport_maxframe_size = 1,
2153 .show_rport_supported_classes = 1,
2154
dea31012005-04-17 16:05:31 -05002155 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2156 .show_rport_dev_loss_tmo = 1,
2157
2158 .get_starget_port_id = lpfc_get_starget_port_id,
2159 .show_starget_port_id = 1,
2160
2161 .get_starget_node_name = lpfc_get_starget_node_name,
2162 .show_starget_node_name = 1,
2163
2164 .get_starget_port_name = lpfc_get_starget_port_name,
2165 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002166
2167 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002168 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2169 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002170
2171 .vport_create = lpfc_vport_create,
2172 .vport_delete = lpfc_vport_delete,
2173 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2174};
2175
2176struct fc_function_template lpfc_vport_transport_functions = {
2177 /* fixed attributes the driver supports */
2178 .show_host_node_name = 1,
2179 .show_host_port_name = 1,
2180 .show_host_supported_classes = 1,
2181 .show_host_supported_fc4s = 1,
2182 .show_host_supported_speeds = 1,
2183 .show_host_maxframe_size = 1,
2184
2185 /* dynamic attributes the driver supports */
2186 .get_host_port_id = lpfc_get_host_port_id,
2187 .show_host_port_id = 1,
2188
2189 .get_host_port_type = lpfc_get_host_port_type,
2190 .show_host_port_type = 1,
2191
2192 .get_host_port_state = lpfc_get_host_port_state,
2193 .show_host_port_state = 1,
2194
2195 /* active_fc4s is shown but doesn't change (thus no get function) */
2196 .show_host_active_fc4s = 1,
2197
2198 .get_host_speed = lpfc_get_host_speed,
2199 .show_host_speed = 1,
2200
2201 .get_host_fabric_name = lpfc_get_host_fabric_name,
2202 .show_host_fabric_name = 1,
2203
2204 /*
2205 * The LPFC driver treats linkdown handling as target loss events
2206 * so there are no sysfs handlers for link_down_tmo.
2207 */
2208
2209 .get_fc_host_stats = lpfc_get_stats,
2210 .reset_fc_host_stats = lpfc_reset_stats,
2211
2212 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2213 .show_rport_maxframe_size = 1,
2214 .show_rport_supported_classes = 1,
2215
2216 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2217 .show_rport_dev_loss_tmo = 1,
2218
2219 .get_starget_port_id = lpfc_get_starget_port_id,
2220 .show_starget_port_id = 1,
2221
2222 .get_starget_node_name = lpfc_get_starget_node_name,
2223 .show_starget_node_name = 1,
2224
2225 .get_starget_port_name = lpfc_get_starget_port_name,
2226 .show_starget_port_name = 1,
2227
2228 .issue_fc_host_lip = lpfc_issue_lip,
2229 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2230 .terminate_rport_io = lpfc_terminate_rport_io,
2231
2232 .vport_disable = lpfc_vport_disable,
dea31012005-04-17 16:05:31 -05002233};
2234
2235void
2236lpfc_get_cfgparam(struct lpfc_hba *phba)
2237{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002238 lpfc_log_verbose_init(phba, lpfc_log_verbose);
2239 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2240 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002241 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002242 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2243 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002244 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
2245 lpfc_fcp_class_init(phba, lpfc_fcp_class);
2246 lpfc_use_adisc_init(phba, lpfc_use_adisc);
2247 lpfc_ack0_init(phba, lpfc_ack0);
2248 lpfc_topology_init(phba, lpfc_topology);
2249 lpfc_scan_down_init(phba, lpfc_scan_down);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002250 lpfc_link_speed_init(phba, lpfc_link_speed);
2251 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
2252 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
2253 lpfc_max_luns_init(phba, lpfc_max_luns);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002254 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart92d7f7b2007-06-17 19:56:38 -05002255 lpfc_peer_port_login_init(phba, lpfc_peer_port_login);
2256 lpfc_vport_restrict_login_init(phba, lpfc_vport_restrict_login);
James Smart4ff43242006-12-02 13:34:56 -05002257 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smartc01f3202006-08-18 17:47:08 -04002258 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
2259 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002260 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002261 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002262 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002263
2264 /*
2265 * The total number of segments is the configuration value plus 2
2266 * since the IOCB need a command and response bde.
2267 */
2268 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
2269
2270 /*
2271 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2272 * used to create the sg_dma_buf_pool must be dynamically calculated
2273 */
2274 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2275 sizeof(struct fcp_rsp) +
2276 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
2277
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002278
James Smart7054a602007-04-25 09:52:34 -04002279 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002280
dea31012005-04-17 16:05:31 -05002281 return;
2282}