blob: 09743d7b6bab2c6a1182f383185a33cf71b05193 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/ctype.h>
James Smart46fa3112007-04-25 09:51:45 -040023#include <linux/delay.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_tcq.h>
31#include <scsi/scsi_transport_fc.h>
32
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_disc.h"
36#include "lpfc_scsi.h"
37#include "lpfc.h"
38#include "lpfc_logmsg.h"
39#include "lpfc_version.h"
40#include "lpfc_compat.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
dea31012005-04-17 16:05:31 -050043
James Smartc01f3202006-08-18 17:47:08 -040044#define LPFC_DEF_DEVLOSS_TMO 30
45#define LPFC_MIN_DEVLOSS_TMO 1
46#define LPFC_MAX_DEVLOSS_TMO 255
dea31012005-04-17 16:05:31 -050047
48static void
49lpfc_jedec_to_ascii(int incr, char hdw[])
50{
51 int i, j;
52 for (i = 0; i < 8; i++) {
53 j = (incr & 0xf);
54 if (j <= 9)
55 hdw[7 - i] = 0x30 + j;
56 else
57 hdw[7 - i] = 0x61 + j - 10;
58 incr = (incr >> 4);
59 }
60 hdw[8] = 0;
61 return;
62}
63
64static ssize_t
65lpfc_drvr_version_show(struct class_device *cdev, char *buf)
66{
67 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
68}
69
70static ssize_t
dea31012005-04-17 16:05:31 -050071lpfc_info_show(struct class_device *cdev, char *buf)
72{
73 struct Scsi_Host *host = class_to_shost(cdev);
James Smart2e0fef82007-06-17 19:56:36 -050074
dea31012005-04-17 16:05:31 -050075 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
76}
77
78static ssize_t
79lpfc_serialnum_show(struct class_device *cdev, char *buf)
80{
James Smart2e0fef82007-06-17 19:56:36 -050081 struct Scsi_Host *shost = class_to_shost(cdev);
82 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
83 struct lpfc_hba *phba = vport->phba;
84
dea31012005-04-17 16:05:31 -050085 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
86}
87
88static ssize_t
89lpfc_modeldesc_show(struct class_device *cdev, char *buf)
90{
James Smart2e0fef82007-06-17 19:56:36 -050091 struct Scsi_Host *shost = class_to_shost(cdev);
92 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
93 struct lpfc_hba *phba = vport->phba;
94
dea31012005-04-17 16:05:31 -050095 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
96}
97
98static ssize_t
99lpfc_modelname_show(struct class_device *cdev, char *buf)
100{
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct Scsi_Host *shost = class_to_shost(cdev);
102 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
103 struct lpfc_hba *phba = vport->phba;
104
dea31012005-04-17 16:05:31 -0500105 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
106}
107
108static ssize_t
109lpfc_programtype_show(struct class_device *cdev, char *buf)
110{
James Smart2e0fef82007-06-17 19:56:36 -0500111 struct Scsi_Host *shost = class_to_shost(cdev);
112 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
113 struct lpfc_hba *phba = vport->phba;
114
dea31012005-04-17 16:05:31 -0500115 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
116}
117
118static ssize_t
James Smart2e0fef82007-06-17 19:56:36 -0500119lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea31012005-04-17 16:05:31 -0500120{
James Smart2e0fef82007-06-17 19:56:36 -0500121 struct Scsi_Host *shost = class_to_shost(cdev);
122 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
123 struct lpfc_hba *phba = vport->phba;
124
dea31012005-04-17 16:05:31 -0500125 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
126}
127
128static ssize_t
129lpfc_fwrev_show(struct class_device *cdev, char *buf)
130{
James Smart2e0fef82007-06-17 19:56:36 -0500131 struct Scsi_Host *shost = class_to_shost(cdev);
132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
133 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500134 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500135
dea31012005-04-17 16:05:31 -0500136 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500137 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500138}
139
140static ssize_t
141lpfc_hdw_show(struct class_device *cdev, char *buf)
142{
143 char hdw[9];
James Smart2e0fef82007-06-17 19:56:36 -0500144 struct Scsi_Host *shost = class_to_shost(cdev);
145 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
146 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500147 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500148
dea31012005-04-17 16:05:31 -0500149 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
150 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
151}
152static ssize_t
153lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct Scsi_Host *shost = class_to_shost(cdev);
156 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
157 struct lpfc_hba *phba = vport->phba;
158
dea31012005-04-17 16:05:31 -0500159 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
160}
161static ssize_t
162lpfc_state_show(struct class_device *cdev, char *buf)
163{
James Smart2e0fef82007-06-17 19:56:36 -0500164 struct Scsi_Host *shost = class_to_shost(cdev);
165 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
166 struct lpfc_hba *phba = vport->phba;
167 int len = 0;
168
169 switch (phba->link_state) {
170 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500171 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500172 case LPFC_INIT_START:
173 case LPFC_INIT_MBX_CMDS:
174 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500175 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500176 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
177 break;
178 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500179 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500180 case LPFC_HBA_READY:
James Smart2e0fef82007-06-17 19:56:36 -0500181 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
182
183 switch (vport->port_state) {
184 len += snprintf(buf + len, PAGE_SIZE-len,
185 "initializing\n");
186 break;
187 case LPFC_LOCAL_CFG_LINK:
188 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500189 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500190 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500191 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500192 case LPFC_FLOGI:
193 case LPFC_FABRIC_CFG_LINK:
194 case LPFC_NS_REG:
195 case LPFC_NS_QRY:
196 case LPFC_BUILD_DISC_LIST:
197 case LPFC_DISC_AUTH:
198 len += snprintf(buf + len, PAGE_SIZE - len,
199 "Discovery\n");
200 break;
201 case LPFC_VPORT_READY:
202 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
203 break;
204
James Smart92d7f7b2007-06-17 19:56:38 -0500205 case LPFC_VPORT_FAILED:
206 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
207 break;
208
209 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500210 len += snprintf(buf + len, PAGE_SIZE - len,
211 "Unknown\n");
212 break;
213 }
214
dea31012005-04-17 16:05:31 -0500215 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500216 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500217 len += snprintf(buf + len, PAGE_SIZE-len,
218 " Public Loop\n");
219 else
220 len += snprintf(buf + len, PAGE_SIZE-len,
221 " Private Loop\n");
222 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500223 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500224 len += snprintf(buf + len, PAGE_SIZE-len,
225 " Fabric\n");
226 else
227 len += snprintf(buf + len, PAGE_SIZE-len,
228 " Point-2-Point\n");
229 }
230 }
James Smart2e0fef82007-06-17 19:56:36 -0500231
dea31012005-04-17 16:05:31 -0500232 return len;
233}
234
235static ssize_t
236lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
237{
James Smart2e0fef82007-06-17 19:56:36 -0500238 struct Scsi_Host *shost = class_to_shost(cdev);
239 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
240
241 return snprintf(buf, PAGE_SIZE, "%d\n",
242 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500243}
244
245
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700246static int
James Smart2e0fef82007-06-17 19:56:36 -0500247lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500248{
James Smart2e0fef82007-06-17 19:56:36 -0500249 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
250 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500251 LPFC_MBOXQ_t *pmboxq;
252 int mbxstatus = MBXERR_ERROR;
253
James Smart2e0fef82007-06-17 19:56:36 -0500254 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
255 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
256 (vport->port_state != LPFC_VPORT_READY))
dea31012005-04-17 16:05:31 -0500257 return -EPERM;
258
259 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
260
261 if (!pmboxq)
262 return -ENOMEM;
263
264 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400265 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
266 pmboxq->mb.mbxOwner = OWN_HOST;
267
James Smart33ccf8d2006-08-17 11:57:58 -0400268 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500269
James Smart4db621e2006-07-06 15:49:49 -0400270 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
271 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
272 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
273 phba->cfg_link_speed);
274 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
275 phba->fc_ratov * 2);
276 }
277
James Smart5b8bd0c2007-04-25 09:52:49 -0400278 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500279 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400280 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500281
282 if (mbxstatus == MBXERR_ERROR)
283 return -EIO;
284
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700285 return 0;
dea31012005-04-17 16:05:31 -0500286}
287
James Smart40496f02006-07-06 15:50:22 -0400288static int
James Smart46fa3112007-04-25 09:51:45 -0400289lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
290{
291 struct completion online_compl;
292 struct lpfc_sli_ring *pring;
293 struct lpfc_sli *psli;
294 int status = 0;
295 int cnt = 0;
296 int i;
297
298 init_completion(&online_compl);
299 lpfc_workq_post_event(phba, &status, &online_compl,
300 LPFC_EVT_OFFLINE_PREP);
301 wait_for_completion(&online_compl);
302
303 if (status != 0)
304 return -EIO;
305
306 psli = &phba->sli;
307
308 for (i = 0; i < psli->num_rings; i++) {
309 pring = &psli->ring[i];
310 /* The linkdown event takes 30 seconds to timeout. */
311 while (pring->txcmplq_cnt) {
312 msleep(10);
313 if (cnt++ > 3000) {
314 lpfc_printf_log(phba,
315 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400316 "0466 Outstanding IO when "
317 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400318 break;
319 }
320 }
321 }
322
323 init_completion(&online_compl);
324 lpfc_workq_post_event(phba, &status, &online_compl, type);
325 wait_for_completion(&online_compl);
326
327 if (status != 0)
328 return -EIO;
329
330 return 0;
331}
332
333static int
James Smart40496f02006-07-06 15:50:22 -0400334lpfc_selective_reset(struct lpfc_hba *phba)
335{
336 struct completion online_compl;
337 int status = 0;
338
James Smart46fa3112007-04-25 09:51:45 -0400339 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400340
341 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400342 return status;
James Smart40496f02006-07-06 15:50:22 -0400343
344 init_completion(&online_compl);
345 lpfc_workq_post_event(phba, &status, &online_compl,
346 LPFC_EVT_ONLINE);
347 wait_for_completion(&online_compl);
348
349 if (status != 0)
350 return -EIO;
351
352 return 0;
353}
354
355static ssize_t
356lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
357{
James Smart2e0fef82007-06-17 19:56:36 -0500358 struct Scsi_Host *shost = class_to_shost(cdev);
359 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
360 struct lpfc_hba *phba = vport->phba;
361
James Smart40496f02006-07-06 15:50:22 -0400362 int status = -EINVAL;
363
364 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
365 status = lpfc_selective_reset(phba);
366
367 if (status == 0)
368 return strlen(buf);
369 else
370 return status;
371}
372
dea31012005-04-17 16:05:31 -0500373static ssize_t
374lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
375{
James Smart2e0fef82007-06-17 19:56:36 -0500376 struct Scsi_Host *shost = class_to_shost(cdev);
377 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
378 struct lpfc_hba *phba = vport->phba;
379
dea31012005-04-17 16:05:31 -0500380 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
381}
382
383static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500384lpfc_board_mode_show(struct class_device *cdev, char *buf)
385{
James Smart2e0fef82007-06-17 19:56:36 -0500386 struct Scsi_Host *shost = class_to_shost(cdev);
387 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
388 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500389 char * state;
390
James Smart2e0fef82007-06-17 19:56:36 -0500391 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500392 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500393 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500394 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500395 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500396 state = "offline";
397 else
398 state = "online";
399
400 return snprintf(buf, PAGE_SIZE, "%s\n", state);
401}
402
403static ssize_t
404lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct Scsi_Host *shost = class_to_shost(cdev);
407 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
408 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500409 struct completion online_compl;
410 int status=0;
411
412 init_completion(&online_compl);
413
James Smart46fa3112007-04-25 09:51:45 -0400414 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500415 lpfc_workq_post_event(phba, &status, &online_compl,
416 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400417 wait_for_completion(&online_compl);
418 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
419 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500420 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400421 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
422 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
423 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500424 else
425 return -EINVAL;
426
Jamie Wellnitz41415862006-02-28 19:25:27 -0500427 if (!status)
428 return strlen(buf);
429 else
430 return -EIO;
431}
432
James Smart92d7f7b2007-06-17 19:56:38 -0500433int
James Smart858c9f62007-06-17 19:56:39 -0500434lpfc_get_hba_info(struct lpfc_hba *phba,
435 uint32_t *mxri, uint32_t *axri,
436 uint32_t *mrpi, uint32_t *arpi,
437 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500438{
439 struct lpfc_sli *psli = &phba->sli;
440 LPFC_MBOXQ_t *pmboxq;
441 MAILBOX_t *pmb;
442 int rc = 0;
443
444 /*
445 * prevent udev from issuing mailbox commands until the port is
446 * configured.
447 */
448 if (phba->link_state < LPFC_LINK_DOWN ||
449 !phba->mbox_mem_pool ||
450 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
451 return 0;
452
453 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
454 return 0;
455
456 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
457 if (!pmboxq)
458 return 0;
459 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
460
461 pmb = &pmboxq->mb;
462 pmb->mbxCommand = MBX_READ_CONFIG;
463 pmb->mbxOwner = OWN_HOST;
464 pmboxq->context1 = NULL;
465
466 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
467 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
468 rc = MBX_NOT_FINISHED;
469 else
470 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
471
472 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500473 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500474 mempool_free(pmboxq, phba->mbox_mem_pool);
475 return 0;
476 }
477
478 if (mrpi)
479 *mrpi = pmb->un.varRdConfig.max_rpi;
480 if (arpi)
481 *arpi = pmb->un.varRdConfig.avail_rpi;
482 if (mxri)
483 *mxri = pmb->un.varRdConfig.max_xri;
484 if (axri)
485 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500486 if (mvpi)
487 *mvpi = pmb->un.varRdConfig.max_vpi;
488 if (avpi)
489 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500490
491 mempool_free(pmboxq, phba->mbox_mem_pool);
492 return 1;
493}
494
495static ssize_t
496lpfc_max_rpi_show(struct class_device *cdev, char *buf)
497{
498 struct Scsi_Host *shost = class_to_shost(cdev);
499 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
500 struct lpfc_hba *phba = vport->phba;
501 uint32_t cnt;
502
James Smart858c9f62007-06-17 19:56:39 -0500503 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500504 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
505 return snprintf(buf, PAGE_SIZE, "Unknown\n");
506}
507
508static ssize_t
509lpfc_used_rpi_show(struct class_device *cdev, char *buf)
510{
511 struct Scsi_Host *shost = class_to_shost(cdev);
512 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
513 struct lpfc_hba *phba = vport->phba;
514 uint32_t cnt, acnt;
515
James Smart858c9f62007-06-17 19:56:39 -0500516 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500517 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
518 return snprintf(buf, PAGE_SIZE, "Unknown\n");
519}
520
521static ssize_t
522lpfc_max_xri_show(struct class_device *cdev, char *buf)
523{
524 struct Scsi_Host *shost = class_to_shost(cdev);
525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
526 struct lpfc_hba *phba = vport->phba;
527 uint32_t cnt;
528
James Smart858c9f62007-06-17 19:56:39 -0500529 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500530 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
531 return snprintf(buf, PAGE_SIZE, "Unknown\n");
532}
533
534static ssize_t
535lpfc_used_xri_show(struct class_device *cdev, char *buf)
536{
537 struct Scsi_Host *shost = class_to_shost(cdev);
538 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
539 struct lpfc_hba *phba = vport->phba;
540 uint32_t cnt, acnt;
541
James Smart858c9f62007-06-17 19:56:39 -0500542 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
543 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
544 return snprintf(buf, PAGE_SIZE, "Unknown\n");
545}
546
547static ssize_t
548lpfc_max_vpi_show(struct class_device *cdev, char *buf)
549{
550 struct Scsi_Host *shost = class_to_shost(cdev);
551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
552 struct lpfc_hba *phba = vport->phba;
553 uint32_t cnt;
554
555 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
556 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
557 return snprintf(buf, PAGE_SIZE, "Unknown\n");
558}
559
560static ssize_t
561lpfc_used_vpi_show(struct class_device *cdev, char *buf)
562{
563 struct Scsi_Host *shost = class_to_shost(cdev);
564 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
565 struct lpfc_hba *phba = vport->phba;
566 uint32_t cnt, acnt;
567
568 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500569 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
570 return snprintf(buf, PAGE_SIZE, "Unknown\n");
571}
572
573static ssize_t
574lpfc_npiv_info_show(struct class_device *cdev, char *buf)
575{
576 struct Scsi_Host *shost = class_to_shost(cdev);
577 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
578 struct lpfc_hba *phba = vport->phba;
579
580 if (!(phba->max_vpi))
581 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
582 if (vport->port_type == LPFC_PHYSICAL_PORT)
583 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
584 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
585}
586
Jamie Wellnitz41415862006-02-28 19:25:27 -0500587static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500588lpfc_poll_show(struct class_device *cdev, char *buf)
589{
James Smart2e0fef82007-06-17 19:56:36 -0500590 struct Scsi_Host *shost = class_to_shost(cdev);
591 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
592 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500593
594 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
595}
596
597static ssize_t
598lpfc_poll_store(struct class_device *cdev, const char *buf,
599 size_t count)
600{
James Smart2e0fef82007-06-17 19:56:36 -0500601 struct Scsi_Host *shost = class_to_shost(cdev);
602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500604 uint32_t creg_val;
605 uint32_t old_val;
606 int val=0;
607
608 if (!isdigit(buf[0]))
609 return -EINVAL;
610
611 if (sscanf(buf, "%i", &val) != 1)
612 return -EINVAL;
613
614 if ((val & 0x3) != val)
615 return -EINVAL;
616
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500618
619 old_val = phba->cfg_poll;
620
621 if (val & ENABLE_FCP_RING_POLLING) {
622 if ((val & DISABLE_FCP_RING_INT) &&
623 !(old_val & DISABLE_FCP_RING_INT)) {
624 creg_val = readl(phba->HCregaddr);
625 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
626 writel(creg_val, phba->HCregaddr);
627 readl(phba->HCregaddr); /* flush */
628
629 lpfc_poll_start_timer(phba);
630 }
631 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500632 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500633 return -EINVAL;
634 }
635
636 if (!(val & DISABLE_FCP_RING_INT) &&
637 (old_val & DISABLE_FCP_RING_INT))
638 {
James Smart2e0fef82007-06-17 19:56:36 -0500639 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500640 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500642 creg_val = readl(phba->HCregaddr);
643 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
644 writel(creg_val, phba->HCregaddr);
645 readl(phba->HCregaddr); /* flush */
646 }
647
648 phba->cfg_poll = val;
649
James Smart2e0fef82007-06-17 19:56:36 -0500650 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500651
652 return strlen(buf);
653}
dea31012005-04-17 16:05:31 -0500654
655#define lpfc_param_show(attr) \
656static ssize_t \
657lpfc_##attr##_show(struct class_device *cdev, char *buf) \
658{ \
James Smart2e0fef82007-06-17 19:56:36 -0500659 struct Scsi_Host *shost = class_to_shost(cdev);\
660 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
661 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500662 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400663 val = phba->cfg_##attr;\
664 return snprintf(buf, PAGE_SIZE, "%d\n",\
665 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500666}
667
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400668#define lpfc_param_hex_show(attr) \
669static ssize_t \
670lpfc_##attr##_show(struct class_device *cdev, char *buf) \
671{ \
James Smart2e0fef82007-06-17 19:56:36 -0500672 struct Scsi_Host *shost = class_to_shost(cdev);\
673 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
674 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400675 int val = 0;\
676 val = phba->cfg_##attr;\
677 return snprintf(buf, PAGE_SIZE, "%#x\n",\
678 phba->cfg_##attr);\
679}
680
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400681#define lpfc_param_init(attr, default, minval, maxval) \
682static int \
683lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
684{ \
685 if (val >= minval && val <= maxval) {\
686 phba->cfg_##attr = val;\
687 return 0;\
688 }\
689 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400690 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
691 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400692 phba->cfg_##attr = default;\
693 return -EINVAL;\
694}
695
696#define lpfc_param_set(attr, default, minval, maxval) \
697static int \
698lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
699{ \
700 if (val >= minval && val <= maxval) {\
701 phba->cfg_##attr = val;\
702 return 0;\
703 }\
704 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400705 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
706 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400707 return -EINVAL;\
708}
709
710#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500711static ssize_t \
712lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
713{ \
James Smart2e0fef82007-06-17 19:56:36 -0500714 struct Scsi_Host *shost = class_to_shost(cdev);\
715 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
716 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400717 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400718 if (!isdigit(buf[0]))\
719 return -EINVAL;\
720 if (sscanf(buf, "%i", &val) != 1)\
721 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400722 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400723 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400724 else \
725 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500726}
727
James Smart3de2a652007-08-02 11:09:59 -0400728#define lpfc_vport_param_show(attr) \
729static ssize_t \
730lpfc_##attr##_show(struct class_device *cdev, char *buf) \
731{ \
732 struct Scsi_Host *shost = class_to_shost(cdev);\
733 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
734 int val = 0;\
735 val = vport->cfg_##attr;\
736 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
737}
738
739#define lpfc_vport_param_hex_show(attr) \
740static ssize_t \
741lpfc_##attr##_show(struct class_device *cdev, char *buf) \
742{ \
743 struct Scsi_Host *shost = class_to_shost(cdev);\
744 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
745 int val = 0;\
746 val = vport->cfg_##attr;\
747 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
748}
749
750#define lpfc_vport_param_init(attr, default, minval, maxval) \
751static int \
752lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
753{ \
754 if (val >= minval && val <= maxval) {\
755 vport->cfg_##attr = val;\
756 return 0;\
757 }\
James Smarte8b62012007-08-02 11:10:09 -0400758 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
759 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
760 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400761 vport->cfg_##attr = default;\
762 return -EINVAL;\
763}
764
765#define lpfc_vport_param_set(attr, default, minval, maxval) \
766static int \
767lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
768{ \
769 if (val >= minval && val <= maxval) {\
770 vport->cfg_##attr = val;\
771 return 0;\
772 }\
James Smarte8b62012007-08-02 11:10:09 -0400773 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
774 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
775 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400776 return -EINVAL;\
777}
778
779#define lpfc_vport_param_store(attr) \
780static ssize_t \
781lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
782{ \
783 struct Scsi_Host *shost = class_to_shost(cdev);\
784 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
785 int val=0;\
786 if (!isdigit(buf[0]))\
787 return -EINVAL;\
788 if (sscanf(buf, "%i", &val) != 1)\
789 return -EINVAL;\
790 if (lpfc_##attr##_set(vport, val) == 0) \
791 return strlen(buf);\
792 else \
793 return -EINVAL;\
794}
795
796
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400797#define LPFC_ATTR(name, defval, minval, maxval, desc) \
798static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500799module_param(lpfc_##name, int, 0);\
800MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400801lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500802
803#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
804static int lpfc_##name = defval;\
805module_param(lpfc_##name, int, 0);\
806MODULE_PARM_DESC(lpfc_##name, desc);\
807lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400808lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500809static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
810
811#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
812static int lpfc_##name = defval;\
813module_param(lpfc_##name, int, 0);\
814MODULE_PARM_DESC(lpfc_##name, desc);\
815lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400816lpfc_param_init(name, defval, minval, maxval)\
817lpfc_param_set(name, defval, minval, maxval)\
818lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500819static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
820 lpfc_##name##_show, lpfc_##name##_store)
821
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400822#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
823static int lpfc_##name = defval;\
824module_param(lpfc_##name, int, 0);\
825MODULE_PARM_DESC(lpfc_##name, desc);\
826lpfc_param_hex_show(name)\
827lpfc_param_init(name, defval, minval, maxval)\
828static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
829
830#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
831static int lpfc_##name = defval;\
832module_param(lpfc_##name, int, 0);\
833MODULE_PARM_DESC(lpfc_##name, desc);\
834lpfc_param_hex_show(name)\
835lpfc_param_init(name, defval, minval, maxval)\
836lpfc_param_set(name, defval, minval, maxval)\
837lpfc_param_store(name)\
838static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
839 lpfc_##name##_show, lpfc_##name##_store)
840
James Smart3de2a652007-08-02 11:09:59 -0400841#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
842static int lpfc_##name = defval;\
843module_param(lpfc_##name, int, 0);\
844MODULE_PARM_DESC(lpfc_##name, desc);\
845lpfc_vport_param_init(name, defval, minval, maxval)
846
847#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
848static int lpfc_##name = defval;\
849module_param(lpfc_##name, int, 0);\
850MODULE_PARM_DESC(lpfc_##name, desc);\
851lpfc_vport_param_show(name)\
852lpfc_vport_param_init(name, defval, minval, maxval)\
853static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
854
855#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
856static int lpfc_##name = defval;\
857module_param(lpfc_##name, int, 0);\
858MODULE_PARM_DESC(lpfc_##name, desc);\
859lpfc_vport_param_show(name)\
860lpfc_vport_param_init(name, defval, minval, maxval)\
861lpfc_vport_param_set(name, defval, minval, maxval)\
862lpfc_vport_param_store(name)\
863static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
864 lpfc_##name##_show, lpfc_##name##_store)
865
866#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
867static int lpfc_##name = defval;\
868module_param(lpfc_##name, int, 0);\
869MODULE_PARM_DESC(lpfc_##name, desc);\
870lpfc_vport_param_hex_show(name)\
871lpfc_vport_param_init(name, defval, minval, maxval)\
872static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
873
874#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
875static int lpfc_##name = defval;\
876module_param(lpfc_##name, int, 0);\
877MODULE_PARM_DESC(lpfc_##name, desc);\
878lpfc_vport_param_hex_show(name)\
879lpfc_vport_param_init(name, defval, minval, maxval)\
880lpfc_vport_param_set(name, defval, minval, maxval)\
881lpfc_vport_param_store(name)\
882static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
883 lpfc_##name##_show, lpfc_##name##_store)
884
dea31012005-04-17 16:05:31 -0500885static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
886static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
887static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
888static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
889static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500890static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500891static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
892static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
893static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
894static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
895 lpfc_option_rom_version_show, NULL);
896static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
897 lpfc_num_discovered_ports_show, NULL);
898static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
899static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
900 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500901static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
902 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400903static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500904static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
905static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
906static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
907static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
908static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
909static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
910static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
dea31012005-04-17 16:05:31 -0500911
James Smartc3f28af2006-08-18 17:47:18 -0400912
James Smarta12e07b2006-12-02 13:35:30 -0500913static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400914
915static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500916lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400917 size_t count)
918{
James Smart2e0fef82007-06-17 19:56:36 -0500919 struct Scsi_Host *shost = class_to_shost(cdev);
920 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
921 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400922 unsigned int cnt = count;
923
924 /*
925 * We're doing a simple sanity check for soft_wwpn setting.
926 * We require that the user write a specific key to enable
927 * the soft_wwpn attribute to be settable. Once the attribute
928 * is written, the enable key resets. If further updates are
929 * desired, the key must be written again to re-enable the
930 * attribute.
931 *
932 * The "key" is not secret - it is a hardcoded string shown
933 * here. The intent is to protect against the random user or
934 * application that is just writing attributes.
935 */
936
937 /* count may include a LF at end of string */
938 if (buf[cnt-1] == '\n')
939 cnt--;
940
James Smarta12e07b2006-12-02 13:35:30 -0500941 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
942 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400943 return -EINVAL;
944
James Smarta12e07b2006-12-02 13:35:30 -0500945 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400946 return count;
947}
James Smarta12e07b2006-12-02 13:35:30 -0500948static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
949 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400950
951static ssize_t
952lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
953{
James Smart2e0fef82007-06-17 19:56:36 -0500954 struct Scsi_Host *shost = class_to_shost(cdev);
955 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
956 struct lpfc_hba *phba = vport->phba;
957
Randy Dunlapafc071e2006-10-23 21:47:13 -0700958 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
959 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400960}
961
962
963static ssize_t
964lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
965{
James Smart2e0fef82007-06-17 19:56:36 -0500966 struct Scsi_Host *shost = class_to_shost(cdev);
967 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
968 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400969 struct completion online_compl;
970 int stat1=0, stat2=0;
971 unsigned int i, j, cnt=count;
972 u8 wwpn[8];
973
974 /* count may include a LF at end of string */
975 if (buf[cnt-1] == '\n')
976 cnt--;
977
James Smarta12e07b2006-12-02 13:35:30 -0500978 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400979 ((cnt == 17) && (*buf++ != 'x')) ||
980 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
981 return -EINVAL;
982
James Smarta12e07b2006-12-02 13:35:30 -0500983 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400984
985 memset(wwpn, 0, sizeof(wwpn));
986
987 /* Validate and store the new name */
988 for (i=0, j=0; i < 16; i++) {
989 if ((*buf >= 'a') && (*buf <= 'f'))
990 j = ((j << 4) | ((*buf++ -'a') + 10));
991 else if ((*buf >= 'A') && (*buf <= 'F'))
992 j = ((j << 4) | ((*buf++ -'A') + 10));
993 else if ((*buf >= '0') && (*buf <= '9'))
994 j = ((j << 4) | (*buf++ -'0'));
995 else
996 return -EINVAL;
997 if (i % 2) {
998 wwpn[i/2] = j & 0xff;
999 j = 0;
1000 }
1001 }
1002 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001003 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001004 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001005 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001006
1007 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1008 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1009
James Smart46fa3112007-04-25 09:51:45 -04001010 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001011 if (stat1)
1012 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001013 "0463 lpfc_soft_wwpn attribute set failed to "
1014 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001015 init_completion(&online_compl);
1016 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1017 wait_for_completion(&online_compl);
1018 if (stat2)
1019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001020 "0464 lpfc_soft_wwpn attribute set failed to "
1021 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001022 return (stat1 || stat2) ? -EIO : count;
1023}
1024static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1025 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1026
James Smarta12e07b2006-12-02 13:35:30 -05001027static ssize_t
1028lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1029{
James Smart51ef4c22007-08-02 11:10:31 -04001030 struct Scsi_Host *shost = class_to_shost(cdev);
1031 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001032 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1033 (unsigned long long)phba->cfg_soft_wwnn);
1034}
1035
1036
1037static ssize_t
1038lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1039{
James Smart51ef4c22007-08-02 11:10:31 -04001040 struct Scsi_Host *shost = class_to_shost(cdev);
1041 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001042 unsigned int i, j, cnt=count;
1043 u8 wwnn[8];
1044
1045 /* count may include a LF at end of string */
1046 if (buf[cnt-1] == '\n')
1047 cnt--;
1048
1049 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1050 ((cnt == 17) && (*buf++ != 'x')) ||
1051 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1052 return -EINVAL;
1053
1054 /*
1055 * Allow wwnn to be set many times, as long as the enable is set.
1056 * However, once the wwpn is set, everything locks.
1057 */
1058
1059 memset(wwnn, 0, sizeof(wwnn));
1060
1061 /* Validate and store the new name */
1062 for (i=0, j=0; i < 16; i++) {
1063 if ((*buf >= 'a') && (*buf <= 'f'))
1064 j = ((j << 4) | ((*buf++ -'a') + 10));
1065 else if ((*buf >= 'A') && (*buf <= 'F'))
1066 j = ((j << 4) | ((*buf++ -'A') + 10));
1067 else if ((*buf >= '0') && (*buf <= '9'))
1068 j = ((j << 4) | (*buf++ -'0'));
1069 else
1070 return -EINVAL;
1071 if (i % 2) {
1072 wwnn[i/2] = j & 0xff;
1073 j = 0;
1074 }
1075 }
1076 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1077
1078 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1079 "lpfc%d: soft_wwnn set. Value will take effect upon "
1080 "setting of the soft_wwpn\n", phba->brd_no);
1081
1082 return count;
1083}
1084static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1085 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1086
James Smartc3f28af2006-08-18 17:47:18 -04001087
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001088static int lpfc_poll = 0;
1089module_param(lpfc_poll, int, 0);
1090MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1091 " 0 - none,"
1092 " 1 - poll with interrupts enabled"
1093 " 3 - poll and disable FCP ring interrupts");
1094
1095static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1096 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001097
James Smart92d7f7b2007-06-17 19:56:38 -05001098int lpfc_sli_mode = 0;
1099module_param(lpfc_sli_mode, int, 0);
1100MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1101 " 0 - auto (SLI-3 if supported),"
1102 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1103 " 3 - select SLI-3");
1104
James Smart78b2d852007-08-02 11:10:21 -04001105LPFC_ATTR_R(enable_npiv, 0, 0, 1, "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05001106
dea31012005-04-17 16:05:31 -05001107/*
James Smartc01f3202006-08-18 17:47:08 -04001108# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1109# until the timer expires. Value range is [0,255]. Default value is 30.
1110*/
1111static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1112static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1113module_param(lpfc_nodev_tmo, int, 0);
1114MODULE_PARM_DESC(lpfc_nodev_tmo,
1115 "Seconds driver will hold I/O waiting "
1116 "for a device to come back");
1117static ssize_t
1118lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1119{
James Smart2e0fef82007-06-17 19:56:36 -05001120 struct Scsi_Host *shost = class_to_shost(cdev);
1121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001122 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001123 val = vport->cfg_devloss_tmo;
1124 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001125}
1126
1127static int
James Smart3de2a652007-08-02 11:09:59 -04001128lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001129{
James Smart3de2a652007-08-02 11:09:59 -04001130 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1131 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1132 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001133 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1134 "0402 Ignoring nodev_tmo module "
1135 "parameter because devloss_tmo is "
1136 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001137 return 0;
1138 }
1139
1140 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001141 vport->cfg_nodev_tmo = val;
1142 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001143 return 0;
1144 }
James Smarte8b62012007-08-02 11:10:09 -04001145 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1146 "0400 lpfc_nodev_tmo attribute cannot be set to"
1147 " %d, allowed range is [%d, %d]\n",
1148 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001149 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001150 return -EINVAL;
1151}
1152
James Smart7054a602007-04-25 09:52:34 -04001153static void
James Smart3de2a652007-08-02 11:09:59 -04001154lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001155{
James Smart858c9f62007-06-17 19:56:39 -05001156 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001157 struct lpfc_nodelist *ndlp;
1158
James Smart51ef4c22007-08-02 11:10:31 -04001159 shost = lpfc_shost_from_vport(vport);
1160 spin_lock_irq(shost->host_lock);
1161 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1162 if (ndlp->rport)
1163 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1164 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001165}
1166
James Smartc01f3202006-08-18 17:47:08 -04001167static int
James Smart3de2a652007-08-02 11:09:59 -04001168lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001169{
James Smart3de2a652007-08-02 11:09:59 -04001170 if (vport->dev_loss_tmo_changed ||
1171 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001172 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1173 "0401 Ignoring change to nodev_tmo "
1174 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001175 return 0;
1176 }
James Smartc01f3202006-08-18 17:47:08 -04001177 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001178 vport->cfg_nodev_tmo = val;
1179 vport->cfg_devloss_tmo = val;
1180 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001181 return 0;
1182 }
James Smarte8b62012007-08-02 11:10:09 -04001183 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1184 "0403 lpfc_nodev_tmo attribute cannot be set to"
1185 "%d, allowed range is [%d, %d]\n",
1186 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001187 return -EINVAL;
1188}
1189
James Smart3de2a652007-08-02 11:09:59 -04001190lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001191
1192static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1193 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1194
1195/*
1196# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1197# disappear until the timer expires. Value range is [0,255]. Default
1198# value is 30.
1199*/
1200module_param(lpfc_devloss_tmo, int, 0);
1201MODULE_PARM_DESC(lpfc_devloss_tmo,
1202 "Seconds driver will hold I/O waiting "
1203 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001204lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1205 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1206lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001207static int
James Smart3de2a652007-08-02 11:09:59 -04001208lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001209{
1210 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001211 vport->cfg_nodev_tmo = val;
1212 vport->cfg_devloss_tmo = val;
1213 vport->dev_loss_tmo_changed = 1;
1214 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001215 return 0;
1216 }
1217
James Smarte8b62012007-08-02 11:10:09 -04001218 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1219 "0404 lpfc_devloss_tmo attribute cannot be set to"
1220 " %d, allowed range is [%d, %d]\n",
1221 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001222 return -EINVAL;
1223}
1224
James Smart3de2a652007-08-02 11:09:59 -04001225lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001226static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1227 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1228
1229/*
dea31012005-04-17 16:05:31 -05001230# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1231# deluged with LOTS of information.
1232# You can set a bit mask to record specific types of verbose messages:
1233#
1234# LOG_ELS 0x1 ELS events
1235# LOG_DISCOVERY 0x2 Link discovery events
1236# LOG_MBOX 0x4 Mailbox events
1237# LOG_INIT 0x8 Initialization events
1238# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001239# LOG_FCP 0x40 FCP traffic history
1240# LOG_NODE 0x80 Node table events
1241# LOG_MISC 0x400 Miscellaneous events
1242# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001243# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001244# LOG_LIBDFC 0x2000 LIBDFC events
1245# LOG_ALL_MSG 0xffff LOG all messages
1246*/
James Smarte8b62012007-08-02 11:10:09 -04001247LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1248 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001249
1250/*
1251# lun_queue_depth: This parameter is used to limit the number of outstanding
1252# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1253*/
James Smart3de2a652007-08-02 11:09:59 -04001254LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1255 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001256
1257/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001258# hba_queue_depth: This parameter is used to limit the number of outstanding
1259# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1260# value is greater than the maximum number of exchanges supported by the HBA,
1261# then maximum number of exchanges supported by the HBA is used to determine
1262# the hba_queue_depth.
1263*/
1264LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1265 "Max number of FCP commands we can queue to a lpfc HBA");
1266
1267/*
James Smart92d7f7b2007-06-17 19:56:38 -05001268# peer_port_login: This parameter allows/prevents logins
1269# between peer ports hosted on the same physical port.
1270# When this parameter is set 0 peer ports of same physical port
1271# are not allowed to login to each other.
1272# When this parameter is set 1 peer ports of same physical port
1273# are allowed to login to each other.
1274# Default value of this parameter is 0.
1275*/
James Smart3de2a652007-08-02 11:09:59 -04001276LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1277 "Allow peer ports on the same physical port to login to each "
1278 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001279
1280/*
James Smart3de2a652007-08-02 11:09:59 -04001281# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001282# between Virtual Ports and remote initiators.
1283# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1284# other initiators and will attempt to PLOGI all remote ports.
1285# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1286# remote ports and will not attempt to PLOGI to other initiators.
1287# This parameter does not restrict to the physical port.
1288# This parameter does not restrict logins to Fabric resident remote ports.
1289# Default value of this parameter is 1.
1290*/
James Smart3de2a652007-08-02 11:09:59 -04001291static int lpfc_restrict_login = 1;
1292module_param(lpfc_restrict_login, int, 0);
1293MODULE_PARM_DESC(lpfc_restrict_login,
1294 "Restrict virtual ports login to remote initiators.");
1295lpfc_vport_param_show(restrict_login);
1296
1297static int
1298lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1299{
1300 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001301 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1302 "0449 lpfc_restrict_login attribute cannot "
1303 "be set to %d, allowed range is [0, 1]\n",
1304 val);
James Smart3de2a652007-08-02 11:09:59 -04001305 vport->cfg_restrict_login = 1;
1306 return -EINVAL;
1307 }
1308 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1309 vport->cfg_restrict_login = 0;
1310 return 0;
1311 }
1312 vport->cfg_restrict_login = val;
1313 return 0;
1314}
1315
1316static int
1317lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1318{
1319 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001320 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1321 "0450 lpfc_restrict_login attribute cannot "
1322 "be set to %d, allowed range is [0, 1]\n",
1323 val);
James Smart3de2a652007-08-02 11:09:59 -04001324 vport->cfg_restrict_login = 1;
1325 return -EINVAL;
1326 }
1327 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001328 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1329 "0468 lpfc_restrict_login must be 0 for "
1330 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001331 vport->cfg_restrict_login = 0;
1332 return 0;
1333 }
1334 vport->cfg_restrict_login = val;
1335 return 0;
1336}
1337lpfc_vport_param_store(restrict_login);
1338static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1339 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001340
1341/*
dea31012005-04-17 16:05:31 -05001342# Some disk devices have a "select ID" or "select Target" capability.
1343# From a protocol standpoint "select ID" usually means select the
1344# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1345# annex" which contains a table that maps a "select ID" (a number
1346# between 0 and 7F) to an ALPA. By default, for compatibility with
1347# older drivers, the lpfc driver scans this table from low ALPA to high
1348# ALPA.
1349#
1350# Turning on the scan-down variable (on = 1, off = 0) will
1351# cause the lpfc driver to use an inverted table, effectively
1352# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1353#
1354# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1355# and will not work across a fabric. Also this parameter will take
1356# effect only in the case when ALPA map is not available.)
1357*/
James Smart3de2a652007-08-02 11:09:59 -04001358LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1359 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001360
1361/*
dea31012005-04-17 16:05:31 -05001362# lpfc_topology: link topology for init link
1363# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001364# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001365# 0x02 = attempt point-to-point mode only
1366# 0x04 = attempt loop mode only
1367# 0x06 = attempt point-to-point mode then loop
1368# Set point-to-point mode if you want to run as an N_Port.
1369# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1370# Default value is 0.
1371*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001372LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001373
1374/*
1375# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1376# connection.
1377# 0 = auto select (default)
1378# 1 = 1 Gigabaud
1379# 2 = 2 Gigabaud
1380# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001381# 8 = 8 Gigabaud
1382# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001383*/
James Smartb87eab32007-04-25 09:53:28 -04001384LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001385
1386/*
1387# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1388# Value range is [2,3]. Default value is 3.
1389*/
James Smart3de2a652007-08-02 11:09:59 -04001390LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1391 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001392
1393/*
1394# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1395# is [0,1]. Default value is 0.
1396*/
James Smart3de2a652007-08-02 11:09:59 -04001397LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1398 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001399
1400/*
1401# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1402# range is [0,1]. Default value is 0.
1403*/
1404LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1405
1406/*
1407# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1408# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001409# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001410# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1411# cr_delay is set to 0.
1412*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001413LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001414 "interrupt response is generated");
1415
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001416LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001417 "interrupt response is generated");
1418
1419/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001420# lpfc_multi_ring_support: Determines how many rings to spread available
1421# cmd/rsp IOCB entries across.
1422# Value range is [1,2]. Default value is 1.
1423*/
1424LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1425 "SLI rings to spread IOCB entries across");
1426
1427/*
James Smarta4bc3372006-12-02 13:34:16 -05001428# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1429# identifies what rctl value to configure the additional ring for.
1430# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1431*/
1432LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1433 255, "Identifies RCTL for additional ring configuration");
1434
1435/*
1436# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1437# identifies what type value to configure the additional ring for.
1438# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1439*/
1440LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1441 255, "Identifies TYPE for additional ring configuration");
1442
1443/*
dea31012005-04-17 16:05:31 -05001444# lpfc_fdmi_on: controls FDMI support.
1445# 0 = no FDMI support
1446# 1 = support FDMI without attribute of hostname
1447# 2 = support FDMI with attribute of hostname
1448# Value range [0,2]. Default value is 0.
1449*/
James Smart3de2a652007-08-02 11:09:59 -04001450LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001451
1452/*
1453# Specifies the maximum number of ELS cmds we can have outstanding (for
1454# discovery). Value range is [1,64]. Default value = 32.
1455*/
James Smart3de2a652007-08-02 11:09:59 -04001456LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001457 "during discovery");
1458
1459/*
James Smart65a29c12006-07-06 15:50:50 -04001460# lpfc_max_luns: maximum allowed LUN.
1461# Value range is [0,65535]. Default value is 255.
1462# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001463*/
James Smart3de2a652007-08-02 11:09:59 -04001464LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001465
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001466/*
1467# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1468# Value range is [1,255], default value is 10.
1469*/
1470LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1471 "Milliseconds driver will wait between polling FCP ring");
1472
James Smart4ff43242006-12-02 13:34:56 -05001473/*
1474# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1475# support this feature
1476# 0 = MSI disabled (default)
1477# 1 = MSI enabled
1478# Value range is [0,1]. Default value is 0.
1479*/
1480LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1481
James Smartc3f28af2006-08-18 17:47:18 -04001482
James Smart92d7f7b2007-06-17 19:56:38 -05001483
James Smart2e0fef82007-06-17 19:56:36 -05001484struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001485 &class_device_attr_info,
1486 &class_device_attr_serialnum,
1487 &class_device_attr_modeldesc,
1488 &class_device_attr_modelname,
1489 &class_device_attr_programtype,
1490 &class_device_attr_portnum,
1491 &class_device_attr_fwrev,
1492 &class_device_attr_hdw,
1493 &class_device_attr_option_rom_version,
1494 &class_device_attr_state,
1495 &class_device_attr_num_discovered_ports,
1496 &class_device_attr_lpfc_drvr_version,
1497 &class_device_attr_lpfc_log_verbose,
1498 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001499 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001500 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001501 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001502 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001503 &class_device_attr_lpfc_fcp_class,
1504 &class_device_attr_lpfc_use_adisc,
1505 &class_device_attr_lpfc_ack0,
1506 &class_device_attr_lpfc_topology,
1507 &class_device_attr_lpfc_scan_down,
1508 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001509 &class_device_attr_lpfc_cr_delay,
1510 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001511 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001512 &class_device_attr_lpfc_multi_ring_rctl,
1513 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001514 &class_device_attr_lpfc_fdmi_on,
1515 &class_device_attr_lpfc_max_luns,
James Smart78b2d852007-08-02 11:10:21 -04001516 &class_device_attr_lpfc_enable_npiv,
dea31012005-04-17 16:05:31 -05001517 &class_device_attr_nport_evt_cnt,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001518 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001519 &class_device_attr_max_vpi,
1520 &class_device_attr_used_vpi,
1521 &class_device_attr_max_rpi,
1522 &class_device_attr_used_rpi,
1523 &class_device_attr_max_xri,
1524 &class_device_attr_used_xri,
1525 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001526 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001527 &class_device_attr_lpfc_poll,
1528 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001529 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001530 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001531 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001532 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001533 NULL,
1534};
1535
James Smart3de2a652007-08-02 11:09:59 -04001536struct class_device_attribute *lpfc_vport_attrs[] = {
1537 &class_device_attr_info,
1538 &class_device_attr_state,
1539 &class_device_attr_num_discovered_ports,
1540 &class_device_attr_lpfc_drvr_version,
1541
1542 &class_device_attr_lpfc_log_verbose,
1543 &class_device_attr_lpfc_lun_queue_depth,
1544 &class_device_attr_lpfc_nodev_tmo,
1545 &class_device_attr_lpfc_devloss_tmo,
1546 &class_device_attr_lpfc_hba_queue_depth,
1547 &class_device_attr_lpfc_peer_port_login,
1548 &class_device_attr_lpfc_restrict_login,
1549 &class_device_attr_lpfc_fcp_class,
1550 &class_device_attr_lpfc_use_adisc,
1551 &class_device_attr_lpfc_fdmi_on,
1552 &class_device_attr_lpfc_max_luns,
1553 &class_device_attr_nport_evt_cnt,
James Smart3de2a652007-08-02 11:09:59 -04001554 &class_device_attr_npiv_info,
1555 NULL,
1556};
1557
dea31012005-04-17 16:05:31 -05001558static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001559sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1560 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001561{
1562 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001563 struct class_device *cdev = container_of(kobj, struct class_device,
1564 kobj);
1565 struct Scsi_Host *shost = class_to_shost(cdev);
1566 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1567 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001568
1569 if ((off + count) > FF_REG_AREA_SIZE)
1570 return -ERANGE;
1571
1572 if (count == 0) return 0;
1573
1574 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1575 return -EINVAL;
1576
James Smart2e0fef82007-06-17 19:56:36 -05001577 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001578 return -EPERM;
1579 }
1580
James Smart2e0fef82007-06-17 19:56:36 -05001581 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001582 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1583 writel(*((uint32_t *)(buf + buf_off)),
1584 phba->ctrl_regs_memmap_p + off + buf_off);
1585
James Smart2e0fef82007-06-17 19:56:36 -05001586 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001587
1588 return count;
1589}
1590
1591static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001592sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1593 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001594{
1595 size_t buf_off;
1596 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001597 struct class_device *cdev = container_of(kobj, struct class_device,
1598 kobj);
1599 struct Scsi_Host *shost = class_to_shost(cdev);
1600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1601 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001602
1603 if (off > FF_REG_AREA_SIZE)
1604 return -ERANGE;
1605
1606 if ((off + count) > FF_REG_AREA_SIZE)
1607 count = FF_REG_AREA_SIZE - off;
1608
1609 if (count == 0) return 0;
1610
1611 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1612 return -EINVAL;
1613
James Smart2e0fef82007-06-17 19:56:36 -05001614 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001615
1616 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1617 tmp_ptr = (uint32_t *)(buf + buf_off);
1618 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1619 }
1620
James Smart2e0fef82007-06-17 19:56:36 -05001621 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001622
1623 return count;
1624}
1625
1626static struct bin_attribute sysfs_ctlreg_attr = {
1627 .attr = {
1628 .name = "ctlreg",
1629 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001630 },
1631 .size = 256,
1632 .read = sysfs_ctlreg_read,
1633 .write = sysfs_ctlreg_write,
1634};
1635
1636
1637static void
James Smart2e0fef82007-06-17 19:56:36 -05001638sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001639{
1640 phba->sysfs_mbox.state = SMBOX_IDLE;
1641 phba->sysfs_mbox.offset = 0;
1642
1643 if (phba->sysfs_mbox.mbox) {
1644 mempool_free(phba->sysfs_mbox.mbox,
1645 phba->mbox_mem_pool);
1646 phba->sysfs_mbox.mbox = NULL;
1647 }
1648}
1649
1650static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001651sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1652 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001653{
James Smart2e0fef82007-06-17 19:56:36 -05001654 struct class_device *cdev = container_of(kobj, struct class_device,
1655 kobj);
1656 struct Scsi_Host *shost = class_to_shost(cdev);
1657 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1658 struct lpfc_hba *phba = vport->phba;
1659 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001660
1661 if ((count + off) > MAILBOX_CMD_SIZE)
1662 return -ERANGE;
1663
1664 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1665 return -EINVAL;
1666
1667 if (count == 0)
1668 return 0;
1669
1670 if (off == 0) {
1671 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1672 if (!mbox)
1673 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001674 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001675 }
1676
James Smart2e0fef82007-06-17 19:56:36 -05001677 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001678
1679 if (off == 0) {
1680 if (phba->sysfs_mbox.mbox)
1681 mempool_free(mbox, phba->mbox_mem_pool);
1682 else
1683 phba->sysfs_mbox.mbox = mbox;
1684 phba->sysfs_mbox.state = SMBOX_WRITING;
1685 } else {
1686 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1687 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001688 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001689 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001690 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001691 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001692 }
1693 }
1694
1695 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1696 buf, count);
1697
1698 phba->sysfs_mbox.offset = off + count;
1699
James Smart2e0fef82007-06-17 19:56:36 -05001700 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001701
1702 return count;
1703}
1704
1705static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001706sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1707 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001708{
James Smart2e0fef82007-06-17 19:56:36 -05001709 struct class_device *cdev = container_of(kobj, struct class_device,
1710 kobj);
1711 struct Scsi_Host *shost = class_to_shost(cdev);
1712 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1713 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001714 int rc;
1715
James Smart1dcb58e2007-04-25 09:51:30 -04001716 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001717 return -ERANGE;
1718
James Smart1dcb58e2007-04-25 09:51:30 -04001719 if ((count + off) > MAILBOX_CMD_SIZE)
1720 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001721
1722 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1723 return -EINVAL;
1724
1725 if (off && count == 0)
1726 return 0;
1727
James Smart2e0fef82007-06-17 19:56:36 -05001728 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001729
1730 if (off == 0 &&
1731 phba->sysfs_mbox.state == SMBOX_WRITING &&
1732 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1733
1734 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1735 /* Offline only */
1736 case MBX_WRITE_NV:
1737 case MBX_INIT_LINK:
1738 case MBX_DOWN_LINK:
1739 case MBX_CONFIG_LINK:
1740 case MBX_CONFIG_RING:
1741 case MBX_RESET_RING:
1742 case MBX_UNREG_LOGIN:
1743 case MBX_CLEAR_LA:
1744 case MBX_DUMP_CONTEXT:
1745 case MBX_RUN_DIAGS:
1746 case MBX_RESTART:
1747 case MBX_FLASH_WR_ULA:
1748 case MBX_SET_MASK:
1749 case MBX_SET_SLIM:
1750 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001751 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001752 printk(KERN_WARNING "mbox_read:Command 0x%x "
1753 "is illegal in on-line state\n",
1754 phba->sysfs_mbox.mbox->mb.mbxCommand);
1755 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001756 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001757 return -EPERM;
1758 }
1759 case MBX_LOAD_SM:
1760 case MBX_READ_NV:
1761 case MBX_READ_CONFIG:
1762 case MBX_READ_RCONFIG:
1763 case MBX_READ_STATUS:
1764 case MBX_READ_XRI:
1765 case MBX_READ_REV:
1766 case MBX_READ_LNK_STAT:
1767 case MBX_DUMP_MEMORY:
1768 case MBX_DOWN_LOAD:
1769 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001770 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001771 case MBX_LOAD_AREA:
1772 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001773 case MBX_BEACON:
1774 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001775 break;
1776 case MBX_READ_SPARM64:
1777 case MBX_READ_LA:
1778 case MBX_READ_LA64:
1779 case MBX_REG_LOGIN:
1780 case MBX_REG_LOGIN64:
1781 case MBX_CONFIG_PORT:
1782 case MBX_RUN_BIU_DIAG:
1783 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1784 phba->sysfs_mbox.mbox->mb.mbxCommand);
1785 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001786 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001787 return -EPERM;
1788 default:
1789 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1790 phba->sysfs_mbox.mbox->mb.mbxCommand);
1791 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001792 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001793 return -EPERM;
1794 }
1795
James Smart92d7f7b2007-06-17 19:56:38 -05001796 phba->sysfs_mbox.mbox->vport = vport;
1797
James Smart2e0fef82007-06-17 19:56:36 -05001798 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001799 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001800 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001801 return -EAGAIN;
1802 }
1803
James Smart2e0fef82007-06-17 19:56:36 -05001804 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001805 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1806
James Smart2e0fef82007-06-17 19:56:36 -05001807 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001808 rc = lpfc_sli_issue_mbox (phba,
1809 phba->sysfs_mbox.mbox,
1810 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001811 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001812
1813 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001814 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001815 rc = lpfc_sli_issue_mbox_wait (phba,
1816 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001817 lpfc_mbox_tmo_val(phba,
1818 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001820 }
1821
1822 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001823 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001824 phba->sysfs_mbox.mbox = NULL;
1825 }
dea31012005-04-17 16:05:31 -05001826 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001827 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001828 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001829 }
1830 phba->sysfs_mbox.state = SMBOX_READING;
1831 }
1832 else if (phba->sysfs_mbox.offset != off ||
1833 phba->sysfs_mbox.state != SMBOX_READING) {
1834 printk(KERN_WARNING "mbox_read: Bad State\n");
1835 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001836 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001837 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001838 }
1839
1840 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1841
1842 phba->sysfs_mbox.offset = off + count;
1843
James Smart1dcb58e2007-04-25 09:51:30 -04001844 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001845 sysfs_mbox_idle(phba);
1846
James Smart2e0fef82007-06-17 19:56:36 -05001847 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001848
1849 return count;
1850}
1851
1852static struct bin_attribute sysfs_mbox_attr = {
1853 .attr = {
1854 .name = "mbox",
1855 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001856 },
James Smart1dcb58e2007-04-25 09:51:30 -04001857 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001858 .read = sysfs_mbox_read,
1859 .write = sysfs_mbox_write,
1860};
1861
1862int
James Smart2e0fef82007-06-17 19:56:36 -05001863lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001864{
James Smart2e0fef82007-06-17 19:56:36 -05001865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001866 int error;
1867
James Smart2e0fef82007-06-17 19:56:36 -05001868 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001869 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001870 if (error)
1871 goto out;
1872
James Smart2e0fef82007-06-17 19:56:36 -05001873 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001874 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001875 if (error)
1876 goto out_remove_ctlreg_attr;
1877
1878 return 0;
1879out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001880 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001881out:
1882 return error;
1883}
1884
1885void
James Smart2e0fef82007-06-17 19:56:36 -05001886lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001887{
James Smart2e0fef82007-06-17 19:56:36 -05001888 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001889
James Smart2e0fef82007-06-17 19:56:36 -05001890 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1891 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001892}
1893
1894
1895/*
1896 * Dynamic FC Host Attributes Support
1897 */
1898
1899static void
1900lpfc_get_host_port_id(struct Scsi_Host *shost)
1901{
James Smart2e0fef82007-06-17 19:56:36 -05001902 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1903
dea31012005-04-17 16:05:31 -05001904 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001905 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001906}
1907
1908static void
1909lpfc_get_host_port_type(struct Scsi_Host *shost)
1910{
James Smart2e0fef82007-06-17 19:56:36 -05001911 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1912 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001913
1914 spin_lock_irq(shost->host_lock);
1915
James Smart92d7f7b2007-06-17 19:56:38 -05001916 if (vport->port_type == LPFC_NPIV_PORT) {
1917 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1918 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001919 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001920 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001921 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1922 else
1923 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1924 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001925 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001926 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1927 else
1928 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1929 }
1930 } else
1931 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1932
1933 spin_unlock_irq(shost->host_lock);
1934}
1935
1936static void
1937lpfc_get_host_port_state(struct Scsi_Host *shost)
1938{
James Smart2e0fef82007-06-17 19:56:36 -05001939 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1940 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001941
1942 spin_lock_irq(shost->host_lock);
1943
James Smart2e0fef82007-06-17 19:56:36 -05001944 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05001945 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1946 else {
James Smart2e0fef82007-06-17 19:56:36 -05001947 switch (phba->link_state) {
1948 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05001949 case LPFC_LINK_DOWN:
1950 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1951 break;
1952 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05001953 case LPFC_CLEAR_LA:
1954 case LPFC_HBA_READY:
1955 /* Links up, beyond this port_type reports state */
1956 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1957 break;
1958 case LPFC_HBA_ERROR:
1959 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1960 break;
1961 default:
1962 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1963 break;
1964 }
1965 }
1966
1967 spin_unlock_irq(shost->host_lock);
1968}
1969
1970static void
1971lpfc_get_host_speed(struct Scsi_Host *shost)
1972{
James Smart2e0fef82007-06-17 19:56:36 -05001973 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1974 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001975
1976 spin_lock_irq(shost->host_lock);
1977
James Smart2e0fef82007-06-17 19:56:36 -05001978 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001979 switch(phba->fc_linkspeed) {
1980 case LA_1GHZ_LINK:
1981 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1982 break;
1983 case LA_2GHZ_LINK:
1984 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1985 break;
1986 case LA_4GHZ_LINK:
1987 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1988 break;
James Smartb87eab32007-04-25 09:53:28 -04001989 case LA_8GHZ_LINK:
1990 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1991 break;
dea31012005-04-17 16:05:31 -05001992 default:
1993 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1994 break;
1995 }
1996 }
1997
1998 spin_unlock_irq(shost->host_lock);
1999}
2000
2001static void
2002lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2003{
James Smart2e0fef82007-06-17 19:56:36 -05002004 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2005 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002006 u64 node_name;
dea31012005-04-17 16:05:31 -05002007
2008 spin_lock_irq(shost->host_lock);
2009
James Smart2e0fef82007-06-17 19:56:36 -05002010 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002011 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002012 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002013 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002014 else
2015 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05002016 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05002017
2018 spin_unlock_irq(shost->host_lock);
2019
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002020 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002021}
2022
dea31012005-04-17 16:05:31 -05002023static struct fc_host_statistics *
2024lpfc_get_stats(struct Scsi_Host *shost)
2025{
James Smart2e0fef82007-06-17 19:56:36 -05002026 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2027 struct lpfc_hba *phba = vport->phba;
2028 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002029 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002030 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002031 LPFC_MBOXQ_t *pmboxq;
2032 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002033 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002034 int rc = 0;
dea31012005-04-17 16:05:31 -05002035
James Smart92d7f7b2007-06-17 19:56:38 -05002036 /*
2037 * prevent udev from issuing mailbox commands until the port is
2038 * configured.
2039 */
James Smart2e0fef82007-06-17 19:56:36 -05002040 if (phba->link_state < LPFC_LINK_DOWN ||
2041 !phba->mbox_mem_pool ||
2042 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002043 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002044
2045 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002046 return NULL;
2047
dea31012005-04-17 16:05:31 -05002048 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2049 if (!pmboxq)
2050 return NULL;
2051 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2052
2053 pmb = &pmboxq->mb;
2054 pmb->mbxCommand = MBX_READ_STATUS;
2055 pmb->mbxOwner = OWN_HOST;
2056 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002057 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002058
James Smart2e0fef82007-06-17 19:56:36 -05002059 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002060 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002061 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002062 else
dea31012005-04-17 16:05:31 -05002063 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2064
2065 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002066 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002067 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002068 return NULL;
2069 }
2070
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002071 memset(hs, 0, sizeof (struct fc_host_statistics));
2072
dea31012005-04-17 16:05:31 -05002073 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2074 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2075 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2076 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2077
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002078 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002079 pmb->mbxCommand = MBX_READ_LNK_STAT;
2080 pmb->mbxOwner = OWN_HOST;
2081 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002082 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002083
James Smart2e0fef82007-06-17 19:56:36 -05002084 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002085 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002086 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002087 else
dea31012005-04-17 16:05:31 -05002088 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2089
2090 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002091 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002092 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002093 return NULL;
2094 }
2095
2096 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2097 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2098 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2099 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2100 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2101 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2102 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2103
James Smart64ba8812006-08-02 15:24:34 -04002104 hs->link_failure_count -= lso->link_failure_count;
2105 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2106 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2107 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2108 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2109 hs->invalid_crc_count -= lso->invalid_crc_count;
2110 hs->error_frames -= lso->error_frames;
2111
dea31012005-04-17 16:05:31 -05002112 if (phba->fc_topology == TOPOLOGY_LOOP) {
2113 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002114 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002115 hs->nos_count = -1;
2116 } else {
2117 hs->lip_count = -1;
2118 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002119 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002120 }
2121
2122 hs->dumped_frames = -1;
2123
James Smart64ba8812006-08-02 15:24:34 -04002124 seconds = get_seconds();
2125 if (seconds < psli->stats_start)
2126 hs->seconds_since_last_reset = seconds +
2127 ((unsigned long)-1 - psli->stats_start);
2128 else
2129 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002130
James Smart1dcb58e2007-04-25 09:51:30 -04002131 mempool_free(pmboxq, phba->mbox_mem_pool);
2132
dea31012005-04-17 16:05:31 -05002133 return hs;
2134}
2135
James Smart64ba8812006-08-02 15:24:34 -04002136static void
2137lpfc_reset_stats(struct Scsi_Host *shost)
2138{
James Smart2e0fef82007-06-17 19:56:36 -05002139 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2140 struct lpfc_hba *phba = vport->phba;
2141 struct lpfc_sli *psli = &phba->sli;
2142 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002143 LPFC_MBOXQ_t *pmboxq;
2144 MAILBOX_t *pmb;
2145 int rc = 0;
2146
James Smart2e0fef82007-06-17 19:56:36 -05002147 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002148 return;
2149
James Smart64ba8812006-08-02 15:24:34 -04002150 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2151 if (!pmboxq)
2152 return;
2153 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2154
2155 pmb = &pmboxq->mb;
2156 pmb->mbxCommand = MBX_READ_STATUS;
2157 pmb->mbxOwner = OWN_HOST;
2158 pmb->un.varWords[0] = 0x1; /* reset request */
2159 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002160 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002161
James Smart2e0fef82007-06-17 19:56:36 -05002162 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002163 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2164 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2165 else
2166 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2167
2168 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002169 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002170 mempool_free(pmboxq, phba->mbox_mem_pool);
2171 return;
2172 }
2173
2174 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2175 pmb->mbxCommand = MBX_READ_LNK_STAT;
2176 pmb->mbxOwner = OWN_HOST;
2177 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002178 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002179
James Smart2e0fef82007-06-17 19:56:36 -05002180 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002181 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2182 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2183 else
2184 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2185
2186 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002187 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002188 mempool_free( pmboxq, phba->mbox_mem_pool);
2189 return;
2190 }
2191
2192 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2193 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2194 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2195 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2196 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2197 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2198 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2199 lso->link_events = (phba->fc_eventTag >> 1);
2200
2201 psli->stats_start = get_seconds();
2202
James Smart1dcb58e2007-04-25 09:51:30 -04002203 mempool_free(pmboxq, phba->mbox_mem_pool);
2204
James Smart64ba8812006-08-02 15:24:34 -04002205 return;
2206}
dea31012005-04-17 16:05:31 -05002207
2208/*
2209 * The LPFC driver treats linkdown handling as target loss events so there
2210 * are no sysfs handlers for link_down_tmo.
2211 */
James Smart685f0bf2007-04-25 09:53:08 -04002212
2213static struct lpfc_nodelist *
2214lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002215{
James Smart2e0fef82007-06-17 19:56:36 -05002216 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2217 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002218 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002219
2220 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002221 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002222 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002223 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2224 starget->id == ndlp->nlp_sid) {
2225 spin_unlock_irq(shost->host_lock);
2226 return ndlp;
dea31012005-04-17 16:05:31 -05002227 }
2228 }
2229 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002230 return NULL;
2231}
dea31012005-04-17 16:05:31 -05002232
James Smart685f0bf2007-04-25 09:53:08 -04002233static void
2234lpfc_get_starget_port_id(struct scsi_target *starget)
2235{
2236 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2237
2238 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002239}
2240
2241static void
2242lpfc_get_starget_node_name(struct scsi_target *starget)
2243{
James Smart685f0bf2007-04-25 09:53:08 -04002244 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002245
James Smart685f0bf2007-04-25 09:53:08 -04002246 fc_starget_node_name(starget) =
2247 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002248}
2249
2250static void
2251lpfc_get_starget_port_name(struct scsi_target *starget)
2252{
James Smart685f0bf2007-04-25 09:53:08 -04002253 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002254
James Smart685f0bf2007-04-25 09:53:08 -04002255 fc_starget_port_name(starget) =
2256 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002257}
2258
2259static void
dea31012005-04-17 16:05:31 -05002260lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2261{
dea31012005-04-17 16:05:31 -05002262 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002263 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002264 else
James Smartc01f3202006-08-18 17:47:08 -04002265 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002266}
2267
2268
2269#define lpfc_rport_show_function(field, format_string, sz, cast) \
2270static ssize_t \
2271lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2272{ \
2273 struct fc_rport *rport = transport_class_to_rport(cdev); \
2274 struct lpfc_rport_data *rdata = rport->hostdata; \
2275 return snprintf(buf, sz, format_string, \
2276 (rdata->target) ? cast rdata->target->field : 0); \
2277}
2278
2279#define lpfc_rport_rd_attr(field, format_string, sz) \
2280 lpfc_rport_show_function(field, format_string, sz, ) \
2281static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2282
2283
2284struct fc_function_template lpfc_transport_functions = {
2285 /* fixed attributes the driver supports */
2286 .show_host_node_name = 1,
2287 .show_host_port_name = 1,
2288 .show_host_supported_classes = 1,
2289 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002290 .show_host_supported_speeds = 1,
2291 .show_host_maxframe_size = 1,
2292
2293 /* dynamic attributes the driver supports */
2294 .get_host_port_id = lpfc_get_host_port_id,
2295 .show_host_port_id = 1,
2296
2297 .get_host_port_type = lpfc_get_host_port_type,
2298 .show_host_port_type = 1,
2299
2300 .get_host_port_state = lpfc_get_host_port_state,
2301 .show_host_port_state = 1,
2302
2303 /* active_fc4s is shown but doesn't change (thus no get function) */
2304 .show_host_active_fc4s = 1,
2305
2306 .get_host_speed = lpfc_get_host_speed,
2307 .show_host_speed = 1,
2308
2309 .get_host_fabric_name = lpfc_get_host_fabric_name,
2310 .show_host_fabric_name = 1,
2311
2312 /*
2313 * The LPFC driver treats linkdown handling as target loss events
2314 * so there are no sysfs handlers for link_down_tmo.
2315 */
2316
2317 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002318 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002319
2320 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2321 .show_rport_maxframe_size = 1,
2322 .show_rport_supported_classes = 1,
2323
dea31012005-04-17 16:05:31 -05002324 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2325 .show_rport_dev_loss_tmo = 1,
2326
2327 .get_starget_port_id = lpfc_get_starget_port_id,
2328 .show_starget_port_id = 1,
2329
2330 .get_starget_node_name = lpfc_get_starget_node_name,
2331 .show_starget_node_name = 1,
2332
2333 .get_starget_port_name = lpfc_get_starget_port_name,
2334 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002335
2336 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002337 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2338 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002339
2340 .vport_create = lpfc_vport_create,
2341 .vport_delete = lpfc_vport_delete,
2342 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2343};
2344
2345struct fc_function_template lpfc_vport_transport_functions = {
2346 /* fixed attributes the driver supports */
2347 .show_host_node_name = 1,
2348 .show_host_port_name = 1,
2349 .show_host_supported_classes = 1,
2350 .show_host_supported_fc4s = 1,
2351 .show_host_supported_speeds = 1,
2352 .show_host_maxframe_size = 1,
2353
2354 /* dynamic attributes the driver supports */
2355 .get_host_port_id = lpfc_get_host_port_id,
2356 .show_host_port_id = 1,
2357
2358 .get_host_port_type = lpfc_get_host_port_type,
2359 .show_host_port_type = 1,
2360
2361 .get_host_port_state = lpfc_get_host_port_state,
2362 .show_host_port_state = 1,
2363
2364 /* active_fc4s is shown but doesn't change (thus no get function) */
2365 .show_host_active_fc4s = 1,
2366
2367 .get_host_speed = lpfc_get_host_speed,
2368 .show_host_speed = 1,
2369
2370 .get_host_fabric_name = lpfc_get_host_fabric_name,
2371 .show_host_fabric_name = 1,
dea31012005-04-17 16:05:31 -05002372
2373 /*
2374 * The LPFC driver treats linkdown handling as target loss events
2375 * so there are no sysfs handlers for link_down_tmo.
2376 */
2377
2378 .get_fc_host_stats = lpfc_get_stats,
2379 .reset_fc_host_stats = lpfc_reset_stats,
2380
2381 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2382 .show_rport_maxframe_size = 1,
2383 .show_rport_supported_classes = 1,
2384
2385 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2386 .show_rport_dev_loss_tmo = 1,
2387
2388 .get_starget_port_id = lpfc_get_starget_port_id,
2389 .show_starget_port_id = 1,
2390
2391 .get_starget_node_name = lpfc_get_starget_node_name,
2392 .show_starget_node_name = 1,
2393
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002394 .get_starget_port_name = lpfc_get_starget_port_name,
2395 .show_starget_port_name = 1,
2396
dea31012005-04-17 16:05:31 -05002397 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2398 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002399
2400 .vport_disable = lpfc_vport_disable,
dea31012005-04-17 16:05:31 -05002401};
2402
2403void
2404lpfc_get_cfgparam(struct lpfc_hba *phba)
2405{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002406 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2407 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002408 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002409 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2410 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002411 lpfc_ack0_init(phba, lpfc_ack0);
2412 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002413 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002414 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002415 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002416 lpfc_use_msi_init(phba, lpfc_use_msi);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002417 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002418 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002419 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002420 /*
2421 * The total number of segments is the configuration value plus 2
2422 * since the IOCB need a command and response bde.
2423 */
2424 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
dea31012005-04-17 16:05:31 -05002425 /*
2426 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2427 * used to create the sg_dma_buf_pool must be dynamically calculated
2428 */
2429 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2430 sizeof(struct fcp_rsp) +
2431 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002432 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002433 return;
2434}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002435
James Smart3de2a652007-08-02 11:09:59 -04002436void
2437lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2438{
James Smarte8b62012007-08-02 11:10:09 -04002439 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002440 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2441 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2442 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2443 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2444 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2445 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2446 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2447 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2448 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2449 lpfc_max_luns_init(vport, lpfc_max_luns);
2450 lpfc_scan_down_init(vport, lpfc_scan_down);
dea31012005-04-17 16:05:31 -05002451 return;
2452}