blob: a9fbb3f88659bb7bbcb117d9f268df77fb786f61 [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
Tony Jonesee959b02008-02-22 00:13:36 +010069lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
70 char *buf)
dea31012005-04-17 16:05:31 -050071{
72 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
73}
74
75static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010076lpfc_info_show(struct device *dev, struct device_attribute *attr,
77 char *buf)
dea31012005-04-17 16:05:31 -050078{
Tony Jonesee959b02008-02-22 00:13:36 +010079 struct Scsi_Host *host = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -050080
dea31012005-04-17 16:05:31 -050081 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
82}
83
84static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010085lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
86 char *buf)
dea31012005-04-17 16:05:31 -050087{
Tony Jonesee959b02008-02-22 00:13:36 +010088 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -050089 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
90 struct lpfc_hba *phba = vport->phba;
91
dea31012005-04-17 16:05:31 -050092 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
93}
94
95static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010096lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
97 char *buf)
James Smart57127f12007-10-27 13:37:05 -040098{
Tony Jonesee959b02008-02-22 00:13:36 +010099 struct Scsi_Host *shost = class_to_shost(dev);
James Smart57127f12007-10-27 13:37:05 -0400100 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
101 struct lpfc_hba *phba = vport->phba;
102 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
103}
104
105static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100106lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
107 char *buf)
dea31012005-04-17 16:05:31 -0500108{
Tony Jonesee959b02008-02-22 00:13:36 +0100109 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500110 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
111 struct lpfc_hba *phba = vport->phba;
112
dea31012005-04-17 16:05:31 -0500113 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
114}
115
116static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100117lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
118 char *buf)
dea31012005-04-17 16:05:31 -0500119{
Tony Jonesee959b02008-02-22 00:13:36 +0100120 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
122 struct lpfc_hba *phba = vport->phba;
123
dea31012005-04-17 16:05:31 -0500124 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
125}
126
127static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100128lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
129 char *buf)
dea31012005-04-17 16:05:31 -0500130{
Tony Jonesee959b02008-02-22 00:13:36 +0100131 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
133 struct lpfc_hba *phba = vport->phba;
134
dea31012005-04-17 16:05:31 -0500135 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
136}
137
138static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100139lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
140 char *buf)
dea31012005-04-17 16:05:31 -0500141{
Tony Jonesee959b02008-02-22 00:13:36 +0100142 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500143 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
144 struct lpfc_hba *phba = vport->phba;
145
dea31012005-04-17 16:05:31 -0500146 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
147}
148
149static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100150lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
151 char *buf)
dea31012005-04-17 16:05:31 -0500152{
Tony Jonesee959b02008-02-22 00:13:36 +0100153 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
155 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500156 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500157
dea31012005-04-17 16:05:31 -0500158 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500159 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500160}
161
162static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100163lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500164{
165 char hdw[9];
Tony Jonesee959b02008-02-22 00:13:36 +0100166 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500167 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
168 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500169 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500170
dea31012005-04-17 16:05:31 -0500171 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
172 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
173}
174static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100175lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
176 char *buf)
dea31012005-04-17 16:05:31 -0500177{
Tony Jonesee959b02008-02-22 00:13:36 +0100178 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500179 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
180 struct lpfc_hba *phba = vport->phba;
181
dea31012005-04-17 16:05:31 -0500182 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
183}
184static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100185lpfc_state_show(struct device *dev, struct device_attribute *attr,
186 char *buf)
dea31012005-04-17 16:05:31 -0500187{
Tony Jonesee959b02008-02-22 00:13:36 +0100188 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500189 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
190 struct lpfc_hba *phba = vport->phba;
191 int len = 0;
192
193 switch (phba->link_state) {
194 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500195 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500196 case LPFC_INIT_START:
197 case LPFC_INIT_MBX_CMDS:
198 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500199 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500200 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
201 break;
202 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500203 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500204 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400205 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500206
207 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500208 case LPFC_LOCAL_CFG_LINK:
209 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500210 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500211 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500212 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500213 case LPFC_FLOGI:
214 case LPFC_FABRIC_CFG_LINK:
215 case LPFC_NS_REG:
216 case LPFC_NS_QRY:
217 case LPFC_BUILD_DISC_LIST:
218 case LPFC_DISC_AUTH:
219 len += snprintf(buf + len, PAGE_SIZE - len,
220 "Discovery\n");
221 break;
222 case LPFC_VPORT_READY:
223 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
224 break;
225
James Smart92d7f7b2007-06-17 19:56:38 -0500226 case LPFC_VPORT_FAILED:
227 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
228 break;
229
230 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500231 len += snprintf(buf + len, PAGE_SIZE - len,
232 "Unknown\n");
233 break;
234 }
235
dea31012005-04-17 16:05:31 -0500236 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500237 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500238 len += snprintf(buf + len, PAGE_SIZE-len,
239 " Public Loop\n");
240 else
241 len += snprintf(buf + len, PAGE_SIZE-len,
242 " Private Loop\n");
243 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500244 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500245 len += snprintf(buf + len, PAGE_SIZE-len,
246 " Fabric\n");
247 else
248 len += snprintf(buf + len, PAGE_SIZE-len,
249 " Point-2-Point\n");
250 }
251 }
James Smart2e0fef82007-06-17 19:56:36 -0500252
dea31012005-04-17 16:05:31 -0500253 return len;
254}
255
256static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100257lpfc_num_discovered_ports_show(struct device *dev,
258 struct device_attribute *attr, char *buf)
dea31012005-04-17 16:05:31 -0500259{
Tony Jonesee959b02008-02-22 00:13:36 +0100260 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500261 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
262
263 return snprintf(buf, PAGE_SIZE, "%d\n",
264 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500265}
266
267
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700268static int
James Smart2e0fef82007-06-17 19:56:36 -0500269lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500270{
James Smart2e0fef82007-06-17 19:56:36 -0500271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
272 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500273 LPFC_MBOXQ_t *pmboxq;
274 int mbxstatus = MBXERR_ERROR;
275
James Smart2e0fef82007-06-17 19:56:36 -0500276 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart83108bd2008-01-11 01:53:09 -0500277 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
dea31012005-04-17 16:05:31 -0500278 return -EPERM;
279
280 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
281
282 if (!pmboxq)
283 return -ENOMEM;
284
285 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400286 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
287 pmboxq->mb.mbxOwner = OWN_HOST;
288
James Smart33ccf8d2006-08-17 11:57:58 -0400289 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500290
James Smart4db621e2006-07-06 15:49:49 -0400291 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
292 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
293 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
294 phba->cfg_link_speed);
295 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
296 phba->fc_ratov * 2);
297 }
298
James Smart5b8bd0c2007-04-25 09:52:49 -0400299 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500300 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400301 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500302
303 if (mbxstatus == MBXERR_ERROR)
304 return -EIO;
305
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700306 return 0;
dea31012005-04-17 16:05:31 -0500307}
308
James Smart40496f02006-07-06 15:50:22 -0400309static int
James Smart46fa3112007-04-25 09:51:45 -0400310lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
311{
312 struct completion online_compl;
313 struct lpfc_sli_ring *pring;
314 struct lpfc_sli *psli;
315 int status = 0;
316 int cnt = 0;
317 int i;
318
319 init_completion(&online_compl);
320 lpfc_workq_post_event(phba, &status, &online_compl,
321 LPFC_EVT_OFFLINE_PREP);
322 wait_for_completion(&online_compl);
323
324 if (status != 0)
325 return -EIO;
326
327 psli = &phba->sli;
328
James Smart09372822008-01-11 01:52:54 -0500329 /* Wait a little for things to settle down, but not
330 * long enough for dev loss timeout to expire.
331 */
James Smart46fa3112007-04-25 09:51:45 -0400332 for (i = 0; i < psli->num_rings; i++) {
333 pring = &psli->ring[i];
James Smart46fa3112007-04-25 09:51:45 -0400334 while (pring->txcmplq_cnt) {
335 msleep(10);
James Smart09372822008-01-11 01:52:54 -0500336 if (cnt++ > 500) { /* 5 secs */
James Smart46fa3112007-04-25 09:51:45 -0400337 lpfc_printf_log(phba,
338 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400339 "0466 Outstanding IO when "
340 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400341 break;
342 }
343 }
344 }
345
346 init_completion(&online_compl);
347 lpfc_workq_post_event(phba, &status, &online_compl, type);
348 wait_for_completion(&online_compl);
349
350 if (status != 0)
351 return -EIO;
352
353 return 0;
354}
355
356static int
James Smart40496f02006-07-06 15:50:22 -0400357lpfc_selective_reset(struct lpfc_hba *phba)
358{
359 struct completion online_compl;
360 int status = 0;
361
James Smart13815c82008-01-11 01:52:48 -0500362 if (!phba->cfg_enable_hba_reset)
363 return -EIO;
364
James Smart46fa3112007-04-25 09:51:45 -0400365 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400366
367 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400368 return status;
James Smart40496f02006-07-06 15:50:22 -0400369
370 init_completion(&online_compl);
371 lpfc_workq_post_event(phba, &status, &online_compl,
372 LPFC_EVT_ONLINE);
373 wait_for_completion(&online_compl);
374
375 if (status != 0)
376 return -EIO;
377
378 return 0;
379}
380
381static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100382lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
383 const char *buf, size_t count)
James Smart40496f02006-07-06 15:50:22 -0400384{
Tony Jonesee959b02008-02-22 00:13:36 +0100385 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
James Smart40496f02006-07-06 15:50:22 -0400389 int status = -EINVAL;
390
391 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
392 status = lpfc_selective_reset(phba);
393
394 if (status == 0)
395 return strlen(buf);
396 else
397 return status;
398}
399
dea31012005-04-17 16:05:31 -0500400static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100401lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
402 char *buf)
dea31012005-04-17 16:05:31 -0500403{
Tony Jonesee959b02008-02-22 00:13:36 +0100404 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500405 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
406 struct lpfc_hba *phba = vport->phba;
407
dea31012005-04-17 16:05:31 -0500408 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
409}
410
411static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100412lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
413 char *buf)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500414{
Tony Jonesee959b02008-02-22 00:13:36 +0100415 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500418 char * state;
419
James Smart2e0fef82007-06-17 19:56:36 -0500420 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500421 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500422 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500423 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500424 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500425 state = "offline";
426 else
427 state = "online";
428
429 return snprintf(buf, PAGE_SIZE, "%s\n", state);
430}
431
432static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100433lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
434 const char *buf, size_t count)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500435{
Tony Jonesee959b02008-02-22 00:13:36 +0100436 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500437 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
438 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500439 struct completion online_compl;
440 int status=0;
441
James Smart13815c82008-01-11 01:52:48 -0500442 if (!phba->cfg_enable_hba_reset)
443 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500444 init_completion(&online_compl);
445
James Smart46fa3112007-04-25 09:51:45 -0400446 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500447 lpfc_workq_post_event(phba, &status, &online_compl,
448 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400449 wait_for_completion(&online_compl);
450 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
451 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500452 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400453 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
454 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
455 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500456 else
457 return -EINVAL;
458
Jamie Wellnitz41415862006-02-28 19:25:27 -0500459 if (!status)
460 return strlen(buf);
461 else
462 return -EIO;
463}
464
James Smart311464e2007-08-02 11:10:37 -0400465static int
James Smart858c9f62007-06-17 19:56:39 -0500466lpfc_get_hba_info(struct lpfc_hba *phba,
467 uint32_t *mxri, uint32_t *axri,
468 uint32_t *mrpi, uint32_t *arpi,
469 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500470{
471 struct lpfc_sli *psli = &phba->sli;
472 LPFC_MBOXQ_t *pmboxq;
473 MAILBOX_t *pmb;
474 int rc = 0;
475
476 /*
477 * prevent udev from issuing mailbox commands until the port is
478 * configured.
479 */
480 if (phba->link_state < LPFC_LINK_DOWN ||
481 !phba->mbox_mem_pool ||
482 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
483 return 0;
484
485 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
486 return 0;
487
488 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
489 if (!pmboxq)
490 return 0;
491 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
492
493 pmb = &pmboxq->mb;
494 pmb->mbxCommand = MBX_READ_CONFIG;
495 pmb->mbxOwner = OWN_HOST;
496 pmboxq->context1 = NULL;
497
498 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
499 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
500 rc = MBX_NOT_FINISHED;
501 else
502 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
503
504 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500505 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500506 mempool_free(pmboxq, phba->mbox_mem_pool);
507 return 0;
508 }
509
510 if (mrpi)
511 *mrpi = pmb->un.varRdConfig.max_rpi;
512 if (arpi)
513 *arpi = pmb->un.varRdConfig.avail_rpi;
514 if (mxri)
515 *mxri = pmb->un.varRdConfig.max_xri;
516 if (axri)
517 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500518 if (mvpi)
519 *mvpi = pmb->un.varRdConfig.max_vpi;
520 if (avpi)
521 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500522
523 mempool_free(pmboxq, phba->mbox_mem_pool);
524 return 1;
525}
526
527static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100528lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
529 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500530{
Tony Jonesee959b02008-02-22 00:13:36 +0100531 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
533 struct lpfc_hba *phba = vport->phba;
534 uint32_t cnt;
535
James Smart858c9f62007-06-17 19:56:39 -0500536 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500537 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
538 return snprintf(buf, PAGE_SIZE, "Unknown\n");
539}
540
541static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100542lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
543 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500544{
Tony Jonesee959b02008-02-22 00:13:36 +0100545 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500546 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
547 struct lpfc_hba *phba = vport->phba;
548 uint32_t cnt, acnt;
549
James Smart858c9f62007-06-17 19:56:39 -0500550 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500551 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
552 return snprintf(buf, PAGE_SIZE, "Unknown\n");
553}
554
555static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100556lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
557 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500558{
Tony Jonesee959b02008-02-22 00:13:36 +0100559 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
562 uint32_t cnt;
563
James Smart858c9f62007-06-17 19:56:39 -0500564 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500565 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
566 return snprintf(buf, PAGE_SIZE, "Unknown\n");
567}
568
569static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100570lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
571 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500572{
Tony Jonesee959b02008-02-22 00:13:36 +0100573 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500574 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
575 struct lpfc_hba *phba = vport->phba;
576 uint32_t cnt, acnt;
577
James Smart858c9f62007-06-17 19:56:39 -0500578 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
579 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
580 return snprintf(buf, PAGE_SIZE, "Unknown\n");
581}
582
583static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100584lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
585 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500586{
Tony Jonesee959b02008-02-22 00:13:36 +0100587 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
589 struct lpfc_hba *phba = vport->phba;
590 uint32_t cnt;
591
592 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
593 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
594 return snprintf(buf, PAGE_SIZE, "Unknown\n");
595}
596
597static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100598lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
599 char *buf)
James Smart858c9f62007-06-17 19:56:39 -0500600{
Tony Jonesee959b02008-02-22 00:13:36 +0100601 struct Scsi_Host *shost = class_to_shost(dev);
James Smart858c9f62007-06-17 19:56:39 -0500602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
604 uint32_t cnt, acnt;
605
606 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500607 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
608 return snprintf(buf, PAGE_SIZE, "Unknown\n");
609}
610
611static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100612lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
613 char *buf)
James Smart92d7f7b2007-06-17 19:56:38 -0500614{
Tony Jonesee959b02008-02-22 00:13:36 +0100615 struct Scsi_Host *shost = class_to_shost(dev);
James Smart92d7f7b2007-06-17 19:56:38 -0500616 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
617 struct lpfc_hba *phba = vport->phba;
618
619 if (!(phba->max_vpi))
620 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
621 if (vport->port_type == LPFC_PHYSICAL_PORT)
622 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
623 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
624}
625
Jamie Wellnitz41415862006-02-28 19:25:27 -0500626static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100627lpfc_poll_show(struct device *dev, struct device_attribute *attr,
628 char *buf)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500629{
Tony Jonesee959b02008-02-22 00:13:36 +0100630 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500631 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
632 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500633
634 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
635}
636
637static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100638lpfc_poll_store(struct device *dev, struct device_attribute *attr,
639 const char *buf, size_t count)
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500640{
Tony Jonesee959b02008-02-22 00:13:36 +0100641 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500642 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
643 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500644 uint32_t creg_val;
645 uint32_t old_val;
646 int val=0;
647
648 if (!isdigit(buf[0]))
649 return -EINVAL;
650
651 if (sscanf(buf, "%i", &val) != 1)
652 return -EINVAL;
653
654 if ((val & 0x3) != val)
655 return -EINVAL;
656
James Smart2e0fef82007-06-17 19:56:36 -0500657 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500658
659 old_val = phba->cfg_poll;
660
661 if (val & ENABLE_FCP_RING_POLLING) {
662 if ((val & DISABLE_FCP_RING_INT) &&
663 !(old_val & DISABLE_FCP_RING_INT)) {
664 creg_val = readl(phba->HCregaddr);
665 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
666 writel(creg_val, phba->HCregaddr);
667 readl(phba->HCregaddr); /* flush */
668
669 lpfc_poll_start_timer(phba);
670 }
671 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500672 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500673 return -EINVAL;
674 }
675
676 if (!(val & DISABLE_FCP_RING_INT) &&
677 (old_val & DISABLE_FCP_RING_INT))
678 {
James Smart2e0fef82007-06-17 19:56:36 -0500679 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500680 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500681 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500682 creg_val = readl(phba->HCregaddr);
683 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
684 writel(creg_val, phba->HCregaddr);
685 readl(phba->HCregaddr); /* flush */
686 }
687
688 phba->cfg_poll = val;
689
James Smart2e0fef82007-06-17 19:56:36 -0500690 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500691
692 return strlen(buf);
693}
dea31012005-04-17 16:05:31 -0500694
695#define lpfc_param_show(attr) \
696static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100697lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
698 char *buf) \
dea31012005-04-17 16:05:31 -0500699{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100700 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -0500701 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
702 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500703 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400704 val = phba->cfg_##attr;\
705 return snprintf(buf, PAGE_SIZE, "%d\n",\
706 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500707}
708
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400709#define lpfc_param_hex_show(attr) \
710static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100711lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
712 char *buf) \
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400713{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100714 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -0500715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
716 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400717 int val = 0;\
718 val = phba->cfg_##attr;\
719 return snprintf(buf, PAGE_SIZE, "%#x\n",\
720 phba->cfg_##attr);\
721}
722
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400723#define lpfc_param_init(attr, default, minval, maxval) \
724static int \
725lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
726{ \
727 if (val >= minval && val <= maxval) {\
728 phba->cfg_##attr = val;\
729 return 0;\
730 }\
731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400732 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
733 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400734 phba->cfg_##attr = default;\
735 return -EINVAL;\
736}
737
738#define lpfc_param_set(attr, default, minval, maxval) \
739static int \
740lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
741{ \
742 if (val >= minval && val <= maxval) {\
743 phba->cfg_##attr = val;\
744 return 0;\
745 }\
746 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400747 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
748 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400749 return -EINVAL;\
750}
751
752#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500753static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100754lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
755 const char *buf, size_t count) \
dea31012005-04-17 16:05:31 -0500756{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100757 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart2e0fef82007-06-17 19:56:36 -0500758 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
759 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400760 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400761 if (!isdigit(buf[0]))\
762 return -EINVAL;\
763 if (sscanf(buf, "%i", &val) != 1)\
764 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400765 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400766 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400767 else \
768 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500769}
770
James Smart3de2a652007-08-02 11:09:59 -0400771#define lpfc_vport_param_show(attr) \
772static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100773lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
774 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -0400775{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100776 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -0400777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
778 int val = 0;\
779 val = vport->cfg_##attr;\
780 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
781}
782
783#define lpfc_vport_param_hex_show(attr) \
784static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100785lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
786 char *buf) \
James Smart3de2a652007-08-02 11:09:59 -0400787{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100788 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -0400789 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
790 int val = 0;\
791 val = vport->cfg_##attr;\
792 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
793}
794
795#define lpfc_vport_param_init(attr, default, minval, maxval) \
796static int \
797lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
798{ \
799 if (val >= minval && val <= maxval) {\
800 vport->cfg_##attr = val;\
801 return 0;\
802 }\
James Smarte8b62012007-08-02 11:10:09 -0400803 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
804 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
805 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400806 vport->cfg_##attr = default;\
807 return -EINVAL;\
808}
809
810#define lpfc_vport_param_set(attr, default, minval, maxval) \
811static int \
812lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
813{ \
814 if (val >= minval && val <= maxval) {\
815 vport->cfg_##attr = val;\
816 return 0;\
817 }\
James Smarte8b62012007-08-02 11:10:09 -0400818 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
819 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
820 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400821 return -EINVAL;\
822}
823
824#define lpfc_vport_param_store(attr) \
825static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +0100826lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
827 const char *buf, size_t count) \
James Smart3de2a652007-08-02 11:09:59 -0400828{ \
Tony Jonesee959b02008-02-22 00:13:36 +0100829 struct Scsi_Host *shost = class_to_shost(dev);\
James Smart3de2a652007-08-02 11:09:59 -0400830 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
831 int val=0;\
832 if (!isdigit(buf[0]))\
833 return -EINVAL;\
834 if (sscanf(buf, "%i", &val) != 1)\
835 return -EINVAL;\
836 if (lpfc_##attr##_set(vport, val) == 0) \
837 return strlen(buf);\
838 else \
839 return -EINVAL;\
840}
841
842
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400843#define LPFC_ATTR(name, defval, minval, maxval, desc) \
844static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500845module_param(lpfc_##name, int, 0);\
846MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400847lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500848
849#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
850static int lpfc_##name = defval;\
851module_param(lpfc_##name, int, 0);\
852MODULE_PARM_DESC(lpfc_##name, desc);\
853lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400854lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +0100855static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
dea31012005-04-17 16:05:31 -0500856
857#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
858static int lpfc_##name = defval;\
859module_param(lpfc_##name, int, 0);\
860MODULE_PARM_DESC(lpfc_##name, desc);\
861lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400862lpfc_param_init(name, defval, minval, maxval)\
863lpfc_param_set(name, defval, minval, maxval)\
864lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +0100865static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
866 lpfc_##name##_show, lpfc_##name##_store)
dea31012005-04-17 16:05:31 -0500867
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400868#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
869static int lpfc_##name = defval;\
870module_param(lpfc_##name, int, 0);\
871MODULE_PARM_DESC(lpfc_##name, desc);\
872lpfc_param_hex_show(name)\
873lpfc_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +0100874static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400875
876#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
877static int lpfc_##name = defval;\
878module_param(lpfc_##name, int, 0);\
879MODULE_PARM_DESC(lpfc_##name, desc);\
880lpfc_param_hex_show(name)\
881lpfc_param_init(name, defval, minval, maxval)\
882lpfc_param_set(name, defval, minval, maxval)\
883lpfc_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +0100884static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
885 lpfc_##name##_show, lpfc_##name##_store)
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400886
James Smart3de2a652007-08-02 11:09:59 -0400887#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
888static int lpfc_##name = defval;\
889module_param(lpfc_##name, int, 0);\
890MODULE_PARM_DESC(lpfc_##name, desc);\
891lpfc_vport_param_init(name, defval, minval, maxval)
892
893#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
894static int lpfc_##name = defval;\
895module_param(lpfc_##name, int, 0);\
896MODULE_PARM_DESC(lpfc_##name, desc);\
897lpfc_vport_param_show(name)\
898lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +0100899static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -0400900
901#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
902static int lpfc_##name = defval;\
903module_param(lpfc_##name, int, 0);\
904MODULE_PARM_DESC(lpfc_##name, desc);\
905lpfc_vport_param_show(name)\
906lpfc_vport_param_init(name, defval, minval, maxval)\
907lpfc_vport_param_set(name, defval, minval, maxval)\
908lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +0100909static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
910 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -0400911
912#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
913static int lpfc_##name = defval;\
914module_param(lpfc_##name, int, 0);\
915MODULE_PARM_DESC(lpfc_##name, desc);\
916lpfc_vport_param_hex_show(name)\
917lpfc_vport_param_init(name, defval, minval, maxval)\
Tony Jonesee959b02008-02-22 00:13:36 +0100918static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
James Smart3de2a652007-08-02 11:09:59 -0400919
920#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
921static int lpfc_##name = defval;\
922module_param(lpfc_##name, int, 0);\
923MODULE_PARM_DESC(lpfc_##name, desc);\
924lpfc_vport_param_hex_show(name)\
925lpfc_vport_param_init(name, defval, minval, maxval)\
926lpfc_vport_param_set(name, defval, minval, maxval)\
927lpfc_vport_param_store(name)\
Tony Jonesee959b02008-02-22 00:13:36 +0100928static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
929 lpfc_##name##_show, lpfc_##name##_store)
James Smart3de2a652007-08-02 11:09:59 -0400930
Tony Jonesee959b02008-02-22 00:13:36 +0100931static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
932static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
933static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
934static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
935static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
936static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
937static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
938static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
939static DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
940static DEVICE_ATTR(option_rom_version, S_IRUGO,
941 lpfc_option_rom_version_show, NULL);
942static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
943 lpfc_num_discovered_ports_show, NULL);
944static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
945static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
946static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
947 lpfc_board_mode_show, lpfc_board_mode_store);
948static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
949static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
950static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
951static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
952static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
953static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
954static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
955static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
956static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
dea31012005-04-17 16:05:31 -0500957
James Smartc3f28af2006-08-18 17:47:18 -0400958
James Smarta12e07b2006-12-02 13:35:30 -0500959static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400960
961static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100962lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
963 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -0400964{
Tony Jonesee959b02008-02-22 00:13:36 +0100965 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -0500966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
967 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400968 unsigned int cnt = count;
969
970 /*
971 * We're doing a simple sanity check for soft_wwpn setting.
972 * We require that the user write a specific key to enable
973 * the soft_wwpn attribute to be settable. Once the attribute
974 * is written, the enable key resets. If further updates are
975 * desired, the key must be written again to re-enable the
976 * attribute.
977 *
978 * The "key" is not secret - it is a hardcoded string shown
979 * here. The intent is to protect against the random user or
980 * application that is just writing attributes.
981 */
982
983 /* count may include a LF at end of string */
984 if (buf[cnt-1] == '\n')
985 cnt--;
986
James Smarta12e07b2006-12-02 13:35:30 -0500987 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
988 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400989 return -EINVAL;
990
James Smarta12e07b2006-12-02 13:35:30 -0500991 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400992 return count;
993}
Tony Jonesee959b02008-02-22 00:13:36 +0100994static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
995 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400996
997static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100998lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
999 char *buf)
James Smartc3f28af2006-08-18 17:47:18 -04001000{
Tony Jonesee959b02008-02-22 00:13:36 +01001001 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001002 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1003 struct lpfc_hba *phba = vport->phba;
1004
Randy Dunlapafc071e2006-10-23 21:47:13 -07001005 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1006 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -04001007}
1008
1009
1010static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001011lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
1012 const char *buf, size_t count)
James Smartc3f28af2006-08-18 17:47:18 -04001013{
Tony Jonesee959b02008-02-22 00:13:36 +01001014 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001015 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1016 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -04001017 struct completion online_compl;
1018 int stat1=0, stat2=0;
1019 unsigned int i, j, cnt=count;
1020 u8 wwpn[8];
1021
James Smart13815c82008-01-11 01:52:48 -05001022 if (!phba->cfg_enable_hba_reset)
1023 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001024 spin_lock_irq(&phba->hbalock);
1025 if (phba->over_temp_state == HBA_OVER_TEMP) {
1026 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001027 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001028 }
1029 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -04001030 /* count may include a LF at end of string */
1031 if (buf[cnt-1] == '\n')
1032 cnt--;
1033
James Smarta12e07b2006-12-02 13:35:30 -05001034 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001035 ((cnt == 17) && (*buf++ != 'x')) ||
1036 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1037 return -EINVAL;
1038
James Smarta12e07b2006-12-02 13:35:30 -05001039 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001040
1041 memset(wwpn, 0, sizeof(wwpn));
1042
1043 /* Validate and store the new name */
1044 for (i=0, j=0; i < 16; i++) {
1045 if ((*buf >= 'a') && (*buf <= 'f'))
1046 j = ((j << 4) | ((*buf++ -'a') + 10));
1047 else if ((*buf >= 'A') && (*buf <= 'F'))
1048 j = ((j << 4) | ((*buf++ -'A') + 10));
1049 else if ((*buf >= '0') && (*buf <= '9'))
1050 j = ((j << 4) | (*buf++ -'0'));
1051 else
1052 return -EINVAL;
1053 if (i % 2) {
1054 wwpn[i/2] = j & 0xff;
1055 j = 0;
1056 }
1057 }
1058 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001059 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001060 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001061 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001062
1063 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1064 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1065
James Smart46fa3112007-04-25 09:51:45 -04001066 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001067 if (stat1)
1068 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001069 "0463 lpfc_soft_wwpn attribute set failed to "
1070 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001071 init_completion(&online_compl);
1072 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1073 wait_for_completion(&online_compl);
1074 if (stat2)
1075 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001076 "0464 lpfc_soft_wwpn attribute set failed to "
1077 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001078 return (stat1 || stat2) ? -EIO : count;
1079}
Tony Jonesee959b02008-02-22 00:13:36 +01001080static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1081 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
James Smartc3f28af2006-08-18 17:47:18 -04001082
James Smarta12e07b2006-12-02 13:35:30 -05001083static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001084lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
1085 char *buf)
James Smarta12e07b2006-12-02 13:35:30 -05001086{
Tony Jonesee959b02008-02-22 00:13:36 +01001087 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001088 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001089 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1090 (unsigned long long)phba->cfg_soft_wwnn);
1091}
1092
1093
1094static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001095lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
1096 const char *buf, size_t count)
James Smarta12e07b2006-12-02 13:35:30 -05001097{
Tony Jonesee959b02008-02-22 00:13:36 +01001098 struct Scsi_Host *shost = class_to_shost(dev);
James Smart51ef4c22007-08-02 11:10:31 -04001099 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001100 unsigned int i, j, cnt=count;
1101 u8 wwnn[8];
1102
1103 /* count may include a LF at end of string */
1104 if (buf[cnt-1] == '\n')
1105 cnt--;
1106
1107 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1108 ((cnt == 17) && (*buf++ != 'x')) ||
1109 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1110 return -EINVAL;
1111
1112 /*
1113 * Allow wwnn to be set many times, as long as the enable is set.
1114 * However, once the wwpn is set, everything locks.
1115 */
1116
1117 memset(wwnn, 0, sizeof(wwnn));
1118
1119 /* Validate and store the new name */
1120 for (i=0, j=0; i < 16; i++) {
1121 if ((*buf >= 'a') && (*buf <= 'f'))
1122 j = ((j << 4) | ((*buf++ -'a') + 10));
1123 else if ((*buf >= 'A') && (*buf <= 'F'))
1124 j = ((j << 4) | ((*buf++ -'A') + 10));
1125 else if ((*buf >= '0') && (*buf <= '9'))
1126 j = ((j << 4) | (*buf++ -'0'));
1127 else
1128 return -EINVAL;
1129 if (i % 2) {
1130 wwnn[i/2] = j & 0xff;
1131 j = 0;
1132 }
1133 }
1134 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1135
1136 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1137 "lpfc%d: soft_wwnn set. Value will take effect upon "
1138 "setting of the soft_wwpn\n", phba->brd_no);
1139
1140 return count;
1141}
Tony Jonesee959b02008-02-22 00:13:36 +01001142static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1143 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
James Smarta12e07b2006-12-02 13:35:30 -05001144
James Smartc3f28af2006-08-18 17:47:18 -04001145
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001146static int lpfc_poll = 0;
1147module_param(lpfc_poll, int, 0);
1148MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1149 " 0 - none,"
1150 " 1 - poll with interrupts enabled"
1151 " 3 - poll and disable FCP ring interrupts");
1152
Tony Jonesee959b02008-02-22 00:13:36 +01001153static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1154 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001155
James Smart92d7f7b2007-06-17 19:56:38 -05001156int lpfc_sli_mode = 0;
1157module_param(lpfc_sli_mode, int, 0);
1158MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1159 " 0 - auto (SLI-3 if supported),"
1160 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1161 " 3 - select SLI-3");
1162
James Smart7ee5d432007-10-27 13:37:17 -04001163int lpfc_enable_npiv = 0;
1164module_param(lpfc_enable_npiv, int, 0);
1165MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1166lpfc_param_show(enable_npiv);
1167lpfc_param_init(enable_npiv, 0, 0, 1);
Tony Jonesee959b02008-02-22 00:13:36 +01001168static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
James Smart7ee5d432007-10-27 13:37:17 -04001169 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001170
dea31012005-04-17 16:05:31 -05001171/*
James Smartc01f3202006-08-18 17:47:08 -04001172# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1173# until the timer expires. Value range is [0,255]. Default value is 30.
1174*/
1175static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1176static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1177module_param(lpfc_nodev_tmo, int, 0);
1178MODULE_PARM_DESC(lpfc_nodev_tmo,
1179 "Seconds driver will hold I/O waiting "
1180 "for a device to come back");
1181static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001182lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
1183 char *buf)
James Smartc01f3202006-08-18 17:47:08 -04001184{
Tony Jonesee959b02008-02-22 00:13:36 +01001185 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001186 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001187 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001188 val = vport->cfg_devloss_tmo;
1189 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001190}
1191
1192static int
James Smart3de2a652007-08-02 11:09:59 -04001193lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001194{
James Smart3de2a652007-08-02 11:09:59 -04001195 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1196 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1197 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001198 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1199 "0402 Ignoring nodev_tmo module "
1200 "parameter because devloss_tmo is "
1201 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001202 return 0;
1203 }
1204
1205 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001206 vport->cfg_nodev_tmo = val;
1207 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001208 return 0;
1209 }
James Smarte8b62012007-08-02 11:10:09 -04001210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1211 "0400 lpfc_nodev_tmo attribute cannot be set to"
1212 " %d, allowed range is [%d, %d]\n",
1213 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001214 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001215 return -EINVAL;
1216}
1217
James Smart7054a602007-04-25 09:52:34 -04001218static void
James Smart3de2a652007-08-02 11:09:59 -04001219lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001220{
James Smart858c9f62007-06-17 19:56:39 -05001221 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001222 struct lpfc_nodelist *ndlp;
1223
James Smart51ef4c22007-08-02 11:10:31 -04001224 shost = lpfc_shost_from_vport(vport);
1225 spin_lock_irq(shost->host_lock);
1226 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
James Smarte47c9092008-02-08 18:49:26 -05001227 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
James Smart51ef4c22007-08-02 11:10:31 -04001228 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1229 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001230}
1231
James Smartc01f3202006-08-18 17:47:08 -04001232static int
James Smart3de2a652007-08-02 11:09:59 -04001233lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001234{
James Smart3de2a652007-08-02 11:09:59 -04001235 if (vport->dev_loss_tmo_changed ||
1236 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001237 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1238 "0401 Ignoring change to nodev_tmo "
1239 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001240 return 0;
1241 }
James Smartc01f3202006-08-18 17:47:08 -04001242 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 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001246 return 0;
1247 }
James Smarte8b62012007-08-02 11:10:09 -04001248 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1249 "0403 lpfc_nodev_tmo attribute cannot be set to"
1250 "%d, allowed range is [%d, %d]\n",
1251 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001252 return -EINVAL;
1253}
1254
James Smart3de2a652007-08-02 11:09:59 -04001255lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001256
Tony Jonesee959b02008-02-22 00:13:36 +01001257static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1258 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001259
1260/*
1261# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1262# disappear until the timer expires. Value range is [0,255]. Default
1263# value is 30.
1264*/
1265module_param(lpfc_devloss_tmo, int, 0);
1266MODULE_PARM_DESC(lpfc_devloss_tmo,
1267 "Seconds driver will hold I/O waiting "
1268 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001269lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1270 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1271lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001272static int
James Smart3de2a652007-08-02 11:09:59 -04001273lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001274{
1275 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001276 vport->cfg_nodev_tmo = val;
1277 vport->cfg_devloss_tmo = val;
1278 vport->dev_loss_tmo_changed = 1;
1279 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001280 return 0;
1281 }
1282
James Smarte8b62012007-08-02 11:10:09 -04001283 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1284 "0404 lpfc_devloss_tmo attribute cannot be set to"
1285 " %d, allowed range is [%d, %d]\n",
1286 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001287 return -EINVAL;
1288}
1289
James Smart3de2a652007-08-02 11:09:59 -04001290lpfc_vport_param_store(devloss_tmo)
Tony Jonesee959b02008-02-22 00:13:36 +01001291static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1292 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
James Smartc01f3202006-08-18 17:47:08 -04001293
1294/*
dea31012005-04-17 16:05:31 -05001295# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1296# deluged with LOTS of information.
1297# You can set a bit mask to record specific types of verbose messages:
1298#
1299# LOG_ELS 0x1 ELS events
1300# LOG_DISCOVERY 0x2 Link discovery events
1301# LOG_MBOX 0x4 Mailbox events
1302# LOG_INIT 0x8 Initialization events
1303# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001304# LOG_FCP 0x40 FCP traffic history
1305# LOG_NODE 0x80 Node table events
1306# LOG_MISC 0x400 Miscellaneous events
1307# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001308# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001309# LOG_LIBDFC 0x2000 LIBDFC events
1310# LOG_ALL_MSG 0xffff LOG all messages
1311*/
James Smarte8b62012007-08-02 11:10:09 -04001312LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1313 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001314
1315/*
James Smart7ee5d432007-10-27 13:37:17 -04001316# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1317# objects that have been registered with the nameserver after login.
1318*/
1319LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1320 "Deregister nameserver objects before LOGO");
1321
1322/*
dea31012005-04-17 16:05:31 -05001323# lun_queue_depth: This parameter is used to limit the number of outstanding
1324# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1325*/
James Smart3de2a652007-08-02 11:09:59 -04001326LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1327 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001328
1329/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001330# hba_queue_depth: This parameter is used to limit the number of outstanding
1331# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1332# value is greater than the maximum number of exchanges supported by the HBA,
1333# then maximum number of exchanges supported by the HBA is used to determine
1334# the hba_queue_depth.
1335*/
1336LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1337 "Max number of FCP commands we can queue to a lpfc HBA");
1338
1339/*
James Smart92d7f7b2007-06-17 19:56:38 -05001340# peer_port_login: This parameter allows/prevents logins
1341# between peer ports hosted on the same physical port.
1342# When this parameter is set 0 peer ports of same physical port
1343# are not allowed to login to each other.
1344# When this parameter is set 1 peer ports of same physical port
1345# are allowed to login to each other.
1346# Default value of this parameter is 0.
1347*/
James Smart3de2a652007-08-02 11:09:59 -04001348LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1349 "Allow peer ports on the same physical port to login to each "
1350 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001351
1352/*
James Smart3de2a652007-08-02 11:09:59 -04001353# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001354# between Virtual Ports and remote initiators.
1355# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1356# other initiators and will attempt to PLOGI all remote ports.
1357# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1358# remote ports and will not attempt to PLOGI to other initiators.
1359# This parameter does not restrict to the physical port.
1360# This parameter does not restrict logins to Fabric resident remote ports.
1361# Default value of this parameter is 1.
1362*/
James Smart3de2a652007-08-02 11:09:59 -04001363static int lpfc_restrict_login = 1;
1364module_param(lpfc_restrict_login, int, 0);
1365MODULE_PARM_DESC(lpfc_restrict_login,
1366 "Restrict virtual ports login to remote initiators.");
1367lpfc_vport_param_show(restrict_login);
1368
1369static int
1370lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1371{
1372 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001373 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1374 "0449 lpfc_restrict_login attribute cannot "
1375 "be set to %d, allowed range is [0, 1]\n",
1376 val);
James Smart3de2a652007-08-02 11:09:59 -04001377 vport->cfg_restrict_login = 1;
1378 return -EINVAL;
1379 }
1380 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1381 vport->cfg_restrict_login = 0;
1382 return 0;
1383 }
1384 vport->cfg_restrict_login = val;
1385 return 0;
1386}
1387
1388static int
1389lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1390{
1391 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001392 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1393 "0450 lpfc_restrict_login attribute cannot "
1394 "be set to %d, allowed range is [0, 1]\n",
1395 val);
James Smart3de2a652007-08-02 11:09:59 -04001396 vport->cfg_restrict_login = 1;
1397 return -EINVAL;
1398 }
1399 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001400 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1401 "0468 lpfc_restrict_login must be 0 for "
1402 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001403 vport->cfg_restrict_login = 0;
1404 return 0;
1405 }
1406 vport->cfg_restrict_login = val;
1407 return 0;
1408}
1409lpfc_vport_param_store(restrict_login);
Tony Jonesee959b02008-02-22 00:13:36 +01001410static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1411 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001412
1413/*
dea31012005-04-17 16:05:31 -05001414# Some disk devices have a "select ID" or "select Target" capability.
1415# From a protocol standpoint "select ID" usually means select the
1416# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1417# annex" which contains a table that maps a "select ID" (a number
1418# between 0 and 7F) to an ALPA. By default, for compatibility with
1419# older drivers, the lpfc driver scans this table from low ALPA to high
1420# ALPA.
1421#
1422# Turning on the scan-down variable (on = 1, off = 0) will
1423# cause the lpfc driver to use an inverted table, effectively
1424# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1425#
1426# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1427# and will not work across a fabric. Also this parameter will take
1428# effect only in the case when ALPA map is not available.)
1429*/
James Smart3de2a652007-08-02 11:09:59 -04001430LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1431 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001432
1433/*
dea31012005-04-17 16:05:31 -05001434# lpfc_topology: link topology for init link
1435# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001436# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001437# 0x02 = attempt point-to-point mode only
1438# 0x04 = attempt loop mode only
1439# 0x06 = attempt point-to-point mode then loop
1440# Set point-to-point mode if you want to run as an N_Port.
1441# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1442# Default value is 0.
1443*/
James Smart83108bd2008-01-11 01:53:09 -05001444static int
1445lpfc_topology_set(struct lpfc_hba *phba, int val)
1446{
1447 int err;
1448 uint32_t prev_val;
1449 if (val >= 0 && val <= 6) {
1450 prev_val = phba->cfg_topology;
1451 phba->cfg_topology = val;
1452 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
1453 if (err)
1454 phba->cfg_topology = prev_val;
1455 return err;
1456 }
1457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1458 "%d:0467 lpfc_topology attribute cannot be set to %d, "
1459 "allowed range is [0, 6]\n",
1460 phba->brd_no, val);
1461 return -EINVAL;
1462}
1463static int lpfc_topology = 0;
1464module_param(lpfc_topology, int, 0);
1465MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
1466lpfc_param_show(topology)
1467lpfc_param_init(topology, 0, 0, 6)
1468lpfc_param_store(topology)
Tony Jonesee959b02008-02-22 00:13:36 +01001469static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05001470 lpfc_topology_show, lpfc_topology_store);
dea31012005-04-17 16:05:31 -05001471
1472/*
1473# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1474# connection.
1475# 0 = auto select (default)
1476# 1 = 1 Gigabaud
1477# 2 = 2 Gigabaud
1478# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001479# 8 = 8 Gigabaud
1480# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001481*/
James Smart83108bd2008-01-11 01:53:09 -05001482static int
1483lpfc_link_speed_set(struct lpfc_hba *phba, int val)
1484{
1485 int err;
1486 uint32_t prev_val;
1487
1488 if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
1489 ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
1490 ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
1491 ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
1492 ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
1493 return -EINVAL;
1494
1495 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
1496 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
1497 prev_val = phba->cfg_link_speed;
1498 phba->cfg_link_speed = val;
1499 err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
1500 if (err)
1501 phba->cfg_link_speed = prev_val;
1502 return err;
1503 }
1504
1505 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1506 "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
1507 "allowed range is [0, 8]\n",
1508 phba->brd_no, val);
1509 return -EINVAL;
1510}
1511
1512static int lpfc_link_speed = 0;
1513module_param(lpfc_link_speed, int, 0);
1514MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
1515lpfc_param_show(link_speed)
1516static int
1517lpfc_link_speed_init(struct lpfc_hba *phba, int val)
1518{
1519 if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
1520 && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
1521 phba->cfg_link_speed = val;
1522 return 0;
1523 }
1524 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1525 "0454 lpfc_link_speed attribute cannot "
1526 "be set to %d, allowed values are "
1527 "["LPFC_LINK_SPEED_STRING"]\n", val);
1528 phba->cfg_link_speed = 0;
1529 return -EINVAL;
1530}
1531
1532lpfc_param_store(link_speed)
Tony Jonesee959b02008-02-22 00:13:36 +01001533static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
James Smart83108bd2008-01-11 01:53:09 -05001534 lpfc_link_speed_show, lpfc_link_speed_store);
dea31012005-04-17 16:05:31 -05001535
1536/*
1537# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1538# Value range is [2,3]. Default value is 3.
1539*/
James Smart3de2a652007-08-02 11:09:59 -04001540LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1541 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001542
1543/*
1544# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1545# is [0,1]. Default value is 0.
1546*/
James Smart3de2a652007-08-02 11:09:59 -04001547LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1548 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001549
1550/*
1551# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1552# range is [0,1]. Default value is 0.
1553*/
1554LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1555
1556/*
1557# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1558# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001559# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001560# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1561# cr_delay is set to 0.
1562*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001563LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001564 "interrupt response is generated");
1565
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001566LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001567 "interrupt response is generated");
1568
1569/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001570# lpfc_multi_ring_support: Determines how many rings to spread available
1571# cmd/rsp IOCB entries across.
1572# Value range is [1,2]. Default value is 1.
1573*/
1574LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1575 "SLI rings to spread IOCB entries across");
1576
1577/*
James Smarta4bc3372006-12-02 13:34:16 -05001578# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1579# identifies what rctl value to configure the additional ring for.
1580# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1581*/
1582LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1583 255, "Identifies RCTL for additional ring configuration");
1584
1585/*
1586# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1587# identifies what type value to configure the additional ring for.
1588# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1589*/
1590LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1591 255, "Identifies TYPE for additional ring configuration");
1592
1593/*
dea31012005-04-17 16:05:31 -05001594# lpfc_fdmi_on: controls FDMI support.
1595# 0 = no FDMI support
1596# 1 = support FDMI without attribute of hostname
1597# 2 = support FDMI with attribute of hostname
1598# Value range [0,2]. Default value is 0.
1599*/
James Smart3de2a652007-08-02 11:09:59 -04001600LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001601
1602/*
1603# Specifies the maximum number of ELS cmds we can have outstanding (for
1604# discovery). Value range is [1,64]. Default value = 32.
1605*/
James Smart3de2a652007-08-02 11:09:59 -04001606LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001607 "during discovery");
1608
1609/*
James Smart65a29c12006-07-06 15:50:50 -04001610# lpfc_max_luns: maximum allowed LUN.
1611# Value range is [0,65535]. Default value is 255.
1612# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001613*/
James Smart3de2a652007-08-02 11:09:59 -04001614LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001615
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001616/*
1617# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1618# Value range is [1,255], default value is 10.
1619*/
1620LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1621 "Milliseconds driver will wait between polling FCP ring");
1622
James Smart4ff43242006-12-02 13:34:56 -05001623/*
1624# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1625# support this feature
1626# 0 = MSI disabled (default)
1627# 1 = MSI enabled
James Smartdb2378e2008-02-08 18:49:51 -05001628# 2 = MSI-X enabled
1629# Value range is [0,2]. Default value is 0.
James Smart4ff43242006-12-02 13:34:56 -05001630*/
James Smartdb2378e2008-02-08 18:49:51 -05001631LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
1632 "MSI-X (2), if possible");
James Smart4ff43242006-12-02 13:34:56 -05001633
James Smart13815c82008-01-11 01:52:48 -05001634/*
1635# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
1636# 0 = HBA resets disabled
1637# 1 = HBA resets enabled (default)
1638# Value range is [0,1]. Default value is 1.
1639*/
1640LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04001641
James Smart13815c82008-01-11 01:52:48 -05001642/*
1643# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
1644# 0 = HBA Heartbeat disabled
1645# 1 = HBA Heartbeat enabled (default)
1646# Value range is [0,1]. Default value is 1.
1647*/
1648LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05001649
James Smart83108bd2008-01-11 01:53:09 -05001650/*
1651 * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
1652 * This value can be set to values between 64 and 256. The default value is
1653 * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
1654 * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
1655 */
1656LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
1657 LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
1658
Tony Jonesee959b02008-02-22 00:13:36 +01001659struct device_attribute *lpfc_hba_attrs[] = {
1660 &dev_attr_info,
1661 &dev_attr_serialnum,
1662 &dev_attr_modeldesc,
1663 &dev_attr_modelname,
1664 &dev_attr_programtype,
1665 &dev_attr_portnum,
1666 &dev_attr_fwrev,
1667 &dev_attr_hdw,
1668 &dev_attr_option_rom_version,
1669 &dev_attr_state,
1670 &dev_attr_num_discovered_ports,
1671 &dev_attr_lpfc_drvr_version,
1672 &dev_attr_lpfc_temp_sensor,
1673 &dev_attr_lpfc_log_verbose,
1674 &dev_attr_lpfc_lun_queue_depth,
1675 &dev_attr_lpfc_hba_queue_depth,
1676 &dev_attr_lpfc_peer_port_login,
1677 &dev_attr_lpfc_nodev_tmo,
1678 &dev_attr_lpfc_devloss_tmo,
1679 &dev_attr_lpfc_fcp_class,
1680 &dev_attr_lpfc_use_adisc,
1681 &dev_attr_lpfc_ack0,
1682 &dev_attr_lpfc_topology,
1683 &dev_attr_lpfc_scan_down,
1684 &dev_attr_lpfc_link_speed,
1685 &dev_attr_lpfc_cr_delay,
1686 &dev_attr_lpfc_cr_count,
1687 &dev_attr_lpfc_multi_ring_support,
1688 &dev_attr_lpfc_multi_ring_rctl,
1689 &dev_attr_lpfc_multi_ring_type,
1690 &dev_attr_lpfc_fdmi_on,
1691 &dev_attr_lpfc_max_luns,
1692 &dev_attr_lpfc_enable_npiv,
1693 &dev_attr_nport_evt_cnt,
1694 &dev_attr_board_mode,
1695 &dev_attr_max_vpi,
1696 &dev_attr_used_vpi,
1697 &dev_attr_max_rpi,
1698 &dev_attr_used_rpi,
1699 &dev_attr_max_xri,
1700 &dev_attr_used_xri,
1701 &dev_attr_npiv_info,
1702 &dev_attr_issue_reset,
1703 &dev_attr_lpfc_poll,
1704 &dev_attr_lpfc_poll_tmo,
1705 &dev_attr_lpfc_use_msi,
1706 &dev_attr_lpfc_soft_wwnn,
1707 &dev_attr_lpfc_soft_wwpn,
1708 &dev_attr_lpfc_soft_wwn_enable,
1709 &dev_attr_lpfc_enable_hba_reset,
1710 &dev_attr_lpfc_enable_hba_heartbeat,
1711 &dev_attr_lpfc_sg_seg_cnt,
dea31012005-04-17 16:05:31 -05001712 NULL,
1713};
1714
Tony Jonesee959b02008-02-22 00:13:36 +01001715struct device_attribute *lpfc_vport_attrs[] = {
1716 &dev_attr_info,
1717 &dev_attr_state,
1718 &dev_attr_num_discovered_ports,
1719 &dev_attr_lpfc_drvr_version,
1720 &dev_attr_lpfc_log_verbose,
1721 &dev_attr_lpfc_lun_queue_depth,
1722 &dev_attr_lpfc_nodev_tmo,
1723 &dev_attr_lpfc_devloss_tmo,
1724 &dev_attr_lpfc_hba_queue_depth,
1725 &dev_attr_lpfc_peer_port_login,
1726 &dev_attr_lpfc_restrict_login,
1727 &dev_attr_lpfc_fcp_class,
1728 &dev_attr_lpfc_use_adisc,
1729 &dev_attr_lpfc_fdmi_on,
1730 &dev_attr_lpfc_max_luns,
1731 &dev_attr_nport_evt_cnt,
1732 &dev_attr_npiv_info,
1733 &dev_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04001734 NULL,
1735};
1736
dea31012005-04-17 16:05:31 -05001737static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001738sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1739 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001740{
1741 size_t buf_off;
Tony Jonesee959b02008-02-22 00:13:36 +01001742 struct device *dev = container_of(kobj, struct device, kobj);
1743 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001744 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1745 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001746
1747 if ((off + count) > FF_REG_AREA_SIZE)
1748 return -ERANGE;
1749
1750 if (count == 0) return 0;
1751
1752 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1753 return -EINVAL;
1754
James Smart2e0fef82007-06-17 19:56:36 -05001755 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001756 return -EPERM;
1757 }
1758
James Smart2e0fef82007-06-17 19:56:36 -05001759 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001760 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1761 writel(*((uint32_t *)(buf + buf_off)),
1762 phba->ctrl_regs_memmap_p + off + buf_off);
1763
James Smart2e0fef82007-06-17 19:56:36 -05001764 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001765
1766 return count;
1767}
1768
1769static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001770sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1771 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001772{
1773 size_t buf_off;
1774 uint32_t * tmp_ptr;
Tony Jonesee959b02008-02-22 00:13:36 +01001775 struct device *dev = container_of(kobj, struct device, kobj);
1776 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001777 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1778 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001779
1780 if (off > FF_REG_AREA_SIZE)
1781 return -ERANGE;
1782
1783 if ((off + count) > FF_REG_AREA_SIZE)
1784 count = FF_REG_AREA_SIZE - off;
1785
1786 if (count == 0) return 0;
1787
1788 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1789 return -EINVAL;
1790
James Smart2e0fef82007-06-17 19:56:36 -05001791 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001792
1793 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1794 tmp_ptr = (uint32_t *)(buf + buf_off);
1795 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1796 }
1797
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001799
1800 return count;
1801}
1802
1803static struct bin_attribute sysfs_ctlreg_attr = {
1804 .attr = {
1805 .name = "ctlreg",
1806 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001807 },
1808 .size = 256,
1809 .read = sysfs_ctlreg_read,
1810 .write = sysfs_ctlreg_write,
1811};
1812
1813
1814static void
James Smart2e0fef82007-06-17 19:56:36 -05001815sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001816{
1817 phba->sysfs_mbox.state = SMBOX_IDLE;
1818 phba->sysfs_mbox.offset = 0;
1819
1820 if (phba->sysfs_mbox.mbox) {
1821 mempool_free(phba->sysfs_mbox.mbox,
1822 phba->mbox_mem_pool);
1823 phba->sysfs_mbox.mbox = NULL;
1824 }
1825}
1826
1827static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001828sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1829 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001830{
Tony Jonesee959b02008-02-22 00:13:36 +01001831 struct device *dev = container_of(kobj, struct device, kobj);
1832 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001833 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1834 struct lpfc_hba *phba = vport->phba;
1835 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001836
1837 if ((count + off) > MAILBOX_CMD_SIZE)
1838 return -ERANGE;
1839
1840 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1841 return -EINVAL;
1842
1843 if (count == 0)
1844 return 0;
1845
1846 if (off == 0) {
1847 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1848 if (!mbox)
1849 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001850 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001851 }
1852
James Smart2e0fef82007-06-17 19:56:36 -05001853 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001854
1855 if (off == 0) {
1856 if (phba->sysfs_mbox.mbox)
1857 mempool_free(mbox, phba->mbox_mem_pool);
1858 else
1859 phba->sysfs_mbox.mbox = mbox;
1860 phba->sysfs_mbox.state = SMBOX_WRITING;
1861 } else {
1862 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1863 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001864 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001865 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001866 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001867 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001868 }
1869 }
1870
1871 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1872 buf, count);
1873
1874 phba->sysfs_mbox.offset = off + count;
1875
James Smart2e0fef82007-06-17 19:56:36 -05001876 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001877
1878 return count;
1879}
1880
1881static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001882sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1883 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001884{
Tony Jonesee959b02008-02-22 00:13:36 +01001885 struct device *dev = container_of(kobj, struct device, kobj);
1886 struct Scsi_Host *shost = class_to_shost(dev);
James Smart2e0fef82007-06-17 19:56:36 -05001887 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1888 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001889 int rc;
1890
James Smart1dcb58e2007-04-25 09:51:30 -04001891 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001892 return -ERANGE;
1893
James Smart1dcb58e2007-04-25 09:51:30 -04001894 if ((count + off) > MAILBOX_CMD_SIZE)
1895 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001896
1897 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1898 return -EINVAL;
1899
1900 if (off && count == 0)
1901 return 0;
1902
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001904
James Smart7af67052007-10-27 13:38:11 -04001905 if (phba->over_temp_state == HBA_OVER_TEMP) {
1906 sysfs_mbox_idle(phba);
1907 spin_unlock_irq(&phba->hbalock);
James Smart09372822008-01-11 01:52:54 -05001908 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -04001909 }
1910
dea31012005-04-17 16:05:31 -05001911 if (off == 0 &&
1912 phba->sysfs_mbox.state == SMBOX_WRITING &&
1913 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1914
1915 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1916 /* Offline only */
dea31012005-04-17 16:05:31 -05001917 case MBX_INIT_LINK:
1918 case MBX_DOWN_LINK:
1919 case MBX_CONFIG_LINK:
1920 case MBX_CONFIG_RING:
1921 case MBX_RESET_RING:
1922 case MBX_UNREG_LOGIN:
1923 case MBX_CLEAR_LA:
1924 case MBX_DUMP_CONTEXT:
1925 case MBX_RUN_DIAGS:
1926 case MBX_RESTART:
dea31012005-04-17 16:05:31 -05001927 case MBX_SET_MASK:
dea31012005-04-17 16:05:31 -05001928 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001929 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001930 printk(KERN_WARNING "mbox_read:Command 0x%x "
1931 "is illegal in on-line state\n",
1932 phba->sysfs_mbox.mbox->mb.mbxCommand);
1933 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001934 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001935 return -EPERM;
1936 }
James Smarta8adb832007-10-27 13:37:53 -04001937 case MBX_WRITE_NV:
1938 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05001939 case MBX_LOAD_SM:
1940 case MBX_READ_NV:
1941 case MBX_READ_CONFIG:
1942 case MBX_READ_RCONFIG:
1943 case MBX_READ_STATUS:
1944 case MBX_READ_XRI:
1945 case MBX_READ_REV:
1946 case MBX_READ_LNK_STAT:
1947 case MBX_DUMP_MEMORY:
1948 case MBX_DOWN_LOAD:
1949 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001950 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001951 case MBX_LOAD_AREA:
1952 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001953 case MBX_BEACON:
1954 case MBX_DEL_LD_ENTRY:
James Smart09372822008-01-11 01:52:54 -05001955 case MBX_SET_VARIABLE:
1956 case MBX_WRITE_WWN:
dea31012005-04-17 16:05:31 -05001957 break;
1958 case MBX_READ_SPARM64:
1959 case MBX_READ_LA:
1960 case MBX_READ_LA64:
1961 case MBX_REG_LOGIN:
1962 case MBX_REG_LOGIN64:
1963 case MBX_CONFIG_PORT:
1964 case MBX_RUN_BIU_DIAG:
1965 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1966 phba->sysfs_mbox.mbox->mb.mbxCommand);
1967 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001968 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001969 return -EPERM;
1970 default:
1971 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1972 phba->sysfs_mbox.mbox->mb.mbxCommand);
1973 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001975 return -EPERM;
1976 }
1977
James Smart09372822008-01-11 01:52:54 -05001978 /* If HBA encountered an error attention, allow only DUMP
James Smart1b32f6a2008-02-08 18:49:39 -05001979 * or RESTART mailbox commands until the HBA is restarted.
James Smart09372822008-01-11 01:52:54 -05001980 */
1981 if ((phba->pport->stopped) &&
James Smart1b32f6a2008-02-08 18:49:39 -05001982 (phba->sysfs_mbox.mbox->mb.mbxCommand !=
1983 MBX_DUMP_MEMORY &&
1984 phba->sysfs_mbox.mbox->mb.mbxCommand !=
James Smart97eab632008-04-07 10:16:05 -04001985 MBX_RESTART &&
1986 phba->sysfs_mbox.mbox->mb.mbxCommand !=
1987 MBX_WRITE_VPARMS)) {
James Smart09372822008-01-11 01:52:54 -05001988 sysfs_mbox_idle(phba);
1989 spin_unlock_irq(&phba->hbalock);
1990 return -EPERM;
1991 }
1992
James Smart92d7f7b2007-06-17 19:56:38 -05001993 phba->sysfs_mbox.mbox->vport = vport;
1994
James Smart58da1ff2008-04-07 10:15:56 -04001995 /* Don't allow mailbox commands to be sent when blocked
1996 * or when in the middle of discovery
1997 */
1998 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO ||
1999 vport->fc_flag & FC_NDISC_ACTIVE) {
James Smart46fa3112007-04-25 09:51:45 -04002000 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002001 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04002002 return -EAGAIN;
2003 }
2004
James Smart2e0fef82007-06-17 19:56:36 -05002005 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05002006 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
2007
James Smart2e0fef82007-06-17 19:56:36 -05002008 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002009 rc = lpfc_sli_issue_mbox (phba,
2010 phba->sysfs_mbox.mbox,
2011 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05002012 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002013
2014 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002015 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002016 rc = lpfc_sli_issue_mbox_wait (phba,
2017 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04002018 lpfc_mbox_tmo_val(phba,
2019 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05002020 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002021 }
2022
2023 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04002024 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04002025 phba->sysfs_mbox.mbox = NULL;
2026 }
dea31012005-04-17 16:05:31 -05002027 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002028 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002029 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05002030 }
2031 phba->sysfs_mbox.state = SMBOX_READING;
2032 }
2033 else if (phba->sysfs_mbox.offset != off ||
2034 phba->sysfs_mbox.state != SMBOX_READING) {
2035 printk(KERN_WARNING "mbox_read: Bad State\n");
2036 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002037 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04002038 return -EAGAIN;
dea31012005-04-17 16:05:31 -05002039 }
2040
2041 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
2042
2043 phba->sysfs_mbox.offset = off + count;
2044
James Smart1dcb58e2007-04-25 09:51:30 -04002045 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05002046 sysfs_mbox_idle(phba);
2047
James Smart2e0fef82007-06-17 19:56:36 -05002048 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002049
2050 return count;
2051}
2052
2053static struct bin_attribute sysfs_mbox_attr = {
2054 .attr = {
2055 .name = "mbox",
2056 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05002057 },
James Smart1dcb58e2007-04-25 09:51:30 -04002058 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05002059 .read = sysfs_mbox_read,
2060 .write = sysfs_mbox_write,
2061};
2062
2063int
James Smart2e0fef82007-06-17 19:56:36 -05002064lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002065{
James Smart2e0fef82007-06-17 19:56:36 -05002066 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002067 int error;
2068
Tony Jonesee959b02008-02-22 00:13:36 +01002069 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002070 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002071 if (error)
2072 goto out;
2073
Tony Jonesee959b02008-02-22 00:13:36 +01002074 error = sysfs_create_bin_file(&shost->shost_dev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05002075 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05002076 if (error)
2077 goto out_remove_ctlreg_attr;
2078
2079 return 0;
2080out_remove_ctlreg_attr:
Tony Jonesee959b02008-02-22 00:13:36 +01002081 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002082out:
2083 return error;
2084}
2085
2086void
James Smart2e0fef82007-06-17 19:56:36 -05002087lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002088{
James Smart2e0fef82007-06-17 19:56:36 -05002089 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002090
Tony Jonesee959b02008-02-22 00:13:36 +01002091 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
2092 sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05002093}
2094
2095
2096/*
2097 * Dynamic FC Host Attributes Support
2098 */
2099
2100static void
2101lpfc_get_host_port_id(struct Scsi_Host *shost)
2102{
James Smart2e0fef82007-06-17 19:56:36 -05002103 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2104
dea31012005-04-17 16:05:31 -05002105 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05002106 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002107}
2108
2109static void
2110lpfc_get_host_port_type(struct Scsi_Host *shost)
2111{
James Smart2e0fef82007-06-17 19:56:36 -05002112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2113 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002114
2115 spin_lock_irq(shost->host_lock);
2116
James Smart92d7f7b2007-06-17 19:56:38 -05002117 if (vport->port_type == LPFC_NPIV_PORT) {
2118 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2119 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002120 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05002121 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05002122 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2123 else
2124 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
2125 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002126 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05002127 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2128 else
2129 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2130 }
2131 } else
2132 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2133
2134 spin_unlock_irq(shost->host_lock);
2135}
2136
2137static void
2138lpfc_get_host_port_state(struct Scsi_Host *shost)
2139{
James Smart2e0fef82007-06-17 19:56:36 -05002140 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2141 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002142
2143 spin_lock_irq(shost->host_lock);
2144
James Smart2e0fef82007-06-17 19:56:36 -05002145 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05002146 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2147 else {
James Smart2e0fef82007-06-17 19:56:36 -05002148 switch (phba->link_state) {
2149 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05002150 case LPFC_LINK_DOWN:
2151 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2152 break;
2153 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05002154 case LPFC_CLEAR_LA:
2155 case LPFC_HBA_READY:
2156 /* Links up, beyond this port_type reports state */
2157 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2158 break;
2159 case LPFC_HBA_ERROR:
2160 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2161 break;
2162 default:
2163 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2164 break;
2165 }
2166 }
2167
2168 spin_unlock_irq(shost->host_lock);
2169}
2170
2171static void
2172lpfc_get_host_speed(struct Scsi_Host *shost)
2173{
James Smart2e0fef82007-06-17 19:56:36 -05002174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2175 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002176
2177 spin_lock_irq(shost->host_lock);
2178
James Smart2e0fef82007-06-17 19:56:36 -05002179 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002180 switch(phba->fc_linkspeed) {
2181 case LA_1GHZ_LINK:
2182 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2183 break;
2184 case LA_2GHZ_LINK:
2185 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2186 break;
2187 case LA_4GHZ_LINK:
2188 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2189 break;
James Smartb87eab32007-04-25 09:53:28 -04002190 case LA_8GHZ_LINK:
2191 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2192 break;
dea31012005-04-17 16:05:31 -05002193 default:
2194 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2195 break;
2196 }
James Smart09372822008-01-11 01:52:54 -05002197 } else
2198 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
dea31012005-04-17 16:05:31 -05002199
2200 spin_unlock_irq(shost->host_lock);
2201}
2202
2203static void
2204lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2205{
James Smart2e0fef82007-06-17 19:56:36 -05002206 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2207 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002208 u64 node_name;
dea31012005-04-17 16:05:31 -05002209
2210 spin_lock_irq(shost->host_lock);
2211
James Smart2e0fef82007-06-17 19:56:36 -05002212 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002213 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002214 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002215 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002216 else
2217 /* fabric is local port if there is no F/FL_Port */
James Smart09372822008-01-11 01:52:54 -05002218 node_name = 0;
dea31012005-04-17 16:05:31 -05002219
2220 spin_unlock_irq(shost->host_lock);
2221
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002222 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002223}
2224
dea31012005-04-17 16:05:31 -05002225static struct fc_host_statistics *
2226lpfc_get_stats(struct Scsi_Host *shost)
2227{
James Smart2e0fef82007-06-17 19:56:36 -05002228 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2229 struct lpfc_hba *phba = vport->phba;
2230 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002231 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002232 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002233 LPFC_MBOXQ_t *pmboxq;
2234 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002235 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002236 int rc = 0;
dea31012005-04-17 16:05:31 -05002237
James Smart92d7f7b2007-06-17 19:56:38 -05002238 /*
2239 * prevent udev from issuing mailbox commands until the port is
2240 * configured.
2241 */
James Smart2e0fef82007-06-17 19:56:36 -05002242 if (phba->link_state < LPFC_LINK_DOWN ||
2243 !phba->mbox_mem_pool ||
2244 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002245 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002246
2247 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002248 return NULL;
2249
dea31012005-04-17 16:05:31 -05002250 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2251 if (!pmboxq)
2252 return NULL;
2253 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2254
2255 pmb = &pmboxq->mb;
2256 pmb->mbxCommand = MBX_READ_STATUS;
2257 pmb->mbxOwner = OWN_HOST;
2258 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002259 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002260
James Smart2e0fef82007-06-17 19:56:36 -05002261 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002262 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002263 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002264 else
dea31012005-04-17 16:05:31 -05002265 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2266
2267 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002268 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002269 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002270 return NULL;
2271 }
2272
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002273 memset(hs, 0, sizeof (struct fc_host_statistics));
2274
dea31012005-04-17 16:05:31 -05002275 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2276 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2277 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2278 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2279
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002280 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002281 pmb->mbxCommand = MBX_READ_LNK_STAT;
2282 pmb->mbxOwner = OWN_HOST;
2283 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002284 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002285
James Smart2e0fef82007-06-17 19:56:36 -05002286 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002287 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002288 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002289 else
dea31012005-04-17 16:05:31 -05002290 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2291
2292 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002293 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002294 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002295 return NULL;
2296 }
2297
2298 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2299 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2300 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2301 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2302 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2303 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2304 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2305
James Smart64ba8812006-08-02 15:24:34 -04002306 hs->link_failure_count -= lso->link_failure_count;
2307 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2308 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2309 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2310 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2311 hs->invalid_crc_count -= lso->invalid_crc_count;
2312 hs->error_frames -= lso->error_frames;
2313
dea31012005-04-17 16:05:31 -05002314 if (phba->fc_topology == TOPOLOGY_LOOP) {
2315 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002316 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002317 hs->nos_count = -1;
2318 } else {
2319 hs->lip_count = -1;
2320 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002321 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002322 }
2323
2324 hs->dumped_frames = -1;
2325
James Smart64ba8812006-08-02 15:24:34 -04002326 seconds = get_seconds();
2327 if (seconds < psli->stats_start)
2328 hs->seconds_since_last_reset = seconds +
2329 ((unsigned long)-1 - psli->stats_start);
2330 else
2331 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002332
James Smart1dcb58e2007-04-25 09:51:30 -04002333 mempool_free(pmboxq, phba->mbox_mem_pool);
2334
dea31012005-04-17 16:05:31 -05002335 return hs;
2336}
2337
James Smart64ba8812006-08-02 15:24:34 -04002338static void
2339lpfc_reset_stats(struct Scsi_Host *shost)
2340{
James Smart2e0fef82007-06-17 19:56:36 -05002341 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2342 struct lpfc_hba *phba = vport->phba;
2343 struct lpfc_sli *psli = &phba->sli;
2344 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002345 LPFC_MBOXQ_t *pmboxq;
2346 MAILBOX_t *pmb;
2347 int rc = 0;
2348
James Smart2e0fef82007-06-17 19:56:36 -05002349 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002350 return;
2351
James Smart64ba8812006-08-02 15:24:34 -04002352 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2353 if (!pmboxq)
2354 return;
2355 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2356
2357 pmb = &pmboxq->mb;
2358 pmb->mbxCommand = MBX_READ_STATUS;
2359 pmb->mbxOwner = OWN_HOST;
2360 pmb->un.varWords[0] = 0x1; /* reset request */
2361 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002362 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002363
James Smart2e0fef82007-06-17 19:56:36 -05002364 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002365 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2366 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2367 else
2368 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2369
2370 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002371 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002372 mempool_free(pmboxq, phba->mbox_mem_pool);
2373 return;
2374 }
2375
2376 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2377 pmb->mbxCommand = MBX_READ_LNK_STAT;
2378 pmb->mbxOwner = OWN_HOST;
2379 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002380 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002381
James Smart2e0fef82007-06-17 19:56:36 -05002382 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002383 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2384 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2385 else
2386 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2387
2388 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002389 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002390 mempool_free( pmboxq, phba->mbox_mem_pool);
2391 return;
2392 }
2393
2394 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2395 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2396 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2397 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2398 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2399 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2400 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2401 lso->link_events = (phba->fc_eventTag >> 1);
2402
2403 psli->stats_start = get_seconds();
2404
James Smart1dcb58e2007-04-25 09:51:30 -04002405 mempool_free(pmboxq, phba->mbox_mem_pool);
2406
James Smart64ba8812006-08-02 15:24:34 -04002407 return;
2408}
dea31012005-04-17 16:05:31 -05002409
2410/*
2411 * The LPFC driver treats linkdown handling as target loss events so there
2412 * are no sysfs handlers for link_down_tmo.
2413 */
James Smart685f0bf2007-04-25 09:53:08 -04002414
2415static struct lpfc_nodelist *
2416lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002417{
James Smart2e0fef82007-06-17 19:56:36 -05002418 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2419 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002420 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002421
2422 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002423 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002424 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002425 if (NLP_CHK_NODE_ACT(ndlp) &&
2426 ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
James Smart685f0bf2007-04-25 09:53:08 -04002427 starget->id == ndlp->nlp_sid) {
2428 spin_unlock_irq(shost->host_lock);
2429 return ndlp;
dea31012005-04-17 16:05:31 -05002430 }
2431 }
2432 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002433 return NULL;
2434}
dea31012005-04-17 16:05:31 -05002435
James Smart685f0bf2007-04-25 09:53:08 -04002436static void
2437lpfc_get_starget_port_id(struct scsi_target *starget)
2438{
2439 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2440
2441 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002442}
2443
2444static void
2445lpfc_get_starget_node_name(struct scsi_target *starget)
2446{
James Smart685f0bf2007-04-25 09:53:08 -04002447 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002448
James Smart685f0bf2007-04-25 09:53:08 -04002449 fc_starget_node_name(starget) =
2450 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002451}
2452
2453static void
2454lpfc_get_starget_port_name(struct scsi_target *starget)
2455{
James Smart685f0bf2007-04-25 09:53:08 -04002456 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002457
James Smart685f0bf2007-04-25 09:53:08 -04002458 fc_starget_port_name(starget) =
2459 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002460}
2461
2462static void
dea31012005-04-17 16:05:31 -05002463lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2464{
dea31012005-04-17 16:05:31 -05002465 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002466 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002467 else
James Smartc01f3202006-08-18 17:47:08 -04002468 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002469}
2470
2471
2472#define lpfc_rport_show_function(field, format_string, sz, cast) \
2473static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01002474lpfc_show_rport_##field (struct device *dev, \
2475 struct device_attribute *attr, \
2476 char *buf) \
dea31012005-04-17 16:05:31 -05002477{ \
Tony Jonesee959b02008-02-22 00:13:36 +01002478 struct fc_rport *rport = transport_class_to_rport(dev); \
dea31012005-04-17 16:05:31 -05002479 struct lpfc_rport_data *rdata = rport->hostdata; \
2480 return snprintf(buf, sz, format_string, \
2481 (rdata->target) ? cast rdata->target->field : 0); \
2482}
2483
2484#define lpfc_rport_rd_attr(field, format_string, sz) \
2485 lpfc_rport_show_function(field, format_string, sz, ) \
2486static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2487
2488
2489struct fc_function_template lpfc_transport_functions = {
2490 /* fixed attributes the driver supports */
2491 .show_host_node_name = 1,
2492 .show_host_port_name = 1,
2493 .show_host_supported_classes = 1,
2494 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002495 .show_host_supported_speeds = 1,
2496 .show_host_maxframe_size = 1,
2497
2498 /* dynamic attributes the driver supports */
2499 .get_host_port_id = lpfc_get_host_port_id,
2500 .show_host_port_id = 1,
2501
2502 .get_host_port_type = lpfc_get_host_port_type,
2503 .show_host_port_type = 1,
2504
2505 .get_host_port_state = lpfc_get_host_port_state,
2506 .show_host_port_state = 1,
2507
2508 /* active_fc4s is shown but doesn't change (thus no get function) */
2509 .show_host_active_fc4s = 1,
2510
2511 .get_host_speed = lpfc_get_host_speed,
2512 .show_host_speed = 1,
2513
2514 .get_host_fabric_name = lpfc_get_host_fabric_name,
2515 .show_host_fabric_name = 1,
2516
2517 /*
2518 * The LPFC driver treats linkdown handling as target loss events
2519 * so there are no sysfs handlers for link_down_tmo.
2520 */
2521
2522 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002523 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002524
2525 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2526 .show_rport_maxframe_size = 1,
2527 .show_rport_supported_classes = 1,
2528
dea31012005-04-17 16:05:31 -05002529 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2530 .show_rport_dev_loss_tmo = 1,
2531
2532 .get_starget_port_id = lpfc_get_starget_port_id,
2533 .show_starget_port_id = 1,
2534
2535 .get_starget_node_name = lpfc_get_starget_node_name,
2536 .show_starget_node_name = 1,
2537
2538 .get_starget_port_name = lpfc_get_starget_port_name,
2539 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002540
2541 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002542 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2543 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002544
James Smart92d7f7b2007-06-17 19:56:38 -05002545 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2546};
2547
James Smart98c9ea52007-10-27 13:37:33 -04002548struct fc_function_template lpfc_vport_transport_functions = {
2549 /* fixed attributes the driver supports */
2550 .show_host_node_name = 1,
2551 .show_host_port_name = 1,
2552 .show_host_supported_classes = 1,
2553 .show_host_supported_fc4s = 1,
2554 .show_host_supported_speeds = 1,
2555 .show_host_maxframe_size = 1,
2556
2557 /* dynamic attributes the driver supports */
2558 .get_host_port_id = lpfc_get_host_port_id,
2559 .show_host_port_id = 1,
2560
2561 .get_host_port_type = lpfc_get_host_port_type,
2562 .show_host_port_type = 1,
2563
2564 .get_host_port_state = lpfc_get_host_port_state,
2565 .show_host_port_state = 1,
2566
2567 /* active_fc4s is shown but doesn't change (thus no get function) */
2568 .show_host_active_fc4s = 1,
2569
2570 .get_host_speed = lpfc_get_host_speed,
2571 .show_host_speed = 1,
2572
2573 .get_host_fabric_name = lpfc_get_host_fabric_name,
2574 .show_host_fabric_name = 1,
2575
2576 /*
2577 * The LPFC driver treats linkdown handling as target loss events
2578 * so there are no sysfs handlers for link_down_tmo.
2579 */
2580
2581 .get_fc_host_stats = lpfc_get_stats,
2582 .reset_fc_host_stats = lpfc_reset_stats,
2583
2584 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2585 .show_rport_maxframe_size = 1,
2586 .show_rport_supported_classes = 1,
2587
2588 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2589 .show_rport_dev_loss_tmo = 1,
2590
2591 .get_starget_port_id = lpfc_get_starget_port_id,
2592 .show_starget_port_id = 1,
2593
2594 .get_starget_node_name = lpfc_get_starget_node_name,
2595 .show_starget_node_name = 1,
2596
2597 .get_starget_port_name = lpfc_get_starget_port_name,
2598 .show_starget_port_name = 1,
2599
2600 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2601 .terminate_rport_io = lpfc_terminate_rport_io,
2602
2603 .vport_disable = lpfc_vport_disable,
2604};
2605
dea31012005-04-17 16:05:31 -05002606void
2607lpfc_get_cfgparam(struct lpfc_hba *phba)
2608{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002609 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2610 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002611 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002612 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2613 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002614 lpfc_ack0_init(phba, lpfc_ack0);
2615 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002616 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002617 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002618 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002619 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05002620 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
2621 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002622 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002623 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002624 phba->cfg_soft_wwpn = 0L;
James Smart83108bd2008-01-11 01:53:09 -05002625 lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
2626 /* Also reinitialize the host templates with new values. */
2627 lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
2628 lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
dea31012005-04-17 16:05:31 -05002629 /*
2630 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
James Smart83108bd2008-01-11 01:53:09 -05002631 * used to create the sg_dma_buf_pool must be dynamically calculated.
2632 * 2 segments are added since the IOCB needs a command and response bde.
dea31012005-04-17 16:05:31 -05002633 */
2634 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2635 sizeof(struct fcp_rsp) +
James Smart83108bd2008-01-11 01:53:09 -05002636 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002637 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002638 return;
2639}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002640
James Smart3de2a652007-08-02 11:09:59 -04002641void
2642lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2643{
James Smarte8b62012007-08-02 11:10:09 -04002644 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002645 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2646 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2647 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2648 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2649 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2650 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2651 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2652 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2653 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2654 lpfc_max_luns_init(vport, lpfc_max_luns);
2655 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04002656 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05002657 return;
2658}