blob: 4e9e890449a36f4f5cd5c738d170bc81509f06d0 [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
James Smart57127f12007-10-27 13:37:05 -040089lpfc_temp_sensor_show(struct class_device *cdev, char *buf)
90{
91 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 return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
95}
96
97static ssize_t
dea31012005-04-17 16:05:31 -050098lpfc_modeldesc_show(struct class_device *cdev, char *buf)
99{
James Smart2e0fef82007-06-17 19:56:36 -0500100 struct Scsi_Host *shost = class_to_shost(cdev);
101 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
102 struct lpfc_hba *phba = vport->phba;
103
dea31012005-04-17 16:05:31 -0500104 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
105}
106
107static ssize_t
108lpfc_modelname_show(struct class_device *cdev, char *buf)
109{
James Smart2e0fef82007-06-17 19:56:36 -0500110 struct Scsi_Host *shost = class_to_shost(cdev);
111 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
112 struct lpfc_hba *phba = vport->phba;
113
dea31012005-04-17 16:05:31 -0500114 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
115}
116
117static ssize_t
118lpfc_programtype_show(struct class_device *cdev, char *buf)
119{
James Smart2e0fef82007-06-17 19:56:36 -0500120 struct Scsi_Host *shost = class_to_shost(cdev);
121 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
122 struct lpfc_hba *phba = vport->phba;
123
dea31012005-04-17 16:05:31 -0500124 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
125}
126
127static ssize_t
James Smart2e0fef82007-06-17 19:56:36 -0500128lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea31012005-04-17 16:05:31 -0500129{
James Smart2e0fef82007-06-17 19:56:36 -0500130 struct Scsi_Host *shost = class_to_shost(cdev);
131 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
132 struct lpfc_hba *phba = vport->phba;
133
dea31012005-04-17 16:05:31 -0500134 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
135}
136
137static ssize_t
138lpfc_fwrev_show(struct class_device *cdev, char *buf)
139{
James Smart2e0fef82007-06-17 19:56:36 -0500140 struct Scsi_Host *shost = class_to_shost(cdev);
141 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
142 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500143 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500144
dea31012005-04-17 16:05:31 -0500145 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500146 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500147}
148
149static ssize_t
150lpfc_hdw_show(struct class_device *cdev, char *buf)
151{
152 char hdw[9];
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct Scsi_Host *shost = class_to_shost(cdev);
154 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
155 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500156 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500157
dea31012005-04-17 16:05:31 -0500158 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
159 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
160}
161static ssize_t
162lpfc_option_rom_version_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
dea31012005-04-17 16:05:31 -0500168 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
169}
170static ssize_t
171lpfc_state_show(struct class_device *cdev, char *buf)
172{
James Smart2e0fef82007-06-17 19:56:36 -0500173 struct Scsi_Host *shost = class_to_shost(cdev);
174 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
175 struct lpfc_hba *phba = vport->phba;
176 int len = 0;
177
178 switch (phba->link_state) {
179 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500180 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500181 case LPFC_INIT_START:
182 case LPFC_INIT_MBX_CMDS:
183 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500184 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500185 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
186 break;
187 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500188 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500189 case LPFC_HBA_READY:
James Smarta8adb832007-10-27 13:37:53 -0400190 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
James Smart2e0fef82007-06-17 19:56:36 -0500191
192 switch (vport->port_state) {
James Smart2e0fef82007-06-17 19:56:36 -0500193 case LPFC_LOCAL_CFG_LINK:
194 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500195 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500196 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500197 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500198 case LPFC_FLOGI:
199 case LPFC_FABRIC_CFG_LINK:
200 case LPFC_NS_REG:
201 case LPFC_NS_QRY:
202 case LPFC_BUILD_DISC_LIST:
203 case LPFC_DISC_AUTH:
204 len += snprintf(buf + len, PAGE_SIZE - len,
205 "Discovery\n");
206 break;
207 case LPFC_VPORT_READY:
208 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
209 break;
210
James Smart92d7f7b2007-06-17 19:56:38 -0500211 case LPFC_VPORT_FAILED:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
213 break;
214
215 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "Unknown\n");
218 break;
219 }
220
dea31012005-04-17 16:05:31 -0500221 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500222 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500223 len += snprintf(buf + len, PAGE_SIZE-len,
224 " Public Loop\n");
225 else
226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Private Loop\n");
228 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500229 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500230 len += snprintf(buf + len, PAGE_SIZE-len,
231 " Fabric\n");
232 else
233 len += snprintf(buf + len, PAGE_SIZE-len,
234 " Point-2-Point\n");
235 }
236 }
James Smart2e0fef82007-06-17 19:56:36 -0500237
dea31012005-04-17 16:05:31 -0500238 return len;
239}
240
241static ssize_t
242lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
243{
James Smart2e0fef82007-06-17 19:56:36 -0500244 struct Scsi_Host *shost = class_to_shost(cdev);
245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246
247 return snprintf(buf, PAGE_SIZE, "%d\n",
248 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500249}
250
251
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700252static int
James Smart2e0fef82007-06-17 19:56:36 -0500253lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500254{
James Smart2e0fef82007-06-17 19:56:36 -0500255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
256 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500257 LPFC_MBOXQ_t *pmboxq;
258 int mbxstatus = MBXERR_ERROR;
259
James Smart2e0fef82007-06-17 19:56:36 -0500260 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
261 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
262 (vport->port_state != LPFC_VPORT_READY))
dea31012005-04-17 16:05:31 -0500263 return -EPERM;
264
265 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
266
267 if (!pmboxq)
268 return -ENOMEM;
269
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400271 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
272 pmboxq->mb.mbxOwner = OWN_HOST;
273
James Smart33ccf8d2006-08-17 11:57:58 -0400274 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500275
James Smart4db621e2006-07-06 15:49:49 -0400276 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
277 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
278 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
279 phba->cfg_link_speed);
280 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
281 phba->fc_ratov * 2);
282 }
283
James Smart5b8bd0c2007-04-25 09:52:49 -0400284 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500285 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400286 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500287
288 if (mbxstatus == MBXERR_ERROR)
289 return -EIO;
290
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700291 return 0;
dea31012005-04-17 16:05:31 -0500292}
293
James Smart40496f02006-07-06 15:50:22 -0400294static int
James Smart46fa3112007-04-25 09:51:45 -0400295lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
296{
297 struct completion online_compl;
298 struct lpfc_sli_ring *pring;
299 struct lpfc_sli *psli;
300 int status = 0;
301 int cnt = 0;
302 int i;
303
304 init_completion(&online_compl);
305 lpfc_workq_post_event(phba, &status, &online_compl,
306 LPFC_EVT_OFFLINE_PREP);
307 wait_for_completion(&online_compl);
308
309 if (status != 0)
310 return -EIO;
311
312 psli = &phba->sli;
313
314 for (i = 0; i < psli->num_rings; i++) {
315 pring = &psli->ring[i];
316 /* The linkdown event takes 30 seconds to timeout. */
317 while (pring->txcmplq_cnt) {
318 msleep(10);
319 if (cnt++ > 3000) {
320 lpfc_printf_log(phba,
321 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400322 "0466 Outstanding IO when "
323 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400324 break;
325 }
326 }
327 }
328
329 init_completion(&online_compl);
330 lpfc_workq_post_event(phba, &status, &online_compl, type);
331 wait_for_completion(&online_compl);
332
333 if (status != 0)
334 return -EIO;
335
336 return 0;
337}
338
339static int
James Smart40496f02006-07-06 15:50:22 -0400340lpfc_selective_reset(struct lpfc_hba *phba)
341{
342 struct completion online_compl;
343 int status = 0;
344
James Smart46fa3112007-04-25 09:51:45 -0400345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400346
347 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400348 return status;
James Smart40496f02006-07-06 15:50:22 -0400349
350 init_completion(&online_compl);
351 lpfc_workq_post_event(phba, &status, &online_compl,
352 LPFC_EVT_ONLINE);
353 wait_for_completion(&online_compl);
354
355 if (status != 0)
356 return -EIO;
357
358 return 0;
359}
360
361static ssize_t
362lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
363{
James Smart2e0fef82007-06-17 19:56:36 -0500364 struct Scsi_Host *shost = class_to_shost(cdev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367
James Smart40496f02006-07-06 15:50:22 -0400368 int status = -EINVAL;
369
370 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
371 status = lpfc_selective_reset(phba);
372
373 if (status == 0)
374 return strlen(buf);
375 else
376 return status;
377}
378
dea31012005-04-17 16:05:31 -0500379static ssize_t
380lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
381{
James Smart2e0fef82007-06-17 19:56:36 -0500382 struct Scsi_Host *shost = class_to_shost(cdev);
383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
384 struct lpfc_hba *phba = vport->phba;
385
dea31012005-04-17 16:05:31 -0500386 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
387}
388
389static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500390lpfc_board_mode_show(struct class_device *cdev, char *buf)
391{
James Smart2e0fef82007-06-17 19:56:36 -0500392 struct Scsi_Host *shost = class_to_shost(cdev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500395 char * state;
396
James Smart2e0fef82007-06-17 19:56:36 -0500397 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500398 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500399 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500400 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500401 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500402 state = "offline";
403 else
404 state = "online";
405
406 return snprintf(buf, PAGE_SIZE, "%s\n", state);
407}
408
409static ssize_t
410lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct Scsi_Host *shost = class_to_shost(cdev);
413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
414 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500415 struct completion online_compl;
416 int status=0;
417
418 init_completion(&online_compl);
419
James Smart46fa3112007-04-25 09:51:45 -0400420 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500421 lpfc_workq_post_event(phba, &status, &online_compl,
422 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400423 wait_for_completion(&online_compl);
424 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
425 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500426 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400427 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
428 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
429 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500430 else
431 return -EINVAL;
432
Jamie Wellnitz41415862006-02-28 19:25:27 -0500433 if (!status)
434 return strlen(buf);
435 else
436 return -EIO;
437}
438
James Smart311464e2007-08-02 11:10:37 -0400439static int
James Smart858c9f62007-06-17 19:56:39 -0500440lpfc_get_hba_info(struct lpfc_hba *phba,
441 uint32_t *mxri, uint32_t *axri,
442 uint32_t *mrpi, uint32_t *arpi,
443 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500444{
445 struct lpfc_sli *psli = &phba->sli;
446 LPFC_MBOXQ_t *pmboxq;
447 MAILBOX_t *pmb;
448 int rc = 0;
449
450 /*
451 * prevent udev from issuing mailbox commands until the port is
452 * configured.
453 */
454 if (phba->link_state < LPFC_LINK_DOWN ||
455 !phba->mbox_mem_pool ||
456 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
457 return 0;
458
459 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
460 return 0;
461
462 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
463 if (!pmboxq)
464 return 0;
465 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
466
467 pmb = &pmboxq->mb;
468 pmb->mbxCommand = MBX_READ_CONFIG;
469 pmb->mbxOwner = OWN_HOST;
470 pmboxq->context1 = NULL;
471
472 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
473 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
474 rc = MBX_NOT_FINISHED;
475 else
476 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
477
478 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500479 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500480 mempool_free(pmboxq, phba->mbox_mem_pool);
481 return 0;
482 }
483
484 if (mrpi)
485 *mrpi = pmb->un.varRdConfig.max_rpi;
486 if (arpi)
487 *arpi = pmb->un.varRdConfig.avail_rpi;
488 if (mxri)
489 *mxri = pmb->un.varRdConfig.max_xri;
490 if (axri)
491 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500492 if (mvpi)
493 *mvpi = pmb->un.varRdConfig.max_vpi;
494 if (avpi)
495 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500496
497 mempool_free(pmboxq, phba->mbox_mem_pool);
498 return 1;
499}
500
501static ssize_t
502lpfc_max_rpi_show(struct class_device *cdev, char *buf)
503{
504 struct Scsi_Host *shost = class_to_shost(cdev);
505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
506 struct lpfc_hba *phba = vport->phba;
507 uint32_t cnt;
508
James Smart858c9f62007-06-17 19:56:39 -0500509 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500510 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
511 return snprintf(buf, PAGE_SIZE, "Unknown\n");
512}
513
514static ssize_t
515lpfc_used_rpi_show(struct class_device *cdev, char *buf)
516{
517 struct Scsi_Host *shost = class_to_shost(cdev);
518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
519 struct lpfc_hba *phba = vport->phba;
520 uint32_t cnt, acnt;
521
James Smart858c9f62007-06-17 19:56:39 -0500522 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500523 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
524 return snprintf(buf, PAGE_SIZE, "Unknown\n");
525}
526
527static ssize_t
528lpfc_max_xri_show(struct class_device *cdev, char *buf)
529{
530 struct Scsi_Host *shost = class_to_shost(cdev);
531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
532 struct lpfc_hba *phba = vport->phba;
533 uint32_t cnt;
534
James Smart858c9f62007-06-17 19:56:39 -0500535 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500536 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
537 return snprintf(buf, PAGE_SIZE, "Unknown\n");
538}
539
540static ssize_t
541lpfc_used_xri_show(struct class_device *cdev, char *buf)
542{
543 struct Scsi_Host *shost = class_to_shost(cdev);
544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
545 struct lpfc_hba *phba = vport->phba;
546 uint32_t cnt, acnt;
547
James Smart858c9f62007-06-17 19:56:39 -0500548 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
549 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
550 return snprintf(buf, PAGE_SIZE, "Unknown\n");
551}
552
553static ssize_t
554lpfc_max_vpi_show(struct class_device *cdev, char *buf)
555{
556 struct Scsi_Host *shost = class_to_shost(cdev);
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 uint32_t cnt;
560
561 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
562 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
563 return snprintf(buf, PAGE_SIZE, "Unknown\n");
564}
565
566static ssize_t
567lpfc_used_vpi_show(struct class_device *cdev, char *buf)
568{
569 struct Scsi_Host *shost = class_to_shost(cdev);
570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
572 uint32_t cnt, acnt;
573
574 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500575 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
576 return snprintf(buf, PAGE_SIZE, "Unknown\n");
577}
578
579static ssize_t
580lpfc_npiv_info_show(struct class_device *cdev, char *buf)
581{
582 struct Scsi_Host *shost = class_to_shost(cdev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
585
586 if (!(phba->max_vpi))
587 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
588 if (vport->port_type == LPFC_PHYSICAL_PORT)
589 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
590 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
591}
592
Jamie Wellnitz41415862006-02-28 19:25:27 -0500593static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500594lpfc_poll_show(struct class_device *cdev, char *buf)
595{
James Smart2e0fef82007-06-17 19:56:36 -0500596 struct Scsi_Host *shost = class_to_shost(cdev);
597 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
598 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500599
600 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
601}
602
603static ssize_t
604lpfc_poll_store(struct class_device *cdev, const char *buf,
605 size_t count)
606{
James Smart2e0fef82007-06-17 19:56:36 -0500607 struct Scsi_Host *shost = class_to_shost(cdev);
608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
609 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500610 uint32_t creg_val;
611 uint32_t old_val;
612 int val=0;
613
614 if (!isdigit(buf[0]))
615 return -EINVAL;
616
617 if (sscanf(buf, "%i", &val) != 1)
618 return -EINVAL;
619
620 if ((val & 0x3) != val)
621 return -EINVAL;
622
James Smart2e0fef82007-06-17 19:56:36 -0500623 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500624
625 old_val = phba->cfg_poll;
626
627 if (val & ENABLE_FCP_RING_POLLING) {
628 if ((val & DISABLE_FCP_RING_INT) &&
629 !(old_val & DISABLE_FCP_RING_INT)) {
630 creg_val = readl(phba->HCregaddr);
631 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
632 writel(creg_val, phba->HCregaddr);
633 readl(phba->HCregaddr); /* flush */
634
635 lpfc_poll_start_timer(phba);
636 }
637 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500638 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500639 return -EINVAL;
640 }
641
642 if (!(val & DISABLE_FCP_RING_INT) &&
643 (old_val & DISABLE_FCP_RING_INT))
644 {
James Smart2e0fef82007-06-17 19:56:36 -0500645 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500646 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500647 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500648 creg_val = readl(phba->HCregaddr);
649 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
650 writel(creg_val, phba->HCregaddr);
651 readl(phba->HCregaddr); /* flush */
652 }
653
654 phba->cfg_poll = val;
655
James Smart2e0fef82007-06-17 19:56:36 -0500656 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500657
658 return strlen(buf);
659}
dea31012005-04-17 16:05:31 -0500660
661#define lpfc_param_show(attr) \
662static ssize_t \
663lpfc_##attr##_show(struct class_device *cdev, char *buf) \
664{ \
James Smart2e0fef82007-06-17 19:56:36 -0500665 struct Scsi_Host *shost = class_to_shost(cdev);\
666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
667 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500668 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400669 val = phba->cfg_##attr;\
670 return snprintf(buf, PAGE_SIZE, "%d\n",\
671 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500672}
673
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400674#define lpfc_param_hex_show(attr) \
675static ssize_t \
676lpfc_##attr##_show(struct class_device *cdev, char *buf) \
677{ \
James Smart2e0fef82007-06-17 19:56:36 -0500678 struct Scsi_Host *shost = class_to_shost(cdev);\
679 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
680 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400681 int val = 0;\
682 val = phba->cfg_##attr;\
683 return snprintf(buf, PAGE_SIZE, "%#x\n",\
684 phba->cfg_##attr);\
685}
686
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400687#define lpfc_param_init(attr, default, minval, maxval) \
688static int \
689lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
690{ \
691 if (val >= minval && val <= maxval) {\
692 phba->cfg_##attr = val;\
693 return 0;\
694 }\
695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400696 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
697 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400698 phba->cfg_##attr = default;\
699 return -EINVAL;\
700}
701
702#define lpfc_param_set(attr, default, minval, maxval) \
703static int \
704lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
705{ \
706 if (val >= minval && val <= maxval) {\
707 phba->cfg_##attr = val;\
708 return 0;\
709 }\
710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400711 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
712 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400713 return -EINVAL;\
714}
715
716#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500717static ssize_t \
718lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
719{ \
James Smart2e0fef82007-06-17 19:56:36 -0500720 struct Scsi_Host *shost = class_to_shost(cdev);\
721 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
722 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400723 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400724 if (!isdigit(buf[0]))\
725 return -EINVAL;\
726 if (sscanf(buf, "%i", &val) != 1)\
727 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400728 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400729 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400730 else \
731 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500732}
733
James Smart3de2a652007-08-02 11:09:59 -0400734#define lpfc_vport_param_show(attr) \
735static ssize_t \
736lpfc_##attr##_show(struct class_device *cdev, char *buf) \
737{ \
738 struct Scsi_Host *shost = class_to_shost(cdev);\
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
740 int val = 0;\
741 val = vport->cfg_##attr;\
742 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
743}
744
745#define lpfc_vport_param_hex_show(attr) \
746static ssize_t \
747lpfc_##attr##_show(struct class_device *cdev, char *buf) \
748{ \
749 struct Scsi_Host *shost = class_to_shost(cdev);\
750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
751 int val = 0;\
752 val = vport->cfg_##attr;\
753 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
754}
755
756#define lpfc_vport_param_init(attr, default, minval, maxval) \
757static int \
758lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
759{ \
760 if (val >= minval && val <= maxval) {\
761 vport->cfg_##attr = val;\
762 return 0;\
763 }\
James Smarte8b62012007-08-02 11:10:09 -0400764 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
765 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
766 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400767 vport->cfg_##attr = default;\
768 return -EINVAL;\
769}
770
771#define lpfc_vport_param_set(attr, default, minval, maxval) \
772static int \
773lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
774{ \
775 if (val >= minval && val <= maxval) {\
776 vport->cfg_##attr = val;\
777 return 0;\
778 }\
James Smarte8b62012007-08-02 11:10:09 -0400779 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
780 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
781 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400782 return -EINVAL;\
783}
784
785#define lpfc_vport_param_store(attr) \
786static ssize_t \
787lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
788{ \
789 struct Scsi_Host *shost = class_to_shost(cdev);\
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
791 int val=0;\
792 if (!isdigit(buf[0]))\
793 return -EINVAL;\
794 if (sscanf(buf, "%i", &val) != 1)\
795 return -EINVAL;\
796 if (lpfc_##attr##_set(vport, val) == 0) \
797 return strlen(buf);\
798 else \
799 return -EINVAL;\
800}
801
802
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400803#define LPFC_ATTR(name, defval, minval, maxval, desc) \
804static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500805module_param(lpfc_##name, int, 0);\
806MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400807lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500808
809#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
810static int lpfc_##name = defval;\
811module_param(lpfc_##name, int, 0);\
812MODULE_PARM_DESC(lpfc_##name, desc);\
813lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400814lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500815static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
816
817#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
818static int lpfc_##name = defval;\
819module_param(lpfc_##name, int, 0);\
820MODULE_PARM_DESC(lpfc_##name, desc);\
821lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400822lpfc_param_init(name, defval, minval, maxval)\
823lpfc_param_set(name, defval, minval, maxval)\
824lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500825static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
826 lpfc_##name##_show, lpfc_##name##_store)
827
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400828#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
829static int lpfc_##name = defval;\
830module_param(lpfc_##name, int, 0);\
831MODULE_PARM_DESC(lpfc_##name, desc);\
832lpfc_param_hex_show(name)\
833lpfc_param_init(name, defval, minval, maxval)\
834static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
835
836#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
837static int lpfc_##name = defval;\
838module_param(lpfc_##name, int, 0);\
839MODULE_PARM_DESC(lpfc_##name, desc);\
840lpfc_param_hex_show(name)\
841lpfc_param_init(name, defval, minval, maxval)\
842lpfc_param_set(name, defval, minval, maxval)\
843lpfc_param_store(name)\
844static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
845 lpfc_##name##_show, lpfc_##name##_store)
846
James Smart3de2a652007-08-02 11:09:59 -0400847#define LPFC_VPORT_ATTR(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_init(name, defval, minval, maxval)
852
853#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
854static int lpfc_##name = defval;\
855module_param(lpfc_##name, int, 0);\
856MODULE_PARM_DESC(lpfc_##name, desc);\
857lpfc_vport_param_show(name)\
858lpfc_vport_param_init(name, defval, minval, maxval)\
859static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
860
861#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
862static int lpfc_##name = defval;\
863module_param(lpfc_##name, int, 0);\
864MODULE_PARM_DESC(lpfc_##name, desc);\
865lpfc_vport_param_show(name)\
866lpfc_vport_param_init(name, defval, minval, maxval)\
867lpfc_vport_param_set(name, defval, minval, maxval)\
868lpfc_vport_param_store(name)\
869static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
870 lpfc_##name##_show, lpfc_##name##_store)
871
872#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
873static int lpfc_##name = defval;\
874module_param(lpfc_##name, int, 0);\
875MODULE_PARM_DESC(lpfc_##name, desc);\
876lpfc_vport_param_hex_show(name)\
877lpfc_vport_param_init(name, defval, minval, maxval)\
878static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
879
880#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
881static int lpfc_##name = defval;\
882module_param(lpfc_##name, int, 0);\
883MODULE_PARM_DESC(lpfc_##name, desc);\
884lpfc_vport_param_hex_show(name)\
885lpfc_vport_param_init(name, defval, minval, maxval)\
886lpfc_vport_param_set(name, defval, minval, maxval)\
887lpfc_vport_param_store(name)\
888static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
889 lpfc_##name##_show, lpfc_##name##_store)
890
dea31012005-04-17 16:05:31 -0500891static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
892static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
893static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
894static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
895static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500896static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500897static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
898static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
899static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
900static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
901 lpfc_option_rom_version_show, NULL);
902static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
903 lpfc_num_discovered_ports_show, NULL);
904static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
905static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
906 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500907static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
908 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400909static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500910static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
911static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
912static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
913static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
914static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
915static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
916static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
James Smart57127f12007-10-27 13:37:05 -0400917static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show,
918 NULL);
dea31012005-04-17 16:05:31 -0500919
James Smartc3f28af2006-08-18 17:47:18 -0400920
James Smarta12e07b2006-12-02 13:35:30 -0500921static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400922
923static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500924lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400925 size_t count)
926{
James Smart2e0fef82007-06-17 19:56:36 -0500927 struct Scsi_Host *shost = class_to_shost(cdev);
928 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
929 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400930 unsigned int cnt = count;
931
932 /*
933 * We're doing a simple sanity check for soft_wwpn setting.
934 * We require that the user write a specific key to enable
935 * the soft_wwpn attribute to be settable. Once the attribute
936 * is written, the enable key resets. If further updates are
937 * desired, the key must be written again to re-enable the
938 * attribute.
939 *
940 * The "key" is not secret - it is a hardcoded string shown
941 * here. The intent is to protect against the random user or
942 * application that is just writing attributes.
943 */
944
945 /* count may include a LF at end of string */
946 if (buf[cnt-1] == '\n')
947 cnt--;
948
James Smarta12e07b2006-12-02 13:35:30 -0500949 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
950 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400951 return -EINVAL;
952
James Smarta12e07b2006-12-02 13:35:30 -0500953 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400954 return count;
955}
James Smarta12e07b2006-12-02 13:35:30 -0500956static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
957 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400958
959static ssize_t
960lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
961{
James Smart2e0fef82007-06-17 19:56:36 -0500962 struct Scsi_Host *shost = class_to_shost(cdev);
963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
964 struct lpfc_hba *phba = vport->phba;
965
Randy Dunlapafc071e2006-10-23 21:47:13 -0700966 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
967 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400968}
969
970
971static ssize_t
972lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
973{
James Smart2e0fef82007-06-17 19:56:36 -0500974 struct Scsi_Host *shost = class_to_shost(cdev);
975 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
976 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400977 struct completion online_compl;
978 int stat1=0, stat2=0;
979 unsigned int i, j, cnt=count;
980 u8 wwpn[8];
981
982 /* count may include a LF at end of string */
983 if (buf[cnt-1] == '\n')
984 cnt--;
985
James Smarta12e07b2006-12-02 13:35:30 -0500986 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400987 ((cnt == 17) && (*buf++ != 'x')) ||
988 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
989 return -EINVAL;
990
James Smarta12e07b2006-12-02 13:35:30 -0500991 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400992
993 memset(wwpn, 0, sizeof(wwpn));
994
995 /* Validate and store the new name */
996 for (i=0, j=0; i < 16; i++) {
997 if ((*buf >= 'a') && (*buf <= 'f'))
998 j = ((j << 4) | ((*buf++ -'a') + 10));
999 else if ((*buf >= 'A') && (*buf <= 'F'))
1000 j = ((j << 4) | ((*buf++ -'A') + 10));
1001 else if ((*buf >= '0') && (*buf <= '9'))
1002 j = ((j << 4) | (*buf++ -'0'));
1003 else
1004 return -EINVAL;
1005 if (i % 2) {
1006 wwpn[i/2] = j & 0xff;
1007 j = 0;
1008 }
1009 }
1010 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001011 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001012 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001013 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001014
1015 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1016 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1017
James Smart46fa3112007-04-25 09:51:45 -04001018 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001019 if (stat1)
1020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001021 "0463 lpfc_soft_wwpn attribute set failed to "
1022 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001023 init_completion(&online_compl);
1024 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1025 wait_for_completion(&online_compl);
1026 if (stat2)
1027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001028 "0464 lpfc_soft_wwpn attribute set failed to "
1029 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001030 return (stat1 || stat2) ? -EIO : count;
1031}
1032static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1033 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1034
James Smarta12e07b2006-12-02 13:35:30 -05001035static ssize_t
1036lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1037{
James Smart51ef4c22007-08-02 11:10:31 -04001038 struct Scsi_Host *shost = class_to_shost(cdev);
1039 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001040 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1041 (unsigned long long)phba->cfg_soft_wwnn);
1042}
1043
1044
1045static ssize_t
1046lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1047{
James Smart51ef4c22007-08-02 11:10:31 -04001048 struct Scsi_Host *shost = class_to_shost(cdev);
1049 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001050 unsigned int i, j, cnt=count;
1051 u8 wwnn[8];
1052
1053 /* count may include a LF at end of string */
1054 if (buf[cnt-1] == '\n')
1055 cnt--;
1056
1057 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1058 ((cnt == 17) && (*buf++ != 'x')) ||
1059 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1060 return -EINVAL;
1061
1062 /*
1063 * Allow wwnn to be set many times, as long as the enable is set.
1064 * However, once the wwpn is set, everything locks.
1065 */
1066
1067 memset(wwnn, 0, sizeof(wwnn));
1068
1069 /* Validate and store the new name */
1070 for (i=0, j=0; i < 16; i++) {
1071 if ((*buf >= 'a') && (*buf <= 'f'))
1072 j = ((j << 4) | ((*buf++ -'a') + 10));
1073 else if ((*buf >= 'A') && (*buf <= 'F'))
1074 j = ((j << 4) | ((*buf++ -'A') + 10));
1075 else if ((*buf >= '0') && (*buf <= '9'))
1076 j = ((j << 4) | (*buf++ -'0'));
1077 else
1078 return -EINVAL;
1079 if (i % 2) {
1080 wwnn[i/2] = j & 0xff;
1081 j = 0;
1082 }
1083 }
1084 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1085
1086 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1087 "lpfc%d: soft_wwnn set. Value will take effect upon "
1088 "setting of the soft_wwpn\n", phba->brd_no);
1089
1090 return count;
1091}
1092static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1093 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1094
James Smartc3f28af2006-08-18 17:47:18 -04001095
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001096static int lpfc_poll = 0;
1097module_param(lpfc_poll, int, 0);
1098MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1099 " 0 - none,"
1100 " 1 - poll with interrupts enabled"
1101 " 3 - poll and disable FCP ring interrupts");
1102
1103static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1104 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001105
James Smart92d7f7b2007-06-17 19:56:38 -05001106int lpfc_sli_mode = 0;
1107module_param(lpfc_sli_mode, int, 0);
1108MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1109 " 0 - auto (SLI-3 if supported),"
1110 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1111 " 3 - select SLI-3");
1112
James Smart7ee5d432007-10-27 13:37:17 -04001113int lpfc_enable_npiv = 0;
1114module_param(lpfc_enable_npiv, int, 0);
1115MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1116lpfc_param_show(enable_npiv);
1117lpfc_param_init(enable_npiv, 0, 0, 1);
1118static CLASS_DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1119 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001120
dea31012005-04-17 16:05:31 -05001121/*
James Smartc01f3202006-08-18 17:47:08 -04001122# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1123# until the timer expires. Value range is [0,255]. Default value is 30.
1124*/
1125static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1126static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1127module_param(lpfc_nodev_tmo, int, 0);
1128MODULE_PARM_DESC(lpfc_nodev_tmo,
1129 "Seconds driver will hold I/O waiting "
1130 "for a device to come back");
1131static ssize_t
1132lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1133{
James Smart2e0fef82007-06-17 19:56:36 -05001134 struct Scsi_Host *shost = class_to_shost(cdev);
1135 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001136 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001137 val = vport->cfg_devloss_tmo;
1138 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001139}
1140
1141static int
James Smart3de2a652007-08-02 11:09:59 -04001142lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001143{
James Smart3de2a652007-08-02 11:09:59 -04001144 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1145 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1146 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001147 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1148 "0402 Ignoring nodev_tmo module "
1149 "parameter because devloss_tmo is "
1150 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001151 return 0;
1152 }
1153
1154 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001155 vport->cfg_nodev_tmo = val;
1156 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001157 return 0;
1158 }
James Smarte8b62012007-08-02 11:10:09 -04001159 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1160 "0400 lpfc_nodev_tmo attribute cannot be set to"
1161 " %d, allowed range is [%d, %d]\n",
1162 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001163 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001164 return -EINVAL;
1165}
1166
James Smart7054a602007-04-25 09:52:34 -04001167static void
James Smart3de2a652007-08-02 11:09:59 -04001168lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001169{
James Smart858c9f62007-06-17 19:56:39 -05001170 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001171 struct lpfc_nodelist *ndlp;
1172
James Smart51ef4c22007-08-02 11:10:31 -04001173 shost = lpfc_shost_from_vport(vport);
1174 spin_lock_irq(shost->host_lock);
1175 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1176 if (ndlp->rport)
1177 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1178 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001179}
1180
James Smartc01f3202006-08-18 17:47:08 -04001181static int
James Smart3de2a652007-08-02 11:09:59 -04001182lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001183{
James Smart3de2a652007-08-02 11:09:59 -04001184 if (vport->dev_loss_tmo_changed ||
1185 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001186 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1187 "0401 Ignoring change to nodev_tmo "
1188 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001189 return 0;
1190 }
James Smartc01f3202006-08-18 17:47:08 -04001191 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001192 vport->cfg_nodev_tmo = val;
1193 vport->cfg_devloss_tmo = val;
1194 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001195 return 0;
1196 }
James Smarte8b62012007-08-02 11:10:09 -04001197 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1198 "0403 lpfc_nodev_tmo attribute cannot be set to"
1199 "%d, allowed range is [%d, %d]\n",
1200 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001201 return -EINVAL;
1202}
1203
James Smart3de2a652007-08-02 11:09:59 -04001204lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001205
1206static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1207 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1208
1209/*
1210# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1211# disappear until the timer expires. Value range is [0,255]. Default
1212# value is 30.
1213*/
1214module_param(lpfc_devloss_tmo, int, 0);
1215MODULE_PARM_DESC(lpfc_devloss_tmo,
1216 "Seconds driver will hold I/O waiting "
1217 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001218lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1219 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1220lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001221static int
James Smart3de2a652007-08-02 11:09:59 -04001222lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001223{
1224 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001225 vport->cfg_nodev_tmo = val;
1226 vport->cfg_devloss_tmo = val;
1227 vport->dev_loss_tmo_changed = 1;
1228 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001229 return 0;
1230 }
1231
James Smarte8b62012007-08-02 11:10:09 -04001232 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1233 "0404 lpfc_devloss_tmo attribute cannot be set to"
1234 " %d, allowed range is [%d, %d]\n",
1235 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001236 return -EINVAL;
1237}
1238
James Smart3de2a652007-08-02 11:09:59 -04001239lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001240static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1241 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1242
1243/*
dea31012005-04-17 16:05:31 -05001244# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1245# deluged with LOTS of information.
1246# You can set a bit mask to record specific types of verbose messages:
1247#
1248# LOG_ELS 0x1 ELS events
1249# LOG_DISCOVERY 0x2 Link discovery events
1250# LOG_MBOX 0x4 Mailbox events
1251# LOG_INIT 0x8 Initialization events
1252# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001253# LOG_FCP 0x40 FCP traffic history
1254# LOG_NODE 0x80 Node table events
1255# LOG_MISC 0x400 Miscellaneous events
1256# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001257# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001258# LOG_LIBDFC 0x2000 LIBDFC events
1259# LOG_ALL_MSG 0xffff LOG all messages
1260*/
James Smarte8b62012007-08-02 11:10:09 -04001261LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1262 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001263
1264/*
James Smart7ee5d432007-10-27 13:37:17 -04001265# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1266# objects that have been registered with the nameserver after login.
1267*/
1268LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1269 "Deregister nameserver objects before LOGO");
1270
1271/*
dea31012005-04-17 16:05:31 -05001272# lun_queue_depth: This parameter is used to limit the number of outstanding
1273# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1274*/
James Smart3de2a652007-08-02 11:09:59 -04001275LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1276 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001277
1278/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001279# hba_queue_depth: This parameter is used to limit the number of outstanding
1280# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1281# value is greater than the maximum number of exchanges supported by the HBA,
1282# then maximum number of exchanges supported by the HBA is used to determine
1283# the hba_queue_depth.
1284*/
1285LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1286 "Max number of FCP commands we can queue to a lpfc HBA");
1287
1288/*
James Smart92d7f7b2007-06-17 19:56:38 -05001289# peer_port_login: This parameter allows/prevents logins
1290# between peer ports hosted on the same physical port.
1291# When this parameter is set 0 peer ports of same physical port
1292# are not allowed to login to each other.
1293# When this parameter is set 1 peer ports of same physical port
1294# are allowed to login to each other.
1295# Default value of this parameter is 0.
1296*/
James Smart3de2a652007-08-02 11:09:59 -04001297LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1298 "Allow peer ports on the same physical port to login to each "
1299 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001300
1301/*
James Smart3de2a652007-08-02 11:09:59 -04001302# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001303# between Virtual Ports and remote initiators.
1304# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1305# other initiators and will attempt to PLOGI all remote ports.
1306# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1307# remote ports and will not attempt to PLOGI to other initiators.
1308# This parameter does not restrict to the physical port.
1309# This parameter does not restrict logins to Fabric resident remote ports.
1310# Default value of this parameter is 1.
1311*/
James Smart3de2a652007-08-02 11:09:59 -04001312static int lpfc_restrict_login = 1;
1313module_param(lpfc_restrict_login, int, 0);
1314MODULE_PARM_DESC(lpfc_restrict_login,
1315 "Restrict virtual ports login to remote initiators.");
1316lpfc_vport_param_show(restrict_login);
1317
1318static int
1319lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1320{
1321 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001322 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1323 "0449 lpfc_restrict_login attribute cannot "
1324 "be set to %d, allowed range is [0, 1]\n",
1325 val);
James Smart3de2a652007-08-02 11:09:59 -04001326 vport->cfg_restrict_login = 1;
1327 return -EINVAL;
1328 }
1329 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1330 vport->cfg_restrict_login = 0;
1331 return 0;
1332 }
1333 vport->cfg_restrict_login = val;
1334 return 0;
1335}
1336
1337static int
1338lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1339{
1340 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001341 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1342 "0450 lpfc_restrict_login attribute cannot "
1343 "be set to %d, allowed range is [0, 1]\n",
1344 val);
James Smart3de2a652007-08-02 11:09:59 -04001345 vport->cfg_restrict_login = 1;
1346 return -EINVAL;
1347 }
1348 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001349 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1350 "0468 lpfc_restrict_login must be 0 for "
1351 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001352 vport->cfg_restrict_login = 0;
1353 return 0;
1354 }
1355 vport->cfg_restrict_login = val;
1356 return 0;
1357}
1358lpfc_vport_param_store(restrict_login);
1359static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1360 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001361
1362/*
dea31012005-04-17 16:05:31 -05001363# Some disk devices have a "select ID" or "select Target" capability.
1364# From a protocol standpoint "select ID" usually means select the
1365# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1366# annex" which contains a table that maps a "select ID" (a number
1367# between 0 and 7F) to an ALPA. By default, for compatibility with
1368# older drivers, the lpfc driver scans this table from low ALPA to high
1369# ALPA.
1370#
1371# Turning on the scan-down variable (on = 1, off = 0) will
1372# cause the lpfc driver to use an inverted table, effectively
1373# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1374#
1375# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1376# and will not work across a fabric. Also this parameter will take
1377# effect only in the case when ALPA map is not available.)
1378*/
James Smart3de2a652007-08-02 11:09:59 -04001379LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1380 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001381
1382/*
dea31012005-04-17 16:05:31 -05001383# lpfc_topology: link topology for init link
1384# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001385# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001386# 0x02 = attempt point-to-point mode only
1387# 0x04 = attempt loop mode only
1388# 0x06 = attempt point-to-point mode then loop
1389# Set point-to-point mode if you want to run as an N_Port.
1390# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1391# Default value is 0.
1392*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001393LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001394
1395/*
1396# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1397# connection.
1398# 0 = auto select (default)
1399# 1 = 1 Gigabaud
1400# 2 = 2 Gigabaud
1401# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001402# 8 = 8 Gigabaud
1403# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001404*/
James Smartb87eab32007-04-25 09:53:28 -04001405LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001406
1407/*
1408# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1409# Value range is [2,3]. Default value is 3.
1410*/
James Smart3de2a652007-08-02 11:09:59 -04001411LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1412 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001413
1414/*
1415# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1416# is [0,1]. Default value is 0.
1417*/
James Smart3de2a652007-08-02 11:09:59 -04001418LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1419 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001420
1421/*
1422# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1423# range is [0,1]. Default value is 0.
1424*/
1425LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1426
1427/*
1428# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1429# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001430# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001431# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1432# cr_delay is set to 0.
1433*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001434LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001435 "interrupt response is generated");
1436
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001437LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001438 "interrupt response is generated");
1439
1440/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001441# lpfc_multi_ring_support: Determines how many rings to spread available
1442# cmd/rsp IOCB entries across.
1443# Value range is [1,2]. Default value is 1.
1444*/
1445LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1446 "SLI rings to spread IOCB entries across");
1447
1448/*
James Smarta4bc3372006-12-02 13:34:16 -05001449# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1450# identifies what rctl value to configure the additional ring for.
1451# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1452*/
1453LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1454 255, "Identifies RCTL for additional ring configuration");
1455
1456/*
1457# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1458# identifies what type value to configure the additional ring for.
1459# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1460*/
1461LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1462 255, "Identifies TYPE for additional ring configuration");
1463
1464/*
dea31012005-04-17 16:05:31 -05001465# lpfc_fdmi_on: controls FDMI support.
1466# 0 = no FDMI support
1467# 1 = support FDMI without attribute of hostname
1468# 2 = support FDMI with attribute of hostname
1469# Value range [0,2]. Default value is 0.
1470*/
James Smart3de2a652007-08-02 11:09:59 -04001471LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001472
1473/*
1474# Specifies the maximum number of ELS cmds we can have outstanding (for
1475# discovery). Value range is [1,64]. Default value = 32.
1476*/
James Smart3de2a652007-08-02 11:09:59 -04001477LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001478 "during discovery");
1479
1480/*
James Smart65a29c12006-07-06 15:50:50 -04001481# lpfc_max_luns: maximum allowed LUN.
1482# Value range is [0,65535]. Default value is 255.
1483# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001484*/
James Smart3de2a652007-08-02 11:09:59 -04001485LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001486
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001487/*
1488# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1489# Value range is [1,255], default value is 10.
1490*/
1491LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1492 "Milliseconds driver will wait between polling FCP ring");
1493
James Smart4ff43242006-12-02 13:34:56 -05001494/*
1495# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1496# support this feature
1497# 0 = MSI disabled (default)
1498# 1 = MSI enabled
1499# Value range is [0,1]. Default value is 0.
1500*/
1501LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1502
James Smartc3f28af2006-08-18 17:47:18 -04001503
James Smart92d7f7b2007-06-17 19:56:38 -05001504
James Smart2e0fef82007-06-17 19:56:36 -05001505struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001506 &class_device_attr_info,
1507 &class_device_attr_serialnum,
1508 &class_device_attr_modeldesc,
1509 &class_device_attr_modelname,
1510 &class_device_attr_programtype,
1511 &class_device_attr_portnum,
1512 &class_device_attr_fwrev,
1513 &class_device_attr_hdw,
1514 &class_device_attr_option_rom_version,
1515 &class_device_attr_state,
1516 &class_device_attr_num_discovered_ports,
1517 &class_device_attr_lpfc_drvr_version,
James Smart57127f12007-10-27 13:37:05 -04001518 &class_device_attr_lpfc_temp_sensor,
dea31012005-04-17 16:05:31 -05001519 &class_device_attr_lpfc_log_verbose,
1520 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001521 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001522 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001523 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001524 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001525 &class_device_attr_lpfc_fcp_class,
1526 &class_device_attr_lpfc_use_adisc,
1527 &class_device_attr_lpfc_ack0,
1528 &class_device_attr_lpfc_topology,
1529 &class_device_attr_lpfc_scan_down,
1530 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001531 &class_device_attr_lpfc_cr_delay,
1532 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001533 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001534 &class_device_attr_lpfc_multi_ring_rctl,
1535 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001536 &class_device_attr_lpfc_fdmi_on,
1537 &class_device_attr_lpfc_max_luns,
James Smart78b2d852007-08-02 11:10:21 -04001538 &class_device_attr_lpfc_enable_npiv,
dea31012005-04-17 16:05:31 -05001539 &class_device_attr_nport_evt_cnt,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001540 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001541 &class_device_attr_max_vpi,
1542 &class_device_attr_used_vpi,
1543 &class_device_attr_max_rpi,
1544 &class_device_attr_used_rpi,
1545 &class_device_attr_max_xri,
1546 &class_device_attr_used_xri,
1547 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001548 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001549 &class_device_attr_lpfc_poll,
1550 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001551 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001552 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001553 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001554 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001555 NULL,
1556};
1557
James Smart3de2a652007-08-02 11:09:59 -04001558struct class_device_attribute *lpfc_vport_attrs[] = {
1559 &class_device_attr_info,
1560 &class_device_attr_state,
1561 &class_device_attr_num_discovered_ports,
1562 &class_device_attr_lpfc_drvr_version,
1563
1564 &class_device_attr_lpfc_log_verbose,
1565 &class_device_attr_lpfc_lun_queue_depth,
1566 &class_device_attr_lpfc_nodev_tmo,
1567 &class_device_attr_lpfc_devloss_tmo,
1568 &class_device_attr_lpfc_hba_queue_depth,
1569 &class_device_attr_lpfc_peer_port_login,
1570 &class_device_attr_lpfc_restrict_login,
1571 &class_device_attr_lpfc_fcp_class,
1572 &class_device_attr_lpfc_use_adisc,
1573 &class_device_attr_lpfc_fdmi_on,
1574 &class_device_attr_lpfc_max_luns,
1575 &class_device_attr_nport_evt_cnt,
James Smart3de2a652007-08-02 11:09:59 -04001576 &class_device_attr_npiv_info,
James Smart7ee5d432007-10-27 13:37:17 -04001577 &class_device_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04001578 NULL,
1579};
1580
dea31012005-04-17 16:05:31 -05001581static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001582sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1583 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001584{
1585 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001586 struct class_device *cdev = container_of(kobj, struct class_device,
1587 kobj);
1588 struct Scsi_Host *shost = class_to_shost(cdev);
1589 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1590 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001591
1592 if ((off + count) > FF_REG_AREA_SIZE)
1593 return -ERANGE;
1594
1595 if (count == 0) return 0;
1596
1597 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1598 return -EINVAL;
1599
James Smart2e0fef82007-06-17 19:56:36 -05001600 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001601 return -EPERM;
1602 }
1603
James Smart2e0fef82007-06-17 19:56:36 -05001604 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001605 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1606 writel(*((uint32_t *)(buf + buf_off)),
1607 phba->ctrl_regs_memmap_p + off + buf_off);
1608
James Smart2e0fef82007-06-17 19:56:36 -05001609 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001610
1611 return count;
1612}
1613
1614static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001615sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1616 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001617{
1618 size_t buf_off;
1619 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001620 struct class_device *cdev = container_of(kobj, struct class_device,
1621 kobj);
1622 struct Scsi_Host *shost = class_to_shost(cdev);
1623 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1624 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001625
1626 if (off > FF_REG_AREA_SIZE)
1627 return -ERANGE;
1628
1629 if ((off + count) > FF_REG_AREA_SIZE)
1630 count = FF_REG_AREA_SIZE - off;
1631
1632 if (count == 0) return 0;
1633
1634 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1635 return -EINVAL;
1636
James Smart2e0fef82007-06-17 19:56:36 -05001637 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001638
1639 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1640 tmp_ptr = (uint32_t *)(buf + buf_off);
1641 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1642 }
1643
James Smart2e0fef82007-06-17 19:56:36 -05001644 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001645
1646 return count;
1647}
1648
1649static struct bin_attribute sysfs_ctlreg_attr = {
1650 .attr = {
1651 .name = "ctlreg",
1652 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001653 },
1654 .size = 256,
1655 .read = sysfs_ctlreg_read,
1656 .write = sysfs_ctlreg_write,
1657};
1658
1659
1660static void
James Smart2e0fef82007-06-17 19:56:36 -05001661sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001662{
1663 phba->sysfs_mbox.state = SMBOX_IDLE;
1664 phba->sysfs_mbox.offset = 0;
1665
1666 if (phba->sysfs_mbox.mbox) {
1667 mempool_free(phba->sysfs_mbox.mbox,
1668 phba->mbox_mem_pool);
1669 phba->sysfs_mbox.mbox = NULL;
1670 }
1671}
1672
1673static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001674sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1675 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001676{
James Smart2e0fef82007-06-17 19:56:36 -05001677 struct class_device *cdev = container_of(kobj, struct class_device,
1678 kobj);
1679 struct Scsi_Host *shost = class_to_shost(cdev);
1680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1681 struct lpfc_hba *phba = vport->phba;
1682 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001683
1684 if ((count + off) > MAILBOX_CMD_SIZE)
1685 return -ERANGE;
1686
1687 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1688 return -EINVAL;
1689
1690 if (count == 0)
1691 return 0;
1692
1693 if (off == 0) {
1694 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1695 if (!mbox)
1696 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001697 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001698 }
1699
James Smart2e0fef82007-06-17 19:56:36 -05001700 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001701
1702 if (off == 0) {
1703 if (phba->sysfs_mbox.mbox)
1704 mempool_free(mbox, phba->mbox_mem_pool);
1705 else
1706 phba->sysfs_mbox.mbox = mbox;
1707 phba->sysfs_mbox.state = SMBOX_WRITING;
1708 } else {
1709 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1710 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001711 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001712 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001713 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001714 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001715 }
1716 }
1717
1718 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1719 buf, count);
1720
1721 phba->sysfs_mbox.offset = off + count;
1722
James Smart2e0fef82007-06-17 19:56:36 -05001723 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001724
1725 return count;
1726}
1727
1728static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001729sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1730 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001731{
James Smart2e0fef82007-06-17 19:56:36 -05001732 struct class_device *cdev = container_of(kobj, struct class_device,
1733 kobj);
1734 struct Scsi_Host *shost = class_to_shost(cdev);
1735 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1736 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001737 int rc;
1738
James Smart1dcb58e2007-04-25 09:51:30 -04001739 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001740 return -ERANGE;
1741
James Smart1dcb58e2007-04-25 09:51:30 -04001742 if ((count + off) > MAILBOX_CMD_SIZE)
1743 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001744
1745 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1746 return -EINVAL;
1747
1748 if (off && count == 0)
1749 return 0;
1750
James Smart2e0fef82007-06-17 19:56:36 -05001751 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001752
1753 if (off == 0 &&
1754 phba->sysfs_mbox.state == SMBOX_WRITING &&
1755 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1756
1757 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1758 /* Offline only */
dea31012005-04-17 16:05:31 -05001759 case MBX_INIT_LINK:
1760 case MBX_DOWN_LINK:
1761 case MBX_CONFIG_LINK:
1762 case MBX_CONFIG_RING:
1763 case MBX_RESET_RING:
1764 case MBX_UNREG_LOGIN:
1765 case MBX_CLEAR_LA:
1766 case MBX_DUMP_CONTEXT:
1767 case MBX_RUN_DIAGS:
1768 case MBX_RESTART:
1769 case MBX_FLASH_WR_ULA:
1770 case MBX_SET_MASK:
1771 case MBX_SET_SLIM:
1772 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001773 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001774 printk(KERN_WARNING "mbox_read:Command 0x%x "
1775 "is illegal in on-line state\n",
1776 phba->sysfs_mbox.mbox->mb.mbxCommand);
1777 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001778 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001779 return -EPERM;
1780 }
James Smarta8adb832007-10-27 13:37:53 -04001781 case MBX_WRITE_NV:
1782 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05001783 case MBX_LOAD_SM:
1784 case MBX_READ_NV:
1785 case MBX_READ_CONFIG:
1786 case MBX_READ_RCONFIG:
1787 case MBX_READ_STATUS:
1788 case MBX_READ_XRI:
1789 case MBX_READ_REV:
1790 case MBX_READ_LNK_STAT:
1791 case MBX_DUMP_MEMORY:
1792 case MBX_DOWN_LOAD:
1793 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001794 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001795 case MBX_LOAD_AREA:
1796 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001797 case MBX_BEACON:
1798 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001799 break;
1800 case MBX_READ_SPARM64:
1801 case MBX_READ_LA:
1802 case MBX_READ_LA64:
1803 case MBX_REG_LOGIN:
1804 case MBX_REG_LOGIN64:
1805 case MBX_CONFIG_PORT:
1806 case MBX_RUN_BIU_DIAG:
1807 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1808 phba->sysfs_mbox.mbox->mb.mbxCommand);
1809 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001810 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001811 return -EPERM;
1812 default:
1813 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1814 phba->sysfs_mbox.mbox->mb.mbxCommand);
1815 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001817 return -EPERM;
1818 }
1819
James Smart92d7f7b2007-06-17 19:56:38 -05001820 phba->sysfs_mbox.mbox->vport = vport;
1821
James Smart2e0fef82007-06-17 19:56:36 -05001822 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001823 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001825 return -EAGAIN;
1826 }
1827
James Smart2e0fef82007-06-17 19:56:36 -05001828 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001829 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1830
James Smart2e0fef82007-06-17 19:56:36 -05001831 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001832 rc = lpfc_sli_issue_mbox (phba,
1833 phba->sysfs_mbox.mbox,
1834 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001835 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001836
1837 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001838 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001839 rc = lpfc_sli_issue_mbox_wait (phba,
1840 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001841 lpfc_mbox_tmo_val(phba,
1842 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001844 }
1845
1846 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001847 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001848 phba->sysfs_mbox.mbox = NULL;
1849 }
dea31012005-04-17 16:05:31 -05001850 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001851 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001852 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001853 }
1854 phba->sysfs_mbox.state = SMBOX_READING;
1855 }
1856 else if (phba->sysfs_mbox.offset != off ||
1857 phba->sysfs_mbox.state != SMBOX_READING) {
1858 printk(KERN_WARNING "mbox_read: Bad State\n");
1859 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001860 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001861 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001862 }
1863
1864 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1865
1866 phba->sysfs_mbox.offset = off + count;
1867
James Smart1dcb58e2007-04-25 09:51:30 -04001868 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001869 sysfs_mbox_idle(phba);
1870
James Smart2e0fef82007-06-17 19:56:36 -05001871 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001872
1873 return count;
1874}
1875
1876static struct bin_attribute sysfs_mbox_attr = {
1877 .attr = {
1878 .name = "mbox",
1879 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001880 },
James Smart1dcb58e2007-04-25 09:51:30 -04001881 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001882 .read = sysfs_mbox_read,
1883 .write = sysfs_mbox_write,
1884};
1885
1886int
James Smart2e0fef82007-06-17 19:56:36 -05001887lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001888{
James Smart2e0fef82007-06-17 19:56:36 -05001889 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001890 int error;
1891
James Smart2e0fef82007-06-17 19:56:36 -05001892 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001893 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001894 if (error)
1895 goto out;
1896
James Smart2e0fef82007-06-17 19:56:36 -05001897 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001898 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001899 if (error)
1900 goto out_remove_ctlreg_attr;
1901
1902 return 0;
1903out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001904 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001905out:
1906 return error;
1907}
1908
1909void
James Smart2e0fef82007-06-17 19:56:36 -05001910lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001911{
James Smart2e0fef82007-06-17 19:56:36 -05001912 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001913
James Smart2e0fef82007-06-17 19:56:36 -05001914 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1915 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001916}
1917
1918
1919/*
1920 * Dynamic FC Host Attributes Support
1921 */
1922
1923static void
1924lpfc_get_host_port_id(struct Scsi_Host *shost)
1925{
James Smart2e0fef82007-06-17 19:56:36 -05001926 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1927
dea31012005-04-17 16:05:31 -05001928 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001929 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001930}
1931
1932static void
1933lpfc_get_host_port_type(struct Scsi_Host *shost)
1934{
James Smart2e0fef82007-06-17 19:56:36 -05001935 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1936 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001937
1938 spin_lock_irq(shost->host_lock);
1939
James Smart92d7f7b2007-06-17 19:56:38 -05001940 if (vport->port_type == LPFC_NPIV_PORT) {
1941 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1942 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001943 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001944 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001945 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1946 else
1947 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1948 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001949 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001950 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1951 else
1952 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1953 }
1954 } else
1955 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1956
1957 spin_unlock_irq(shost->host_lock);
1958}
1959
1960static void
1961lpfc_get_host_port_state(struct Scsi_Host *shost)
1962{
James Smart2e0fef82007-06-17 19:56:36 -05001963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1964 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001965
1966 spin_lock_irq(shost->host_lock);
1967
James Smart2e0fef82007-06-17 19:56:36 -05001968 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05001969 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1970 else {
James Smart2e0fef82007-06-17 19:56:36 -05001971 switch (phba->link_state) {
1972 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05001973 case LPFC_LINK_DOWN:
1974 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1975 break;
1976 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05001977 case LPFC_CLEAR_LA:
1978 case LPFC_HBA_READY:
1979 /* Links up, beyond this port_type reports state */
1980 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1981 break;
1982 case LPFC_HBA_ERROR:
1983 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1984 break;
1985 default:
1986 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1987 break;
1988 }
1989 }
1990
1991 spin_unlock_irq(shost->host_lock);
1992}
1993
1994static void
1995lpfc_get_host_speed(struct Scsi_Host *shost)
1996{
James Smart2e0fef82007-06-17 19:56:36 -05001997 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1998 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001999
2000 spin_lock_irq(shost->host_lock);
2001
James Smart2e0fef82007-06-17 19:56:36 -05002002 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002003 switch(phba->fc_linkspeed) {
2004 case LA_1GHZ_LINK:
2005 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2006 break;
2007 case LA_2GHZ_LINK:
2008 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2009 break;
2010 case LA_4GHZ_LINK:
2011 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2012 break;
James Smartb87eab32007-04-25 09:53:28 -04002013 case LA_8GHZ_LINK:
2014 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2015 break;
dea31012005-04-17 16:05:31 -05002016 default:
2017 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2018 break;
2019 }
2020 }
2021
2022 spin_unlock_irq(shost->host_lock);
2023}
2024
2025static void
2026lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2027{
James Smart2e0fef82007-06-17 19:56:36 -05002028 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2029 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002030 u64 node_name;
dea31012005-04-17 16:05:31 -05002031
2032 spin_lock_irq(shost->host_lock);
2033
James Smart2e0fef82007-06-17 19:56:36 -05002034 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002035 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002036 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002037 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002038 else
2039 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05002040 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05002041
2042 spin_unlock_irq(shost->host_lock);
2043
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002044 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002045}
2046
dea31012005-04-17 16:05:31 -05002047static struct fc_host_statistics *
2048lpfc_get_stats(struct Scsi_Host *shost)
2049{
James Smart2e0fef82007-06-17 19:56:36 -05002050 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2051 struct lpfc_hba *phba = vport->phba;
2052 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002053 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002054 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002055 LPFC_MBOXQ_t *pmboxq;
2056 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002057 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002058 int rc = 0;
dea31012005-04-17 16:05:31 -05002059
James Smart92d7f7b2007-06-17 19:56:38 -05002060 /*
2061 * prevent udev from issuing mailbox commands until the port is
2062 * configured.
2063 */
James Smart2e0fef82007-06-17 19:56:36 -05002064 if (phba->link_state < LPFC_LINK_DOWN ||
2065 !phba->mbox_mem_pool ||
2066 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002067 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002068
2069 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002070 return NULL;
2071
dea31012005-04-17 16:05:31 -05002072 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2073 if (!pmboxq)
2074 return NULL;
2075 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2076
2077 pmb = &pmboxq->mb;
2078 pmb->mbxCommand = MBX_READ_STATUS;
2079 pmb->mbxOwner = OWN_HOST;
2080 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002081 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002082
James Smart2e0fef82007-06-17 19:56:36 -05002083 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002084 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002085 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002086 else
dea31012005-04-17 16:05:31 -05002087 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2088
2089 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002090 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002091 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002092 return NULL;
2093 }
2094
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002095 memset(hs, 0, sizeof (struct fc_host_statistics));
2096
dea31012005-04-17 16:05:31 -05002097 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2098 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2099 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2100 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2101
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002102 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002103 pmb->mbxCommand = MBX_READ_LNK_STAT;
2104 pmb->mbxOwner = OWN_HOST;
2105 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002106 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002107
James Smart2e0fef82007-06-17 19:56:36 -05002108 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002109 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002110 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002111 else
dea31012005-04-17 16:05:31 -05002112 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2113
2114 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002115 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002116 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002117 return NULL;
2118 }
2119
2120 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2121 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2122 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2123 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2124 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2125 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2126 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2127
James Smart64ba8812006-08-02 15:24:34 -04002128 hs->link_failure_count -= lso->link_failure_count;
2129 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2130 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2131 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2132 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2133 hs->invalid_crc_count -= lso->invalid_crc_count;
2134 hs->error_frames -= lso->error_frames;
2135
dea31012005-04-17 16:05:31 -05002136 if (phba->fc_topology == TOPOLOGY_LOOP) {
2137 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002138 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002139 hs->nos_count = -1;
2140 } else {
2141 hs->lip_count = -1;
2142 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002143 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002144 }
2145
2146 hs->dumped_frames = -1;
2147
James Smart64ba8812006-08-02 15:24:34 -04002148 seconds = get_seconds();
2149 if (seconds < psli->stats_start)
2150 hs->seconds_since_last_reset = seconds +
2151 ((unsigned long)-1 - psli->stats_start);
2152 else
2153 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002154
James Smart1dcb58e2007-04-25 09:51:30 -04002155 mempool_free(pmboxq, phba->mbox_mem_pool);
2156
dea31012005-04-17 16:05:31 -05002157 return hs;
2158}
2159
James Smart64ba8812006-08-02 15:24:34 -04002160static void
2161lpfc_reset_stats(struct Scsi_Host *shost)
2162{
James Smart2e0fef82007-06-17 19:56:36 -05002163 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2164 struct lpfc_hba *phba = vport->phba;
2165 struct lpfc_sli *psli = &phba->sli;
2166 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002167 LPFC_MBOXQ_t *pmboxq;
2168 MAILBOX_t *pmb;
2169 int rc = 0;
2170
James Smart2e0fef82007-06-17 19:56:36 -05002171 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002172 return;
2173
James Smart64ba8812006-08-02 15:24:34 -04002174 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2175 if (!pmboxq)
2176 return;
2177 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2178
2179 pmb = &pmboxq->mb;
2180 pmb->mbxCommand = MBX_READ_STATUS;
2181 pmb->mbxOwner = OWN_HOST;
2182 pmb->un.varWords[0] = 0x1; /* reset request */
2183 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002184 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002185
James Smart2e0fef82007-06-17 19:56:36 -05002186 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002187 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2188 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2189 else
2190 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2191
2192 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002193 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002194 mempool_free(pmboxq, phba->mbox_mem_pool);
2195 return;
2196 }
2197
2198 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2199 pmb->mbxCommand = MBX_READ_LNK_STAT;
2200 pmb->mbxOwner = OWN_HOST;
2201 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002202 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002203
James Smart2e0fef82007-06-17 19:56:36 -05002204 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002205 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2206 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2207 else
2208 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2209
2210 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002211 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002212 mempool_free( pmboxq, phba->mbox_mem_pool);
2213 return;
2214 }
2215
2216 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2217 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2218 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2219 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2220 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2221 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2222 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2223 lso->link_events = (phba->fc_eventTag >> 1);
2224
2225 psli->stats_start = get_seconds();
2226
James Smart1dcb58e2007-04-25 09:51:30 -04002227 mempool_free(pmboxq, phba->mbox_mem_pool);
2228
James Smart64ba8812006-08-02 15:24:34 -04002229 return;
2230}
dea31012005-04-17 16:05:31 -05002231
2232/*
2233 * The LPFC driver treats linkdown handling as target loss events so there
2234 * are no sysfs handlers for link_down_tmo.
2235 */
James Smart685f0bf2007-04-25 09:53:08 -04002236
2237static struct lpfc_nodelist *
2238lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002239{
James Smart2e0fef82007-06-17 19:56:36 -05002240 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2241 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002242 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002243
2244 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002245 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002246 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002247 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2248 starget->id == ndlp->nlp_sid) {
2249 spin_unlock_irq(shost->host_lock);
2250 return ndlp;
dea31012005-04-17 16:05:31 -05002251 }
2252 }
2253 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002254 return NULL;
2255}
dea31012005-04-17 16:05:31 -05002256
James Smart685f0bf2007-04-25 09:53:08 -04002257static void
2258lpfc_get_starget_port_id(struct scsi_target *starget)
2259{
2260 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2261
2262 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002263}
2264
2265static void
2266lpfc_get_starget_node_name(struct scsi_target *starget)
2267{
James Smart685f0bf2007-04-25 09:53:08 -04002268 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002269
James Smart685f0bf2007-04-25 09:53:08 -04002270 fc_starget_node_name(starget) =
2271 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002272}
2273
2274static void
2275lpfc_get_starget_port_name(struct scsi_target *starget)
2276{
James Smart685f0bf2007-04-25 09:53:08 -04002277 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002278
James Smart685f0bf2007-04-25 09:53:08 -04002279 fc_starget_port_name(starget) =
2280 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002281}
2282
2283static void
dea31012005-04-17 16:05:31 -05002284lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2285{
dea31012005-04-17 16:05:31 -05002286 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002287 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002288 else
James Smartc01f3202006-08-18 17:47:08 -04002289 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002290}
2291
2292
2293#define lpfc_rport_show_function(field, format_string, sz, cast) \
2294static ssize_t \
2295lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2296{ \
2297 struct fc_rport *rport = transport_class_to_rport(cdev); \
2298 struct lpfc_rport_data *rdata = rport->hostdata; \
2299 return snprintf(buf, sz, format_string, \
2300 (rdata->target) ? cast rdata->target->field : 0); \
2301}
2302
2303#define lpfc_rport_rd_attr(field, format_string, sz) \
2304 lpfc_rport_show_function(field, format_string, sz, ) \
2305static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2306
2307
2308struct fc_function_template lpfc_transport_functions = {
2309 /* fixed attributes the driver supports */
2310 .show_host_node_name = 1,
2311 .show_host_port_name = 1,
2312 .show_host_supported_classes = 1,
2313 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002314 .show_host_supported_speeds = 1,
2315 .show_host_maxframe_size = 1,
2316
2317 /* dynamic attributes the driver supports */
2318 .get_host_port_id = lpfc_get_host_port_id,
2319 .show_host_port_id = 1,
2320
2321 .get_host_port_type = lpfc_get_host_port_type,
2322 .show_host_port_type = 1,
2323
2324 .get_host_port_state = lpfc_get_host_port_state,
2325 .show_host_port_state = 1,
2326
2327 /* active_fc4s is shown but doesn't change (thus no get function) */
2328 .show_host_active_fc4s = 1,
2329
2330 .get_host_speed = lpfc_get_host_speed,
2331 .show_host_speed = 1,
2332
2333 .get_host_fabric_name = lpfc_get_host_fabric_name,
2334 .show_host_fabric_name = 1,
2335
2336 /*
2337 * The LPFC driver treats linkdown handling as target loss events
2338 * so there are no sysfs handlers for link_down_tmo.
2339 */
2340
2341 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002342 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002343
2344 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2345 .show_rport_maxframe_size = 1,
2346 .show_rport_supported_classes = 1,
2347
dea31012005-04-17 16:05:31 -05002348 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2349 .show_rport_dev_loss_tmo = 1,
2350
2351 .get_starget_port_id = lpfc_get_starget_port_id,
2352 .show_starget_port_id = 1,
2353
2354 .get_starget_node_name = lpfc_get_starget_node_name,
2355 .show_starget_node_name = 1,
2356
2357 .get_starget_port_name = lpfc_get_starget_port_name,
2358 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002359
2360 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002361 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2362 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002363
James Smart92d7f7b2007-06-17 19:56:38 -05002364 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2365};
2366
James Smart98c9ea52007-10-27 13:37:33 -04002367struct fc_function_template lpfc_vport_transport_functions = {
2368 /* fixed attributes the driver supports */
2369 .show_host_node_name = 1,
2370 .show_host_port_name = 1,
2371 .show_host_supported_classes = 1,
2372 .show_host_supported_fc4s = 1,
2373 .show_host_supported_speeds = 1,
2374 .show_host_maxframe_size = 1,
2375
2376 /* dynamic attributes the driver supports */
2377 .get_host_port_id = lpfc_get_host_port_id,
2378 .show_host_port_id = 1,
2379
2380 .get_host_port_type = lpfc_get_host_port_type,
2381 .show_host_port_type = 1,
2382
2383 .get_host_port_state = lpfc_get_host_port_state,
2384 .show_host_port_state = 1,
2385
2386 /* active_fc4s is shown but doesn't change (thus no get function) */
2387 .show_host_active_fc4s = 1,
2388
2389 .get_host_speed = lpfc_get_host_speed,
2390 .show_host_speed = 1,
2391
2392 .get_host_fabric_name = lpfc_get_host_fabric_name,
2393 .show_host_fabric_name = 1,
2394
2395 /*
2396 * The LPFC driver treats linkdown handling as target loss events
2397 * so there are no sysfs handlers for link_down_tmo.
2398 */
2399
2400 .get_fc_host_stats = lpfc_get_stats,
2401 .reset_fc_host_stats = lpfc_reset_stats,
2402
2403 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2404 .show_rport_maxframe_size = 1,
2405 .show_rport_supported_classes = 1,
2406
2407 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2408 .show_rport_dev_loss_tmo = 1,
2409
2410 .get_starget_port_id = lpfc_get_starget_port_id,
2411 .show_starget_port_id = 1,
2412
2413 .get_starget_node_name = lpfc_get_starget_node_name,
2414 .show_starget_node_name = 1,
2415
2416 .get_starget_port_name = lpfc_get_starget_port_name,
2417 .show_starget_port_name = 1,
2418
2419 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2420 .terminate_rport_io = lpfc_terminate_rport_io,
2421
2422 .vport_disable = lpfc_vport_disable,
2423};
2424
dea31012005-04-17 16:05:31 -05002425void
2426lpfc_get_cfgparam(struct lpfc_hba *phba)
2427{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002428 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2429 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002430 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002431 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2432 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002433 lpfc_ack0_init(phba, lpfc_ack0);
2434 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002435 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002436 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002437 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002438 lpfc_use_msi_init(phba, lpfc_use_msi);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002439 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002440 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002441 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002442 /*
2443 * The total number of segments is the configuration value plus 2
2444 * since the IOCB need a command and response bde.
2445 */
2446 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
dea31012005-04-17 16:05:31 -05002447 /*
2448 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2449 * used to create the sg_dma_buf_pool must be dynamically calculated
2450 */
2451 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2452 sizeof(struct fcp_rsp) +
2453 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002454 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002455 return;
2456}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002457
James Smart3de2a652007-08-02 11:09:59 -04002458void
2459lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2460{
James Smarte8b62012007-08-02 11:10:09 -04002461 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002462 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2463 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2464 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2465 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2466 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2467 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2468 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2469 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2470 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2471 lpfc_max_luns_init(vport, lpfc_max_luns);
2472 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04002473 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05002474 return;
2475}