blob: 4bae4a2ed2f1e9218b627f279d513a847b5ce931 [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 Smart09372822008-01-11 01:52:54 -05004 * Copyright (C) 2004-2008 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
James Smart83108bd2008-01-11 01:53:09 -050048#define LPFC_MAX_LINK_SPEED 8
49#define LPFC_LINK_SPEED_BITMAP 0x00000117
50#define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
51
dea31012005-04-17 16:05:31 -050052static void
53lpfc_jedec_to_ascii(int incr, char hdw[])
54{
55 int i, j;
56 for (i = 0; i < 8; i++) {
57 j = (incr & 0xf);
58 if (j <= 9)
59 hdw[7 - i] = 0x30 + j;
60 else
61 hdw[7 - i] = 0x61 + j - 10;
62 incr = (incr >> 4);
63 }
64 hdw[8] = 0;
65 return;
66}
67
68static ssize_t
69lpfc_drvr_version_show(struct class_device *cdev, char *buf)
70{
71 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
72}
73
74static ssize_t
dea31012005-04-17 16:05:31 -050075lpfc_info_show(struct class_device *cdev, char *buf)
76{
77 struct Scsi_Host *host = class_to_shost(cdev);
James Smart2e0fef82007-06-17 19:56:36 -050078
dea31012005-04-17 16:05:31 -050079 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
80}
81
82static ssize_t
83lpfc_serialnum_show(struct class_device *cdev, char *buf)
84{
James Smart2e0fef82007-06-17 19:56:36 -050085 struct Scsi_Host *shost = class_to_shost(cdev);
86 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
87 struct lpfc_hba *phba = vport->phba;
88
dea31012005-04-17 16:05:31 -050089 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
90}
91
92static ssize_t
James Smart57127f12007-10-27 13:37:05 -040093lpfc_temp_sensor_show(struct class_device *cdev, char *buf)
94{
95 struct Scsi_Host *shost = class_to_shost(cdev);
96 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
97 struct lpfc_hba *phba = vport->phba;
98 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
99}
100
101static ssize_t
dea31012005-04-17 16:05:31 -0500102lpfc_modeldesc_show(struct class_device *cdev, char *buf)
103{
James Smart2e0fef82007-06-17 19:56:36 -0500104 struct Scsi_Host *shost = class_to_shost(cdev);
105 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
106 struct lpfc_hba *phba = vport->phba;
107
dea31012005-04-17 16:05:31 -0500108 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
109}
110
111static ssize_t
112lpfc_modelname_show(struct class_device *cdev, char *buf)
113{
James Smart2e0fef82007-06-17 19:56:36 -0500114 struct Scsi_Host *shost = class_to_shost(cdev);
115 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
116 struct lpfc_hba *phba = vport->phba;
117
dea31012005-04-17 16:05:31 -0500118 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
119}
120
121static ssize_t
122lpfc_programtype_show(struct class_device *cdev, char *buf)
123{
James Smart2e0fef82007-06-17 19:56:36 -0500124 struct Scsi_Host *shost = class_to_shost(cdev);
125 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
126 struct lpfc_hba *phba = vport->phba;
127
dea31012005-04-17 16:05:31 -0500128 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
129}
130
131static ssize_t
James Smart2e0fef82007-06-17 19:56:36 -0500132lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea31012005-04-17 16:05:31 -0500133{
James Smart2e0fef82007-06-17 19:56:36 -0500134 struct Scsi_Host *shost = class_to_shost(cdev);
135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
136 struct lpfc_hba *phba = vport->phba;
137
dea31012005-04-17 16:05:31 -0500138 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
139}
140
141static ssize_t
142lpfc_fwrev_show(struct class_device *cdev, char *buf)
143{
James Smart2e0fef82007-06-17 19:56:36 -0500144 struct Scsi_Host *shost = class_to_shost(cdev);
145 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
146 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500147 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500148
dea31012005-04-17 16:05:31 -0500149 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500150 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500151}
152
153static ssize_t
154lpfc_hdw_show(struct class_device *cdev, char *buf)
155{
156 char hdw[9];
James Smart2e0fef82007-06-17 19:56:36 -0500157 struct Scsi_Host *shost = class_to_shost(cdev);
158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
159 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500160 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500161
dea31012005-04-17 16:05:31 -0500162 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
163 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
164}
165static ssize_t
166lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
167{
James Smart2e0fef82007-06-17 19:56:36 -0500168 struct Scsi_Host *shost = class_to_shost(cdev);
169 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
170 struct lpfc_hba *phba = vport->phba;
171
dea31012005-04-17 16:05:31 -0500172 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
173}
174static ssize_t
175lpfc_state_show(struct class_device *cdev, char *buf)
176{
James Smart2e0fef82007-06-17 19:56:36 -0500177 struct Scsi_Host *shost = class_to_shost(cdev);
178 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
179 struct lpfc_hba *phba = vport->phba;
180 int len = 0;
181
182 switch (phba->link_state) {
183 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500184 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500185 case LPFC_INIT_START:
186 case LPFC_INIT_MBX_CMDS:
187 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500188 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500189 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
190 break;
191 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500192 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500193 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400194 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500195
196 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500197 case LPFC_LOCAL_CFG_LINK:
198 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500199 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500200 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500201 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500202 case LPFC_FLOGI:
203 case LPFC_FABRIC_CFG_LINK:
204 case LPFC_NS_REG:
205 case LPFC_NS_QRY:
206 case LPFC_BUILD_DISC_LIST:
207 case LPFC_DISC_AUTH:
208 len += snprintf(buf + len, PAGE_SIZE - len,
209 "Discovery\n");
210 break;
211 case LPFC_VPORT_READY:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
213 break;
214
James Smart92d7f7b2007-06-17 19:56:38 -0500215 case LPFC_VPORT_FAILED:
216 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
217 break;
218
219 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500220 len += snprintf(buf + len, PAGE_SIZE - len,
221 "Unknown\n");
222 break;
223 }
224
dea31012005-04-17 16:05:31 -0500225 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500226 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500227 len += snprintf(buf + len, PAGE_SIZE-len,
228 " Public Loop\n");
229 else
230 len += snprintf(buf + len, PAGE_SIZE-len,
231 " Private Loop\n");
232 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500233 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500234 len += snprintf(buf + len, PAGE_SIZE-len,
235 " Fabric\n");
236 else
237 len += snprintf(buf + len, PAGE_SIZE-len,
238 " Point-2-Point\n");
239 }
240 }
James Smart2e0fef82007-06-17 19:56:36 -0500241
dea31012005-04-17 16:05:31 -0500242 return len;
243}
244
245static ssize_t
246lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
247{
James Smart2e0fef82007-06-17 19:56:36 -0500248 struct Scsi_Host *shost = class_to_shost(cdev);
249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250
251 return snprintf(buf, PAGE_SIZE, "%d\n",
252 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500253}
254
255
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700256static int
James Smart2e0fef82007-06-17 19:56:36 -0500257lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500258{
James Smart2e0fef82007-06-17 19:56:36 -0500259 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
260 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500261 LPFC_MBOXQ_t *pmboxq;
262 int mbxstatus = MBXERR_ERROR;
263
James Smart2e0fef82007-06-17 19:56:36 -0500264 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500265 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500266 return -EPERM;
267
268 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
269
270 if (!pmboxq)
271 return -ENOMEM;
272
273 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400274 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
275 pmboxq->mb.mbxOwner = OWN_HOST;
276
James Smart33ccf8d2006-08-17 11:57:58 -0400277 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500278
James Smart4db621e2006-07-06 15:49:49 -0400279 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
280 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
281 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
282 phba->cfg_link_speed);
283 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
284 phba->fc_ratov * 2);
285 }
286
James Smart5b8bd0c2007-04-25 09:52:49 -0400287 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500288 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400289 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500290
291 if (mbxstatus == MBXERR_ERROR)
292 return -EIO;
293
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700294 return 0;
dea31012005-04-17 16:05:31 -0500295}
296
James Smart40496f02006-07-06 15:50:22 -0400297static int
James Smart46fa3112007-04-25 09:51:45 -0400298lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
299{
300 struct completion online_compl;
301 struct lpfc_sli_ring *pring;
302 struct lpfc_sli *psli;
303 int status = 0;
304 int cnt = 0;
305 int i;
306
307 init_completion(&online_compl);
308 lpfc_workq_post_event(phba, &status, &online_compl,
309 LPFC_EVT_OFFLINE_PREP);
310 wait_for_completion(&online_compl);
311
312 if (status != 0)
313 return -EIO;
314
315 psli = &phba->sli;
316
James Smart09372822008-01-11 01:52:54 -0500317 /* Wait a little for things to settle down, but not
318 * long enough for dev loss timeout to expire.
319 */
James Smart46fa3112007-04-25 09:51:45 -0400320 for (i = 0; i < psli->num_rings; i++) {
321 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400322 while (pring->txcmplq_cnt) {
323 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500324 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400325 lpfc_printf_log(phba,
326 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400327 "0466 Outstanding IO when "
328 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400329 break;
330 }
331 }
332 }
333
334 init_completion(&online_compl);
335 lpfc_workq_post_event(phba, &status, &online_compl, type);
336 wait_for_completion(&online_compl);
337
338 if (status != 0)
339 return -EIO;
340
341 return 0;
342}
343
344static int
James Smart40496f02006-07-06 15:50:22 -0400345lpfc_selective_reset(struct lpfc_hba *phba)
346{
347 struct completion online_compl;
348 int status = 0;
349
James Smart13815c82008-01-11 01:52:48 -0500350 if (!phba->cfg_enable_hba_reset)
351 return -EIO;
352
James Smart46fa3112007-04-25 09:51:45 -0400353 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400354
355 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400356 return status;
James Smart40496f02006-07-06 15:50:22 -0400357
358 init_completion(&online_compl);
359 lpfc_workq_post_event(phba, &status, &online_compl,
360 LPFC_EVT_ONLINE);
361 wait_for_completion(&online_compl);
362
363 if (status != 0)
364 return -EIO;
365
366 return 0;
367}
368
369static ssize_t
370lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
371{
James Smart2e0fef82007-06-17 19:56:36 -0500372 struct Scsi_Host *shost = class_to_shost(cdev);
373 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
374 struct lpfc_hba *phba = vport->phba;
375
James Smart40496f02006-07-06 15:50:22 -0400376 int status = -EINVAL;
377
378 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
379 status = lpfc_selective_reset(phba);
380
381 if (status == 0)
382 return strlen(buf);
383 else
384 return status;
385}
386
dea31012005-04-17 16:05:31 -0500387static ssize_t
388lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
389{
James Smart2e0fef82007-06-17 19:56:36 -0500390 struct Scsi_Host *shost = class_to_shost(cdev);
391 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
392 struct lpfc_hba *phba = vport->phba;
393
dea31012005-04-17 16:05:31 -0500394 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
395}
396
397static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500398lpfc_board_mode_show(struct class_device *cdev, char *buf)
399{
James Smart2e0fef82007-06-17 19:56:36 -0500400 struct Scsi_Host *shost = class_to_shost(cdev);
401 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
402 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500403 char * state;
404
James Smart2e0fef82007-06-17 19:56:36 -0500405 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500406 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500407 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500408 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500409 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500410 state = "offline";
411 else
412 state = "online";
413
414 return snprintf(buf, PAGE_SIZE, "%s\n", state);
415}
416
417static ssize_t
418lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
419{
James Smart2e0fef82007-06-17 19:56:36 -0500420 struct Scsi_Host *shost = class_to_shost(cdev);
421 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
422 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500423 struct completion online_compl;
424 int status=0;
425
James Smart13815c82008-01-11 01:52:48 -0500426 if (!phba->cfg_enable_hba_reset)
427 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500428 init_completion(&online_compl);
429
James Smart46fa3112007-04-25 09:51:45 -0400430 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500431 lpfc_workq_post_event(phba, &status, &online_compl,
432 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400433 wait_for_completion(&online_compl);
434 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
435 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500436 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400437 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
438 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
439 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500440 else
441 return -EINVAL;
442
Jamie Wellnitz41415862006-02-28 19:25:27 -0500443 if (!status)
444 return strlen(buf);
445 else
446 return -EIO;
447}
448
James Smart311464e2007-08-02 11:10:37 -0400449static int
James Smart858c9f62007-06-17 19:56:39 -0500450lpfc_get_hba_info(struct lpfc_hba *phba,
451 uint32_t *mxri, uint32_t *axri,
452 uint32_t *mrpi, uint32_t *arpi,
453 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500454{
455 struct lpfc_sli *psli = &phba->sli;
456 LPFC_MBOXQ_t *pmboxq;
457 MAILBOX_t *pmb;
458 int rc = 0;
459
460 /*
461 * prevent udev from issuing mailbox commands until the port is
462 * configured.
463 */
464 if (phba->link_state < LPFC_LINK_DOWN ||
465 !phba->mbox_mem_pool ||
466 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
467 return 0;
468
469 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
470 return 0;
471
472 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
473 if (!pmboxq)
474 return 0;
475 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
476
477 pmb = &pmboxq->mb;
478 pmb->mbxCommand = MBX_READ_CONFIG;
479 pmb->mbxOwner = OWN_HOST;
480 pmboxq->context1 = NULL;
481
482 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
483 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
484 rc = MBX_NOT_FINISHED;
485 else
486 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
487
488 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500489 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500490 mempool_free(pmboxq, phba->mbox_mem_pool);
491 return 0;
492 }
493
494 if (mrpi)
495 *mrpi = pmb->un.varRdConfig.max_rpi;
496 if (arpi)
497 *arpi = pmb->un.varRdConfig.avail_rpi;
498 if (mxri)
499 *mxri = pmb->un.varRdConfig.max_xri;
500 if (axri)
501 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500502 if (mvpi)
503 *mvpi = pmb->un.varRdConfig.max_vpi;
504 if (avpi)
505 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500506
507 mempool_free(pmboxq, phba->mbox_mem_pool);
508 return 1;
509}
510
511static ssize_t
512lpfc_max_rpi_show(struct class_device *cdev, char *buf)
513{
514 struct Scsi_Host *shost = class_to_shost(cdev);
515 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
516 struct lpfc_hba *phba = vport->phba;
517 uint32_t cnt;
518
James Smart858c9f62007-06-17 19:56:39 -0500519 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500520 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
521 return snprintf(buf, PAGE_SIZE, "Unknown\n");
522}
523
524static ssize_t
525lpfc_used_rpi_show(struct class_device *cdev, char *buf)
526{
527 struct Scsi_Host *shost = class_to_shost(cdev);
528 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
529 struct lpfc_hba *phba = vport->phba;
530 uint32_t cnt, acnt;
531
James Smart858c9f62007-06-17 19:56:39 -0500532 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500533 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
534 return snprintf(buf, PAGE_SIZE, "Unknown\n");
535}
536
537static ssize_t
538lpfc_max_xri_show(struct class_device *cdev, char *buf)
539{
540 struct Scsi_Host *shost = class_to_shost(cdev);
541 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
542 struct lpfc_hba *phba = vport->phba;
543 uint32_t cnt;
544
James Smart858c9f62007-06-17 19:56:39 -0500545 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500546 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
547 return snprintf(buf, PAGE_SIZE, "Unknown\n");
548}
549
550static ssize_t
551lpfc_used_xri_show(struct class_device *cdev, char *buf)
552{
553 struct Scsi_Host *shost = class_to_shost(cdev);
554 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
555 struct lpfc_hba *phba = vport->phba;
556 uint32_t cnt, acnt;
557
James Smart858c9f62007-06-17 19:56:39 -0500558 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
559 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
560 return snprintf(buf, PAGE_SIZE, "Unknown\n");
561}
562
563static ssize_t
564lpfc_max_vpi_show(struct class_device *cdev, char *buf)
565{
566 struct Scsi_Host *shost = class_to_shost(cdev);
567 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
568 struct lpfc_hba *phba = vport->phba;
569 uint32_t cnt;
570
571 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
572 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
573 return snprintf(buf, PAGE_SIZE, "Unknown\n");
574}
575
576static ssize_t
577lpfc_used_vpi_show(struct class_device *cdev, char *buf)
578{
579 struct Scsi_Host *shost = class_to_shost(cdev);
580 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
581 struct lpfc_hba *phba = vport->phba;
582 uint32_t cnt, acnt;
583
584 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500585 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
586 return snprintf(buf, PAGE_SIZE, "Unknown\n");
587}
588
589static ssize_t
590lpfc_npiv_info_show(struct class_device *cdev, char *buf)
591{
592 struct Scsi_Host *shost = class_to_shost(cdev);
593 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
594 struct lpfc_hba *phba = vport->phba;
595
596 if (!(phba->max_vpi))
597 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
598 if (vport->port_type == LPFC_PHYSICAL_PORT)
599 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
600 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
601}
602
Jamie Wellnitz41415862006-02-28 19:25:27 -0500603static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500604lpfc_poll_show(struct class_device *cdev, char *buf)
605{
James Smart2e0fef82007-06-17 19:56:36 -0500606 struct Scsi_Host *shost = class_to_shost(cdev);
607 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
608 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500609
610 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
611}
612
613static ssize_t
614lpfc_poll_store(struct class_device *cdev, const char *buf,
615 size_t count)
616{
James Smart2e0fef82007-06-17 19:56:36 -0500617 struct Scsi_Host *shost = class_to_shost(cdev);
618 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
619 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500620 uint32_t creg_val;
621 uint32_t old_val;
622 int val=0;
623
624 if (!isdigit(buf[0]))
625 return -EINVAL;
626
627 if (sscanf(buf, "%i", &val) != 1)
628 return -EINVAL;
629
630 if ((val & 0x3) != val)
631 return -EINVAL;
632
James Smart2e0fef82007-06-17 19:56:36 -0500633 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500634
635 old_val = phba->cfg_poll;
636
637 if (val & ENABLE_FCP_RING_POLLING) {
638 if ((val & DISABLE_FCP_RING_INT) &&
639 !(old_val & DISABLE_FCP_RING_INT)) {
640 creg_val = readl(phba->HCregaddr);
641 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
642 writel(creg_val, phba->HCregaddr);
643 readl(phba->HCregaddr); /* flush */
644
645 lpfc_poll_start_timer(phba);
646 }
647 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500648 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500649 return -EINVAL;
650 }
651
652 if (!(val & DISABLE_FCP_RING_INT) &&
653 (old_val & DISABLE_FCP_RING_INT))
654 {
James Smart2e0fef82007-06-17 19:56:36 -0500655 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500656 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500657 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500658 creg_val = readl(phba->HCregaddr);
659 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
660 writel(creg_val, phba->HCregaddr);
661 readl(phba->HCregaddr); /* flush */
662 }
663
664 phba->cfg_poll = val;
665
James Smart2e0fef82007-06-17 19:56:36 -0500666 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500667
668 return strlen(buf);
669}
dea31012005-04-17 16:05:31 -0500670
671#define lpfc_param_show(attr) \
672static ssize_t \
673lpfc_##attr##_show(struct class_device *cdev, char *buf) \
674{ \
James Smart2e0fef82007-06-17 19:56:36 -0500675 struct Scsi_Host *shost = class_to_shost(cdev);\
676 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
677 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500678 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400679 val = phba->cfg_##attr;\
680 return snprintf(buf, PAGE_SIZE, "%d\n",\
681 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500682}
683
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400684#define lpfc_param_hex_show(attr) \
685static ssize_t \
686lpfc_##attr##_show(struct class_device *cdev, char *buf) \
687{ \
James Smart2e0fef82007-06-17 19:56:36 -0500688 struct Scsi_Host *shost = class_to_shost(cdev);\
689 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
690 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400691 int val = 0;\
692 val = phba->cfg_##attr;\
693 return snprintf(buf, PAGE_SIZE, "%#x\n",\
694 phba->cfg_##attr);\
695}
696
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400697#define lpfc_param_init(attr, default, minval, maxval) \
698static int \
699lpfc_##attr##_init(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, \
James Smarte8b62012007-08-02 11:10:09 -0400706 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
707 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400708 phba->cfg_##attr = default;\
709 return -EINVAL;\
710}
711
712#define lpfc_param_set(attr, default, minval, maxval) \
713static int \
714lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
715{ \
716 if (val >= minval && val <= maxval) {\
717 phba->cfg_##attr = val;\
718 return 0;\
719 }\
720 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400721 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
722 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400723 return -EINVAL;\
724}
725
726#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500727static ssize_t \
728lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
729{ \
James Smart2e0fef82007-06-17 19:56:36 -0500730 struct Scsi_Host *shost = class_to_shost(cdev);\
731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
732 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400733 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400734 if (!isdigit(buf[0]))\
735 return -EINVAL;\
736 if (sscanf(buf, "%i", &val) != 1)\
737 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400738 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400739 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400740 else \
741 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500742}
743
James Smart3de2a652007-08-02 11:09:59 -0400744#define lpfc_vport_param_show(attr) \
745static ssize_t \
746lpfc_##attr##_show(struct class_device *cdev, char *buf) \
747{ \
748 struct Scsi_Host *shost = class_to_shost(cdev);\
749 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
750 int val = 0;\
751 val = vport->cfg_##attr;\
752 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
753}
754
755#define lpfc_vport_param_hex_show(attr) \
756static ssize_t \
757lpfc_##attr##_show(struct class_device *cdev, char *buf) \
758{ \
759 struct Scsi_Host *shost = class_to_shost(cdev);\
760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
761 int val = 0;\
762 val = vport->cfg_##attr;\
763 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
764}
765
766#define lpfc_vport_param_init(attr, default, minval, maxval) \
767static int \
768lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
769{ \
770 if (val >= minval && val <= maxval) {\
771 vport->cfg_##attr = val;\
772 return 0;\
773 }\
James Smarte8b62012007-08-02 11:10:09 -0400774 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
775 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
776 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400777 vport->cfg_##attr = default;\
778 return -EINVAL;\
779}
780
781#define lpfc_vport_param_set(attr, default, minval, maxval) \
782static int \
783lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
784{ \
785 if (val >= minval && val <= maxval) {\
786 vport->cfg_##attr = val;\
787 return 0;\
788 }\
James Smarte8b62012007-08-02 11:10:09 -0400789 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
790 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
791 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400792 return -EINVAL;\
793}
794
795#define lpfc_vport_param_store(attr) \
796static ssize_t \
797lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
798{ \
799 struct Scsi_Host *shost = class_to_shost(cdev);\
800 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
801 int val=0;\
802 if (!isdigit(buf[0]))\
803 return -EINVAL;\
804 if (sscanf(buf, "%i", &val) != 1)\
805 return -EINVAL;\
806 if (lpfc_##attr##_set(vport, val) == 0) \
807 return strlen(buf);\
808 else \
809 return -EINVAL;\
810}
811
812
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400813#define LPFC_ATTR(name, defval, minval, maxval, desc) \
814static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500815module_param(lpfc_##name, int, 0);\
816MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400817lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500818
819#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
820static int lpfc_##name = defval;\
821module_param(lpfc_##name, int, 0);\
822MODULE_PARM_DESC(lpfc_##name, desc);\
823lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400824lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500825static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
826
827#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
828static int lpfc_##name = defval;\
829module_param(lpfc_##name, int, 0);\
830MODULE_PARM_DESC(lpfc_##name, desc);\
831lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400832lpfc_param_init(name, defval, minval, maxval)\
833lpfc_param_set(name, defval, minval, maxval)\
834lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500835static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
836 lpfc_##name##_show, lpfc_##name##_store)
837
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400838#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
839static int lpfc_##name = defval;\
840module_param(lpfc_##name, int, 0);\
841MODULE_PARM_DESC(lpfc_##name, desc);\
842lpfc_param_hex_show(name)\
843lpfc_param_init(name, defval, minval, maxval)\
844static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
845
846#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
847static int lpfc_##name = defval;\
848module_param(lpfc_##name, int, 0);\
849MODULE_PARM_DESC(lpfc_##name, desc);\
850lpfc_param_hex_show(name)\
851lpfc_param_init(name, defval, minval, maxval)\
852lpfc_param_set(name, defval, minval, maxval)\
853lpfc_param_store(name)\
854static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
855 lpfc_##name##_show, lpfc_##name##_store)
856
James Smart3de2a652007-08-02 11:09:59 -0400857#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
858static int lpfc_##name = defval;\
859module_param(lpfc_##name, int, 0);\
860MODULE_PARM_DESC(lpfc_##name, desc);\
861lpfc_vport_param_init(name, defval, minval, maxval)
862
863#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
864static int lpfc_##name = defval;\
865module_param(lpfc_##name, int, 0);\
866MODULE_PARM_DESC(lpfc_##name, desc);\
867lpfc_vport_param_show(name)\
868lpfc_vport_param_init(name, defval, minval, maxval)\
869static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
870
871#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
872static int lpfc_##name = defval;\
873module_param(lpfc_##name, int, 0);\
874MODULE_PARM_DESC(lpfc_##name, desc);\
875lpfc_vport_param_show(name)\
876lpfc_vport_param_init(name, defval, minval, maxval)\
877lpfc_vport_param_set(name, defval, minval, maxval)\
878lpfc_vport_param_store(name)\
879static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
880 lpfc_##name##_show, lpfc_##name##_store)
881
882#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
883static int lpfc_##name = defval;\
884module_param(lpfc_##name, int, 0);\
885MODULE_PARM_DESC(lpfc_##name, desc);\
886lpfc_vport_param_hex_show(name)\
887lpfc_vport_param_init(name, defval, minval, maxval)\
888static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
889
890#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
891static int lpfc_##name = defval;\
892module_param(lpfc_##name, int, 0);\
893MODULE_PARM_DESC(lpfc_##name, desc);\
894lpfc_vport_param_hex_show(name)\
895lpfc_vport_param_init(name, defval, minval, maxval)\
896lpfc_vport_param_set(name, defval, minval, maxval)\
897lpfc_vport_param_store(name)\
898static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
899 lpfc_##name##_show, lpfc_##name##_store)
900
dea31012005-04-17 16:05:31 -0500901static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
902static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
903static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
904static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
905static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500906static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500907static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
908static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
909static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
910static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
911 lpfc_option_rom_version_show, NULL);
912static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
913 lpfc_num_discovered_ports_show, NULL);
914static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
915static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
916 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500917static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
918 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400919static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500920static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
921static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
922static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
923static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
924static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
925static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
926static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
James Smart57127f12007-10-27 13:37:05 -0400927static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show,
928 NULL);
dea31012005-04-17 16:05:31 -0500929
James Smartc3f28af2006-08-18 17:47:18 -0400930
James Smarta12e07b2006-12-02 13:35:30 -0500931static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400932
933static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500934lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400935 size_t count)
936{
James Smart2e0fef82007-06-17 19:56:36 -0500937 struct Scsi_Host *shost = class_to_shost(cdev);
938 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
939 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400940 unsigned int cnt = count;
941
942 /*
943 * We're doing a simple sanity check for soft_wwpn setting.
944 * We require that the user write a specific key to enable
945 * the soft_wwpn attribute to be settable. Once the attribute
946 * is written, the enable key resets. If further updates are
947 * desired, the key must be written again to re-enable the
948 * attribute.
949 *
950 * The "key" is not secret - it is a hardcoded string shown
951 * here. The intent is to protect against the random user or
952 * application that is just writing attributes.
953 */
954
955 /* count may include a LF at end of string */
956 if (buf[cnt-1] == '\n')
957 cnt--;
958
James Smarta12e07b2006-12-02 13:35:30 -0500959 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
960 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400961 return -EINVAL;
962
James Smarta12e07b2006-12-02 13:35:30 -0500963 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400964 return count;
965}
James Smarta12e07b2006-12-02 13:35:30 -0500966static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
967 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400968
969static ssize_t
970lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
971{
James Smart2e0fef82007-06-17 19:56:36 -0500972 struct Scsi_Host *shost = class_to_shost(cdev);
973 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
974 struct lpfc_hba *phba = vport->phba;
975
Randy Dunlapafc071e2006-10-23 21:47:13 -0700976 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
977 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400978}
979
980
981static ssize_t
982lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
983{
James Smart2e0fef82007-06-17 19:56:36 -0500984 struct Scsi_Host *shost = class_to_shost(cdev);
985 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
986 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400987 struct completion online_compl;
988 int stat1=0, stat2=0;
989 unsigned int i, j, cnt=count;
990 u8 wwpn[8];
991
James Smart13815c82008-01-11 01:52:48 -0500992 if (!phba->cfg_enable_hba_reset)
993 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -0400994 spin_lock_irq(&phba->hbalock);
995 if (phba->over_temp_state == HBA_OVER_TEMP) {
996 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -0500997 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -0400998 }
999 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001000 /* count may include a LF at end of string */
1001 if (buf[cnt-1] == '\n')
1002 cnt--;
1003
James Smarta12e07b2006-12-02 13:35:30 -05001004 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001005 ((cnt == 17) && (*buf++ != 'x')) ||
1006 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1007 return -EINVAL;
1008
James Smarta12e07b2006-12-02 13:35:30 -05001009 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001010
1011 memset(wwpn, 0, sizeof(wwpn));
1012
1013 /* Validate and store the new name */
1014 for (i=0, j=0; i < 16; i++) {
1015 if ((*buf >= 'a') && (*buf <= 'f'))
1016 j = ((j << 4) | ((*buf++ -'a') + 10));
1017 else if ((*buf >= 'A') && (*buf <= 'F'))
1018 j = ((j << 4) | ((*buf++ -'A') + 10));
1019 else if ((*buf >= '0') && (*buf <= '9'))
1020 j = ((j << 4) | (*buf++ -'0'));
1021 else
1022 return -EINVAL;
1023 if (i % 2) {
1024 wwpn[i/2] = j & 0xff;
1025 j = 0;
1026 }
1027 }
1028 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001029 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001030 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001031 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001032
1033 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1034 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1035
James Smart46fa3112007-04-25 09:51:45 -04001036 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001037 if (stat1)
1038 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001039 "0463 lpfc_soft_wwpn attribute set failed to "
1040 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001041 init_completion(&online_compl);
1042 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1043 wait_for_completion(&online_compl);
1044 if (stat2)
1045 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001046 "0464 lpfc_soft_wwpn attribute set failed to "
1047 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001048 return (stat1 || stat2) ? -EIO : count;
1049}
1050static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1051 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1052
James Smarta12e07b2006-12-02 13:35:30 -05001053static ssize_t
1054lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1055{
James Smart51ef4c22007-08-02 11:10:31 -04001056 struct Scsi_Host *shost = class_to_shost(cdev);
1057 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001058 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1059 (unsigned long long)phba->cfg_soft_wwnn);
1060}
1061
1062
1063static ssize_t
1064lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1065{
James Smart51ef4c22007-08-02 11:10:31 -04001066 struct Scsi_Host *shost = class_to_shost(cdev);
1067 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001068 unsigned int i, j, cnt=count;
1069 u8 wwnn[8];
1070
1071 /* count may include a LF at end of string */
1072 if (buf[cnt-1] == '\n')
1073 cnt--;
1074
1075 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1076 ((cnt == 17) && (*buf++ != 'x')) ||
1077 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1078 return -EINVAL;
1079
1080 /*
1081 * Allow wwnn to be set many times, as long as the enable is set.
1082 * However, once the wwpn is set, everything locks.
1083 */
1084
1085 memset(wwnn, 0, sizeof(wwnn));
1086
1087 /* Validate and store the new name */
1088 for (i=0, j=0; i < 16; i++) {
1089 if ((*buf >= 'a') && (*buf <= 'f'))
1090 j = ((j << 4) | ((*buf++ -'a') + 10));
1091 else if ((*buf >= 'A') && (*buf <= 'F'))
1092 j = ((j << 4) | ((*buf++ -'A') + 10));
1093 else if ((*buf >= '0') && (*buf <= '9'))
1094 j = ((j << 4) | (*buf++ -'0'));
1095 else
1096 return -EINVAL;
1097 if (i % 2) {
1098 wwnn[i/2] = j & 0xff;
1099 j = 0;
1100 }
1101 }
1102 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1103
1104 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1105 "lpfc%d: soft_wwnn set. Value will take effect upon "
1106 "setting of the soft_wwpn\n", phba->brd_no);
1107
1108 return count;
1109}
1110static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1111 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1112
James Smartc3f28af2006-08-18 17:47:18 -04001113
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001114static int lpfc_poll = 0;
1115module_param(lpfc_poll, int, 0);
1116MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1117 " 0 - none,"
1118 " 1 - poll with interrupts enabled"
1119 " 3 - poll and disable FCP ring interrupts");
1120
1121static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1122 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001123
James Smart92d7f7b2007-06-17 19:56:38 -05001124int lpfc_sli_mode = 0;
1125module_param(lpfc_sli_mode, int, 0);
1126MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1127 " 0 - auto (SLI-3 if supported),"
1128 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1129 " 3 - select SLI-3");
1130
James Smart7ee5d432007-10-27 13:37:17 -04001131int lpfc_enable_npiv = 0;
1132module_param(lpfc_enable_npiv, int, 0);
1133MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1134lpfc_param_show(enable_npiv);
1135lpfc_param_init(enable_npiv, 0, 0, 1);
1136static CLASS_DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1137 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001138
dea31012005-04-17 16:05:31 -05001139/*
James Smartc01f3202006-08-18 17:47:08 -04001140# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1141# until the timer expires. Value range is [0,255]. Default value is 30.
1142*/
1143static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1144static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1145module_param(lpfc_nodev_tmo, int, 0);
1146MODULE_PARM_DESC(lpfc_nodev_tmo,
1147 "Seconds driver will hold I/O waiting "
1148 "for a device to come back");
1149static ssize_t
1150lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1151{
James Smart2e0fef82007-06-17 19:56:36 -05001152 struct Scsi_Host *shost = class_to_shost(cdev);
1153 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001154 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001155 val = vport->cfg_devloss_tmo;
1156 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001157}
1158
1159static int
James Smart3de2a652007-08-02 11:09:59 -04001160lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001161{
James Smart3de2a652007-08-02 11:09:59 -04001162 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1163 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1164 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001165 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1166 "0402 Ignoring nodev_tmo module "
1167 "parameter because devloss_tmo is "
1168 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001169 return 0;
1170 }
1171
1172 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001173 vport->cfg_nodev_tmo = val;
1174 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001175 return 0;
1176 }
James Smarte8b62012007-08-02 11:10:09 -04001177 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1178 "0400 lpfc_nodev_tmo attribute cannot be set to"
1179 " %d, allowed range is [%d, %d]\n",
1180 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001181 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001182 return -EINVAL;
1183}
1184
James Smart7054a602007-04-25 09:52:34 -04001185static void
James Smart3de2a652007-08-02 11:09:59 -04001186lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001187{
James Smart858c9f62007-06-17 19:56:39 -05001188 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001189 struct lpfc_nodelist *ndlp;
1190
James Smart51ef4c22007-08-02 11:10:31 -04001191 shost = lpfc_shost_from_vport(vport);
1192 spin_lock_irq(shost->host_lock);
1193 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1194 if (ndlp->rport)
1195 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1196 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001197}
1198
James Smartc01f3202006-08-18 17:47:08 -04001199static int
James Smart3de2a652007-08-02 11:09:59 -04001200lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001201{
James Smart3de2a652007-08-02 11:09:59 -04001202 if (vport->dev_loss_tmo_changed ||
1203 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001204 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1205 "0401 Ignoring change to nodev_tmo "
1206 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001207 return 0;
1208 }
James Smartc01f3202006-08-18 17:47:08 -04001209 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001210 vport->cfg_nodev_tmo = val;
1211 vport->cfg_devloss_tmo = val;
1212 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001213 return 0;
1214 }
James Smarte8b62012007-08-02 11:10:09 -04001215 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1216 "0403 lpfc_nodev_tmo attribute cannot be set to"
1217 "%d, allowed range is [%d, %d]\n",
1218 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001219 return -EINVAL;
1220}
1221
James Smart3de2a652007-08-02 11:09:59 -04001222lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001223
1224static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1225 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1226
1227/*
1228# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1229# disappear until the timer expires. Value range is [0,255]. Default
1230# value is 30.
1231*/
1232module_param(lpfc_devloss_tmo, int, 0);
1233MODULE_PARM_DESC(lpfc_devloss_tmo,
1234 "Seconds driver will hold I/O waiting "
1235 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001236lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1237 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1238lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001239static int
James Smart3de2a652007-08-02 11:09:59 -04001240lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001241{
1242 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001243 vport->cfg_nodev_tmo = val;
1244 vport->cfg_devloss_tmo = val;
1245 vport->dev_loss_tmo_changed = 1;
1246 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001247 return 0;
1248 }
1249
James Smarte8b62012007-08-02 11:10:09 -04001250 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1251 "0404 lpfc_devloss_tmo attribute cannot be set to"
1252 " %d, allowed range is [%d, %d]\n",
1253 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001254 return -EINVAL;
1255}
1256
James Smart3de2a652007-08-02 11:09:59 -04001257lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001258static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1259 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1260
1261/*
dea31012005-04-17 16:05:31 -05001262# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1263# deluged with LOTS of information.
1264# You can set a bit mask to record specific types of verbose messages:
1265#
1266# LOG_ELS 0x1 ELS events
1267# LOG_DISCOVERY 0x2 Link discovery events
1268# LOG_MBOX 0x4 Mailbox events
1269# LOG_INIT 0x8 Initialization events
1270# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001271# LOG_FCP 0x40 FCP traffic history
1272# LOG_NODE 0x80 Node table events
1273# LOG_MISC 0x400 Miscellaneous events
1274# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001275# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001276# LOG_LIBDFC 0x2000 LIBDFC events
1277# LOG_ALL_MSG 0xffff LOG all messages
1278*/
James Smarte8b62012007-08-02 11:10:09 -04001279LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1280 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001281
1282/*
James Smart7ee5d432007-10-27 13:37:17 -04001283# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1284# objects that have been registered with the nameserver after login.
1285*/
1286LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1287 "Deregister nameserver objects before LOGO");
1288
1289/*
dea31012005-04-17 16:05:31 -05001290# lun_queue_depth: This parameter is used to limit the number of outstanding
1291# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1292*/
James Smart3de2a652007-08-02 11:09:59 -04001293LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1294 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001295
1296/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001297# hba_queue_depth: This parameter is used to limit the number of outstanding
1298# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1299# value is greater than the maximum number of exchanges supported by the HBA,
1300# then maximum number of exchanges supported by the HBA is used to determine
1301# the hba_queue_depth.
1302*/
1303LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1304 "Max number of FCP commands we can queue to a lpfc HBA");
1305
1306/*
James Smart92d7f7b2007-06-17 19:56:38 -05001307# peer_port_login: This parameter allows/prevents logins
1308# between peer ports hosted on the same physical port.
1309# When this parameter is set 0 peer ports of same physical port
1310# are not allowed to login to each other.
1311# When this parameter is set 1 peer ports of same physical port
1312# are allowed to login to each other.
1313# Default value of this parameter is 0.
1314*/
James Smart3de2a652007-08-02 11:09:59 -04001315LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1316 "Allow peer ports on the same physical port to login to each "
1317 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001318
1319/*
James Smart3de2a652007-08-02 11:09:59 -04001320# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001321# between Virtual Ports and remote initiators.
1322# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1323# other initiators and will attempt to PLOGI all remote ports.
1324# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1325# remote ports and will not attempt to PLOGI to other initiators.
1326# This parameter does not restrict to the physical port.
1327# This parameter does not restrict logins to Fabric resident remote ports.
1328# Default value of this parameter is 1.
1329*/
James Smart3de2a652007-08-02 11:09:59 -04001330static int lpfc_restrict_login = 1;
1331module_param(lpfc_restrict_login, int, 0);
1332MODULE_PARM_DESC(lpfc_restrict_login,
1333 "Restrict virtual ports login to remote initiators.");
1334lpfc_vport_param_show(restrict_login);
1335
1336static int
1337lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1338{
1339 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001340 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1341 "0449 lpfc_restrict_login attribute cannot "
1342 "be set to %d, allowed range is [0, 1]\n",
1343 val);
James Smart3de2a652007-08-02 11:09:59 -04001344 vport->cfg_restrict_login = 1;
1345 return -EINVAL;
1346 }
1347 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1348 vport->cfg_restrict_login = 0;
1349 return 0;
1350 }
1351 vport->cfg_restrict_login = val;
1352 return 0;
1353}
1354
1355static int
1356lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1357{
1358 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001359 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1360 "0450 lpfc_restrict_login attribute cannot "
1361 "be set to %d, allowed range is [0, 1]\n",
1362 val);
James Smart3de2a652007-08-02 11:09:59 -04001363 vport->cfg_restrict_login = 1;
1364 return -EINVAL;
1365 }
1366 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001367 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1368 "0468 lpfc_restrict_login must be 0 for "
1369 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001370 vport->cfg_restrict_login = 0;
1371 return 0;
1372 }
1373 vport->cfg_restrict_login = val;
1374 return 0;
1375}
1376lpfc_vport_param_store(restrict_login);
1377static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1378 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001379
1380/*
dea31012005-04-17 16:05:31 -05001381# Some disk devices have a "select ID" or "select Target" capability.
1382# From a protocol standpoint "select ID" usually means select the
1383# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1384# annex" which contains a table that maps a "select ID" (a number
1385# between 0 and 7F) to an ALPA. By default, for compatibility with
1386# older drivers, the lpfc driver scans this table from low ALPA to high
1387# ALPA.
1388#
1389# Turning on the scan-down variable (on = 1, off = 0) will
1390# cause the lpfc driver to use an inverted table, effectively
1391# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1392#
1393# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1394# and will not work across a fabric. Also this parameter will take
1395# effect only in the case when ALPA map is not available.)
1396*/
James Smart3de2a652007-08-02 11:09:59 -04001397LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1398 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001399
1400/*
dea31012005-04-17 16:05:31 -05001401# lpfc_topology: link topology for init link
1402# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001403# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001404# 0x02 = attempt point-to-point mode only
1405# 0x04 = attempt loop mode only
1406# 0x06 = attempt point-to-point mode then loop
1407# Set point-to-point mode if you want to run as an N_Port.
1408# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1409# Default value is 0.
1410*/
James Smart83108bd2008-01-11 01:53:09 -05001411static int
1412lpfc_topology_set(struct lpfc_hba *phba, int val)
1413{
1414 int err;
1415 uint32_t prev_val;
1416 if (val >= 0 && val <= 6) {
1417 prev_val = phba->cfg_topology;
1418 phba->cfg_topology = val;
1419 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
1420 if (err)
1421 phba->cfg_topology = prev_val;
1422 return err;
1423 }
1424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1425 "%d:0467 lpfc_topology attribute cannot be set to %d, "
1426 "allowed range is [0, 6]\n",
1427 phba->brd_no, val);
1428 return -EINVAL;
1429}
1430static int lpfc_topology = 0;
1431module_param(lpfc_topology, int, 0);
1432MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
1433lpfc_param_show(topology)
1434lpfc_param_init(topology, 0, 0, 6)
1435lpfc_param_store(topology)
1436static CLASS_DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
1437 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05001438
1439/*
1440# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1441# connection.
1442# 0 = auto select (default)
1443# 1 = 1 Gigabaud
1444# 2 = 2 Gigabaud
1445# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001446# 8 = 8 Gigabaud
1447# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001448*/
James Smart83108bd2008-01-11 01:53:09 -05001449static int
1450lpfc_link_speed_set(struct lpfc_hba *phba, int val)
1451{
1452 int err;
1453 uint32_t prev_val;
1454
1455 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
1456 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
1457 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
1458 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
1459 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
1460 return -EINVAL;
1461
1462 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
1463 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
1464 prev_val = phba->cfg_link_speed;
1465 phba->cfg_link_speed = val;
1466 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
1467 if (err)
1468 phba->cfg_link_speed = prev_val;
1469 return err;
1470 }
1471
1472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1473 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
1474 "allowed range is [0, 8]\n",
1475 phba->brd_no, val);
1476 return -EINVAL;
1477}
1478
1479static int lpfc_link_speed = 0;
1480module_param(lpfc_link_speed, int, 0);
1481MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
1482lpfc_param_show(link_speed)
1483static int
1484lpfc_link_speed_init(struct lpfc_hba *phba, int val)
1485{
1486 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
1487 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
1488 phba->cfg_link_speed = val;
1489 return 0;
1490 }
1491 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1492 "0454 lpfc_link_speed attribute cannot "
1493 "be set to %d, allowed values are "
1494 "["LPFC_LINK_SPEED_STRING"]\n", val);
1495 phba->cfg_link_speed = 0;
1496 return -EINVAL;
1497}
1498
1499lpfc_param_store(link_speed)
1500static CLASS_DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
1501 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05001502
1503/*
1504# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1505# Value range is [2,3]. Default value is 3.
1506*/
James Smart3de2a652007-08-02 11:09:59 -04001507LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1508 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001509
1510/*
1511# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1512# is [0,1]. Default value is 0.
1513*/
James Smart3de2a652007-08-02 11:09:59 -04001514LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1515 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001516
1517/*
1518# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1519# range is [0,1]. Default value is 0.
1520*/
1521LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1522
1523/*
1524# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1525# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001526# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001527# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1528# cr_delay is set to 0.
1529*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001530LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001531 "interrupt response is generated");
1532
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001533LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001534 "interrupt response is generated");
1535
1536/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001537# lpfc_multi_ring_support: Determines how many rings to spread available
1538# cmd/rsp IOCB entries across.
1539# Value range is [1,2]. Default value is 1.
1540*/
1541LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1542 "SLI rings to spread IOCB entries across");
1543
1544/*
James Smarta4bc3372006-12-02 13:34:16 -05001545# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1546# identifies what rctl value to configure the additional ring for.
1547# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1548*/
1549LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1550 255, "Identifies RCTL for additional ring configuration");
1551
1552/*
1553# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1554# identifies what type value to configure the additional ring for.
1555# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1556*/
1557LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1558 255, "Identifies TYPE for additional ring configuration");
1559
1560/*
dea31012005-04-17 16:05:31 -05001561# lpfc_fdmi_on: controls FDMI support.
1562# 0 = no FDMI support
1563# 1 = support FDMI without attribute of hostname
1564# 2 = support FDMI with attribute of hostname
1565# Value range [0,2]. Default value is 0.
1566*/
James Smart3de2a652007-08-02 11:09:59 -04001567LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001568
1569/*
1570# Specifies the maximum number of ELS cmds we can have outstanding (for
1571# discovery). Value range is [1,64]. Default value = 32.
1572*/
James Smart3de2a652007-08-02 11:09:59 -04001573LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001574 "during discovery");
1575
1576/*
James Smart65a29c12006-07-06 15:50:50 -04001577# lpfc_max_luns: maximum allowed LUN.
1578# Value range is [0,65535]. Default value is 255.
1579# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001580*/
James Smart3de2a652007-08-02 11:09:59 -04001581LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001582
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001583/*
1584# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1585# Value range is [1,255], default value is 10.
1586*/
1587LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1588 "Milliseconds driver will wait between polling FCP ring");
1589
James Smart4ff43242006-12-02 13:34:56 -05001590/*
1591# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1592# support this feature
1593# 0 = MSI disabled (default)
1594# 1 = MSI enabled
1595# Value range is [0,1]. Default value is 0.
1596*/
1597LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1598
James Smart13815c82008-01-11 01:52:48 -05001599/*
1600# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
1601# 0 = HBA resets disabled
1602# 1 = HBA resets enabled (default)
1603# Value range is [0,1]. Default value is 1.
1604*/
1605LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04001606
James Smart13815c82008-01-11 01:52:48 -05001607/*
1608# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
1609# 0 = HBA Heartbeat disabled
1610# 1 = HBA Heartbeat enabled (default)
1611# Value range is [0,1]. Default value is 1.
1612*/
1613LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05001614
James Smart83108bd2008-01-11 01:53:09 -05001615/*
1616 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
1617 * This value can be set to values between 64 and 256. The default value is
1618 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
1619 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
1620 */
1621LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
1622 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
1623
James Smart2e0fef82007-06-17 19:56:36 -05001624struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001625 &class_device_attr_info,
1626 &class_device_attr_serialnum,
1627 &class_device_attr_modeldesc,
1628 &class_device_attr_modelname,
1629 &class_device_attr_programtype,
1630 &class_device_attr_portnum,
1631 &class_device_attr_fwrev,
1632 &class_device_attr_hdw,
1633 &class_device_attr_option_rom_version,
1634 &class_device_attr_state,
1635 &class_device_attr_num_discovered_ports,
1636 &class_device_attr_lpfc_drvr_version,
James Smart57127f12007-10-27 13:37:05 -04001637 &class_device_attr_lpfc_temp_sensor,
dea31012005-04-17 16:05:31 -05001638 &class_device_attr_lpfc_log_verbose,
1639 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001640 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001641 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001642 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001643 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001644 &class_device_attr_lpfc_fcp_class,
1645 &class_device_attr_lpfc_use_adisc,
1646 &class_device_attr_lpfc_ack0,
1647 &class_device_attr_lpfc_topology,
1648 &class_device_attr_lpfc_scan_down,
1649 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001650 &class_device_attr_lpfc_cr_delay,
1651 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001652 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001653 &class_device_attr_lpfc_multi_ring_rctl,
1654 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001655 &class_device_attr_lpfc_fdmi_on,
1656 &class_device_attr_lpfc_max_luns,
James Smart78b2d852007-08-02 11:10:21 -04001657 &class_device_attr_lpfc_enable_npiv,
dea31012005-04-17 16:05:31 -05001658 &class_device_attr_nport_evt_cnt,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001659 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001660 &class_device_attr_max_vpi,
1661 &class_device_attr_used_vpi,
1662 &class_device_attr_max_rpi,
1663 &class_device_attr_used_rpi,
1664 &class_device_attr_max_xri,
1665 &class_device_attr_used_xri,
1666 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001667 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001668 &class_device_attr_lpfc_poll,
1669 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001670 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001671 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001672 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001673 &class_device_attr_lpfc_soft_wwn_enable,
James Smart13815c82008-01-11 01:52:48 -05001674 &class_device_attr_lpfc_enable_hba_reset,
1675 &class_device_attr_lpfc_enable_hba_heartbeat,
James Smart83108bd2008-01-11 01:53:09 -05001676 &class_device_attr_lpfc_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05001677 NULL,
1678};
1679
James Smart3de2a652007-08-02 11:09:59 -04001680struct class_device_attribute *lpfc_vport_attrs[] = {
1681 &class_device_attr_info,
1682 &class_device_attr_state,
1683 &class_device_attr_num_discovered_ports,
1684 &class_device_attr_lpfc_drvr_version,
1685
1686 &class_device_attr_lpfc_log_verbose,
1687 &class_device_attr_lpfc_lun_queue_depth,
1688 &class_device_attr_lpfc_nodev_tmo,
1689 &class_device_attr_lpfc_devloss_tmo,
1690 &class_device_attr_lpfc_hba_queue_depth,
1691 &class_device_attr_lpfc_peer_port_login,
1692 &class_device_attr_lpfc_restrict_login,
1693 &class_device_attr_lpfc_fcp_class,
1694 &class_device_attr_lpfc_use_adisc,
1695 &class_device_attr_lpfc_fdmi_on,
1696 &class_device_attr_lpfc_max_luns,
1697 &class_device_attr_nport_evt_cnt,
James Smart3de2a652007-08-02 11:09:59 -04001698 &class_device_attr_npiv_info,
James Smart7ee5d432007-10-27 13:37:17 -04001699 &class_device_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04001700 NULL,
1701};
1702
dea31012005-04-17 16:05:31 -05001703static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001704sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1705 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001706{
1707 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001708 struct class_device *cdev = container_of(kobj, struct class_device,
1709 kobj);
1710 struct Scsi_Host *shost = class_to_shost(cdev);
1711 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1712 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001713
1714 if ((off + count) > FF_REG_AREA_SIZE)
1715 return -ERANGE;
1716
1717 if (count == 0) return 0;
1718
1719 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1720 return -EINVAL;
1721
James Smart2e0fef82007-06-17 19:56:36 -05001722 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001723 return -EPERM;
1724 }
1725
James Smart2e0fef82007-06-17 19:56:36 -05001726 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001727 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1728 writel(*((uint32_t *)(buf + buf_off)),
1729 phba->ctrl_regs_memmap_p + off + buf_off);
1730
James Smart2e0fef82007-06-17 19:56:36 -05001731 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001732
1733 return count;
1734}
1735
1736static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001737sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1738 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001739{
1740 size_t buf_off;
1741 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001742 struct class_device *cdev = container_of(kobj, struct class_device,
1743 kobj);
1744 struct Scsi_Host *shost = class_to_shost(cdev);
1745 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1746 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001747
1748 if (off > FF_REG_AREA_SIZE)
1749 return -ERANGE;
1750
1751 if ((off + count) > FF_REG_AREA_SIZE)
1752 count = FF_REG_AREA_SIZE - off;
1753
1754 if (count == 0) return 0;
1755
1756 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1757 return -EINVAL;
1758
James Smart2e0fef82007-06-17 19:56:36 -05001759 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001760
1761 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1762 tmp_ptr = (uint32_t *)(buf + buf_off);
1763 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1764 }
1765
James Smart2e0fef82007-06-17 19:56:36 -05001766 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001767
1768 return count;
1769}
1770
1771static struct bin_attribute sysfs_ctlreg_attr = {
1772 .attr = {
1773 .name = "ctlreg",
1774 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001775 },
1776 .size = 256,
1777 .read = sysfs_ctlreg_read,
1778 .write = sysfs_ctlreg_write,
1779};
1780
1781
1782static void
James Smart2e0fef82007-06-17 19:56:36 -05001783sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001784{
1785 phba->sysfs_mbox.state = SMBOX_IDLE;
1786 phba->sysfs_mbox.offset = 0;
1787
1788 if (phba->sysfs_mbox.mbox) {
1789 mempool_free(phba->sysfs_mbox.mbox,
1790 phba->mbox_mem_pool);
1791 phba->sysfs_mbox.mbox = NULL;
1792 }
1793}
1794
1795static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001796sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1797 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001798{
James Smart2e0fef82007-06-17 19:56:36 -05001799 struct class_device *cdev = container_of(kobj, struct class_device,
1800 kobj);
1801 struct Scsi_Host *shost = class_to_shost(cdev);
1802 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1803 struct lpfc_hba *phba = vport->phba;
1804 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001805
1806 if ((count + off) > MAILBOX_CMD_SIZE)
1807 return -ERANGE;
1808
1809 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1810 return -EINVAL;
1811
1812 if (count == 0)
1813 return 0;
1814
1815 if (off == 0) {
1816 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1817 if (!mbox)
1818 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001819 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001820 }
1821
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001823
1824 if (off == 0) {
1825 if (phba->sysfs_mbox.mbox)
1826 mempool_free(mbox, phba->mbox_mem_pool);
1827 else
1828 phba->sysfs_mbox.mbox = mbox;
1829 phba->sysfs_mbox.state = SMBOX_WRITING;
1830 } else {
1831 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1832 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001833 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001834 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001835 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001836 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001837 }
1838 }
1839
1840 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1841 buf, count);
1842
1843 phba->sysfs_mbox.offset = off + count;
1844
James Smart2e0fef82007-06-17 19:56:36 -05001845 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001846
1847 return count;
1848}
1849
1850static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001851sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1852 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001853{
James Smart2e0fef82007-06-17 19:56:36 -05001854 struct class_device *cdev = container_of(kobj, struct class_device,
1855 kobj);
1856 struct Scsi_Host *shost = class_to_shost(cdev);
1857 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1858 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001859 int rc;
1860
James Smart1dcb58e2007-04-25 09:51:30 -04001861 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001862 return -ERANGE;
1863
James Smart1dcb58e2007-04-25 09:51:30 -04001864 if ((count + off) > MAILBOX_CMD_SIZE)
1865 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001866
1867 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1868 return -EINVAL;
1869
1870 if (off && count == 0)
1871 return 0;
1872
James Smart2e0fef82007-06-17 19:56:36 -05001873 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001874
James Smart7af67052007-10-27 13:38:11 -04001875 if (phba->over_temp_state == HBA_OVER_TEMP) {
1876 sysfs_mbox_idle(phba);
1877 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001878 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001879 }
1880
dea31012005-04-17 16:05:31 -05001881 if (off == 0 &&
1882 phba->sysfs_mbox.state == SMBOX_WRITING &&
1883 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1884
1885 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1886 /* Offline only */
dea31012005-04-17 16:05:31 -05001887 case MBX_INIT_LINK:
1888 case MBX_DOWN_LINK:
1889 case MBX_CONFIG_LINK:
1890 case MBX_CONFIG_RING:
1891 case MBX_RESET_RING:
1892 case MBX_UNREG_LOGIN:
1893 case MBX_CLEAR_LA:
1894 case MBX_DUMP_CONTEXT:
1895 case MBX_RUN_DIAGS:
1896 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05001897 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05001898 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001899 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001900 printk(KERN_WARNING "mbox_read:Command 0x%x "
1901 "is illegal in on-line state\n",
1902 phba->sysfs_mbox.mbox->mb.mbxCommand);
1903 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001904 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001905 return -EPERM;
1906 }
James Smarta8adb832007-10-27 13:37:53 -04001907 case MBX_WRITE_NV:
1908 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05001909 case MBX_LOAD_SM:
1910 case MBX_READ_NV:
1911 case MBX_READ_CONFIG:
1912 case MBX_READ_RCONFIG:
1913 case MBX_READ_STATUS:
1914 case MBX_READ_XRI:
1915 case MBX_READ_REV:
1916 case MBX_READ_LNK_STAT:
1917 case MBX_DUMP_MEMORY:
1918 case MBX_DOWN_LOAD:
1919 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001920 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001921 case MBX_LOAD_AREA:
1922 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001923 case MBX_BEACON:
1924 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05001925 case MBX_SET_VARIABLE:
1926 case MBX_WRITE_WWN:
dea31012005-04-17 16:05:31 -05001927 break;
1928 case MBX_READ_SPARM64:
1929 case MBX_READ_LA:
1930 case MBX_READ_LA64:
1931 case MBX_REG_LOGIN:
1932 case MBX_REG_LOGIN64:
1933 case MBX_CONFIG_PORT:
1934 case MBX_RUN_BIU_DIAG:
1935 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1936 phba->sysfs_mbox.mbox->mb.mbxCommand);
1937 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001939 return -EPERM;
1940 default:
1941 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1942 phba->sysfs_mbox.mbox->mb.mbxCommand);
1943 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001944 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001945 return -EPERM;
1946 }
1947
James Smart09372822008-01-11 01:52:54 -05001948 /* If HBA encountered an error attention, allow only DUMP
1949 * mailbox command until the HBA is restarted.
1950 */
1951 if ((phba->pport->stopped) &&
1952 (phba->sysfs_mbox.mbox->mb.mbxCommand
1953 != MBX_DUMP_MEMORY)) {
1954 sysfs_mbox_idle(phba);
1955 spin_unlock_irq(&phba->hbalock);
1956 return -EPERM;
1957 }
1958
James Smart92d7f7b2007-06-17 19:56:38 -05001959 phba->sysfs_mbox.mbox->vport = vport;
1960
James Smart2e0fef82007-06-17 19:56:36 -05001961 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001962 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001964 return -EAGAIN;
1965 }
1966
James Smart2e0fef82007-06-17 19:56:36 -05001967 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001968 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1969
James Smart2e0fef82007-06-17 19:56:36 -05001970 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001971 rc = lpfc_sli_issue_mbox (phba,
1972 phba->sysfs_mbox.mbox,
1973 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001975
1976 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001977 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001978 rc = lpfc_sli_issue_mbox_wait (phba,
1979 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001980 lpfc_mbox_tmo_val(phba,
1981 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001982 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001983 }
1984
1985 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001986 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001987 phba->sysfs_mbox.mbox = NULL;
1988 }
dea31012005-04-17 16:05:31 -05001989 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001990 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001991 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001992 }
1993 phba->sysfs_mbox.state = SMBOX_READING;
1994 }
1995 else if (phba->sysfs_mbox.offset != off ||
1996 phba->sysfs_mbox.state != SMBOX_READING) {
1997 printk(KERN_WARNING "mbox_read: Bad State\n");
1998 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001999 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002000 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002001 }
2002
2003 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2004
2005 phba->sysfs_mbox.offset = off + count;
2006
James Smart1dcb58e2007-04-25 09:51:30 -04002007 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002008 sysfs_mbox_idle(phba);
2009
James Smart2e0fef82007-06-17 19:56:36 -05002010 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002011
2012 return count;
2013}
2014
2015static struct bin_attribute sysfs_mbox_attr = {
2016 .attr = {
2017 .name = "mbox",
2018 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002019 },
James Smart1dcb58e2007-04-25 09:51:30 -04002020 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05002021 .read = sysfs_mbox_read,
2022 .write = sysfs_mbox_write,
2023};
2024
2025int
James Smart2e0fef82007-06-17 19:56:36 -05002026lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002027{
James Smart2e0fef82007-06-17 19:56:36 -05002028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002029 int error;
2030
James Smart2e0fef82007-06-17 19:56:36 -05002031 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002032 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002033 if (error)
2034 goto out;
2035
James Smart2e0fef82007-06-17 19:56:36 -05002036 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002037 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05002038 if (error)
2039 goto out_remove_ctlreg_attr;
2040
2041 return 0;
2042out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05002043 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002044out:
2045 return error;
2046}
2047
2048void
James Smart2e0fef82007-06-17 19:56:36 -05002049lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002050{
James Smart2e0fef82007-06-17 19:56:36 -05002051 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002052
James Smart2e0fef82007-06-17 19:56:36 -05002053 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
2054 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002055}
2056
2057
2058/*
2059 * Dynamic FC Host Attributes Support
2060 */
2061
2062static void
2063lpfc_get_host_port_id(struct Scsi_Host *shost)
2064{
James Smart2e0fef82007-06-17 19:56:36 -05002065 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2066
dea31012005-04-17 16:05:31 -05002067 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05002068 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002069}
2070
2071static void
2072lpfc_get_host_port_type(struct Scsi_Host *shost)
2073{
James Smart2e0fef82007-06-17 19:56:36 -05002074 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2075 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002076
2077 spin_lock_irq(shost->host_lock);
2078
James Smart92d7f7b2007-06-17 19:56:38 -05002079 if (vport->port_type == LPFC_NPIV_PORT) {
2080 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2081 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002082 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05002083 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05002084 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2085 else
2086 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
2087 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002088 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05002089 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2090 else
2091 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2092 }
2093 } else
2094 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2095
2096 spin_unlock_irq(shost->host_lock);
2097}
2098
2099static void
2100lpfc_get_host_port_state(struct Scsi_Host *shost)
2101{
James Smart2e0fef82007-06-17 19:56:36 -05002102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2103 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002104
2105 spin_lock_irq(shost->host_lock);
2106
James Smart2e0fef82007-06-17 19:56:36 -05002107 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05002108 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2109 else {
James Smart2e0fef82007-06-17 19:56:36 -05002110 switch (phba->link_state) {
2111 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05002112 case LPFC_LINK_DOWN:
2113 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2114 break;
2115 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05002116 case LPFC_CLEAR_LA:
2117 case LPFC_HBA_READY:
2118 /* Links up, beyond this port_type reports state */
2119 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2120 break;
2121 case LPFC_HBA_ERROR:
2122 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2123 break;
2124 default:
2125 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2126 break;
2127 }
2128 }
2129
2130 spin_unlock_irq(shost->host_lock);
2131}
2132
2133static void
2134lpfc_get_host_speed(struct Scsi_Host *shost)
2135{
James Smart2e0fef82007-06-17 19:56:36 -05002136 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2137 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002138
2139 spin_lock_irq(shost->host_lock);
2140
James Smart2e0fef82007-06-17 19:56:36 -05002141 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002142 switch(phba->fc_linkspeed) {
2143 case LA_1GHZ_LINK:
2144 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2145 break;
2146 case LA_2GHZ_LINK:
2147 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2148 break;
2149 case LA_4GHZ_LINK:
2150 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2151 break;
James Smartb87eab32007-04-25 09:53:28 -04002152 case LA_8GHZ_LINK:
2153 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2154 break;
dea31012005-04-17 16:05:31 -05002155 default:
2156 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2157 break;
2158 }
James Smart09372822008-01-11 01:52:54 -05002159 } else
2160 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05002161
2162 spin_unlock_irq(shost->host_lock);
2163}
2164
2165static void
2166lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2167{
James Smart2e0fef82007-06-17 19:56:36 -05002168 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2169 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002170 u64 node_name;
dea31012005-04-17 16:05:31 -05002171
2172 spin_lock_irq(shost->host_lock);
2173
James Smart2e0fef82007-06-17 19:56:36 -05002174 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002175 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002176 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002177 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002178 else
2179 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05002180 node_name = 0;
dea31012005-04-17 16:05:31 -05002181
2182 spin_unlock_irq(shost->host_lock);
2183
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002184 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002185}
2186
dea31012005-04-17 16:05:31 -05002187static struct fc_host_statistics *
2188lpfc_get_stats(struct Scsi_Host *shost)
2189{
James Smart2e0fef82007-06-17 19:56:36 -05002190 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2191 struct lpfc_hba *phba = vport->phba;
2192 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002193 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002194 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002195 LPFC_MBOXQ_t *pmboxq;
2196 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002197 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002198 int rc = 0;
dea31012005-04-17 16:05:31 -05002199
James Smart92d7f7b2007-06-17 19:56:38 -05002200 /*
2201 * prevent udev from issuing mailbox commands until the port is
2202 * configured.
2203 */
James Smart2e0fef82007-06-17 19:56:36 -05002204 if (phba->link_state < LPFC_LINK_DOWN ||
2205 !phba->mbox_mem_pool ||
2206 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002207 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002208
2209 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002210 return NULL;
2211
dea31012005-04-17 16:05:31 -05002212 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2213 if (!pmboxq)
2214 return NULL;
2215 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2216
2217 pmb = &pmboxq->mb;
2218 pmb->mbxCommand = MBX_READ_STATUS;
2219 pmb->mbxOwner = OWN_HOST;
2220 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002221 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002222
James Smart2e0fef82007-06-17 19:56:36 -05002223 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002224 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002225 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002226 else
dea31012005-04-17 16:05:31 -05002227 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2228
2229 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002230 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002231 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002232 return NULL;
2233 }
2234
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002235 memset(hs, 0, sizeof (struct fc_host_statistics));
2236
dea31012005-04-17 16:05:31 -05002237 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2238 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2239 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2240 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2241
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002242 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002243 pmb->mbxCommand = MBX_READ_LNK_STAT;
2244 pmb->mbxOwner = OWN_HOST;
2245 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002246 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002247
James Smart2e0fef82007-06-17 19:56:36 -05002248 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002249 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002250 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002251 else
dea31012005-04-17 16:05:31 -05002252 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2253
2254 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002255 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002256 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002257 return NULL;
2258 }
2259
2260 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2261 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2262 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2263 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2264 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2265 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2266 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2267
James Smart64ba8812006-08-02 15:24:34 -04002268 hs->link_failure_count -= lso->link_failure_count;
2269 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2270 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2271 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2272 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2273 hs->invalid_crc_count -= lso->invalid_crc_count;
2274 hs->error_frames -= lso->error_frames;
2275
dea31012005-04-17 16:05:31 -05002276 if (phba->fc_topology == TOPOLOGY_LOOP) {
2277 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002278 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002279 hs->nos_count = -1;
2280 } else {
2281 hs->lip_count = -1;
2282 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002283 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002284 }
2285
2286 hs->dumped_frames = -1;
2287
James Smart64ba8812006-08-02 15:24:34 -04002288 seconds = get_seconds();
2289 if (seconds < psli->stats_start)
2290 hs->seconds_since_last_reset = seconds +
2291 ((unsigned long)-1 - psli->stats_start);
2292 else
2293 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002294
James Smart1dcb58e2007-04-25 09:51:30 -04002295 mempool_free(pmboxq, phba->mbox_mem_pool);
2296
dea31012005-04-17 16:05:31 -05002297 return hs;
2298}
2299
James Smart64ba8812006-08-02 15:24:34 -04002300static void
2301lpfc_reset_stats(struct Scsi_Host *shost)
2302{
James Smart2e0fef82007-06-17 19:56:36 -05002303 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2304 struct lpfc_hba *phba = vport->phba;
2305 struct lpfc_sli *psli = &phba->sli;
2306 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002307 LPFC_MBOXQ_t *pmboxq;
2308 MAILBOX_t *pmb;
2309 int rc = 0;
2310
James Smart2e0fef82007-06-17 19:56:36 -05002311 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002312 return;
2313
James Smart64ba8812006-08-02 15:24:34 -04002314 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2315 if (!pmboxq)
2316 return;
2317 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2318
2319 pmb = &pmboxq->mb;
2320 pmb->mbxCommand = MBX_READ_STATUS;
2321 pmb->mbxOwner = OWN_HOST;
2322 pmb->un.varWords[0] = 0x1; /* reset request */
2323 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002324 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002325
James Smart2e0fef82007-06-17 19:56:36 -05002326 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002327 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2328 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2329 else
2330 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2331
2332 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002333 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002334 mempool_free(pmboxq, phba->mbox_mem_pool);
2335 return;
2336 }
2337
2338 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2339 pmb->mbxCommand = MBX_READ_LNK_STAT;
2340 pmb->mbxOwner = OWN_HOST;
2341 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002342 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002343
James Smart2e0fef82007-06-17 19:56:36 -05002344 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002345 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2346 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2347 else
2348 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2349
2350 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002351 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002352 mempool_free( pmboxq, phba->mbox_mem_pool);
2353 return;
2354 }
2355
2356 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2357 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2358 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2359 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2360 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2361 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2362 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2363 lso->link_events = (phba->fc_eventTag >> 1);
2364
2365 psli->stats_start = get_seconds();
2366
James Smart1dcb58e2007-04-25 09:51:30 -04002367 mempool_free(pmboxq, phba->mbox_mem_pool);
2368
James Smart64ba8812006-08-02 15:24:34 -04002369 return;
2370}
dea31012005-04-17 16:05:31 -05002371
2372/*
2373 * The LPFC driver treats linkdown handling as target loss events so there
2374 * are no sysfs handlers for link_down_tmo.
2375 */
James Smart685f0bf2007-04-25 09:53:08 -04002376
2377static struct lpfc_nodelist *
2378lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002379{
James Smart2e0fef82007-06-17 19:56:36 -05002380 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2381 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002382 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002383
2384 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002385 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002386 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002387 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2388 starget->id == ndlp->nlp_sid) {
2389 spin_unlock_irq(shost->host_lock);
2390 return ndlp;
dea31012005-04-17 16:05:31 -05002391 }
2392 }
2393 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002394 return NULL;
2395}
dea31012005-04-17 16:05:31 -05002396
James Smart685f0bf2007-04-25 09:53:08 -04002397static void
2398lpfc_get_starget_port_id(struct scsi_target *starget)
2399{
2400 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2401
2402 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002403}
2404
2405static void
2406lpfc_get_starget_node_name(struct scsi_target *starget)
2407{
James Smart685f0bf2007-04-25 09:53:08 -04002408 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002409
James Smart685f0bf2007-04-25 09:53:08 -04002410 fc_starget_node_name(starget) =
2411 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002412}
2413
2414static void
2415lpfc_get_starget_port_name(struct scsi_target *starget)
2416{
James Smart685f0bf2007-04-25 09:53:08 -04002417 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002418
James Smart685f0bf2007-04-25 09:53:08 -04002419 fc_starget_port_name(starget) =
2420 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002421}
2422
2423static void
dea31012005-04-17 16:05:31 -05002424lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2425{
dea31012005-04-17 16:05:31 -05002426 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002427 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002428 else
James Smartc01f3202006-08-18 17:47:08 -04002429 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002430}
2431
2432
2433#define lpfc_rport_show_function(field, format_string, sz, cast) \
2434static ssize_t \
2435lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2436{ \
2437 struct fc_rport *rport = transport_class_to_rport(cdev); \
2438 struct lpfc_rport_data *rdata = rport->hostdata; \
2439 return snprintf(buf, sz, format_string, \
2440 (rdata->target) ? cast rdata->target->field : 0); \
2441}
2442
2443#define lpfc_rport_rd_attr(field, format_string, sz) \
2444 lpfc_rport_show_function(field, format_string, sz, ) \
2445static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2446
2447
2448struct fc_function_template lpfc_transport_functions = {
2449 /* fixed attributes the driver supports */
2450 .show_host_node_name = 1,
2451 .show_host_port_name = 1,
2452 .show_host_supported_classes = 1,
2453 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002454 .show_host_supported_speeds = 1,
2455 .show_host_maxframe_size = 1,
2456
2457 /* dynamic attributes the driver supports */
2458 .get_host_port_id = lpfc_get_host_port_id,
2459 .show_host_port_id = 1,
2460
2461 .get_host_port_type = lpfc_get_host_port_type,
2462 .show_host_port_type = 1,
2463
2464 .get_host_port_state = lpfc_get_host_port_state,
2465 .show_host_port_state = 1,
2466
2467 /* active_fc4s is shown but doesn't change (thus no get function) */
2468 .show_host_active_fc4s = 1,
2469
2470 .get_host_speed = lpfc_get_host_speed,
2471 .show_host_speed = 1,
2472
2473 .get_host_fabric_name = lpfc_get_host_fabric_name,
2474 .show_host_fabric_name = 1,
2475
2476 /*
2477 * The LPFC driver treats linkdown handling as target loss events
2478 * so there are no sysfs handlers for link_down_tmo.
2479 */
2480
2481 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002482 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002483
2484 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2485 .show_rport_maxframe_size = 1,
2486 .show_rport_supported_classes = 1,
2487
dea31012005-04-17 16:05:31 -05002488 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2489 .show_rport_dev_loss_tmo = 1,
2490
2491 .get_starget_port_id = lpfc_get_starget_port_id,
2492 .show_starget_port_id = 1,
2493
2494 .get_starget_node_name = lpfc_get_starget_node_name,
2495 .show_starget_node_name = 1,
2496
2497 .get_starget_port_name = lpfc_get_starget_port_name,
2498 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002499
2500 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002501 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2502 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002503
James Smart92d7f7b2007-06-17 19:56:38 -05002504 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2505};
2506
James Smart98c9ea52007-10-27 13:37:33 -04002507struct fc_function_template lpfc_vport_transport_functions = {
2508 /* fixed attributes the driver supports */
2509 .show_host_node_name = 1,
2510 .show_host_port_name = 1,
2511 .show_host_supported_classes = 1,
2512 .show_host_supported_fc4s = 1,
2513 .show_host_supported_speeds = 1,
2514 .show_host_maxframe_size = 1,
2515
2516 /* dynamic attributes the driver supports */
2517 .get_host_port_id = lpfc_get_host_port_id,
2518 .show_host_port_id = 1,
2519
2520 .get_host_port_type = lpfc_get_host_port_type,
2521 .show_host_port_type = 1,
2522
2523 .get_host_port_state = lpfc_get_host_port_state,
2524 .show_host_port_state = 1,
2525
2526 /* active_fc4s is shown but doesn't change (thus no get function) */
2527 .show_host_active_fc4s = 1,
2528
2529 .get_host_speed = lpfc_get_host_speed,
2530 .show_host_speed = 1,
2531
2532 .get_host_fabric_name = lpfc_get_host_fabric_name,
2533 .show_host_fabric_name = 1,
2534
2535 /*
2536 * The LPFC driver treats linkdown handling as target loss events
2537 * so there are no sysfs handlers for link_down_tmo.
2538 */
2539
2540 .get_fc_host_stats = lpfc_get_stats,
2541 .reset_fc_host_stats = lpfc_reset_stats,
2542
2543 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2544 .show_rport_maxframe_size = 1,
2545 .show_rport_supported_classes = 1,
2546
2547 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2548 .show_rport_dev_loss_tmo = 1,
2549
2550 .get_starget_port_id = lpfc_get_starget_port_id,
2551 .show_starget_port_id = 1,
2552
2553 .get_starget_node_name = lpfc_get_starget_node_name,
2554 .show_starget_node_name = 1,
2555
2556 .get_starget_port_name = lpfc_get_starget_port_name,
2557 .show_starget_port_name = 1,
2558
2559 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2560 .terminate_rport_io = lpfc_terminate_rport_io,
2561
2562 .vport_disable = lpfc_vport_disable,
2563};
2564
dea31012005-04-17 16:05:31 -05002565void
2566lpfc_get_cfgparam(struct lpfc_hba *phba)
2567{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002568 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2569 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002570 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002571 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2572 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002573 lpfc_ack0_init(phba, lpfc_ack0);
2574 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002575 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002576 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002577 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002578 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05002579 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
2580 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002581 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002582 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002583 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05002584 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
2585 /* Also reinitialize the host templates with new values. */
2586 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
2587 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
dea31012005-04-17 16:05:31 -05002588 /*
2589 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05002590 * used to create the sg_dma_buf_pool must be dynamically calculated.
2591 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05002592 */
2593 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2594 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05002595 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002596 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002597 return;
2598}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002599
James Smart3de2a652007-08-02 11:09:59 -04002600void
2601lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2602{
James Smarte8b62012007-08-02 11:10:09 -04002603 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002604 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2605 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2606 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2607 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2608 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2609 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2610 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2611 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2612 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2613 lpfc_max_luns_init(vport, lpfc_max_luns);
2614 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04002615 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05002616 return;
2617}